package com.effektif.mongo.test;

import com.effektif.mongo.MongoConfiguration;
import com.effektif.workflow.api.Configuration;
import com.effektif.workflow.api.WorkflowEngine;
import com.effektif.workflow.api.activities.*;
import com.effektif.workflow.api.model.ActivityId;
import com.effektif.workflow.api.model.Deployment;
import com.effektif.workflow.api.model.TriggerInstance;
import com.effektif.workflow.api.query.WorkflowInstanceQuery;
import com.effektif.workflow.api.workflow.ExecutableWorkflow;
import com.effektif.workflow.api.workflowinstance.WorkflowInstance;

import java.util.List;

/**
 * Created by Jeroen on 12/06/15.
 */
public class FindByActivityIdTest {

    public static Configuration cachedConfiguration;

    public static void main(String[] args) {

        Configuration mongoConfiguration = new MongoConfiguration()
                .server("localhost")
                .databaseName("effektif");

        cachedConfiguration = mongoConfiguration;

        WorkflowEngine workflowEngine = cachedConfiguration.getWorkflowEngine();

        // Create a workflow
        ExecutableWorkflow workflow1 = new ExecutableWorkflow()
                .sourceWorkflowId("Server test workflow")
                .activity("One", new StartEvent()
                        .transitionToNext())
                .activity("Two", new NoneTask()
                        .transitionToNext())
                .activity("Three", new ReceiveTask()
                        .transitionToNext())
                .activity("Four", new HttpServiceTask()
                        .transitionToNext())
                .activity("Five", new EndEvent());

        Deployment deployment = workflowEngine.deployWorkflow(workflow1);

        TriggerInstance start = new TriggerInstance()
                .workflowId(deployment.getWorkflowId());

        WorkflowInstance workflowInstance = workflowEngine.start(start);

        // Now find all workflowInstances in a particular ActivityId, they should be in "Three"
        WorkflowInstanceQuery workflowInstanceQuery = new WorkflowInstanceQuery()
                .activityId(new ActivityId("Three"));

        WorkflowInstanceQuery workflowInstanceQuery2 = new WorkflowInstanceQuery();
//                .workflowInstanceId(workflowInstance.getId());

        List<WorkflowInstance> workflowInstances = workflowEngine.findWorkflowInstances(workflowInstanceQuery);

        List<WorkflowInstance> workflowInstances2 = workflowEngine.findWorkflowInstances(workflowInstanceQuery2);

        System.out.println("Nr of workflowInstances found: " + workflowInstances.size());
        System.out.println("Nr of workflowInstances found: " + workflowInstances2.size());
    }

}


@@ -221,59 +221,8 @@
 .*;%0A
-import com.effektif.workflow.api.model.ActivityId;%0A
 impo
@@ -268,16 +268,16 @@
 oyment;%0A
+
 import c
@@ -1031,16 +1031,75 @@
 orkflow%0A
+        ExecutableWorkflow f = new ExecutableWorkflow();%0A%0A%0A
         
@@ -2122,31 +2122,16 @@
 yId(
-new ActivityId(
 %22Three%22)
 );%0A%0A
@@ -2126,17 +2126,16 @@
 %22Three%22)
-)
 ;%0A%0A     
@@ -2590,24 +2590,43 @@
 ances.size()
+ + %22 (should be 1)%22
 );%0A        S
@@ -2704,18 +2704,653 @@
 2.size()
-);
+ + %22 (should be 1)%22);%0A%0A        TriggerInstance start2 = new TriggerInstance()%0A                .workflowId(deployment.getWorkflowId());%0A%0A        workflowInstance = workflowEngine.start(start);%0A%0A        List%3CWorkflowInstance%3E workflowInstances3 = workflowEngine.findWorkflowInstances(workflowInstanceQuery2);%0A%0A        System.out.println(%22Nr of workflowInstances found: %22 + workflowInstances.size() + %22 (should be 1)%22);%0A        System.out.println(%22Nr of workflowInstances found: %22 + workflowInstances2.size() + %22 (should be 1)%22);%0A        System.out.println(%22Nr of workflowInstances found: %22 + workflowInstances3.size() + %22 (should be 2)%22);%0A
 %0A    %7D%0A%0A

Change ActivityId to String