Skip to content

Commit

Permalink
Merge #94
Browse files Browse the repository at this point in the history
  • Loading branch information
jsyrjala committed Jan 15, 2015
2 parents e4be7a7 + a3d52bd commit 63a7df1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- Use more optimal SQL when polling workflows when database supports update returning syntax
- Only rollback poll operation when no workflows could be allocated for executing (when multiple pollers compete for same workflows)
- Allow configuring executor queue length with _nflow.dispatcher.executor.queue.size_
- nflow-rest:
- Add support for user-provided action description when updating a workflow instance

## 1.2.0 (2014-12-23)

Expand Down
2 changes: 1 addition & 1 deletion nflow-jetty/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<nflow.explorer.version>0.0.3</nflow.explorer.version>
<nflow.explorer.version>0.0.4</nflow.explorer.version>
<swagger.ui.version>2.0.24</swagger.ui.version>
</properties>
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import static javax.ws.rs.core.Response.noContent;
import static javax.ws.rs.core.Response.status;
import static javax.ws.rs.core.Response.Status.CONFLICT;
import static org.apache.commons.lang3.StringUtils.defaultIfBlank;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.trimToEmpty;
import static org.apache.commons.lang3.StringUtils.trimToNull;
import static org.joda.time.DateTime.now;
Expand Down Expand Up @@ -86,14 +88,18 @@ public Response updateWorkflowInstance(
@PathParam("id") int id,
UpdateWorkflowInstanceRequest req) {
WorkflowInstance.Builder builder = new WorkflowInstance.Builder().setId(id);
String msg = "";
String msg = defaultIfBlank(req.actionDescription, "");
if (!isEmpty(req.state)) {
builder.setState(req.state);
msg = "API changed state to " + req.state + ". ";
if (isBlank(req.actionDescription)) {
msg = "API changed state to " + req.state + ". ";
}
}
if (req.nextActivationTime != null) {
builder.setNextActivation(req.nextActivationTime);
msg += "API changed nextActivationTime to " + req.nextActivationTime + ".";
if (isBlank(req.actionDescription)) {
msg += "API changed nextActivationTime to " + req.nextActivationTime + ".";
}
}
if (msg.isEmpty()) {
return noContent().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public class UpdateWorkflowInstanceRequest {
@ApiModelProperty(value = "New next activation time for next workflow instance processing", required=false)
public DateTime nextActivationTime;

@ApiModelProperty(value = "Description of the action", required = false)
public String actionDescription;
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,18 @@ public void whenUpdatingStateUpdateWorkflowInstanceWorks() {
req.state = "newState";
resource.updateWorkflowInstance(3, req);
verify(workflowInstances).updateWorkflowInstance((WorkflowInstance) argThat(hasField("state", equalTo(req.state))),
(WorkflowInstanceAction)argThat(hasField("stateText", equalTo("API changed state to newState."))));
(WorkflowInstanceAction) argThat(hasField("stateText", equalTo("API changed state to newState."))));
}

@Test
public void whenUpdatingStateWithDescriptionUpdateWorkflowInstanceWorks() {
when(workflowInstances.getWorkflowInstance(3)).thenReturn(i);
UpdateWorkflowInstanceRequest req = new UpdateWorkflowInstanceRequest();
req.state = "newState";
req.actionDescription = "description";
resource.updateWorkflowInstance(3, req);
verify(workflowInstances).updateWorkflowInstance((WorkflowInstance) argThat(hasField("state", equalTo(req.state))),
(WorkflowInstanceAction) argThat(hasField("stateText", equalTo("description"))));
}

@Test
Expand All @@ -93,10 +104,22 @@ public void whenUpdatingNextActivationTimeUpdateWorkflowInstanceWorks() {
UpdateWorkflowInstanceRequest req = new UpdateWorkflowInstanceRequest();
req.nextActivationTime = new DateTime(2014,11,12,17,55,0);
resource.updateWorkflowInstance(3, req);
verify(workflowInstances).updateWorkflowInstance((WorkflowInstance) argThat(hasField("state", equalTo(null))),
(WorkflowInstanceAction)argThat(hasField("stateText", equalTo("API changed nextActivationTime to " + req.nextActivationTime + "."))));
verify(workflowInstances).updateWorkflowInstance(
(WorkflowInstance) argThat(hasField("state", equalTo(null))),
(WorkflowInstanceAction) argThat(hasField("stateText", equalTo("API changed nextActivationTime to "
+ req.nextActivationTime + "."))));
}

@Test
public void whenUpdatingNextActivationTimeWithDescriptionUpdateWorkflowInstanceWorks() {
when(workflowInstances.getWorkflowInstance(3)).thenReturn(i);
UpdateWorkflowInstanceRequest req = new UpdateWorkflowInstanceRequest();
req.nextActivationTime = new DateTime(2014, 11, 12, 17, 55, 0);
req.actionDescription = "description";
resource.updateWorkflowInstance(3, req);
verify(workflowInstances).updateWorkflowInstance((WorkflowInstance) argThat(hasField("state", equalTo(null))),
(WorkflowInstanceAction) argThat(hasField("stateText", equalTo("description"))));
}

@SuppressWarnings("unchecked")
@Test
Expand Down

0 comments on commit 63a7df1

Please sign in to comment.