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
This commit is contained in:
Tuna Aksoy
2015-04-27 13:45:05 +00:00
parent 899cf5fad1
commit 3e2fd99f96
6 changed files with 126 additions and 23 deletions

View File

@@ -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
</value>
</property>

View File

@@ -209,6 +209,7 @@
<property name="filterRegistry" ref="nodeFilterRegistry" />
<property name="dispositionService" ref="dispositionService"/>
<property name="filePlanService" ref="FilePlanService" />
<property name="classificationService" ref="ClassificationService" />
</bean>
<bean id="rmTypeFormFilter"

View File

@@ -66,4 +66,22 @@ public interface ClassificationService
void classifyContent(String classificationLevelId, String classificationAuthority,
Set<String> 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;
}

View File

@@ -238,7 +238,8 @@ public class ClassificationServiceImpl extends ServiceBaseImpl
}
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
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<String> 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);
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}