Search in sources :

Example 76 with InvalidArgumentException

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

the class RMSiteEntityResourceUnitTest method updateRMSiteCompliance.

@Test
public void updateRMSiteCompliance() 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.setCompliance(RMSiteCompliance.STANDARD);
    try {
        rmSiteEntityResource.update(siteId, site, parameters);
        fail("Expected ecxeption as rm site compliance cannot be changed.");
    } catch (InvalidArgumentException ex) {
        assertEquals("Site update does not support field: compliance", 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)

Example 77 with InvalidArgumentException

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

the class RMSiteEntityResourceUnitTest method updateRMSiteId.

@Test
public void updateRMSiteId() 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.setId("newSiteID");
    try {
        rmSiteEntityResource.update(siteId, site, parameters);
        fail("Expected ecxeption as rm site id cannot be changed.");
    } catch (InvalidArgumentException ex) {
        assertEquals("Site update does not support field: id", 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)

Example 78 with InvalidArgumentException

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

the class RMSiteEntityResourceUnitTest method updateRMSiteVisibility.

@Test
public void updateRMSiteVisibility() 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.setVisibility(SiteVisibility.PRIVATE);
    try {
        rmSiteEntityResource.update(siteId, site, parameters);
        fail("Expected ecxeption as rm site visibility cannot be changed.");
    } catch (InvalidArgumentException ex) {
        assertEquals("Site update does not support field: visibility", 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)

Example 79 with InvalidArgumentException

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

the class RecognizedParamsExtractor method getPaging.

/**
 * Gets the default paging object
 * @param skip
 * @param maxItems
 * @return
 */
default Paging getPaging(String skip, String maxItems) {
    int skipped = Paging.DEFAULT_SKIP_COUNT;
    int max = Paging.DEFAULT_MAX_ITEMS;
    try {
        if (skip != null) {
            skipped = Integer.parseInt(skip);
        }
        if (maxItems != null) {
            max = Integer.parseInt(maxItems);
        }
        if (skipped < 0) {
            throw new InvalidArgumentException("Negative values not supported for skipCount.");
        }
        if (max < 1) {
            throw new InvalidArgumentException("Only positive values supported for maxItems.");
        }
    } catch (NumberFormatException error) {
        String errorMsg = "Invalid paging parameters skipCount: " + skip + ", maxItems:" + maxItems;
        if (rpeLogger().isDebugEnabled()) {
            rpeLogger().debug(errorMsg);
        }
        if (skip == null) {
            errorMsg = "Invalid paging parameter maxItems:" + maxItems;
        }
        if (maxItems == null) {
            errorMsg = "Invalid paging parameter skipCount:" + skip;
        }
        throw new InvalidArgumentException(errorMsg);
    }
    return Paging.valueOf(skipped, max);
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)

Example 80 with InvalidArgumentException

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

the class Api method valueOf.

/**
 * Creates an valid instance of the Api object
 * @param apiName a String in lowercase
 * @param apiScope SCOPE
 * @param apiVersion postive integer
 * @return Api
 */
public static Api valueOf(String apiName, String apiScope, String apiVersion) throws InvalidArgumentException {
    SCOPE scope = null;
    int version = 1;
    try {
        if (!StringUtils.isAllLowerCase(apiName))
            throw new InvalidArgumentException("Api name must be lowercase");
        scope = SCOPE.valueOf(apiScope.toUpperCase());
        version = Integer.parseInt(apiVersion);
        if (version < 1)
            throw new InvalidArgumentException("Version must be a positive integer.");
    } catch (Exception error) {
        // Just throw it on.
        if (error instanceof InvalidArgumentException)
            throw (InvalidArgumentException) error;
        logger.debug("Invalid API definition: " + apiName + " " + apiScope + " " + apiVersion);
        throw new InvalidArgumentException("Invalid API definition:" + error.getMessage());
    }
    Api anApi = new Api(apiName, scope, version);
    return ALFRESCO_PUBLIC.equals(anApi) ? ALFRESCO_PUBLIC : anApi;
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)

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