class IntegrationDeploymentHandler extends BaseHandler {

    @PUT
    @Produces(MediaType.APPLICATION_JSON)
    public IntegrationDeployment update(@Context final SecurityContext sec,
        @NotNull @PathParam("id") @Parameter(required = true) final String id) {
        final DataManager dataManager = getDataManager();
        final Integration integration = dataManager.fetch(Integration.class, id);

        if (integration == null) {
            throw new EntityNotFoundException();
        }

        // Update previous deployments targetState=Undeployed and make sure
        // nextDeploymentVersion is larger than all previous ones.
        Optional<Integer> maybeLatestVersion = dataManager
            .fetchAllByPropertyValue(IntegrationDeployment.class, "integrationId", id).map(deployment -> {
                if (deployment.getTargetState() != IntegrationDeploymentState.Unpublished) {
                    dataManager.update(deployment.withTargetState(IntegrationDeploymentState.Unpublished));
                }

                return deployment.getVersion();
            }).max(Integer::compareTo);

        final int version = maybeLatestVersion.map(v -> v + 1).orElse(1);
        final Optional<String> validationStatus = validateQuotas(id, sec.getUserPrincipal().getName());
        final IntegrationDeployment deployment = new IntegrationDeployment.Builder()
            .id(IntegrationDeployment.compositeId(id, version)).spec(integration).version(version)
            .userId(sec.getUserPrincipal().getName())
            .createdAt(System.currentTimeMillis())
            .statusMessage(validationStatus).build();

        return getDataManager().create(deployment);
    }

    @Autowired public  IntegrationDeploymentHandler(final DataManager dataMgr, OpenShiftService openShiftService,
            UserConfigurationProperties properties);

}