mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Implementation of new tests as part of RM-2241.
Test to ensure the Unclassified abbreviation ('U') is rejected when duplicated by end user configuration. Test to ensure any duplicate abbreviations are rejected. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@106134 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
package org.alfresco.module.org_alfresco_module_rm.classification;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.alfresco.module.org_alfresco_module_rm.util.RMCollectionUtils.getDuplicateElements;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.IllegalAbbreviationChars;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.IllegalConfiguration;
|
||||
@@ -60,6 +61,10 @@ public class ClassificationLevelValidation
|
||||
{
|
||||
throw new MissingConfiguration("Classification level ID is missing.");
|
||||
}
|
||||
else if (levelId.equals(ClassificationLevelManager.UNCLASSIFIED_ID))
|
||||
{
|
||||
throw new IllegalConfiguration("Unclassified ID abbreviation is reserved for system use.");
|
||||
}
|
||||
else if (levelId.length() > ABBREVIATION_LENGTH_LIMIT)
|
||||
{
|
||||
throw new IllegalConfiguration("Illegal classification level abbreviation. Length " +
|
||||
@@ -86,6 +91,12 @@ public class ClassificationLevelValidation
|
||||
throw new MissingConfiguration("Classification level configuration is missing.");
|
||||
}
|
||||
|
||||
final List<ClassificationLevel> duplicateLevels = getDuplicateElements(levels);
|
||||
if (!duplicateLevels.isEmpty())
|
||||
{
|
||||
throw new IllegalConfiguration("Duplicate ID abbreviations are not allowed: " + duplicateLevels);
|
||||
}
|
||||
|
||||
for (ClassificationLevel level : levels)
|
||||
{
|
||||
validateLevel(level);
|
||||
|
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2014 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.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Various common helper methods for Collections.
|
||||
*
|
||||
* @author Neil Mc Erlean
|
||||
* @since 3.0
|
||||
*/
|
||||
// This class should all be moved to core Alfresco whenever possible and reused from there.
|
||||
public final class RMCollectionUtils
|
||||
{
|
||||
private RMCollectionUtils() { /* Intentionally empty. */}
|
||||
|
||||
/**
|
||||
* Gets the list of duplicate elements contained within the specified list, if any.
|
||||
* @param l the list in which to find duplicates.
|
||||
* @param <T> the element type of the list.
|
||||
* @return a list of duplicate elements. If there are no duplicates, returns an empty list.
|
||||
*/
|
||||
public static <T> List<T> getDuplicateElements(List<T> l)
|
||||
{
|
||||
final Set<T> uniqueElems = new HashSet<>();
|
||||
final List<T> duplicateElems = new ArrayList<>();
|
||||
|
||||
for (T elem: l)
|
||||
{
|
||||
if (uniqueElems.contains(elem))
|
||||
{
|
||||
if (!duplicateElems.contains(elem)) duplicateElems.add(elem);
|
||||
}
|
||||
else
|
||||
{
|
||||
uniqueElems.add(elem);
|
||||
}
|
||||
}
|
||||
return duplicateElems;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user