From 3e2fd99f96300fec2ab44a1cabede3ab43a7193f Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Mon, 27 Apr 2015 13:45:05 +0000 Subject: [PATCH] RM-2061 (Add classification properties to document details view) RM-2062 (Add classification properties to record details view) +review RM-29 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@102759 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../classified-content-context.xml | 2 + .../org_alfresco_module_rm/module-context.xml | 13 +++--- .../classification/ClassificationService.java | 20 ++++++++- .../ClassificationServiceImpl.java | 28 ++++++------ .../RecordsManagementNodeFormFilter.java | 43 +++++++++++++++++++ .../ClassificationServiceImplUnitTest.java | 43 ++++++++++++++++++- 6 files changed, 126 insertions(+), 23 deletions(-) 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 2b6ecc2f39..d83ff155e3 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 @@ -78,6 +78,8 @@ org.alfresco.module.org_alfresco_module_rm.classification.ClassificationService.getClassificationLevels=ACL_ALLOW org.alfresco.module.org_alfresco_module_rm.classification.ClassificationService.getClassificationReasons=ACL_ALLOW org.alfresco.module.org_alfresco_module_rm.classification.ClassificationService.classifyContent=ACL_ALLOW + org.alfresco.module.org_alfresco_module_rm.classification.ClassificationService.getClassificationLevelById=ACL_ALLOW + org.alfresco.module.org_alfresco_module_rm.classification.ClassificationService.getClassificationReasonById=ACL_ALLOW org.alfresco.module.org_alfresco_module_rm.classification.ClassificationService.*=ACL_DENY diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/module-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/module-context.xml index 8813e31814..d3fb16bc30 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/module-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/module-context.xml @@ -5,10 +5,10 @@ - + - + @@ -63,7 +63,7 @@ - + @@ -105,7 +105,7 @@ - + @@ -124,7 +124,7 @@ - + @@ -168,7 +168,7 @@ - + @@ -209,6 +209,7 @@ + classificationReasonIds, NodeRef content) throws LevelIdNotFound, ReasonIdNotFound, InvalidNodeRefException, InvalidNode; + + /** + * Gets the classification level for the given classification level id + * + * @param classificationLevelId {@link String} The classification level id for which the classification level should be retrieved. + * @return The classification level for the given classification level id + * @throws LevelIdNotFound If the given classification level id is not found + */ + ClassificationLevel getClassificationLevelById(String classificationLevelId) throws LevelIdNotFound; + + /** + * Gets the classification reason for the given classification reason id + * + * @param classificationReasonId {@link String} The classification reason id for which the classification reason should be retrieved. + * @return The classification reason for the given classification reason id + * @throws ReasonIdNotFound If the given classification reason id is not found + */ + ClassificationReason getClassificationReasonById(String classificationReasonId) throws ReasonIdNotFound; } 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 536937ac6a..075b298142 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 @@ -238,7 +238,8 @@ public class ClassificationServiceImpl extends ServiceBaseImpl } Map properties = new HashMap(); - checkClassificationLevelId(classificationLevelId); + // Check the classification level id - an exception will be thrown if the id cannot be found + getClassificationLevelById(classificationLevelId); // Initial classification id if (nodeService.getProperty(content, PROP_INITIAL_CLASSIFICATION) == null) @@ -256,7 +257,8 @@ public class ClassificationServiceImpl extends ServiceBaseImpl HashSet classificationReasons = new HashSet<>(); for (String classificationReasonId : classificationReasonIds) { - checkClassificationReasonId(classificationReasonId); + // Check the classification reason id - an exception will be thrown if the id cannot be found + getClassificationReasonById(classificationReasonId); classificationReasons.add(classificationReasonId); } properties.put(PROP_CLASSIFICATION_REASONS, classificationReasons); @@ -266,24 +268,22 @@ public class ClassificationServiceImpl extends ServiceBaseImpl } /** - * 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 + * @see org.alfresco.module.org_alfresco_module_rm.classification.ClassificationService#getClassificationLevelById(java.lang.String) */ - private void checkClassificationLevelId(String classificationLevelId) throws LevelIdNotFound + @Override + public ClassificationLevel getClassificationLevelById(String classificationLevelId) throws LevelIdNotFound { - levelManager.findLevelById(classificationLevelId); + checkNotBlank("classificationLevelId", classificationLevelId); + return 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 + * @see org.alfresco.module.org_alfresco_module_rm.classification.ClassificationService#getClassificationReasonById(java.lang.String) */ - private void checkClassificationReasonId(String classificationReasonId) throws ReasonIdNotFound + @Override + public ClassificationReason getClassificationReasonById(String classificationReasonId) throws ReasonIdNotFound { - reasonManager.findReasonById(classificationReasonId); + checkNotBlank("classificationReasonId", classificationReasonId); + return reasonManager.findReasonById(classificationReasonId); } } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/forms/RecordsManagementNodeFormFilter.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/forms/RecordsManagementNodeFormFilter.java index 1572905e19..3e037a690e 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/forms/RecordsManagementNodeFormFilter.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/forms/RecordsManagementNodeFormFilter.java @@ -19,13 +19,17 @@ package org.alfresco.module.org_alfresco_module_rm.forms; import static org.alfresco.repo.security.authentication.AuthenticationUtil.runAsSystem; +import static org.apache.commons.lang.StringUtils.isNotBlank; import java.io.Serializable; import java.util.List; import java.util.Map; import java.util.Set; +import org.alfresco.model.ContentModel; import org.alfresco.model.ImapModel; +import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationService; +import org.alfresco.module.org_alfresco_module_rm.classification.model.ClassifiedContentModel; import org.alfresco.module.org_alfresco_module_rm.compatibility.CompatibilityModel; import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule; import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionScheduleImpl; @@ -70,6 +74,8 @@ public class RecordsManagementNodeFormFilter extends RecordsManagementFormFilter protected static final String TRANSIENT_DECLARED = "rmDeclared"; protected static final String TRANSIENT_CATEGORY_ID = "rmCategoryIdentifier"; protected static final String TRANSIENT_DISPOSITION_INSTRUCTIONS = "rmDispositionInstructions"; + protected static final String TRANSIENT_CURRENT_CLASSIFICATION = "clfCurrentClassification"; + protected static final String TRANSIENT_INITIAL_CLASSIFICATION = "clfInitialClassification"; /** Disposition service */ private DispositionService dispositionService; @@ -77,6 +83,9 @@ public class RecordsManagementNodeFormFilter extends RecordsManagementFormFilter /** File Plan Service */ private FilePlanService filePlanService; + /** Classification Service */ + private ClassificationService classificationService; + /** * Returns the disposition service * @@ -97,6 +106,16 @@ public class RecordsManagementNodeFormFilter extends RecordsManagementFormFilter return this.filePlanService; } + /** + * Returns the classification service + * + * @return Classification service + */ + protected ClassificationService getClassificationService() + { + return this.classificationService; + } + /** * Sets the disposition service * @@ -115,6 +134,14 @@ public class RecordsManagementNodeFormFilter extends RecordsManagementFormFilter this.filePlanService = filePlanService; } + /** + * @param classificationService classification service + */ + public void setClassificationService(ClassificationService classificationService) + { + this.classificationService = classificationService; + } + /** * @see org.alfresco.repo.forms.processor.Filter#afterGenerate(java.lang.Object, java.util.List, java.util.List, org.alfresco.repo.forms.Form, java.util.Map) */ @@ -171,7 +198,23 @@ public class RecordsManagementNodeFormFilter extends RecordsManagementFormFilter protectRecordLevelDispositionPropertyField(form); } } + } + if (dictionaryService.isSubClass(nodeService.getType(nodeRef), ContentModel.TYPE_CONTENT)) + { + String initialClassificationId = (String) nodeService.getProperty(nodeRef, ClassifiedContentModel.PROP_INITIAL_CLASSIFICATION); + if (isNotBlank(initialClassificationId)) + { + String initialClassificationDisplayLabel = getClassificationService().getClassificationLevelById(initialClassificationId).getDisplayLabel(); + addTransientPropertyField(form, TRANSIENT_INITIAL_CLASSIFICATION, DataTypeDefinition.TEXT, initialClassificationDisplayLabel); + } + + String currentClassificationId = (String) nodeService.getProperty(nodeRef, ClassifiedContentModel.PROP_CURRENT_CLASSIFICATION); + if (isNotBlank(currentClassificationId)) + { + String currentClassificationDisplayLabel = getClassificationService().getClassificationLevelById(currentClassificationId).getDisplayLabel(); + addTransientPropertyField(form, TRANSIENT_CURRENT_CLASSIFICATION, DataTypeDefinition.TEXT, currentClassificationDisplayLabel); + } } } diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImplUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImplUnitTest.java index 17c8867f52..a2278e13a3 100644 --- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImplUnitTest.java +++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImplUnitTest.java @@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -36,11 +37,11 @@ import java.util.Map; import java.util.Set; import java.util.stream.Stream; -import com.google.common.collect.Sets; - import org.alfresco.model.ContentModel; import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceException.InvalidNode; +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.test.util.ExceptionUtils; import org.alfresco.module.org_alfresco_module_rm.test.util.MockAuthenticationUtilHelper; @@ -61,6 +62,8 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import com.google.common.collect.Sets; + /** * Unit tests for {@link ClassificationServiceImpl}. * @@ -324,4 +327,40 @@ public class ClassificationServiceImplUnitTest classificationServiceImpl.classifyContent("levelId1", "classificationAuthority", Sets.newHashSet("reasonId1", "reasonId2"), classifiedContent); } + + @Test + public void getClassificationLevelById() + { + String levelId = "classificationLevelId1"; + ClassificationLevel classificationLevel = new ClassificationLevel(levelId, "displayLabelKey"); + when(mockLevelManager.findLevelById(levelId)).thenReturn(classificationLevel); + ClassificationLevel classificationLevelById = classificationServiceImpl.getClassificationLevelById(levelId); + assertEquals(classificationLevel, classificationLevelById); + } + + @Test(expected = LevelIdNotFound.class) + public void getClassificationLevelById_nonExisting() + { + String classificationLevelId = "aRandomId"; + doThrow(new LevelIdNotFound("Id not found!")).when(mockLevelManager).findLevelById(classificationLevelId); + classificationServiceImpl.getClassificationLevelById(classificationLevelId); + } + + @Test + public void getClassificationReasonById() + { + String reasonId = "classificationReasonId1"; + ClassificationReason classificationReason = new ClassificationReason(reasonId, "displayLabelKey"); + when(mockReasonManager.findReasonById(reasonId)).thenReturn(classificationReason); + ClassificationReason classificationReasonById = classificationServiceImpl.getClassificationReasonById(reasonId); + assertEquals(classificationReason, classificationReasonById); + } + + @Test(expected = ReasonIdNotFound.class) + public void getClassificationReasonById_nonExisting() + { + String classificationReasonId = "aRandomId"; + doThrow(new ReasonIdNotFound("Id not found!")).when(mockReasonManager).findReasonById(classificationReasonId); + classificationServiceImpl.getClassificationReasonById(classificationReasonId); + } }