Search in sources :

Example 1 with InvalidArgumentException

use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.

the class GroupsImpl method getGroupsSortProp.

private Pair<String, Boolean> getGroupsSortProp(Parameters parameters) {
    Pair<String, Boolean> sortProp;
    List<SortColumn> sortCols = parameters.getSorting();
    if ((sortCols != null) && (sortCols.size() > 0)) {
        if (sortCols.size() > 1) {
            throw new InvalidArgumentException("Multiple sort fields not allowed.");
        }
        SortColumn sortCol = sortCols.get(0);
        String sortPropName = SORT_PARAMS_TO_NAMES.get(sortCol.column);
        if (sortPropName == null) {
            throw new InvalidArgumentException("Invalid sort field: " + sortCol.column);
        }
        sortProp = new Pair<>(sortPropName, (sortCol.asc ? Boolean.TRUE : Boolean.FALSE));
    } else {
        sortProp = getGroupsSortPropDefault();
    }
    return sortProp;
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) SortColumn(org.alfresco.rest.framework.resource.parameters.SortColumn)

Example 2 with InvalidArgumentException

use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.

the class NodesImpl method requestRenditions.

private void requestRenditions(List<ThumbnailDefinition> thumbnailDefs, Node fileNode) {
    if (thumbnailDefs != null) {
        ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry();
        for (ThumbnailDefinition thumbnailDef : thumbnailDefs) {
            NodeRef sourceNodeRef = fileNode.getNodeRef();
            String mimeType = fileNode.getContent().getMimeType();
            long size = fileNode.getContent().getSizeInBytes();
            // Check if anything is currently available to generate thumbnails for the specified mimeType
            if (!registry.isThumbnailDefinitionAvailable(null, mimeType, size, sourceNodeRef, thumbnailDef)) {
                throw new InvalidArgumentException("Unable to create thumbnail '" + thumbnailDef.getName() + "' for " + mimeType + " as no transformer is currently available.");
            }
            Action action = ThumbnailHelper.createCreateThumbnailAction(thumbnailDef, sr);
            // Queue async creation of thumbnail
            actionService.executeAction(action, sourceNodeRef, true, true);
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ThumbnailDefinition(org.alfresco.repo.thumbnail.ThumbnailDefinition) Action(org.alfresco.service.cmr.action.Action) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ThumbnailRegistry(org.alfresco.repo.thumbnail.ThumbnailRegistry)

Example 3 with InvalidArgumentException

use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.

the class RenditionsImpl method getRenditionByName.

protected NodeRef getRenditionByName(NodeRef nodeRef, String renditionId, Parameters parameters) {
    if (nodeRef == null) {
        return null;
    }
    if (StringUtils.isEmpty(renditionId)) {
        throw new InvalidArgumentException("renditionId can't be null or empty.");
    }
    // Thumbnails have a cm: prefix.
    QName renditionQName = QName.resolveToQName(namespaceService, renditionId);
    ChildAssociationRef nodeRefRendition = renditionService.getRenditionByName(nodeRef, renditionQName);
    if (nodeRefRendition == null) {
        return null;
    }
    return tenantService.getName(nodeRef, nodeRefRendition.getChildRef());
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 4 with InvalidArgumentException

use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project records-management by Alfresco.

the class RMSiteEntityResourceUnitTest method deleteRMSiteWithPermanentParam.

@Test
public void deleteRMSiteWithPermanentParam() throws Exception {
    String siteId = RM_SITE_ID;
    Params parameters = mock(Params.class);
    when(parameters.getParameter(PERMANENT_PARAMETER)).thenReturn(Boolean.toString(true));
    try {
        rmSiteEntityResource.delete(siteId, parameters);
        fail("Expected ecxeption as parameter permanent was present in the request.");
    } catch (InvalidArgumentException ex) {
        assertEquals("DELETE does not support parameter: permanent", ex.getMsgId());
    }
    verify(mockedRMSites, never()).deleteSite(siteId, parameters);
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) Params(org.alfresco.rest.framework.resource.parameters.Params) BaseUnitTest(org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest) Test(org.junit.Test)

Example 5 with InvalidArgumentException

use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project records-management by Alfresco.

the class RMSiteEntityResourceUnitTest method updateRMSiteGuid.

@Test
public void updateRMSiteGuid() throws Exception {
    String siteId = RM_SITE_ID;
    Params parameters = mock(Params.class);
    RMSite site = new RMSite();
    site.setTitle("New Title");
    site.setDescription("New Description");
    site.setGuid("newGUID");
    try {
        rmSiteEntityResource.update(siteId, site, parameters);
        fail("Expected ecxeption as rm site guid cannot be changed.");
    } catch (InvalidArgumentException ex) {
        assertEquals("Site update does not support field: guid", ex.getMsgId());
    }
    verify(mockedRMSites, never()).updateRMSite(any(String.class), any(SiteUpdate.class), any(Parameters.class));
}
Also used : RMSite(org.alfresco.rm.rest.api.model.RMSite) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) Parameters(org.alfresco.rest.framework.resource.parameters.Parameters) SiteUpdate(org.alfresco.rest.api.model.SiteUpdate) Params(org.alfresco.rest.framework.resource.parameters.Params) BaseUnitTest(org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest) Test(org.junit.Test)

Aggregations

InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)132 NodeRef (org.alfresco.service.cmr.repository.NodeRef)39 QName (org.alfresco.service.namespace.QName)37 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)31 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)24 ArrayList (java.util.ArrayList)22 Test (org.junit.Test)20 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)17 Serializable (java.io.Serializable)12 SortColumn (org.alfresco.rest.framework.resource.parameters.SortColumn)12 SearchParameters (org.alfresco.service.cmr.search.SearchParameters)11 Paging (org.alfresco.rest.framework.resource.parameters.Paging)10 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)9 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)9 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)9 Pair (org.alfresco.util.Pair)9 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 Params (org.alfresco.rest.framework.resource.parameters.Params)8 RelationshipResourceNotFoundException (org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException)7