0

在我的文檔管理過程中,經常需要提供一些額外的文檔(例如評論列表,差異列表,一些截圖等)。如何在工作流程中添加附件?

這些額外的文檔可以方便地添加到Activiti表單中。我希望能夠在業務流程的初始階段和修訂階段添加文檔。

對於這一點,我添加在workflow-model.xml(相關部分)與關聯的方面:

... 
<type name="mswf:activitiRevise"> 
    ... 
    <mandatory-aspects> 
     ... 
     <aspect>mswf:attachments</aspect> 
    </mandatory-aspects> 
</type>   
... 
<aspect name="mswf:attachments"> 
    <associations> 
     <association name="mswf:package"> 
      <source> 
       <mandatory>false</mandatory> 
       <many>true</many> 
      </source> 
      <target> 
       <class>cm:content</class> 
       <mandatory>false</mandatory> 
       <many>true</many> 
      </target> 
     </association> 
    </associations>  
</aspect> 
... 
etc 

share-config-custom.xml我有以下(相關部分):

... 
<config evaluator="task-type" condition="bpm:startTask"> 
    <forms> 
     <form id="workflow-details"> 
      <field-visibility> 
       ... 
       <show id="mswf:package" /> 
      </field-visibility> 
      <appearance> 
       ... 
       <set id="attachments" appearance="title" label-id="Additional docs" /> 
       <field id="mswf:package" set="attachments" /> 
      </appearance> 
     </form> 
     <form> 
      <field-visibility> 
       <show id="mswf:package" /> 
       ... 
      </field-visibility> 
      <appearance> 
       <set id="attachments" appearance="title" label-id="Additional docs" /> 
       <field id="mswf:package" set="attachments" /> 
       ... 
      </appearance> 
     </form> 
    </forms> 
</config> 
... 
etc 

現在我有一個額外的領域,我可以選擇適當的文件。

enter image description here

它的工作原理 - 我加了一些文件,並可以在所有的文檔管理流程的各個階段的看到它們。

當我嘗試更改一組最初選定的文件時,會發生此問題。例如,當我嘗試添加一個新的。如果我添加一個新的(或刪除) - 更改不會保存,並且在下一個任務中,我會看到在開始時選擇的相同文檔。

爲了控制這種行爲,我開發了WebScript,在其中嘗試管理屬性。我打電話從共享的WebScript在getAddedItems()方法:

/** 
* Returns items that have been added to the current value 
* 
* @method getAddedItems 
* @return {array} 
*/ 
getAddedItems: function ObjectFinder_getAddedItems() { 
    var addedItems = [], 
    currentItems = Alfresco.util.arrayToObject(this.options.currentValue.split(",")); 

    for (var item in this.selectedItems) { 
     if (this.selectedItems.hasOwnProperty(item)) { 
      if (!(item in currentItems)) { 
       addedItems.push(item);      
      } 
     } 
    } 

    ... 

    // here the call to the WebScript 

    return addedItems; 
}, 

我的Java支持WebScript的部分:

... 
public class WorkflowAttachmentsManipulator extends DeclarativeWebScript { 
    private static final String WORKFLOW_MODEL_URI = "..."; 
    private WorkflowService workflowService; 

    @Override 
    protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) { 
     Map<String, Object> model = new HashMap<>(); 

     String taskId = req.getParameter("taskId"); 
     String addedItem = req.getParameter("addedItem"); 

     WorkflowTask workflowTask = workflowService.getTaskById(taskId); 
     Map<QName, Serializable> taskProperties = workflowTask.getProperties(); 

     ... 
     taskProperties.replace(
      QName.createQName(WORKFLOW_MODEL_URI, "package"), oldValue, addedItem); 
     workflowService.updateTask(taskId, taskProperties, null, null); 

... 

我試圖與一些任意的,並且replace(...)方法返回更換所選文件true。在alfrescotomcat-stdout.2017-09-06.log我也看到屬性已被替換:

調用WebScript之前(在包兩個文件了):

key: {WORKFLOW_MODEL_URI_HERE}package 
value: [workspace://SpacesStore/7f980005-2a1b-49a5-a8ff-ce9dff31a98a, 
     workspace://SpacesStore/30d9122f-4467-451b-aeab-ca8b164f7769] 

調用WebScript(在包一個文件)後,

key: {WORKFLOW_MODEL_URI_HERE}package 
value: workspace://SpacesStore/1a0b110f-1e09-4ca2-b367-fe25e4964a4e 

在當前任務更新窗體後,我看到我的新文件。

但修改/審查後,該值不會保存(丟失),並在下一個任務中看到相同的文件。比方說,爲當前用戶的任務ID爲activiti$204587,那麼它成爲等於activiti$204647 ...

我添加了一些調試代碼的BPMN圖,發現mswf_package內容的調用WebScript後並沒有改變。

enter image description here

在 '提交',主要配置:

for(var i = 0; i < mswf_package.size(); i++) { 
    logger.log(mswf_package.get(i).nodeRef); 
} 

輸出:

DEBUG [repo.jscript.ScriptLogger] [http-apr-8080-exec-9] workspace://SpacesStore/7f980005-2a1b-49a5-a8ff-ce9dff31a98a 
DEBUG [repo.jscript.ScriptLogger] [http-apr-8080-exec-9] workspace://SpacesStore/30d9122f-4467-451b-aeab-ca8b164f7769 

在 '審查工作',該createcomplete事件偵聽器:

for(var i = 0; i < mswf_package.size(); i++) { 
    logger.log(mswf_package.get(i).nodeRef); 
} 

輸出:

DEBUG [repo.jscript.ScriptLogger] [http-apr-8080-exec-9] workspace://SpacesStore/7f980005-2a1b-49a5-a8ff-ce9dff31a98a 
DEBUG [repo.jscript.ScriptLogger] [http-apr-8080-exec-9] workspace://SpacesStore/30d9122f-4467-451b-aeab-ca8b164f7769 

如何在工作流中添加額外的附件...難道...

我會的信息非常感謝?。謝謝大家。

回答

1

一組與NodeRefs字符串可以傳遞給下面WebScript,例如:

public class WorkflowAttachmentsManipulator extends DeclarativeWebScript { 
    private static final String WORKFLOW_MODEL_URI = "..."; 
    private WorkflowService workflowService; 

    @Override 
    protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) { 
     Map<String, Object> model = new HashMap<>(); 

     String taskId = req.getParameter("taskId"); 
     String addedItems = req.getParameter("addedItems"); 

     String oldValue = ""; 

     WorkflowTask workflowTask = workflowService.getTaskById(taskId); 
     Map<QName, Serializable> taskProperties = workflowTask.getProperties(); 

     Iterator taskIterator = taskProperties.entrySet().iterator(); 
     while(taskIterator.hasNext()) { 
      Map.Entry taskPair = (Map.Entry)taskIterator.next(); 
      Object key = taskPair.getKey(); 
      if(key != null && 
       key.toString().equalsIgnoreCase("{" + WORKFLOW_MODEL_URI + "}package")) { 

       if(taskPair.getValue() != null) { 
        oldValue = taskPair.getValue().toString(); 
        if(!oldValue.equals("[]")) { 
         oldValue = oldValue.replaceAll("[\\[\\]]", ""); 
         addedItems = "[" + oldValue + "," + addedItems + "]"; 
        } else { 

         if(addedItems.indexOf(",") > 0) { 
          addedItems = "[" + addedItems + "]";  
         } 
        } 
       } 

       taskProperties.replace(
        QName.createQName(WORKFLOW_MODEL_URI, "package"), 
        oldValue, 
        addedItems); 

       workflowService.updateTask(workflowTask.getId(), 
        taskProperties, null, null); 

       break; 
      } 
     } 
     ... 
    } 

    public WorkflowService getWorkflowService() { 
     return workflowService; 
    } 

    public void setWorkflowService(WorkflowService workflowService) { 
     this.workflowService = workflowService; 
    } 
} 

此代碼覆蓋附件的某些任務。

其他文件需要區別於文檔管理過程中涉及的文件。這是可以做到,例如,如下:

/** 
* Returns items that have been added to the current value 
* 
* @method getAddedItems 
* @return {array} 
*/ 
getAddedItems: function ObjectFinder_getAddedItems() { 
    var addedItems = [], 
    currentItems = Alfresco.util.arrayToObject(this.options.currentValue.split(",")); 

    var attachments = []; 

    for (var item in this.selectedItems) { 
     if (this.selectedItems.hasOwnProperty(item)) {   
      if (!(item in currentItems)) { 
       // modified for differentiation 
       if (this.options.displayMode == "items") { 
        attachments.push(item); 
       } else { 
        addedItems.push(item);      
       } 
      } 
     } 
    } 

    ... 

    // call to the WebScript with attachments 

    // modified for merge 
    return addedItems.concat(attachments); 
}, 

爲了節省重寫的附件中的過程變量,有必要定義complete事件的監聽器。

此外,也可以由鏈條從任務通過使用這種技術「通過」文件到任務(有改動):

偵聽器complete事件:

public class TaskCompleteListener implements TaskListener { 
    @Override 
    public void notify(DelegateTask delegateTask) { 
     DelegateExecution execution = delegateTask.getExecution();  
     execution.setVariable("mswf_package", delegateTask.getVariable("mswf_package")); 
    } 
} 

收聽者的create事件:

public class TaskCreateListener implements TaskListener { 
    @Override 
    public void notify(DelegateTask delegateTask) { 
     DelegateExecution execution = delegateTask.getExecution(); 
     delegateTask.setVariable("mswf_package", execution.getVariable("mswf_package")); 
    } 
} 

這解決了我的問題。

相關問題