Search in sources :

Example 21 with NotFoundException

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());
    }
}
Also used : DisabledServiceException(org.alfresco.rest.framework.core.exceptions.DisabledServiceException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) StaleEntityException(org.alfresco.rest.framework.core.exceptions.StaleEntityException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Example 22 with NotFoundException

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());
}
Also used : UnsupportedResourceOperationException(org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException) InsufficientStorageException(org.alfresco.rest.framework.core.exceptions.InsufficientStorageException) FormNotFoundException(org.alfresco.repo.forms.FormNotFoundException) RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) DeletedResourceException(org.alfresco.rest.framework.core.exceptions.DeletedResourceException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) ErrorResponse(org.alfresco.rest.framework.core.exceptions.ErrorResponse) RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) FormNotFoundException(org.alfresco.repo.forms.FormNotFoundException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) StaleEntityException(org.alfresco.rest.framework.core.exceptions.StaleEntityException) InvalidQueryException(org.alfresco.rest.framework.resource.parameters.where.InvalidQueryException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException) Test(org.junit.Test)

Example 23 with NotFoundException

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);
}
Also used : NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) Api(org.alfresco.rest.framework.Api) ResourceWithMetadata(org.alfresco.rest.framework.core.ResourceWithMetadata) Test(org.junit.Test)

Example 24 with NotFoundException

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);
}
Also used : NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) ResourceWithMetadata(org.alfresco.rest.framework.core.ResourceWithMetadata) Test(org.junit.Test)

Aggregations

NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)24 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)11 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)9 NodeRef (org.alfresco.service.cmr.repository.NodeRef)9 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)8 DisabledServiceException (org.alfresco.rest.framework.core.exceptions.DisabledServiceException)6 ResourceWithMetadata (org.alfresco.rest.framework.core.ResourceWithMetadata)4 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)4 StaleEntityException (org.alfresco.rest.framework.core.exceptions.StaleEntityException)4 ContentData (org.alfresco.service.cmr.repository.ContentData)4 IntegrityException (org.alfresco.repo.node.integrity.IntegrityException)3 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)3 QName (org.alfresco.service.namespace.QName)3 Test (org.junit.Test)3 File (java.io.File)2 InputStream (java.io.InputStream)2 Serializable (java.io.Serializable)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 RenditionDefinition2 (org.alfresco.repo.rendition2.RenditionDefinition2)2