Search in sources :

Example 41 with SearchParameters

use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.

the class SearchMapperTests method toSearchParameters.

@Test
public void toSearchParameters() throws Exception {
    SearchRequestContext searchRequest = SearchRequestContext.from(minimalQuery());
    SearchParameters searchParameters = searchMapper.toSearchParameters(ResultMapperTests.EMPTY_PARAMS, minimalQuery(), searchRequest);
    assertNotNull(searchParameters);
    // Test defaults
    assertEquals("There should be only 1 default store", 1, searchParameters.getStores().size());
    assertEquals("workspaces store is the default", StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, searchParameters.getStores().get(0));
    assertEquals(LimitBy.FINAL_SIZE, searchParameters.getLimitBy());
    assertEquals(100, searchParameters.getLimit());
    searchParameters = searchMapper.toSearchParameters(ResultMapperTests.EMPTY_PARAMS, helper.searchQueryFromJson(), searchRequest);
    assertNotNull(searchParameters);
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) SearchRequestContext(org.alfresco.rest.api.search.context.SearchRequestContext) Test(org.junit.Test)

Example 42 with SearchParameters

use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.

the class SearchMapperTests method fromPaging.

@Test
public void fromPaging() throws Exception {
    SearchParameters searchParameters = new SearchParameters();
    // Doesn't error
    searchMapper.fromPaging(searchParameters, null);
    Paging paging = Paging.DEFAULT;
    searchMapper.fromPaging(searchParameters, paging);
    assertEquals(searchParameters.getLimit(), paging.getMaxItems());
    assertEquals(searchParameters.getSkipCount(), paging.getSkipCount());
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) Paging(org.alfresco.rest.framework.resource.parameters.Paging) Test(org.junit.Test)

Example 43 with SearchParameters

use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.

the class SearchMapperTests method fromSort.

@Test
public void fromSort() throws Exception {
    SearchParameters searchParameters = new SearchParameters();
    // Doesn't error
    searchMapper.fromSort(searchParameters, null);
    try {
        searchMapper.fromSort(searchParameters, Arrays.asList(new SortDef("wrongenum", null, false)));
        fail();
    } catch (InvalidArgumentException iae) {
        // wrongenum is illegal
        assertNotNull(iae);
    }
    searchMapper.fromSort(searchParameters, Arrays.asList(new SortDef("FIELD", "my", true), new SortDef("SCORE", null, false), new SortDef("DOCUMENT", null, true)));
    assertEquals(3, searchParameters.getSortDefinitions().size());
    searchParameters.getSortDefinitions().forEach(sortDefinition -> {
        switch(sortDefinition.getSortType()) {
            case FIELD:
                assertEquals("my", sortDefinition.getField());
                assertEquals(true, sortDefinition.isAscending());
                break;
            case SCORE:
                assertNull(sortDefinition.getField());
                assertEquals(false, sortDefinition.isAscending());
                break;
            case DOCUMENT:
                assertNull(sortDefinition.getField());
                assertEquals(true, sortDefinition.isAscending());
                break;
            default:
                fail("Invalid sortDefinition");
        }
    });
    searchParameters = new SearchParameters();
    searchParameters.setLanguage(SearchService.LANGUAGE_CMIS_ALFRESCO);
    try {
        searchMapper.fromSort(searchParameters, Arrays.asList(new SortDef("FIELD", null, false)));
        fail();
    } catch (InvalidArgumentException iae) {
        // You can't specify SORT when using the CMIS language
        assertNotNull(iae);
    }
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) SortDef(org.alfresco.rest.api.search.model.SortDef) Test(org.junit.Test)

Example 44 with SearchParameters

use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.

the class SearchMapperTests method fromDefaults.

@Test
public void fromDefaults() throws Exception {
    SearchParameters searchParameters = new SearchParameters();
    // Doesn't error
    searchMapper.fromDefault(searchParameters, null);
    searchMapper.fromDefault(searchParameters, new Default(null, null, null, null, null));
    searchMapper.fromDefault(searchParameters, new Default(null, "AND", null, null, null));
    assertEquals("AND", searchParameters.getDefaultFTSOperator().toString());
    searchMapper.fromDefault(searchParameters, new Default(null, null, "or", null, null));
    assertEquals("OR", searchParameters.getDefaultFTSFieldOperator().toString());
    try {
        searchMapper.fromDefault(searchParameters, new Default(null, null, "ELSE", null, null));
        fail();
    } catch (IllegalArgumentException iae) {
        // ELSE is illegal
        assertNotNull(iae);
    }
    searchMapper.fromDefault(searchParameters, new Default(null, null, null, "nspa", "dfn"));
    assertEquals("nspa", searchParameters.getNamespace());
    assertEquals("dfn", searchParameters.getDefaultFieldName());
    assertEquals(0, searchParameters.getTextAttributes().size());
    searchMapper.fromDefault(searchParameters, new Default(Arrays.asList("sausage", "mash"), null, null, null, null));
    assertEquals(2, searchParameters.getTextAttributes().size());
    assertTrue(searchParameters.getTextAttributes().contains("sausage"));
    assertTrue(searchParameters.getTextAttributes().contains("mash"));
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) Default(org.alfresco.rest.api.search.model.Default) Test(org.junit.Test)

Example 45 with SearchParameters

use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.

the class SearchMapperTests method fromLimits.

@Test
public void fromLimits() throws Exception {
    SearchParameters searchParameters = new SearchParameters();
    searchMapper.setDefaults(searchParameters);
    // Doesn't error
    searchMapper.fromLimits(searchParameters, null);
    assertEquals(500, searchParameters.getLimit());
    assertEquals(LimitBy.UNLIMITED, searchParameters.getLimitBy());
    searchMapper.fromLimits(searchParameters, new Limits(null, null));
    assertEquals(LimitBy.UNLIMITED, searchParameters.getLimitBy());
    assertEquals(500, searchParameters.getLimit());
    searchMapper.fromLimits(searchParameters, new Limits(null, 34));
    assertEquals(LimitBy.NUMBER_OF_PERMISSION_EVALUATIONS, searchParameters.getLimitBy());
    assertEquals(34, searchParameters.getMaxPermissionChecks());
    assertEquals(-1, searchParameters.getLimit());
    assertEquals(-1, searchParameters.getMaxPermissionCheckTimeMillis());
    searchParameters = new SearchParameters();
    searchMapper.setDefaults(searchParameters);
    searchMapper.fromLimits(searchParameters, new Limits(1000, null));
    assertEquals(LimitBy.NUMBER_OF_PERMISSION_EVALUATIONS, searchParameters.getLimitBy());
    assertEquals(1000, searchParameters.getMaxPermissionCheckTimeMillis());
    assertEquals(-1, searchParameters.getLimit());
    assertEquals(-1, searchParameters.getMaxPermissionChecks());
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) Limits(org.alfresco.rest.api.search.model.Limits) Test(org.junit.Test)

Aggregations

SearchParameters (org.alfresco.service.cmr.search.SearchParameters)56 Test (org.junit.Test)28 ResultSet (org.alfresco.service.cmr.search.ResultSet)20 NodeRef (org.alfresco.service.cmr.repository.NodeRef)19 ArrayList (java.util.ArrayList)15 SearchRequestContext (org.alfresco.rest.api.search.context.SearchRequestContext)11 IOException (java.io.IOException)10 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)10 HashMap (java.util.HashMap)8 SearchQuery (org.alfresco.rest.api.search.model.SearchQuery)8 JSONObject (org.json.JSONObject)8 List (java.util.List)7 QName (org.alfresco.service.namespace.QName)7 JSONTokener (org.json.JSONTokener)7 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)6 SearchSQLQuery (org.alfresco.rest.api.search.model.SearchSQLQuery)6 Params (org.alfresco.rest.framework.resource.parameters.Params)6 StoreRef (org.alfresco.service.cmr.repository.StoreRef)6 GeneralHighlightParameters (org.alfresco.service.cmr.search.GeneralHighlightParameters)6 JSONArray (org.json.JSONArray)6