AnsweredAssumed Answered

Alfresco action: create a folder with a name from the uploaded metadata

Question asked by robinho on Mar 4, 2014
Latest reply on Mar 4, 2014 by kaynezhang


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).

Thank you

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
                    }
            }

    }
}

Outcomes