Search in sources :

Example 11 with SearchParameters

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

the class SearchMapperTests method fromTimezone.

@Test
public void fromTimezone() throws Exception {
    SearchParameters searchParameters = new SearchParameters();
    // Doesn't error
    searchMapper.fromLocalization(searchParameters, null);
    searchMapper.fromLocalization(searchParameters, new Localization("", null));
    try {
        searchMapper.fromLocalization(searchParameters, new Localization("nonsense", null));
        fail();
    } catch (IllegalArgumentException iae) {
        assertTrue(iae.getLocalizedMessage().contains("Invalid timezone"));
    }
    try {
        searchMapper.fromLocalization(searchParameters, new Localization("GMT+25", null));
        fail();
    } catch (IllegalArgumentException iae) {
        assertTrue(iae.getLocalizedMessage().contains("Invalid timezone"));
    }
    searchMapper.fromLocalization(searchParameters, new Localization("America/New_York", null));
    assertEquals("America/New_York", searchParameters.getTimezone());
    searchMapper.fromLocalization(searchParameters, new Localization("America/Denver", null));
    assertEquals("America/Denver", searchParameters.getTimezone());
    searchMapper.fromLocalization(searchParameters, new Localization("America/Los_Angeles", null));
    assertEquals("America/Los_Angeles", searchParameters.getTimezone());
    searchMapper.fromLocalization(searchParameters, new Localization("Europe/Madrid", null));
    assertEquals("Europe/Madrid", searchParameters.getTimezone());
    searchMapper.fromLocalization(searchParameters, new Localization("GMT+1", null));
    assertEquals("GMT+01:00", searchParameters.getTimezone());
    searchMapper.fromLocalization(searchParameters, new Localization("GMT+01:00", null));
    assertEquals("GMT+01:00", searchParameters.getTimezone());
    searchMapper.fromLocalization(searchParameters, new Localization("GMT-9", null));
    assertEquals("GMT-09:00", searchParameters.getTimezone());
    searchMapper.fromLocalization(searchParameters, new Localization("GMT+08:00", null));
    assertEquals("GMT+08:00", searchParameters.getTimezone());
    searchMapper.fromLocalization(searchParameters, new Localization("GMT-12:00", null));
    assertEquals("GMT-12:00", searchParameters.getTimezone());
    try {
        searchMapper.fromLocalization(searchParameters, new Localization("UTC+5", null));
        fail();
    } catch (IllegalArgumentException iae) {
        assertTrue("UTC is not support by java.util.timezone", iae.getLocalizedMessage().contains("Incompatible timezoneId"));
    }
    try {
        searchMapper.fromLocalization(searchParameters, new Localization("UTC+06:00", null));
        fail();
    } catch (IllegalArgumentException iae) {
        assertTrue(iae.getLocalizedMessage().contains("Incompatible timezoneId"));
    }
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) Localization(org.alfresco.rest.api.search.model.Localization) Test(org.junit.Test)

Example 12 with SearchParameters

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

the class SearchMapperTests method fromFilterQuery.

@Test
public void fromFilterQuery() throws Exception {
    SearchParameters searchParameters = new SearchParameters();
    // Doesn't error
    searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("hedgehog", null, null), new FilterQuery("king", null, null)));
    assertEquals(2, searchParameters.getFilterQueries().size());
    assertEquals("hedgehog", searchParameters.getFilterQueries().get(0));
    assertEquals("king", searchParameters.getFilterQueries().get(1));
    searchParameters = new SearchParameters();
    searchParameters.setLanguage(SearchService.LANGUAGE_CMIS_ALFRESCO);
    try {
        searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("hedgehog", null, null)));
        fail();
    } catch (InvalidArgumentException iae) {
        // You can't specify FilterQuery when using the CMIS language
        assertNotNull(iae);
    }
    try {
        searchParameters.setLanguage(SearchService.LANGUAGE_SOLR_ALFRESCO);
        searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery(null, null, null)));
        fail();
    } catch (IllegalArgumentException iae) {
        // You can't specify FilterQuery when using the CMIS language
        assertNotNull(iae);
    }
    searchParameters = new SearchParameters();
    searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("{!afts}description:xyz", Arrays.asList("desc1", "desc2"), null)));
    assertEquals("{!afts tag=desc1,desc2 }description:xyz", searchParameters.getFilterQueries().get(0));
    searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("{!afts}description:xyz", Arrays.asList("desc1"), null)));
    assertEquals("{!afts tag=desc1 }description:xyz", searchParameters.getFilterQueries().get(1));
    searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("description:xyz", Arrays.asList("desc1"), null)));
    assertEquals("{!afts tag=desc1 }description:xyz", searchParameters.getFilterQueries().get(2));
    searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("{!afts} description:xyz", Arrays.asList("desc1"), null)));
    assertEquals("{!afts tag=desc1 } description:xyz", searchParameters.getFilterQueries().get(3));
    searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery(" {!afts cake} description:xyz", Arrays.asList("desc1"), null)));
    assertEquals("{!afts tag=desc1 cake} description:xyz", searchParameters.getFilterQueries().get(4));
    searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("{!afts tag=desc1}description:xyz", Arrays.asList("desc1"), null)));
    assertEquals("{!afts tag=desc1}description:xyz", searchParameters.getFilterQueries().get(5));
    searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("created:2011", Arrays.asList("desc1"), null)));
    assertEquals("{!afts tag=desc1 }created:2011", searchParameters.getFilterQueries().get(6));
    searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("=cm:name:cabbage", Arrays.asList("desc1"), null)));
    assertEquals("{!afts tag=desc1 }=cm:name:cabbage", searchParameters.getFilterQueries().get(7));
    searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("{http://www.alfresco.org/model/content/1.0}title:workflow", null, null)));
    assertEquals("{http://www.alfresco.org/model/content/1.0}title:workflow", searchParameters.getFilterQueries().get(8));
    searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("{http://www.alfresco.org/model/content/1.0}title:workflow", Arrays.asList("desc1"), null)));
    assertEquals("{!afts tag=desc1 }{http://www.alfresco.org/model/content/1.0}title:workflow", searchParameters.getFilterQueries().get(9));
    searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("{!afts} description:xyz", Arrays.asList("desc1", "desc2"), null)));
    assertEquals("{!afts tag=desc1,desc2 }description:xyz", searchParameters.getFilterQueries().get(0));
    searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("{ !afts } description:xyz", Arrays.asList("desc1", "desc2"), null)));
    assertEquals("{!afts tag=desc1,desc2 }description:xyz", searchParameters.getFilterQueries().get(0));
    searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery(null, Arrays.asList("desc1"), Arrays.asList("cm:name:cabbage", "cm:creator:bob"))));
    assertEquals("{!afts tag=desc1 }cm:name:cabbage OR cm:creator:bob", searchParameters.getFilterQueries().get(12));
    searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery(null, null, Arrays.asList("cm:name:cabbage", "cm:creator:bob"))));
    assertEquals("cm:name:cabbage OR cm:creator:bob", searchParameters.getFilterQueries().get(13));
    searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery(null, null, Arrays.asList("cm:name:cabbage"))));
    assertEquals("cm:name:cabbage", searchParameters.getFilterQueries().get(14));
    searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("created:2011", null, Arrays.asList("cm:name:cabbage"))));
    assertEquals("Single query should take precident over multiple queries ORed together.", "created:2011", searchParameters.getFilterQueries().get(15));
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) FilterQuery(org.alfresco.rest.api.search.model.FilterQuery) Test(org.junit.Test)

Example 13 with SearchParameters

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

the class SearchMapperTests method fromHighlight.

@Test
public void fromHighlight() throws Exception {
    SearchParameters searchParameters = new SearchParameters();
    List<FieldHighlightParameters> fields = Arrays.asList(new FieldHighlightParameters("desc", 50, 100, false, "@", "#"), new FieldHighlightParameters("title", 55, 105, true, "*", "¿"));
    GeneralHighlightParameters highlightParameters = new GeneralHighlightParameters(5, 10, false, "{", "}", 20, true, fields);
    searchMapper.fromHighlight(searchParameters, highlightParameters);
    assertEquals(searchParameters.getHighlight(), highlightParameters);
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) FieldHighlightParameters(org.alfresco.service.cmr.search.FieldHighlightParameters) GeneralHighlightParameters(org.alfresco.service.cmr.search.GeneralHighlightParameters) Test(org.junit.Test)

Example 14 with SearchParameters

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

the class SearchMapperTests method fromFacetQuery.

@Test
public void fromFacetQuery() throws Exception {
    SearchParameters searchParameters = new SearchParameters();
    // Doesn't error
    searchMapper.fromFacetQuery(searchParameters, null);
    searchMapper.fromFacetQuery(searchParameters, Arrays.asList(new FacetQuery("ping", null, null), new FacetQuery("pong", "table", null)));
    assertEquals(2, searchParameters.getFacetQueries().size());
    assertEquals("{!afts key='ping'}ping", searchParameters.getFacetQueries().get(0));
    assertEquals("{!afts key='table'}pong", searchParameters.getFacetQueries().get(1));
    try {
        searchMapper.fromFacetQuery(searchParameters, Arrays.asList(new FacetQuery("ping", null, null), new FacetQuery("{!afts}pang", "tennis", null)));
        fail();
    } catch (InvalidArgumentException iae) {
        // Cannot start with afts
        assertNotNull(iae);
    }
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) FacetQuery(org.alfresco.rest.api.search.model.FacetQuery) Test(org.junit.Test)

Example 15 with SearchParameters

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

the class SearchMapperTests method testMandatory.

@Test(expected = IllegalArgumentException.class)
public void testMandatory() throws Exception {
    SearchRequestContext searchRequest = SearchRequestContext.from(SearchQuery.EMPTY);
    SearchParameters searchParameters = searchMapper.toSearchParameters(ResultMapperTests.EMPTY_PARAMS, SearchQuery.EMPTY, searchRequest);
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) SearchRequestContext(org.alfresco.rest.api.search.context.SearchRequestContext) 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