From 79c68e3e945dd2e805b6c8456c24c7c15855dffb Mon Sep 17 00:00:00 2001 From: gabriel-farache Date: Wed, 28 Jun 2023 14:22:12 +0200 Subject: [PATCH] Return Checkers in WorkFlowDefinitions --- .../parodos/flows/PrebuiltWorkFlowTest.java | 14 ++- .../parodos/flows/SimpleWorkFlowTest.java | 25 ++-- .../FailedWithAlertMessageWorkFlowTest.java | 15 +-- .../PendingWithAlertMessageWorkFlowTest.java | 15 +-- ...entialFailedWithExceptionWorkFlowTest.java | 15 ++- .../SequentialFailedWorkFlowTest.java | 15 ++- .../parodos/workflow/enums/WorkType.java | 2 +- workflow-service-sdk/api/openapi.yaml | 8 ++ .../docs/WorkDefinitionResponseDTO.md | 3 +- .../docs/WorkFlowDefinitionResponseDTO.md | 3 +- workflow-service-sdk/docs/WorkRequestDTO.md | 1 + .../docs/WorkStatusResponseDTO.md | 1 + .../sdk/model/WorkDefinitionResponseDTO.java | 15 ++- .../model/WorkFlowDefinitionResponseDTO.java | 50 ++++++-- .../parodos/sdk/model/WorkRequestDTO.java | 4 +- .../sdk/model/WorkStatusResponseDTO.java | 4 +- .../generated/openapi/openapi.json | 11 +- .../dto/WorkDefinitionResponseDTO.java | 28 ++++- .../dto/WorkFlowDefinitionResponseDTO.java | 20 ++- .../WorkFlowDefinitionServiceImpl.java | 119 ++++++++++++------ .../workflow/WorkFlowDelegateTest.java | 5 +- .../WorkFlowDefinitionControllerTest.java | 3 +- .../WorkFlowDefinitionServiceImplTest.java | 9 +- .../service/WorkFlowServiceImplTest.java | 9 +- 24 files changed, 263 insertions(+), 131 deletions(-) diff --git a/integration-tests/src/test/java/com/redhat/parodos/flows/PrebuiltWorkFlowTest.java b/integration-tests/src/test/java/com/redhat/parodos/flows/PrebuiltWorkFlowTest.java index 9c56ce32c..bae6cc25c 100644 --- a/integration-tests/src/test/java/com/redhat/parodos/flows/PrebuiltWorkFlowTest.java +++ b/integration-tests/src/test/java/com/redhat/parodos/flows/PrebuiltWorkFlowTest.java @@ -2,6 +2,7 @@ import java.util.Arrays; import java.util.List; +import java.util.Optional; import java.util.function.Consumer; import com.redhat.parodos.flows.common.WorkFlowTestBuilder; @@ -79,12 +80,13 @@ private Consumer getWorkFlowDefinitionResponseCon assertNotNull(workFlowDefinition.getWorks()); assertEquals(1, workFlowDefinition.getWorks().size()); - assertEquals("notificationTask", workFlowDefinition.getWorks().get(0).getName()); - assertEquals(WorkDefinitionResponseDTO.WorkTypeEnum.TASK, - workFlowDefinition.getWorks().get(0).getWorkType()); - assertTrue(CollectionUtils.isEmpty(workFlowDefinition.getWorks().get(0).getWorks())); - assertNull(workFlowDefinition.getWorks().get(0).getProcessingType()); - assertNotNull(workFlowDefinition.getWorks().get(0).getParameters()); + Optional firstWork = workFlowDefinition.getWorks().stream().findFirst(); + assertTrue(firstWork.isPresent()); + assertEquals("notificationTask", firstWork.get().getName()); + assertEquals(WorkDefinitionResponseDTO.WorkTypeEnum.TASK, firstWork.get().getWorkType()); + assertTrue(CollectionUtils.isEmpty(firstWork.get().getWorks())); + assertNull(firstWork.get().getProcessingType()); + assertNotNull(firstWork.get().getParameters()); }; } diff --git a/integration-tests/src/test/java/com/redhat/parodos/flows/SimpleWorkFlowTest.java b/integration-tests/src/test/java/com/redhat/parodos/flows/SimpleWorkFlowTest.java index ab9aa0536..15f4b2b5a 100644 --- a/integration-tests/src/test/java/com/redhat/parodos/flows/SimpleWorkFlowTest.java +++ b/integration-tests/src/test/java/com/redhat/parodos/flows/SimpleWorkFlowTest.java @@ -90,19 +90,18 @@ private static Consumer getWorkFlowDefinitionResp assertNotNull(workFlowDefinition.getWorks()); assertEquals(2, workFlowDefinition.getWorks().size()); - assertEquals("restCallTask", workFlowDefinition.getWorks().get(0).getName()); - assertEquals(WorkDefinitionResponseDTO.WorkTypeEnum.TASK, - workFlowDefinition.getWorks().get(0).getWorkType()); - assertTrue(CollectionUtils.isEmpty(workFlowDefinition.getWorks().get(0).getWorks())); - assertNull(workFlowDefinition.getWorks().get(0).getProcessingType()); - assertNotNull(workFlowDefinition.getWorks().get(0).getParameters()); - - assertEquals("loggingTask", workFlowDefinition.getWorks().get(1).getName()); - assertEquals(WorkDefinitionResponseDTO.WorkTypeEnum.TASK, - workFlowDefinition.getWorks().get(1).getWorkType()); - assertTrue(CollectionUtils.isEmpty(workFlowDefinition.getWorks().get(1).getWorks())); - assertNull(workFlowDefinition.getWorks().get(1).getProcessingType()); - assertNotNull(workFlowDefinition.getWorks().get(1).getParameters()); + List works = workFlowDefinition.getWorks().stream().toList(); + assertEquals("restCallTask", works.get(0).getName()); + assertEquals(WorkDefinitionResponseDTO.WorkTypeEnum.TASK, works.get(0).getWorkType()); + assertTrue(CollectionUtils.isEmpty(works.get(0).getWorks())); + assertNull(works.get(0).getProcessingType()); + assertNotNull(works.get(0).getParameters()); + + assertEquals("loggingTask", works.get(1).getName()); + assertEquals(WorkDefinitionResponseDTO.WorkTypeEnum.TASK, works.get(1).getWorkType()); + assertTrue(CollectionUtils.isEmpty(works.get(1).getWorks())); + assertNull(works.get(1).getProcessingType()); + assertNotNull(works.get(1).getParameters()); }; } diff --git a/integration-tests/src/test/java/com/redhat/parodos/flows/negative/FailedWithAlertMessageWorkFlowTest.java b/integration-tests/src/test/java/com/redhat/parodos/flows/negative/FailedWithAlertMessageWorkFlowTest.java index 936842d8c..4dac01bfb 100644 --- a/integration-tests/src/test/java/com/redhat/parodos/flows/negative/FailedWithAlertMessageWorkFlowTest.java +++ b/integration-tests/src/test/java/com/redhat/parodos/flows/negative/FailedWithAlertMessageWorkFlowTest.java @@ -1,5 +1,6 @@ package com.redhat.parodos.flows.negative; +import java.util.List; import java.util.function.Consumer; import com.redhat.parodos.flows.common.WorkFlowTestBuilder; @@ -86,13 +87,13 @@ private static Consumer getWorkFlowDefinitionResp assertThat(workFlowDefinition.getWorks()).isNotNull(); assertThat(workFlowDefinition.getWorks()).hasSize(2); - assertThat(workFlowDefinition.getWorks().get(1).getName()).isEqualTo("doNothingAgainWorkFlowTask"); - assertThat(workFlowDefinition.getWorks().get(1).getWorkType()) - .isEqualTo(WorkDefinitionResponseDTO.WorkTypeEnum.TASK); - assertThat(workFlowDefinition.getWorks().get(1).getWorks()).isNullOrEmpty(); - assertThat(workFlowDefinition.getWorks().get(1).getProcessingType()).isNull(); - assertThat(workFlowDefinition.getWorks().get(1).getParameters()).isNotNull(); - assertThat(workFlowDefinition.getWorks().get(0).getName()).isEqualTo("failedWithAlertMessageWorkFlowTask"); + List works = workFlowDefinition.getWorks().stream().toList(); + assertThat(works.get(1).getName()).isEqualTo("doNothingAgainWorkFlowTask"); + assertThat(works.get(1).getWorkType()).isEqualTo(WorkDefinitionResponseDTO.WorkTypeEnum.TASK); + assertThat(works.get(1).getWorks()).isNullOrEmpty(); + assertThat(works.get(1).getProcessingType()).isNull(); + assertThat(works.get(1).getParameters()).isNotNull(); + assertThat(works.get(0).getName()).isEqualTo("failedWithAlertMessageWorkFlowTask"); }; } diff --git a/integration-tests/src/test/java/com/redhat/parodos/flows/negative/PendingWithAlertMessageWorkFlowTest.java b/integration-tests/src/test/java/com/redhat/parodos/flows/negative/PendingWithAlertMessageWorkFlowTest.java index 30b79b05f..862d04d32 100644 --- a/integration-tests/src/test/java/com/redhat/parodos/flows/negative/PendingWithAlertMessageWorkFlowTest.java +++ b/integration-tests/src/test/java/com/redhat/parodos/flows/negative/PendingWithAlertMessageWorkFlowTest.java @@ -1,5 +1,6 @@ package com.redhat.parodos.flows.negative; +import java.util.List; import java.util.function.Consumer; import com.redhat.parodos.flows.common.WorkFlowTestBuilder; @@ -86,13 +87,13 @@ private static Consumer getWorkFlowDefinitionResp assertThat(workFlowDefinition.getWorks()).isNotNull(); assertThat(workFlowDefinition.getWorks()).hasSize(2); - assertThat(workFlowDefinition.getWorks().get(1).getName()).isEqualTo("doNothingWorkFlowTask"); - assertThat(workFlowDefinition.getWorks().get(1).getWorkType()) - .isEqualTo(WorkDefinitionResponseDTO.WorkTypeEnum.TASK); - assertThat(workFlowDefinition.getWorks().get(1).getWorks()).isNullOrEmpty(); - assertThat(workFlowDefinition.getWorks().get(1).getProcessingType()).isNull(); - assertThat(workFlowDefinition.getWorks().get(1).getParameters()).isNotNull(); - assertThat(workFlowDefinition.getWorks().get(0).getName()).isEqualTo("pendingWithAlertMessageWorkFlowTask"); + List works = workFlowDefinition.getWorks().stream().toList(); + assertThat(works.get(1).getName()).isEqualTo("doNothingWorkFlowTask"); + assertThat(works.get(1).getWorkType()).isEqualTo(WorkDefinitionResponseDTO.WorkTypeEnum.TASK); + assertThat(works.get(1).getWorks()).isNullOrEmpty(); + assertThat(works.get(1).getProcessingType()).isNull(); + assertThat(works.get(1).getParameters()).isNotNull(); + assertThat(works.get(0).getName()).isEqualTo("pendingWithAlertMessageWorkFlowTask"); }; } diff --git a/integration-tests/src/test/java/com/redhat/parodos/flows/negative/SequentialFailedWithExceptionWorkFlowTest.java b/integration-tests/src/test/java/com/redhat/parodos/flows/negative/SequentialFailedWithExceptionWorkFlowTest.java index 6a9aec9ad..07be3d7fd 100644 --- a/integration-tests/src/test/java/com/redhat/parodos/flows/negative/SequentialFailedWithExceptionWorkFlowTest.java +++ b/integration-tests/src/test/java/com/redhat/parodos/flows/negative/SequentialFailedWithExceptionWorkFlowTest.java @@ -1,5 +1,6 @@ package com.redhat.parodos.flows.negative; +import java.util.Optional; import java.util.function.Consumer; import com.redhat.parodos.flows.common.WorkFlowTestBuilder; @@ -21,6 +22,7 @@ import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; @Slf4j public class SequentialFailedWithExceptionWorkFlowTest { @@ -77,12 +79,13 @@ private static Consumer getWorkFlowDefinitionResp assertThat(workFlowDefinition.getWorks()).isNotNull(); assertThat(workFlowDefinition.getWorks()).hasSize(1); - assertThat(workFlowDefinition.getWorks().get(0).getName()).isEqualTo("failedWithExceptionWorkFlowTask"); - assertThat(workFlowDefinition.getWorks().get(0).getWorkType()) - .isEqualTo(WorkDefinitionResponseDTO.WorkTypeEnum.TASK); - assertThat(workFlowDefinition.getWorks().get(0).getWorks()).isNullOrEmpty(); - assertThat(workFlowDefinition.getWorks().get(0).getProcessingType()).isNull(); - assertThat(workFlowDefinition.getWorks().get(0).getParameters()).isNotNull(); + Optional firstWork = workFlowDefinition.getWorks().stream().findFirst(); + assertTrue(firstWork.isPresent()); + assertThat(firstWork.get().getName()).isEqualTo("failedWithExceptionWorkFlowTask"); + assertThat(firstWork.get().getWorkType()).isEqualTo(WorkDefinitionResponseDTO.WorkTypeEnum.TASK); + assertThat(firstWork.get().getWorks()).isNullOrEmpty(); + assertThat(firstWork.get().getProcessingType()).isNull(); + assertThat(firstWork.get().getParameters()).isNotNull(); }; } diff --git a/integration-tests/src/test/java/com/redhat/parodos/flows/negative/SequentialFailedWorkFlowTest.java b/integration-tests/src/test/java/com/redhat/parodos/flows/negative/SequentialFailedWorkFlowTest.java index 71cd71b82..234d0d0dc 100644 --- a/integration-tests/src/test/java/com/redhat/parodos/flows/negative/SequentialFailedWorkFlowTest.java +++ b/integration-tests/src/test/java/com/redhat/parodos/flows/negative/SequentialFailedWorkFlowTest.java @@ -1,5 +1,6 @@ package com.redhat.parodos.flows.negative; +import java.util.Optional; import java.util.function.Consumer; import com.redhat.parodos.flows.common.WorkFlowTestBuilder; @@ -21,6 +22,7 @@ import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; @Slf4j public class SequentialFailedWorkFlowTest { @@ -74,12 +76,13 @@ private static Consumer getWorkFlowDefinitionResp assertThat(workFlowDefinition.getWorks()).isNotNull(); assertThat(workFlowDefinition.getWorks()).hasSize(1); - assertThat(workFlowDefinition.getWorks().get(0).getName()).isEqualTo("failedWorkFlowTask"); - assertThat(workFlowDefinition.getWorks().get(0).getWorkType()) - .isEqualTo(WorkDefinitionResponseDTO.WorkTypeEnum.TASK); - assertThat(workFlowDefinition.getWorks().get(0).getWorks()).isNullOrEmpty(); - assertThat(workFlowDefinition.getWorks().get(0).getProcessingType()).isNull(); - assertThat(workFlowDefinition.getWorks().get(0).getParameters()).isNotNull(); + Optional firstWork = workFlowDefinition.getWorks().stream().findFirst(); + assertTrue(firstWork.isPresent()); + assertThat(firstWork.get().getName()).isEqualTo("failedWorkFlowTask"); + assertThat(firstWork.get().getWorkType()).isEqualTo(WorkDefinitionResponseDTO.WorkTypeEnum.TASK); + assertThat(firstWork.get().getWorks()).isNullOrEmpty(); + assertThat(firstWork.get().getProcessingType()).isNull(); + assertThat(firstWork.get().getParameters()).isNotNull(); }; } diff --git a/parodos-model-api/src/main/java/com/redhat/parodos/workflow/enums/WorkType.java b/parodos-model-api/src/main/java/com/redhat/parodos/workflow/enums/WorkType.java index 7d3f2f6bc..932b48d97 100644 --- a/parodos-model-api/src/main/java/com/redhat/parodos/workflow/enums/WorkType.java +++ b/parodos-model-api/src/main/java/com/redhat/parodos/workflow/enums/WorkType.java @@ -24,6 +24,6 @@ */ public enum WorkType { - TASK, WORKFLOW + TASK, WORKFLOW, CHECKER } diff --git a/workflow-service-sdk/api/openapi.yaml b/workflow-service-sdk/api/openapi.yaml index ab24a0a34..54edcbf6f 100644 --- a/workflow-service-sdk/api/openapi.yaml +++ b/workflow-service-sdk/api/openapi.yaml @@ -1133,11 +1133,13 @@ components: enum: - TASK - WORKFLOW + - CHECKER type: string works: items: $ref: '#/components/schemas/WorkDefinitionResponseDTO' type: array + uniqueItems: true type: object WorkFlowCheckerTaskRequestDTO: example: @@ -1259,6 +1261,7 @@ components: type: object WorkFlowDefinitionResponseDTO: example: + cronExpression: cronExpression processingType: SEQUENTIAL rollbackWorkflow: rollbackWorkflow works: @@ -1307,6 +1310,8 @@ components: createDate: format: date-time type: string + cronExpression: + type: string id: format: uuid type: string @@ -1342,6 +1347,7 @@ components: items: $ref: '#/components/schemas/WorkDefinitionResponseDTO' type: array + uniqueItems: true type: object WorkFlowExecutionResponseDTO: example: @@ -1703,6 +1709,7 @@ components: enum: - TASK - WORKFLOW + - CHECKER type: string workName: type: string @@ -1736,6 +1743,7 @@ components: enum: - TASK - WORKFLOW + - CHECKER type: string works: items: diff --git a/workflow-service-sdk/docs/WorkDefinitionResponseDTO.md b/workflow-service-sdk/docs/WorkDefinitionResponseDTO.md index 9a2ab7c7b..3faa8d2df 100644 --- a/workflow-service-sdk/docs/WorkDefinitionResponseDTO.md +++ b/workflow-service-sdk/docs/WorkDefinitionResponseDTO.md @@ -14,7 +14,7 @@ |**parameters** | **Map<String, Map<String, Object>>** | | [optional] | |**processingType** | [**ProcessingTypeEnum**](#ProcessingTypeEnum) | | [optional] | |**workType** | [**WorkTypeEnum**](#WorkTypeEnum) | | [optional] | -|**works** | [**List<WorkDefinitionResponseDTO>**](WorkDefinitionResponseDTO.md) | | [optional] | +|**works** | [**Set<WorkDefinitionResponseDTO>**](WorkDefinitionResponseDTO.md) | | [optional] | @@ -45,6 +45,7 @@ |---- | -----| | TASK | "TASK" | | WORKFLOW | "WORKFLOW" | +| CHECKER | "CHECKER" | diff --git a/workflow-service-sdk/docs/WorkFlowDefinitionResponseDTO.md b/workflow-service-sdk/docs/WorkFlowDefinitionResponseDTO.md index 0b005c23e..247bcf7c9 100644 --- a/workflow-service-sdk/docs/WorkFlowDefinitionResponseDTO.md +++ b/workflow-service-sdk/docs/WorkFlowDefinitionResponseDTO.md @@ -9,6 +9,7 @@ |------------ | ------------- | ------------- | -------------| |**author** | **String** | | [optional] | |**createDate** | **Date** | | [optional] | +|**cronExpression** | **String** | | [optional] | |**id** | **UUID** | | [optional] | |**modifyDate** | **Date** | | [optional] | |**name** | **String** | | [optional] | @@ -17,7 +18,7 @@ |**properties** | [**WorkFlowPropertiesDefinitionDTO**](WorkFlowPropertiesDefinitionDTO.md) | | [optional] | |**rollbackWorkflow** | **String** | | [optional] | |**type** | [**TypeEnum**](#TypeEnum) | | [optional] | -|**works** | [**List<WorkDefinitionResponseDTO>**](WorkDefinitionResponseDTO.md) | | [optional] | +|**works** | [**Set<WorkDefinitionResponseDTO>**](WorkDefinitionResponseDTO.md) | | [optional] | diff --git a/workflow-service-sdk/docs/WorkRequestDTO.md b/workflow-service-sdk/docs/WorkRequestDTO.md index 114ee524f..d1aa9b466 100644 --- a/workflow-service-sdk/docs/WorkRequestDTO.md +++ b/workflow-service-sdk/docs/WorkRequestDTO.md @@ -19,6 +19,7 @@ |---- | -----| | TASK | "TASK" | | WORKFLOW | "WORKFLOW" | +| CHECKER | "CHECKER" | diff --git a/workflow-service-sdk/docs/WorkStatusResponseDTO.md b/workflow-service-sdk/docs/WorkStatusResponseDTO.md index 97a45a254..6b3acc4d0 100644 --- a/workflow-service-sdk/docs/WorkStatusResponseDTO.md +++ b/workflow-service-sdk/docs/WorkStatusResponseDTO.md @@ -34,6 +34,7 @@ |---- | -----| | TASK | "TASK" | | WORKFLOW | "WORKFLOW" | +| CHECKER | "CHECKER" | diff --git a/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/model/WorkDefinitionResponseDTO.java b/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/model/WorkDefinitionResponseDTO.java index 17a43b0a8..e33a05d7d 100644 --- a/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/model/WorkDefinitionResponseDTO.java +++ b/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/model/WorkDefinitionResponseDTO.java @@ -16,6 +16,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -188,7 +189,9 @@ public enum WorkTypeEnum { TASK("TASK"), - WORKFLOW("WORKFLOW"); + WORKFLOW("WORKFLOW"), + + CHECKER("CHECKER"); private String value; @@ -239,7 +242,7 @@ public WorkTypeEnum read(final JsonReader jsonReader) throws IOException { public static final String SERIALIZED_NAME_WORKS = "works"; @SerializedName(SERIALIZED_NAME_WORKS) - private List works; + private Set works; public WorkDefinitionResponseDTO() { } @@ -393,7 +396,7 @@ public void setWorkType(WorkTypeEnum workType) { this.workType = workType; } - public WorkDefinitionResponseDTO works(List works) { + public WorkDefinitionResponseDTO works(Set works) { this.works = works; return this; @@ -401,7 +404,7 @@ public WorkDefinitionResponseDTO works(List works) { public WorkDefinitionResponseDTO addWorksItem(WorkDefinitionResponseDTO worksItem) { if (this.works == null) { - this.works = new ArrayList<>(); + this.works = new LinkedHashSet<>(); } this.works.add(worksItem); return this; @@ -412,11 +415,11 @@ public WorkDefinitionResponseDTO addWorksItem(WorkDefinitionResponseDTO worksIte * @return works **/ @javax.annotation.Nullable - public List getWorks() { + public Set getWorks() { return works; } - public void setWorks(List works) { + public void setWorks(Set works) { this.works = works; } diff --git a/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/model/WorkFlowDefinitionResponseDTO.java b/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/model/WorkFlowDefinitionResponseDTO.java index b28ef3766..ed0c12300 100644 --- a/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/model/WorkFlowDefinitionResponseDTO.java +++ b/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/model/WorkFlowDefinitionResponseDTO.java @@ -13,11 +13,10 @@ package com.redhat.parodos.sdk.model; import java.io.IOException; -import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.HashSet; -import java.util.List; +import java.util.LinkedHashSet; import java.util.Map; import java.util.Map.Entry; import java.util.Objects; @@ -53,6 +52,11 @@ public class WorkFlowDefinitionResponseDTO { @SerializedName(SERIALIZED_NAME_CREATE_DATE) private Date createDate; + public static final String SERIALIZED_NAME_CRON_EXPRESSION = "cronExpression"; + + @SerializedName(SERIALIZED_NAME_CRON_EXPRESSION) + private String cronExpression; + public static final String SERIALIZED_NAME_ID = "id"; @SerializedName(SERIALIZED_NAME_ID) @@ -204,7 +208,7 @@ public TypeEnum read(final JsonReader jsonReader) throws IOException { public static final String SERIALIZED_NAME_WORKS = "works"; @SerializedName(SERIALIZED_NAME_WORKS) - private List works; + private Set works; public WorkFlowDefinitionResponseDTO() { } @@ -247,6 +251,25 @@ public void setCreateDate(Date createDate) { this.createDate = createDate; } + public WorkFlowDefinitionResponseDTO cronExpression(String cronExpression) { + + this.cronExpression = cronExpression; + return this; + } + + /** + * Get cronExpression + * @return cronExpression + **/ + @javax.annotation.Nullable + public String getCronExpression() { + return cronExpression; + } + + public void setCronExpression(String cronExpression) { + this.cronExpression = cronExpression; + } + public WorkFlowDefinitionResponseDTO id(UUID id) { this.id = id; @@ -407,7 +430,7 @@ public void setType(TypeEnum type) { this.type = type; } - public WorkFlowDefinitionResponseDTO works(List works) { + public WorkFlowDefinitionResponseDTO works(Set works) { this.works = works; return this; @@ -415,7 +438,7 @@ public WorkFlowDefinitionResponseDTO works(List works public WorkFlowDefinitionResponseDTO addWorksItem(WorkDefinitionResponseDTO worksItem) { if (this.works == null) { - this.works = new ArrayList<>(); + this.works = new LinkedHashSet<>(); } this.works.add(worksItem); return this; @@ -426,11 +449,11 @@ public WorkFlowDefinitionResponseDTO addWorksItem(WorkDefinitionResponseDTO work * @return works **/ @javax.annotation.Nullable - public List getWorks() { + public Set getWorks() { return works; } - public void setWorks(List works) { + public void setWorks(Set works) { this.works = works; } @@ -445,6 +468,7 @@ public boolean equals(Object o) { WorkFlowDefinitionResponseDTO workFlowDefinitionResponseDTO = (WorkFlowDefinitionResponseDTO) o; return Objects.equals(this.author, workFlowDefinitionResponseDTO.author) && Objects.equals(this.createDate, workFlowDefinitionResponseDTO.createDate) + && Objects.equals(this.cronExpression, workFlowDefinitionResponseDTO.cronExpression) && Objects.equals(this.id, workFlowDefinitionResponseDTO.id) && Objects.equals(this.modifyDate, workFlowDefinitionResponseDTO.modifyDate) && Objects.equals(this.name, workFlowDefinitionResponseDTO.name) @@ -458,8 +482,8 @@ public boolean equals(Object o) { @Override public int hashCode() { - return Objects.hash(author, createDate, id, modifyDate, name, parameters, processingType, properties, - rollbackWorkflow, type, works); + return Objects.hash(author, createDate, cronExpression, id, modifyDate, name, parameters, processingType, + properties, rollbackWorkflow, type, works); } @Override @@ -468,6 +492,7 @@ public String toString() { sb.append("class WorkFlowDefinitionResponseDTO {\n"); sb.append(" author: ").append(toIndentedString(author)).append("\n"); sb.append(" createDate: ").append(toIndentedString(createDate)).append("\n"); + sb.append(" cronExpression: ").append(toIndentedString(cronExpression)).append("\n"); sb.append(" id: ").append(toIndentedString(id)).append("\n"); sb.append(" modifyDate: ").append(toIndentedString(modifyDate)).append("\n"); sb.append(" name: ").append(toIndentedString(name)).append("\n"); @@ -501,6 +526,7 @@ private String toIndentedString(Object o) { openapiFields = new HashSet(); openapiFields.add("author"); openapiFields.add("createDate"); + openapiFields.add("cronExpression"); openapiFields.add("id"); openapiFields.add("modifyDate"); openapiFields.add("name"); @@ -552,6 +578,12 @@ public static void validateJsonObject(JsonObject jsonObj) throws IOException { String.format("Expected the field `author` to be a primitive type in the JSON string but got `%s`", jsonObj.get("author").toString())); } + if ((jsonObj.get("cronExpression") != null && !jsonObj.get("cronExpression").isJsonNull()) + && !jsonObj.get("cronExpression").isJsonPrimitive()) { + throw new IllegalArgumentException(String.format( + "Expected the field `cronExpression` to be a primitive type in the JSON string but got `%s`", + jsonObj.get("cronExpression").toString())); + } if ((jsonObj.get("id") != null && !jsonObj.get("id").isJsonNull()) && !jsonObj.get("id").isJsonPrimitive()) { throw new IllegalArgumentException( String.format("Expected the field `id` to be a primitive type in the JSON string but got `%s`", diff --git a/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/model/WorkRequestDTO.java b/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/model/WorkRequestDTO.java index 1d6a3b032..0960ba38b 100644 --- a/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/model/WorkRequestDTO.java +++ b/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/model/WorkRequestDTO.java @@ -52,7 +52,9 @@ public enum TypeEnum { TASK("TASK"), - WORKFLOW("WORKFLOW"); + WORKFLOW("WORKFLOW"), + + CHECKER("CHECKER"); private String value; diff --git a/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/model/WorkStatusResponseDTO.java b/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/model/WorkStatusResponseDTO.java index 178b3ce03..060937baf 100644 --- a/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/model/WorkStatusResponseDTO.java +++ b/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/model/WorkStatusResponseDTO.java @@ -124,7 +124,9 @@ public enum TypeEnum { TASK("TASK"), - WORKFLOW("WORKFLOW"); + WORKFLOW("WORKFLOW"), + + CHECKER("CHECKER"); private String value; diff --git a/workflow-service/generated/openapi/openapi.json b/workflow-service/generated/openapi/openapi.json index bbc323477..e72a3ac7f 100644 --- a/workflow-service/generated/openapi/openapi.json +++ b/workflow-service/generated/openapi/openapi.json @@ -1440,9 +1440,10 @@ }, "workType" : { "type" : "string", - "enum" : [ "TASK", "WORKFLOW" ] + "enum" : [ "TASK", "WORKFLOW", "CHECKER" ] }, "works" : { + "uniqueItems" : true, "type" : "array", "items" : { "$ref" : "#/components/schemas/WorkDefinitionResponseDTO" @@ -1481,6 +1482,9 @@ "type" : "string", "format" : "date-time" }, + "cronExpression" : { + "type" : "string" + }, "id" : { "type" : "string", "format" : "uuid" @@ -1516,6 +1520,7 @@ "enum" : [ "ASSESSMENT", "CHECKER", "INFRASTRUCTURE", "ESCALATION" ] }, "works" : { + "uniqueItems" : true, "type" : "array", "items" : { "$ref" : "#/components/schemas/WorkDefinitionResponseDTO" @@ -1746,7 +1751,7 @@ }, "type" : { "type" : "string", - "enum" : [ "TASK", "WORKFLOW" ] + "enum" : [ "TASK", "WORKFLOW", "CHECKER" ] }, "workName" : { "type" : "string" @@ -1771,7 +1776,7 @@ }, "type" : { "type" : "string", - "enum" : [ "TASK", "WORKFLOW" ] + "enum" : [ "TASK", "WORKFLOW", "CHECKER" ] }, "works" : { "type" : "array", diff --git a/workflow-service/src/main/java/com/redhat/parodos/workflow/definition/dto/WorkDefinitionResponseDTO.java b/workflow-service/src/main/java/com/redhat/parodos/workflow/definition/dto/WorkDefinitionResponseDTO.java index 26b4016b5..5b635e459 100644 --- a/workflow-service/src/main/java/com/redhat/parodos/workflow/definition/dto/WorkDefinitionResponseDTO.java +++ b/workflow-service/src/main/java/com/redhat/parodos/workflow/definition/dto/WorkDefinitionResponseDTO.java @@ -15,15 +15,17 @@ */ package com.redhat.parodos.workflow.definition.dto; -import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.UUID; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.type.TypeReference; +import com.redhat.parodos.workflow.definition.entity.WorkFlowCheckerMappingDefinition; import com.redhat.parodos.workflow.definition.entity.WorkFlowDefinition; import com.redhat.parodos.workflow.definition.entity.WorkFlowTaskDefinition; import com.redhat.parodos.workflow.definition.entity.WorkFlowWorkDefinition; @@ -61,12 +63,15 @@ public class WorkDefinitionResponseDTO { private String author; - private List works; + private Set works; private Map> parameters; private List outputs; + @JsonIgnore + private UUID checkerWorkId; + @JsonIgnore private Integer numberOfWorkUnits; @@ -87,15 +92,26 @@ public WorkDefinitionResponseDTOBuilder parameterFromString(String parameters) { public static WorkDefinitionResponseDTO fromWorkFlowDefinitionEntity(WorkFlowDefinition wd, List dependencies) { return WorkDefinitionResponseDTO.builder().id(wd.getId()).workType(WorkType.WORKFLOW).name(wd.getName()) - .parameterFromString(wd.getParameters()).processingType(wd.getProcessingType()).works(new ArrayList<>()) + .parameterFromString(wd.getParameters()).processingType(wd.getProcessingType()).works(new HashSet<>()) .numberOfWorkUnits(dependencies.size()).build(); } public static WorkDefinitionResponseDTO fromWorkFlowTaskDefinition(WorkFlowTaskDefinition wdt) { - return WorkDefinitionResponseDTO.builder().id(wdt.getId()).workType(WorkType.TASK).name(wdt.getName()) - .parameterFromString(wdt.getParameters()) + WorkDefinitionResponseDTOBuilder builder = WorkDefinitionResponseDTO.builder().id(wdt.getId()) + .workType(WorkType.TASK).name(wdt.getName()).parameterFromString(wdt.getParameters()) .outputs(WorkFlowDTOUtil.readStringAsObject(wdt.getOutputs(), new TypeReference<>() { - }, List.of())).build(); + }, List.of())).numberOfWorkUnits(0); + + if (wdt.getWorkFlowCheckerMappingDefinition() != null) { + builder = builder.checkerWorkId(wdt.getWorkFlowCheckerMappingDefinition().getId()); + } + + return builder.build(); + } + + public static WorkDefinitionResponseDTO fromWorkFlowCheckerMappingDefinition(WorkFlowCheckerMappingDefinition wcd) { + return WorkDefinitionResponseDTO.builder().workType(WorkType.CHECKER).numberOfWorkUnits(wcd.getTasks().size()) + .checkerWorkId(wcd.getCheckWorkFlow().getCheckerWorkFlowDefinition().getId()).build(); } } diff --git a/workflow-service/src/main/java/com/redhat/parodos/workflow/definition/dto/WorkFlowDefinitionResponseDTO.java b/workflow-service/src/main/java/com/redhat/parodos/workflow/definition/dto/WorkFlowDefinitionResponseDTO.java index d791c6381..6653fdb81 100644 --- a/workflow-service/src/main/java/com/redhat/parodos/workflow/definition/dto/WorkFlowDefinitionResponseDTO.java +++ b/workflow-service/src/main/java/com/redhat/parodos/workflow/definition/dto/WorkFlowDefinitionResponseDTO.java @@ -16,9 +16,9 @@ package com.redhat.parodos.workflow.definition.dto; import java.util.Date; -import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; import java.util.UUID; import com.fasterxml.jackson.annotation.JsonInclude; @@ -68,11 +68,14 @@ public class WorkFlowDefinitionResponseDTO { private WorkFlowPropertiesDefinitionDTO properties; @JsonInclude(JsonInclude.Include.NON_EMPTY) - private List works; + private Set works; @JsonInclude(JsonInclude.Include.NON_NULL) private String rollbackWorkflow; + @JsonInclude(JsonInclude.Include.NON_NULL) + private String cronExpression; + public static class WorkFlowDefinitionResponseDTOBuilder { public WorkFlowDefinitionResponseDTOBuilder parameterFromString(String parameters) { @@ -88,15 +91,20 @@ public WorkFlowDefinitionResponseDTOBuilder parameterFromString(String parameter } public static WorkFlowDefinitionResponseDTO fromEntity(WorkFlowDefinition workFlowDefinition, - List works) { - return WorkFlowDefinitionResponseDTO.builder().id(workFlowDefinition.getId()).name(workFlowDefinition.getName()) + Set works) { + WorkFlowDefinitionResponseDTOBuilder builder = WorkFlowDefinitionResponseDTO.builder() + .id(workFlowDefinition.getId()).name(workFlowDefinition.getName()) .properties(WorkFlowPropertiesDefinitionDTO.fromEntity(workFlowDefinition.getProperties())) .parameterFromString(workFlowDefinition.getParameters()).author(workFlowDefinition.getAuthor()) .createDate(workFlowDefinition.getCreateDate()).modifyDate(workFlowDefinition.getModifyDate()) .type(workFlowDefinition.getType()).processingType(workFlowDefinition.getProcessingType()).works(works) .rollbackWorkflow(Optional.ofNullable(workFlowDefinition.getRollbackWorkFlowDefinition()) - .map(WorkFlowDefinition::getName).orElse(null)) - .build(); + .map(WorkFlowDefinition::getName).orElse(null)); + + if (workFlowDefinition.getCheckerWorkFlowDefinition() != null) { + builder = builder.cronExpression(workFlowDefinition.getCheckerWorkFlowDefinition().getCronExpression()); + } + return builder.build(); } } \ No newline at end of file diff --git a/workflow-service/src/main/java/com/redhat/parodos/workflow/definition/service/WorkFlowDefinitionServiceImpl.java b/workflow-service/src/main/java/com/redhat/parodos/workflow/definition/service/WorkFlowDefinitionServiceImpl.java index a7c090875..281367a1f 100644 --- a/workflow-service/src/main/java/com/redhat/parodos/workflow/definition/service/WorkFlowDefinitionServiceImpl.java +++ b/workflow-service/src/main/java/com/redhat/parodos/workflow/definition/service/WorkFlowDefinitionServiceImpl.java @@ -19,11 +19,14 @@ import java.util.Comparator; import java.util.Date; import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Queue; +import java.util.Set; import java.util.UUID; -import java.util.concurrent.CopyOnWriteArrayList; import com.fasterxml.jackson.core.type.TypeReference; import com.redhat.parodos.common.entity.AbstractEntity; @@ -263,8 +266,11 @@ public WorkFlowDefinition getParentWorkFlowByWorkName(String workName) { .map(WorkFlowWorkDefinition::getWorkFlowDefinition).orElse(null); } - private void getWorksFromWorkDefinition(List workFlowWorkDefinitions, - CopyOnWriteArrayList responseDTOs) { + private void getWorksFromWorkDefinition(WorkDefinitionResponseDTO workflow, + List workFlowWorkDefinitions, Queue responseDTOs) { + if (workflow.getWorks() == null) { + workflow.setWorks(new HashSet<>()); + } workFlowWorkDefinitions.forEach(workFlowWorkDefinition -> { WorkType workType = workFlowWorkDefinition.getWorkDefinitionType(); @@ -280,7 +286,22 @@ private void getWorksFromWorkDefinition(List workFlowWor + workFlowWorkDefinition.getWorkDefinitionId()); return; } - responseDTOs.add(WorkDefinitionResponseDTO.fromWorkFlowTaskDefinition(wdt.get())); + WorkDefinitionResponseDTO work = WorkDefinitionResponseDTO.fromWorkFlowTaskDefinition(wdt.get()); + workflow.getWorks().add(work); + responseDTOs.add(work); + } + case CHECKER -> { + Optional wcd = workFlowCheckerMappingDefinitionRepository + .findById(workFlowWorkDefinition.getWorkDefinitionId()); + if (wcd.isEmpty()) { + log.error("Cannot find the checker definition with id " + + workFlowWorkDefinition.getWorkDefinitionId()); + return; + } + WorkDefinitionResponseDTO work = WorkDefinitionResponseDTO + .fromWorkFlowCheckerMappingDefinition(wcd.get()); + workflow.getWorks().add(work); + responseDTOs.add(work); } case WORKFLOW -> { Optional wd = workFlowDefinitionRepository @@ -292,8 +313,10 @@ private void getWorksFromWorkDefinition(List workFlowWor } List wdWorkFlowWorkDependencies = workFlowWorkRepository .findByWorkFlowDefinitionIdOrderByCreateDateAsc(wd.get().getId()); - responseDTOs.add(WorkDefinitionResponseDTO.fromWorkFlowDefinitionEntity(wd.get(), - wdWorkFlowWorkDependencies)); + WorkDefinitionResponseDTO work = WorkDefinitionResponseDTO.fromWorkFlowDefinitionEntity(wd.get(), + wdWorkFlowWorkDependencies); + workflow.getWorks().add(work); + responseDTOs.add(work); } default -> { } @@ -302,51 +325,65 @@ private void getWorksFromWorkDefinition(List workFlowWor } - private List buildWorkFlowWorksDTOs(WorkFlowDefinition workFlowDefinition, + private Set buildWorkFlowWorksDTOs(WorkFlowDefinition workFlowDefinition, List workFlowWorkDefinitions) { - CopyOnWriteArrayList workDefinitionResponseDTOs = new CopyOnWriteArrayList<>(); - Map workFlowWorksStartIndex = new HashMap<>(); + Queue workDefinitionResponseDTOs = new LinkedList<>(); + WorkDefinitionResponseDTO rootWorkFlow = buildRootWorkFlow(workFlowDefinition, workFlowWorkDefinitions, + workDefinitionResponseDTOs); + + // fill in subsequent workUnits + // workDefinitionResponseDTOs.size() will grow as long as there are new works + populateWorkFlowWorksRecursive(workDefinitionResponseDTOs); - // add workflow - workDefinitionResponseDTOs - .add(WorkDefinitionResponseDTO.builder().id(workFlowDefinition.getId()).workType(WorkType.WORKFLOW) - .name(workFlowDefinition.getName()).parameterFromString(workFlowDefinition.getParameters()) - .processingType(workFlowDefinition.getProcessingType()).works(new ArrayList<>()) - .numberOfWorkUnits(workFlowWorkDefinitions.size()).build()); - workFlowWorksStartIndex.put(workFlowDefinition.getName(), 1); + return rootWorkFlow.getWorks(); + } + private WorkDefinitionResponseDTO buildRootWorkFlow(WorkFlowDefinition workFlowDefinition, + List workFlowWorkDefinitions, + Queue workDefinitionResponseDTOs) { + WorkDefinitionResponseDTO rootWorkFlow = WorkDefinitionResponseDTO.builder().id(workFlowDefinition.getId()) + .workType(workFlowDefinition.getType() == WorkFlowType.CHECKER ? WorkType.CHECKER : WorkType.WORKFLOW) + .name(workFlowDefinition.getName()).parameterFromString(workFlowDefinition.getParameters()) + .processingType(workFlowDefinition.getProcessingType()).works(new HashSet<>()) + .numberOfWorkUnits(workFlowWorkDefinitions.size()).build(); + workDefinitionResponseDTOs.add(rootWorkFlow); // add workflowWorkUnits - this.getWorksFromWorkDefinition(workFlowWorkDefinitions, workDefinitionResponseDTOs); + this.getWorksFromWorkDefinition(rootWorkFlow, workFlowWorkDefinitions, workDefinitionResponseDTOs); - // fill in subsequent workUnits - // this responseSize is like this because we modify the size of the - // workDefinitionResponseDTO - for (int i = 1; i < workDefinitionResponseDTOs.size(); i++) { - if (workDefinitionResponseDTOs.get(i).getWorkType() == WorkType.WORKFLOW) { - workFlowWorksStartIndex.put(workDefinitionResponseDTOs.get(i).getName(), - workDefinitionResponseDTOs.size()); - - List workFlowWorkUnits1Definition = workFlowWorkRepository - .findByWorkFlowDefinitionIdOrderByCreateDateAsc(workDefinitionResponseDTOs.get(i).getId()) - .stream().sorted(Comparator.comparing(WorkFlowWorkDefinition::getCreateDate)).toList(); - this.getWorksFromWorkDefinition(workFlowWorkUnits1Definition, workDefinitionResponseDTOs); - } + return rootWorkFlow; + } + + private void populateWorkFlowWorksRecursive(Queue workDefinitionResponseDTOs) { + if (workDefinitionResponseDTOs.isEmpty()) { + return; } + WorkDefinitionResponseDTO workflow = workDefinitionResponseDTOs.poll(); + List workFlowWorkUnitsDefinition = workFlowWorkRepository + .findByWorkFlowDefinitionIdOrderByCreateDateAsc(workflow.getId()).stream() + .sorted(Comparator.comparing(WorkFlowWorkDefinition::getCreateDate)).toList(); - for (int j = workDefinitionResponseDTOs.size() - 1; j >= 0; j--) { - if (workDefinitionResponseDTOs.get(j).getWorkType() == WorkType.WORKFLOW) { - List tmpList = new ArrayList<>(); - for (int k = workFlowWorksStartIndex.get(workDefinitionResponseDTOs.get(j) - .getName()); k < workFlowWorksStartIndex.get(workDefinitionResponseDTOs.get(j).getName()) - + workDefinitionResponseDTOs.get(j).getNumberOfWorkUnits() - && k < workDefinitionResponseDTOs.size(); k++) { + this.getWorksFromWorkDefinition(workflow, workFlowWorkUnitsDefinition, workDefinitionResponseDTOs); + this.getCheckerWorkFromWorkDefinition(workflow, workDefinitionResponseDTOs); + populateWorkFlowWorksRecursive(workDefinitionResponseDTOs); + } - tmpList.add(workDefinitionResponseDTOs.get(k)); - } - workDefinitionResponseDTOs.get(j).setWorks(tmpList); + private void getCheckerWorkFromWorkDefinition(WorkDefinitionResponseDTO workflow, + Queue workDefinitionResponseDTOs) { + if (workflow.getCheckerWorkId() != null) { + WorkFlowDefinition checkerWorkflowDefinition = workFlowCheckerMappingDefinitionRepository + .findById(workflow.getCheckerWorkId()).get().getCheckWorkFlow(); + WorkDefinitionResponseDTO checkerWorkflowDefinitionDTO = WorkDefinitionResponseDTO.builder() + .id(checkerWorkflowDefinition.getId()).workType(WorkType.CHECKER) + .name(checkerWorkflowDefinition.getName()) + .parameterFromString(checkerWorkflowDefinition.getParameters()) + .processingType(checkerWorkflowDefinition.getProcessingType()).works(new HashSet<>()) + .numberOfWorkUnits(checkerWorkflowDefinition.getNumberOfWorks()).build(); + workDefinitionResponseDTOs.add(checkerWorkflowDefinitionDTO); + if (workflow.getWorks() == null) { + workflow.setWorks(new HashSet<>()); } + workflow.getWorks().add(checkerWorkflowDefinitionDTO); } - return workDefinitionResponseDTOs.get(0).getWorks(); } public void cleanAllDefinitionMappings() { diff --git a/workflow-service/src/test/java/com/redhat/parodos/workflow/WorkFlowDelegateTest.java b/workflow-service/src/test/java/com/redhat/parodos/workflow/WorkFlowDelegateTest.java index 2a8364760..41f9099f2 100644 --- a/workflow-service/src/test/java/com/redhat/parodos/workflow/WorkFlowDelegateTest.java +++ b/workflow-service/src/test/java/com/redhat/parodos/workflow/WorkFlowDelegateTest.java @@ -17,6 +17,7 @@ import java.util.HashMap; import java.util.List; +import java.util.Set; import java.util.UUID; import com.fasterxml.jackson.core.type.TypeReference; @@ -115,8 +116,8 @@ private WorkFlowDefinitionResponseDTO sampleWorkflowDefinitionResponse() { return WorkFlowDefinitionResponseDTO .builder().name( TEST_WORKFLOW_NAME) - .works(List.of(WorkDefinitionResponseDTO.builder().name(TEST_SUB_WORKFLOW_NAME) - .workType(WorkType.WORKFLOW).works(List.of(WorkDefinitionResponseDTO.builder() + .works(Set.of(WorkDefinitionResponseDTO.builder().name(TEST_SUB_WORKFLOW_NAME) + .workType(WorkType.WORKFLOW).works(Set.of(WorkDefinitionResponseDTO.builder() .name(TEST_TASK_NAME).workType(WorkType.TASK).build())) .build())) .build(); diff --git a/workflow-service/src/test/java/com/redhat/parodos/workflow/definition/controller/WorkFlowDefinitionControllerTest.java b/workflow-service/src/test/java/com/redhat/parodos/workflow/definition/controller/WorkFlowDefinitionControllerTest.java index bffd16812..d22c25fd1 100644 --- a/workflow-service/src/test/java/com/redhat/parodos/workflow/definition/controller/WorkFlowDefinitionControllerTest.java +++ b/workflow-service/src/test/java/com/redhat/parodos/workflow/definition/controller/WorkFlowDefinitionControllerTest.java @@ -1,6 +1,7 @@ package com.redhat.parodos.workflow.definition.controller; import java.util.List; +import java.util.Set; import java.util.UUID; import com.redhat.parodos.ControllerMockClient; @@ -167,7 +168,7 @@ private WorkFlowDefinitionResponseDTO createSampleWorkFlowDefinition(String name WorkFlowDefinitionResponseDTO workFlowDefinitionResponseDTO = new WorkFlowDefinitionResponseDTO(); workFlowDefinitionResponseDTO.setName(name); workFlowDefinitionResponseDTO.setId(UUID.randomUUID()); - workFlowDefinitionResponseDTO.setWorks(List.of(createSampleWorkFlowTaskDefinition("task1"))); + workFlowDefinitionResponseDTO.setWorks(Set.of(createSampleWorkFlowTaskDefinition("task1"))); return workFlowDefinitionResponseDTO; } diff --git a/workflow-service/src/test/java/com/redhat/parodos/workflow/definition/service/WorkFlowDefinitionServiceImplTest.java b/workflow-service/src/test/java/com/redhat/parodos/workflow/definition/service/WorkFlowDefinitionServiceImplTest.java index 3df0ac6d0..18665dc6a 100644 --- a/workflow-service/src/test/java/com/redhat/parodos/workflow/definition/service/WorkFlowDefinitionServiceImplTest.java +++ b/workflow-service/src/test/java/com/redhat/parodos/workflow/definition/service/WorkFlowDefinitionServiceImplTest.java @@ -24,6 +24,7 @@ import java.util.UUID; import com.redhat.parodos.common.exceptions.ResourceNotFoundException; +import com.redhat.parodos.workflow.definition.dto.WorkDefinitionResponseDTO; import com.redhat.parodos.workflow.definition.dto.WorkFlowCheckerDTO; import com.redhat.parodos.workflow.definition.dto.WorkFlowDefinitionResponseDTO; import com.redhat.parodos.workflow.definition.entity.WorkFlowCheckerMappingDefinition; @@ -53,6 +54,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; @@ -248,10 +250,11 @@ public void getWorkFlowDefinitionByNameWithMasterWorkflow() { verify(this.workFlowDefinitionRepository, times(1)).findFirstByName(any()); when(this.workFlowDefinitionRepository.findFirstByName(any())).thenReturn(sampleWorkFlowDefinition(TEST)); - + Optional firstWork = result.getWorks().stream().findFirst(); + assertTrue(firstWork.isPresent()); assertEquals(result.getWorks().size(), 1); - assertEquals(result.getWorks().get(0).getName(), "SubWorkFlow"); - assertEquals(result.getWorks().get(0).getWorkType(), WorkType.WORKFLOW); + assertEquals(firstWork.get().getName(), "SubWorkFlow"); + assertEquals(firstWork.get().getWorkType(), WorkType.WORKFLOW); } @Test diff --git a/workflow-service/src/test/java/com/redhat/parodos/workflow/execution/service/WorkFlowServiceImplTest.java b/workflow-service/src/test/java/com/redhat/parodos/workflow/execution/service/WorkFlowServiceImplTest.java index ed286c8bb..c1fed2cfa 100644 --- a/workflow-service/src/test/java/com/redhat/parodos/workflow/execution/service/WorkFlowServiceImplTest.java +++ b/workflow-service/src/test/java/com/redhat/parodos/workflow/execution/service/WorkFlowServiceImplTest.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; import java.util.UUID; import com.redhat.parodos.common.exceptions.ResourceNotFoundException; @@ -163,7 +164,7 @@ void executeWithDTOWithValidData() { workFlowExecution.setId(UUID.randomUUID()); when(this.workFlowRepository.save(any())).thenReturn(workFlowExecution); WorkFlowDefinitionResponseDTO workFlowDefinitionResponseDTO = WorkFlowDefinitionResponseDTO.builder() - .name(TEST_WORKFLOW_NAME).works(List.of()).build(); + .name(TEST_WORKFLOW_NAME).works(Set.of()).build(); when(this.workFlowDefinitionService.getWorkFlowDefinitionByName(TEST_WORKFLOW_NAME)) .thenReturn(workFlowDefinitionResponseDTO); when(this.userService.getUserEntityByUsername("test-user")).thenReturn(user); @@ -205,7 +206,7 @@ void executeWithDTOWithMissingInvokingExecutionContext() { UUID invokingExecutionId = UUID.randomUUID(); when(this.workFlowRepository.findById(invokingExecutionId)).thenReturn(Optional.empty()); WorkFlowDefinitionResponseDTO workFlowDefinitionResponseDTO = WorkFlowDefinitionResponseDTO.builder() - .name(TEST_WORKFLOW_NAME).works(List.of()).build(); + .name(TEST_WORKFLOW_NAME).works(Set.of()).build(); when(this.workFlowDefinitionService.getWorkFlowDefinitionByName(TEST_WORKFLOW_NAME)) .thenReturn(workFlowDefinitionResponseDTO); when(this.userService.getUserEntityByUsername("test-user")).thenReturn(user); @@ -263,7 +264,7 @@ void executeWithDTOWithEmptyInvokingExecutionContext() { // @formatter:on when(this.workFlowRepository.findById(invokingExecutionId)).thenReturn(Optional.of(invokingWorkFlowExecution)); WorkFlowDefinitionResponseDTO workFlowDefinitionResponseDTO = WorkFlowDefinitionResponseDTO.builder() - .name(TEST_WORKFLOW_NAME).works(List.of()).build(); + .name(TEST_WORKFLOW_NAME).works(Set.of()).build(); when(this.workFlowDefinitionService.getWorkFlowDefinitionByName(TEST_WORKFLOW_NAME)) .thenReturn(workFlowDefinitionResponseDTO); when(this.userService.getUserEntityByUsername("test-user")).thenReturn(user); @@ -330,7 +331,7 @@ void executeWithDTOWithInvokingExecutionContext() { // @formatter:on when(this.workFlowRepository.findById(invokingExecutionId)).thenReturn(Optional.of(invokingWorkFlowExecution)); WorkFlowDefinitionResponseDTO workFlowDefinitionResponseDTO = WorkFlowDefinitionResponseDTO.builder() - .name(TEST_WORKFLOW_NAME).works(List.of()).build(); + .name(TEST_WORKFLOW_NAME).works(Set.of()).build(); when(this.workFlowDefinitionService.getWorkFlowDefinitionByName(TEST_WORKFLOW_NAME)) .thenReturn(workFlowDefinitionResponseDTO); when(this.userService.getUserEntityByUsername("test-user")).thenReturn(user);