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
This commit is contained in:
Tom Page
2015-07-23 13:06:48 +00:00
parent aff3da54ef
commit 3b159f2ba9
5 changed files with 239 additions and 50 deletions

View File

@@ -28,6 +28,10 @@
<constraints> <constraints>
<constraint name="clf:classificationLevelRestriction" <constraint name="clf:classificationLevelRestriction"
type="org.alfresco.module.org_alfresco_module_rm.classification.ClassificationLevelConstraint" /> type="org.alfresco.module.org_alfresco_module_rm.classification.ClassificationLevelConstraint" />
<constraint name="clf:classificationReasonRestriction"
type="org.alfresco.module.org_alfresco_module_rm.classification.ClassificationReasonConstraint" />
<constraint name="clf:exemptionCategoryRestriction"
type="org.alfresco.module.org_alfresco_module_rm.classification.ExemptionCategoryConstraint" />
</constraints> </constraints>
<!-- Types --> <!-- Types -->
@@ -78,6 +82,49 @@
<description>Holds the ids of classification reasons</description> <description>Holds the ids of classification reasons</description>
<type>d:text</type> <type>d:text</type>
<multiple>true</multiple> <multiple>true</multiple>
<constraints>
<constraint ref="clf:classificationReasonRestriction" />
</constraints>
</property>
<property name="clf:downgradeDate">
<title>Downgrade Date</title>
<description>The date when the classification may be downgraded</description>
<type>d:date</type>
<mandatory>false</mandatory>
</property>
<property name="clf:downgradeEvent">
<title>Downgrade Event</title>
<description>An event for which the classification may be downgraded</description>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
<property name="clf:downgradeInstructions">
<title>Downgrade Instructions</title>
<description>Instructions to be followed when considering whether to downgrade the classification</description>
<type>d:text</type>
<mandatory>false</mandatory>
<!-- TODO Constraint on this and two previous fields -->
</property>
<property name="clf:declasificationDate">
<title>Declassification Date</title>
<description>The date when this may be declassified</description>
<type>d:date</type>
<mandatory>false</mandatory>
</property>
<property name="clf:declasificationEvent">
<title>Declassification Event</title>
<description>The event when this may be declassified</description>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
<property name="clf:declasificationExemptions">
<title>Declassification Exemptions</title>
<description>Exemptions that may preclude this from being declassified</description>
<type>d:text</type>
<multiple>true</multiple>
<constraints>
<constraint ref="clf:exemptionCategoryRestriction" />
</constraints>
</property> </property>
</properties> </properties>
</aspect> </aspect>

View File

@@ -22,47 +22,22 @@ package org.alfresco.module.org_alfresco_module_rm.classification;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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}. * Check that a value is a valid {@link ClassificationLevel} by checking the {@link ClassificationSchemeService}.
* *
* @author tpage * @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 <tt>String</tt> instances, but may * Get the allowed values. Note that these are <tt>String</tt> instances, but may
* represent non-<tt>String</tt> values. It is up to the caller to distinguish. * represent non-<tt>String</tt> values. It is up to the caller to distinguish.
* *
* @return Returns the values allowed * @return Returns the values allowed
*/ */
private List<String> getAllowedValues() @Override
protected List<String> getAllowedValues()
{ {
List<ClassificationLevel> classificationLevels = classificationSchemeService.getClassificationLevels(); List<ClassificationLevel> classificationLevels = classificationSchemeService.getClassificationLevels();
List<String> values = new ArrayList<String>(); List<String> values = new ArrayList<String>();
@@ -72,25 +47,4 @@ public class ClassificationLevelConstraint extends AbstractConstraint
} }
return values; 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);
}
}
} }

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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 <tt>String</tt> instances, but may
* represent non-<tt>String</tt> values. It is up to the caller to distinguish.
*
* @return Returns the values allowed
*/
@Override
protected List<String> getAllowedValues()
{
List<ClassificationReason> classificationReasons = classificationSchemeService.getClassificationReasons();
List<String> values = new ArrayList<String>();
for (ClassificationReason classificationReason : classificationReasons)
{
values.add(classificationReason.getId());
}
return values;
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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 <tt>String</tt> instances, but may
* represent non-<tt>String</tt> values. It is up to the caller to distinguish.
*
* @return Returns the values allowed
*/
protected abstract List<String> 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);
}
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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 <tt>String</tt> instances, but may
* represent non-<tt>String</tt> values. It is up to the caller to distinguish.
*
* @return Returns the values allowed
*/
@Override
protected List<String> getAllowedValues()
{
List<ExemptionCategory> exemptionCategories = classificationSchemeService.getExemptionCategories();
List<String> values = new ArrayList<String>();
for (ExemptionCategory exemptionCategory : exemptionCategories)
{
values.add(exemptionCategory.getId());
}
return values;
}
}