02-09-2011 02:19 PM
package ca.athabascau.alfresco.calendar.policies;
import static java.lang.String.format;
import static org.alfresco.repo.policy.Behaviour.NotificationFrequency.EVERY_EVENT;
import static org.apache.commons.lang.Validate.notNull;
import org.alfresco.repo.node.NodeServicePolicies.OnCreateNodePolicy;
import org.alfresco.repo.policy.Behaviour;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.rule.RuleService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.stereotype.Component;
import ca.athabascau.alfresco.calendar.models.content.AuCalendarContentModel;
import ca.athabascau.alfresco.calendar.services.AuCalendarService;
@Component
public class WebFolderCreationPolicy implements OnCreateNodePolicy {
private static final Logger LOGGER = Logger.getLogger(WebFolderCreationPolicy.class);
private static final String DELEGATE_METHOD_NAME = "onCreateNode";
private AuCalendarService auCalendarService;
private NodeService nodeService;
private PolicyComponent policyComponent;
private RuleService ruleService;
@Required
public void setAuCalendarService(final AuCalendarService service){
auCalendarService = service;
}
@Required
public void setNodeService(final NodeService service){
nodeService = service;
}
@Required
public void setPolicyComponent(final PolicyComponent component) {
policyComponent = component;
}
@Required
public void setRuleService(final RuleService service){
ruleService = service;
}
public void init() {
final Behaviour behaviour = new JavaBehaviour(this, DELEGATE_METHOD_NAME, EVERY_EVENT);
if (LOGGER.isInfoEnabled()){
LOGGER.info(format("Delegate Method Name = %s", DELEGATE_METHOD_NAME));
LOGGER.info(format("Notification Frequency = %s", EVERY_EVENT));
}
policyComponent.bindClassBehaviour(OnCreateNodePolicy.QNAME, AuCalendarContentModel.TYPE_WEB_FOLDER, behaviour);
}
@Override
public void onCreateNode(final ChildAssociationRef childAssociationRef) {
notNull(childAssociationRef, "ChildAssociationRef must be specified.");
final NodeRef childRef = childAssociationRef.getChildRef();
notNull(childAssociationRef.getChildRef(), "ChildRef must be specified.");
if (! nodeService.getType(childRef).equals(AuCalendarContentModel.TYPE_WEB_FOLDER)){
if (LOGGER.isDebugEnabled()){
LOGGER.debug(format("NodeRef %s is not of type %s. Policy does not apply.", childRef, AuCalendarContentModel.TYPE_WEB_FOLDER));
}
return;
}
if (! ruleService.isEnabled()){
if (LOGGER.isDebugEnabled()){
LOGGER.debug("Rules are not enabled in Alfresco. Policy does not apply.");
}
return;
}
if (! ruleService.rulesEnabled(childRef)){
if (LOGGER.isDebugEnabled()){
LOGGER.debug(format("Rules are not enabled for NodeRef %s. Policy does not apply.", childRef));
}
return;
}
auCalendarService.addUpdateRule(childRef);
auCalendarService.addDeleteRule(childRef);
if (LOGGER.isDebugEnabled()){
LOGGER.debug(format("Add and Update rules have been applied to NodeRef %s. Policy has been applied.", childRef));
}
}
}
policyComponent.bindClassBehaviour(OnCreateNodePolicy.QNAME, AuCalendarContentModel.TYPE_WEB_FOLDER, behaviour);
policyComponent.bindClassBehaviour(OnCreateNodePolicy.QNAME, WebFolderCreationPolicy.class, behaviour);
11-05-2013 07:13 AM
11-05-2013 09:36 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.