From b3dd2d8528bd285de170199cd8e29068fc27e9f6 Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Fri, 17 Apr 2015 14:28:13 +0000 Subject: [PATCH] RM-2045 (Java API to add a classification to a document) * Check the id's of classification reasons and level + review RM-25 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@102125 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../ClassificationServiceImpl.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) 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 409cb94eae..215cb2832d 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 @@ -28,7 +28,9 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.LevelIdNotFound; import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.MissingConfiguration; +import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.ReasonIdNotFound; import org.alfresco.module.org_alfresco_module_rm.classification.model.ClassifiedContentModel; import org.alfresco.module.org_alfresco_module_rm.util.ServiceBaseImpl; import org.alfresco.repo.security.authentication.AuthenticationUtil; @@ -223,6 +225,7 @@ public class ClassificationServiceImpl extends ServiceBaseImpl mandatory("document", document); Map properties = new HashMap(); + checkClassificationLevelId(classificationLevelId); // Initial classification id if (nodeService.getProperty(document, PROP_INITIAL_CLASSIFICATION) == null) @@ -240,6 +243,7 @@ public class ClassificationServiceImpl extends ServiceBaseImpl HashSet classificationReasons = new HashSet<>(); for (String classificationReasonId : classificationReasonIds) { + checkClassificationReasonId(classificationReasonId); classificationReasons.add(classificationReasonId); } properties.put(PROP_CLASSIFICATION_REASONS, classificationReasons); @@ -247,4 +251,26 @@ public class ClassificationServiceImpl extends ServiceBaseImpl // Add aspect nodeService.addAspect(document, ASPECT_CLASSIFIED, properties); } + + /** + * Helper method to check if a classification level with the given id exists + * + * @param classificationLevelId {@link String} The id of the classification level + * @throws {@link LevelIdNotFound} throws an exception if a classification level with given id does not exist + */ + private void checkClassificationLevelId(String classificationLevelId) throws LevelIdNotFound + { + levelManager.findLevelById(classificationLevelId); + } + + /** + * Helper method to check if a classification reason with the given id exists + * + * @param classificationReasonId {@String} The id of the classification reason + * @throws {@link ReasonIdNotFound} throws an exception if a classification reason with the given id does not exist + */ + private void checkClassificationReasonId(String classificationReasonId) throws ReasonIdNotFound + { + reasonManager.findReasonById(classificationReasonId); + } }