FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix handling of empty string for instant + refactor to asString by vzickner · Pull Request #4 · flowable/flowable-external-client-java · GitHub

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

Filter by extension

Filter by extension .java  (5) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -109,34 +109,34 @@ protected List<AcquiredExternalWorkerJob> asList(String response) {

protected AcquiredExternalWorkerJob asJob(ObjectNode jobNode) {
BaseAcquiredExternalWorkerJob job = new BaseAcquiredExternalWorkerJob();
job.setId(jobNode.path("id").asText(null));
job.setCorrelationId(jobNode.path("correlationId").asText(null));
job.setId(jobNode.path("id").asString(null));
job.setCorrelationId(jobNode.path("correlationId").asString(null));
job.setRetries(jobNode.path("retries").asInt(0));

if (jobNode.hasNonNull("processInstanceId")) {
job.setScopeId(jobNode.path("processInstanceId").asText(null));
job.setScopeId(jobNode.path("processInstanceId").asString(null));
job.setScopeType("bpmn");
job.setSubScopeId(jobNode.path("executionId").asText(null));
job.setScopeDefinitionId(jobNode.path("processDefinitionId").asText(null));
job.setSubScopeId(jobNode.path("executionId").asString(null));
job.setScopeDefinitionId(jobNode.path("processDefinitionId").asString(null));
} else {
job.setScopeId(jobNode.path("scopeId").asText(null));
job.setScopeType(jobNode.path("scopeType").asText(null));
job.setSubScopeId(jobNode.path("subScopeId").asText(null));
job.setScopeDefinitionId(jobNode.path("scopeDefinitionId").asText(null));
job.setScopeId(jobNode.path("scopeId").asString(null));
job.setScopeType(jobNode.path("scopeType").asString(null));
job.setSubScopeId(jobNode.path("subScopeId").asString(null));
job.setScopeDefinitionId(jobNode.path("scopeDefinitionId").asString(null));
}

job.setTenantId(jobNode.path("tenantId").asText(null));
job.setTenantId(jobNode.path("tenantId").asString(null));

job.setElementId(jobNode.path("elementId").asText(null));
job.setElementName(jobNode.path("elementName").asText(null));
job.setElementId(jobNode.path("elementId").asString(null));
job.setElementName(jobNode.path("elementName").asString(null));

job.setExceptionMessage(jobNode.path("exceptionMessage").asText(null));
job.setExceptionMessage(jobNode.path("exceptionMessage").asString(null));

job.setCreateTime(asInstant(jobNode.path("createTime").asText(null)));
job.setDueDate(asInstant(jobNode.path("dueDate").asText(null)));
job.setCreateTime(asInstant(jobNode.path("createTime").asString(null)));
job.setDueDate(asInstant(jobNode.path("dueDate").asString(null)));

job.setWorkerId(jobNode.path("lockOwner").asText(null));
job.setLockExpirationTime(asInstant(jobNode.path("lockExpirationTime").asText(null)));
job.setWorkerId(jobNode.path("lockOwner").asString(null));
job.setLockExpirationTime(asInstant(jobNode.path("lockExpirationTime").asString(null)));

JsonNode variablesNode = jobNode.path("variables");
if (variablesNode.isArray() && !variablesNode.isEmpty()) {
Expand All @@ -147,7 +147,7 @@ protected AcquiredExternalWorkerJob asJob(ObjectNode jobNode) {
}

protected Instant asInstant(String value) {
if (value == null) {
if (value == null || value.isEmpty()) {
return null;
}

Expand All @@ -157,12 +157,12 @@ protected Instant asInstant(String value) {
protected void parseVariables(ArrayNode variablesNode, BiConsumer<String, Object> variableConsumer) {
for (JsonNode variableNode : variablesNode) {

String variableName = variableNode.path("name").asText(null);
String variableName = variableNode.path("name").asString(null);
if (variableName == null || variableName.isEmpty()) {
continue;
}

String type = variableNode.path("type").asText(null);
String type = variableNode.path("type").asString(null);
JsonNode valueNode = variableNode.path("value");

variableConsumer.accept(variableName, parseVariableValue(type, valueNode));
Expand All @@ -175,15 +175,15 @@ protected Object parseVariableValue(String type, JsonNode valueNode) {
}

return switch (type) {
case "string" -> valueNode.textValue();
case "string" -> valueNode.stringValue();
case "json" -> valueNode;
case "boolean" -> valueNode.booleanValue();
case "double" -> valueNode.doubleValue();
case "long" -> valueNode.longValue();
case "date" -> Date.from(Instant.parse(valueNode.textValue()));
case "instant" -> Instant.parse(valueNode.textValue());
case "localDate" -> LocalDate.parse(valueNode.textValue());
case "localDateTime" -> LocalDateTime.parse(valueNode.textValue());
case "date" -> Date.from(Instant.parse(valueNode.stringValue()));
case "instant" -> Instant.parse(valueNode.stringValue());
case "localDate" -> LocalDate.parse(valueNode.stringValue());
case "localDateTime" -> LocalDateTime.parse(valueNode.stringValue());
case "short" -> valueNode.shortValue();
case "integer" -> valueNode.intValue();
default -> {
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,37 @@ void failJobReturnsInvalidStatusCode(int statusCode) {
.hasMessage("Failing a job failed with status " + statusCode + " and body: " + responseBody);
}

@Test
void acquireJobWithNullDueDate() {
restInvoker.response = new TestRestResponse(200, """
[
{
"id": "job-1",
"correlationId": "correlation-1",
"processInstanceId": "proc-1",
"executionId": "exec-1",
"processDefinitionId": "proc-def-1",
"tenantId": "flowable",
"elementId": "elem-1",
"elementName": "Element 1",
"createTime": "2023-08-21T13:12:28Z",
"dueDate": null,
"retries": 4,
"lockOwner": "tester-worker",
"lockExpirationTime": "2023-08-22T10:12:28Z"
}
]
""");
List<AcquiredExternalWorkerJob> jobs = client.createJobAcquireBuilder().topic("customer").acquireAndLock();

assertThat(jobs).hasSize(1);
AcquiredExternalWorkerJob job = jobs.get(0);
assertThat(job.getId()).isEqualTo("job-1");
assertThat(job.getCreateTime()).isEqualTo(Instant.parse("2023-08-21T13:12:28Z"));
assertThat(job.getDueDate()).isNull();
assertThat(job.getLockExpirationTime()).isEqualTo(Instant.parse("2023-08-22T10:12:28Z"));
}

static class TestRestInvoker implements RestInvoker {

protected String path;
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ public void processJob(AcquiredExternalWorkerJob job) {

Object workerException = job.getVariables().get("workerException");
if (workerException instanceof ObjectNode node) {
String message = node.path("message").asText();
String message = node.path("message").asString();
FlowableWorkerException exception = new FlowableWorkerException(message);
int retries = node.path("retries").asInt(-1);
if (retries > 0) {
exception.setRetries(retries);
}

String details = node.path("details").asText(null);
String details = node.path("details").asString(null);
if (details != null) {
exception.setErrorDetails(details);
}

String retryTimeout = node.path("retryTimeout").asText(null);
String retryTimeout = node.path("retryTimeout").asString(null);
if (retryTimeout != null) {
exception.setRetryTimeout(Duration.parse(retryTimeout));
}
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ public WorkerResult processJob(AcquiredExternalWorkerJob job, WorkerResultBuilde

Object workerFailure = job.getVariables().get("workerFailure");
if (workerFailure instanceof ObjectNode node) {
String message = node.path("message").asText();
String message = node.path("message").asString();
WorkerResult.Failure failure = resultBuilder.failure().message(message);
int retries = node.path("retries").asInt(-1);
if (retries > 0) {
failure.retries(retries);
}

String details = node.path("details").asText(null);
String details = node.path("details").asString(null);
if (details != null) {
failure.details(details);
}

String retryTimeout = node.path("retryTimeout").asText(null);
String retryTimeout = node.path("retryTimeout").asString(null);
if (retryTimeout != null) {
failure.retryTimeout(Duration.parse(retryTimeout));
}
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,9 @@ void workerThrowsException() {
errorDetails: '${json-unit.any-string}'
}
""");
assertThat(request.body().path("errorMessage").asText())
assertThat(request.body().path("errorMessage").asString())
.startsWith("Listener method");
assertThat(request.body().path("errorDetails").asText())
assertThat(request.body().path("errorDetails").asString())
.contains("Test error");
},
atIndex(0));
Expand Down

Back | FazBrowse Home | New Git URL