Question

I want to run an action (with a rule) when a file enters the folder in my alfresco repository. The file needs to be moved to a new folder. The new folder will be named after the metadata property "subject" from the file I uploaded.

I am not able to figure out how to do this. Who got any tips? (A repository webscript is also an option).

This is how I see it:

import java.util.List;

public class MoveExecuter extends ActionExecuterAbstractBase {
public static final String DESTINATION_FOLDER = "destination-folder";

private FileFolderService fileFolderService;
private NodeService nodeService;

@Override
protected void addParameterDefinitions(List<ParameterDefinition> paramList) {
    paramList.add(
        new ParameterDefinitionImpl(DESTINATION_FOLDER,
                                    DataTypeDefinition.NODE_REF,
                                    true,
                                    getParamDisplayLabel(METADATA VALUE FROM FIELD SUBJECT FROM INCOMING FILE)));}


   public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) {
   NodeRef destinationParent = (NodeRef)ruleAction.getParameterValue(DESTINATION_FOLDER);


            // if the node exists
            if (this.nodeService.exists(destinationParent) == true) {
                try {
                    fileFolderService.move(incomingfile, destinationParent, null);
                } catch (FileNotFoundException e) {
                    // Do nothing
                }
                if (this.nodeService.exists(destinationParent) == false) {
                    try {
                       nodeService.createNode(parentRef, assocTypeQName, assocQName, "metadata field subject");
                        fileFolderService.move(incomingfile, destinationParent, null);
                    } catch (FileNotFoundException e) {
                        // Do nothing
                    }
            }

    }
}
Was it helpful?

Solution

For such a simple action I'd just use a JavaScript instead of a java Action.

Install the JavaScript addon from googlecode or github (newer version) And just write your Javascript code according the api and run it in runtime in the console to test your code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top