Search in sources :

Example 1 with DuplicateEntityException

use of com.netflix.spinnaker.front50.exceptions.DuplicateEntityException in project front50 by spinnaker.

the class StrategyController method update.

@PreAuthorize("hasPermission(#strategy.application, 'APPLICATION', 'WRITE')")
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public Pipeline update(@PathVariable final String id, @RequestBody final Pipeline strategy) {
    Pipeline existingStrategy = pipelineStrategyDAO.findById(id);
    if (!strategy.getId().equals(existingStrategy.getId())) {
        throw new InvalidRequestException(format("The provided id '%s' doesn't match the strategy id '%s'", id, strategy.getId()));
    }
    boolean alreadyExists = pipelineStrategyDAO.getPipelinesByApplication(strategy.getApplication()).stream().anyMatch(it -> it.getName().equalsIgnoreCase(strategy.getName()) && !it.getId().equals(id));
    if (alreadyExists) {
        throw new DuplicateEntityException(format("A strategy with name '%s' already exists in application '%s'", strategy.getName(), strategy.getApplication()));
    }
    strategy.setLastModified(System.currentTimeMillis());
    pipelineStrategyDAO.update(id, strategy);
    return strategy;
}
Also used : DuplicateEntityException(com.netflix.spinnaker.front50.exceptions.DuplicateEntityException) InvalidRequestException(com.netflix.spinnaker.front50.exceptions.InvalidRequestException) Pipeline(com.netflix.spinnaker.front50.api.model.pipeline.Pipeline) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

Pipeline (com.netflix.spinnaker.front50.api.model.pipeline.Pipeline)1 DuplicateEntityException (com.netflix.spinnaker.front50.exceptions.DuplicateEntityException)1 InvalidRequestException (com.netflix.spinnaker.front50.exceptions.InvalidRequestException)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1