diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/classified-content-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/classified-content-context.xml
index 74d5728808..55e5947cbc 100644
--- a/rm-server/config/alfresco/module/org_alfresco_module_rm/classified-content-context.xml
+++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/classified-content-context.xml
@@ -81,6 +81,10 @@
+
+
+
+
diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/model/classifiedContentModel.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/model/classifiedContentModel.xml
index 1e48844238..b88d692a67 100644
--- a/rm-server/config/alfresco/module/org_alfresco_module_rm/model/classifiedContentModel.xml
+++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/model/classifiedContentModel.xml
@@ -26,7 +26,7 @@
-
+
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/RMConstraintMessageKeys.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/RMConstraintMessageKeys.java
new file mode 100644
index 0000000000..f5ed6b9e62
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/RMConstraintMessageKeys.java
@@ -0,0 +1,30 @@
+/*
+ * 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.caveat;
+
+/**
+ * A class to hold I18N keys for messages related to constraint validation.
+ *
+ * @author tpage
+ */
+public class RMConstraintMessageKeys
+{
+ public static final String ERR_NON_STRING = "d_dictionary.constraint.string_length.non_string";
+ public static final String ERR_INVALID_VALUE = "d_dictionary.constraint.list_of_values.invalid_value";
+}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/RMListOfValuesConstraint.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/RMListOfValuesConstraint.java
index 356ac485bc..8b2f20ce09 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/RMListOfValuesConstraint.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/RMListOfValuesConstraint.java
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2005-2014 Alfresco Software Limited.
*
* This file is part of Alfresco
@@ -14,239 +14,237 @@
* 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.caveat;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint;
-import org.alfresco.repo.security.authentication.AuthenticationUtil;
-import org.alfresco.service.cmr.dictionary.ConstraintException;
-import org.alfresco.service.cmr.i18n.MessageLookup;
-import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
-import org.alfresco.service.cmr.repository.datatype.TypeConversionException;
-import org.apache.commons.lang.StringUtils;
-import org.springframework.extensions.surf.util.I18NUtil;
-
-/**
- * RM Constraint implementation that ensures the value is one of a constrained
- * list of values. By default, this constraint is case-sensitive.
- *
- * @see #setAllowedValues(List)
- * @see #setCaseSensitive(boolean)
- *
- * @author janv
- */
-public class RMListOfValuesConstraint extends ListOfValuesConstraint
-{
- private static final String ERR_NON_STRING = "d_dictionary.constraint.string_length.non_string";
- private static final String ERR_INVALID_VALUE = "d_dictionary.constraint.list_of_values.invalid_value";
- private static final String LOV_CONSTRAINT_VALUE = "listconstraint";
- private List allowedValues;
- private List allowedValuesUpper;
- // defined match logic used by caveat matching (default = "AND")
- private MatchLogic matchLogic = MatchLogic.AND;
-
- public enum MatchLogic
- {
- // closed marking - all values must match
- AND,
- // open marking - at least one value must match
- OR;
- }
-
- // note: alternative to static init could be to use 'registered' constraint
- private static RMCaveatConfigService caveatConfigService;
-
- public void setCaveatConfigService(RMCaveatConfigService caveatConfigService)
- {
- RMListOfValuesConstraint.caveatConfigService = caveatConfigService;
- }
-
-
- @Override
- public String toString()
- {
- StringBuilder sb = new StringBuilder(80);
- sb.append("RMListOfValuesConstraint")
- .append("[allowedValues=").append(getAllowedValues())
- .append(", caseSensitive=").append(isCaseSensitive())
- .append(", sorted=").append(isCaseSensitive())
- .append(", matchLogic=").append(getMatchLogic())
- .append("]");
- return sb.toString();
- }
-
- public RMListOfValuesConstraint()
- {
- super();
-
- // Set RM list of value constraints to be sorted by default
- sorted = true;
- }
-
- /**
- * Get the allowed values. Note that these are String instances, but may
- * represent non-String values. It is up to the caller to distinguish.
- *
- * @return Returns the values allowed
- */
- @Override
- public List getRawAllowedValues()
- {
- String runAsUser = AuthenticationUtil.getRunAsUser();
- if ((runAsUser != null) && (! runAsUser.equals(AuthenticationUtil.getSystemUserName())) && (caveatConfigService != null))
- {
- // get allowed values for current user
- List allowedForUser = caveatConfigService.getRMAllowedValues(getShortName());
-
- List filteredList = new ArrayList(allowedForUser.size());
- for (String allowed : allowedForUser)
- {
- if (this.allowedValues.contains(allowed))
- {
- filteredList.add(allowed);
- }
- }
-
- return filteredList;
- }
- else
- {
- return this.allowedValues;
- }
- }
-
- public String getDisplayLabel(String constraintAllowableValue, MessageLookup messageLookup)
- {
- if (!this.allowedValues.contains(constraintAllowableValue))
- {
- return null;
- }
-
- String key = LOV_CONSTRAINT_VALUE;
- key += "." + this.getShortName();
- key += "." + constraintAllowableValue;
- key = StringUtils.replace(key, ":", "_");
-
- String message = messageLookup.getMessage(key, I18NUtil.getLocale());
- return message == null ? constraintAllowableValue : message;
- }
-
- private List getAllowedValuesUpper()
- {
- String runAsUser = AuthenticationUtil.getRunAsUser();
- if ((runAsUser != null) && (! runAsUser.equals(AuthenticationUtil.getSystemUserName())) && (caveatConfigService != null))
- {
- // get allowed values for current user
- List allowedForUser = caveatConfigService.getRMAllowedValues(getType());
-
- List filteredList = new ArrayList(allowedForUser.size());
- for (String allowed : allowedForUser)
- {
- if (this.allowedValuesUpper.contains(allowed.toUpperCase()))
- {
- filteredList.add(allowed);
- }
- }
-
- return filteredList;
- }
- else
- {
- return this.allowedValuesUpper;
- }
- }
- /**
- * Set the values that are allowed by the constraint.
- *
- * @param values a list of allowed values
- */
- @SuppressWarnings({ "unchecked", "rawtypes" })
- @Override
- public void setAllowedValues(List allowedValues)
- {
- if (allowedValues == null)
- {
- allowedValues = new ArrayList(0);
- }
- int valueCount = allowedValues.size();
- this.allowedValues = Collections.unmodifiableList(allowedValues);
-
- // make the upper case versions
- this.allowedValuesUpper = new ArrayList(valueCount);
- for (String allowedValue : this.allowedValues)
- {
- allowedValuesUpper.add(allowedValue.toUpperCase());
- }
- }
-
- @Override
- public void initialize()
- {
- checkPropertyNotNull("allowedValues", allowedValues);
- }
-
- @Override
- public Map getParameters()
- {
- Map params = new HashMap(2);
-
- params.put("caseSensitive", isCaseSensitive());
- params.put("allowedValues", getAllowedValues());
- params.put("sorted", isSorted());
- params.put("matchLogic", getMatchLogic());
-
- return params;
- }
-
- public MatchLogic getMatchLogicEnum()
- {
- return matchLogic;
- }
-
- public String getMatchLogic()
- {
- return matchLogic.toString();
- }
-
- public void setMatchLogic(String matchLogicStr)
- {
- this.matchLogic = MatchLogic.valueOf(matchLogicStr);
- }
-
- @Override
- protected void evaluateSingleValue(Object value)
- {
- // convert the value to a String
- String valueStr = null;
- try
- {
- valueStr = DefaultTypeConverter.INSTANCE.convert(String.class, value);
- }
- catch (TypeConversionException e)
- {
- throw new ConstraintException(ERR_NON_STRING, value, e);
- }
- // check that the value is in the set of allowed values
- if (isCaseSensitive())
- {
- if (!getAllowedValues().contains(valueStr))
- {
- throw new ConstraintException(ERR_INVALID_VALUE, value);
- }
- }
- else
- {
- if (!getAllowedValuesUpper().contains(valueStr.toUpperCase()))
- {
- throw new ConstraintException(ERR_INVALID_VALUE, value);
- }
- }
- }
-}
+ * along with Alfresco. If not, see .
+ */
+package org.alfresco.module.org_alfresco_module_rm.caveat;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint;
+import org.alfresco.repo.security.authentication.AuthenticationUtil;
+import org.alfresco.service.cmr.dictionary.ConstraintException;
+import org.alfresco.service.cmr.i18n.MessageLookup;
+import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
+import org.alfresco.service.cmr.repository.datatype.TypeConversionException;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.extensions.surf.util.I18NUtil;
+
+/**
+ * RM Constraint implementation that ensures the value is one of a constrained
+ * list of values. By default, this constraint is case-sensitive.
+ *
+ * @see #setAllowedValues(List)
+ * @see #setCaseSensitive(boolean)
+ *
+ * @author janv
+ */
+public class RMListOfValuesConstraint extends ListOfValuesConstraint
+{
+ private static final String LOV_CONSTRAINT_VALUE = "listconstraint";
+ private List allowedValues;
+ private List allowedValuesUpper;
+ // defined match logic used by caveat matching (default = "AND")
+ private MatchLogic matchLogic = MatchLogic.AND;
+
+ public enum MatchLogic
+ {
+ // closed marking - all values must match
+ AND,
+ // open marking - at least one value must match
+ OR;
+ }
+
+ // note: alternative to static init could be to use 'registered' constraint
+ private static RMCaveatConfigService caveatConfigService;
+
+ public void setCaveatConfigService(RMCaveatConfigService caveatConfigService)
+ {
+ RMListOfValuesConstraint.caveatConfigService = caveatConfigService;
+ }
+
+
+ @Override
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder(80);
+ sb.append("RMListOfValuesConstraint")
+ .append("[allowedValues=").append(getAllowedValues())
+ .append(", caseSensitive=").append(isCaseSensitive())
+ .append(", sorted=").append(isSorted())
+ .append(", matchLogic=").append(getMatchLogic())
+ .append("]");
+ return sb.toString();
+ }
+
+ public RMListOfValuesConstraint()
+ {
+ super();
+
+ // Set RM list of value constraints to be sorted by default
+ sorted = true;
+ }
+
+ /**
+ * Get the allowed values. Note that these are String instances, but may
+ * represent non-String values. It is up to the caller to distinguish.
+ *
+ * @return Returns the values allowed
+ */
+ @Override
+ public List getRawAllowedValues()
+ {
+ String runAsUser = AuthenticationUtil.getRunAsUser();
+ if ((runAsUser != null) && (! runAsUser.equals(AuthenticationUtil.getSystemUserName())) && (caveatConfigService != null))
+ {
+ // get allowed values for current user
+ List allowedForUser = caveatConfigService.getRMAllowedValues(getShortName());
+
+ List filteredList = new ArrayList(allowedForUser.size());
+ for (String allowed : allowedForUser)
+ {
+ if (this.allowedValues.contains(allowed))
+ {
+ filteredList.add(allowed);
+ }
+ }
+
+ return filteredList;
+ }
+ else
+ {
+ return this.allowedValues;
+ }
+ }
+
+ public String getDisplayLabel(String constraintAllowableValue, MessageLookup messageLookup)
+ {
+ if (!this.allowedValues.contains(constraintAllowableValue))
+ {
+ return null;
+ }
+
+ String key = LOV_CONSTRAINT_VALUE;
+ key += "." + this.getShortName();
+ key += "." + constraintAllowableValue;
+ key = StringUtils.replace(key, ":", "_");
+
+ String message = messageLookup.getMessage(key, I18NUtil.getLocale());
+ return message == null ? constraintAllowableValue : message;
+ }
+
+ private List getAllowedValuesUpper()
+ {
+ String runAsUser = AuthenticationUtil.getRunAsUser();
+ if ((runAsUser != null) && (! runAsUser.equals(AuthenticationUtil.getSystemUserName())) && (caveatConfigService != null))
+ {
+ // get allowed values for current user
+ List allowedForUser = caveatConfigService.getRMAllowedValues(getType());
+
+ List filteredList = new ArrayList(allowedForUser.size());
+ for (String allowed : allowedForUser)
+ {
+ if (this.allowedValuesUpper.contains(allowed.toUpperCase()))
+ {
+ filteredList.add(allowed);
+ }
+ }
+
+ return filteredList;
+ }
+ else
+ {
+ return this.allowedValuesUpper;
+ }
+ }
+ /**
+ * Set the values that are allowed by the constraint.
+ *
+ * @param values a list of allowed values
+ */
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Override
+ public void setAllowedValues(List allowedValues)
+ {
+ if (allowedValues == null)
+ {
+ allowedValues = new ArrayList(0);
+ }
+ int valueCount = allowedValues.size();
+ this.allowedValues = Collections.unmodifiableList(allowedValues);
+
+ // make the upper case versions
+ this.allowedValuesUpper = new ArrayList(valueCount);
+ for (String allowedValue : this.allowedValues)
+ {
+ allowedValuesUpper.add(allowedValue.toUpperCase());
+ }
+ }
+
+ @Override
+ public void initialize()
+ {
+ checkPropertyNotNull("allowedValues", allowedValues);
+ }
+
+ @Override
+ public Map getParameters()
+ {
+ Map params = new HashMap(2);
+
+ params.put("caseSensitive", isCaseSensitive());
+ params.put("allowedValues", getAllowedValues());
+ params.put("sorted", isSorted());
+ params.put("matchLogic", getMatchLogic());
+
+ return params;
+ }
+
+ public MatchLogic getMatchLogicEnum()
+ {
+ return matchLogic;
+ }
+
+ public String getMatchLogic()
+ {
+ return matchLogic.toString();
+ }
+
+ public void setMatchLogic(String matchLogicStr)
+ {
+ this.matchLogic = MatchLogic.valueOf(matchLogicStr);
+ }
+
+ @Override
+ protected void evaluateSingleValue(Object value)
+ {
+ // convert the value to a String
+ String valueStr = null;
+ try
+ {
+ valueStr = DefaultTypeConverter.INSTANCE.convert(String.class, value);
+ }
+ catch (TypeConversionException e)
+ {
+ throw new ConstraintException(RMConstraintMessageKeys.ERR_NON_STRING, value, e);
+ }
+ // check that the value is in the set of allowed values
+ if (isCaseSensitive())
+ {
+ if (!getAllowedValues().contains(valueStr))
+ {
+ throw new ConstraintException(RMConstraintMessageKeys.ERR_INVALID_VALUE, value);
+ }
+ }
+ else
+ {
+ if (!getAllowedValuesUpper().contains(valueStr.toUpperCase()))
+ {
+ throw new ConstraintException(RMConstraintMessageKeys.ERR_INVALID_VALUE, value);
+ }
+ }
+ }
+}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationLevel.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationLevel.java
index c151682f06..196a604bc2 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationLevel.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationLevel.java
@@ -35,7 +35,7 @@ public final class ClassificationLevel implements Serializable
{
/** serial version uid */
private static final long serialVersionUID = -3375064867090476422L;
-
+
private final String id;
private final String displayLabelKey;
@@ -50,7 +50,10 @@ public final class ClassificationLevel implements Serializable
/** Returns the unique identifier for this classification level. */
public String getId() { return this.id; }
- /** Returns the localised (current locale) display label for this classification level. */
+ /**
+ * Returns the localised (current locale) display label for this classification level. If no translation is found
+ * then return the key instead.
+ */
public String getDisplayLabel()
{
String message = I18NUtil.getMessage(displayLabelKey);
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationLevelConstraint.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationLevelConstraint.java
new file mode 100644
index 0000000000..12489789e8
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationLevelConstraint.java
@@ -0,0 +1,96 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.List;
+
+import org.alfresco.module.org_alfresco_module_rm.caveat.RMConstraintMessageKeys;
+import org.alfresco.repo.dictionary.constraint.AbstractConstraint;
+import org.alfresco.service.cmr.dictionary.ConstraintException;
+import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
+import org.alfresco.service.cmr.repository.datatype.TypeConversionException;
+
+/**
+ * Check that a value is a valid {@link ClassificationLevel} by checking the {@link ClassificationService}.
+ *
+ * @author tpage
+ */
+public class ClassificationLevelConstraint extends AbstractConstraint
+{
+ /** The classification service provides access to the valid classification levels. */
+ private ClassificationService classificationService;
+
+ /** Constraints must use a default constructor. */
+ public ClassificationLevelConstraint()
+ {
+ super();
+ this.classificationService = ClassificationServiceProvider.getClassificationService();
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder();
+ // TODO Decide whether calling getAllowedValues() is a good idea.
+ sb.append("ClassificationLevelConstraint")
+ .append("[allowedValues=").append(getAllowedValues())
+ .append("]");
+ return sb.toString();
+ }
+
+ /**
+ * Get the allowed values. Note that these are String instances, but may
+ * represent non-String values. It is up to the caller to distinguish.
+ *
+ * @return Returns the values allowed
+ */
+ private List getAllowedValues()
+ {
+ List classificationLevels = classificationService.getClassificationLevels();
+ List values = new ArrayList();
+ for (ClassificationLevel classificationLevel : classificationLevels)
+ {
+ values.add(classificationLevel.getId());
+ }
+ return values;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected void evaluateSingleValue(Object value)
+ {
+ // convert the value to a String
+ String valueStr = null;
+ try
+ {
+ valueStr = DefaultTypeConverter.INSTANCE.convert(String.class, value);
+ }
+ catch (TypeConversionException e)
+ {
+ throw new ConstraintException(RMConstraintMessageKeys.ERR_NON_STRING, value);
+ }
+ // Check that the classification level is one of the configured levels.
+ if (!getAllowedValues().contains(valueStr))
+ {
+ throw new ConstraintException(RMConstraintMessageKeys.ERR_INVALID_VALUE, value);
+ }
+ }
+}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImpl.java
index a0adee0f29..b4b4e9eb22 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImpl.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImpl.java
@@ -42,7 +42,7 @@ public class ClassificationServiceImpl extends ServiceBaseImpl
private static final Serializable[] REASONS_KEY = new String[] { "org.alfresco",
"module.org_alfresco_module_rm",
"classification.reasons" };
- private static final Logger LOGGER = LoggerFactory.getLogger(ClassificationServiceImpl.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(ClassificationServiceImpl.class);
private AttributeService attributeService; // TODO What about other code (e.g. REST API) accessing the AttrService?
private ClassificationServiceDAO classificationServiceDao;
@@ -80,7 +80,7 @@ public class ClassificationServiceImpl extends ServiceBaseImpl
this.configuredLevels = allPersistedLevels;
}
}
-
+
void initConfiguredClassificationReasons()
{
final List persistedReasons = getPersistedReasons();
@@ -143,7 +143,7 @@ public class ClassificationServiceImpl extends ServiceBaseImpl
{
return classificationServiceDao.getConfiguredLevels();
}
-
+
/**
* Gets the list of classification reasons as persisted in the system.
* @return the list of classification reasons if they have been persisted, else {@code null}.
@@ -186,7 +186,8 @@ public class ClassificationServiceImpl extends ServiceBaseImpl
@Override
public List getClassificationLevels()
{
- if (configuredLevels == null) {
+ if (configuredLevels == null)
+ {
return Collections.emptyList();
}
// FIXME Currently assume user has highest security clearance, this should be fixed as part of RM-2112.
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceProvider.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceProvider.java
new file mode 100644
index 0000000000..7e55c2d032
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceProvider.java
@@ -0,0 +1,59 @@
+/*
+ * 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 java.util.concurrent.atomic.AtomicReference;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * A Spring class used to provide the {@link ClassificationService} to non-Spring classes.
+ *
+ * @author tpage
+ */
+public class ClassificationServiceProvider
+{
+ /** Logging utility for the class. */
+ private static final Logger LOGGER = LoggerFactory.getLogger(ClassificationServiceProvider.class);
+ /** The Spring application context. */
+ private static final AtomicReference CLASSIFICATION_SERVICE_REF = new AtomicReference<>();
+
+ /** Constructor that takes the classification service and makes it available statically. */
+ public ClassificationServiceProvider(ClassificationService classificationService)
+ {
+ ClassificationService oldClassificationService = CLASSIFICATION_SERVICE_REF.getAndSet(classificationService);
+ if (oldClassificationService != null)
+ {
+ LOGGER.debug("Unexpected instantiation of ClassificationServiceProvider has updated reference to classification service.");
+ }
+ }
+
+ /**
+ * Get the ClassificationService
as defined in the Spring context.
+ *
+ * @return The service bean.
+ */
+ public static ClassificationService getClassificationService()
+ {
+ return CLASSIFICATION_SERVICE_REF.get();
+ }
+}
diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationLevelConstraintUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationLevelConstraintUnitTest.java
new file mode 100644
index 0000000000..2e5c39fbc8
--- /dev/null
+++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationLevelConstraintUnitTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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 org.mockito.Mockito.doReturn;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.alfresco.service.cmr.dictionary.ConstraintException;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+/**
+ * Unit tests for the {@link ClassificationLevelConstraint}.
+ *
+ * @author tpage
+ */
+public class ClassificationLevelConstraintUnitTest
+{
+ private static final ClassificationLevel LEVEL_ONE = new ClassificationLevel("id1", "DisplayKey1");
+ private static final ClassificationLevel LEVEL_TWO = new ClassificationLevel("id2", "DisplayKey2");
+ private static final List DEFAULT_LEVELS = Arrays.asList(LEVEL_ONE, LEVEL_TWO);
+
+ @InjectMocks ClassificationLevelConstraint classificationLevelConstraint;
+ @Mock ClassificationService mockClassificationService;
+
+ @Before
+ public void setUp()
+ {
+ MockitoAnnotations.initMocks(this);
+
+ // Currently this list of levels suffices for all the tests.
+ doReturn(DEFAULT_LEVELS).when(mockClassificationService).getClassificationLevels();
+ }
+
+ /** Check that evaluateSingleValue throws no exceptions when an id is found. */
+ @Test
+ public void evaluateSingleValue_valid()
+ {
+ classificationLevelConstraint.evaluateSingleValue("id1");
+ }
+
+ /** Check that evaluateSingleValue throws an exception when an id is not found. */
+ @Test(expected = ConstraintException.class)
+ public void evaluateSingleValue_stringNotFound()
+ {
+ classificationLevelConstraint.evaluateSingleValue("non-existant id");
+ }
+
+ /** Check that evaluateSingleValue throws an exception when supplied with something that isn't a String. */
+ @Test(expected = ConstraintException.class)
+ public void evaluateSingleValue_notString()
+ {
+ classificationLevelConstraint.evaluateSingleValue(Integer.valueOf(123));
+ }
+}
diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationSuite.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationSuite.java
index 64e7be1bc0..6275c0c220 100644
--- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationSuite.java
+++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationSuite.java
@@ -28,8 +28,9 @@ import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses(
{
- ClassificationServiceImplUnitTest.class,
- ClassificationServiceDAOUnitTest.class
+ ClassificationLevelConstraintUnitTest.class,
+ ClassificationServiceDAOUnitTest.class,
+ ClassificationServiceImplUnitTest.class
})
public class ClassificationSuite
{