cancel
Showing results for 
Search instead for 
Did you mean: 

System created nodes

blackout
Champ in-the-making
Champ in-the-making
Good day,

two questions:

First: is there a way to have the system creating folders during a workflow? If yes, how?

Second: I built up this process definition:
<?xml version="1.0" encoding="UTF-8"?>

<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="wf:goprocessdefinition">
   
   <swimlane name="sales" />
   
   <swimlane name="reception">
      <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
         <actor>#{people.getPerson("receptionuser1")}</actor>
      </assignment>
   </swimlane>
   
   <swimlane name="planner">
      <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
         <actor>#{people.getPerson("planneruser1")}</actor>
      </assignment>
   </swimlane>
   
   <start-state name="start">
      <task name="wf:startGoFlow" swimlane="sales"/>
      <transition name="" to="addCustomerProjectFolders">
         <!– Send email –>
      </transition>
   </start-state>
   
   <state name="addCustomerProjectFolders">
      <transition name="" to="updatePipeline">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
                  var folders = companyhome.childrenByXPath("*[@cm:name='Test Space']/
                                                   *[@cm:name='Gare']");
                  var gareFolder = folders[0];
                  
                  if (gareFolder != null)
                  {
                     folders = gareFolder.childrenByXPath("*[@cm:name='" + wf_customerName + "']");
                     var customerFolder = folders[0];
                     if (customerFolder == null)
                     {
                        customerFolder = gareFolder.createFolder(wf_customerName);
                        customerFolder.setInheritsPermissions(false);
                        customerFolder.removePermission("All");
                        customerFolder.setPermission("Read");
                        customerFolder.setPermission("Write", "receptionuser1");
                        customerFolder.setPermission("AddChildren", "receptionuser1");
                     }
                     
                     if (customerFolder != null)
                     {
                        folders = customerFolder.childrenByXPath("*[@cm:name='" + wf_projectName + "']");
                        var projectFolder = folders[0];
                        if (projectFolder == null)
                        {
                           projectFolder = customerFolder.createFolder(wf_projectName);
                           projectFolder.setInheritsPermissions(false);
                           projectFolder.removePermission("All");
                           projectFolder.setPermission("Read");
                           projectFolder.setPermission("Write", "receptionuser1");
                           projectFolder.setPermission("AddChildren", "receptionuser1");
                        }
                     }
                  }
            </script>
         </action>
      </transition>
   </state>
   
   <task-node name="updatePipeline">
      <task name="wf:updatePipelineTask" swimlane="reception"/>
      <transition name="" to="handleable" />
   </task-node>
   
   <decision name="handleable">
      <transition name="yesItIs" to="addDDGOTEFolders">
         <condition>#{wf_handleable}</condition>
      </transition>
      <transition name="noIsNot" to="archiveProject" />
   </decision>
   
   <state name="addDDGOTEFolders">
        <transition name="" to="selTeamLeader">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               var folders = companyhome.childrenByXPath("*[@cm:name='Test Space']/
                                                *[@cm:name='Gare']/
                                                *[@cm:name='" + wf_customerName + "']/
                                                *[@cm:name='" + wf_projectName + "']");
               var projectFolder = folders[0];
               if (projectFolder != null)
               {
                  folders = projectFolder.childrenByXPath("*[@cm:name='Documenti di gara']");
                  var documentiDiGara = folders[0];
                  if (documentiDiGara == null)
                  {
                     documentiDiGara = projectFolder.createFolder("Documenti di gara");
                     documentiDiGara.setInheritsPermissions(false);
                     documentiDiGara.removePermission("All");
                     documentiDiGara.setPermission("Read");
                     documentiDiGara.setPermission("Write", "receptionuser1");
                     documentiDiGara.setPermission("AddChildren", "receptionuser1");
                  }
                  
                  folders = projectFolder.childrenByXPath("*[@cm:name='Offerta tecnico economica']");
                  var offertaTecnicoEconomica = folders[0];
                  if (offertaTecnicoEconomica == null)
                  {
                     offertaTecnicoEconomica = projectFolder.createFolder("Offerta tecnico economica");
                     offertaTecnicoEconomica.setInheritsPermissions(false);
                     offertaTecnicoEconomica.removePermission("All");
                     offertaTecnicoEconomica.setPermission("Read");
                     offertaTecnicoEconomica.setPermission("Write", "salesuser1");
                     offertaTecnicoEconomica.setPermission("AddChildren", "salesuser1");
                  }
               }
            </script>
           </action>
        </transition>
   </state>
   
   <state name="archiveProject">
      <!– Script per l'archiviazione –>
      <transition name="" to="end"/>
   </state>
   
   <task-node name="selTeamLeader">
      <task name="wf:selTeamLeaderTask" swimlane="planner" />
      <transition name="" to="addOTEPermissions">
         <!– Send email –>
      </transition>
   </task-node>
   
   <state name="addOTEPermissions">
        <transition name="" to="end">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               var folders = companyhome.childrenByXPath("*[@cm:name='Test Space']/
                                                *[@cm:name='Gare']/
                                                *[@cm:name='" + wf_customerName + "']/
                                                *[@cm:name='" + wf_projectName + "']/
                                                *[@cm:name='Offerta tecnico economica']");
               var offertaTecnicoEconomica = folders[0];
               offertTecnicoEconomica.removePermission("All");
               offertaTecnicoEconomica.setPermission("Write", bpm_assignee);
               offertaTecnicoEconomica.setPermission("AddChildren", bpm_assignee);
            </script>
           </action>
        </transition>
   </state>
   
   <end-state name="end" />
   
</process-definition>
Does the <state> work in Alfresco? If yes, is it performed by the system or not?

Thanks in advance.
3 REPLIES 3

davidc
Star Contributor
Star Contributor
First: is there a way to have the system creating folders during a workflow? If yes, how?

Yes - you can write Javascript to create folders.  Javascript may be placed into the workflow definition wherever an action is allowed e.g. on transitions, on events, or on node entry.

To define system steps i.e. steps which are automatically entered, executed and exited by the system without user intervention, use the following pattern:

   
  <node name="auto">
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
        <script>
           // some arbitrary javascript e.g. create folder

           // exit node - here we exit via the default transition
           // or executionContext.leaveNode(transitionName)
           executionContext.leaveNode();
        </script>
      </action>
      <transition name="" to="next"/>
   </node>

Replace your <state> entries with the above.

blackout
Champ in-the-making
Champ in-the-making
Thanks for your answer,

it works with <node> instead of <state>, but if I check the Space Details of the folder created by that node, the Creator is always the user in the current swimlane (if you read the process definition above, the addCustomerProjectFolders is performed by the user of the sales swimlane), so the problem of the permissions on folder stands still.

Let me try to be more clear: I need the System itself (or an admin user) to be the Creator of the folders, so that I can set permissions as I prefere.
In the above definition, the receptionuser1 decides if the variable wf_handleable is true or false, if is true, the same receptionuser1 (during the execution of the addDDGOTEFolders) creates the folders and modifies the permissions (everyone can read, only salesuser1 has write permission over "Offerta Tecnico Economica" folder). Later in the workflow, a folder is created under "Offerta Tecnico Economica", and it has to be accessible to an assigned user, but is impossible for planneruser1 to set permission since he has only read access on the folder. I thought that if the System could create the folders instead of the current user I could avoid problems as this. Is this possible?

Thanks

P.S.: please, let me know if I was not clear enaugh, is quite hard for me to explain this problem.

davidc
Star Contributor
Star Contributor
Currently, there's no support for "run as" in a workflow definition.

A workaround is to develop a Java action which creates the folder.  With our Java API, you can "run as".

Or you could extend our Javascript action to add a "run as" parameter.  Take a look at the class:

org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript