@Override public void delete(String id) { Integration existing = Getter.super.get(id); //Set all integration status to Undeployed. Set<String> deploymentIds = getDataManager().fetchIdsByPropertyValue(IntegrationDeployment.class, "integrationId", existing.getId().get()); if (deploymentIds != null && !deploymentIds.isEmpty()) { deploymentIds.stream() .map(i -> getDataManager().fetch(IntegrationDeployment.class, i)) .filter(r -> r != null) .map(r -> r.withTargetState(IntegrationDeploymentState.Unpublished)) .forEach(r -> getDataManager().update(r)); } Integration updatedIntegration = new Integration.Builder() .createFrom(existing) .updatedAt(System.currentTimeMillis()) .isDeleted(true) .build(); Updater.super.update(id, updatedIntegration); }
@Before public void setupMocks() { validator.dataManager = mock(DataManager.class); when(validator.dataManager.fetchIdsByPropertyValue(Connection.class, "name", "Existing")) .thenReturn(new HashSet<>(Arrays.asList("same"))); when(validator.dataManager.fetchIdsByPropertyValue(Integration.class, "name", "Existing")) .thenReturn(new HashSet<>(Arrays.asList("deleted"))); when(validator.dataManager.fetch(Integration.class, "deleted")) .thenReturn(new Integration.Builder().name("Existing").id("deleted").isDeleted(true).build()); }
private void importIntegrations(SecurityContext sec, JsonDbDao<Integration> export, ArrayList<ChangeEvent> result) { for (Integration integration : export.fetchAll().getItems()) { Integration.Builder builder = new Integration.Builder() .createFrom(integration) .isDeleted(false) .updatedAt(System.currentTimeMillis()); // Do we need to create it? String id = integration.getId().get(); Integration previous = dataManager.fetch(Integration.class, id); if (previous == null) { LOG.info("Creating integration: {}", integration.getName()); integrationHandler.create(sec, builder.build()); result.add(ChangeEvent.of("created", integration.getKind().getModelName(), id)); } else { LOG.info("Updating integration: {}", integration.getName()); integrationHandler.update(id, builder.version(previous.getVersion()+1).build()); result.add(ChangeEvent.of("updated", integration.getKind().getModelName(), id)); } integrationHandler.updateBulletinBoard(id); break; } }