diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceService.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceService.java index f1797ed7ec..acdc467bb5 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceService.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceService.java @@ -41,12 +41,8 @@ public interface SecurityClearanceService /** * Get users' security clearances. * - * @param userNameFragment A username fragment which will be used to apply a 'starts with' query. - * @param sortAscending if @code true} returns data sorted in ascending order by username. - * @param req paging request definition. + * @param queryParams parameters for the query. * @return security clearances for the specified page of users. */ - PagingResults getUsersSecurityClearance(String userNameFragment, - boolean sortAscending, - PagingRequest req); + PagingResults getUsersSecurityClearance(UserQueryParams queryParams); } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceServiceImpl.java index 530c6255d4..035173df1f 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/SecurityClearanceServiceImpl.java @@ -18,10 +18,6 @@ */ package org.alfresco.module.org_alfresco_module_rm.classification; -import static java.util.Arrays.asList; -import static org.alfresco.model.ContentModel.PROP_FIRSTNAME; -import static org.alfresco.model.ContentModel.PROP_LASTNAME; -import static org.alfresco.model.ContentModel.PROP_USERNAME; import static org.alfresco.module.org_alfresco_module_rm.classification.model.ClassifiedContentModel.ASPECT_SECURITY_CLEARANCE; import static org.alfresco.module.org_alfresco_module_rm.classification.model.ClassifiedContentModel.PROP_CLEARANCE_LEVEL; @@ -31,12 +27,11 @@ import org.alfresco.query.PagingResults; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.security.PersonService.PersonInfo; -import org.alfresco.service.namespace.QName; import org.alfresco.util.Pair; +import org.alfresco.util.ParameterCheck; import java.util.ArrayList; import java.util.List; -import java.util.Objects; /** * @author Neil Mc Erlean @@ -53,7 +48,7 @@ public class SecurityClearanceServiceImpl extends ServiceBaseImpl implements Sec public SecurityClearance getUserSecurityClearance() { final String currentUser = authenticationUtil.getFullyAuthenticatedUser(); - Objects.requireNonNull(currentUser, "Fully authenticated user is null, which is not allowed."); + ParameterCheck.mandatoryString("currentUser", currentUser); return getUserSecurityClearance(currentUser); } @@ -77,14 +72,13 @@ public class SecurityClearanceServiceImpl extends ServiceBaseImpl implements Sec return new SecurityClearance(personInfo, classificationLevel); } - public PagingResults getUsersSecurityClearance(String userNameFragment, - boolean sortAscending, - PagingRequest req) + public PagingResults getUsersSecurityClearance(UserQueryParams queryParams) { - final List filterProps = asList(PROP_USERNAME, PROP_FIRSTNAME, PROP_LASTNAME); - final List> sortProps = asList(new Pair<>(PROP_USERNAME, sortAscending)); - - final PagingResults p = personService.getPeople(userNameFragment, filterProps, sortProps, req); + final PagingResults p = personService.getPeople(queryParams.getSearchTerm(), + queryParams.getFilterProps(), + queryParams.getSortProps(), + new PagingRequest(queryParams.getSkipCount(), + queryParams.getMaxItems())); return new PagingResults() { diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/UserQueryParams.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/UserQueryParams.java new file mode 100644 index 0000000000..dc874ad7ec --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/UserQueryParams.java @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2005-2015 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.module.org_alfresco_module_rm.classification; + +import static java.util.Arrays.asList; +import static org.alfresco.model.ContentModel.PROP_FIRSTNAME; +import static org.alfresco.model.ContentModel.PROP_LASTNAME; +import static org.alfresco.model.ContentModel.PROP_USERNAME; + +import org.alfresco.service.namespace.QName; +import org.alfresco.util.Pair; +import org.alfresco.util.ParameterCheck; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Configurable options to be used when querying for users by {@link SecurityClearance}. + * + * @author Neil Mc Erlean + * @since 3.0 + */ +public final class UserQueryParams +{ + // Required parameter. No default value. This is the username fragment. + private final String searchTerm; + + // These configurable parameters have default values. + private List filterProps = asList(PROP_USERNAME, PROP_FIRSTNAME, PROP_LASTNAME); + private List> sortProps = asList(new Pair<>(PROP_USERNAME, true)); + private int skipCount = 0; + private int maxItems = 10; + + public UserQueryParams(final String searchTerm) + { + ParameterCheck.mandatoryString("searchTerm", searchTerm); + this.searchTerm = searchTerm; + } + + /** Sets the skip count required for the query. */ + public UserQueryParams withSkipCount(final int skipCount) + { + this.skipCount = skipCount; + return this; + } + + /** Sets the max items count required for the query. */ + public UserQueryParams withMaxItems(final int maxItems) + { + this.maxItems = maxItems; + return this; + } + + /** Sets the filter properties required for the query. */ + public UserQueryParams withFilterProps(QName firstFilterProp, QName... otherFilterProps) + { + this.filterProps = Collections.unmodifiableList(toList(firstFilterProp, otherFilterProps)); + return this; + } + + /** Sets the sort properties required for the query. */ + public UserQueryParams withSortProps(Pair firstSortProp, Pair... otherSortProps) + { + this.sortProps = Collections.unmodifiableList(toList(firstSortProp, otherSortProps)); + return this; + } + + public String getSearchTerm() { return this.searchTerm; } + public List getFilterProps() { return this.filterProps; } + public List> getSortProps() { return this.sortProps; } + public int getSkipCount() { return this.skipCount; } + public int getMaxItems() { return this.maxItems; } + + /** Helper method to turn a varargs into a List, ensuring at least one element is present. */ + private List toList(T firstElem, T... otherElems) + { + // At least one element is required. + ParameterCheck.mandatory("firstElem", firstElem); + + List elementList = new ArrayList<>(); + elementList.add(firstElem); + + if (otherElems != null) + { + elementList.addAll(asList(otherElems)); + } + + return elementList; + } +}