Search in sources :

Example 6 with Params

use of org.alfresco.rest.framework.resource.parameters.Params in project alfresco-remote-api by Alfresco.

the class SearchApiWebscriptTests method testPaging.

@Test
public void testPaging() throws Exception {
    Params params = webscript.getParams(null, null, null, null);
    // Defaults
    assertNotNull(params.getPaging());
    assertEquals(Paging.DEFAULT_MAX_ITEMS, params.getPaging().getMaxItems());
    assertEquals(Paging.DEFAULT_SKIP_COUNT, params.getPaging().getSkipCount());
    params = webscript.getParams(null, null, null, Paging.valueOf(4, 20));
    assertEquals(20, params.getPaging().getMaxItems());
    assertEquals(4, params.getPaging().getSkipCount());
}
Also used : Params(org.alfresco.rest.framework.resource.parameters.Params) Test(org.junit.Test)

Example 7 with Params

use of org.alfresco.rest.framework.resource.parameters.Params in project alfresco-remote-api by Alfresco.

the class SearchApiWebscriptTests method testInclude.

@Test
public void testInclude() throws Exception {
    Params params = webscript.getParams(null, null, null, null);
    // Defaults
    assertNotNull(params.getInclude());
    assertEquals(0, params.getInclude().size());
    params = webscript.getParams(null, null, Arrays.asList("name", "size"), null);
    assertNotNull(params.getInclude());
    assertEquals(2, params.getInclude().size());
}
Also used : Params(org.alfresco.rest.framework.resource.parameters.Params) Test(org.junit.Test)

Example 8 with Params

use of org.alfresco.rest.framework.resource.parameters.Params in project alfresco-remote-api by Alfresco.

the class SearchApiWebscriptTests method testFilter.

@Test
public void testFilter() throws Exception {
    Params params = webscript.getParams(null, null, null, null);
    // Defaults
    assertNotNull(params.getFilter());
    params = webscript.getParams(null, null, Arrays.asList("name", "size"), null);
    assertTrue("This isn't used until include is also specfied", params.getFilter().isAllowed("name"));
    assertTrue("Anything is allowed if include hasn't been specfied", params.getFilter().isAllowed("horse"));
    params = webscript.getParams(null, Arrays.asList("cat", "dog"), null, null);
    assertTrue(params.getFilter().isAllowed("cat"));
    assertTrue(params.getFilter().isAllowed("dog"));
    assertFalse(params.getFilter().isAllowed("horse"));
    params = webscript.getParams(null, Arrays.asList("cat", "dog"), Arrays.asList("name", "size"), null);
    assertTrue(params.getFilter().isAllowed("cat"));
    assertFalse(params.getFilter().isAllowed("horse"));
    assertTrue("name and size should be automatically added to the filter list", params.getFilter().isAllowed("name"));
    assertTrue("name and size should be automatically added to the filter list", params.getFilter().isAllowed("size"));
}
Also used : Params(org.alfresco.rest.framework.resource.parameters.Params) Test(org.junit.Test)

Example 9 with Params

use of org.alfresco.rest.framework.resource.parameters.Params in project alfresco-remote-api by Alfresco.

the class ResourceWebScriptHelper method executeResource.

/**
 * Executes a single related Resource.  The results are added to list of embedded results used by
 * the ExecutionResult object.
 *
 * @param api Api
 * @param params Params
 * @param uniqueEntityId String
 * @param resourceKey String
 * @param resource ResourceWithMetadata
 * @return Object
 */
private Object executeResource(final Api api, Params params, final String uniqueEntityId, final String resourceKey, final ResourceWithMetadata resource) {
    try {
        BeanPropertiesFilter paramFilter = null;
        final Object[] resultOfExecution = new Object[1];
        Map<String, BeanPropertiesFilter> filters = params.getRelationsFilter();
        if (filters != null) {
            paramFilter = filters.get(resourceKey);
        }
        final Params executionParams = Params.valueOf(paramFilter, uniqueEntityId, params.getRequest());
        final WithResponse callBack = new WithResponse(Status.STATUS_OK, ResponseWriter.DEFAULT_JSON_CONTENT, ResponseWriter.CACHE_NEVER);
        // Read only because this only occurs for GET requests
        Object result = executor.executeAction(resource, executionParams, callBack);
        return processAdditionsToTheResponse(null, api, null, executionParams, result);
    } catch (NotFoundException e) {
        // ignore, cannot access the object so don't embed it
        if (logger.isDebugEnabled()) {
            logger.debug("Ignored error, cannot access the object so can't embed it ", e);
        }
    } catch (PermissionDeniedException e) {
        // ignore, cannot access the object so don't embed it
        if (logger.isDebugEnabled()) {
            logger.debug("Ignored error, cannot access the object so can't embed it ", e);
        }
    } catch (Throwable throwable) {
        logger.warn("Failed to execute a RelatedResource for " + resourceKey + " " + throwable.getMessage());
    }
    // default
    return null;
}
Also used : Params(org.alfresco.rest.framework.resource.parameters.Params) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) BeanPropertiesFilter(org.alfresco.rest.framework.jacksonextensions.BeanPropertiesFilter)

Example 10 with Params

use of org.alfresco.rest.framework.resource.parameters.Params in project records-management by Alfresco.

the class RMSiteEntityResourceUnitTest method deleteNonRMSite.

@Test
public void deleteNonRMSite() throws Exception {
    String siteId = NON_RM_SITE_ID;
    Params parameters = mock(Params.class);
    when(parameters.getParameter(PERMANENT_PARAMETER)).thenReturn(null);
    try {
        rmSiteEntityResource.delete(siteId, parameters);
        fail("Expected ecxeption as siteId was different than rm");
    } catch (InvalidParameterException ex) {
        assertEquals("The Deletion is supported only for siteId = rm.", ex.getMessage());
    }
    verify(mockedRMSites, never()).deleteRMSite(siteId, parameters);
}
Also used : InvalidParameterException(java.security.InvalidParameterException) Params(org.alfresco.rest.framework.resource.parameters.Params) BaseUnitTest(org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest) Test(org.junit.Test)

Aggregations

Params (org.alfresco.rest.framework.resource.parameters.Params)30 Test (org.junit.Test)23 BaseUnitTest (org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)13 HashMap (java.util.HashMap)8 Parameters (org.alfresco.rest.framework.resource.parameters.Parameters)8 RMSite (org.alfresco.rm.rest.api.model.RMSite)8 SiteUpdate (org.alfresco.rest.api.model.SiteUpdate)7 WebScriptRequest (org.springframework.extensions.webscripts.WebScriptRequest)7 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)6 Match (org.springframework.extensions.webscripts.Match)6 StringReader (java.io.StringReader)3 InvalidParameterException (java.security.InvalidParameterException)3 List (java.util.List)3 UnsupportedResourceOperationException (org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException)3 Farmer (org.alfresco.rest.framework.tests.api.mocks.Farmer)3 ResourceWebScriptPost (org.alfresco.rest.framework.webscripts.ResourceWebScriptPost)3 Content (org.springframework.extensions.surf.util.Content)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 BeanPropertiesFilter (org.alfresco.rest.framework.jacksonextensions.BeanPropertiesFilter)2