WorkflowResource { @GET @Path("/{name}/correlated/{correlationId}") @ApiOperation("Lists workflows for the given correlation id") @Consumes(MediaType.WILDCARD) public List<Workflow> getWorkflows(@PathParam("name") String name, @PathParam("correlationId") String correlationId, @QueryParam("includeClosed") @DefaultValue("false") boolean includeClosed, @QueryParam("includeTasks") @DefaultValue("false") boolean includeTasks) { return workflowService.getWorkflows(name, correlationId, includeClosed, includeTasks); } @Inject  WorkflowResource(WorkflowService workflowService); @POST @Produces({MediaType.TEXT_PLAIN}) @ApiOperation("Start a new workflow with StartWorkflowRequest, which allows task to be executed in a domain") String startWorkflow(StartWorkflowRequest request); @POST @Path("/{name}") @Produces({MediaType.TEXT_PLAIN}) @ApiOperation("Start a new workflow. Returns the ID of the workflow instance that can be later used for tracking") String startWorkflow(@PathParam("name") String name,
                                @QueryParam("version") Integer version,
                                @QueryParam("correlationId") String correlationId,
                                @QueryParam("priority") @DefaultValue("0") Integer priority,
                                Map<String, Object> input); @GET @Path("/{name}/correlated/{correlationId}") @ApiOperation("Lists workflows for the given correlation id") @Consumes(MediaType.WILDCARD) List<Workflow> getWorkflows(@PathParam("name") String name,
                                       @PathParam("correlationId") String correlationId,
                                       @QueryParam("includeClosed") @DefaultValue("false") boolean includeClosed,
                                       @QueryParam("includeTasks") @DefaultValue("false") boolean includeTasks); @POST @Path("/{name}/correlated") @ApiOperation("Lists workflows for the given correlation id list") @Consumes(MediaType.APPLICATION_JSON) Map<String, List<Workflow>> getWorkflows(@PathParam("name") String name,
                                                    @QueryParam("includeClosed") @DefaultValue("false") boolean includeClosed,
                                                    @QueryParam("includeTasks") @DefaultValue("false") boolean includeTasks,
                                                    List<String> correlationIds); @GET @Path("/{workflowId}") @ApiOperation("Gets the workflow by workflow id") @Consumes(MediaType.WILDCARD) Workflow getExecutionStatus(@PathParam("workflowId") String workflowId,
                                       @QueryParam("includeTasks") @DefaultValue("true") boolean includeTasks); @DELETE @Path("/{workflowId}/remove") @ApiOperation("Removes the workflow from the system") @Consumes(MediaType.WILDCARD) void delete(@PathParam("workflowId") String workflowId,
                       @QueryParam("archiveWorkflow") @DefaultValue("true") boolean archiveWorkflow); @GET @Path("/running/{name}") @ApiOperation("Retrieve all the running workflows") @Consumes(MediaType.WILDCARD) List<String> getRunningWorkflow(@PathParam("name") String workflowName,
                                           @QueryParam("version") @DefaultValue("1") Integer version,
                                           @QueryParam("startTime") Long startTime,
                                           @QueryParam("endTime") Long endTime); @PUT @Path("/decide/{workflowId}") @ApiOperation("Starts the decision task for a workflow") @Consumes(MediaType.WILDCARD) void decide(@PathParam("workflowId") String workflowId); @PUT @Path("/{workflowId}/pause") @ApiOperation("Pauses the workflow") @Consumes(MediaType.WILDCARD) void pauseWorkflow(@PathParam("workflowId") String workflowId); @PUT @Path("/{workflowId}/resume") @ApiOperation("Resumes the workflow") @Consumes(MediaType.WILDCARD) void resumeWorkflow(@PathParam("workflowId") String workflowId); @PUT @Path("/{workflowId}/skiptask/{taskReferenceName}") @ApiOperation("Skips a given task from a current running workflow") @Consumes(MediaType.APPLICATION_JSON) void skipTaskFromWorkflow(@PathParam("workflowId") String workflowId,
                                     @PathParam("taskReferenceName") String taskReferenceName,
                                     SkipTaskRequest skipTaskRequest); @POST @Path("/{workflowId}/rerun") @ApiOperation("Reruns the workflow from a specific task") @Consumes(MediaType.APPLICATION_JSON) @Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON}) String rerun(@PathParam("workflowId") String workflowId,
                        RerunWorkflowRequest request); @POST @Path("/{workflowId}/restart") @ApiOperation("Restarts a completed workflow") @Consumes(MediaType.WILDCARD) void restart(@PathParam("workflowId") String workflowId, @QueryParam("useLatestDefinitions") @DefaultValue("false") boolean useLatestDefinitions); @POST @Path("/{workflowId}/retry") @ApiOperation("Retries the last failed task") @Consumes(MediaType.WILDCARD) void retry(@PathParam("workflowId") String workflowId); @POST @Path("/{workflowId}/resetcallbacks") @ApiOperation("Resets callback times of all non-terminal SIMPLE tasks to 0") @Consumes(MediaType.WILDCARD) void resetWorkflow(@PathParam("workflowId") String workflowId); @DELETE @Path("/{workflowId}") @ApiOperation("Terminate workflow execution") @Consumes(MediaType.WILDCARD) void terminate(@PathParam("workflowId") String workflowId,
                          @QueryParam("reason") String reason); @ApiOperation(value = "Search for workflows based on payload and other parameters", notes = "use sort options as sort=<field>:ASC|DESC e.g. sort=name&sort=workflowId:DESC." + " If order is not specified, defaults to ASC.") @GET @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @Path("/search") SearchResult<WorkflowSummary> search(@QueryParam("start") @DefaultValue("0") int start,
                                                @QueryParam("size") @DefaultValue("100") int size,
                                                @QueryParam("sort") String sort,
                                                @QueryParam("freeText") @DefaultValue("*") String freeText,
                                                @QueryParam("query") String query); @ApiOperation(value = "Search for workflows based on task parameters", notes = "use sort options as sort=<field>:ASC|DESC e.g. sort=name&sort=workflowId:DESC." + " If order is not specified, defaults to ASC") @GET @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @Path("/search-by-tasks") SearchResult<WorkflowSummary> searchWorkflowsByTasks(@QueryParam("start") @DefaultValue("0") int start,
                                                                @QueryParam("size") @DefaultValue("100") int size,
                                                                @QueryParam("sort") String sort,
                                                                @QueryParam("freeText") @DefaultValue("*") String freeText,
                                                                @QueryParam("query") String query); @GET @ApiOperation("Get the uri and path of the external storage where the workflow payload is to be stored") @Consumes(MediaType.WILDCARD) @Path("/externalstoragelocation") ExternalStorageLocation getExternalStorageLocation(@QueryParam("path") String path, @QueryParam("operation") String operation, @QueryParam("payloadType") String payloadType);  }
@Test public void getWorkflows() { Workflow workflow = new Workflow(); workflow.setCorrelationId("123"); ArrayList<Workflow> listOfWorkflows = new ArrayList<Workflow>() {{ add(workflow); }}; when(mockWorkflowService.getWorkflows(anyString(), anyString(), anyBoolean(), anyBoolean())).thenReturn(listOfWorkflows); assertEquals(listOfWorkflows, workflowResource.getWorkflows("test1", "123", true, true)); }
@Test public void testGetWorklfowsMultipleCorrelationId() { Workflow workflow = new Workflow(); workflow.setCorrelationId("c123"); List<Workflow> workflowArrayList = new ArrayList<Workflow>() {{ add(workflow); }}; List<String> correlationIdList = new ArrayList<String>() {{ add("c123"); }}; Map<String, List<Workflow>> workflowMap = new HashMap<>(); workflowMap.put("c123", workflowArrayList); when(mockWorkflowService.getWorkflows(anyString(), anyBoolean(), anyBoolean(), anyList())) .thenReturn(workflowMap); assertEquals(workflowMap, workflowResource.getWorkflows("test", true, true, correlationIdList)); }