use of org.alfresco.rest.api.search.context.SearchRequestContext 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);
}
use of org.alfresco.rest.api.search.context.SearchRequestContext in project alfresco-remote-api by Alfresco.
the class SearchMapperTests method facetFormatV2.
@Test
public void facetFormatV2() {
Query query = new Query("afts", "a*", "");
SearchQuery sq = new SearchQuery(query, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, FacetFormat.V2);
SearchRequestContext searchRequestContext = SearchRequestContext.from(sq);
SearchParameters searchParameters = searchMapper.toSearchParameters(ResultMapperTests.EMPTY_PARAMS, sq, searchRequestContext);
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());
}
use of org.alfresco.rest.api.search.context.SearchRequestContext in project alfresco-remote-api by Alfresco.
the class SearchMapperTests method fromPivot.
@Test
public void fromPivot() throws Exception {
SearchParameters searchParameters = new SearchParameters();
searchMapper.fromPivot(searchParameters, null, null, null, null, null);
List<FacetField> facets = new ArrayList<>(1);
facets.add(new FacetField("myfield", null, null, null, null, null, null, null, null, null, null));
facets.add(new FacetField("yourfield", null, null, null, null, null, null, null, null, null, null));
FacetFields ff = new FacetFields(facets);
searchMapper.fromFacetFields(searchParameters, ff);
searchMapper.fromPivot(searchParameters, null, ff, null, null, null);
assertEquals(2, searchParameters.getFieldFacets().size());
assertEquals(0, searchParameters.getPivots().size());
// Handle unknown pivot.
searchParameters = new SearchParameters();
try {
searchMapper.fromPivot(searchParameters, null, ff, null, Arrays.asList(new Pivot(null, null)), null);
fail();
} catch (IllegalArgumentException iae) {
// "bob" doesn't refer to a field facet
assertNotNull(iae);
}
try {
searchMapper.fromPivot(searchParameters, null, ff, null, Arrays.asList(new Pivot("", null)), null);
fail();
} catch (IllegalArgumentException iae) {
assertNotNull(iae);
}
SearchRequestContext searchRequestContext = SearchRequestContext.from(minimalQuery());
// "bob" doesn't refer to a field facet but its the last one so needs to refer to a stat
StatsRequestParameters bobf = new StatsRequestParameters("bob", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
StatsRequestParameters bobL = new StatsRequestParameters("creator", "bob", null, null, null, null, null, null, null, null, null, null, null, null, null, null);
try {
searchMapper.fromPivot(searchParameters, Arrays.asList(bobf), ff, null, Arrays.asList(new Pivot("bob", null)), searchRequestContext);
fail();
} catch (InvalidArgumentException iae) {
// "bob" refers to a stat but it can't be at the root pivot, it needs to be nested
assertNotNull(iae);
}
searchMapper.fromPivot(searchParameters, Arrays.asList(bobf), ff, null, Arrays.asList(new Pivot("yourfield", Arrays.asList(new Pivot("bob", null)))), searchRequestContext);
assertEquals(1, searchParameters.getPivots().size());
try {
searchMapper.fromPivot(searchParameters, null, ff, null, Arrays.asList(new Pivot("ken", null), new Pivot("bob", null)), searchRequestContext);
fail();
} catch (InvalidArgumentException iae) {
// "ken" doesn't refer to a field facet and its not the last one
assertNotNull(iae);
}
searchParameters = new SearchParameters();
searchMapper.fromPivot(searchParameters, null, ff, null, Arrays.asList(new Pivot("myfield", null)), searchRequestContext);
searchMapper.fromFacetFields(searchParameters, ff);
// Moved from a field facet to a pivot
assertEquals(0, searchParameters.getFieldFacets().size());
assertEquals(1, searchParameters.getPivots().size());
assertEquals("myfield", searchParameters.getPivots().get(0).get(0));
searchParameters = new SearchParameters();
try {
searchMapper.fromPivot(searchParameters, Arrays.asList(bobf), ff, null, Arrays.asList(new Pivot("bob", Arrays.asList(new Pivot("hope", null)))), searchRequestContext);
fail();
} catch (InvalidArgumentException iae) {
// "bob" doesn't refer to a field facet or stat
assertNotNull(iae);
}
searchRequestContext = SearchRequestContext.from(minimalQuery());
facets = new ArrayList<>(1);
facets.add(new FacetField("king", null, null, null, null, null, null, null, null, null, null));
ff = new FacetFields(facets);
searchMapper.fromPivot(searchParameters, Arrays.asList(bobf), ff, null, Arrays.asList(new Pivot("king", Arrays.asList(new Pivot("bob", null)))), searchRequestContext);
assertEquals(1, searchParameters.getPivots().size());
assertEquals(2, searchParameters.getPivots().get(0).size());
assertEquals("king", searchParameters.getPivots().get(0).get(0));
assertEquals("bob", searchParameters.getPivots().get(0).get(1));
searchRequestContext = SearchRequestContext.from(minimalQuery());
searchParameters = new SearchParameters();
facets = new ArrayList<>(1);
facets.add(new FacetField("king", null, null, null, null, null, null, null, null, null, null));
facets.add(new FacetField("kong", null, null, null, null, null, null, null, null, null, null));
facets.add(new FacetField("kang", null, null, null, null, null, null, null, null, null, null));
ff = new FacetFields(facets);
searchMapper.fromPivot(searchParameters, Arrays.asList(bobf), ff, null, Arrays.asList(new Pivot("king", Arrays.asList(new Pivot("bob", null))), new Pivot("kong", null)), searchRequestContext);
assertEquals(2, searchParameters.getPivots().size());
assertEquals(2, searchParameters.getPivots().get(0).size());
assertEquals("king", searchParameters.getPivots().get(0).get(0));
assertEquals("bob", searchParameters.getPivots().get(0).get(1));
assertEquals("kong", searchParameters.getPivots().get(1).get(0));
searchRequestContext = SearchRequestContext.from(minimalQuery());
searchParameters = new SearchParameters();
List<RangeParameters> rangeParams = new ArrayList<RangeParameters>();
facets = new ArrayList<>(2);
facets.add(new FacetField("king", null, null, null, null, null, null, null, null, null, null));
facets.add(new FacetField("kong", null, null, null, null, null, null, null, null, null, null));
ff = new FacetFields(facets);
rangeParams.add(new RangeParameters("content.size", "0", "100000", "1000", true, null, null, "hope", null));
searchMapper.fromPivot(searchParameters, Arrays.asList(bobf), ff, rangeParams, Arrays.asList(new Pivot("king", Arrays.asList(new Pivot("bob", null))), new Pivot("kong", Arrays.asList(new Pivot("hope", null)))), searchRequestContext);
assertEquals(2, searchParameters.getPivots().size());
assertEquals(2, searchParameters.getPivots().get(0).size());
assertEquals("king", searchParameters.getPivots().get(0).get(0));
assertEquals("bob", searchParameters.getPivots().get(0).get(1));
assertEquals("kong", searchParameters.getPivots().get(1).get(0));
assertEquals("hope", searchParameters.getPivots().get(1).get(1));
}
use of org.alfresco.rest.api.search.context.SearchRequestContext in project alfresco-remote-api by Alfresco.
the class SearchMapperTests method fromScope.
@Test
public void fromScope() throws Exception {
SearchParameters searchParameters = new SearchParameters();
searchMapper.setDefaults(searchParameters);
SearchRequestContext searchRequestContext = SearchRequestContext.from(minimalQuery());
// Doesn't error, has default store
searchMapper.fromScope(searchParameters, null, searchRequestContext);
assertEquals(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, searchParameters.getStores().get(0));
searchMapper.fromScope(searchParameters, new Scope(null), searchRequestContext);
assertEquals(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, searchParameters.getStores().get(0));
try {
searchMapper.fromScope(searchParameters, new Scope(Arrays.asList("nonsense")), searchRequestContext);
fail();
} catch (InvalidArgumentException iae) {
// Must be a valid store ref
assertNotNull(iae);
}
searchMapper.fromScope(searchParameters, new Scope(Arrays.asList(StoreMapper.DELETED, StoreMapper.LIVE_NODES, StoreMapper.VERSIONS)), searchRequestContext);
assertEquals(3, searchParameters.getStores().size());
assertEquals(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE.toString(), searchParameters.getStores().get(0).toString());
assertEquals(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE.toString(), searchParameters.getStores().get(1).toString());
assertEquals(StoreMapper.STORE_REF_VERSION2_SPACESSTORE.toString(), searchParameters.getStores().get(2).toString());
searchMapper.fromScope(searchParameters, new Scope(Arrays.asList(StoreMapper.HISTORY)), searchRequestContext);
assertEquals(1, searchParameters.getStores().size());
assertEquals(StoreMapper.STORE_REF_HISTORY.toString(), searchParameters.getStores().get(0).toString());
try {
searchMapper.fromScope(searchParameters, new Scope(Arrays.asList(StoreMapper.HISTORY, StoreMapper.DELETED)), searchRequestContext);
fail();
} catch (InvalidArgumentException iae) {
// Must be a valid scope with history
assertNotNull(iae);
}
try {
searchMapper.fromScope(searchParameters, new Scope(Arrays.asList(StoreMapper.HISTORY, StoreMapper.LIVE_NODES)), searchRequestContext);
fail();
} catch (InvalidArgumentException iae) {
// Must be a valid scope with history
assertNotNull(iae);
}
try {
searchMapper.fromScope(searchParameters, new Scope(Arrays.asList(StoreMapper.HISTORY, StoreMapper.VERSIONS)), searchRequestContext);
fail();
} catch (InvalidArgumentException iae) {
// Must be a valid scope with history
assertNotNull(iae);
}
}
Aggregations