use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException 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.rest.framework.core.exceptions.InvalidArgumentException 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.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class SearchMapper method fromScope.
/**
* SearchParameters from Scope object
* @param Scope scope
* @param sp SearchParameters
* @param searchRequestContext
*/
public void fromScope(SearchParameters sp, Scope scope, SearchRequestContext searchRequestContext) {
if (scope != null) {
List<String> stores = scope.getLocations();
if (stores != null && !stores.isEmpty()) {
// First reset the stores then add them.
sp.getStores().clear();
searchRequestContext.getStores().addAll(stores);
for (String aStore : stores) {
try {
sp.addStore(storeMapper.getStoreRef(aStore));
} catch (AlfrescoRuntimeException are) {
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { aStore });
}
}
if (stores.contains(StoreMapper.HISTORY) && (stores.size() > 1)) {
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { ": scope 'history' can only be used on its own" });
}
}
}
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class SearchMapper method fromFacetQuery.
/**
** SearchParameters from List<FacetQuery>
* @param sp
* @param facetQueries
*/
public void fromFacetQuery(SearchParameters sp, List<FacetQuery> facetQueries) {
if (facetQueries != null && !facetQueries.isEmpty()) {
for (FacetQuery fq : facetQueries) {
ParameterCheck.mandatoryString("facetQuery query", fq.getQuery());
String query = fq.getQuery();
String label = fq.getLabel() != null ? fq.getLabel() : query;
if (query.startsWith("{!afts")) {
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { ": Facet queries should not start with !afts" });
}
query = "{!afts key='" + label + "'}" + query;
sp.addFacetQuery(query);
}
}
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class SearchMapper method fromFacetIntervals.
/**
* Sets the Interval Parameters object on search parameters
*
* It does some valiation then takes any "SETS" at the top level and sets them at every field level.
*
* @param sp SearchParameters
* @param facetIntervals IntervalParameters
*/
public void fromFacetIntervals(SearchParameters sp, IntervalParameters facetIntervals) {
if (facetIntervals != null) {
ParameterCheck.mandatory("facetIntervals intervals", facetIntervals.getIntervals());
Set<IntervalSet> globalSets = facetIntervals.getSets();
validateSets(globalSets, "facetIntervals");
if (facetIntervals.getIntervals() != null && !facetIntervals.getIntervals().isEmpty()) {
List<String> intervalLabels = new ArrayList<>(facetIntervals.getIntervals().size());
for (Interval interval : facetIntervals.getIntervals()) {
ParameterCheck.mandatory("facetIntervals intervals field", interval.getField());
validateSets(interval.getSets(), "facetIntervals intervals " + interval.getField());
if (interval.getSets() != null && globalSets != null) {
interval.getSets().addAll(globalSets);
}
ParameterCheck.mandatoryCollection("facetIntervals intervals sets", interval.getSets());
List<Map.Entry<String, Long>> duplicateSetLabels = interval.getSets().stream().collect(groupingBy(IntervalSet::getLabel, Collectors.counting())).entrySet().stream().filter(e -> e.getValue().intValue() > 1).collect(toList());
if (!duplicateSetLabels.isEmpty()) {
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { ": duplicate set interval label " + duplicateSetLabels.toString() });
}
if (interval.getLabel() != null)
intervalLabels.add(interval.getLabel());
}
List<Map.Entry<String, Long>> duplicateIntervalLabels = intervalLabels.stream().collect(groupingBy(Function.identity(), Collectors.counting())).entrySet().stream().filter(e -> e.getValue().intValue() > 1).collect(toList());
if (!duplicateIntervalLabels.isEmpty()) {
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { ": duplicate interval label " + duplicateIntervalLabels.toString() });
}
}
if (facetIntervals.getSets() != null) {
facetIntervals.getSets().clear();
}
}
sp.setInterval(facetIntervals);
}
Aggregations