mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Implementation and unit tests for RM-2481, RM-2482, RM-2483 and RM-2489.
This checkin adds behaviours for ensuring that classification aspect/properties are correclty copied between nodes and their renditions on the creation of new renditions, on the classification or reclassification of nodes with existing renditions. To do this I needed what should be, in my opinion, a common Alfresco utility method - the ability to copy an aspect from one node to another (aspect meaning property group i.e. no assocs). I've created that method and put it in CoreServicesExtras. It should really be moved to core. + review RM git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@110069 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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.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.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.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Behaviour bean for classified rendition nodes.
|
||||
*
|
||||
* @since 3.0.a
|
||||
*/
|
||||
@BehaviourBean
|
||||
(
|
||||
defaultType = "rn:rendition"
|
||||
)
|
||||
public class ClassifiedRenditions extends BaseBehaviourBean
|
||||
implements NodeServicePolicies.OnAddAspectPolicy,
|
||||
ClassifiedContentModel
|
||||
{
|
||||
private ContentClassificationService contentClassificationService;
|
||||
private CoreServicesExtras servicesExtras;
|
||||
private RenditionService renditionService;
|
||||
|
||||
public void setContentClassificationService(ContentClassificationService service)
|
||||
{
|
||||
this.contentClassificationService = service;
|
||||
}
|
||||
|
||||
public void setCoreServicesExtras(CoreServicesExtras extras)
|
||||
{
|
||||
this.servicesExtras = extras;
|
||||
}
|
||||
|
||||
public void setRenditionService(RenditionService service)
|
||||
{
|
||||
this.renditionService = service;
|
||||
}
|
||||
|
||||
/**
|
||||
* Behaviour associated with creating a rendition of an already classified node.
|
||||
*/
|
||||
@Override
|
||||
@Behaviour
|
||||
(
|
||||
kind = BehaviourKind.CLASS,
|
||||
notificationFrequency = NotificationFrequency.EVERY_EVENT
|
||||
)
|
||||
public void onAddAspect(final NodeRef renditionNodeRef, final QName aspectTypeQName)
|
||||
{
|
||||
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))
|
||||
{
|
||||
// All renditions should be given the same classification as their source node
|
||||
servicesExtras.copyAspect(sourceNode, renditionNodeRef, ASPECT_CLASSIFIED);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}, authenticationUtil.getSystemUserName());
|
||||
}
|
||||
}
|
@@ -30,6 +30,7 @@ import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationS
|
||||
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.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;
|
||||
@@ -38,6 +39,8 @@ import org.alfresco.repo.policy.annotation.BehaviourBean;
|
||||
import org.alfresco.repo.policy.annotation.BehaviourKind;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
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;
|
||||
|
||||
@@ -51,15 +54,28 @@ import org.alfresco.service.namespace.QName;
|
||||
defaultType = "clf:classified"
|
||||
)
|
||||
public class ClassifiedAspect extends BaseBehaviourBean implements NodeServicePolicies.OnUpdatePropertiesPolicy,
|
||||
NodeServicePolicies.OnAddAspectPolicy, ClassifiedContentModel
|
||||
NodeServicePolicies.OnAddAspectPolicy,
|
||||
ClassifiedContentModel
|
||||
{
|
||||
private ClassificationSchemeService classificationSchemeService;
|
||||
private RenditionService renditionService;
|
||||
private CoreServicesExtras servicesExtras;
|
||||
|
||||
public void setClassificationSchemeService(ClassificationSchemeService service)
|
||||
{
|
||||
this.classificationSchemeService = 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>
|
||||
@@ -104,6 +120,8 @@ public class ClassifiedAspect extends BaseBehaviourBean implements NodeServicePo
|
||||
|
||||
checkConsistencyOfProperties(nodeRef);
|
||||
|
||||
copyClassifiedPropertiesToRenditions(nodeRef);
|
||||
|
||||
return null;
|
||||
}
|
||||
}, AuthenticationUtil.getSystemUserName());
|
||||
@@ -127,11 +145,24 @@ public class ClassifiedAspect extends BaseBehaviourBean implements NodeServicePo
|
||||
public Void doWork()
|
||||
{
|
||||
checkConsistencyOfProperties(nodeRef);
|
||||
|
||||
copyClassifiedPropertiesToRenditions(nodeRef);
|
||||
|
||||
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.
|
||||
*
|
||||
|
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import static org.alfresco.util.collections.CollectionUtils.filterKeys;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.AspectDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryException;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.collections.Function;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Provides additional methods of general use that could (in principle) be moved to the core services.
|
||||
*
|
||||
* @author Neil Mc Erlean
|
||||
* @since 3.0.a
|
||||
*/
|
||||
public class CoreServicesExtras
|
||||
{
|
||||
private DictionaryService dictionaryService;
|
||||
private NodeService nodeService;
|
||||
|
||||
public void setDictionaryService(DictionaryService service)
|
||||
{
|
||||
this.dictionaryService = service;
|
||||
}
|
||||
|
||||
public void setNodeService(NodeService service)
|
||||
{
|
||||
this.nodeService = service;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method copies the property values for the specified aspect from one node to another.
|
||||
* All associations are ignored.
|
||||
*
|
||||
* @param from the node whose property values are to be read.
|
||||
* @param to the node to which the property values are to be written.
|
||||
* @return a Map of the property values which were copied.
|
||||
*/
|
||||
public Map<QName, Serializable> copyAspect(NodeRef from, NodeRef to, QName aspectQName)
|
||||
{
|
||||
final AspectDefinition aspectDefn = dictionaryService.getAspect(aspectQName);
|
||||
|
||||
if (aspectDefn == null) { throw new DictionaryException("Unknown aspect: " + aspectQName); }
|
||||
|
||||
final Set<QName> aspectProperties = aspectDefn.getProperties().keySet();
|
||||
|
||||
final Map<QName, Serializable> nodeProperties = nodeService.getProperties(from);
|
||||
final Map<QName, Serializable> relevantPropVals = filterKeys(nodeProperties, new Function<QName, Boolean>()
|
||||
{
|
||||
@Override public Boolean apply(QName value)
|
||||
{
|
||||
return aspectProperties.contains(value);
|
||||
}
|
||||
});
|
||||
nodeService.setProperties(to, relevantPropVals);
|
||||
return relevantPropVals;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user