Edits following review of RM-2113 code.

I have changed the SecurityClearanceService query API so that it accepts a single Java object containing all the configurable options for such a query. Sensible default values are set where possible. The query object follows the Builder pattern so it should be easier to use the defaults in a query and still possible to change those defaults ifnecessary.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@103471 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Neil McErlean
2015-05-01 09:50:59 +00:00
parent 41b4817995
commit 966dd52d12
3 changed files with 117 additions and 20 deletions

View File

@@ -41,12 +41,8 @@ public interface SecurityClearanceService
/** /**
* Get users' security clearances. * Get users' security clearances.
* *
* @param userNameFragment A username fragment which will be used to apply a 'starts with' query. * @param queryParams parameters for the query.
* @param sortAscending if @code true} returns data sorted in ascending order by username.
* @param req paging request definition.
* @return security clearances for the specified page of users. * @return security clearances for the specified page of users.
*/ */
PagingResults<SecurityClearance> getUsersSecurityClearance(String userNameFragment, PagingResults<SecurityClearance> getUsersSecurityClearance(UserQueryParams queryParams);
boolean sortAscending,
PagingRequest req);
} }

View File

@@ -18,10 +18,6 @@
*/ */
package org.alfresco.module.org_alfresco_module_rm.classification; 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.ASPECT_SECURITY_CLEARANCE;
import static org.alfresco.module.org_alfresco_module_rm.classification.model.ClassifiedContentModel.PROP_CLEARANCE_LEVEL; 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.repository.NodeRef;
import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.security.PersonService.PersonInfo; import org.alfresco.service.cmr.security.PersonService.PersonInfo;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair; import org.alfresco.util.Pair;
import org.alfresco.util.ParameterCheck;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
/** /**
* @author Neil Mc Erlean * @author Neil Mc Erlean
@@ -53,7 +48,7 @@ public class SecurityClearanceServiceImpl extends ServiceBaseImpl implements Sec
public SecurityClearance getUserSecurityClearance() public SecurityClearance getUserSecurityClearance()
{ {
final String currentUser = authenticationUtil.getFullyAuthenticatedUser(); final String currentUser = authenticationUtil.getFullyAuthenticatedUser();
Objects.requireNonNull(currentUser, "Fully authenticated user is null, which is not allowed."); ParameterCheck.mandatoryString("currentUser", currentUser);
return getUserSecurityClearance(currentUser); return getUserSecurityClearance(currentUser);
} }
@@ -77,14 +72,13 @@ public class SecurityClearanceServiceImpl extends ServiceBaseImpl implements Sec
return new SecurityClearance(personInfo, classificationLevel); return new SecurityClearance(personInfo, classificationLevel);
} }
public PagingResults<SecurityClearance> getUsersSecurityClearance(String userNameFragment, public PagingResults<SecurityClearance> getUsersSecurityClearance(UserQueryParams queryParams)
boolean sortAscending,
PagingRequest req)
{ {
final List<QName> filterProps = asList(PROP_USERNAME, PROP_FIRSTNAME, PROP_LASTNAME); final PagingResults<PersonInfo> p = personService.getPeople(queryParams.getSearchTerm(),
final List<Pair<QName, Boolean>> sortProps = asList(new Pair<>(PROP_USERNAME, sortAscending)); queryParams.getFilterProps(),
queryParams.getSortProps(),
final PagingResults<PersonInfo> p = personService.getPeople(userNameFragment, filterProps, sortProps, req); new PagingRequest(queryParams.getSkipCount(),
queryParams.getMaxItems()));
return new PagingResults<SecurityClearance>() return new PagingResults<SecurityClearance>()
{ {

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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<QName> filterProps = asList(PROP_USERNAME, PROP_FIRSTNAME, PROP_LASTNAME);
private List<Pair<QName, Boolean>> 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<QName, Boolean> firstSortProp, Pair<QName, Boolean>... otherSortProps)
{
this.sortProps = Collections.unmodifiableList(toList(firstSortProp, otherSortProps));
return this;
}
public String getSearchTerm() { return this.searchTerm; }
public List<QName> getFilterProps() { return this.filterProps; }
public List<Pair<QName, Boolean>> 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 <T> List<T> toList(T firstElem, T... otherElems)
{
// At least one element is required.
ParameterCheck.mandatory("firstElem", firstElem);
List<T> elementList = new ArrayList<>();
elementList.add(firstElem);
if (otherElems != null)
{
elementList.addAll(asList(otherElems));
}
return elementList;
}
}