Skip to content

feat: add 'order_by' and 'skip_if' parameters in WorkflowRuleTarget #504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 6, 2019
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());
}
}