@Override public List<WorkflowInstanceImpl> findWorkflowInstances(WorkflowInstanceQuery query) { if (query.getWorkflowInstanceId()!=null) { WorkflowInstanceImpl workflowInstance = workflowInstances.get(query.getWorkflowInstanceId()); if (workflowInstance!=null && workflowInstance.isIncluded(query)) { return Lists.of(workflowInstance); } else { return Collections.EMPTY_LIST; } } List<WorkflowInstanceImpl> workflowInstances = new ArrayList<>(); Iterator<WorkflowInstanceImpl> iterator = this.workflowInstances.values().iterator(); int limit = query.getLimit()!=null ? query.getLimit() : Integer.MAX_VALUE; while (iterator.hasNext() && workflowInstances.size()<limit) { WorkflowInstanceImpl workflowInstance = iterator.next(); if (workflowInstance.isIncluded(query)) { workflowInstances.add(workflowInstance); } } return workflowInstances; }
values = (Collection<Object>) value; } else { values = Lists.of(value);
@Test public void testListOfNumbersType() { ExecutableWorkflow workflow = new ExecutableWorkflow() .variable("v", new ListType(new NumberType())); deploy(workflow); WorkflowInstance workflowInstance = workflowEngine.start(new TriggerInstance() .workflowId(workflow.getId()) .data("v", Lists.of(5, 6))); GenericType genericType = new GenericType(List.class, Long.class); List<Long> listOfNumbers = workflowInstance.getVariableValue("v", genericType); assertEquals(new Long(5), listOfNumbers.get(0)); assertEquals(new Long(6), listOfNumbers.get(1)); }
@Test public void testListOfEmailAddressesType() { ExecutableWorkflow workflow = new ExecutableWorkflow() .variable("v", new ListType(new EmailAddressType())); deploy(workflow); WorkflowInstance workflowInstance = workflowEngine.start(new TriggerInstance().workflowId(workflow.getId()) .data("v", Lists.of("info@effektif.com", "sales@effektif.com"))); List<String> value = (List<String>) workflowInstance.getVariableValue("v"); assertEquals("info@effektif.com", value.get(0)); assertEquals("sales@effektif.com", value.get(1)); value = (List<String>)workflowInstance.getVariableValue("v"); assertEquals("info@effektif.com", value.get(0)); assertEquals("sales@effektif.com", value.get(1)); }
@Test public void testListOfDatesType() { ExecutableWorkflow workflow = new ExecutableWorkflow() .variable("v", new ListType(new DateType())); deploy(workflow); long time1 = new Date().getTime(); long time2 = time1+1; WorkflowInstance workflowInstance = workflowEngine.start(new TriggerInstance() .workflowId(workflow.getId()) .data("v", Lists.of(new LocalDateTime(time1), new LocalDateTime(time2)))); List<LocalDateTime> variableValue = (List<LocalDateTime>) workflowInstance.getVariableValue("v"); assertEquals(new LocalDateTime(time1), variableValue.get(0)); assertEquals(new LocalDateTime(time2), variableValue.get(1)); }
@Test public void testListOfMoneyType() { ExecutableWorkflow workflow = new ExecutableWorkflow() .variable("v", new ListType(new MoneyType())); deploy(workflow); WorkflowInstance workflowInstance = workflowEngine.start(new TriggerInstance() .workflowId(workflow.getId()) .data("v", Lists.of( new Money().amount(5d).currency("USD"), new Money().amount(6d).currency("EUR")))); List<Money> moneys = workflowInstance.getVariableValue("v"); assertEquals(new Double(5d), moneys.get(0).getAmount()); assertEquals("USD", moneys.get(0).getCurrency()); assertEquals(new Double(6d), moneys.get(1).getAmount()); assertEquals("EUR", moneys.get(1).getCurrency()); }
@Test public void testListOfLinkType() { ExecutableWorkflow workflow = new ExecutableWorkflow() .variable("v", new ListType(new LinkType())); deploy(workflow); WorkflowInstance workflowInstance = workflowEngine.start( new TriggerInstance().workflowId(workflow.getId()) .data("v", Lists.of( "http://effektif.com/", "http://signavio.com/"))); List<String> links = (List<String>) workflowInstance.getVariableValue("v"); assertEquals("http://effektif.com/", links.get(0)); assertEquals("http://signavio.com/", links.get(1)); }
workflow.variable(new Variable().id("variable05").type(new JavaBeanType(Integer.class))); workflow.variable(new Variable().id("variable06").type(LinkType.INSTANCE).defaultValue("http://example.org/")); workflow.variable(new Variable().id("variable07").type(new ListType(NumberType.INSTANCE)).defaultValue(Lists.of(40, 41, 42))); Money defaultMoneyValue = new Money().currency("EUR").amount(41.99); workflow.variable(new Variable().id("variable08").type(MoneyType.INSTANCE).defaultValue(defaultMoneyValue)); assertEquals(Lists.of(40, 41, 42), workflow.getVariables().get(6).getDefaultValue());
@Test public void testTextTemplateRendersList() { ExecutableWorkflow workflow = new ExecutableWorkflow() .variable("colours", new ListType(TextType.INSTANCE)) .activity("render", new JavaServiceTask() .javaClass(BindingTemplateTest.class) .methodName("setTemplateValue") .argTemplate("Colours: {{colours}}")); deploy(workflow); start(new TriggerInstance() .workflowId(workflow.getId()) .data("colours", Lists.of("red", "orange", "yellow"))); assertEquals("Colours: \n\n* red\n* orange\n* yellow\n\n", templateValue); }
@Test public void testUnspecified() { Unspecified unspecified = new Unspecified() .left(new Binding<>().expression("left")) .right(new Binding<>().expression("right")) // single condition .condition(new Equals().leftExpression("one").rightExpression("two")); // multiple conditions unspecified.setConditions(Lists.of( new Equals().leftExpression("three").rightExpression("four"), new Equals().leftExpression("five").rightExpression("six"))); unspecified = serialize(unspecified, Unspecified.class); assertNotNull(unspecified.getLeft()); assertEquals("left", unspecified.getLeft().getExpression()); assertNotNull(unspecified.getRight()); assertEquals("right", unspecified.getRight().getExpression()); // single and multiple conditions end up all in multiple conditions if the list is bigger than 1 assertNull(unspecified.getCondition()); assertNotNull(unspecified.getConditions()); assertEquals(3, unspecified.getConditions().size()); assertEquals("one", ((Equals) unspecified.getConditions().get(0)).getLeft().getExpression()); assertEquals("two", ((Equals) unspecified.getConditions().get(0)).getRight().getExpression()); assertEquals("three", ((Equals) unspecified.getConditions().get(1)).getLeft().getExpression()); assertEquals("four", ((Equals) unspecified.getConditions().get(1)).getRight().getExpression()); assertEquals("five", ((Equals) unspecified.getConditions().get(2)).getLeft().getExpression()); assertEquals("six", ((Equals) unspecified.getConditions().get(2)).getRight().getExpression()); }
@Test public void testMultiInstanceBasics() throws Exception { ExecutableWorkflow workflow = new ExecutableWorkflow() .variable("reviewers", new ListType(TextType.INSTANCE)) .activity("Review", msgExpression("reviewer") .multiInstance(new MultiInstance() .valuesExpression("reviewers") .variable("reviewer", TextType.INSTANCE))); deploy(workflow); WorkflowInstance workflowInstance = workflowEngine.start(new TriggerInstance() .workflowId(workflow.getId()) .data("reviewers", Lists.of( "jack", "john", "mary"))); assertTrue(workflowInstance.isEnded()); assertEquals("jack", getMessage(0)); assertEquals("john", getMessage(1)); assertEquals("mary", getMessage(2)); } }