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;
}
Aggregations