As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
<config evaluator="string-compare" condition="change-title"> <forms> <form> <field-visibility> <show id="newName"/> </field-visibility> <appearance> <field id="newName" label-id="prop.newName"> <!– <control template="/org/alfresco/components/form/controls/textarea.ftl" /> –> </field> </appearance> </form> </forms> </config> <config evaluator="string-compare" condition="DocLibActions"> <actions> <action id="change-title-doc" type="javascript" icon="activate-reg" label="actions.document.changeTitle"> <param name="function">onActionFormDialog</param> <!– Additional parameters for onFormDialog function –> <param name="itemKind">action</param> <param name="itemId">change-title</param> <param name="mode">create</param> <param name="destination">{node.nodeRef}</param> <param name="successMessage">message.changeTitle.success</param> <param name="failureMessage">message.changeTitle.failure</param> <evaluator>my.evaluator.doclib.indicator.isDocumentAndArchiver</evaluator> </action> </actions> <actionGroups> <actionGroup id="document-details"> <action index="540" id="change-title-doc" /> </actionGroup> <actionGroup id="document-browse"> <action index="540" id="change-title-doc" /> </actionGroup> </actionGroups> </config>
<bean id="change-title" class="my.action.executer.ChangeTitle" parent="action-executer"> <property name="nodeService"> <ref bean="NodeService" /> </property> <property name="publicAction"> <value>false</value> </property> </bean>
package my.action.executer; import java.util.List; import my.model.myModel; import javax.script.*; import org.alfresco.repo.action.ParameterDefinitionImpl; import org.alfresco.repo.action.executer.ActionExecuterAbstractBase; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ParameterDefinition; import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.namespace.QName; public class ChangeTitle extends ActionExecuterAbstractBase { public final static String NAME = "newName"; public final static String FILENAME = "fileName"; public final static String FILETITLE = "fileTitle"; /** The NodeService to be used by the bean */ protected NodeService nodeService; @Override protected void executeImpl(Action action, NodeRef actionedUponNodeRef) { //READ PROPERTY NAME FROM DOCUMENT QName PROP_QNAME_NAME = QName.createQName(myModel.NAMESPACE_ALFRESCO_MODEL, "name"); String fileName = (String) nodeService.getProperty(actionedUponNodeRef, PROP_QNAME_NAME); //SPLIT NAME String[] array = fileName.split("_"); //GET NEW NAME FROM DIALOG FORM String newName = (String) action.getParameterValue(NAME); array[3] = newName + ".pdf"; newName = String.join("_", array); QName AL_NAME = QName.createQName(myModel.NAMESPACE_ALFRESCO_MODEL, "name"); nodeService.setProperty(actionedUponNodeRef, AL_NAME, newName); //READ PROPERTY TITLE FROM DOCUMENT QName PROP_QNAME_TITLE = QName.createQName(myModel.NAMESPACE_ALFRESCO_MODEL, "title"); String fileTitle = (String) nodeService.getProperty(actionedUponNodeRef, PROP_QNAME_TITLE); //GET INDEX OF FIRST SPACE int indexSpace = fileTitle.indexOf(" "); String newTitle = fileTitle.substring(0, (indexSpace + 1)) + array[3]; QName AL_TITLE = QName.createQName(myModel.NAMESPACE_ALFRESCO_MODEL, "title"); nodeService.setProperty(actionedUponNodeRef, AL_TITLE, newTitle); //ScriptEngineManager manager = new ScriptEngineManager(); //ScriptEngine engine = manager.getEngineByName("JavaScript"); //try{ // JavaScript code in a String // String script1 = (String)"function changeName(node,newName) {var nodeRef = search.findNode(node);" // + "nodeRef.name = newName; nodeRef.save();}"; // String skripta = (String)"function main() { runAsAdminUtil.runAsAdmin(changeTitle);}" // + "var changeTitle = function changeTitle() {" // + "/*var doc = search.findNode("+actionedUponNodeRef+");*/" // + "doc.name = "+newTitle+";" // + "}" // + "main();"; // evaluate script //engine.eval(skripta); //Log.debug("posle eval"); //Invocable inv = (Invocable) engine; //inv.invokeFunction("changeName", actionedUponNodeRef, newTitle ); //This one works. //} //catch(Exception e){ //} } @Override protected void addParameterDefinitions(List<ParameterDefinition> paramList) { paramList.add( new ParameterDefinitionImpl( // Create a new parameter definition to add to the list NAME, // The name used to identify the parameter DataTypeDefinition.TEXT, // The parameter value type false, // Indicates whether the parameter is mandatory getParamDisplayLabel(NAME))); // The parameters display label paramList.add( new ParameterDefinitionImpl( // Create a new parameter definition to add to the list FILENAME, // The name used to identify the parameter DataTypeDefinition.TEXT, // The parameter value type false, // Indicates whether the parameter is mandatory getParamDisplayLabel(FILENAME))); paramList.add( new ParameterDefinitionImpl( // Create a new parameter definition to add to the list FILETITLE, // The name used to identify the parameter DataTypeDefinition.TEXT, // The parameter value type false, // Indicates whether the parameter is mandatory getParamDisplayLabel(FILETITLE))); } /** * @param nodeService The NodeService to set. */ public void setNodeService(NodeService nodeService) { this.nodeService = nodeService; } }