cancel
Showing results for 
Search instead for 
Did you mean: 

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

robinho
Champ in-the-making
Champ in-the-making


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

    }
}

1 REPLY 1

kaynezhang
World-Class Innovator
World-Class Innovator
You can write a javascript and configure a rule on the folder that will execute your javascript.
In your javascript do following:
1.extract property "subject" from the file you upload.
2.Check if a folder named after the property "subject" exists
3.If the folder exists ,move your upload file to the folder.if it dose not exist ,create it and move your upload file to it.