This is the RM-specific parts of the refactor for classified renditions - see RM-2549.

This builds on the separate MetadataReferral services to link renditions to classified source nodes via a new classifiedRendition aspect which defines a new classifiedRendition assoc. The spring bean 'classifiedRenditionAssoc' defines that only the clf:classified aspect and its metadata will be linked.




git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/BRANCHES/classified_renditions@111643 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Neil McErlean
2015-09-08 15:32:10 +00:00
parent 7ec55f4830
commit 1e84916582
9 changed files with 126 additions and 211 deletions

View File

@@ -23,11 +23,6 @@ import static org.alfresco.module.org_alfresco_module_rm.util.RMParameterCheck.c
import static org.alfresco.util.ParameterCheck.mandatory;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.model.QuickShareModel;
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.InvalidNode;
@@ -35,6 +30,7 @@ import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationE
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.ReasonIdNotFound;
import org.alfresco.module.org_alfresco_module_rm.classification.model.ClassifiedContentModel;
import org.alfresco.module.org_alfresco_module_rm.freeze.FreezeService;
import org.alfresco.module.org_alfresco_module_rm.referredmetadata.ReferredMetadataService;
import org.alfresco.module.org_alfresco_module_rm.util.ServiceBaseImpl;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
@@ -43,6 +39,11 @@ import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
/**
* A service to handle the classification of content.
*
@@ -57,12 +58,17 @@ public class ContentClassificationServiceImpl extends ServiceBaseImpl
private SecurityClearanceService securityClearanceService;
private ClassificationServiceBootstrap classificationServiceBootstrap;
private FreezeService freezeService;
private ReferredMetadataService referredMetadataService;
public void setLevelManager(ClassificationLevelManager levelManager) { this.levelManager = levelManager; }
public void setReasonManager(ClassificationReasonManager reasonManager) { this.reasonManager = reasonManager; }
public void setSecurityClearanceService(SecurityClearanceService securityClearanceService) { this.securityClearanceService = securityClearanceService; }
public void setClassificationServiceBootstrap(ClassificationServiceBootstrap classificationServiceBootstrap) { this.classificationServiceBootstrap = classificationServiceBootstrap; }
public void setFreezeService(FreezeService service) { this.freezeService = service; }
public void setReferredMetadataService(ReferredMetadataService service)
{
this.referredMetadataService = service;
}
public void init()
{
@@ -80,16 +86,24 @@ public class ContentClassificationServiceImpl extends ServiceBaseImpl
{
public ClassificationLevel doWork() throws Exception
{
// by default everything is unclassified
ClassificationLevel result = ClassificationLevelManager.UNCLASSIFIED;
final String classificationId;
if (nodeService.hasAspect(nodeRef, ASPECT_CLASSIFIED))
{
String classificationId = (String)nodeService.getProperty(nodeRef, PROP_CURRENT_CLASSIFICATION);
result = levelManager.findLevelById(classificationId);
classificationId = (String)nodeService.getProperty(nodeRef, PROP_CURRENT_CLASSIFICATION);
}
else if (referredMetadataService.isReferringMetadata(nodeRef, ASPECT_CLASSIFIED))
{
classificationId = (String) referredMetadataService.getReferredProperty(nodeRef, PROP_CURRENT_CLASSIFICATION);
// Note that this property value could be null/missing.
}
else
{
classificationId = null;
}
return result;
// by default everything is unclassified
return classificationId == null ? ClassificationLevelManager.UNCLASSIFIED : levelManager.findLevelById(classificationId);
}
});
};
@@ -231,12 +245,19 @@ public class ContentClassificationServiceImpl extends ServiceBaseImpl
mandatory("nodeRef", nodeRef);
boolean isClassified = false;
String currentClassification = (String) nodeService.getProperty(nodeRef, PROP_CURRENT_CLASSIFICATION);
if (nodeService.hasAspect(nodeRef, ASPECT_CLASSIFIED) &&
!(UNCLASSIFIED_ID).equals(currentClassification))
final String currentClassification;
if (nodeService.hasAspect(nodeRef, ASPECT_CLASSIFIED))
{
isClassified = true;
currentClassification = (String) nodeService.getProperty(nodeRef, PROP_CURRENT_CLASSIFICATION);
isClassified = currentClassification != null && ! UNCLASSIFIED_ID.equals(currentClassification);
}
else if (referredMetadataService.isReferringMetadata(nodeRef, ASPECT_CLASSIFIED))
{
currentClassification = (String) referredMetadataService.getReferredProperty(nodeRef, PROP_CURRENT_CLASSIFICATION);
// This could be a null/missing property.
isClassified = currentClassification != null && ! UNCLASSIFIED_ID.equals(currentClassification);
}
return isClassified;

View File

@@ -62,4 +62,8 @@ public interface ClassifiedContentModel
/** Security Clearance aspect. */
QName ASPECT_SECURITY_CLEARANCE = QName.createQName(CLF_URI, "securityClearance");
QName PROP_CLEARANCE_LEVEL = QName.createQName(CLF_URI, "clearanceLevel");
/** Classified Rendition aspect. */
QName ASPECT_CLASSIFIED_RENDITION = QName.createQName(CLF_URI, "classifiedRendition");
QName ASSOC_CLASSIFIED_RENDITION = QName.createQName(CLF_URI, "classifiedRendition");
}

View File

@@ -20,21 +20,22 @@ package org.alfresco.module.org_alfresco_module_rm.model.clf;
import org.alfresco.module.org_alfresco_module_rm.classification.ContentClassificationService;
import org.alfresco.module.org_alfresco_module_rm.classification.model.ClassifiedContentModel;
import org.alfresco.module.org_alfresco_module_rm.referredmetadata.ReferralAdminService;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
import org.alfresco.module.org_alfresco_module_rm.util.CoreServicesExtras;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
import org.alfresco.repo.policy.annotation.Behaviour;
import org.alfresco.repo.policy.annotation.BehaviourBean;
import org.alfresco.repo.policy.annotation.BehaviourKind;
import org.alfresco.service.cmr.rendition.RenditionService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
/**
* Behaviour bean for classified rendition nodes.
*
* @since 3.0.a
* @since 2.4.a
*/
@BehaviourBean
(
@@ -45,7 +46,7 @@ public class ClassifiedRenditions extends BaseBehaviourBean
ClassifiedContentModel
{
private ContentClassificationService contentClassificationService;
private CoreServicesExtras servicesExtras;
private ReferralAdminService referralAdminService;
private RenditionService renditionService;
public void setContentClassificationService(ContentClassificationService service)
@@ -53,9 +54,9 @@ public class ClassifiedRenditions extends BaseBehaviourBean
this.contentClassificationService = service;
}
public void setCoreServicesExtras(CoreServicesExtras extras)
public void setReferralAdminService(ReferralAdminService service)
{
this.servicesExtras = extras;
this.referralAdminService = service;
}
public void setRenditionService(RenditionService service)
@@ -74,16 +75,19 @@ public class ClassifiedRenditions extends BaseBehaviourBean
)
public void onAddAspect(final NodeRef renditionNodeRef, final QName aspectTypeQName)
{
// When a rendition is created, set up a metadata link of its classification to the source node.
authenticationUtil.runAs(new org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork<Void>()
{
public Void doWork()
{
final NodeRef sourceNode = renditionService.getSourceNode(renditionNodeRef).getParentRef();
if (contentClassificationService.isClassified(sourceNode))
final ChildAssociationRef chAssRef = renditionService.getSourceNode(renditionNodeRef);
final NodeRef sourceNode = chAssRef.getParentRef();
if (contentClassificationService.isClassified(sourceNode) &&
referralAdminService.getAttachedReferralFrom(renditionNodeRef, ASPECT_CLASSIFIED) != null)
{
// All renditions should be given the same classification as their source node
servicesExtras.copyAspect(sourceNode, renditionNodeRef, ASPECT_CLASSIFIED);
referralAdminService.attachReferrer(renditionNodeRef, sourceNode, ASSOC_CLASSIFIED_RENDITION);
}
return null;
}
}, authenticationUtil.getSystemUserName());

View File

@@ -20,17 +20,13 @@ package org.alfresco.module.org_alfresco_module_rm.model.clf.aspect;
import static org.alfresco.module.org_alfresco_module_rm.util.RMCollectionUtils.diffKey;
import java.io.Serializable;
import java.util.Date;
import java.util.Map;
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.MissingDowngradeInstructions;
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationLevel;
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationSchemeService;
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationSchemeService.Reclassification;
import org.alfresco.module.org_alfresco_module_rm.classification.model.ClassifiedContentModel;
import org.alfresco.module.org_alfresco_module_rm.referredmetadata.ReferralAdminService;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
import org.alfresco.module.org_alfresco_module_rm.util.CoreServicesExtras;
import org.alfresco.module.org_alfresco_module_rm.util.RMCollectionUtils.Difference;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
@@ -44,10 +40,15 @@ import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* clf:classification behaviour bean
*
* @since 3.0.a
* @since 2.4.a
*/
@BehaviourBean
(
@@ -58,31 +59,27 @@ public class ClassifiedAspect extends BaseBehaviourBean implements NodeServicePo
ClassifiedContentModel
{
private ClassificationSchemeService classificationSchemeService;
private ReferralAdminService referralAdminService;
private RenditionService renditionService;
private CoreServicesExtras servicesExtras;
public void setClassificationSchemeService(ClassificationSchemeService service)
{
this.classificationSchemeService = service;
}
public void setReferralAdminService(ReferralAdminService service)
{
this.referralAdminService = service;
}
public void setRenditionService(RenditionService service)
{
this.renditionService = service;
}
public void setCoreServicesExtras(CoreServicesExtras extras)
{
this.servicesExtras = extras;
}
/**
* Behaviour associated with updating the classified aspect properties.
* <p>
* Ensures that on reclassification of content (in other words a change in the value of the
* {@link ClassifiedContentModel#PROP_CURRENT_CLASSIFICATION clf:currentClassification} property)
* that various metadata are correctly updated as a side-effect.
* <p>
* Validates the consistency of the properties.
*/
@Override
@@ -91,7 +88,7 @@ public class ClassifiedAspect extends BaseBehaviourBean implements NodeServicePo
kind = BehaviourKind.CLASS,
notificationFrequency = NotificationFrequency.EVERY_EVENT
)
public void onUpdateProperties(final NodeRef nodeRef,
public void onUpdateProperties(final NodeRef classifiedNode,
final Map<QName, Serializable> before,
final Map<QName, Serializable> after)
{
@@ -101,7 +98,7 @@ public class ClassifiedAspect extends BaseBehaviourBean implements NodeServicePo
{
final Difference classificationChange = diffKey(before, after, PROP_CURRENT_CLASSIFICATION);
if (classificationChange == Difference.CHANGED && nodeService.hasAspect(nodeRef, ASPECT_CLASSIFIED))
if (classificationChange == Difference.CHANGED && nodeService.hasAspect(classifiedNode, ASPECT_CLASSIFIED))
{
final String oldValue = (String)before.get(PROP_CURRENT_CLASSIFICATION);
final String newValue = (String)after.get(PROP_CURRENT_CLASSIFICATION);
@@ -113,14 +110,12 @@ public class ClassifiedAspect extends BaseBehaviourBean implements NodeServicePo
if (reclassification != null)
{
nodeService.setProperty(nodeRef, PROP_LAST_RECLASSIFICATION_ACTION, reclassification.toModelString());
nodeService.setProperty(nodeRef, PROP_LAST_RECLASSIFY_AT, new Date());
nodeService.setProperty(classifiedNode, PROP_LAST_RECLASSIFICATION_ACTION, reclassification.toModelString());
nodeService.setProperty(classifiedNode, PROP_LAST_RECLASSIFY_AT, new Date());
}
}
checkConsistencyOfProperties(nodeRef);
copyClassifiedPropertiesToRenditions(nodeRef);
checkConsistencyOfProperties(classifiedNode);
return null;
}
@@ -136,33 +131,33 @@ public class ClassifiedAspect extends BaseBehaviourBean implements NodeServicePo
@Behaviour
(
kind = BehaviourKind.CLASS,
notificationFrequency = NotificationFrequency.EVERY_EVENT
notificationFrequency = NotificationFrequency.FIRST_EVENT
)
public void onAddAspect(final NodeRef nodeRef, final QName aspectTypeQName)
public void onAddAspect(final NodeRef classifiedNode, final QName aspectTypeQName)
{
AuthenticationUtil.runAs(new RunAsWork<Void>()
{
public Void doWork()
{
checkConsistencyOfProperties(nodeRef);
checkConsistencyOfProperties(classifiedNode);
copyClassifiedPropertiesToRenditions(nodeRef);
// If this node has any renditions, we must ensure that they inherit the classification
// from their source node.
final List<ChildAssociationRef> renditions = renditionService.getRenditions(classifiedNode);
for (ChildAssociationRef chAssRef : renditions)
{
final NodeRef renditionNode = chAssRef.getChildRef();
if (referralAdminService.getAttachedReferralFrom(renditionNode, ASPECT_CLASSIFIED_RENDITION) == null)
{
referralAdminService.attachReferrer(renditionNode, classifiedNode, ASSOC_CLASSIFIED_RENDITION);
}
}
return null;
}
}, AuthenticationUtil.getSystemUserName());
}
private void copyClassifiedPropertiesToRenditions(NodeRef nodeRef)
{
// All renditions should be given the same classification as their source node
for (final ChildAssociationRef chAssRef : renditionService.getRenditions(nodeRef))
{
final NodeRef renditionNode = chAssRef.getChildRef();
servicesExtras.copyAspect(nodeRef, renditionNode, ASPECT_CLASSIFIED);
}
}
/**
* Check the consistency of the classification properties and throw an exception if they are invalid.
*