use of org.alfresco.service.cmr.search.SearchParameters.FieldFacet in project alfresco-remote-api by Alfresco.
the class SearchMapper method fromFacetFields.
/**
* SearchParameters from FacetFields object
* @param sp SearchParameters
* @param FacetFields facetFields
*/
public void fromFacetFields(SearchParameters sp, FacetFields facetFields) {
if (facetFields != null) {
ParameterCheck.mandatory("facetFields facets", facetFields.getFacets());
if (facetFields.getFacets() != null && !facetFields.getFacets().isEmpty()) {
for (FacetField facet : facetFields.getFacets()) {
ParameterCheck.mandatoryString("facetFields facet field", facet.getField());
String field = facet.getField();
FieldFacet ff = new FieldFacet(field);
if (facet.getSort() != null && !facet.getSort().isEmpty()) {
try {
ff.setSort(FieldFacetSort.valueOf(facet.getSort()));
} catch (IllegalArgumentException e) {
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { facet.getSort() });
}
}
if (facet.getMethod() != null && !facet.getMethod().isEmpty()) {
try {
ff.setMethod(FieldFacetMethod.valueOf(facet.getMethod()));
} catch (IllegalArgumentException e) {
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { facet.getMethod() });
}
}
ff.setPrefix(facet.getPrefix());
ff.setLabel(facet.getLabel());
ff.setExcludeFilters(facet.getExcludeFilters());
ff.setCountDocsMissingFacetField(facet.getMissing());
ff.setLimitOrNull(facet.getLimit());
ff.setOffset(facet.getOffset());
ff.setMinCount(facet.getMincount());
ff.setEnumMethodCacheMinDF(facet.getFacetEnumCacheMinDf());
sp.addFieldFacet(ff);
}
}
}
}
use of org.alfresco.service.cmr.search.SearchParameters.FieldFacet in project alfresco-remote-api by Alfresco.
the class SearchMapperTests method fromFacetFields.
@Test
public void fromFacetFields() throws Exception {
SearchParameters searchParameters = new SearchParameters();
// Doesn't error
searchMapper.fromFacetFields(searchParameters, null);
try {
searchMapper.fromFacetFields(searchParameters, new FacetFields(null));
fail();
} catch (IllegalArgumentException iae) {
assertTrue(iae.getLocalizedMessage().contains("facetFields facets is a mandatory parameter"));
}
try {
searchMapper.fromFacetFields(searchParameters, new FacetFields(Arrays.asList(new FacetField(null, null, null, null, null, null, null, null, null, null, null))));
fail();
} catch (IllegalArgumentException iae) {
assertTrue(iae.getLocalizedMessage().contains("facetFields facet field is a mandatory parameter"));
}
searchMapper.fromFacetFields(searchParameters, new FacetFields(Arrays.asList(new FacetField("myfield", null, null, null, null, null, null, null, null, null, null))));
assertEquals(1, searchParameters.getFieldFacets().size());
FieldFacet ff = searchParameters.getFieldFacets().get(0);
// Check defaults
// assertEquals(true, ff.getMissing());
assertNull(ff.getLimitOrNull());
assertEquals(0, ff.getOffset());
assertEquals(1, ff.getMinCount());
assertFalse(ff.isCountDocsMissingFacetField());
assertEquals(0, ff.getEnumMethodCacheMinDF());
// assertEquals("{key='myfield'}myfield" ,ff.getField());
searchParameters = new SearchParameters();
searchMapper.fromFacetFields(searchParameters, new FacetFields(Arrays.asList(new FacetField("myfield", "mylabel", "myprefix", null, null, null, null, null, null, null, null))));
ff = searchParameters.getFieldFacets().get(0);
// assertEquals("{key='mylabel'}myfield" ,ff.getField());
assertEquals("myprefix", ff.getPrefix());
try {
searchMapper.fromFacetFields(searchParameters, new FacetFields(Arrays.asList(new FacetField("myfield", null, null, "badsort", null, null, null, null, null, null, null))));
fail();
} catch (InvalidArgumentException iae) {
// Sort is an enum
assertNotNull(iae);
}
try {
searchMapper.fromFacetFields(searchParameters, new FacetFields(Arrays.asList(new FacetField("myfield", null, null, null, "badmethod", null, null, null, null, null, null))));
fail();
} catch (InvalidArgumentException iae) {
// Method is an enum
assertNotNull(iae);
}
searchParameters = new SearchParameters();
searchMapper.fromFacetFields(searchParameters, new FacetFields(Arrays.asList(new FacetField("myfield", null, null, "INDEX", "ENUM", null, null, null, null, null, null))));
ff = searchParameters.getFieldFacets().get(0);
assertEquals("INDEX", ff.getSort().toString());
assertEquals("ENUM", ff.getMethod().toString());
}
Aggregations