1 5 6 package org.exoplatform.portlets.workflow.component; 7 8 import org.exoplatform.faces.core.component.UIFileUpload; 9 import org.exoplatform.faces.core.component.UIPortlet; 10 import org.exoplatform.faces.core.event.ExoActionEvent; 11 import org.exoplatform.faces.core.event.ExoActionListener; 12 import org.exoplatform.services.workflow.WorkflowDefinitionService; 13 import org.exoplatform.services.workflow.WorkflowServiceContainer; 14 import org.jbpm.JpdlException; 15 16 import javax.faces.context.FacesContext; 17 import javax.portlet.ActionResponse; 18 import javax.portlet.PortletMode; 19 import java.io.ByteArrayInputStream ; 20 import java.io.IOException ; 21 import java.util.Collection ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 import java.util.jar.JarInputStream ; 25 26 31 public class UIWorkflowEdit extends UIPortlet{ 32 33 public static String COMPONENT_ID = "workflow-edit"; 34 private static WorkflowServiceContainer workflowServiceContainer; 35 36 public UIWorkflowEdit(WorkflowServiceContainer serviceContainer, 37 UIFileUpload uiFileUpload) { 38 this.setRendererType("ChildrenRenderer"); 39 this.setId(COMPONENT_ID); 40 workflowServiceContainer = serviceContainer; 41 List children = getChildren(); 42 uiFileUpload.setClazz("UIFileUpload"); 43 uiFileUpload.setNumberOfField(1); 44 uiFileUpload.setRendered(true) ; 45 children.add(uiFileUpload); 46 47 uiFileUpload.addActionListener(ProcessUploadListener.class, UIFileUpload.UPLOAD_ACTION) ; 48 uiFileUpload.addActionListener(CancelListener.class, UIFileUpload.CANCEL_ACTION) ; 49 } 50 51 public static class ProcessUploadListener extends ExoActionListener{ 52 public void execute(ExoActionEvent event) throws Exception { 53 UIFileUpload uiFileUpload = (UIFileUpload) event.getComponent(); 54 Collection processes = uiFileUpload.getUserInputs(); 55 for (Iterator iterator = processes.iterator(); iterator.hasNext();) { 56 UIFileUpload.UserInput userInput = (UIFileUpload.UserInput) iterator.next(); 57 WorkflowDefinitionService workflowDefinitionService = workflowServiceContainer. 58 createWorkflowDefinitionService(); 59 try { 60 JarInputStream iS = new JarInputStream (new ByteArrayInputStream (userInput.getStream())); 61 workflowDefinitionService.deployProcessArchive(iS); 62 } catch (IOException e) { 63 e.printStackTrace(); 64 } catch (JpdlException e) { 65 e.printStackTrace(); 66 } finally { 67 workflowDefinitionService.close(); 68 } 69 } 70 ActionResponse actionResponse = (ActionResponse) FacesContext.getCurrentInstance(). 71 getExternalContext().getResponse(); 72 actionResponse.setPortletMode(PortletMode.VIEW); 73 } 74 } 75 76 public static class CancelListener extends ExoActionListener{ 77 public void execute(ExoActionEvent event) throws Exception { 78 ActionResponse actionResponse = (ActionResponse) FacesContext.getCurrentInstance(). 79 getExternalContext().getResponse(); 80 actionResponse.setPortletMode(PortletMode.VIEW); 81 } 82 } 83 84 } 85 | Popular Tags |