use of com.netflix.spinnaker.front50.exceptions.InvalidRequestException in project front50 by spinnaker.
the class ReorderPipelinesController method handlePipelineReorder.
private void handlePipelineReorder(Map<String, Object> requestBody, ItemDAO<Pipeline> pipelineItemDAO) {
String application = (String) requestBody.get("application");
Map<String, Integer> idsToIndices = (Map<String, Integer>) requestBody.get("idsToIndices");
if (application == null) {
throw new InvalidRequestException("`application` is required field on request body");
}
if (idsToIndices == null) {
throw new InvalidRequestException("`idsToIndices` is required field on request body");
}
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (!fiatPermissionEvaluator.storeWholePermission() && !fiatPermissionEvaluator.hasPermission(auth, application, "APPLICATION", "WRITE")) {
throw new InvalidRequestException("Application write permission is required to reorder pipelines");
}
for (String id : idsToIndices.keySet()) {
Pipeline pipeline = pipelineItemDAO.findById(id);
if (pipeline == null) {
throw new NotFoundException(String.format("No pipeline of id %s found", id));
}
if (!pipeline.getApplication().equals(application)) {
throw new InvalidRequestException(String.format("Pipeline with id %s does not belong to application %s", id, application));
}
pipeline.setIndex(idsToIndices.get(id));
pipelineItemDAO.update(id, pipeline);
}
}
use of com.netflix.spinnaker.front50.exceptions.InvalidRequestException 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;
}
use of com.netflix.spinnaker.front50.exceptions.InvalidRequestException in project front50 by spinnaker.
the class DeliveryController method upsertConfig.
@PreAuthorize("hasPermission(#config.application, 'APPLICATION', 'WRITE')")
@ApiOperation(value = "", notes = "Update a delivery config")
@RequestMapping(method = RequestMethod.PUT, value = "/deliveries/{id}")
Delivery upsertConfig(@PathVariable String id, @RequestBody Delivery config) {
if (!id.equals(config.getId())) {
throw new InvalidRequestException("URL id (" + id + ") does not match submitted id (" + config.getId() + ")");
}
try {
Delivery existing = deliveryRepository.findById(id);
config.setCreateTs(existing.getCreateTs());
} catch (NotFoundException e) {
// ignore because we will create config
}
return deliveryRepository.upsertConfig(config);
}
Aggregations