mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
- Added update and inboundAndUpdate as example rule types that can be commented in.
- Added parameter to content update policy to indicate whether it is new content being updated - Added triigers to support update rule type git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2275 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -18,6 +18,8 @@ package org.alfresco.repo.content;
|
||||
|
||||
import org.alfresco.repo.policy.ClassPolicy;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Content service policies interface
|
||||
@@ -26,6 +28,9 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
*/
|
||||
public interface ContentServicePolicies
|
||||
{
|
||||
/** The QName's of the policies */
|
||||
public static final QName ON_CONTENT_UPDATE = QName.createQName(NamespaceService.ALFRESCO_URI, "onContentUpdate");
|
||||
|
||||
/**
|
||||
* On content update policy interface
|
||||
*/
|
||||
@@ -34,6 +39,6 @@ public interface ContentServicePolicies
|
||||
/**
|
||||
* @param nodeRef the node reference
|
||||
*/
|
||||
public void onContentUpdate(NodeRef nodeRef);
|
||||
public void onContentUpdate(NodeRef nodeRef, boolean newContent);
|
||||
}
|
||||
}
|
||||
|
@@ -147,6 +147,7 @@ public class RoutingContentService implements ContentService
|
||||
Map<QName, Serializable> after)
|
||||
{
|
||||
boolean fire = false;
|
||||
boolean newContent = false;
|
||||
// check if any of the content properties have changed
|
||||
for (QName propertyQName : after.keySet())
|
||||
{
|
||||
@@ -173,6 +174,38 @@ public class RoutingContentService implements ContentService
|
||||
}
|
||||
else if (!EqualsHelper.nullSafeEquals(beforeValue, afterValue))
|
||||
{
|
||||
// So debug ...
|
||||
if (logger.isDebugEnabled() == true)
|
||||
{
|
||||
String beforeString = "";
|
||||
if (beforeValue != null)
|
||||
{
|
||||
beforeString = beforeValue.toString();
|
||||
}
|
||||
String afterString = "";
|
||||
if (afterValue != null)
|
||||
{
|
||||
afterString = afterValue.toString();
|
||||
}
|
||||
logger.debug("onContentUpate: before = " + beforeString + "; after = " + afterString);
|
||||
}
|
||||
|
||||
// Figure out if the content is new or not
|
||||
String beforeContentUrl = null;
|
||||
if (beforeValue != null)
|
||||
{
|
||||
beforeContentUrl = beforeValue.getContentUrl();
|
||||
}
|
||||
String afterContentUrl = null;
|
||||
if (afterValue != null)
|
||||
{
|
||||
afterContentUrl = afterValue.getContentUrl();
|
||||
}
|
||||
if (beforeContentUrl == null && afterContentUrl != null)
|
||||
{
|
||||
newContent = true;
|
||||
}
|
||||
|
||||
// the content changed
|
||||
// at the moment, we are only interested in this one change
|
||||
fire = true;
|
||||
@@ -192,7 +225,7 @@ public class RoutingContentService implements ContentService
|
||||
Set<QName> types = new HashSet<QName>(this.nodeService.getAspects(nodeRef));
|
||||
types.add(this.nodeService.getType(nodeRef));
|
||||
OnContentUpdatePolicy policy = this.onContentUpdateDelegate.get(types);
|
||||
policy.onContentUpdate(nodeRef);
|
||||
policy.onContentUpdate(nodeRef, newContent);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -257,6 +257,7 @@ public class RoutingContentServiceTest extends BaseSpringTest
|
||||
}
|
||||
|
||||
private boolean policyFired = false;
|
||||
private boolean newContent = true;
|
||||
|
||||
/**
|
||||
* Tests that the content update policy firs correctly
|
||||
@@ -273,6 +274,8 @@ public class RoutingContentServiceTest extends BaseSpringTest
|
||||
ContentWriter contentWriter = this.contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true);
|
||||
contentWriter.putContent("content update one");
|
||||
assertFalse(this.policyFired);
|
||||
|
||||
this.newContent = false;
|
||||
|
||||
// Now check that the policy is fired when the versionable aspect is present
|
||||
this.nodeService.addAspect(this.contentNodeRef, ContentModel.ASPECT_VERSIONABLE, null);
|
||||
@@ -287,9 +290,10 @@ public class RoutingContentServiceTest extends BaseSpringTest
|
||||
assertFalse(this.policyFired);
|
||||
}
|
||||
|
||||
public void onContentUpdateBehaviourTest(NodeRef nodeRef)
|
||||
public void onContentUpdateBehaviourTest(NodeRef nodeRef, boolean newContent)
|
||||
{
|
||||
assertEquals(this.contentNodeRef, nodeRef);
|
||||
assertEquals(this.newContent, newContent);
|
||||
assertTrue(this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE));
|
||||
this.policyFired = true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user