Search in sources :

Example 16 with Params

use of org.alfresco.rest.framework.resource.parameters.Params 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)

Example 17 with Params

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

the class RMSiteEntityResourceUnitTest method updateRMSiteRole.

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

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

the class QuickShareLinksImpl method getParamsWithCreatedStatus.

private Parameters getParamsWithCreatedStatus() {
    String filterStatusCreated = "(" + Renditions.PARAM_STATUS + "='" + Rendition.RenditionStatus.CREATED + "')";
    Query whereQuery = getWhereClause(filterStatusCreated);
    Params.RecognizedParams recParams = new Params.RecognizedParams(null, null, null, null, null, null, whereQuery, null, false);
    Parameters params = Params.valueOf(recParams, null, null, null);
    return params;
}
Also used : Parameters(org.alfresco.rest.framework.resource.parameters.Parameters) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) Query(org.alfresco.rest.framework.resource.parameters.where.Query) Params(org.alfresco.rest.framework.resource.parameters.Params)

Example 19 with Params

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

the class SearchApiWebscript method execute.

@Override
public void execute(WebScriptRequest webScriptRequest, WebScriptResponse webScriptResponse) throws IOException {
    try {
        // Turn JSON into a Java object respresentation
        SearchQuery searchQuery = extractJsonContent(webScriptRequest, assistant.getJsonHelper(), SearchQuery.class);
        // Parse the parameters
        Params params = getParams(webScriptRequest, searchQuery.getFields(), searchQuery.getInclude(), searchQuery.getPaging());
        // Make a copy of the request
        SearchRequestContext searchRequestContext = SearchRequestContext.from(searchQuery);
        // Turn the SearchQuery json into the Java SearchParameters object
        SearchParameters searchParams = searchMapper.toSearchParameters(params, searchQuery, searchRequestContext);
        // Call searchService
        ResultSet results = searchService.query(searchParams);
        // Turn solr results into JSON
        CollectionWithPagingInfo<Node> resultJson = resultMapper.toCollectionWithPagingInfo(params, searchRequestContext, searchQuery, results);
        // Post-process the request and pass in params, eg. params.getFilter()
        Object toRender = helper.processAdditionsToTheResponse(null, null, null, params, resultJson);
        // Write response
        setResponse(webScriptResponse, DEFAULT_SUCCESS);
        renderJsonResponse(webScriptResponse, toRender, assistant.getJsonHelper());
    } catch (Exception exception) {
        renderException(exception, webScriptResponse, assistant);
    }
}
Also used : SearchQuery(org.alfresco.rest.api.search.model.SearchQuery) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) Node(org.alfresco.rest.api.model.Node) ResultSet(org.alfresco.service.cmr.search.ResultSet) Params(org.alfresco.rest.framework.resource.parameters.Params) SearchRequestContext(org.alfresco.rest.api.search.context.SearchRequestContext) IOException(java.io.IOException)

Example 20 with Params

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

the class SearchApiWebscript method getParams.

/**
 * Gets the Params object, parameters come from the SearchQuery json not the request
 * @param webScriptRequest
 * @param searchQuery
 * @return Params
 */
protected Params getParams(WebScriptRequest webScriptRequest, List<String> fields, List<String> include, Paging paging) {
    if (paging == null) {
        paging = Paging.DEFAULT;
    }
    BeanPropertiesFilter filter = null;
    if (fields != null && !fields.isEmpty()) {
        List<String> selectList = new ArrayList<>(fields.size());
        selectList.addAll(fields);
        if (include != null && !include.isEmpty()) {
            selectList.addAll(include);
        }
        filter = getFilter("", selectList);
    }
    Params.RecognizedParams recognizedParams = new Params.RecognizedParams(null, paging, filter, null, include, null, null, null, false);
    return Params.valueOf(null, recognizedParams, null, webScriptRequest);
}
Also used : ArrayList(java.util.ArrayList) Params(org.alfresco.rest.framework.resource.parameters.Params) BeanPropertiesFilter(org.alfresco.rest.framework.jacksonextensions.BeanPropertiesFilter)

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