@Before public void setup() { for (int customerId = 1; customerId <= 5; customerId++) { ProcessInstance pi = sf.getWorkflowService() .startProcess(new QName(MODEL_NAME2, "OrderCreation").toString(), null, true); List<ActivityInstance> w = getWorklist(); Assert.assertEquals("worklist", 1, w.size()); ActivityInstance ai = w.get(0); Assert.assertEquals("process instance", pi.getOID(), ai.getProcessInstanceOID()); Assert.assertEquals("activity instance", "EnterOrderData", ai.getActivity().getId()); Map<String, Object> order = CollectionUtils.newMap(); order.put("date", new Date()); order.put("customerId", customerId); ai = complete( ai, PredefinedConstants.DEFAULT_CONTEXT, Collections.singletonMap("Order", order)); try { ProcessInstanceStateBarrier.instance().await(pi.getOID(), ProcessInstanceState.Completed); } catch (Exception e) { } w = getWorklist(); } }
/** * 采用活动定义、流程实例以及活动参与者ID号构造 * * @param define 活动定义 * @param process 流程实例 * @param person 活动参与者 */ public ActivityInstance( ActivityDef define, ProcessInstance process, String actorExpression, String sender, String sendid, ActivityInstance foreActivityIns) throws Exception { this.define = define; this.defid = define.getID(); this.process = process; this.actorexpression = actorExpression; this.processName = this.process.getName(); this.defname = this.define.getName(); // 活动发送人,发送时间 this.setSender(sender); this.setSenderId(sendid); this.setSendTime(new Date()); this.foreActivityInstance = foreActivityIns; // 设置活动状态 state = "开始活动"; // 添加到流程中 process.add(this); }
/* * Helper methods */ public static Activity activity(Process process, ProcessInstance instance, Task task) throws StatusCodeError { Activity activity = null; if (process.isAllowPerInstanceActivities() && task != null && task.getTaskDefinitionKey() != null && instance != null) { Map<String, Activity> activityMap = instance.getActivityMap(); if (activityMap != null) activity = activityMap.get(task.getTaskDefinitionKey()); if (activity != null) return activity; } ProcessDeployment deployment = process.getDeployment(); if (deployment == null) throw new InternalServerError(Constants.ExceptionCodes.process_is_misconfigured); String activityKey = deployment.getStartActivityKey(); if (task != null) activityKey = task.getTaskDefinitionKey(); if (activityKey != null) activity = deployment.getActivity(activityKey); if (activity != null) return activity; throw new InternalServerError(Constants.ExceptionCodes.process_is_misconfigured); }
public static void main(String[] args) throws Exception { ProcessDefinition process = new ProcessDefinition(); Role role = new Role(); role.setName("unpayedFactService"); role.setDefaultEndpoint("http://localhost:8080/axis/UnpayedUserQueryService.jws"); process.setRoles(new Role[] {role}); ProcessVariable var1 = new ProcessVariable(); var1.setName("unpayedFactReturn"); var1.setType(String.class); process.setProcessVariables(new ProcessVariable[] {var1}); ServiceDefinition sd = new ServiceDefinition(); sd.setName("unpayedFactService"); sd.setWsdlLocation("http://localhost:8080/axis/UnpayedUserQueryService.jws?wsdl"); WebServiceActivity wsAct = new WebServiceActivity(); wsAct.setOperationName("getUnpayedFact"); wsAct.setRole(role); wsAct.setService(sd); wsAct.setParameters(new Object[] {"7709211907315"}); wsAct.setOutput(var1); wsAct.setPortType("UnpayedUserQueryService"); process.addChildActivity(wsAct); process.afterDeserialization(); // (ProcessDefinition) GlobalContext.deserialize(new FileInputStream(""), // ProcessDefinition.class); ProcessInstance instance = new DefaultProcessInstance(); instance.setProcessDefinition(process); instance.setProcessTransactionContext(new SimulatorTransactionContext()); instance.execute(); }
@SuppressWarnings("unchecked") private List<ActivityInstance> getWorklist(ProcessInstance pi, EvaluationPolicy... policies) { WorkflowService ws = sf.getWorkflowService(); WorklistQuery query = WorklistQuery.findCompleteWorklist(); if (policies != null) { for (EvaluationPolicy policy : policies) { query.setPolicy(policy); } } query.getFilter().add(new ProcessInstanceFilter(pi.getOID(), false)); Worklist worklist = ws.getWorklist(query); return worklist.getCumulatedItems(); }
public Builder instance(ProcessInstance instance, ViewContext context) { if (instance != null) { String processDefinitionKey = instance.getProcessDefinitionKey(); String processInstanceId = instance.getProcessInstanceId(); Set<Attachment> attachments = instance.getAttachments(); this.processInstanceId = processInstanceId; this.activation = context.getApplicationUri( ProcessInstance.Constants.ROOT_ELEMENT_NAME, processDefinitionKey, processInstanceId, "activation"); this.attachment = context.getApplicationUri( ProcessInstance.Constants.ROOT_ELEMENT_NAME, processDefinitionKey, processInstanceId, Attachment.Constants.ROOT_ELEMENT_NAME); this.cancellation = context.getApplicationUri( ProcessInstance.Constants.ROOT_ELEMENT_NAME, processDefinitionKey, processInstanceId, "cancellation"); this.history = context.getApplicationUri( ProcessInstance.Constants.ROOT_ELEMENT_NAME, processDefinitionKey, processInstanceId, History.Constants.ROOT_ELEMENT_NAME); this.restart = context.getApplicationUri( ProcessInstance.Constants.ROOT_ELEMENT_NAME, processDefinitionKey, processInstanceId, "restart"); this.suspension = context.getApplicationUri( ProcessInstance.Constants.ROOT_ELEMENT_NAME, processDefinitionKey, processInstanceId, "suspension"); this.bucketUrl = context.getApplicationUri( ProcessInstance.Constants.ROOT_ELEMENT_NAME, processDefinitionKey, processInstanceId, "value/Bucket"); if (attachments != null && !attachments.isEmpty()) { PassthroughSanitizer passthroughSanitizer = new PassthroughSanitizer(); this.attachmentCount = attachments.size(); this.attachments = new ArrayList<Attachment>(attachments.size()); for (Attachment attachment : attachments) { this.attachments.add( new Attachment.Builder(attachment, passthroughSanitizer) .processDefinitionKey(processDefinitionKey) .processInstanceId(processInstanceId) .build(context)); } } else { this.attachmentCount = instance.getAttachmentIds().size(); } } return this; }
public Token startScenario() { ProcessDefinition pd = milestoneProcessDefinition; ProcessInstance pi = new ProcessInstance(pd); pi.signal(); return pi.getRootToken(); }
public void executeActivity(ProcessInstance instance) throws Exception { try { Thread.currentThread().setContextClassLoader(GlobalContext.getComponentClassLoader()); if (getStublessInvocation()) { ServiceDefinition sd = getService(); String wsdlUrl = sd.getWsdlLocation(); WSDLReader reader = (new WSDLFactoryImpl()).newWSDLReader(); reader.readWSDL(wsdlUrl); Object[] actualParameters = getActualParameters(instance); String endpoint = ""; try { endpoint = role.getMapping(instance, getTracingTag()).getEndpoint(); } catch (Exception e) { throw new UEngineException("Couldn't get the endpoint to invoke WS", e); } WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); WSIFService service = factory.getService(wsdlUrl, null, null, endpoint, null); WSIFPort port = service.getPort(); WSIFOperation operation = port.createOperation(getOperationName()); WSIFMessage input = operation.createInputMessage(); WSIFMessage output = operation.createOutputMessage(); WSIFMessage fault = operation.createFaultMessage(); Message me = input.getMessageDefinition(); Map partList = me.getParts(); Set set = partList.keySet(); int i = 0; for (Iterator iter = set.iterator(); iter.hasNext(); i++) { String partName = (String) iter.next(); input.setObjectPart(partName, actualParameters[i]); } if (operation.executeRequestResponseOperation(input, output, fault)) { String partName = (String) output.getPartNames().next(); Object result = output.getObjectPart(partName); ProcessVariable outputVar = getOutput(); outputVar.set(instance, "", (Serializable) result); System.out.println("result=" + result); } else { throw new UEngineException(fault.toString()); } } else { ServiceProvider sp = GlobalContext.getServiceProvider(getService(), getPortType()); System.out.println( "role is null? " + role + " rolemapping is null?" + role.getMapping(instance, getTracingTag())); String endpoint = role.getMapping(instance, getTracingTag()).getEndpoint(); System.out.println("invoking endpoint? " + endpoint); Object[] actualParameters = getActualParameters(instance); Object res = sp.invokeService(endpoint, operationName, actualParameters); if (res != null && getOutput() != null) instance.set("" /* getTracingTag() */, getOutput().getName(), (java.io.Serializable) res); } fireComplete(instance); } catch (Exception e) { throw new UEngineException("WebServiceActivity:: fail to replace the classloader", e); } }
@Override public boolean isEnded() { return processInstance.getState() == ProcessInstance.STATE_COMPLETED; }
/** * Fires a element even if it is not enabled. When the element has duplicates, it looks ahead to * set which duplicate to fire. * * <p><b>Note:</b> The element MUST be in the net. * * @param element element to be fired. * @param pi process instance where the element to be fired is. * @param elementPositionInPi element position. * @return int number of tokens that needed to be added to fire this element. */ public int fire(int element, ProcessInstance pi, int elementPositionInPi) { int addedTokens = 0; int elementDuplicates; if ((hNet.getReverseDuplicatesMapping()[element]).size() == 1) { elementDuplicates = hNet.getReverseDuplicatesMapping()[element].get(0); } else { // identify which duplicate to fire HNSubSet duplicates = hNet.getReverseDuplicatesMapping()[element].deepCopy(); // getting the duplicates that are enabled for (int i = 0; i < duplicates.size(); i++) { if (!isEnabled(duplicates.get(i))) { duplicates.remove(duplicates.get(i)); } } if (duplicates.size() > 0) { if (duplicates.size() == 1) { elementDuplicates = duplicates.get(0); } else { // getting the output tasks of the duplicates. These output // are used to // look ahead at the process instance HNSubSet unionMappedToATEsCode = getAllOutputElementsOfDuplicates(duplicates); AuditTrailEntryList ATEntriesList = pi.getAuditTrailEntryList(); // advancing the pointer in the ATEntries till the current // element + 1 AuditTrailEntry ATEntry; int elementInATE = -1; for (int i = elementPositionInPi + 1; i < ATEntriesList.size(); i++) { try { ATEntry = ATEntriesList.get(i); elementInATE = this.hNet .getLogEvents() .findLogEventNumber(ATEntry.getElement(), ATEntry.getType()); if (unionMappedToATEsCode.contains(elementInATE)) { break; } } catch (IOException ex) { break; } catch (IndexOutOfBoundsException ex) { break; } } elementDuplicates = identifyDuplicateToFire(duplicates, elementInATE); } } else { // because no duplicate is enabled, a random one is chosen to // fire... elementDuplicates = (hNet.getReverseDuplicatesMapping()[element]) .get(generator.nextInt(hNet.getReverseDuplicatesMapping()[element].size())); } } bestCombination = findBestSetTasks(elementDuplicates); addedTokens += bestCombination.getNumberMissingTokens(); removeTokensOutputPlaces(elementDuplicates, bestCombination.getTasks()); addTokensOutputPlaces(elementDuplicates); addToPossiblyEnabledElements(elementDuplicates); // registering the firing of element... hNet.increaseElementActualFiring( elementDuplicates, MethodsForWorkflowLogDataStructures.getNumberSimilarProcessInstances(pi)); // updating the arc usage for the individual... hNet.increaseArcUsage( bestCombination.getElementToFire(), bestCombination.getTasks(), MethodsForWorkflowLogDataStructures.getNumberSimilarProcessInstances(pi)); return addedTokens; }