Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion src/main/java/com/twilio/taskrouter/WorkflowRuleTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,37 @@ public class WorkflowRuleTarget extends TaskRouterResource {

@JsonProperty("timeout")
private final Integer timeout;

@JsonProperty("order_by")
private final String orderBy;

@JsonProperty("skip_if")
private final String skipIf;

@JsonCreator
private WorkflowRuleTarget(
@JsonProperty("queue") String queue,
@JsonProperty("expression") String expression,
@JsonProperty("priority") Integer priority,
@JsonProperty("timeout") Integer timeout
@JsonProperty("timeout") Integer timeout,
@JsonProperty("order_by") String orderBy,
@JsonProperty("skip_if") String skipIf
) {
this.queue = queue;
this.expression = expression;
this.priority = priority;
this.timeout = timeout;
this.orderBy = orderBy;
this.skipIf = skipIf;
}

private WorkflowRuleTarget(Builder b) throws IllegalArgumentException {
this.queue = b.queue;
this.expression = b.expression;
this.priority = b.priority;
this.timeout = b.timeout;
this.orderBy = b.orderBy;
this.skipIf = b.skipIf;
}

/**
Expand Down Expand Up @@ -79,6 +91,22 @@ public Integer getTimeout() {
return timeout;
}

/**
* Get the orderBy for the workflow rule target.
* @return the orderBy
*/
public String getOrderBy() {
return orderBy;
}

/**
* Get the skipIf for the workflow rule target.
* @return the skipIf
*/
public String getSkipIf() {
return skipIf;
}

/**
* Return a string representation of this workflow rule target.
* @return string representation of target
Expand All @@ -90,6 +118,8 @@ public String toString() {
.add("expression", expression)
.add("priority", priority)
.add("timeout", timeout)
.add("orderBy", orderBy)
.add("skipIf", skipIf)
.toString();
}

Expand All @@ -111,6 +141,8 @@ public static class Builder {
private String expression;
private Integer priority;
private Integer timeout;
private String orderBy;
private String skipIf;

public Builder(String queue) {
this.queue = queue;
Expand All @@ -130,6 +162,16 @@ public Builder timeout(Integer timeout) {
this.timeout = timeout;
return this;
}

public Builder orderBy(String orderBy) {
this.orderBy = orderBy;
return this;
}

public Builder skipIf(String skipIf) {
this.skipIf = skipIf;
return this;
}

public WorkflowRuleTarget build() {
return new WorkflowRuleTarget(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,26 @@ public void testToJson() throws IOException {
.expression("1==1")
.priority(5)
.timeout(30)
.orderBy("worker.english_level ASC")
.skipIf("workers.available == 0")
.build();

Assert.assertEquals(
"{\"queue\":\"QS123\",\"expression\":\"1==1\",\"priority\":5,\"timeout\":30}",
"{\"queue\":\"QS123\",\"expression\":\"1==1\",\"priority\":5,\"timeout\":30,\"order_by\":\"worker.english_level ASC\",\"skip_if\":\"workers.available == 0\"}",
target.toJson()
);
}

@Test
public void testFromJson() throws IOException {
WorkflowRuleTarget target =
WorkflowRuleTarget.fromJson("{\"queue\":\"QS123\",\"expression\":\"1==1\",\"priority\":5,\"timeout\":30}");
WorkflowRuleTarget.fromJson("{\"queue\":\"QS123\",\"expression\":\"1==1\",\"priority\":5,\"timeout\":30,\"order_by\":\"worker.english_level ASC\",\"skip_if\":\"workers.available == 0\"}");

Assert.assertEquals("QS123", target.getQueue());
Assert.assertEquals("1==1", target.getExpression());
Assert.assertEquals(5, (int)target.getPriority());
Assert.assertEquals(30, (int)target.getTimeout());
Assert.assertEquals("worker.english_level ASC", target.getOrderBy());
Assert.assertEquals("workers.available == 0", target.getSkipIf());
}
}