1 package org.infoglue.cms.webservices; 2 3 import java.util.Map ; 4 5 import org.apache.log4j.Logger; 6 import org.infoglue.cms.applications.workflowtool.function.InfoglueFunction; 7 import org.infoglue.cms.controllers.kernel.impl.simple.LanguageController; 8 import org.infoglue.cms.controllers.kernel.impl.simple.UserControllerProxy; 9 import org.infoglue.cms.controllers.kernel.impl.simple.WorkflowController; 10 import org.infoglue.cms.entities.mydesktop.WorkflowVO; 11 import org.infoglue.cms.exception.SystemException; 12 import org.infoglue.cms.security.InfoGluePrincipal; 13 import org.infoglue.cms.util.workflow.WorkflowFacade; 14 import org.infoglue.deliver.util.webservices.DynamicWebserviceSerializer; 15 16 19 20 public class RemoteWorkflowServiceImpl extends RemoteInfoGlueService 21 { 22 25 private final static Logger logger = Logger.getLogger(RemoteWorkflowServiceImpl.class.getName()); 26 27 30 private InfoGluePrincipal principal; 31 32 35 private Map inputs; 36 37 40 public RemoteWorkflowServiceImpl() 41 { 42 super(); 43 } 44 45 57 public Boolean start(final String principalName, final Integer languageId, final String workflowName, final Object [] inputsArray, final Object [] ppp) 58 { 59 try 60 { 61 final DynamicWebserviceSerializer serializer = new DynamicWebserviceSerializer(); 62 initializePrincipal(principalName, workflowName); 63 initializeInputs((Map ) serializer.deserialize(inputsArray), languageId); 64 65 logger.debug("start(" + principalName + "," + workflowName + "," + languageId + "," + inputs + ")"); 66 67 final WorkflowVO workflowVO = WorkflowController.getController().initializeWorkflow(principal, workflowName, 0, inputs); 68 if(hasTerminated(workflowVO)) 69 { 70 logger.debug("The workflow has terminated."); 71 return Boolean.FALSE; 72 } 73 } 74 catch(Throwable t) 75 { 76 System.out.println(t); 77 return Boolean.FALSE; 78 } 79 80 updateCaches(); 81 82 return Boolean.TRUE; 83 } 84 85 91 private boolean hasTerminated(final WorkflowVO workflowVO) 92 { 93 return new WorkflowFacade(principal, workflowVO.getIdAsPrimitive()).isFinished(); 94 } 95 96 102 private void initializeInputs(final Map callerInputs, final Integer languageId) throws SystemException 103 { 104 inputs = callerInputs; 105 inputs.put(InfoglueFunction.PRINCIPAL_PARAMETER, principal); 106 inputs.put(InfoglueFunction.LOCALE_PARAMETER, LanguageController.getController().getLocaleWithId(languageId)); 107 } 108 109 116 private void initializePrincipal(final String userName, final String workflowName) throws SystemException 117 { 118 try 119 { 120 principal = UserControllerProxy.getController().getUser(userName); 121 } 122 catch(SystemException e) 123 { 124 throw e; 125 } 126 catch(Exception e) 127 { 128 throw new SystemException(e); 129 } 130 if(principal == null) 131 { 132 throw new SystemException("No such principal [" + userName + "]."); 133 } 134 if(!WorkflowController.getController().getIsAccessApproved(workflowName, principal)) 135 { 136 throw new SystemException("The principal [" + userName + "] is not allowed to create the [" + workflowName + "] workflow."); 137 } 138 } 139 } 140 | Popular Tags |