use of com.netflix.spinnaker.kork.web.exceptions.NotFoundException in project front50 by spinnaker.
the class S3StorageService method loadObject.
@Override
public <T extends Timestamped> T loadObject(ObjectType objectType, String objectKey) throws NotFoundException {
try {
S3Object s3Object = amazonS3.getObject(bucket, buildS3Key(objectType.group, objectKey, objectType.defaultMetadataFilename));
T item = deserialize(s3Object, (Class<T>) objectType.clazz);
item.setLastModified(s3Object.getObjectMetadata().getLastModified().getTime());
return item;
} catch (AmazonS3Exception e) {
if (e.getStatusCode() == 404) {
throw new NotFoundException("Object not found (key: " + objectKey + ")");
}
throw e;
} catch (IOException e) {
throw new IllegalStateException("Unable to deserialize object (key: " + objectKey + ")", e);
}
}
use of com.netflix.spinnaker.kork.web.exceptions.NotFoundException in project front50 by spinnaker.
the class S3StorageService method listObjectVersions.
@Override
public <T extends Timestamped> Collection<T> listObjectVersions(ObjectType objectType, String objectKey, int maxResults) throws NotFoundException {
if (maxResults == 1) {
List<T> results = new ArrayList<>();
results.add(loadObject(objectType, objectKey));
return results;
}
try {
VersionListing versionListing = amazonS3.listVersions(new ListVersionsRequest(bucket, buildS3Key(objectType.group, objectKey, objectType.defaultMetadataFilename), null, null, null, maxResults));
return versionListing.getVersionSummaries().stream().map(s3VersionSummary -> {
try {
S3Object s3Object = amazonS3.getObject(new GetObjectRequest(bucket, buildS3Key(objectType.group, objectKey, objectType.defaultMetadataFilename), s3VersionSummary.getVersionId()));
T item = deserialize(s3Object, (Class<T>) objectType.clazz);
item.setLastModified(s3Object.getObjectMetadata().getLastModified().getTime());
return item;
} catch (IOException e) {
throw new IllegalStateException(e);
}
}).collect(Collectors.toList());
} catch (AmazonS3Exception e) {
if (e.getStatusCode() == 404) {
throw new NotFoundException(String.format("No item found with id of %s", objectKey.toLowerCase()));
}
throw e;
}
}
use of com.netflix.spinnaker.kork.web.exceptions.NotFoundException 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.kork.web.exceptions.NotFoundException 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);
}
use of com.netflix.spinnaker.kork.web.exceptions.NotFoundException in project front50 by spinnaker.
the class OracleStorageService method loadObject.
@Override
public <T extends Timestamped> T loadObject(ObjectType objectType, String objectKey) throws NotFoundException {
WebResource wr = client.resource(UriBuilder.fromPath(endpoint + "/n/{arg1}/b/{arg2}/o/{arg3}").build(region, namespace, bucketName, buildOSSKey(objectType.group, objectKey, objectType.defaultMetadataFilename)));
wr.accept(MediaType.APPLICATION_JSON_TYPE);
try {
T obj = (T) wr.get(objectType.clazz);
return obj;
} catch (UniformInterfaceException e) {
if (e.getResponse().getStatus() == 404) {
throw new NotFoundException("Object not found (key: " + objectKey + ")");
}
throw e;
}
}
Aggregations