use of org.alfresco.rest.api.search.model.SortDef in project alfresco-remote-api by Alfresco.
the class SearchMapper method fromSort.
/**
* SearchParameters from List<SortDef>
* @param sp SearchParameters
* @param sort List<SortDef>
*/
public void fromSort(SearchParameters sp, List<SortDef> sort) {
if (sort != null && !sort.isEmpty()) {
if (LANGUAGE_CMIS_ALFRESCO.equals(sp.getLanguage())) {
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { ": sort {} not allowed with cmis language" });
}
for (SortDef sortDef : sort) {
try {
SortType sortType = SortType.valueOf(sortDef.getType());
String field = sortDef.getField();
sp.addSort(new SortDefinition(sortType, field, sortDef.isAscending()));
} catch (IllegalArgumentException e) {
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { sortDef.getType() });
}
}
}
}
use of org.alfresco.rest.api.search.model.SortDef in project alfresco-remote-api by Alfresco.
the class SearchMapperTests method fromSort.
@Test
public void fromSort() throws Exception {
SearchParameters searchParameters = new SearchParameters();
// Doesn't error
searchMapper.fromSort(searchParameters, null);
try {
searchMapper.fromSort(searchParameters, Arrays.asList(new SortDef("wrongenum", null, false)));
fail();
} catch (InvalidArgumentException iae) {
// wrongenum is illegal
assertNotNull(iae);
}
searchMapper.fromSort(searchParameters, Arrays.asList(new SortDef("FIELD", "my", true), new SortDef("SCORE", null, false), new SortDef("DOCUMENT", null, true)));
assertEquals(3, searchParameters.getSortDefinitions().size());
searchParameters.getSortDefinitions().forEach(sortDefinition -> {
switch(sortDefinition.getSortType()) {
case FIELD:
assertEquals("my", sortDefinition.getField());
assertEquals(true, sortDefinition.isAscending());
break;
case SCORE:
assertNull(sortDefinition.getField());
assertEquals(false, sortDefinition.isAscending());
break;
case DOCUMENT:
assertNull(sortDefinition.getField());
assertEquals(true, sortDefinition.isAscending());
break;
default:
fail("Invalid sortDefinition");
}
});
searchParameters = new SearchParameters();
searchParameters.setLanguage(SearchService.LANGUAGE_CMIS_ALFRESCO);
try {
searchMapper.fromSort(searchParameters, Arrays.asList(new SortDef("FIELD", null, false)));
fail();
} catch (InvalidArgumentException iae) {
// You can't specify SORT when using the CMIS language
assertNotNull(iae);
}
}
Aggregations