diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/dao/QueryField.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/dao/QueryField.java new file mode 100644 index 0000000000..79a937bf29 --- /dev/null +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/dao/QueryField.java @@ -0,0 +1,40 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2017 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.module.org_alfresco_module_rm.util.dao; + +import org.alfresco.api.AlfrescoPublicApi; + +/** + * Interface for representations of fields that queries can be sorted by. + * + * @author Tom Page + * @since 2.6 + */ +@AlfrescoPublicApi +public interface QueryField +{ +} diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/dao/QueryParams.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/dao/QueryParams.java new file mode 100644 index 0000000000..b11b71cea5 --- /dev/null +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/dao/QueryParams.java @@ -0,0 +1,124 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2017 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.module.org_alfresco_module_rm.util.dao; + +import java.util.List; + +import com.google.common.collect.ImmutableList; + +import org.alfresco.api.AlfrescoPublicApi; +import org.alfresco.util.Pair; + +/** + * Options when listing something. + * + * @author Tom Page + * @since 2.6 + */ +@AlfrescoPublicApi +public class QueryParams +{ + /** The ordered list of columns to sort on (and their sort direction). */ + private List> sortProps; + /** The number of items to skip before creating the list. */ + private int skipCount = 0; + /** The total number of items to return (assuming enough are available). */ + private int maxItems = 10; + + /** + * Constructor that takes the sort order. + * + * @param sortProps A list of fields to sort on, and the direction to sort in. + */ + public QueryParams(List> sortProps) + { + setSortProps(sortProps); + } + + /** Sets the skip count required. */ + public QueryParams withSkipCount(final int skipCount) + { + this.skipCount = skipCount; + return this; + } + + /** Sets the max items count required. */ + public QueryParams withMaxItems(final int maxItems) + { + this.maxItems = maxItems; + return this; + } + + /** + * Sets the sort properties required. + * + * @param sortProps A list of pairs of properties and sort directions. + * @return The updated QueryParams object. + */ + public QueryParams withSortProps(List> sortProps) + { + this.setSortProps(sortProps); + return this; + } + + /** + * Sets the sort properties required and validates the list. + * + * @param sortProps A list of pairs of properties and sort directions. + */ + public void setSortProps(List> sortProps) + { + this.sortProps = ImmutableList.copyOf(sortProps); + + //validate the list + for(Pair sortPair : sortProps) + { + if(sortPair == null || sortPair.getFirst() == null || sortPair.getSecond() == null) + { + throw new IllegalArgumentException("Unexpected null or null containing element in list: " + sortProps); + } + } + } + + /** Get the ordered list of columns to sort on (and their sort direction). */ + public List> getSortProps() + { + return this.sortProps; + } + + /** Get the number of items to skip before creating the list. */ + public int getSkipCount() + { + return this.skipCount; + } + + /** Get the total number of items to return (assuming enough are available). */ + public int getMaxItems() + { + return this.maxItems; + } +}