Custom rule is necessary when we want to perform our custom action based on content entry/update/deletion action.
When specific content enters into space, we will perform our custom action on it.
e.g. ranaming file/allow only specific type of files etc. etc.
Lets have steps to create custom rule
I have used alfresco 4.2.x version.
#1) context file [custom-rule-context.xml]
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'> <beans> <bean id="custom-rule-executer" class="com.example.alfresco.repo.action.CustomRuleExecutor" parent="action-executer"> <property name="nodeService"> <ref bean="NodeService" /> </property> <property name="fileFolderService"> <ref bean="fileFolderService"/> </property> </bean> <bean id="custom-rule-executer-messages" class="org.alfresco.i18n.ResourceBundleBootstrapComponent"> <property name="resourceBundles"> <list> <value>alfresco.extension.custom-rule-messages</value> </list> </property> </bean> </beans>#2) Properties File [custom-rule-messages.properties]
custom-rule-executer.title=My Custom Rule. custom-rule-executer.description=This action will allow Custom Rule files. custom-rule-executer.param_tags.display-label=My Custom Rule files.
#3) Custom Rule class [CustomRuleExecutor.java]
public class CustomRuleExecutor extends ActionExecuterAbstractBase {
Logger logger = Logger.getLogger(CustomRuleExecutor.class);
private NodeService nodeService;
private FileFolderService fileFolderService;
@Override
protected void executeImpl(Action action, NodeRef addedFile) {
try {
//add your code here for custom action
} catch (InvalidNodeRefException ine) {
logger.error("### Node Invalid");
throw ine;
} catch (FileExistsException e) {
e.printStackTrace();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
}
@Override
protected void addParameterDefinitions(List<ParameterDefinition> arg0) {
}
public NodeService getNodeService() {
return nodeService;
}
public void setNodeService(NodeService nodeService) {
this.nodeService = nodeService;
}
public FileFolderService getFileFolderService() {
return fileFolderService;
}
public void setFileFolderService(FileFolderService fileFolderService) {
this.fileFolderService = fileFolderService;
}
}
Place context file and properties file in /tomcat/shared/classes/alfresco/extension folder and
restart alfresco
===============
Ghanshyam Rathod
India
No comments:
Post a Comment