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);
}
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));
}
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());
}
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);
}
}
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);
}
Aggregations