Search in sources :

Example 61 with InvalidArgumentException

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

the class WebScriptOptionsMetaData method execute.

@Override
public void execute(final Api api, WebScriptRequest req, WebScriptResponse res) throws IOException {
    final Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    ResourceDictionary resourceDic = lookupDictionary.getDictionary();
    Map<String, ResourceWithMetadata> apiResources = resourceDic.getAllResources().get(api);
    if (apiResources == null) {
        throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_INVALID_API);
    }
    String collectionName = templateVars.get(ResourceLocator.COLLECTION_RESOURCE);
    String resourceName = templateVars.get(ResourceLocator.RELATIONSHIP_RESOURCE);
    String resourceKey = ResourceDictionary.resourceKey(collectionName, resourceName);
    if (logger.isDebugEnabled()) {
        logger.debug("Locating resource :" + resourceKey);
    }
    ResourceWithMetadata resource = apiResources.get(resourceKey);
    if (resource == null) {
        // Get entity resource and check if we are referencing a property on it.
        resourceKey = ResourceDictionary.propertyResourceKey(collectionName, resourceName);
        resource = apiResources.get(resourceKey);
    }
    ResourceMetaDataWriter writer = chooseWriter(req);
    writer.writeMetaData(res.getOutputStream(), resource, apiResources);
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ResourceDictionary(org.alfresco.rest.framework.core.ResourceDictionary) ResourceWithMetadata(org.alfresco.rest.framework.core.ResourceWithMetadata) ResourceMetaDataWriter(org.alfresco.rest.framework.metadata.ResourceMetaDataWriter)

Example 62 with InvalidArgumentException

use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException 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 63 with InvalidArgumentException

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

the class SearchMapperTests method fromQuery.

@Test
public void fromQuery() throws Exception {
    SearchParameters searchParameters = new SearchParameters();
    try {
        searchMapper.fromQuery(searchParameters, new Query(null, null, null));
        fail();
    } catch (IllegalArgumentException iae) {
        assertTrue(iae.getLocalizedMessage().contains("query is a mandatory parameter"));
    }
    Query q = new Query(null, "hello", null);
    searchMapper.fromQuery(searchParameters, q);
    // Default
    assertEquals(LANGUAGE_FTS_ALFRESCO, searchParameters.getLanguage());
    q = new Query("world", "hello", null);
    try {
        searchMapper.fromQuery(searchParameters, q);
        fail();
    } catch (InvalidArgumentException iae) {
        assertNotNull(iae);
    // world is not a valid language type
    }
    q = new Query("afts", "hello", null);
    searchMapper.fromQuery(searchParameters, q);
    assertEquals(LANGUAGE_FTS_ALFRESCO, searchParameters.getLanguage());
    q = new Query("cMiS", "hello", null);
    searchMapper.fromQuery(searchParameters, q);
    assertEquals(LANGUAGE_CMIS_ALFRESCO, searchParameters.getLanguage());
    q = new Query("LuCENE", "hello", null);
    searchMapper.fromQuery(searchParameters, q);
    assertEquals(LANGUAGE_LUCENE, searchParameters.getLanguage());
    assertEquals("hello", searchParameters.getQuery());
    q = new Query("LuCENE", "hello", "Heload");
    searchMapper.fromQuery(searchParameters, q);
    assertEquals("Heload", searchParameters.getSearchTerm());
}
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) FilterQuery(org.alfresco.rest.api.search.model.FilterQuery) Query(org.alfresco.rest.api.search.model.Query) SearchQuery(org.alfresco.rest.api.search.model.SearchQuery) Test(org.junit.Test)

Example 64 with InvalidArgumentException

use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException 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 65 with InvalidArgumentException

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

the class SearchMapperTests method fromInterval.

@Test
public void fromInterval() throws Exception {
    SearchParameters searchParameters = new SearchParameters();
    IntervalParameters intervalParameters = new IntervalParameters(null, null);
    try {
        searchMapper.fromFacetIntervals(searchParameters, intervalParameters);
        fail();
    } catch (IllegalArgumentException iae) {
        // intervals is required
        assertNotNull(iae);
    }
    Set<IntervalSet> intervalSets = new HashSet(Arrays.asList(new IntervalSet(null, "1", null, null, null)));
    List<Interval> intervalList = Arrays.asList(new Interval(null, "bob", null));
    intervalParameters = new IntervalParameters(intervalSets, intervalList);
    try {
        searchMapper.fromFacetIntervals(searchParameters, intervalParameters);
        fail();
    } catch (IllegalArgumentException iae) {
        // facetIntervals intervals field is required
        assertNotNull(iae);
    }
    intervalList = Arrays.asList(new Interval("aFileld", "bob", null));
    intervalParameters = new IntervalParameters(intervalSets, intervalList);
    try {
        searchMapper.fromFacetIntervals(searchParameters, intervalParameters);
        fail();
    } catch (IllegalArgumentException iae) {
        // set start is required
        assertNotNull(iae);
    }
    intervalSets = new HashSet(Arrays.asList(new IntervalSet("1", null, null, null, true)));
    intervalParameters = new IntervalParameters(intervalSets, intervalList);
    try {
        searchMapper.fromFacetIntervals(searchParameters, intervalParameters);
        fail();
    } catch (IllegalArgumentException iae) {
        // set end is required
        assertNotNull(iae);
    }
    intervalSets = new HashSet<>();
    intervalSets.add(new IntervalSet("0", "3", "bob", null, null));
    intervalSets.add(new IntervalSet("30", "50", "bill", true, true));
    Set<IntervalSet> anIntervalSet = new HashSet<>();
    anIntervalSet.add(new IntervalSet("1", "10", "bert", false, false));
    intervalList = Arrays.asList(new Interval("cm:price", "Price", null), new Interval("cm:price", "Price", anIntervalSet));
    intervalParameters = new IntervalParameters(intervalSets, intervalList);
    try {
        searchMapper.fromFacetIntervals(searchParameters, intervalParameters);
        fail();
    } catch (InvalidArgumentException iae) {
        // duplicate labels
        assertNotNull(iae);
    }
    intervalList = Arrays.asList(new Interval("cm:price", "Prices", null), new Interval("cm:price", "Pricey", anIntervalSet));
    intervalParameters = new IntervalParameters(intervalSets, intervalList);
    searchMapper.fromFacetIntervals(searchParameters, intervalParameters);
    assertEquals(searchParameters.getInterval(), intervalParameters);
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) IntervalParameters(org.alfresco.service.cmr.search.IntervalParameters) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) IntervalSet(org.alfresco.service.cmr.search.IntervalSet) HashSet(java.util.HashSet) Interval(org.alfresco.service.cmr.search.Interval) Test(org.junit.Test)

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