diff --git a/workflow-examples/src/test/java/com/redhat/parodos/examples/integration/ComplexWorkFlow.java b/workflow-examples/src/test/java/com/redhat/parodos/examples/integration/ComplexWorkFlow.java
index 795451d55..0ddd1d252 100644
--- a/workflow-examples/src/test/java/com/redhat/parodos/examples/integration/ComplexWorkFlow.java
+++ b/workflow-examples/src/test/java/com/redhat/parodos/examples/integration/ComplexWorkFlow.java
@@ -11,7 +11,6 @@
import com.redhat.parodos.sdk.model.WorkFlowDefinitionResponseDTO;
import com.redhat.parodos.sdk.model.WorkFlowRequestDTO;
import com.redhat.parodos.sdk.model.WorkFlowResponseDTO;
-import com.redhat.parodos.sdk.model.WorkFlowResponseDTO.WorkStatusEnum;
import com.redhat.parodos.sdk.model.WorkFlowStatusResponseDTO;
import com.redhat.parodos.sdk.model.WorkRequestDTO;
import com.redhat.parodos.workflow.utils.CredUtils;
@@ -67,10 +66,10 @@ public void runComplexWorkFlow() throws ApiException, InterruptedException {
.arguments(List.of(new ArgumentRequestDTO().key("GIT_REPO_URL").value("git_repo_url")))));
WorkFlowResponseDTO workFlowResponseDTO = workflowApi.execute(workFlowRequestDTO);
- assertEquals(WorkStatusEnum.COMPLETED, workFlowResponseDTO.getWorkStatus());
+ assertEquals(WorkFlowResponseDTO.WorkStatusEnum.COMPLETED, workFlowResponseDTO.getWorkStatus());
log.info("workflow finished successfully with response: {}", workFlowResponseDTO);
if (workFlowResponseDTO.getWorkFlowOptions() == null
- || workFlowResponseDTO.getWorkStatus() != WorkStatusEnum.COMPLETED) {
+ || workFlowResponseDTO.getWorkStatus() != WorkFlowResponseDTO.WorkStatusEnum.COMPLETED) {
fail("There is no valid INFRASTRUCTURE_OPTION");
}
@@ -112,7 +111,7 @@ public void runComplexWorkFlow() throws ApiException, InterruptedException {
workFlowResponseDTO = workflowApi.execute(workFlowRequestDTO);
assertNotNull("There is no valid WorkFlowExecutionId", workFlowResponseDTO.getWorkFlowExecutionId());
- assertEquals(workFlowResponseDTO.getWorkStatus(), WorkStatusEnum.IN_PROGRESS);
+ assertEquals(workFlowResponseDTO.getWorkStatus(), WorkFlowResponseDTO.WorkStatusEnum.IN_PROGRESS);
log.info("Onboarding workflow execution id: {}", workFlowResponseDTO.getWorkFlowExecutionId());
WorkFlowStatusResponseDTO workFlowStatusResponseDTO = waitWorkflowStatusAsync(workflowApi,
@@ -120,7 +119,7 @@ public void runComplexWorkFlow() throws ApiException, InterruptedException {
assertNotNull(workFlowStatusResponseDTO);
assertNotNull(workFlowStatusResponseDTO.getWorkFlowExecutionId());
- assertEquals(WorkStatusEnum.COMPLETED.toString(), workFlowStatusResponseDTO.getStatus());
+ assertEquals(WorkFlowResponseDTO.WorkStatusEnum.COMPLETED.toString(), workFlowStatusResponseDTO.getStatus());
log.info("Onboarding workflow execution completed with status {}", workFlowStatusResponseDTO.getStatus());
}
diff --git a/workflow-examples/src/test/java/com/redhat/parodos/examples/integration/EscalationFlow.java b/workflow-examples/src/test/java/com/redhat/parodos/examples/integration/EscalationFlow.java
index f65b5d771..8254d8e2c 100644
--- a/workflow-examples/src/test/java/com/redhat/parodos/examples/integration/EscalationFlow.java
+++ b/workflow-examples/src/test/java/com/redhat/parodos/examples/integration/EscalationFlow.java
@@ -7,7 +7,6 @@
import com.redhat.parodos.sdk.model.ProjectResponseDTO;
import com.redhat.parodos.sdk.model.WorkFlowRequestDTO;
import com.redhat.parodos.sdk.model.WorkFlowResponseDTO;
-import com.redhat.parodos.sdk.model.WorkFlowResponseDTO.WorkStatusEnum;
import com.redhat.parodos.sdk.model.WorkFlowStatusResponseDTO;
import com.redhat.parodos.workflow.utils.CredUtils;
import lombok.extern.slf4j.Slf4j;
@@ -57,7 +56,7 @@ public void runEscalationFlow() throws ApiException, InterruptedException {
WorkFlowResponseDTO workFlowResponseDTO = workflowApi.execute(workFlowRequestDTO);
assertNotNull("There is no valid WorkFlowExecutionId", workFlowResponseDTO.getWorkFlowExecutionId());
- assertEquals(workFlowResponseDTO.getWorkStatus(), WorkStatusEnum.IN_PROGRESS);
+ assertEquals(workFlowResponseDTO.getWorkStatus(), WorkFlowResponseDTO.WorkStatusEnum.IN_PROGRESS);
log.info("Simple escalation workflow execution id: {}", workFlowResponseDTO.getWorkFlowExecutionId());
log.info("Simple Escalation Flow {}", workFlowResponseDTO.getWorkStatus());
log.info("Waiting for checkers to complete...");
@@ -67,7 +66,7 @@ public void runEscalationFlow() throws ApiException, InterruptedException {
assertNotNull(workFlowStatusResponseDTO);
assertNotNull(workFlowStatusResponseDTO.getWorkFlowExecutionId());
- assertEquals(WorkStatusEnum.COMPLETED.toString(), workFlowStatusResponseDTO.getStatus());
+ assertEquals(WorkFlowResponseDTO.WorkStatusEnum.COMPLETED.toString(), workFlowStatusResponseDTO.getStatus());
log.info("******** Simple Escalation Flow {} ********", workFlowStatusResponseDTO.getStatus());
}
diff --git a/workflow-examples/src/test/java/com/redhat/parodos/examples/integration/KubeapiWorkFlow.java b/workflow-examples/src/test/java/com/redhat/parodos/examples/integration/KubeapiWorkFlow.java
index cd5866297..3785ee56c 100644
--- a/workflow-examples/src/test/java/com/redhat/parodos/examples/integration/KubeapiWorkFlow.java
+++ b/workflow-examples/src/test/java/com/redhat/parodos/examples/integration/KubeapiWorkFlow.java
@@ -1,6 +1,5 @@
package com.redhat.parodos.examples.integration;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.redhat.parodos.examples.integration.utils.ExamplesUtils;
import com.redhat.parodos.sdk.api.WorkflowApi;
import com.redhat.parodos.sdk.api.WorkflowDefinitionApi;
diff --git a/workflow-examples/src/test/java/com/redhat/parodos/examples/integration/PrebuiltWorkFlow.java b/workflow-examples/src/test/java/com/redhat/parodos/examples/integration/PrebuiltWorkFlow.java
index 0cc60a566..7c6e9da0b 100644
--- a/workflow-examples/src/test/java/com/redhat/parodos/examples/integration/PrebuiltWorkFlow.java
+++ b/workflow-examples/src/test/java/com/redhat/parodos/examples/integration/PrebuiltWorkFlow.java
@@ -8,10 +8,10 @@
import com.redhat.parodos.sdk.invoker.Configuration;
import com.redhat.parodos.sdk.model.ProjectResponseDTO;
import com.redhat.parodos.sdk.model.WorkFlowDefinitionResponseDTO;
+import com.redhat.parodos.sdk.model.WorkFlowResponseDTO;
import com.redhat.parodos.sdk.model.WorkRequestDTO;
import com.redhat.parodos.sdk.model.ArgumentRequestDTO;
import com.redhat.parodos.sdk.model.WorkFlowRequestDTO;
-import com.redhat.parodos.sdk.model.WorkFlowResponseDTO;
import com.redhat.parodos.workflow.consts.WorkFlowConstants;
import com.redhat.parodos.workflow.enums.WorkFlowType;
import com.redhat.parodos.workflow.enums.WorkType;
diff --git a/workflow-examples/src/test/java/com/redhat/parodos/examples/integration/SimpleWorkFlow.java b/workflow-examples/src/test/java/com/redhat/parodos/examples/integration/SimpleWorkFlow.java
index 90f3aa597..d215542d6 100644
--- a/workflow-examples/src/test/java/com/redhat/parodos/examples/integration/SimpleWorkFlow.java
+++ b/workflow-examples/src/test/java/com/redhat/parodos/examples/integration/SimpleWorkFlow.java
@@ -11,7 +11,6 @@
import com.redhat.parodos.sdk.model.WorkFlowDefinitionResponseDTO;
import com.redhat.parodos.sdk.model.WorkFlowRequestDTO;
import com.redhat.parodos.sdk.model.WorkFlowResponseDTO;
-import com.redhat.parodos.sdk.model.WorkFlowResponseDTO.WorkStatusEnum;
import com.redhat.parodos.sdk.model.WorkRequestDTO;
import com.redhat.parodos.workflow.consts.WorkFlowConstants;
import com.redhat.parodos.workflow.enums.WorkFlowType;
@@ -114,7 +113,7 @@ public void runSimpleWorkFlow() throws ApiException, InterruptedException {
assertNotNull(workFlowResponseDTO.getWorkFlowExecutionId());
assertNull(workFlowResponseDTO.getWorkFlowOptions());
assertNotNull(workFlowResponseDTO.getWorkStatus());
- assertEquals(WorkStatusEnum.COMPLETED, workFlowResponseDTO.getWorkStatus());
+ assertEquals(WorkFlowResponseDTO.WorkStatusEnum.COMPLETED, workFlowResponseDTO.getWorkStatus());
log.info("workflow finished successfully with response: {}", workFlowResponseDTO);
log.info("******** Simple Sequence Flow Completed ********");
diff --git a/workflow-service-sdk/README.md b/workflow-service-sdk/README.md
index 5161daf76..6d0065ef5 100644
--- a/workflow-service-sdk/README.md
+++ b/workflow-service-sdk/README.md
@@ -117,6 +117,7 @@ Class | Method | HTTP request | Description
*ProjectApi* | [**getProjects**](docs/ProjectApi.md#getProjects) | **GET** /api/v1/projects | Returns a list of project
*WorkflowApi* | [**execute**](docs/WorkflowApi.md#execute) | **POST** /api/v1/workflows | Executes a workflow
*WorkflowApi* | [**getStatus**](docs/WorkflowApi.md#getStatus) | **GET** /api/v1/workflows/{workFlowExecutionId}/status | Returns a workflow status
+*WorkflowApi* | [**getStatusByProjectId**](docs/WorkflowApi.md#getStatusByProjectId) | **GET** /api/v1/workflows | Returns workflows by project id
*WorkflowApi* | [**getWorkflowParameters**](docs/WorkflowApi.md#getWorkflowParameters) | **GET** /api/v1/workflows/{workFlowExecutionId}/context | Returns workflow context parameters
*WorkflowApi* | [**updateWorkFlowCheckerTaskStatus**](docs/WorkflowApi.md#updateWorkFlowCheckerTaskStatus) | **POST** /api/v1/workflows/{workFlowExecutionId}/checkers/{workFlowCheckerTaskName} | Updates a workflow checker task status
*WorkflowDefinitionApi* | [**getWorkFlowDefinitionById**](docs/WorkflowDefinitionApi.md#getWorkFlowDefinitionById) | **GET** /api/v1/workflowdefinitions/{id} | Returns information about a workflow definition by id
@@ -127,6 +128,7 @@ Class | Method | HTTP request | Description
## Documentation for Models
- [ArgumentRequestDTO](docs/ArgumentRequestDTO.md)
+ - [GetStatusByProjectId200Response](docs/GetStatusByProjectId200Response.md)
- [ProjectRequestDTO](docs/ProjectRequestDTO.md)
- [ProjectResponseDTO](docs/ProjectResponseDTO.md)
- [UpdateParameter200Response](docs/UpdateParameter200Response.md)
diff --git a/workflow-service-sdk/api/openapi.yaml b/workflow-service-sdk/api/openapi.yaml
index bdc51fb04..a279bb212 100644
--- a/workflow-service-sdk/api/openapi.yaml
+++ b/workflow-service-sdk/api/openapi.yaml
@@ -203,6 +203,32 @@ paths:
x-content-type: application/json
x-accepts: application/json
/api/v1/workflows:
+ get:
+ operationId: getStatusByProjectId
+ parameters:
+ - explode: true
+ in: query
+ name: projectId
+ required: false
+ schema:
+ format: uuid
+ type: string
+ style: form
+ responses:
+ "200":
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/getStatusByProjectId_200_response'
+ description: Succeeded
+ "401":
+ description: Unauthorized
+ "403":
+ description: Forbidden
+ summary: Returns workflows by project id
+ tags:
+ - Workflow
+ x-accepts: application/json
post:
operationId: execute
requestBody:
@@ -921,6 +947,7 @@ components:
WorkFlowResponseDTO:
example:
workStatus: FAILED
+ workFlowName: workFlowName
workFlowOptions:
continuationOptions:
- identifier: identifier
@@ -1006,11 +1033,26 @@ components:
details:
- details
- details
+ endDate: endDate
workFlowExecutionId: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
+ createUser: createUser
+ projectId: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
+ startDate: startDate
properties:
+ createUser:
+ type: string
+ endDate:
+ type: string
+ projectId:
+ format: uuid
+ type: string
+ startDate:
+ type: string
workFlowExecutionId:
format: uuid
type: string
+ workFlowName:
+ type: string
workFlowOptions:
$ref: '#/components/schemas/WorkFlowOptions'
workStatus:
@@ -1117,4 +1159,7 @@ components:
updateParameter_200_response:
allOf:
- $ref: '#/components/schemas/WorkParameterValueResponseDTO'
+ getStatusByProjectId_200_response:
+ allOf:
+ - $ref: '#/components/schemas/WorkFlowStatusResponseDTO'
diff --git a/workflow-service-sdk/docs/GetStatusByProjectId200Response.md b/workflow-service-sdk/docs/GetStatusByProjectId200Response.md
new file mode 100644
index 000000000..314714cb5
--- /dev/null
+++ b/workflow-service-sdk/docs/GetStatusByProjectId200Response.md
@@ -0,0 +1,16 @@
+
+
+# GetStatusByProjectId200Response
+
+
+## Properties
+
+| Name | Type | Description | Notes |
+|------------ | ------------- | ------------- | -------------|
+|**status** | **String** | | [optional] |
+|**workFlowExecutionId** | **UUID** | | [optional] |
+|**workFlowName** | **String** | | [optional] |
+|**works** | [**List<WorkStatusResponseDTO>**](WorkStatusResponseDTO.md) | | [optional] |
+
+
+
diff --git a/workflow-service-sdk/docs/WorkFlowResponseDTO.md b/workflow-service-sdk/docs/WorkFlowResponseDTO.md
index 562089907..63cc6a73b 100644
--- a/workflow-service-sdk/docs/WorkFlowResponseDTO.md
+++ b/workflow-service-sdk/docs/WorkFlowResponseDTO.md
@@ -7,7 +7,12 @@
| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
+|**createUser** | **String** | | [optional] |
+|**endDate** | **String** | | [optional] |
+|**projectId** | **UUID** | | [optional] |
+|**startDate** | **String** | | [optional] |
|**workFlowExecutionId** | **UUID** | | [optional] |
+|**workFlowName** | **String** | | [optional] |
|**workFlowOptions** | [**WorkFlowOptions**](WorkFlowOptions.md) | | [optional] |
|**workStatus** | [**WorkStatusEnum**](#WorkStatusEnum) | | [optional] |
diff --git a/workflow-service-sdk/docs/WorkflowApi.md b/workflow-service-sdk/docs/WorkflowApi.md
index d53b34e2a..3e1516b73 100644
--- a/workflow-service-sdk/docs/WorkflowApi.md
+++ b/workflow-service-sdk/docs/WorkflowApi.md
@@ -6,6 +6,7 @@ All URIs are relative to *http://localhost:8080*
|------------- | ------------- | -------------|
| [**execute**](WorkflowApi.md#execute) | **POST** /api/v1/workflows | Executes a workflow |
| [**getStatus**](WorkflowApi.md#getStatus) | **GET** /api/v1/workflows/{workFlowExecutionId}/status | Returns a workflow status |
+| [**getStatusByProjectId**](WorkflowApi.md#getStatusByProjectId) | **GET** /api/v1/workflows | Returns workflows by project id |
| [**getWorkflowParameters**](WorkflowApi.md#getWorkflowParameters) | **GET** /api/v1/workflows/{workFlowExecutionId}/context | Returns workflow context parameters |
| [**updateWorkFlowCheckerTaskStatus**](WorkflowApi.md#updateWorkFlowCheckerTaskStatus) | **POST** /api/v1/workflows/{workFlowExecutionId}/checkers/{workFlowCheckerTaskName} | Updates a workflow checker task status |
@@ -134,6 +135,68 @@ No authorization required
| **401** | Unauthorized | - |
| **403** | Forbidden | - |
+
+# **getStatusByProjectId**
+> GetStatusByProjectId200Response getStatusByProjectId(projectId)
+
+Returns workflows by project id
+
+### Example
+```java
+// Import classes:
+import com.redhat.parodos.sdk.invoker.ApiClient;
+import com.redhat.parodos.sdk.invoker.ApiException;
+import com.redhat.parodos.sdk.invoker.Configuration;
+import com.redhat.parodos.sdk.invoker.models.*;
+import com.redhat.parodos.sdk.api.WorkflowApi;
+
+public class Example {
+ public static void main(String[] args) {
+ ApiClient defaultClient = Configuration.getDefaultApiClient();
+ defaultClient.setBasePath("http://localhost:8080");
+
+ WorkflowApi apiInstance = new WorkflowApi(defaultClient);
+ UUID projectId = UUID.randomUUID(); // UUID |
+ try {
+ GetStatusByProjectId200Response result = apiInstance.getStatusByProjectId(projectId);
+ System.out.println(result);
+ } catch (ApiException e) {
+ System.err.println("Exception when calling WorkflowApi#getStatusByProjectId");
+ System.err.println("Status code: " + e.getCode());
+ System.err.println("Reason: " + e.getResponseBody());
+ System.err.println("Response headers: " + e.getResponseHeaders());
+ e.printStackTrace();
+ }
+ }
+}
+```
+
+### Parameters
+
+| Name | Type | Description | Notes |
+|------------- | ------------- | ------------- | -------------|
+| **projectId** | **UUID**| | [optional] |
+
+### Return type
+
+[**GetStatusByProjectId200Response**](GetStatusByProjectId200Response.md)
+
+### Authorization
+
+No authorization required
+
+### HTTP request headers
+
+ - **Content-Type**: Not defined
+ - **Accept**: application/json
+
+### HTTP response details
+| Status code | Description | Response headers |
+|-------------|-------------|------------------|
+| **200** | Succeeded | - |
+| **401** | Unauthorized | - |
+| **403** | Forbidden | - |
+
# **getWorkflowParameters**
> WorkFlowContextResponseDTO getWorkflowParameters(workFlowExecutionId, param)
diff --git a/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/api/WorkflowApi.java b/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/api/WorkflowApi.java
index 2241d2a87..9952c22ea 100644
--- a/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/api/WorkflowApi.java
+++ b/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/api/WorkflowApi.java
@@ -25,6 +25,7 @@
import java.io.IOException;
+import com.redhat.parodos.sdk.model.GetStatusByProjectId200Response;
import java.util.UUID;
import com.redhat.parodos.sdk.model.WorkFlowCheckerTaskRequestDTO;
import com.redhat.parodos.sdk.model.WorkFlowContextResponseDTO;
@@ -483,6 +484,206 @@ public okhttp3.Call getStatusAsync(UUID workFlowExecutionId, final ApiCallback
+ *
+ * Status Code |
+ * Description |
+ * Response Headers |
+ *
+ *
+ * 200 |
+ * Succeeded |
+ * - |
+ *
+ *
+ * 401 |
+ * Unauthorized |
+ * - |
+ *
+ *
+ * 403 |
+ * Forbidden |
+ * - |
+ *
+ *
+ */
+ public okhttp3.Call getStatusByProjectIdCall(UUID projectId, final ApiCallback _callback) throws ApiException {
+ String basePath = null;
+ // Operation Servers
+ String[] localBasePaths = new String[] {};
+
+ // Determine Base Path to Use
+ if (localCustomBaseUrl != null) {
+ basePath = localCustomBaseUrl;
+ }
+ else if (localBasePaths.length > 0) {
+ basePath = localBasePaths[localHostIndex];
+ }
+ else {
+ basePath = null;
+ }
+
+ Object localVarPostBody = null;
+
+ // create path and map variables
+ String localVarPath = "/api/v1/workflows";
+
+ List localVarQueryParams = new ArrayList();
+ List localVarCollectionQueryParams = new ArrayList();
+ Map localVarHeaderParams = new HashMap();
+ Map localVarCookieParams = new HashMap();
+ Map localVarFormParams = new HashMap();
+
+ if (projectId != null) {
+ localVarQueryParams.addAll(localVarApiClient.parameterToPair("projectId", projectId));
+ }
+
+ final String[] localVarAccepts = { "application/json" };
+ final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);
+ if (localVarAccept != null) {
+ localVarHeaderParams.put("Accept", localVarAccept);
+ }
+
+ final String[] localVarContentTypes = {};
+ final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes);
+ if (localVarContentType != null) {
+ localVarHeaderParams.put("Content-Type", localVarContentType);
+ }
+
+ String[] localVarAuthNames = new String[] {};
+ return localVarApiClient.buildCall(basePath, localVarPath, "GET", localVarQueryParams,
+ localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams,
+ localVarFormParams, localVarAuthNames, _callback);
+ }
+
+ @SuppressWarnings("rawtypes")
+ private okhttp3.Call getStatusByProjectIdValidateBeforeCall(UUID projectId, final ApiCallback _callback)
+ throws ApiException {
+ return getStatusByProjectIdCall(projectId, _callback);
+
+ }
+
+ /**
+ * Returns workflows by project id
+ * @param projectId (optional)
+ * @return GetStatusByProjectId200Response
+ * @throws ApiException If fail to call the API, e.g. server error or cannot
+ * deserialize the response body
+ * @http.response.details
+ *
+ *
+ * Status Code |
+ * Description |
+ * Response Headers |
+ *
+ *
+ * 200 |
+ * Succeeded |
+ * - |
+ *
+ *
+ * 401 |
+ * Unauthorized |
+ * - |
+ *
+ *
+ * 403 |
+ * Forbidden |
+ * - |
+ *
+ *
+ */
+ public GetStatusByProjectId200Response getStatusByProjectId(UUID projectId) throws ApiException {
+ ApiResponse localVarResp = getStatusByProjectIdWithHttpInfo(projectId);
+ return localVarResp.getData();
+ }
+
+ /**
+ * Returns workflows by project id
+ * @param projectId (optional)
+ * @return ApiResponse<GetStatusByProjectId200Response>
+ * @throws ApiException If fail to call the API, e.g. server error or cannot
+ * deserialize the response body
+ * @http.response.details
+ *
+ *
+ * Status Code |
+ * Description |
+ * Response Headers |
+ *
+ *
+ * 200 |
+ * Succeeded |
+ * - |
+ *
+ *
+ * 401 |
+ * Unauthorized |
+ * - |
+ *
+ *
+ * 403 |
+ * Forbidden |
+ * - |
+ *
+ *
+ */
+ public ApiResponse getStatusByProjectIdWithHttpInfo(UUID projectId)
+ throws ApiException {
+ okhttp3.Call localVarCall = getStatusByProjectIdValidateBeforeCall(projectId, null);
+ Type localVarReturnType = new TypeToken() {
+ }.getType();
+ return localVarApiClient.execute(localVarCall, localVarReturnType);
+ }
+
+ /**
+ * Returns workflows by project id (asynchronously)
+ * @param projectId (optional)
+ * @param _callback The callback to be executed when the API call finishes
+ * @return The request call
+ * @throws ApiException If fail to process the API call, e.g. serializing the request
+ * body object
+ * @http.response.details
+ *
+ *
+ * Status Code |
+ * Description |
+ * Response Headers |
+ *
+ *
+ * 200 |
+ * Succeeded |
+ * - |
+ *
+ *
+ * 401 |
+ * Unauthorized |
+ * - |
+ *
+ *
+ * 403 |
+ * Forbidden |
+ * - |
+ *
+ *
+ */
+ public okhttp3.Call getStatusByProjectIdAsync(UUID projectId,
+ final ApiCallback _callback) throws ApiException {
+
+ okhttp3.Call localVarCall = getStatusByProjectIdValidateBeforeCall(projectId, _callback);
+ Type localVarReturnType = new TypeToken() {
+ }.getType();
+ localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
+ return localVarCall;
+ }
+
/**
* Build call for getWorkflowParameters
* @param workFlowExecutionId (required)
diff --git a/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/invoker/JSON.java b/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/invoker/JSON.java
index 7942bf303..1cff5ddf4 100644
--- a/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/invoker/JSON.java
+++ b/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/invoker/JSON.java
@@ -94,6 +94,8 @@ private static Class getClassByDiscriminator(Map classByDiscriminatorValue, Stri
gsonBuilder.registerTypeAdapter(byte[].class, byteArrayAdapter);
gsonBuilder.registerTypeAdapterFactory(
new com.redhat.parodos.sdk.model.ArgumentRequestDTO.CustomTypeAdapterFactory());
+ gsonBuilder.registerTypeAdapterFactory(
+ new com.redhat.parodos.sdk.model.GetStatusByProjectId200Response.CustomTypeAdapterFactory());
gsonBuilder.registerTypeAdapterFactory(
new com.redhat.parodos.sdk.model.ProjectRequestDTO.CustomTypeAdapterFactory());
gsonBuilder.registerTypeAdapterFactory(
diff --git a/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/model/GetStatusByProjectId200Response.java b/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/model/GetStatusByProjectId200Response.java
new file mode 100644
index 000000000..e875ce7d8
--- /dev/null
+++ b/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/model/GetStatusByProjectId200Response.java
@@ -0,0 +1,344 @@
+/*
+ * Parodos Workflow Service API
+ * This is the API documentation for the Parodos Workflow Service. It provides operations to execute assessments to determine infrastructure options (tooling + environments). Also executes infrastructure task workflows to call downstream systems to stand-up an infrastructure option.
+ *
+ * The version of the OpenAPI document: v1.0.0
+ *
+ *
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
+ * https://openapi-generator.tech
+ * Do not edit the class manually.
+ */
+
+package com.redhat.parodos.sdk.model;
+
+import java.util.Objects;
+import java.util.Arrays;
+import com.google.gson.TypeAdapter;
+import com.google.gson.annotations.JsonAdapter;
+import com.google.gson.annotations.SerializedName;
+import com.google.gson.stream.JsonReader;
+import com.google.gson.stream.JsonWriter;
+import com.redhat.parodos.sdk.model.WorkStatusResponseDTO;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParseException;
+import com.google.gson.TypeAdapterFactory;
+import com.google.gson.reflect.TypeToken;
+
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import com.redhat.parodos.sdk.invoker.JSON;
+
+/**
+ * GetStatusByProjectId200Response
+ */
+@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
+public class GetStatusByProjectId200Response {
+
+ public static final String SERIALIZED_NAME_STATUS = "status";
+
+ @SerializedName(SERIALIZED_NAME_STATUS)
+ private String status;
+
+ public static final String SERIALIZED_NAME_WORK_FLOW_EXECUTION_ID = "workFlowExecutionId";
+
+ @SerializedName(SERIALIZED_NAME_WORK_FLOW_EXECUTION_ID)
+ private UUID workFlowExecutionId;
+
+ public static final String SERIALIZED_NAME_WORK_FLOW_NAME = "workFlowName";
+
+ @SerializedName(SERIALIZED_NAME_WORK_FLOW_NAME)
+ private String workFlowName;
+
+ public static final String SERIALIZED_NAME_WORKS = "works";
+
+ @SerializedName(SERIALIZED_NAME_WORKS)
+ private List works = new ArrayList<>();
+
+ public GetStatusByProjectId200Response() {
+ }
+
+ public GetStatusByProjectId200Response status(String status) {
+
+ this.status = status;
+ return this;
+ }
+
+ /**
+ * Get status
+ * @return status
+ **/
+ @javax.annotation.Nullable
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public GetStatusByProjectId200Response workFlowExecutionId(UUID workFlowExecutionId) {
+
+ this.workFlowExecutionId = workFlowExecutionId;
+ return this;
+ }
+
+ /**
+ * Get workFlowExecutionId
+ * @return workFlowExecutionId
+ **/
+ @javax.annotation.Nullable
+
+ public UUID getWorkFlowExecutionId() {
+ return workFlowExecutionId;
+ }
+
+ public void setWorkFlowExecutionId(UUID workFlowExecutionId) {
+ this.workFlowExecutionId = workFlowExecutionId;
+ }
+
+ public GetStatusByProjectId200Response workFlowName(String workFlowName) {
+
+ this.workFlowName = workFlowName;
+ return this;
+ }
+
+ /**
+ * Get workFlowName
+ * @return workFlowName
+ **/
+ @javax.annotation.Nullable
+
+ public String getWorkFlowName() {
+ return workFlowName;
+ }
+
+ public void setWorkFlowName(String workFlowName) {
+ this.workFlowName = workFlowName;
+ }
+
+ public GetStatusByProjectId200Response works(List works) {
+
+ this.works = works;
+ return this;
+ }
+
+ public GetStatusByProjectId200Response addWorksItem(WorkStatusResponseDTO worksItem) {
+ if (this.works == null) {
+ this.works = new ArrayList<>();
+ }
+ this.works.add(worksItem);
+ return this;
+ }
+
+ /**
+ * Get works
+ * @return works
+ **/
+ @javax.annotation.Nullable
+
+ public List getWorks() {
+ return works;
+ }
+
+ public void setWorks(List works) {
+ this.works = works;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ GetStatusByProjectId200Response getStatusByProjectId200Response = (GetStatusByProjectId200Response) o;
+ return Objects.equals(this.status, getStatusByProjectId200Response.status)
+ && Objects.equals(this.workFlowExecutionId, getStatusByProjectId200Response.workFlowExecutionId)
+ && Objects.equals(this.workFlowName, getStatusByProjectId200Response.workFlowName)
+ && Objects.equals(this.works, getStatusByProjectId200Response.works);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(status, workFlowExecutionId, workFlowName, works);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("class GetStatusByProjectId200Response {\n");
+ sb.append(" status: ").append(toIndentedString(status)).append("\n");
+ sb.append(" workFlowExecutionId: ").append(toIndentedString(workFlowExecutionId)).append("\n");
+ sb.append(" workFlowName: ").append(toIndentedString(workFlowName)).append("\n");
+ sb.append(" works: ").append(toIndentedString(works)).append("\n");
+ sb.append("}");
+ return sb.toString();
+ }
+
+ /**
+ * Convert the given object to string with each line indented by 4 spaces (except the
+ * first line).
+ */
+ private String toIndentedString(Object o) {
+ if (o == null) {
+ return "null";
+ }
+ return o.toString().replace("\n", "\n ");
+ }
+
+ public static HashSet openapiFields;
+
+ public static HashSet openapiRequiredFields;
+
+ static {
+ // a set of all properties/fields (JSON key names)
+ openapiFields = new HashSet();
+ openapiFields.add("status");
+ openapiFields.add("workFlowExecutionId");
+ openapiFields.add("workFlowName");
+ openapiFields.add("works");
+
+ // a set of required properties/fields (JSON key names)
+ openapiRequiredFields = new HashSet();
+ }
+
+ /**
+ * Validates the JSON Object and throws an exception if issues found
+ * @param jsonObj JSON Object
+ * @throws IOException if the JSON Object is invalid with respect to
+ * GetStatusByProjectId200Response
+ */
+ public static void validateJsonObject(JsonObject jsonObj) throws IOException {
+ if (jsonObj == null) {
+ if (!GetStatusByProjectId200Response.openapiRequiredFields.isEmpty()) { // has
+ // required
+ // fields
+ // but
+ // JSON
+ // object
+ // is
+ // null
+ throw new IllegalArgumentException(String.format(
+ "The required field(s) %s in GetStatusByProjectId200Response is not found in the empty JSON string",
+ GetStatusByProjectId200Response.openapiRequiredFields.toString()));
+ }
+ }
+
+ Set> entries = jsonObj.entrySet();
+ // check to see if the JSON string contains additional fields
+ for (Entry entry : entries) {
+ if (!GetStatusByProjectId200Response.openapiFields.contains(entry.getKey())) {
+ throw new IllegalArgumentException(String.format(
+ "The field `%s` in the JSON string is not defined in the `GetStatusByProjectId200Response` properties. JSON: %s",
+ entry.getKey(), jsonObj.toString()));
+ }
+ }
+ if ((jsonObj.get("status") != null && !jsonObj.get("status").isJsonNull())
+ && !jsonObj.get("status").isJsonPrimitive()) {
+ throw new IllegalArgumentException(
+ String.format("Expected the field `status` to be a primitive type in the JSON string but got `%s`",
+ jsonObj.get("status").toString()));
+ }
+ if ((jsonObj.get("workFlowExecutionId") != null && !jsonObj.get("workFlowExecutionId").isJsonNull())
+ && !jsonObj.get("workFlowExecutionId").isJsonPrimitive()) {
+ throw new IllegalArgumentException(String.format(
+ "Expected the field `workFlowExecutionId` to be a primitive type in the JSON string but got `%s`",
+ jsonObj.get("workFlowExecutionId").toString()));
+ }
+ if ((jsonObj.get("workFlowName") != null && !jsonObj.get("workFlowName").isJsonNull())
+ && !jsonObj.get("workFlowName").isJsonPrimitive()) {
+ throw new IllegalArgumentException(String.format(
+ "Expected the field `workFlowName` to be a primitive type in the JSON string but got `%s`",
+ jsonObj.get("workFlowName").toString()));
+ }
+ if (jsonObj.get("works") != null && !jsonObj.get("works").isJsonNull()) {
+ JsonArray jsonArrayworks = jsonObj.getAsJsonArray("works");
+ if (jsonArrayworks != null) {
+ // ensure the json data is an array
+ if (!jsonObj.get("works").isJsonArray()) {
+ throw new IllegalArgumentException(
+ String.format("Expected the field `works` to be an array in the JSON string but got `%s`",
+ jsonObj.get("works").toString()));
+ }
+
+ // validate the optional field `works` (array)
+ for (int i = 0; i < jsonArrayworks.size(); i++) {
+ WorkStatusResponseDTO.validateJsonObject(jsonArrayworks.get(i).getAsJsonObject());
+ }
+ ;
+ }
+ }
+ }
+
+ public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public TypeAdapter create(Gson gson, TypeToken type) {
+ if (!GetStatusByProjectId200Response.class.isAssignableFrom(type.getRawType())) {
+ return null; // this class only serializes
+ // 'GetStatusByProjectId200Response' and its subtypes
+ }
+ final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class);
+ final TypeAdapter thisAdapter = gson.getDelegateAdapter(this,
+ TypeToken.get(GetStatusByProjectId200Response.class));
+
+ return (TypeAdapter) new TypeAdapter() {
+ @Override
+ public void write(JsonWriter out, GetStatusByProjectId200Response value) throws IOException {
+ JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
+ elementAdapter.write(out, obj);
+ }
+
+ @Override
+ public GetStatusByProjectId200Response read(JsonReader in) throws IOException {
+ JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
+ validateJsonObject(jsonObj);
+ return thisAdapter.fromJsonTree(jsonObj);
+ }
+
+ }.nullSafe();
+ }
+
+ }
+
+ /**
+ * Create an instance of GetStatusByProjectId200Response given an JSON string
+ * @param jsonString JSON string
+ * @return An instance of GetStatusByProjectId200Response
+ * @throws IOException if the JSON string is invalid with respect to
+ * GetStatusByProjectId200Response
+ */
+ public static GetStatusByProjectId200Response fromJson(String jsonString) throws IOException {
+ return JSON.getGson().fromJson(jsonString, GetStatusByProjectId200Response.class);
+ }
+
+ /**
+ * Convert an instance of GetStatusByProjectId200Response to an JSON string
+ * @return JSON string
+ */
+ public String toJson() {
+ return JSON.getGson().toJson(this);
+ }
+
+}
diff --git a/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/model/WorkFlowResponseDTO.java b/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/model/WorkFlowResponseDTO.java
index cd31cbc75..95f800c6b 100644
--- a/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/model/WorkFlowResponseDTO.java
+++ b/workflow-service-sdk/src/main/java/com/redhat/parodos/sdk/model/WorkFlowResponseDTO.java
@@ -50,11 +50,36 @@
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class WorkFlowResponseDTO {
+ public static final String SERIALIZED_NAME_CREATE_USER = "createUser";
+
+ @SerializedName(SERIALIZED_NAME_CREATE_USER)
+ private String createUser;
+
+ public static final String SERIALIZED_NAME_END_DATE = "endDate";
+
+ @SerializedName(SERIALIZED_NAME_END_DATE)
+ private String endDate;
+
+ public static final String SERIALIZED_NAME_PROJECT_ID = "projectId";
+
+ @SerializedName(SERIALIZED_NAME_PROJECT_ID)
+ private UUID projectId;
+
+ public static final String SERIALIZED_NAME_START_DATE = "startDate";
+
+ @SerializedName(SERIALIZED_NAME_START_DATE)
+ private String startDate;
+
public static final String SERIALIZED_NAME_WORK_FLOW_EXECUTION_ID = "workFlowExecutionId";
@SerializedName(SERIALIZED_NAME_WORK_FLOW_EXECUTION_ID)
private UUID workFlowExecutionId;
+ public static final String SERIALIZED_NAME_WORK_FLOW_NAME = "workFlowName";
+
+ @SerializedName(SERIALIZED_NAME_WORK_FLOW_NAME)
+ private String workFlowName;
+
public static final String SERIALIZED_NAME_WORK_FLOW_OPTIONS = "workFlowOptions";
@SerializedName(SERIALIZED_NAME_WORK_FLOW_OPTIONS)
@@ -125,6 +150,86 @@ public WorkStatusEnum read(final JsonReader jsonReader) throws IOException {
public WorkFlowResponseDTO() {
}
+ public WorkFlowResponseDTO createUser(String createUser) {
+
+ this.createUser = createUser;
+ return this;
+ }
+
+ /**
+ * Get createUser
+ * @return createUser
+ **/
+ @javax.annotation.Nullable
+
+ public String getCreateUser() {
+ return createUser;
+ }
+
+ public void setCreateUser(String createUser) {
+ this.createUser = createUser;
+ }
+
+ public WorkFlowResponseDTO endDate(String endDate) {
+
+ this.endDate = endDate;
+ return this;
+ }
+
+ /**
+ * Get endDate
+ * @return endDate
+ **/
+ @javax.annotation.Nullable
+
+ public String getEndDate() {
+ return endDate;
+ }
+
+ public void setEndDate(String endDate) {
+ this.endDate = endDate;
+ }
+
+ public WorkFlowResponseDTO projectId(UUID projectId) {
+
+ this.projectId = projectId;
+ return this;
+ }
+
+ /**
+ * Get projectId
+ * @return projectId
+ **/
+ @javax.annotation.Nullable
+
+ public UUID getProjectId() {
+ return projectId;
+ }
+
+ public void setProjectId(UUID projectId) {
+ this.projectId = projectId;
+ }
+
+ public WorkFlowResponseDTO startDate(String startDate) {
+
+ this.startDate = startDate;
+ return this;
+ }
+
+ /**
+ * Get startDate
+ * @return startDate
+ **/
+ @javax.annotation.Nullable
+
+ public String getStartDate() {
+ return startDate;
+ }
+
+ public void setStartDate(String startDate) {
+ this.startDate = startDate;
+ }
+
public WorkFlowResponseDTO workFlowExecutionId(UUID workFlowExecutionId) {
this.workFlowExecutionId = workFlowExecutionId;
@@ -145,6 +250,26 @@ public void setWorkFlowExecutionId(UUID workFlowExecutionId) {
this.workFlowExecutionId = workFlowExecutionId;
}
+ public WorkFlowResponseDTO workFlowName(String workFlowName) {
+
+ this.workFlowName = workFlowName;
+ return this;
+ }
+
+ /**
+ * Get workFlowName
+ * @return workFlowName
+ **/
+ @javax.annotation.Nullable
+
+ public String getWorkFlowName() {
+ return workFlowName;
+ }
+
+ public void setWorkFlowName(String workFlowName) {
+ this.workFlowName = workFlowName;
+ }
+
public WorkFlowResponseDTO workFlowOptions(WorkFlowOptions workFlowOptions) {
this.workFlowOptions = workFlowOptions;
@@ -194,21 +319,32 @@ public boolean equals(Object o) {
return false;
}
WorkFlowResponseDTO workFlowResponseDTO = (WorkFlowResponseDTO) o;
- return Objects.equals(this.workFlowExecutionId, workFlowResponseDTO.workFlowExecutionId)
+ return Objects.equals(this.createUser, workFlowResponseDTO.createUser)
+ && Objects.equals(this.endDate, workFlowResponseDTO.endDate)
+ && Objects.equals(this.projectId, workFlowResponseDTO.projectId)
+ && Objects.equals(this.startDate, workFlowResponseDTO.startDate)
+ && Objects.equals(this.workFlowExecutionId, workFlowResponseDTO.workFlowExecutionId)
+ && Objects.equals(this.workFlowName, workFlowResponseDTO.workFlowName)
&& Objects.equals(this.workFlowOptions, workFlowResponseDTO.workFlowOptions)
&& Objects.equals(this.workStatus, workFlowResponseDTO.workStatus);
}
@Override
public int hashCode() {
- return Objects.hash(workFlowExecutionId, workFlowOptions, workStatus);
+ return Objects.hash(createUser, endDate, projectId, startDate, workFlowExecutionId, workFlowName,
+ workFlowOptions, workStatus);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class WorkFlowResponseDTO {\n");
+ sb.append(" createUser: ").append(toIndentedString(createUser)).append("\n");
+ sb.append(" endDate: ").append(toIndentedString(endDate)).append("\n");
+ sb.append(" projectId: ").append(toIndentedString(projectId)).append("\n");
+ sb.append(" startDate: ").append(toIndentedString(startDate)).append("\n");
sb.append(" workFlowExecutionId: ").append(toIndentedString(workFlowExecutionId)).append("\n");
+ sb.append(" workFlowName: ").append(toIndentedString(workFlowName)).append("\n");
sb.append(" workFlowOptions: ").append(toIndentedString(workFlowOptions)).append("\n");
sb.append(" workStatus: ").append(toIndentedString(workStatus)).append("\n");
sb.append("}");
@@ -233,7 +369,12 @@ private String toIndentedString(Object o) {
static {
// a set of all properties/fields (JSON key names)
openapiFields = new HashSet();
+ openapiFields.add("createUser");
+ openapiFields.add("endDate");
+ openapiFields.add("projectId");
+ openapiFields.add("startDate");
openapiFields.add("workFlowExecutionId");
+ openapiFields.add("workFlowName");
openapiFields.add("workFlowOptions");
openapiFields.add("workStatus");
@@ -267,12 +408,42 @@ public static void validateJsonObject(JsonObject jsonObj) throws IOException {
entry.getKey(), jsonObj.toString()));
}
}
+ if ((jsonObj.get("createUser") != null && !jsonObj.get("createUser").isJsonNull())
+ && !jsonObj.get("createUser").isJsonPrimitive()) {
+ throw new IllegalArgumentException(String.format(
+ "Expected the field `createUser` to be a primitive type in the JSON string but got `%s`",
+ jsonObj.get("createUser").toString()));
+ }
+ if ((jsonObj.get("endDate") != null && !jsonObj.get("endDate").isJsonNull())
+ && !jsonObj.get("endDate").isJsonPrimitive()) {
+ throw new IllegalArgumentException(
+ String.format("Expected the field `endDate` to be a primitive type in the JSON string but got `%s`",
+ jsonObj.get("endDate").toString()));
+ }
+ if ((jsonObj.get("projectId") != null && !jsonObj.get("projectId").isJsonNull())
+ && !jsonObj.get("projectId").isJsonPrimitive()) {
+ throw new IllegalArgumentException(String.format(
+ "Expected the field `projectId` to be a primitive type in the JSON string but got `%s`",
+ jsonObj.get("projectId").toString()));
+ }
+ if ((jsonObj.get("startDate") != null && !jsonObj.get("startDate").isJsonNull())
+ && !jsonObj.get("startDate").isJsonPrimitive()) {
+ throw new IllegalArgumentException(String.format(
+ "Expected the field `startDate` to be a primitive type in the JSON string but got `%s`",
+ jsonObj.get("startDate").toString()));
+ }
if ((jsonObj.get("workFlowExecutionId") != null && !jsonObj.get("workFlowExecutionId").isJsonNull())
&& !jsonObj.get("workFlowExecutionId").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format(
"Expected the field `workFlowExecutionId` to be a primitive type in the JSON string but got `%s`",
jsonObj.get("workFlowExecutionId").toString()));
}
+ if ((jsonObj.get("workFlowName") != null && !jsonObj.get("workFlowName").isJsonNull())
+ && !jsonObj.get("workFlowName").isJsonPrimitive()) {
+ throw new IllegalArgumentException(String.format(
+ "Expected the field `workFlowName` to be a primitive type in the JSON string but got `%s`",
+ jsonObj.get("workFlowName").toString()));
+ }
// validate the optional field `workFlowOptions`
if (jsonObj.get("workFlowOptions") != null && !jsonObj.get("workFlowOptions").isJsonNull()) {
WorkFlowOptions.validateJsonObject(jsonObj.getAsJsonObject("workFlowOptions"));
diff --git a/workflow-service-sdk/src/test/java/com/redhat/parodos/sdk/api/WorkflowApiTest.java b/workflow-service-sdk/src/test/java/com/redhat/parodos/sdk/api/WorkflowApiTest.java
new file mode 100644
index 000000000..26e04df66
--- /dev/null
+++ b/workflow-service-sdk/src/test/java/com/redhat/parodos/sdk/api/WorkflowApiTest.java
@@ -0,0 +1,83 @@
+/*
+ * Parodos Workflow Service API
+ * This is the API documentation for the Parodos Workflow Service. It provides operations to execute assessments to determine infrastructure options (tooling + environments). Also executes infrastructure task workflows to call downstream systems to stand-up an infrastructure option.
+ *
+ * The version of the OpenAPI document: v1.0.0
+ *
+ *
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
+ * https://openapi-generator.tech
+ * Do not edit the class manually.
+ */
+
+package com.redhat.parodos.sdk.api;
+
+import com.redhat.parodos.sdk.invoker.ApiException;
+import com.redhat.parodos.sdk.model.WorkFlowCheckerTaskRequestDTO;
+import com.redhat.parodos.sdk.model.WorkFlowContextResponseDTO;
+import com.redhat.parodos.sdk.model.WorkFlowRequestDTO;
+import com.redhat.parodos.sdk.model.WorkFlowResponseDTO;
+import com.redhat.parodos.sdk.model.WorkFlowStatusResponseDTO;
+import org.junit.Test;
+import org.junit.Ignore;
+
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * API tests for WorkflowApi
+ */
+@Ignore
+public class WorkflowApiTest {
+
+ private final WorkflowApi api = new WorkflowApi();
+
+ /**
+ * Executes a workflow
+ * @throws ApiException if the Api call fails
+ */
+ @Test
+ public void executeTest() throws ApiException {
+ WorkFlowRequestDTO workFlowRequestDTO = null;
+ WorkFlowResponseDTO response = api.execute(workFlowRequestDTO);
+ // TODO: test validations
+ }
+
+ /**
+ * Returns a workflow status
+ * @throws ApiException if the Api call fails
+ */
+ @Test
+ public void getStatusTest() throws ApiException {
+ UUID workFlowExecutionId = null;
+ WorkFlowStatusResponseDTO response = api.getStatus(workFlowExecutionId);
+ // TODO: test validations
+ }
+
+ /**
+ * Returns workflow context parameters
+ * @throws ApiException if the Api call fails
+ */
+ @Test
+ public void getWorkflowParametersTest() throws ApiException {
+ UUID workFlowExecutionId = null;
+ List param = null;
+ WorkFlowContextResponseDTO response = api.getWorkflowParameters(workFlowExecutionId, param);
+ // TODO: test validations
+ }
+
+ /**
+ * Updates a workflow checker task status
+ * @throws ApiException if the Api call fails
+ */
+ @Test
+ public void updateWorkFlowCheckerTaskStatusTest() throws ApiException {
+ UUID workFlowExecutionId = null;
+ String workFlowCheckerTaskName = null;
+ WorkFlowCheckerTaskRequestDTO workFlowCheckerTaskRequestDTO = null;
+ String response = api.updateWorkFlowCheckerTaskStatus(workFlowExecutionId, workFlowCheckerTaskName,
+ workFlowCheckerTaskRequestDTO);
+ // TODO: test validations
+ }
+
+}
diff --git a/workflow-service-sdk/src/test/java/com/redhat/parodos/sdk/model/ProjectResponseDTOTest.java b/workflow-service-sdk/src/test/java/com/redhat/parodos/sdk/model/ProjectResponseDTOTest.java
new file mode 100644
index 000000000..c3be48bf5
--- /dev/null
+++ b/workflow-service-sdk/src/test/java/com/redhat/parodos/sdk/model/ProjectResponseDTOTest.java
@@ -0,0 +1,88 @@
+/*
+ * Parodos Workflow Service API
+ * This is the API documentation for the Parodos Workflow Service. It provides operations to execute assessments to determine infrastructure options (tooling + environments). Also executes infrastructure task workflows to call downstream systems to stand-up an infrastructure option.
+ *
+ * The version of the OpenAPI document: v1.0.0
+ *
+ *
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
+ * https://openapi-generator.tech
+ * Do not edit the class manually.
+ */
+
+package com.redhat.parodos.sdk.model;
+
+import org.junit.Test;
+
+/**
+ * Model tests for ProjectResponseDTO
+ */
+public class ProjectResponseDTOTest {
+
+ private final ProjectResponseDTO model = new ProjectResponseDTO();
+
+ /**
+ * Model tests for ProjectResponseDTO
+ */
+ @Test
+ public void testProjectResponseDTO() {
+ // TODO: test ProjectResponseDTO
+ }
+
+ /**
+ * Test the property 'createDate'
+ */
+ @Test
+ public void createDateTest() {
+ // TODO: test createDate
+ }
+
+ /**
+ * Test the property 'description'
+ */
+ @Test
+ public void descriptionTest() {
+ // TODO: test description
+ }
+
+ /**
+ * Test the property 'id'
+ */
+ @Test
+ public void idTest() {
+ // TODO: test id
+ }
+
+ /**
+ * Test the property 'modifyDate'
+ */
+ @Test
+ public void modifyDateTest() {
+ // TODO: test modifyDate
+ }
+
+ /**
+ * Test the property 'name'
+ */
+ @Test
+ public void nameTest() {
+ // TODO: test name
+ }
+
+ /**
+ * Test the property 'status'
+ */
+ @Test
+ public void statusTest() {
+ // TODO: test status
+ }
+
+ /**
+ * Test the property 'username'
+ */
+ @Test
+ public void usernameTest() {
+ // TODO: test username
+ }
+
+}
diff --git a/workflow-service-sdk/src/test/java/com/redhat/parodos/sdk/model/WorkFlowContextResponseDTOTest.java b/workflow-service-sdk/src/test/java/com/redhat/parodos/sdk/model/WorkFlowContextResponseDTOTest.java
new file mode 100644
index 000000000..afee4a5ec
--- /dev/null
+++ b/workflow-service-sdk/src/test/java/com/redhat/parodos/sdk/model/WorkFlowContextResponseDTOTest.java
@@ -0,0 +1,48 @@
+/*
+ * Parodos Workflow Service API
+ * This is the API documentation for the Parodos Workflow Service. It provides operations to execute assessments to determine infrastructure options (tooling + environments). Also executes infrastructure task workflows to call downstream systems to stand-up an infrastructure option.
+ *
+ * The version of the OpenAPI document: v1.0.0
+ *
+ *
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
+ * https://openapi-generator.tech
+ * Do not edit the class manually.
+ */
+
+package com.redhat.parodos.sdk.model;
+
+import org.junit.Test;
+
+/**
+ * Model tests for WorkFlowContextResponseDTO
+ */
+public class WorkFlowContextResponseDTOTest {
+
+ private final WorkFlowContextResponseDTO model = new WorkFlowContextResponseDTO();
+
+ /**
+ * Model tests for WorkFlowContextResponseDTO
+ */
+ @Test
+ public void testWorkFlowContextResponseDTO() {
+ // TODO: test WorkFlowContextResponseDTO
+ }
+
+ /**
+ * Test the property 'workFlowExecutionId'
+ */
+ @Test
+ public void workFlowExecutionIdTest() {
+ // TODO: test workFlowExecutionId
+ }
+
+ /**
+ * Test the property 'workFlowOptions'
+ */
+ @Test
+ public void workFlowOptionsTest() {
+ // TODO: test workFlowOptions
+ }
+
+}
diff --git a/workflow-service/generated/openapi/openapi.json b/workflow-service/generated/openapi/openapi.json
index 07e80d68d..7bc5489a8 100644
--- a/workflow-service/generated/openapi/openapi.json
+++ b/workflow-service/generated/openapi/openapi.json
@@ -260,6 +260,40 @@
}
},
"/api/v1/workflows" : {
+ "get" : {
+ "operationId" : "getStatusByProjectId",
+ "parameters" : [ {
+ "in" : "query",
+ "name" : "projectId",
+ "required" : false,
+ "schema" : {
+ "type" : "string",
+ "format" : "uuid"
+ }
+ } ],
+ "responses" : {
+ "200" : {
+ "content" : {
+ "application/json" : {
+ "schema" : {
+ "allOf" : [ {
+ "$ref" : "#/components/schemas/WorkFlowStatusResponseDTO"
+ } ]
+ }
+ }
+ },
+ "description" : "Succeeded"
+ },
+ "401" : {
+ "description" : "Unauthorized"
+ },
+ "403" : {
+ "description" : "Forbidden"
+ }
+ },
+ "summary" : "Returns workflows by project id",
+ "tags" : [ "Workflow" ]
+ },
"post" : {
"operationId" : "execute",
"requestBody" : {
@@ -731,10 +765,26 @@
"WorkFlowResponseDTO" : {
"type" : "object",
"properties" : {
+ "createUser" : {
+ "type" : "string"
+ },
+ "endDate" : {
+ "type" : "string"
+ },
+ "projectId" : {
+ "type" : "string",
+ "format" : "uuid"
+ },
+ "startDate" : {
+ "type" : "string"
+ },
"workFlowExecutionId" : {
"type" : "string",
"format" : "uuid"
},
+ "workFlowName" : {
+ "type" : "string"
+ },
"workFlowOptions" : {
"$ref" : "#/components/schemas/WorkFlowOptions"
},
diff --git a/workflow-service/src/main/java/com/redhat/parodos/project/repository/ProjectRepository.java b/workflow-service/src/main/java/com/redhat/parodos/project/repository/ProjectRepository.java
index 82bd2a02e..4833537ee 100644
--- a/workflow-service/src/main/java/com/redhat/parodos/project/repository/ProjectRepository.java
+++ b/workflow-service/src/main/java/com/redhat/parodos/project/repository/ProjectRepository.java
@@ -17,6 +17,7 @@
import com.redhat.parodos.project.entity.Project;
+import java.util.List;
import java.util.Optional;
import java.util.UUID;
import org.springframework.data.jpa.repository.JpaRepository;
@@ -30,4 +31,8 @@ public interface ProjectRepository extends JpaRepository {
Optional findByNameIgnoreCase(String name);
+ List findAllByUserUsername(String username);
+
+ Optional findByIdAndUserUsername(UUID id, String username);
+
}
diff --git a/workflow-service/src/main/java/com/redhat/parodos/project/service/ProjectService.java b/workflow-service/src/main/java/com/redhat/parodos/project/service/ProjectService.java
index b5817d626..4a6a9de4a 100644
--- a/workflow-service/src/main/java/com/redhat/parodos/project/service/ProjectService.java
+++ b/workflow-service/src/main/java/com/redhat/parodos/project/service/ProjectService.java
@@ -17,6 +17,7 @@
import com.redhat.parodos.project.dto.ProjectRequestDTO;
import com.redhat.parodos.project.dto.ProjectResponseDTO;
+
import java.util.List;
import java.util.UUID;
@@ -33,4 +34,8 @@ public interface ProjectService {
List getProjects();
+ List findProjectsByUserName(String userName);
+
+ ProjectResponseDTO getProjectByIdAndUsername(UUID id, String username);
+
}
diff --git a/workflow-service/src/main/java/com/redhat/parodos/project/service/ProjectServiceImpl.java b/workflow-service/src/main/java/com/redhat/parodos/project/service/ProjectServiceImpl.java
index 12e044f9c..447cc43e2 100644
--- a/workflow-service/src/main/java/com/redhat/parodos/project/service/ProjectServiceImpl.java
+++ b/workflow-service/src/main/java/com/redhat/parodos/project/service/ProjectServiceImpl.java
@@ -15,22 +15,24 @@
*/
package com.redhat.parodos.project.service;
-import javax.persistence.EntityExistsException;
-import java.util.Date;
-import java.util.List;
-import java.util.Optional;
-import java.util.UUID;
-import java.util.stream.Collectors;
-
+import com.redhat.parodos.project.dto.ProjectRequestDTO;
+import com.redhat.parodos.project.dto.ProjectResponseDTO;
+import com.redhat.parodos.project.entity.Project;
+import com.redhat.parodos.project.repository.ProjectRepository;
+import com.redhat.parodos.security.SecurityUtils;
+import com.redhat.parodos.user.service.UserService;
import com.redhat.parodos.workflow.execution.entity.WorkFlowExecution;
import com.redhat.parodos.workflow.execution.repository.WorkFlowRepository;
import org.modelmapper.ModelMapper;
+import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
+import org.springframework.web.server.ResponseStatusException;
-import com.redhat.parodos.project.dto.ProjectRequestDTO;
-import com.redhat.parodos.project.dto.ProjectResponseDTO;
-import com.redhat.parodos.project.entity.Project;
-import com.redhat.parodos.project.repository.ProjectRepository;
+import javax.persistence.EntityExistsException;
+import java.util.Date;
+import java.util.List;
+import java.util.Optional;
+import java.util.UUID;
/**
* Project service implementation
@@ -45,12 +47,15 @@ public class ProjectServiceImpl implements ProjectService {
private final WorkFlowRepository workFlowRepository;
+ private final UserService userService;
+
private final ModelMapper modelMapper;
public ProjectServiceImpl(ProjectRepository projectRepository, WorkFlowRepository workFlowRepository,
- ModelMapper modelMapper) {
+ UserService userService, ModelMapper modelMapper) {
this.projectRepository = projectRepository;
this.workFlowRepository = workFlowRepository;
+ this.userService = userService;
this.modelMapper = modelMapper;
}
@@ -63,16 +68,16 @@ public ProjectResponseDTO save(ProjectRequestDTO projectRequestDTO) {
}
// get user from security utils and set on project
Project project = projectRepository.save(Project.builder().name(projectRequestDTO.getName())
- .description(projectRequestDTO.getDescription()).createDate(new Date()).modifyDate(new Date()).build());
+ .description(projectRequestDTO.getDescription()).createDate(new Date()).modifyDate(new Date())
+ .user(userService.getUserEntityByUsername(SecurityUtils.getUsername())).build());
return modelMapper.map(project, ProjectResponseDTO.class);
}
@Override
public ProjectResponseDTO getProjectById(UUID id) {
- return modelMapper.map(
- projectRepository.findById(id)
- .orElseThrow(() -> new RuntimeException(String.format("Project with id: %s not found", id))),
- ProjectResponseDTO.class);
+ return modelMapper
+ .map(projectRepository.findById(id).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND,
+ String.format("Project with id: %s not found", id))), ProjectResponseDTO.class);
}
@Override
@@ -85,7 +90,22 @@ public List getProjects() {
.createDate(project.getCreateDate()).modifyDate(project.getModifyDate())
.description(project.getDescription())
.status(null == workFlowExecution ? "" : workFlowExecution.getStatus().name()).build();
- }).collect(Collectors.toList());
+ }).toList();
+ }
+
+ @Override
+ public ProjectResponseDTO getProjectByIdAndUsername(UUID id, String username) {
+ return modelMapper.map(
+ projectRepository.findByIdAndUserUsername(id, username)
+ .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, String.format(
+ "Project with id: %s not found for user: %s", id, SecurityUtils.getUsername()))),
+ ProjectResponseDTO.class);
+ }
+
+ @Override
+ public List findProjectsByUserName(String username) {
+ return projectRepository.findAllByUserUsername(username).stream()
+ .map(project -> modelMapper.map(project, ProjectResponseDTO.class)).toList();
}
}
diff --git a/workflow-service/src/main/java/com/redhat/parodos/security/SecurityUtils.java b/workflow-service/src/main/java/com/redhat/parodos/security/SecurityUtils.java
index 540416902..f39a67eda 100644
--- a/workflow-service/src/main/java/com/redhat/parodos/security/SecurityUtils.java
+++ b/workflow-service/src/main/java/com/redhat/parodos/security/SecurityUtils.java
@@ -17,6 +17,8 @@
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.ldap.userdetails.LdapUserDetailsImpl;
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken;
import org.springframework.stereotype.Component;
import lombok.extern.slf4j.Slf4j;
@@ -29,7 +31,6 @@
*
*/
-@Component
@Slf4j
public class SecurityUtils {
@@ -40,13 +41,13 @@ private SecurityUtils() {
* Extract preferred username from security context.
* @return username.
*/
- public String getUsername() {
- Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
- if (authentication instanceof JwtAuthenticationToken) {
- return ((JwtAuthenticationToken) authentication).getToken().getClaim("preferred_username");
+ public static String getUsername() {
+ UserDetails ldapDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
+ if (ldapDetails != null) {
+ return ldapDetails.getUsername();
}
- log.error(
- "Unable to find the username for the authenticated user - if this is being ran under the 'local' profile this behavior is expected");
+ else
+ log.error("Unable to get the LdapDetails to get the username");
return null;
}
diff --git a/workflow-service/src/main/java/com/redhat/parodos/user/entity/User.java b/workflow-service/src/main/java/com/redhat/parodos/user/entity/User.java
index a50563574..12e0e2e11 100644
--- a/workflow-service/src/main/java/com/redhat/parodos/user/entity/User.java
+++ b/workflow-service/src/main/java/com/redhat/parodos/user/entity/User.java
@@ -39,7 +39,7 @@
* @author Annel Ketcha (Github: anludke)
*/
-@Entity(name = "user")
+@Entity(name = "users")
@Builder
@Getter
@Setter
diff --git a/workflow-service/src/main/java/com/redhat/parodos/user/service/UserService.java b/workflow-service/src/main/java/com/redhat/parodos/user/service/UserService.java
index 57d6a782b..a96fe0cc6 100644
--- a/workflow-service/src/main/java/com/redhat/parodos/user/service/UserService.java
+++ b/workflow-service/src/main/java/com/redhat/parodos/user/service/UserService.java
@@ -33,4 +33,6 @@ public interface UserService {
UserResponseDTO getUserByUsername(String username);
+ User getUserEntityByUsername(String username);
+
}
diff --git a/workflow-service/src/main/java/com/redhat/parodos/user/service/UserServiceImpl.java b/workflow-service/src/main/java/com/redhat/parodos/user/service/UserServiceImpl.java
index acb1528ec..d2e71262b 100644
--- a/workflow-service/src/main/java/com/redhat/parodos/user/service/UserServiceImpl.java
+++ b/workflow-service/src/main/java/com/redhat/parodos/user/service/UserServiceImpl.java
@@ -15,14 +15,16 @@
*/
package com.redhat.parodos.user.service;
-import java.util.Optional;
-import java.util.UUID;
-
import com.redhat.parodos.user.dto.UserResponseDTO;
import com.redhat.parodos.user.entity.User;
import com.redhat.parodos.user.repository.UserRepository;
import org.modelmapper.ModelMapper;
+import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
+import org.springframework.web.server.ResponseStatusException;
+
+import java.util.Optional;
+import java.util.UUID;
/**
* User service implementation
@@ -63,4 +65,10 @@ public UserResponseDTO getUserByUsername(String username) {
return modelMapper.map(user.get(), UserResponseDTO.class);
}
+ @Override
+ public User getUserEntityByUsername(String username) {
+ return userRepository.findByUsername(username).stream().findFirst().orElseThrow(
+ () -> new ResponseStatusException(HttpStatus.NOT_FOUND, "user " + username + " is not found"));
+ }
+
}
diff --git a/workflow-service/src/main/java/com/redhat/parodos/workflow/execution/controller/WorkFlowController.java b/workflow-service/src/main/java/com/redhat/parodos/workflow/execution/controller/WorkFlowController.java
index a47f50deb..8943a19f4 100644
--- a/workflow-service/src/main/java/com/redhat/parodos/workflow/execution/controller/WorkFlowController.java
+++ b/workflow-service/src/main/java/com/redhat/parodos/workflow/execution/controller/WorkFlowController.java
@@ -15,15 +15,6 @@
*/
package com.redhat.parodos.workflow.execution.controller;
-import javax.validation.ConstraintViolation;
-import javax.validation.ConstraintViolationException;
-import javax.validation.Valid;
-import javax.validation.constraints.NotEmpty;
-import java.util.List;
-import java.util.Set;
-import java.util.UUID;
-import java.util.stream.Collectors;
-
import com.redhat.parodos.workflow.context.WorkContextDelegate;
import com.redhat.parodos.workflow.execution.dto.WorkFlowCheckerTaskRequestDTO;
import com.redhat.parodos.workflow.execution.dto.WorkFlowContextResponseDTO;
@@ -52,6 +43,15 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
+import javax.validation.ConstraintViolation;
+import javax.validation.ConstraintViolationException;
+import javax.validation.Valid;
+import javax.validation.constraints.NotEmpty;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+import java.util.stream.Collectors;
+
/**
* Workflow controller to execute workflow and get status
*
@@ -124,6 +124,20 @@ public ResponseEntity getStatus(@PathVariable UUID wo
return ResponseEntity.ok(workFlowService.getWorkFlowStatus(workFlowExecutionId));
}
+ @Operation(summary = "Returns workflows by project id")
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Succeeded",
+ content = { @Content(mediaType = "application/json",
+ schema = @Schema(allOf = WorkFlowStatusResponseDTO.class)) }),
+ @ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content),
+ @ApiResponse(responseCode = "403", description = "Forbidden", content = @Content) })
+ @GetMapping()
+ public ResponseEntity> getStatusByProjectId(
+ @RequestParam(value = "projectId", required = false) UUID projectId) {
+ return ResponseEntity.ok(projectId != null ? workFlowService.getWorkFlowsByProjectId(projectId)
+ : workFlowService.getWorkFlows());
+ }
+
@Operation(summary = "Returns workflow context parameters")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Succeeded",
diff --git a/workflow-service/src/main/java/com/redhat/parodos/workflow/execution/dto/WorkFlowResponseDTO.java b/workflow-service/src/main/java/com/redhat/parodos/workflow/execution/dto/WorkFlowResponseDTO.java
index e683fdbc4..086be2c1d 100644
--- a/workflow-service/src/main/java/com/redhat/parodos/workflow/execution/dto/WorkFlowResponseDTO.java
+++ b/workflow-service/src/main/java/com/redhat/parodos/workflow/execution/dto/WorkFlowResponseDTO.java
@@ -36,14 +36,23 @@
@Data
@AllArgsConstructor
@NoArgsConstructor
+@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class WorkFlowResponseDTO {
private UUID workFlowExecutionId;
- @JsonInclude(JsonInclude.Include.NON_EMPTY)
+ private UUID projectId;
+
+ private String workFlowName;
+
private WorkFlowOptions workFlowOptions;
- @JsonInclude(JsonInclude.Include.NON_EMPTY)
private WorkStatus workStatus;
+ private String startDate;
+
+ private String endDate;
+
+ private String createUser;
+
}
diff --git a/workflow-service/src/main/java/com/redhat/parodos/workflow/execution/repository/WorkFlowRepository.java b/workflow-service/src/main/java/com/redhat/parodos/workflow/execution/repository/WorkFlowRepository.java
index 8dbaf638b..6e1305500 100644
--- a/workflow-service/src/main/java/com/redhat/parodos/workflow/execution/repository/WorkFlowRepository.java
+++ b/workflow-service/src/main/java/com/redhat/parodos/workflow/execution/repository/WorkFlowRepository.java
@@ -38,6 +38,8 @@ WorkFlowExecution findFirstByWorkFlowDefinitionIdAndMainWorkFlowExecution(UUID w
List findByMainWorkFlowExecution(WorkFlowExecution mainWorkFlowExecution);
+ List findAllByProjectId(UUID projectId);
+
WorkFlowExecution findFirstByMainWorkFlowExecutionAndWorkFlowDefinitionId(WorkFlowExecution mainWorkFlowExecution,
UUID workFlowDefinitionId);
diff --git a/workflow-service/src/main/java/com/redhat/parodos/workflow/execution/service/WorkFlowService.java b/workflow-service/src/main/java/com/redhat/parodos/workflow/execution/service/WorkFlowService.java
index 6f52e8586..c642aeebb 100644
--- a/workflow-service/src/main/java/com/redhat/parodos/workflow/execution/service/WorkFlowService.java
+++ b/workflow-service/src/main/java/com/redhat/parodos/workflow/execution/service/WorkFlowService.java
@@ -19,6 +19,7 @@
import com.redhat.parodos.workflow.enums.WorkFlowStatus;
import com.redhat.parodos.workflow.execution.dto.WorkFlowContextResponseDTO;
import com.redhat.parodos.workflow.execution.dto.WorkFlowRequestDTO;
+import com.redhat.parodos.workflow.execution.dto.WorkFlowResponseDTO;
import com.redhat.parodos.workflow.execution.dto.WorkFlowStatusResponseDTO;
import com.redhat.parodos.workflow.execution.entity.WorkFlowExecution;
import com.redhat.parodos.workflow.execution.entity.WorkFlowTaskExecution;
@@ -45,6 +46,10 @@ WorkFlowExecution saveWorkFlow(UUID projectId, UUID workFlowDefinitionId, WorkFl
WorkFlowExecution updateWorkFlow(WorkFlowExecution workFlowExecution);
+ List getWorkFlowsByProjectId(UUID projectId);
+
+ List getWorkFlows();
+
WorkFlowStatusResponseDTO getWorkFlowStatus(UUID workFlowExecutionId);
WorkFlowContextResponseDTO getWorkflowParameters(UUID workFlowExecutionId,
diff --git a/workflow-service/src/main/java/com/redhat/parodos/workflow/execution/service/WorkFlowServiceImpl.java b/workflow-service/src/main/java/com/redhat/parodos/workflow/execution/service/WorkFlowServiceImpl.java
index 0c239f0e7..ec8735236 100644
--- a/workflow-service/src/main/java/com/redhat/parodos/workflow/execution/service/WorkFlowServiceImpl.java
+++ b/workflow-service/src/main/java/com/redhat/parodos/workflow/execution/service/WorkFlowServiceImpl.java
@@ -15,6 +15,9 @@
*/
package com.redhat.parodos.workflow.execution.service;
+import com.redhat.parodos.project.dto.ProjectResponseDTO;
+import com.redhat.parodos.project.service.ProjectService;
+import com.redhat.parodos.security.SecurityUtils;
import com.redhat.parodos.workflow.WorkFlowDelegate;
import com.redhat.parodos.workflow.execution.dto.WorkFlowContextResponseDTO;
import com.redhat.parodos.workflow.execution.dto.WorkFlowOptionsResponseDTO;
@@ -33,6 +36,7 @@
import com.redhat.parodos.workflow.enums.WorkFlowType;
import com.redhat.parodos.workflow.exceptions.WorkflowPersistenceFailedException;
import com.redhat.parodos.workflow.execution.dto.WorkFlowRequestDTO;
+import com.redhat.parodos.workflow.execution.dto.WorkFlowResponseDTO;
import com.redhat.parodos.workflow.execution.dto.WorkFlowStatusResponseDTO;
import com.redhat.parodos.workflow.execution.dto.WorkStatusResponseDTO;
import com.redhat.parodos.workflow.execution.entity.WorkFlowExecution;
@@ -48,6 +52,7 @@
import com.redhat.parodos.workflows.workflow.WorkFlow;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.Nullable;
+import org.modelmapper.ModelMapper;
import org.springframework.dao.DataAccessException;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
@@ -74,6 +79,8 @@
@Service
public class WorkFlowServiceImpl implements WorkFlowService {
+ private final ProjectService projectService;
+
private final WorkFlowDelegate workFlowDelegate;
private final WorkFlowServiceDelegate workFlowServiceDelegate;
@@ -96,7 +103,8 @@ public WorkFlowServiceImpl(WorkFlowDelegate workFlowDelegate, WorkFlowServiceDel
WorkFlowDefinitionRepository workFlowDefinitionRepository,
WorkFlowTaskDefinitionRepository workFlowTaskDefinitionRepository, WorkFlowRepository workFlowRepository,
WorkFlowTaskRepository workFlowTaskRepository, WorkFlowWorkRepository workFlowWorkRepository,
- WorkFlowDefinitionService workFlowDefinitionService, MeterRegistry metricRegistry) {
+ WorkFlowDefinitionService workFlowDefinitionService, MeterRegistry metricRegistry,
+ ProjectService projectService, ModelMapper modelMapper) {
this.workFlowDelegate = workFlowDelegate;
this.workFlowServiceDelegate = workFlowServiceDelegate;
this.workFlowDefinitionRepository = workFlowDefinitionRepository;
@@ -106,6 +114,7 @@ public WorkFlowServiceImpl(WorkFlowDelegate workFlowDelegate, WorkFlowServiceDel
this.workFlowWorkRepository = workFlowWorkRepository;
this.workFlowDefinitionService = workFlowDefinitionService;
this.metricRegistry = metricRegistry;
+ this.projectService = projectService;
}
private void statusCounterWithStatus(WorkFlowStatus status) {
@@ -172,6 +181,24 @@ public synchronized WorkFlowExecution updateWorkFlow(WorkFlowExecution workFlowE
return workFlowRepository.save(workFlowExecution);
}
+ @Override
+ public List getWorkFlowsByProjectId(UUID projectId) {
+ ProjectResponseDTO project = projectService.getProjectByIdAndUsername(projectId, SecurityUtils.getUsername());
+ return workFlowRepository.findAllByProjectId(project.getId()).stream()
+ .filter(workFlowExecution -> workFlowExecution.getMainWorkFlowExecution() == null)
+ .map(this::buildWorkflowResponseDTO).toList();
+ }
+
+ @Override
+ public List getWorkFlows() {
+ List projects = projectService.findProjectsByUserName(SecurityUtils.getUsername());
+ return projects.stream()
+ .flatMap(project -> workFlowRepository.findAllByProjectId(project.getId()).stream()
+ .filter(workFlowExecution -> workFlowExecution.getMainWorkFlowExecution() == null)
+ .map(this::buildWorkflowResponseDTO))
+ .toList();
+ }
+
@Override
public WorkFlowStatusResponseDTO getWorkFlowStatus(UUID workFlowExecutionId) {
WorkFlowExecution workFlowExecution = workFlowRepository.findById(workFlowExecutionId).orElseThrow(() -> {
@@ -336,4 +363,15 @@ public void gracefulShutdown() {
log.info(">> Shutting down the workflow service");
}
+ private WorkFlowResponseDTO buildWorkflowResponseDTO(WorkFlowExecution workflowExecution) {
+ return WorkFlowResponseDTO.builder().workFlowExecutionId(workflowExecution.getId())
+ .projectId(workflowExecution.getProjectId())
+ .workFlowName(workFlowDefinitionService
+ .getWorkFlowDefinitionById(workflowExecution.getWorkFlowDefinitionId()).getName())
+ .workStatus(WorkStatus.valueOf(workflowExecution.getStatus().name()))
+ .startDate(Optional.ofNullable(workflowExecution.getStartDate()).map(Date::toString).orElse(null))
+ .endDate(Optional.ofNullable(workflowExecution.getEndDate()).map(Date::toString).orElse(null))
+ .createUser(SecurityUtils.getUsername()).build();
+ }
+
}
diff --git a/workflow-service/src/main/resources/db/changelog/data.xml b/workflow-service/src/main/resources/db/changelog/data.xml
index 5d22e156e..451e2eb24 100644
--- a/workflow-service/src/main/resources/db/changelog/data.xml
+++ b/workflow-service/src/main/resources/db/changelog/data.xml
@@ -6,7 +6,7 @@
-
+
diff --git a/workflow-service/src/main/resources/db/changelog/tables.xml b/workflow-service/src/main/resources/db/changelog/tables.xml
index 5f6c63fe3..6cd9b7d9b 100644
--- a/workflow-service/src/main/resources/db/changelog/tables.xml
+++ b/workflow-service/src/main/resources/db/changelog/tables.xml
@@ -6,7 +6,7 @@
-
+
@@ -36,7 +36,7 @@
-
+
diff --git a/workflow-service/src/test/java/com/redhat/parodos/project/repository/ProjectRepositoryTest.java b/workflow-service/src/test/java/com/redhat/parodos/project/repository/ProjectRepositoryTest.java
index 2dbb4b35e..9c7b0a2ac 100644
--- a/workflow-service/src/test/java/com/redhat/parodos/project/repository/ProjectRepositoryTest.java
+++ b/workflow-service/src/test/java/com/redhat/parodos/project/repository/ProjectRepositoryTest.java
@@ -1,19 +1,22 @@
package com.redhat.parodos.project.repository;
+import com.redhat.parodos.project.entity.Project;
+import com.redhat.parodos.repository.RepositoryTestBase;
+import com.redhat.parodos.user.entity.User;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
+
import javax.persistence.PersistenceException;
import java.util.List;
import java.util.UUID;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import com.redhat.parodos.project.entity.Project;
-import com.redhat.parodos.repository.RepositoryTestBase;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-
public class ProjectRepositoryTest extends RepositoryTestBase {
@Autowired
@@ -87,9 +90,35 @@ public void testUniqueNameConstraint() {
assertThrows(PersistenceException.class, () -> createProject(name));
}
+ @Test
+ void testFindAllByUsername() {
+ // given
+ Project project = createProject("test-project", "test-user");
+
+ // then
+ assertThat(projectRepository.findAllByUserUsername("test-user")).hasSize(1).contains(project);
+ }
+
+ @Test
+ void testFindByIdAndUsername() {
+ // given
+ Project project = createProject("test-project", "test-user");
+
+ // then
+ assertThat(projectRepository.findByIdAndUserUsername(project.getId(), "test-user")).hasValue(project);
+ }
+
+ private Project createProject(String name, String username) {
+ User user = User.builder().username(username).build();
+ entityManager.persistAndFlush(user);
+
+ Project project = Project.builder().name(name).description(name + " test").user(user).build();
+ return entityManager.persistAndFlush(project);
+ }
+
private void createProject(String name) {
Project project = Project.builder().name(name).description(name + " test").build();
entityManager.persistAndFlush(project);
}
-}
\ No newline at end of file
+}
diff --git a/workflow-service/src/test/java/com/redhat/parodos/project/service/ProjectServiceImplTest.java b/workflow-service/src/test/java/com/redhat/parodos/project/service/ProjectServiceImplTest.java
index 64715b674..6c889c14e 100644
--- a/workflow-service/src/test/java/com/redhat/parodos/project/service/ProjectServiceImplTest.java
+++ b/workflow-service/src/test/java/com/redhat/parodos/project/service/ProjectServiceImplTest.java
@@ -4,14 +4,20 @@
import com.redhat.parodos.project.dto.ProjectResponseDTO;
import com.redhat.parodos.project.entity.Project;
import com.redhat.parodos.project.repository.ProjectRepository;
+import com.redhat.parodos.user.entity.User;
+import com.redhat.parodos.user.service.UserService;
import com.redhat.parodos.workflow.enums.WorkFlowStatus;
import com.redhat.parodos.workflow.execution.entity.WorkFlowExecution;
import com.redhat.parodos.workflow.execution.repository.WorkFlowRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.modelmapper.ModelMapper;
+import org.springframework.security.test.context.support.WithMockUser;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.web.server.ResponseStatusException;
import java.util.ArrayList;
import java.util.Arrays;
@@ -26,7 +32,9 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.nullable;
+@ExtendWith(SpringExtension.class)
class ProjectServiceImplTest {
private ProjectRepository projectRepository;
@@ -35,11 +43,14 @@ class ProjectServiceImplTest {
private ProjectServiceImpl projectService;
+ private UserService userService;
+
@BeforeEach
public void initEach() {
this.projectRepository = Mockito.mock(ProjectRepository.class);
this.workFlowRepository = Mockito.mock(WorkFlowRepository.class);
- this.projectService = new ProjectServiceImpl(this.projectRepository, this.workFlowRepository,
+ this.userService = Mockito.mock(UserService.class);
+ this.projectService = new ProjectServiceImpl(this.projectRepository, this.workFlowRepository, userService,
new ModelMapper());
}
@@ -65,18 +76,30 @@ public void testFindProjectByIdWithValidData() {
}
@Test
- public void testFindProjectByIdWithInvalidData() {
+ public void testFindProjectByIdAndUserNameWithValidData() {
+ String username = "test-user";
// given
Project project = getSampleProject("test");
- Mockito.when(this.projectRepository.findById(project.getId())).thenReturn(Optional.empty());
+ Mockito.when(this.projectRepository.findByIdAndUserUsername(project.getId(), username))
+ .thenReturn(Optional.of(project));
// when
- Exception exception = assertThrows(RuntimeException.class, () -> {
- this.projectService.getProjectById(project.getId());
- });
+ ProjectResponseDTO res = this.projectService.getProjectByIdAndUsername(project.getId(), username);
// then
- assertEquals(exception.getMessage(), String.format("Project with id: %s not found", project.getId()));
+ assertNotNull(res);
+ assertEquals(res.getId().toString(), project.getId().toString());
+ }
+
+ @Test
+ public void testFindProjectByIdWithInvalidData() {
+ // given
+ Project project = getSampleProject("test");
+ Mockito.when(this.projectRepository.findById(project.getId())).thenReturn(Optional.empty());
+
+ // when
+ assertThrows(ResponseStatusException.class, () -> this.projectService.getProjectById(project.getId()),
+ String.format("404 NOT_FOUND \"Project with id: %s not found\"", project.getId()));
}
@Test
@@ -135,11 +158,13 @@ public void testGetProjectsWithInvalidData() {
}
@Test
+ @WithMockUser(username = "test-user")
public void testSaveWithValidData() {
// given
Project project = getSampleProject("test");
Mockito.when(this.projectRepository.save(any(Project.class))).thenReturn(project);
-
+ Mockito.when(userService.getUserEntityByUsername(nullable(String.class)))
+ .thenReturn(User.builder().username("test-user").build());
ProjectRequestDTO projectDTO = ProjectRequestDTO.builder().name("dto").description("dto description").build();
// when
diff --git a/workflow-service/src/test/java/com/redhat/parodos/repository/RepositoryTestBase.java b/workflow-service/src/test/java/com/redhat/parodos/repository/RepositoryTestBase.java
index 0ba107384..b34e7cbe2 100644
--- a/workflow-service/src/test/java/com/redhat/parodos/repository/RepositoryTestBase.java
+++ b/workflow-service/src/test/java/com/redhat/parodos/repository/RepositoryTestBase.java
@@ -1,17 +1,17 @@
package com.redhat.parodos.repository;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-
import com.redhat.parodos.workflow.execution.repository.WorkFlowRepository;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.transaction.annotation.Transactional;
-@RunWith(SpringRunner.class)
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+@ExtendWith(SpringExtension.class)
@DataJpaTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@Transactional
diff --git a/workflow-service/src/test/java/com/redhat/parodos/workflow/definition/service/WorkFlowDefinitionServiceDataTest.java b/workflow-service/src/test/java/com/redhat/parodos/workflow/definition/service/WorkFlowDefinitionServiceDataTest.java
index 679f311ed..75358e3f7 100644
--- a/workflow-service/src/test/java/com/redhat/parodos/workflow/definition/service/WorkFlowDefinitionServiceDataTest.java
+++ b/workflow-service/src/test/java/com/redhat/parodos/workflow/definition/service/WorkFlowDefinitionServiceDataTest.java
@@ -69,6 +69,11 @@ class WorkFlowDefinitionServiceDataTest {
@BeforeEach
void init() {
+ workFlowCheckerMappingDefinitionRepository.deleteAllInBatch();
+ workFlowWorkRepository.deleteAllInBatch();
+ workFlowTaskDefinitionRepository.deleteAllInBatch();
+ workFlowDefinitionRepository.deleteAllInBatch();
+
workFlowDefinitionService = new WorkFlowDefinitionServiceImpl(workFlowDefinitionRepository,
workFlowTaskDefinitionRepository, workFlowCheckerMappingDefinitionRepository, workFlowWorkRepository,
new ModelMapper());
@@ -83,10 +88,10 @@ void init() {
.build();
WorkFlowWorkDefinition workFlowWorkDefinition = WorkFlowWorkDefinition.builder()
.workDefinitionId(UUID.randomUUID()).workFlowDefinition(workFlowDefinition).build();
- entityManager.persist(workFlowDefinition);
- entityManager.persist(workFlowTaskDefinition);
- entityManager.persist(workFlowCheckerMappingDefinition);
- entityManager.persist(workFlowWorkDefinition);
+ entityManager.persistAndFlush(workFlowDefinition);
+ entityManager.persistAndFlush(workFlowTaskDefinition);
+ entityManager.persistAndFlush(workFlowCheckerMappingDefinition);
+ entityManager.persistAndFlush(workFlowWorkDefinition);
}
@Test
diff --git a/workflow-service/src/test/java/com/redhat/parodos/workflow/execution/controller/WorkFlowControllerTest.java b/workflow-service/src/test/java/com/redhat/parodos/workflow/execution/controller/WorkFlowControllerTest.java
index 83515982c..aa411fc9f 100644
--- a/workflow-service/src/test/java/com/redhat/parodos/workflow/execution/controller/WorkFlowControllerTest.java
+++ b/workflow-service/src/test/java/com/redhat/parodos/workflow/execution/controller/WorkFlowControllerTest.java
@@ -14,12 +14,14 @@
import com.redhat.parodos.workflow.enums.WorkType;
import com.redhat.parodos.workflow.execution.dto.WorkFlowCheckerTaskRequestDTO;
import com.redhat.parodos.workflow.execution.dto.WorkFlowRequestDTO;
+import com.redhat.parodos.workflow.execution.dto.WorkFlowResponseDTO;
import com.redhat.parodos.workflow.execution.dto.WorkFlowStatusResponseDTO;
import com.redhat.parodos.workflow.execution.dto.WorkStatusResponseDTO;
import com.redhat.parodos.workflow.execution.service.WorkFlowServiceImpl;
import com.redhat.parodos.workflow.task.enums.WorkFlowTaskStatus;
import com.redhat.parodos.workflows.work.WorkContext;
import com.redhat.parodos.workflows.work.WorkReport;
+import com.redhat.parodos.workflows.work.WorkStatus;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
@@ -35,6 +37,9 @@
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.web.server.ResponseStatusException;
+import static org.hamcrest.Matchers.equalToIgnoringCase;
+import static org.hamcrest.Matchers.hasSize;
+
@SpringBootTest
@DirtiesContext
@AutoConfigureMockMvc
@@ -232,6 +237,22 @@ public void TestGetStatusWithValidData() throws Exception {
.andExpect(MockMvcResultMatchers.status().isOk());
}
+ @Test
+ void TestGetWorkFlowByProjectIdWithValidData() throws Exception {
+ UUID workFlowExecutionId = UUID.randomUUID();
+ UUID projectId = UUID.randomUUID();
+ Mockito.when(workFlowService.getWorkFlowsByProjectId(projectId)).thenReturn(List.of(WorkFlowResponseDTO
+ .builder().workFlowExecutionId(workFlowExecutionId).workStatus(WorkStatus.COMPLETED).build()));
+ // when
+ this.mockMvc
+ .perform(this.getRequestWithValidCredentials("/api/v1/workflows").param("projectId",
+ projectId.toString()))
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON))
+ .andExpect(MockMvcResultMatchers.jsonPath("$", hasSize(1))).andExpect(MockMvcResultMatchers
+ .jsonPath("$[0].workStatus", equalToIgnoringCase(ParodosWorkStatus.COMPLETED.name())));
+ }
+
private String getWorkFlowCheckerTaskRequestDTOJsonPayload() throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
WorkFlowCheckerTaskRequestDTO workFlowCheckerTaskRequestDTO = WorkFlowCheckerTaskRequestDTO.builder()
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 a07b78596..7785ae4c1 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
@@ -1,20 +1,10 @@
package com.redhat.parodos.workflow.execution.service;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.UUID;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-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.mockito.ArgumentMatchers.any;
-
+import com.redhat.parodos.project.dto.ProjectResponseDTO;
+import com.redhat.parodos.project.service.ProjectService;
import com.redhat.parodos.workflow.WorkFlowDelegate;
import com.redhat.parodos.workflow.context.WorkContextDelegate;
+import com.redhat.parodos.workflow.definition.dto.WorkFlowDefinitionResponseDTO;
import com.redhat.parodos.workflow.definition.entity.WorkFlowDefinition;
import com.redhat.parodos.workflow.definition.entity.WorkFlowTaskDefinition;
import com.redhat.parodos.workflow.definition.entity.WorkFlowWorkDefinition;
@@ -22,6 +12,7 @@
import com.redhat.parodos.workflow.definition.repository.WorkFlowTaskDefinitionRepository;
import com.redhat.parodos.workflow.definition.repository.WorkFlowWorkRepository;
import com.redhat.parodos.workflow.definition.service.WorkFlowDefinitionServiceImpl;
+import com.redhat.parodos.workflow.enums.ParodosWorkStatus;
import com.redhat.parodos.workflow.enums.WorkFlowStatus;
import com.redhat.parodos.workflow.enums.WorkType;
import com.redhat.parodos.workflow.execution.dto.WorkFlowContextResponseDTO;
@@ -46,15 +37,33 @@
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
import org.mockito.Mockito;
+import org.modelmapper.ModelMapper;
+import org.springframework.security.test.context.support.WithMockUser;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.web.server.ResponseStatusException;
-class WorkFlowServiceImplTest {
+import javax.swing.*;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.UUID;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+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.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.nullable;
- @Mock
- private MeterRegistry meterRegistry;
+@ExtendWith(SpringExtension.class)
+class WorkFlowServiceImplTest {
private WorkFlowDelegate workFlowDelegate;
@@ -74,8 +83,12 @@ class WorkFlowServiceImplTest {
private WorkFlowDefinitionServiceImpl workFlowDefinitionService;
+ private ProjectService projectService;
+
private MeterRegistry metricRegistry;
+ private ModelMapper modelMapper;
+
@BeforeEach
void initEach() {
this.workFlowDelegate = Mockito.mock(WorkFlowDelegate.class);
@@ -87,11 +100,13 @@ void initEach() {
this.workFlowWorkRepository = Mockito.mock(WorkFlowWorkRepository.class);
this.workFlowDefinitionService = Mockito.mock(WorkFlowDefinitionServiceImpl.class);
this.metricRegistry = new SimpleMeterRegistry();
+ this.projectService = Mockito.mock(ProjectService.class);
+ this.modelMapper = new ModelMapper();
this.workFlowService = new WorkFlowServiceImpl(this.workFlowDelegate, this.workFlowServiceDelegate,
this.workFlowDefinitionRepository, this.workFlowTaskDefinitionRepository, this.workFlowRepository,
this.workFlowTaskRepository, this.workFlowWorkRepository, this.workFlowDefinitionService,
- this.metricRegistry);
+ this.metricRegistry, this.projectService, this.modelMapper);
}
@Test
@@ -502,35 +517,33 @@ void testGetWorkFlowStatusWithValidData() {
workFlowDefinition.setWorkFlowTaskDefinitions(List.of(workFlowTask1Definition));
// when
- Mockito.when(this.workFlowDefinitionRepository.findById(Mockito.eq(workFlowDefinitionId)))
+ Mockito.when(this.workFlowDefinitionRepository.findById(eq(workFlowDefinitionId)))
.thenReturn(Optional.of(workFlowDefinition));
- Mockito.when(this.workFlowRepository.findById(Mockito.eq(workFlowExecutionId)))
+ Mockito.when(this.workFlowRepository.findById(eq(workFlowExecutionId)))
.thenReturn(Optional.of(workFlowExecution));
- Mockito.when(this.workFlowDefinitionRepository.findById(Mockito.eq(testSubWorkFlow1DefinitionId)))
+ Mockito.when(this.workFlowDefinitionRepository.findById(eq(testSubWorkFlow1DefinitionId)))
.thenReturn(Optional.of(subWorkFlow1Definition));
Mockito.when(this.workFlowRepository.findFirstByMainWorkFlowExecutionAndWorkFlowDefinitionId(
- Mockito.eq(workFlowExecution), Mockito.eq(testSubWorkFlow1DefinitionId)))
- .thenReturn(subWorkFlow1Execution);
+ eq(workFlowExecution), eq(testSubWorkFlow1DefinitionId))).thenReturn(subWorkFlow1Execution);
- Mockito.when(this.workFlowTaskDefinitionRepository.findById(Mockito.eq(subWorkFlow1Task1DefinitionId)))
+ Mockito.when(this.workFlowTaskDefinitionRepository.findById(eq(subWorkFlow1Task1DefinitionId)))
.thenReturn(Optional.of(subWorkFlow1Task1Definition));
- Mockito.when(this.workFlowTaskDefinitionRepository.findById(Mockito.eq(workFlowTask1DefinitionId)))
+ Mockito.when(this.workFlowTaskDefinitionRepository.findById(eq(workFlowTask1DefinitionId)))
.thenReturn(Optional.of(workFlowTask1Definition));
Mockito.when(workFlowTaskRepository.findByWorkFlowExecutionIdAndWorkFlowTaskDefinitionId(
- Mockito.eq(testSubWorkFlow1ExecutionId), Mockito.eq(subWorkFlow1Task1DefinitionId)))
+ eq(testSubWorkFlow1ExecutionId), eq(subWorkFlow1Task1DefinitionId)))
.thenReturn(List.of(subWorkFlow1Task1Execution));
Mockito.when(workFlowTaskRepository.findByWorkFlowExecutionIdAndWorkFlowTaskDefinitionId(
- Mockito.eq(workFlowExecutionId), Mockito.eq(workFlowTask1DefinitionId)))
- .thenReturn(List.of(workFlowTask1Execution));
+ eq(workFlowExecutionId), eq(workFlowTask1DefinitionId))).thenReturn(List.of(workFlowTask1Execution));
- Mockito.when(this.workFlowServiceDelegate.getWorkFlowAndWorksStatus(Mockito.eq(workFlowExecution),
- Mockito.eq(workFlowDefinition)))
+ Mockito.when(
+ this.workFlowServiceDelegate.getWorkFlowAndWorksStatus(eq(workFlowExecution), eq(workFlowDefinition)))
.thenReturn(List.of(
WorkStatusResponseDTO.builder().name(SUB_WORKFLOW_1_NAME).type(WorkType.WORKFLOW)
.status(com.redhat.parodos.workflow.enums.ParodosWorkStatus.PENDING)
@@ -579,7 +592,7 @@ void testGetWorkFlowStatusWithInvalidExecutionData() {
UUID workFlowExecutionId = UUID.randomUUID();
// when
- Mockito.when(this.workFlowRepository.findById(Mockito.eq(workFlowExecutionId))).thenReturn(Optional.empty());
+ Mockito.when(this.workFlowRepository.findById(eq(workFlowExecutionId))).thenReturn(Optional.empty());
assertThrows(ResponseStatusException.class, () -> {
this.workFlowService.getWorkFlowStatus(workFlowExecutionId);
@@ -598,11 +611,10 @@ void testGetWorkFlowStatusWithInvalidDefinitionData() {
WorkFlowExecution workFlowExecution = Mockito.mock(WorkFlowExecution.class);
// when
- Mockito.when(this.workFlowRepository.findById(Mockito.eq(workFlowExecutionId)))
+ Mockito.when(this.workFlowRepository.findById(eq(workFlowExecutionId)))
.thenReturn(Optional.of(workFlowExecution));
- Mockito.when(this.workFlowDefinitionRepository.findById(Mockito.eq(workFlowDefinitionId)))
- .thenReturn(Optional.empty());
+ Mockito.when(this.workFlowDefinitionRepository.findById(eq(workFlowDefinitionId))).thenReturn(Optional.empty());
assertThrows(ResponseStatusException.class, () -> {
this.workFlowService.getWorkFlowStatus(workFlowExecutionId);
@@ -610,8 +622,8 @@ void testGetWorkFlowStatusWithInvalidDefinitionData() {
Mockito.verify(this.workFlowRepository, Mockito.times(1)).findById(any());
Mockito.verify(this.workFlowDefinitionRepository, Mockito.times(1)).findById(any());
- Mockito.verify(this.workFlowServiceDelegate, Mockito.never())
- .getWorkFlowAndWorksStatus(Mockito.eq(workFlowExecution), Mockito.any());
+ Mockito.verify(this.workFlowServiceDelegate, Mockito.never()).getWorkFlowAndWorksStatus(eq(workFlowExecution),
+ Mockito.any());
}
@Test
@@ -623,10 +635,10 @@ void testGetWorkFlowStatusWithNonMainWorkFlowData() {
WorkFlowDefinition workFlowDefinition = Mockito.mock(WorkFlowDefinition.class);
// when
- Mockito.when(this.workFlowRepository.findById(Mockito.eq(workFlowExecutionId)))
+ Mockito.when(this.workFlowRepository.findById(eq(workFlowExecutionId)))
.thenReturn(Optional.of(workFlowExecution));
- Mockito.when(this.workFlowDefinitionRepository.findById(Mockito.eq(workFlowDefinitionId)))
+ Mockito.when(this.workFlowDefinitionRepository.findById(eq(workFlowDefinitionId)))
.thenReturn(Optional.of(workFlowDefinition));
Mockito.when(workFlowExecution.getMainWorkFlowExecution()).thenReturn(null);
@@ -637,8 +649,8 @@ void testGetWorkFlowStatusWithNonMainWorkFlowData() {
Mockito.verify(this.workFlowRepository, Mockito.times(1)).findById(any());
Mockito.verify(this.workFlowDefinitionRepository, Mockito.times(1)).findById(any());
- Mockito.verify(this.workFlowServiceDelegate, Mockito.never())
- .getWorkFlowAndWorksStatus(Mockito.eq(workFlowExecution), Mockito.eq(workFlowDefinition));
+ Mockito.verify(this.workFlowServiceDelegate, Mockito.never()).getWorkFlowAndWorksStatus(eq(workFlowExecution),
+ eq(workFlowDefinition));
}
@Test
@@ -691,32 +703,32 @@ void testGetWorkFlowStatusWhenSubWorkflowNotExecutedWithValidData() {
workFlowDefinition.setWorkFlowTaskDefinitions(List.of(workFlowTask1Definition));
// when
- Mockito.when(this.workFlowDefinitionRepository.findById(Mockito.eq(workFlowDefinitionId)))
+ Mockito.when(this.workFlowDefinitionRepository.findById(eq(workFlowDefinitionId)))
.thenReturn(Optional.of(workFlowDefinition));
- Mockito.when(this.workFlowRepository.findById(Mockito.eq(workFlowExecutionId)))
+ Mockito.when(this.workFlowRepository.findById(eq(workFlowExecutionId)))
.thenReturn(Optional.of(workFlowExecution));
- Mockito.when(this.workFlowDefinitionRepository.findById(Mockito.eq(subWorkFlow1DefinitionId)))
+ Mockito.when(this.workFlowDefinitionRepository.findById(eq(subWorkFlow1DefinitionId)))
.thenReturn(Optional.of(subWorkFlow1Definition));
Mockito.when(this.workFlowRepository.findFirstByMainWorkFlowExecutionAndWorkFlowDefinitionId(
- Mockito.eq(workFlowExecution), Mockito.eq(subWorkFlow1DefinitionId))).thenReturn(null);
+ eq(workFlowExecution), eq(subWorkFlow1DefinitionId))).thenReturn(null);
- Mockito.when(this.workFlowTaskDefinitionRepository.findById(Mockito.eq(subWorkFlow1Task1DefinitionId)))
+ Mockito.when(this.workFlowTaskDefinitionRepository.findById(eq(subWorkFlow1Task1DefinitionId)))
.thenReturn(Optional.of(subWorkFlow1Task1Definition));
- Mockito.when(this.workFlowTaskDefinitionRepository.findById(Mockito.eq(workFlowTask1DefinitionId)))
+ Mockito.when(this.workFlowTaskDefinitionRepository.findById(eq(workFlowTask1DefinitionId)))
.thenReturn(Optional.of(workFlowTask1Definition));
Mockito.when(workFlowTaskRepository.findByWorkFlowExecutionIdAndWorkFlowTaskDefinitionId(
- Mockito.eq(subWorkFlow1ExecutionId), Mockito.eq(subWorkFlow1Task1DefinitionId))).thenReturn(List.of());
+ eq(subWorkFlow1ExecutionId), eq(subWorkFlow1Task1DefinitionId))).thenReturn(List.of());
Mockito.when(workFlowTaskRepository.findByWorkFlowExecutionIdAndWorkFlowTaskDefinitionId(
- Mockito.eq(workFlowExecutionId), Mockito.eq(workFlowTask1DefinitionId))).thenReturn(List.of());
+ eq(workFlowExecutionId), eq(workFlowTask1DefinitionId))).thenReturn(List.of());
- Mockito.when(this.workFlowServiceDelegate.getWorkFlowAndWorksStatus(Mockito.eq(workFlowExecution),
- Mockito.eq(workFlowDefinition)))
+ Mockito.when(
+ this.workFlowServiceDelegate.getWorkFlowAndWorksStatus(eq(workFlowExecution), eq(workFlowDefinition)))
.thenReturn(List.of(
WorkStatusResponseDTO.builder().name(SUB_WORKFLOW_1_NAME).type(WorkType.WORKFLOW)
.status(com.redhat.parodos.workflow.enums.ParodosWorkStatus.PENDING)
@@ -765,7 +777,7 @@ void testUpdateWorkFlowCheckerTaskStatusWithValidData() {
WorkFlowExecution mainWorkFlowExecution = WorkFlowExecution.builder().status(WorkFlowStatus.FAILED)
.projectId(projectId).workFlowDefinitionId(UUID.randomUUID()).build();
mainWorkFlowExecution.setId(workFlowExecutionId);
- Mockito.when(this.workFlowRepository.findById(Mockito.eq(workFlowExecutionId)))
+ Mockito.when(this.workFlowRepository.findById(eq(workFlowExecutionId)))
.thenReturn(Optional.of(mainWorkFlowExecution));
// workflow checker definition
@@ -812,7 +824,7 @@ void testUpdateWorkFlowCheckerTaskStatusWithInvalidExecutionData() {
String workFlowCheckerTaskName = "testWorkFlowTask";
// when
- Mockito.when(this.workFlowRepository.findById(Mockito.eq(workFlowExecutionId))).thenReturn(Optional.empty());
+ Mockito.when(this.workFlowRepository.findById(eq(workFlowExecutionId))).thenReturn(Optional.empty());
assertThrows(ResponseStatusException.class, () -> {
this.workFlowService.updateWorkFlowCheckerTaskStatus(workFlowExecutionId, workFlowCheckerTaskName,
@@ -831,7 +843,7 @@ void testUpdateWorkFlowCheckerTaskStatusWithInvalidTaskData() {
String workFlowCheckerTaskName = "testWorkFlowTask";
// when
- Mockito.when(this.workFlowRepository.findById(Mockito.eq(workFlowExecutionId)))
+ Mockito.when(this.workFlowRepository.findById(eq(workFlowExecutionId)))
.thenReturn(Optional.of(WorkFlowExecution.builder().status(WorkFlowStatus.FAILED)
.projectId(UUID.randomUUID()).workFlowDefinitionId(UUID.randomUUID()).build()));
@@ -862,7 +874,7 @@ public void testGetWorkflowParametersWithWorkflowOptions() {
Map.of("newOptions", List.of(new WorkFlowOption.Builder("test-id", "test-workflow").build())));
Mockito.when(executionContext.getWorkContext()).thenReturn(workContext);
- Mockito.when(this.workFlowRepository.findById(Mockito.eq(workFlowExecutionId)))
+ Mockito.when(this.workFlowRepository.findById(eq(workFlowExecutionId)))
.thenReturn(Optional.of(workFlowExecution));
// when
@@ -892,7 +904,7 @@ public void testGetWorkflowParametersWithoutWorkflowOptions() {
Mockito.when(workFlowExecution.getWorkFlowExecutionContext()).thenReturn(executionContext);
Mockito.when(executionContext.getWorkContext()).thenReturn(new WorkContext());
- Mockito.when(this.workFlowRepository.findById(Mockito.eq(workFlowExecutionId)))
+ Mockito.when(this.workFlowRepository.findById(eq(workFlowExecutionId)))
.thenReturn(Optional.of(workFlowExecution));
// when
@@ -907,6 +919,64 @@ public void testGetWorkflowParametersWithoutWorkflowOptions() {
assertNull(workflowParameters.getWorkFlowOptions().getNewOptions());
}
+ @Test
+ @WithMockUser(username = "test-user")
+ void getWorkFlowsByProjectId_when_projectIsFound_then_returnWorkFlowStatus() {
+ String workName = "test-workflow";
+ UUID projectId = UUID.randomUUID();
+ UUID workflowExecutionId = UUID.randomUUID();
+ WorkFlowDefinition workFlowDefinition = sampleWorkflowDefinition(workName);
+ WorkFlowExecution workFlowExecution = WorkFlowExecution.builder().projectId(projectId)
+ .status(WorkFlowStatus.COMPLETED).workFlowDefinitionId(workFlowDefinition.getId()).build();
+ workFlowExecution.setId(workflowExecutionId);
+ List workStatusResponseDTOList = List
+ .of(WorkStatusResponseDTO.builder().name(workName).status(ParodosWorkStatus.COMPLETED).build());
+ Mockito.when(workFlowRepository.findAllByProjectId(projectId)).thenReturn(List.of(workFlowExecution));
+ Mockito.when(projectService.getProjectByIdAndUsername(eq(projectId), nullable(String.class)))
+ .thenReturn(ProjectResponseDTO.builder().id(projectId).name("test-project").build());
+ Mockito.when(workFlowDefinitionService.getWorkFlowDefinitionById(any()))
+ .thenReturn(WorkFlowDefinitionResponseDTO.builder().name("test").build());
+
+ assertThat(workFlowService.getWorkFlowsByProjectId(projectId)).hasSize(1).extracting("workStatus")
+ .contains(WorkStatus.COMPLETED);
+ }
+
+ @Test
+ @WithMockUser(username = "test-user")
+ void getWorkFlows_when_projectIsFound_then_returnWorkFlowStatus() {
+ String workName = "test-workflow";
+ UUID project1Id = UUID.randomUUID();
+ UUID project2Id = UUID.randomUUID();
+ UUID workflowExecution1Id = UUID.randomUUID();
+ UUID workflowExecution2Id = UUID.randomUUID();
+ WorkFlowExecution workFlowExecution1 = WorkFlowExecution.builder().projectId(project1Id)
+ .status(WorkFlowStatus.COMPLETED).build();
+ workFlowExecution1.setId(workflowExecution1Id);
+ WorkFlowExecution workFlowExecution2 = WorkFlowExecution.builder().projectId(project2Id)
+ .status(WorkFlowStatus.FAILED).build();
+ workFlowExecution2.setId(workflowExecution2Id);
+
+ Mockito.when(workFlowRepository.findAllByProjectId(project1Id)).thenReturn(List.of(workFlowExecution1));
+ Mockito.when(workFlowRepository.findAllByProjectId(project2Id)).thenReturn(List.of(workFlowExecution2));
+ Mockito.when(projectService.findProjectsByUserName(nullable(String.class)))
+ .thenReturn(List.of(ProjectResponseDTO.builder().id(project1Id).name("test-project1").build(),
+ ProjectResponseDTO.builder().id(project2Id).name("test-project2").build()));
+ Mockito.when(workFlowDefinitionService.getWorkFlowDefinitionById(any()))
+ .thenReturn(WorkFlowDefinitionResponseDTO.builder().name("test").build());
+
+ assertThat(workFlowService.getWorkFlows()).hasSize(2).extracting("workStatus").contains(WorkStatus.COMPLETED,
+ WorkStatus.FAILED);
+ }
+
+ @Test
+ void getWorkFlowsByProjectId_when_projectIsNotFound_then_returnException() {
+ UUID projectId = UUID.randomUUID();
+
+ Mockito.when(projectService.getProjectById(projectId)).thenReturn(null);
+
+ assertThrows(RuntimeException.class, () -> workFlowService.getWorkFlowsByProjectId(projectId));
+ }
+
private WorkFlowDefinition sampleWorkflowDefinition(String name) {
WorkFlowDefinition wf = WorkFlowDefinition.builder().name(name).build();
wf.setId(UUID.randomUUID());