use of org.alfresco.rest.framework.core.exceptions.NotFoundException in project alfresco-remote-api by Alfresco.
the class RenditionsImpl method createRendition.
@Override
public void createRendition(NodeRef nodeRef, String versionLabelId, Rendition rendition, boolean executeAsync, Parameters parameters) {
// If thumbnail generation has been configured off, then don't bother.
if (!renditionService2.isEnabled()) {
throw new DisabledServiceException("Rendition generation has been disabled.");
}
final NodeRef sourceNodeRef = validateNode(nodeRef.getStoreRef(), nodeRef.getId(), versionLabelId, parameters);
final NodeRef renditionNodeRef = getRenditionByName(sourceNodeRef, rendition.getId(), parameters);
if (renditionNodeRef != null) {
// 409
throw new ConstraintViolatedException(rendition.getId() + " rendition already exists.");
}
try {
renditionService2.render(sourceNodeRef, rendition.getId());
} catch (IllegalArgumentException e) {
// 404
throw new NotFoundException(rendition.getId() + " is not registered.");
} catch (UnsupportedOperationException e) {
// 400
throw new IllegalArgumentException((e.getMessage()));
} catch (IllegalStateException e) {
// 409
throw new StaleEntityException(e.getMessage());
}
}
use of org.alfresco.rest.framework.core.exceptions.NotFoundException in project alfresco-remote-api by Alfresco.
the class ExceptionResolverTests method testMatchException.
// 04180006 Authentication failed for Web Script org/alfresco/api/ResourceWebScript.get
@Test
public void testMatchException() {
ErrorResponse response = assistant.resolveException(new ApiException(null));
assertNotNull(response);
// default to INTERNAL_SERVER_ERROR
assertEquals(500, response.getStatusCode());
response = assistant.resolveException(new InvalidArgumentException(null));
// default to STATUS_BAD_REQUEST
assertEquals(400, response.getStatusCode());
response = assistant.resolveException(new InvalidQueryException(null));
// default to STATUS_BAD_REQUEST
assertEquals(400, response.getStatusCode());
response = assistant.resolveException(new NotFoundException(null));
// default to STATUS_NOT_FOUND
assertEquals(404, response.getStatusCode());
response = assistant.resolveException(new EntityNotFoundException(null));
// default to STATUS_NOT_FOUND
assertEquals(404, response.getStatusCode());
response = assistant.resolveException(new RelationshipResourceNotFoundException(null, null));
// default to STATUS_NOT_FOUND
assertEquals(404, response.getStatusCode());
response = assistant.resolveException(new PermissionDeniedException(null));
// default to STATUS_FORBIDDEN
assertEquals(403, response.getStatusCode());
response = assistant.resolveException(new UnsupportedResourceOperationException(null));
// default to STATUS_METHOD_NOT_ALLOWED
assertEquals(405, response.getStatusCode());
response = assistant.resolveException(new DeletedResourceException(null));
// default to STATUS_METHOD_NOT_ALLOWED
assertEquals(405, response.getStatusCode());
response = assistant.resolveException(new ConstraintViolatedException(null));
// default to STATUS_CONFLICT
assertEquals(409, response.getStatusCode());
response = assistant.resolveException(new StaleEntityException(null));
// default to STATUS_CONFLICT
assertEquals(409, response.getStatusCode());
// Try a random exception
response = assistant.resolveException(new FormNotFoundException(null));
// default to INTERNAL_SERVER_ERROR
assertEquals(500, response.getStatusCode());
response = assistant.resolveException(new InsufficientStorageException(null));
assertEquals(507, response.getStatusCode());
response = assistant.resolveException(new IntegrityException(null));
assertEquals(422, response.getStatusCode());
}
use of org.alfresco.rest.framework.core.exceptions.NotFoundException in project alfresco-remote-api by Alfresco.
the class ResourceLocatorTests method testResourceVersions.
@Test
public void testResourceVersions() {
ResourceWithMetadata aResource = null;
try {
aResource = locator.locateEntityResource(api, "sheepnoaction", HttpMethod.GET);
fail("Should throw an NotFoundException");
} catch (NotFoundException error) {
// this is correct
}
// Previously no actions for this entity, with v2 now have a GET action
Api v2 = Api.valueOf(api.getName(), api.getScope().toString(), "2");
aResource = locator.locateEntityResource(v2, "sheepnoaction", HttpMethod.GET);
assertNotNull(aResource);
// Not defined in v2 but now available because all v1 are available in v2.
aResource = locator.locateEntityResource(v2, "sheep", HttpMethod.GET);
assertNotNull(aResource);
try {
// Not defined in v1
aResource = locator.locateRelationResource(api, "sheepnoaction", "v3isaresource", HttpMethod.GET);
fail("Only available in v3");
} catch (NotFoundException error) {
// this is correct
}
try {
// Not defined in v2
aResource = locator.locateRelationResource(v2, "sheepnoaction", "v3isaresource", HttpMethod.GET);
fail("Only available in v3");
} catch (NotFoundException error) {
// this is correct
}
// Only defined in V3
Api v3 = Api.valueOf(api.getName(), api.getScope().toString(), "3");
aResource = locator.locateRelationResource(v3, "sheepnoaction", "v3isaresource", HttpMethod.GET);
assertNotNull("This resource is only available in v3", aResource);
// Defined in v1 but available in v3
aResource = locator.locateEntityResource(v3, "sheep", HttpMethod.GET);
assertNotNull("This resource should be available in v3", aResource);
}
use of org.alfresco.rest.framework.core.exceptions.NotFoundException in project alfresco-remote-api by Alfresco.
the class ResourceLocatorTests method testInvalidApis.
@Test
public void testInvalidApis() {
ResourceWithMetadata entityResource = null;
try {
entityResource = locator.locateEntityResource(Api.valueOf("alfrescomock", "public", "1"), "sheep", HttpMethod.GET);
fail("Should throw an NotFoundException");
} catch (NotFoundException error) {
// this is correct
}
try {
entityResource = locator.locateEntityResource(Api.valueOf("alfrescomock", "public", "999"), "sheep", HttpMethod.GET);
fail("Should throw an NotFoundException");
} catch (NotFoundException error) {
// this is correct
}
entityResource = locator.locateEntityResource(Api.valueOf("alfrescomock", "private", "1"), "sheep", HttpMethod.GET);
assertNotNull(entityResource);
}
Aggregations