Search in sources :

Example 11 with InvalidArgumentException

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);
            }
        }
    }
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) FieldFacet(org.alfresco.service.cmr.search.SearchParameters.FieldFacet) FacetField(org.alfresco.rest.api.search.model.FacetField)

Example 12 with InvalidArgumentException

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() });
            }
        }
    }
}
Also used : SortType(org.alfresco.service.cmr.search.SearchParameters.SortDefinition.SortType) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) SortDef(org.alfresco.rest.api.search.model.SortDef) SortDefinition(org.alfresco.service.cmr.search.SearchParameters.SortDefinition)

Example 13 with InvalidArgumentException

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" });
            }
        }
    }
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 14 with InvalidArgumentException

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);
        }
    }
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) FacetQuery(org.alfresco.rest.api.search.model.FacetQuery)

Example 15 with InvalidArgumentException

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);
}
Also used : Arrays(java.util.Arrays) FacetQuery(org.alfresco.rest.api.search.model.FacetQuery) Pivot(org.alfresco.rest.api.search.model.Pivot) Paging(org.alfresco.rest.framework.resource.parameters.Paging) PARAM_INCLUDE_PROPERTIES(org.alfresco.rest.api.Nodes.PARAM_INCLUDE_PROPERTIES) RangeParameters(org.alfresco.service.cmr.search.RangeParameters) Template(org.alfresco.rest.api.search.model.Template) IntervalParameters(org.alfresco.service.cmr.search.IntervalParameters) Limits(org.alfresco.rest.api.search.model.Limits) Matcher(java.util.regex.Matcher) Params(org.alfresco.rest.framework.resource.parameters.Params) Locale(java.util.Locale) Map(java.util.Map) LANGUAGE_FTS_ALFRESCO(org.alfresco.service.cmr.search.SearchService.LANGUAGE_FTS_ALFRESCO) Scope(org.alfresco.rest.api.search.model.Scope) PARAM_INCLUDE_PATH(org.alfresco.rest.api.Nodes.PARAM_INCLUDE_PATH) Localization(org.alfresco.rest.api.search.model.Localization) TimeZone(java.util.TimeZone) Set(java.util.Set) FacetFields(org.alfresco.rest.api.search.model.FacetFields) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) IntervalSet(org.alfresco.service.cmr.search.IntervalSet) List(java.util.List) LuceneQueryLanguageSPI(org.alfresco.repo.search.impl.lucene.LuceneQueryLanguageSPI) PARAM_INCLUDE_ALLOWABLEOPERATIONS(org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ALLOWABLEOPERATIONS) Optional(java.util.Optional) Default(org.alfresco.rest.api.search.model.Default) FilterQuery(org.alfresco.rest.api.search.model.FilterQuery) SortDef(org.alfresco.rest.api.search.model.SortDef) LimitBy(org.alfresco.service.cmr.search.LimitBy) PARAM_INCLUDE_ISLINK(org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ISLINK) Interval(org.alfresco.service.cmr.search.Interval) FieldFacet(org.alfresco.service.cmr.search.SearchParameters.FieldFacet) SearchRequestContext(org.alfresco.rest.api.search.context.SearchRequestContext) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) GeneralHighlightParameters(org.alfresco.service.cmr.search.GeneralHighlightParameters) Function(java.util.function.Function) ArrayList(java.util.ArrayList) FieldFacetSort(org.alfresco.service.cmr.search.SearchParameters.FieldFacetSort) PARAM_INCLUDE_ASPECTNAMES(org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ASPECTNAMES) ParameterCheck(org.alfresco.util.ParameterCheck) StatsRequestParameters(org.alfresco.service.cmr.search.StatsRequestParameters) FacetField(org.alfresco.rest.api.search.model.FacetField) LANGUAGE_LUCENE(org.alfresco.service.cmr.search.SearchService.LANGUAGE_LUCENE) SortType(org.alfresco.service.cmr.search.SearchParameters.SortDefinition.SortType) StoreRef(org.alfresco.service.cmr.repository.StoreRef) PARAM_INCLUDE_ASSOCIATION(org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ASSOCIATION) FieldFacetMethod(org.alfresco.service.cmr.search.SearchParameters.FieldFacetMethod) LANGUAGE_CMIS_ALFRESCO(org.alfresco.service.cmr.search.SearchService.LANGUAGE_CMIS_ALFRESCO) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) Operator(org.alfresco.service.cmr.search.SearchParameters.Operator) Query(org.alfresco.rest.api.search.model.Query) Collectors.toList(java.util.stream.Collectors.toList) SearchQuery(org.alfresco.rest.api.search.model.SearchQuery) SortDefinition(org.alfresco.service.cmr.search.SearchParameters.SortDefinition) Spelling(org.alfresco.rest.api.search.model.Spelling) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) IntervalSet(org.alfresco.service.cmr.search.IntervalSet) ArrayList(java.util.ArrayList) Interval(org.alfresco.service.cmr.search.Interval)

Aggregations

InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)124 NodeRef (org.alfresco.service.cmr.repository.NodeRef)36 QName (org.alfresco.service.namespace.QName)36 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)30 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)22 ArrayList (java.util.ArrayList)21 Test (org.junit.Test)20 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)16 Serializable (java.io.Serializable)11 SearchParameters (org.alfresco.service.cmr.search.SearchParameters)11 Paging (org.alfresco.rest.framework.resource.parameters.Paging)10 SortColumn (org.alfresco.rest.framework.resource.parameters.SortColumn)10 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)9 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 Params (org.alfresco.rest.framework.resource.parameters.Params)8 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)8 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)7 Pair (org.alfresco.util.Pair)7 List (java.util.List)6