From 3b159f2ba99e10ec75e256d96d1cb5c5c5b1e3fc Mon Sep 17 00:00:00 2001 From: Tom Page Date: Thu, 23 Jul 2015 13:06:48 +0000 Subject: [PATCH] RM-2400 Add classification schedule properties to model. Refactor constraints, and create new constraints for exemption categories and classification reasons. +review RM git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@108859 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../model/classifiedContentModel.xml | 47 ++++++++++ .../ClassificationLevelConstraint.java | 54 +----------- .../ClassificationReasonConstraint.java | 50 +++++++++++ .../ClassificationSchemeEntityConstraint.java | 88 +++++++++++++++++++ .../ExemptionCategoryConstraint.java | 50 +++++++++++ 5 files changed, 239 insertions(+), 50 deletions(-) create mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationReasonConstraint.java create mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationSchemeEntityConstraint.java create mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ExemptionCategoryConstraint.java 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 54e2cb2b9d..61c042e759 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 @@ -28,6 +28,10 @@ + + @@ -78,6 +82,49 @@ Holds the ids of classification reasons d:text true + + + + + + Downgrade Date + The date when the classification may be downgraded + d:date + false + + + Downgrade Event + An event for which the classification may be downgraded + d:text + false + + + Downgrade Instructions + Instructions to be followed when considering whether to downgrade the classification + d:text + false + + + + Declassification Date + The date when this may be declassified + d:date + false + + + Declassification Event + The event when this may be declassified + d:text + false + + + Declassification Exemptions + Exemptions that may preclude this from being declassified + d:text + true + + + 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 index 2291034bec..588d0a9f8a 100644 --- 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 @@ -22,47 +22,22 @@ 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 ClassificationSchemeService}. * * @author tpage + * @since 3.0.a */ -public class ClassificationLevelConstraint extends AbstractConstraint +public class ClassificationLevelConstraint extends ClassificationSchemeEntityConstraint { - /** The classification scheme service provides access to the valid classification levels. */ - private ClassificationSchemeService classificationSchemeService; - - /** Constraints must use a default constructor. */ - public ClassificationLevelConstraint() - { - super(); - this.classificationSchemeService = ClassificationSchemeServiceProvider.getClassificationSchemeService(); - } - - @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() + @Override + protected List getAllowedValues() { List classificationLevels = classificationSchemeService.getClassificationLevels(); List values = new ArrayList(); @@ -72,25 +47,4 @@ public class ClassificationLevelConstraint extends AbstractConstraint } 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/ClassificationReasonConstraint.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationReasonConstraint.java new file mode 100644 index 0000000000..1807f7f9ab --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationReasonConstraint.java @@ -0,0 +1,50 @@ +/* + * 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; + +/** + * Check that a value is a valid {@link ClassificationReason} by checking the {@link ClassificationSchemeService}. + * + * @author tpage + * @since 3.0.a + */ +public class ClassificationReasonConstraint extends ClassificationSchemeEntityConstraint +{ + /** + * 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 + protected List getAllowedValues() + { + List classificationReasons = classificationSchemeService.getClassificationReasons(); + List values = new ArrayList(); + for (ClassificationReason classificationReason : classificationReasons) + { + values.add(classificationReason.getId()); + } + return values; + } +} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationSchemeEntityConstraint.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationSchemeEntityConstraint.java new file mode 100644 index 0000000000..cec0fb1cfb --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationSchemeEntityConstraint.java @@ -0,0 +1,88 @@ +/* + * 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.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; + +/** + * Abstract for constraints the check that a value is a valid {@link ClassificationSchemeEntity} using the + * {@link ClassificationSchemeService}. + * + * @author tpage + * @since 3.0.a + */ +public abstract class ClassificationSchemeEntityConstraint extends AbstractConstraint +{ + /** The classification scheme service provides access to the valid classification levels. */ + protected ClassificationSchemeService classificationSchemeService; + + /** Constraints must use a default constructor. */ + public ClassificationSchemeEntityConstraint() + { + super(); + this.classificationSchemeService = ClassificationSchemeServiceProvider.getClassificationSchemeService(); + } + + @Override + public String toString() + { + StringBuilder sb = new StringBuilder(); + // TODO Decide whether calling getAllowedValues() is a good idea. + sb.append(this.getClass().getSimpleName()) + .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 + */ + protected abstract List getAllowedValues(); + + /** {@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/ExemptionCategoryConstraint.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ExemptionCategoryConstraint.java new file mode 100644 index 0000000000..1d1f538438 --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/ExemptionCategoryConstraint.java @@ -0,0 +1,50 @@ +/* + * 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; + +/** + * Check that a value is a valid {@link ExemptionCategory} by checking the {@link ClassificationSchemeService}. + * + * @author tpage + * @since 3.0.a + */ +public class ExemptionCategoryConstraint extends ClassificationSchemeEntityConstraint +{ + /** + * 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 + protected List getAllowedValues() + { + List exemptionCategories = classificationSchemeService.getExemptionCategories(); + List values = new ArrayList(); + for (ExemptionCategory exemptionCategory : exemptionCategories) + { + values.add(exemptionCategory.getId()); + } + return values; + } +}