@Override public Integration get(String id) { Integration integration = Getter.super.get(id); if ( integration.isDeleted() ) { //Not sure if we need to do that for both current and desired status, //but If we don't do include the desired state, IntegrationITCase is not going to pass anytime soon. Why? //Cause that test, is using NoopHandlerProvider, so that means no controllers. throw new EntityNotFoundException(String.format("Integration %s has been deleted", integration.getId())); } // Get the latest connection configs. List<Connection> connections = integration.getConnections().stream() .map(this::toCurrentConnection) .collect(Collectors.toList()); List<Step> steps = integration.getSteps().stream() .map(this::toCurrentSteps) .collect(Collectors.toList()); return new Integration.Builder() .createFrom(integration) .connections(connections) .steps(steps) .build(); }
@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); }
private void setVersion(IntegrationDeployment integrationDeployment) { Integration integration = integrationDeployment.getIntegrationId().map(i -> dataManager.fetch(Integration.class, i)).orElseThrow(()-> new IllegalStateException("Integration not found!")); dataManager.update(new Integration.Builder().createFrom(integration).version(integrationDeployment.getVersion()).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; } }
@Override public Integration create(@Context SecurityContext sec, @ConvertGroup(from = Default.class, to = AllValidations.class) final Integration integration) { Integration encryptedIntegration = encryptionSupport.encrypt(integration); Integration updatedIntegration = new Integration.Builder() .createFrom(encryptedIntegration) .createdAt(System.currentTimeMillis()) .build(); // Create the the integration. return getDataManager().create(updatedIntegration); }
public Integration encrypt(Integration integration) { return new Integration.Builder() .createFrom(integration) .steps(encrypt(integration.getSteps())) .build(); }
@Override public void update(String id, @ConvertGroup(from = Default.class, to = AllValidations.class) Integration integration) { Integration existing = Getter.super.get(id); Integration updatedIntegration = new Integration.Builder() .createFrom(encryptionSupport.encrypt(integration)) .version(existing.getVersion()+1) .updatedAt(System.currentTimeMillis()) .build(); getDataManager().update(updatedIntegration); updateBulletinBoard(id); }
private void updateIntegration(IntegrationDeployment integrationDeployment, IntegrationDeploymentState state) { Integration current = dataManager.fetch(Integration.class, integrationDeployment.getIntegrationId().orElseThrow(() -> new IllegalStateException("IntegrationDeployment should have an integrationId"))); //Set the deployed integrationDeployment id. Integration updated = new Integration.Builder().createFrom(current) .deploymentId(integrationDeployment.getVersion().get()) .currentStatus(state) .build(); dataManager.update(updated); }