01-21-2016 07:10 AM
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.policy.Behaviour;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
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.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.apache.log4j.Logger;
import com.models.DocModel;
import com.models.FolModel;
/**
*
* Class used for checking validity of country folder type
*
*
*/
public class CountryFolderCheckBehaviour implements
NodeServicePolicies.BeforeCreateNodePolicy,
NodeServicePolicies.BeforeSetNodeTypePolicy {
// Dependencies
private NodeService nodeService;
private PolicyComponent policyComponent;
// Behaviours
private Behaviour beforeCreateNode;
private Behaviour beforeSetNodeType;
private Logger logger = Logger.getLogger(CountryFolderCheckBehaviour.class);
public void init() {
if (logger.isDebugEnabled())
logger.debug("******************* Initializing case country folder check *******************");
// Create behaviours
this.beforeCreateNode = new JavaBehaviour(this, "beforeCreateNode",
NotificationFrequency.TRANSACTION_COMMIT);
this.beforeSetNodeType = new JavaBehaviour(this, "beforeSetNodeType",
NotificationFrequency.TRANSACTION_COMMIT);
// Bind behaviours to node policies
this.policyComponent.bindClassBehaviour(QName.createQName(
NamespaceService.ALFRESCO_URI, "beforeCreateNode"),
FolModel.COUNTRY_FOL,
this.beforeCreateNode);
this.policyComponent.bindClassBehaviour(QName.createQName(
NamespaceService.ALFRESCO_URI, "beforeSetNodeType"),
FolModel.COUNTRY_FOL,
this.beforeSetNodeType);
}
@Override
public void beforeCreateNode(NodeRef parentRef, QName assocTypeQName,
QName assocQName, QName nodeTypeQName) {
if (logger.isDebugEnabled())
logger.debug("Inside beforeCreateNode");
checkFolderValidity(parentRef);
}
@Override
public void beforeSetNodeType(NodeRef parentRef, QName oldType,
QName newType) {
if (logger.isDebugEnabled())
logger.debug("Inside beforeSetNodeType");
checkFolderValidity(parentRef);
}
/**
* Method used for checking validity for country folder type
*
* @param parentNodeName
* name of the parent node
*
*/
private void checkFolderValidity(NodeRef parentNode) {
String parentNodeName = (nodeService.getProperty(parentNode,
ContentModel.PROP_NAME)).toString();
try {
if (!parentNodeName.equals("documentLibrary")) {
throw new AlfrescoRuntimeException(
"Cannot create country type folder");
}
} finally {
if (logger.isDebugEnabled())
logger.debug("******************* Creating country folder *******************");
}
}
public void setNodeService(NodeService nodeService) {
this.nodeService = nodeService;
}
public void setPolicyComponent(PolicyComponent policyComponent) {
this.policyComponent = policyComponent;
}
}
01-25-2016 01:08 AM
01-25-2016 03:08 AM
01-27-2016 05:06 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.