From d9aa5492e012ce1d5f6f681a0da8cb0cc2eff6f3 Mon Sep 17 00:00:00 2001 From: Annel Ketcha Date: Wed, 2 Aug 2023 21:17:29 -0400 Subject: [PATCH 1/3] remove workflow-service-sdk dependency from prebuilt-tasks --- prebuilt-tasks/pom.xml | 18 --- .../infrastructure/ProjectRequester.java | 18 --- ...jectAccessRequestApprovalWorkFlowTask.java | 11 +- .../ProjectAccessRequestWorkFlowTask.java | 57 +++++---- ...essRequestApprovalWorkFlowCheckerTask.java | 53 +++++--- .../tasks/project/dto/AccessRequestDTO.java | 15 +++ .../tasks/project/dto/AccessResponseDTO.java | 19 +++ .../project/dto/AccessStatusResponseDTO.java | 17 +++ ...ctAccessRequestEscalationWorkFlowTask.java | 11 +- ...AccessRequestApprovalWorkFlowTaskTest.java | 68 ++++++++++ .../ProjectAccessRequestWorkFlowTaskTest.java | 55 +++++--- ...equestApprovalWorkFlowCheckerTaskTest.java | 120 ++++++++++++++++++ ...cessRequestEscalationWorkFlowTaskTest.java | 67 ++++++++++ ...ectAccessRequestWorkFlowConfiguration.java | 25 ++-- .../client/ProjectRequesterClient.java | 52 -------- .../src/main/resources/application-local.yml | 7 - 16 files changed, 436 insertions(+), 177 deletions(-) delete mode 100644 prebuilt-tasks/src/main/java/com/redhat/parodos/infrastructure/ProjectRequester.java create mode 100644 prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/dto/AccessRequestDTO.java create mode 100644 prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/dto/AccessResponseDTO.java create mode 100644 prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/dto/AccessStatusResponseDTO.java delete mode 100644 workflow-service/src/main/java/com/redhat/parodos/client/ProjectRequesterClient.java diff --git a/prebuilt-tasks/pom.xml b/prebuilt-tasks/pom.xml index 1e18d0ad7..60dc4a42b 100644 --- a/prebuilt-tasks/pom.xml +++ b/prebuilt-tasks/pom.xml @@ -90,11 +90,6 @@ notification-service-sdk ${revision} - - dev.parodos - workflow-service-sdk - ${revision} - org.springframework spring-web @@ -103,19 +98,16 @@ com.fasterxml.jackson.dataformat jackson-dataformat-yaml - org.eclipse.jgit org.eclipse.jgit ${jgit-version} - com.github.mwiede jsch 0.2.9 - org.eclipse.jgit org.eclipse.jgit.ssh.jsch @@ -127,25 +119,21 @@ - org.bouncycastle bcprov-jdk18on 1.73 - org.eclipse.jgit org.eclipse.jgit.ssh.apache ${jgit-version} - org.eclipse.jgit org.eclipse.jgit.gpg.bc ${jgit-version} - org.eclipse.jgit org.eclipse.jgit.archive @@ -178,7 +166,6 @@ ${azure-resourcemanager-version} - io.fabric8 kubernetes-client @@ -200,7 +187,6 @@ generator-annotations ${fabric8.version} - com.squareup.okhttp3 @@ -208,26 +194,22 @@ 4.11.0 test - org.apache.sshd sshd-core 2.10.0 test-jar - org.apache.sshd sshd-common 2.10.0 - org.apache.sshd sshd-git 2.10.0 - diff --git a/prebuilt-tasks/src/main/java/com/redhat/parodos/infrastructure/ProjectRequester.java b/prebuilt-tasks/src/main/java/com/redhat/parodos/infrastructure/ProjectRequester.java deleted file mode 100644 index 03333e4a7..000000000 --- a/prebuilt-tasks/src/main/java/com/redhat/parodos/infrastructure/ProjectRequester.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.redhat.parodos.infrastructure; - -import java.util.UUID; - -import com.redhat.parodos.sdk.invoker.ApiException; -import com.redhat.parodos.sdk.model.AccessRequestDTO; -import com.redhat.parodos.sdk.model.AccessResponseDTO; -import com.redhat.parodos.sdk.model.AccessStatusResponseDTO; - -public interface ProjectRequester { - - String getBasePath(); - - AccessResponseDTO createAccess(UUID id, AccessRequestDTO accessRequestDTO) throws ApiException; - - AccessStatusResponseDTO getAccessStatus(UUID id) throws ApiException; - -} diff --git a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/ProjectAccessRequestApprovalWorkFlowTask.java b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/ProjectAccessRequestApprovalWorkFlowTask.java index 1642e9cd9..16db4b419 100644 --- a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/ProjectAccessRequestApprovalWorkFlowTask.java +++ b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/ProjectAccessRequestApprovalWorkFlowTask.java @@ -19,7 +19,6 @@ import java.util.UUID; import com.redhat.parodos.infrastructure.Notifier; -import com.redhat.parodos.infrastructure.ProjectRequester; import com.redhat.parodos.notification.sdk.model.NotificationMessageCreateRequestDTO; import com.redhat.parodos.workflow.exception.MissingParameterException; import com.redhat.parodos.workflow.task.BaseWorkFlowTask; @@ -42,13 +41,13 @@ @Slf4j public class ProjectAccessRequestApprovalWorkFlowTask extends BaseWorkFlowTask { - private final ProjectRequester projectRequester; + private final String serviceUrl; private final Notifier notifier; - public ProjectAccessRequestApprovalWorkFlowTask(ProjectRequester projectRequester, Notifier notifier) { + public ProjectAccessRequestApprovalWorkFlowTask(String serviceUrl, Notifier notifier) { super(); - this.projectRequester = projectRequester; + this.serviceUrl = serviceUrl; this.notifier = notifier; } @@ -69,8 +68,8 @@ public WorkReport execute(WorkContext workContext) { NotificationMessageCreateRequestDTO notificationMessageCreateRequestDTO = new NotificationMessageCreateRequestDTO(); notificationMessageCreateRequestDTO.setSubject(NOTIFICATION_SUBJECT_ACCESS_REQUEST_APPROVAL); notificationMessageCreateRequestDTO.setUsernames(Arrays.stream(approvalUsernames.split(",")).toList()); - notificationMessageCreateRequestDTO.setBody(getMessage( - String.format("%s/api/v1/projects/access/%s", projectRequester.getBasePath(), accessRequestId))); + notificationMessageCreateRequestDTO + .setBody(getMessage("%s/api/v1/projects/access/%s".formatted(serviceUrl, accessRequestId))); notifier.send(notificationMessageCreateRequestDTO); return new DefaultWorkReport(WorkStatus.COMPLETED, workContext); } diff --git a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/ProjectAccessRequestWorkFlowTask.java b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/ProjectAccessRequestWorkFlowTask.java index cb1898ada..d935b02ad 100644 --- a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/ProjectAccessRequestWorkFlowTask.java +++ b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/ProjectAccessRequestWorkFlowTask.java @@ -3,10 +3,10 @@ import java.util.List; import java.util.Objects; -import com.redhat.parodos.infrastructure.ProjectRequester; -import com.redhat.parodos.sdk.invoker.ApiException; -import com.redhat.parodos.sdk.model.AccessRequestDTO; -import com.redhat.parodos.sdk.model.AccessResponseDTO; +import com.redhat.parodos.project.enums.Role; +import com.redhat.parodos.tasks.project.dto.AccessRequestDTO; +import com.redhat.parodos.tasks.project.dto.AccessResponseDTO; +import com.redhat.parodos.utils.RestUtils; import com.redhat.parodos.workflow.exception.MissingParameterException; import com.redhat.parodos.workflow.parameter.WorkParameter; import com.redhat.parodos.workflow.parameter.WorkParameterType; @@ -18,6 +18,8 @@ import lombok.NonNull; import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; + import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.ACCESS_REQUEST_APPROVAL_USERNAMES; import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.ACCESS_REQUEST_ESCALATION_USERNAME; import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.ACCESS_REQUEST_ID; @@ -28,10 +30,16 @@ @Slf4j public class ProjectAccessRequestWorkFlowTask extends BaseWorkFlowTask { - private final ProjectRequester projectRequester; + private final String serviceUrl; + + private final String serviceUsername; + + private final String servicePassword; - public ProjectAccessRequestWorkFlowTask(ProjectRequester projectRequester) { - this.projectRequester = projectRequester; + public ProjectAccessRequestWorkFlowTask(String serviceUrl, String serviceUsername, String servicePassword) { + this.serviceUrl = serviceUrl; + this.serviceUsername = serviceUsername; + this.servicePassword = servicePassword; } @Override @@ -48,30 +56,35 @@ public WorkReport execute(WorkContext workContext) { } try { - AccessRequestDTO.RoleEnum.valueOf(role.toUpperCase()); + Role.valueOf(role.toUpperCase()); } catch (IllegalArgumentException e) { log.error("Exception when trying to convert role requested: {}", e.getMessage()); return new DefaultWorkReport(WorkStatus.FAILED, workContext, e); } - AccessRequestDTO accessRequestDTO = new AccessRequestDTO(); - accessRequestDTO.setUsername(username); - accessRequestDTO.setRole(AccessRequestDTO.RoleEnum.valueOf(role.toUpperCase())); - accessRequestDTO.setUsername(username); try { - AccessResponseDTO accessResponseDTO = projectRequester.createAccess(getProjectId(workContext), - accessRequestDTO); - addParameter(ACCESS_REQUEST_ID, Objects.requireNonNull(accessResponseDTO.getAccessRequestId()).toString()); - addParameter(ACCESS_REQUEST_APPROVAL_USERNAMES, - String.join(",", Objects.requireNonNull(accessResponseDTO.getApprovalSentTo()))); - addParameter(ACCESS_REQUEST_ESCALATION_USERNAME, String.join(",", accessResponseDTO.getEscalationSentTo())); - return new DefaultWorkReport(WorkStatus.COMPLETED, workContext); + String urlString = "%s/api/v1/projects/%s/access".formatted(serviceUrl, getProjectId(workContext)); + AccessRequestDTO requestDTO = AccessRequestDTO.builder().username(username) + .role(Role.valueOf(role.toUpperCase())).build(); + ResponseEntity responseDTO = RestUtils.executePost(urlString, requestDTO, + serviceUsername, servicePassword, AccessResponseDTO.class); + if (responseDTO.getStatusCode().is2xxSuccessful()) { + log.info("Rest call completed with response: {}", responseDTO.getBody()); + addParameter(ACCESS_REQUEST_ID, + Objects.requireNonNull(responseDTO.getBody()).getAccessRequestId().toString()); + addParameter(ACCESS_REQUEST_APPROVAL_USERNAMES, + String.join(",", Objects.requireNonNull(responseDTO.getBody()).getApprovalSentTo())); + addParameter(ACCESS_REQUEST_ESCALATION_USERNAME, + String.join(",", Objects.requireNonNull(responseDTO.getBody()).getEscalationSentTo())); + return new DefaultWorkReport(WorkStatus.COMPLETED, workContext); + } + log.error("Call to the api was not successful with status code: {}", responseDTO.getStatusCode()); } - catch (ApiException e) { - log.error("There was an issue with the api call: {}", e.getMessage()); - return new DefaultWorkReport(WorkStatus.FAILED, workContext); + catch (Exception e) { + log.error("There was an issue with the REST call: {}", e.getMessage()); } + return new DefaultWorkReport(WorkStatus.FAILED, workContext); } @Override diff --git a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/checker/ProjectAccessRequestApprovalWorkFlowCheckerTask.java b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/checker/ProjectAccessRequestApprovalWorkFlowCheckerTask.java index 08076583d..affd9b930 100644 --- a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/checker/ProjectAccessRequestApprovalWorkFlowCheckerTask.java +++ b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/checker/ProjectAccessRequestApprovalWorkFlowCheckerTask.java @@ -18,9 +18,8 @@ import java.util.Objects; import java.util.UUID; -import com.redhat.parodos.infrastructure.ProjectRequester; -import com.redhat.parodos.sdk.invoker.ApiException; -import com.redhat.parodos.sdk.model.AccessStatusResponseDTO; +import com.redhat.parodos.tasks.project.dto.AccessStatusResponseDTO; +import com.redhat.parodos.utils.RestUtils; import com.redhat.parodos.workflow.exception.MissingParameterException; import com.redhat.parodos.workflow.task.checker.BaseWorkFlowCheckerTask; import com.redhat.parodos.workflows.work.DefaultWorkReport; @@ -30,6 +29,8 @@ import com.redhat.parodos.workflows.workflow.WorkFlow; import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; + import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.ACCESS_REQUEST_ID; /** @@ -41,12 +42,18 @@ @Slf4j public class ProjectAccessRequestApprovalWorkFlowCheckerTask extends BaseWorkFlowCheckerTask { - private final ProjectRequester projectRequester; + private final String serviceUrl; + + private final String serviceUsername; + + private final String servicePassword; public ProjectAccessRequestApprovalWorkFlowCheckerTask(WorkFlow projectAccessRequestApprovalEscalationWorkFlow, - long sla, ProjectRequester projectRequester) { + long sla, String serviceUrl, String serviceUsername, String servicePassword) { super(projectAccessRequestApprovalEscalationWorkFlow, sla); - this.projectRequester = projectRequester; + this.serviceUrl = serviceUrl; + this.serviceUsername = serviceUsername; + this.servicePassword = servicePassword; } @Override @@ -62,22 +69,30 @@ public WorkReport checkWorkFlowStatus(WorkContext workContext) { } try { - AccessStatusResponseDTO accessStatusResponseDTO = projectRequester.getAccessStatus(accessRequestId); - switch (Objects.requireNonNull(accessStatusResponseDTO.getStatus())) { - case REJECTED -> { - log.info("Project access request {} is rejected!", accessStatusResponseDTO.getAccessRequestId()); - return new DefaultWorkReport(WorkStatus.REJECTED, workContext); - } - case APPROVED -> { - log.info("Project access request {} is completed!", accessStatusResponseDTO.getAccessRequestId()); - return new DefaultWorkReport(WorkStatus.COMPLETED, workContext); + String urlString = "%s/api/v1/projects/access/%s".formatted(serviceUrl, accessRequestId); + ResponseEntity responseDTO = RestUtils.restExchange(urlString, serviceUsername, + servicePassword, AccessStatusResponseDTO.class); + if (!responseDTO.getStatusCode().is2xxSuccessful()) { + log.error("Call to the api was not successful: {}", responseDTO.getStatusCode()); + } + else { + log.info("Rest call completed with response: {}", responseDTO.getBody()); + switch (Objects.requireNonNull(responseDTO.getBody()).getStatus()) { + case APPROVED -> { + log.info("Project access request {} is approved", responseDTO.getBody().getAccessRequestId()); + return new DefaultWorkReport(WorkStatus.COMPLETED, workContext); + } + case REJECTED -> { + log.info("Project access request {} is rejected", responseDTO.getBody().getAccessRequestId()); + return new DefaultWorkReport(WorkStatus.REJECTED, workContext); + } + default -> log.info("Project access request {} is waiting for approval", + responseDTO.getBody().getAccessRequestId()); } - default -> log.info("Project access request {} awaits for approval", - accessStatusResponseDTO.getAccessRequestId()); } } - catch (ApiException e) { - log.error("There was an issue with the api call: {}", e.getMessage()); + catch (Exception e) { + log.error("There was an issue with the REST call: {}", e.getMessage()); } return new DefaultWorkReport(WorkStatus.FAILED, workContext); } diff --git a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/dto/AccessRequestDTO.java b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/dto/AccessRequestDTO.java new file mode 100644 index 000000000..0e7f7c279 --- /dev/null +++ b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/dto/AccessRequestDTO.java @@ -0,0 +1,15 @@ +package com.redhat.parodos.tasks.project.dto; + +import com.redhat.parodos.project.enums.Role; +import lombok.Builder; +import lombok.Data; + +@Builder +@Data +public class AccessRequestDTO { + + private String username; + + private Role role; + +} diff --git a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/dto/AccessResponseDTO.java b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/dto/AccessResponseDTO.java new file mode 100644 index 000000000..f89cf2d41 --- /dev/null +++ b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/dto/AccessResponseDTO.java @@ -0,0 +1,19 @@ +package com.redhat.parodos.tasks.project.dto; + +import java.util.List; +import java.util.UUID; + +import lombok.Builder; +import lombok.Data; + +@Builder +@Data +public class AccessResponseDTO { + + private UUID accessRequestId; + + private List approvalSentTo; + + private String escalationSentTo; + +} diff --git a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/dto/AccessStatusResponseDTO.java b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/dto/AccessStatusResponseDTO.java new file mode 100644 index 000000000..63d5c7939 --- /dev/null +++ b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/dto/AccessStatusResponseDTO.java @@ -0,0 +1,17 @@ +package com.redhat.parodos.tasks.project.dto; + +import java.util.UUID; + +import com.redhat.parodos.project.enums.ProjectAccessStatus; +import lombok.Builder; +import lombok.Data; + +@Builder +@Data +public class AccessStatusResponseDTO { + + private UUID accessRequestId; + + private ProjectAccessStatus status; + +} diff --git a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/escalation/ProjectAccessRequestEscalationWorkFlowTask.java b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/escalation/ProjectAccessRequestEscalationWorkFlowTask.java index 7b698fddc..2eaf60317 100644 --- a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/escalation/ProjectAccessRequestEscalationWorkFlowTask.java +++ b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/escalation/ProjectAccessRequestEscalationWorkFlowTask.java @@ -18,7 +18,6 @@ import java.util.UUID; import com.redhat.parodos.infrastructure.Notifier; -import com.redhat.parodos.infrastructure.ProjectRequester; import com.redhat.parodos.notification.sdk.model.NotificationMessageCreateRequestDTO; import com.redhat.parodos.workflow.exception.MissingParameterException; import com.redhat.parodos.workflow.task.BaseWorkFlowTask; @@ -41,13 +40,13 @@ @Slf4j public class ProjectAccessRequestEscalationWorkFlowTask extends BaseWorkFlowTask { - private final ProjectRequester projectRequester; + private final String serviceUrl; private final Notifier notifier; - public ProjectAccessRequestEscalationWorkFlowTask(ProjectRequester projectRequester, Notifier notifier) { + public ProjectAccessRequestEscalationWorkFlowTask(String serviceUrl, Notifier notifier) { super(); - this.projectRequester = projectRequester; + this.serviceUrl = serviceUrl; this.notifier = notifier; } @@ -67,8 +66,8 @@ public WorkReport execute(WorkContext workContext) { NotificationMessageCreateRequestDTO notificationMessageCreateRequestDTO = new NotificationMessageCreateRequestDTO(); notificationMessageCreateRequestDTO.setSubject(NOTIFICATION_SUBJECT_ACCESS_REQUEST_ESCALATION); notificationMessageCreateRequestDTO.addUsernamesItem(escalationUsername); - notificationMessageCreateRequestDTO.setBody(getMessage( - String.format("%s/api/v1/projects/access/%s/status", projectRequester.getBasePath(), accessRequestId))); + notificationMessageCreateRequestDTO + .setBody(getMessage("%s/api/v1/projects/access/%s/status".formatted(serviceUrl, accessRequestId))); notifier.send(notificationMessageCreateRequestDTO); return new DefaultWorkReport(WorkStatus.COMPLETED, workContext); } diff --git a/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/project/ProjectAccessRequestApprovalWorkFlowTaskTest.java b/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/project/ProjectAccessRequestApprovalWorkFlowTaskTest.java index 1b6f5f922..ba7da66a2 100644 --- a/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/project/ProjectAccessRequestApprovalWorkFlowTaskTest.java +++ b/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/project/ProjectAccessRequestApprovalWorkFlowTaskTest.java @@ -1,5 +1,73 @@ package com.redhat.parodos.tasks.project; +import java.util.UUID; + +import com.redhat.parodos.infrastructure.Notifier; +import com.redhat.parodos.workflow.exception.MissingParameterException; +import com.redhat.parodos.workflows.work.WorkContext; +import com.redhat.parodos.workflows.work.WorkReport; +import com.redhat.parodos.workflows.work.WorkStatus; +import lombok.SneakyThrows; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.spy; + +@RunWith(MockitoJUnitRunner.class) public class ProjectAccessRequestApprovalWorkFlowTaskTest { + private static final String SERVICE_URL_TEST = "service-url-test"; + + private static final String ACCESS_REQUEST_ID_PARAMETER_NAME = "ACCESS_REQUEST_ID"; + + private static final String ACCESS_REQUEST_APPROVAL_USERNAMES_PARAMETER_NAME = "ACCESS_REQUEST_APPROVAL_USERNAMES"; + + private static final String ACCESS_REQUEST_APPROVAL_USERNAMES_VALUE_TEST = "approval-username-test"; + + @Mock + private Notifier notifier; + + private WorkContext workContext; + + private ProjectAccessRequestApprovalWorkFlowTask projectAccessRequestApprovalWorkFlowTask; + + @Before + public void setUp() { + this.projectAccessRequestApprovalWorkFlowTask = spy( + new ProjectAccessRequestApprovalWorkFlowTask(SERVICE_URL_TEST, notifier)); + this.projectAccessRequestApprovalWorkFlowTask.setBeanName("projectAccessRequestApprovalWorkFlowTask"); + workContext = new WorkContext(); + } + + @Test + @SneakyThrows + public void executeSuccess() { + doReturn(String.valueOf(UUID.randomUUID())).when(this.projectAccessRequestApprovalWorkFlowTask) + .getRequiredParameterValue(eq(ACCESS_REQUEST_ID_PARAMETER_NAME)); + doReturn(ACCESS_REQUEST_APPROVAL_USERNAMES_VALUE_TEST).when(this.projectAccessRequestApprovalWorkFlowTask) + .getRequiredParameterValue(eq(ACCESS_REQUEST_APPROVAL_USERNAMES_PARAMETER_NAME)); + doNothing().when(notifier).send(any()); + + WorkReport workReport = projectAccessRequestApprovalWorkFlowTask.execute(workContext); + assertEquals(WorkStatus.COMPLETED, workReport.getStatus()); + } + + @Test + @SneakyThrows + public void executeFail() { + doThrow(MissingParameterException.class).when(this.projectAccessRequestApprovalWorkFlowTask) + .getRequiredParameterValue(eq(ACCESS_REQUEST_ID_PARAMETER_NAME)); + WorkReport workReport = projectAccessRequestApprovalWorkFlowTask.execute(workContext); + assertEquals(WorkStatus.FAILED, workReport.getStatus()); + } + } diff --git a/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/project/ProjectAccessRequestWorkFlowTaskTest.java b/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/project/ProjectAccessRequestWorkFlowTaskTest.java index c6684ec4f..5500bf58e 100644 --- a/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/project/ProjectAccessRequestWorkFlowTaskTest.java +++ b/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/project/ProjectAccessRequestWorkFlowTaskTest.java @@ -1,9 +1,11 @@ package com.redhat.parodos.tasks.project; +import java.util.List; import java.util.UUID; -import com.redhat.parodos.infrastructure.ProjectRequester; -import com.redhat.parodos.sdk.model.AccessResponseDTO; +import com.redhat.parodos.tasks.project.dto.AccessResponseDTO; +import com.redhat.parodos.utils.RestUtils; +import com.redhat.parodos.workflow.exception.MissingParameterException; import com.redhat.parodos.workflow.utils.WorkContextUtils; import com.redhat.parodos.workflows.work.WorkContext; import com.redhat.parodos.workflows.work.WorkReport; @@ -12,20 +14,29 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mock; +import org.mockito.MockedStatic; import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.http.ResponseEntity; + import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mockStatic; import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) public class ProjectAccessRequestWorkFlowTaskTest { + private static final String SERVICE_URL_TEST = "service-url-test"; + + private static final String SERVICE_USERNAME_TEST = "service-username-test"; + + private static final String SERVICE_PASSWORD_TEST = "service-password-test"; + private static final String USERNAME_PARAMETER_NAME = "USERNAME"; private static final String USERNAME_VALUE_TEST = "username-test"; @@ -42,16 +53,14 @@ public class ProjectAccessRequestWorkFlowTaskTest { private static final String ESCALATION_USERNAME_TEST = "test"; - @Mock - private ProjectRequester projectRequester; - private WorkContext workContext; private ProjectAccessRequestWorkFlowTask projectAccessRequestWorkFlowTask; @Before public void setUp() { - this.projectAccessRequestWorkFlowTask = spy(new ProjectAccessRequestWorkFlowTask(projectRequester)); + this.projectAccessRequestWorkFlowTask = spy( + new ProjectAccessRequestWorkFlowTask(SERVICE_URL_TEST, SERVICE_USERNAME_TEST, SERVICE_PASSWORD_TEST)); this.projectAccessRequestWorkFlowTask.setBeanName("projectAccessRequestWorkFlowTask"); workContext = new WorkContext(); WorkContextUtils.setProjectId(workContext, UUID.randomUUID()); @@ -65,17 +74,16 @@ public void executeSuccess() { doReturn(ROLE_VALUE_TEST).when(this.projectAccessRequestWorkFlowTask) .getOptionalParameterValue(eq(ROLE_PARAMETER_NAME), eq(ROLE_DEFAULT_VALUE), eq(false)); - AccessResponseDTO accessResponseDTO = new AccessResponseDTO(); - accessResponseDTO.setAccessRequestId(UUID.randomUUID()); - accessResponseDTO.addApprovalSentToItem(APPROVAL_USERNAME_TEST); - accessResponseDTO.setEscalationSentTo(ESCALATION_USERNAME_TEST); - - when(projectRequester.createAccess(any(), any())).thenReturn(accessResponseDTO); - - doNothing().when(projectAccessRequestWorkFlowTask).addParameter(any(), any()); - - WorkReport workReport = projectAccessRequestWorkFlowTask.execute(workContext); - assertEquals(WorkStatus.COMPLETED, workReport.getStatus()); + try (MockedStatic restUtilsMockedStatic = mockStatic(RestUtils.class)) { + restUtilsMockedStatic.when( + () -> RestUtils.executePost(any(String.class), any(), any(String.class), any(String.class), any())) + .thenReturn(ResponseEntity.ok(AccessResponseDTO.builder().accessRequestId(UUID.randomUUID()) + .approvalSentTo(List.of(APPROVAL_USERNAME_TEST)).escalationSentTo(ESCALATION_USERNAME_TEST) + .build())); + doNothing().when(projectAccessRequestWorkFlowTask).addParameter(any(), any()); + WorkReport workReport = projectAccessRequestWorkFlowTask.execute(workContext); + assertEquals(WorkStatus.COMPLETED, workReport.getStatus()); + } } @Test @@ -89,4 +97,13 @@ public void executeFailForInvalidRole() { assertEquals(WorkStatus.FAILED, workReport.getStatus()); } + @Test + @SneakyThrows + public void executeFailForMissingRequiredParameter() { + doThrow(MissingParameterException.class).when(this.projectAccessRequestWorkFlowTask) + .getRequiredParameterValue(eq(USERNAME_PARAMETER_NAME)); + WorkReport workReport = projectAccessRequestWorkFlowTask.execute(workContext); + assertEquals(WorkStatus.FAILED, workReport.getStatus()); + } + } diff --git a/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/project/checker/ProjectAccessRequestApprovalWorkFlowCheckerTaskTest.java b/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/project/checker/ProjectAccessRequestApprovalWorkFlowCheckerTaskTest.java index 73f0d29b7..ba81860f6 100644 --- a/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/project/checker/ProjectAccessRequestApprovalWorkFlowCheckerTaskTest.java +++ b/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/project/checker/ProjectAccessRequestApprovalWorkFlowCheckerTaskTest.java @@ -1,5 +1,125 @@ package com.redhat.parodos.tasks.project.checker; +import java.util.UUID; + +import com.redhat.parodos.project.enums.ProjectAccessStatus; +import com.redhat.parodos.tasks.project.dto.AccessStatusResponseDTO; +import com.redhat.parodos.utils.RestUtils; +import com.redhat.parodos.workflow.exception.MissingParameterException; +import com.redhat.parodos.workflow.utils.WorkContextUtils; +import com.redhat.parodos.workflows.work.WorkContext; +import com.redhat.parodos.workflows.work.WorkReport; +import com.redhat.parodos.workflows.work.WorkStatus; +import com.redhat.parodos.workflows.workflow.WorkFlow; +import lombok.SneakyThrows; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockedStatic; +import org.mockito.junit.MockitoJUnitRunner; + +import org.springframework.http.ResponseEntity; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.spy; + +@RunWith(MockitoJUnitRunner.class) public class ProjectAccessRequestApprovalWorkFlowCheckerTaskTest { + private static final String SERVICE_URL_TEST = "service-url-test"; + + private static final String SERVICE_USERNAME_TEST = "service-username-test"; + + private static final String SERVICE_PASSWORD_TEST = "service-password-test"; + + private static final String ACCESS_REQUEST_ID_PARAMETER_NAME = "ACCESS_REQUEST_ID"; + + private static final long SLA_TEST = 100L; + + @Mock + private WorkFlow workFlow; + + private WorkContext workContext; + + private ProjectAccessRequestApprovalWorkFlowCheckerTask projectAccessRequestApprovalWorkFlowCheckerTask; + + @Before + public void setUp() { + this.projectAccessRequestApprovalWorkFlowCheckerTask = spy(new ProjectAccessRequestApprovalWorkFlowCheckerTask( + workFlow, SLA_TEST, SERVICE_URL_TEST, SERVICE_USERNAME_TEST, SERVICE_PASSWORD_TEST)); + this.projectAccessRequestApprovalWorkFlowCheckerTask + .setBeanName("projectAccessRequestApprovalWorkFlowCheckerTask"); + workContext = new WorkContext(); + WorkContextUtils.setProjectId(workContext, UUID.randomUUID()); + } + + @Test + @SneakyThrows + public void checkWorkFlowStatusCompleted() { + UUID accessRequestId = UUID.randomUUID(); + + doReturn(String.valueOf(accessRequestId)).when(this.projectAccessRequestApprovalWorkFlowCheckerTask) + .getRequiredParameterValue(eq(ACCESS_REQUEST_ID_PARAMETER_NAME)); + + try (MockedStatic restUtilsMockedStatic = mockStatic(RestUtils.class)) { + restUtilsMockedStatic + .when(() -> RestUtils.restExchange(any(String.class), any(String.class), any(String.class), any())) + .thenReturn(ResponseEntity.ok(AccessStatusResponseDTO.builder().accessRequestId(accessRequestId) + .status(ProjectAccessStatus.APPROVED).build())); + WorkReport workReport = projectAccessRequestApprovalWorkFlowCheckerTask.execute(workContext); + assertEquals(WorkStatus.COMPLETED, workReport.getStatus()); + } + } + + @Test + @SneakyThrows + public void checkWorkFlowStatusRejected() { + UUID accessRequestId = UUID.randomUUID(); + + doReturn(String.valueOf(accessRequestId)).when(this.projectAccessRequestApprovalWorkFlowCheckerTask) + .getRequiredParameterValue(eq(ACCESS_REQUEST_ID_PARAMETER_NAME)); + + try (MockedStatic restUtilsMockedStatic = mockStatic(RestUtils.class)) { + restUtilsMockedStatic + .when(() -> RestUtils.restExchange(any(String.class), any(String.class), any(String.class), any())) + .thenReturn(ResponseEntity.ok(AccessStatusResponseDTO.builder().accessRequestId(accessRequestId) + .status(ProjectAccessStatus.REJECTED).build())); + WorkReport workReport = projectAccessRequestApprovalWorkFlowCheckerTask.execute(workContext); + assertEquals(WorkStatus.REJECTED, workReport.getStatus()); + } + } + + @Test + @SneakyThrows + public void checkWorkFlowStatusPending() { + UUID accessRequestId = UUID.randomUUID(); + + doReturn(String.valueOf(accessRequestId)).when(this.projectAccessRequestApprovalWorkFlowCheckerTask) + .getRequiredParameterValue(eq(ACCESS_REQUEST_ID_PARAMETER_NAME)); + + try (MockedStatic restUtilsMockedStatic = mockStatic(RestUtils.class)) { + restUtilsMockedStatic + .when(() -> RestUtils.restExchange(any(String.class), any(String.class), any(String.class), any())) + .thenReturn(ResponseEntity.ok(AccessStatusResponseDTO.builder().accessRequestId(accessRequestId) + .status(ProjectAccessStatus.PENDING).build())); + WorkReport workReport = projectAccessRequestApprovalWorkFlowCheckerTask.execute(workContext); + assertEquals(WorkStatus.FAILED, workReport.getStatus()); + } + } + + @Test + @SneakyThrows + public void executeFailForMissingRequiredParameter() { + doThrow(MissingParameterException.class).when(this.projectAccessRequestApprovalWorkFlowCheckerTask) + .getRequiredParameterValue(eq(ACCESS_REQUEST_ID_PARAMETER_NAME)); + WorkReport workReport = projectAccessRequestApprovalWorkFlowCheckerTask.execute(workContext); + assertEquals(WorkStatus.FAILED, workReport.getStatus()); + } + } diff --git a/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/project/escalation/ProjectAccessRequestEscalationWorkFlowTaskTest.java b/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/project/escalation/ProjectAccessRequestEscalationWorkFlowTaskTest.java index b3609bc28..937a39679 100644 --- a/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/project/escalation/ProjectAccessRequestEscalationWorkFlowTaskTest.java +++ b/prebuilt-tasks/src/test/java/com/redhat/parodos/tasks/project/escalation/ProjectAccessRequestEscalationWorkFlowTaskTest.java @@ -1,5 +1,72 @@ package com.redhat.parodos.tasks.project.escalation; +import java.util.UUID; + +import com.redhat.parodos.infrastructure.Notifier; +import com.redhat.parodos.workflow.exception.MissingParameterException; +import com.redhat.parodos.workflows.work.WorkContext; +import com.redhat.parodos.workflows.work.WorkReport; +import com.redhat.parodos.workflows.work.WorkStatus; +import lombok.SneakyThrows; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.spy; + +@RunWith(MockitoJUnitRunner.class) public class ProjectAccessRequestEscalationWorkFlowTaskTest { + private static final String SERVICE_URL_TEST = "service-url-test"; + + private static final String ACCESS_REQUEST_ID_PARAMETER_NAME = "ACCESS_REQUEST_ID"; + + private static final String ACCESS_REQUEST_ESCALATION_USERNAME_PARAMETER_NAME = "ACCESS_REQUEST_ESCALATION_USERNAME"; + + private static final String ACCESS_REQUEST_ESCALATION_USERNAME_VALUE_TEST = "escalation-username-test"; + + @Mock + private Notifier notifier; + + private WorkContext workContext; + + private ProjectAccessRequestEscalationWorkFlowTask projectAccessRequestEscalationWorkFlowTask; + + @Before + public void setUp() { + this.projectAccessRequestEscalationWorkFlowTask = spy( + new ProjectAccessRequestEscalationWorkFlowTask(SERVICE_URL_TEST, notifier)); + this.projectAccessRequestEscalationWorkFlowTask.setBeanName("projectAccessRequestEscalationWorkFlowTask"); + workContext = new WorkContext(); + } + + @Test + @SneakyThrows + public void executeSuccess() { + doReturn(String.valueOf(UUID.randomUUID())).when(this.projectAccessRequestEscalationWorkFlowTask) + .getRequiredParameterValue(eq(ACCESS_REQUEST_ID_PARAMETER_NAME)); + doReturn(ACCESS_REQUEST_ESCALATION_USERNAME_VALUE_TEST).when(this.projectAccessRequestEscalationWorkFlowTask) + .getRequiredParameterValue(eq(ACCESS_REQUEST_ESCALATION_USERNAME_PARAMETER_NAME)); + doNothing().when(notifier).send(any()); + WorkReport workReport = projectAccessRequestEscalationWorkFlowTask.execute(workContext); + assertEquals(WorkStatus.COMPLETED, workReport.getStatus()); + } + + @Test + @SneakyThrows + public void executeFail() { + doThrow(MissingParameterException.class).when(this.projectAccessRequestEscalationWorkFlowTask) + .getRequiredParameterValue(eq(ACCESS_REQUEST_ID_PARAMETER_NAME)); + WorkReport workReport = projectAccessRequestEscalationWorkFlowTask.execute(workContext); + assertEquals(WorkStatus.FAILED, workReport.getStatus()); + } + } diff --git a/workflow-examples/src/main/java/com/redhat/parodos/examples/prebuilt/project/ProjectAccessRequestWorkFlowConfiguration.java b/workflow-examples/src/main/java/com/redhat/parodos/examples/prebuilt/project/ProjectAccessRequestWorkFlowConfiguration.java index 7d36fa15f..6ebaff895 100644 --- a/workflow-examples/src/main/java/com/redhat/parodos/examples/prebuilt/project/ProjectAccessRequestWorkFlowConfiguration.java +++ b/workflow-examples/src/main/java/com/redhat/parodos/examples/prebuilt/project/ProjectAccessRequestWorkFlowConfiguration.java @@ -4,7 +4,6 @@ import java.util.List; import com.redhat.parodos.infrastructure.Notifier; -import com.redhat.parodos.infrastructure.ProjectRequester; import com.redhat.parodos.tasks.project.ProjectAccessRequestApprovalWorkFlowTask; import com.redhat.parodos.tasks.project.ProjectAccessRequestWorkFlowTask; import com.redhat.parodos.tasks.project.checker.ProjectAccessRequestApprovalWorkFlowCheckerTask; @@ -17,6 +16,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -26,8 +26,8 @@ public class ProjectAccessRequestWorkFlowConfiguration { @Bean ProjectAccessRequestEscalationWorkFlowTask projectAccessRequestEscalationWorkFlowTask( - ProjectRequester projectRequester, Notifier notifier) { - return new ProjectAccessRequestEscalationWorkFlowTask(projectRequester, notifier); + @Value("${SERVICE_URL:http://localhost:8080}") String serviceUrl, Notifier notifier) { + return new ProjectAccessRequestEscalationWorkFlowTask(serviceUrl, notifier); } @Bean(name = "projectAccessRequestEscalationWorkFlow") @@ -41,9 +41,11 @@ WorkFlow projectAccessRequestEscalationWorkFlow( @Bean ProjectAccessRequestApprovalWorkFlowCheckerTask projectAccessRequestApprovalWorkFlowCheckerTask( @Qualifier("projectAccessRequestEscalationWorkFlow") WorkFlow projectAccessRequestEscalationWorkFlow, - ProjectRequester projectRequester) { + @Value("${SERVICE_URL:http://localhost:8080}") String serviceUrl, + @Value("${SERVICE_USERNAME:test}") String serviceUsername, + @Value("${SERVICE_PASSWORD:test}") String servicePassword) { return new ProjectAccessRequestApprovalWorkFlowCheckerTask(projectAccessRequestEscalationWorkFlow, - new Date().getTime() / 1000 + 30, projectRequester); + new Date().getTime() / 1000 + 30, serviceUrl, serviceUsername, servicePassword); } @Bean(name = "projectAccessRequestApprovalWorkFlowChecker") @@ -55,16 +57,19 @@ WorkFlow projectAccessRequestApprovalWorkFlowChecker( } @Bean - ProjectAccessRequestWorkFlowTask projectAccessRequestWorkFlowTask(ProjectRequester projectRequester) { - return new ProjectAccessRequestWorkFlowTask(projectRequester); + ProjectAccessRequestWorkFlowTask projectAccessRequestWorkFlowTask( + @Value("${SERVICE_URL:http://localhost:8080}") String serviceUrl, + @Value("${SERVICE_USERNAME:test}") String serviceUsername, + @Value("${SERVICE_PASSWORD:test}") String servicePassword) { + return new ProjectAccessRequestWorkFlowTask(serviceUrl, serviceUsername, servicePassword); } @Bean ProjectAccessRequestApprovalWorkFlowTask projectAccessRequestApprovalWorkFlowTask( - @Qualifier("projectAccessRequestApprovalWorkFlowChecker") WorkFlow projectAccessRequestApprovalWorkFlowChecker, - ProjectRequester projectRequester, Notifier notifier) { + @Value("${SERVICE_URL:http://localhost:8080}") String serviceUrl, Notifier notifier, + @Qualifier("projectAccessRequestApprovalWorkFlowChecker") WorkFlow projectAccessRequestApprovalWorkFlowChecker) { ProjectAccessRequestApprovalWorkFlowTask projectAccessRequestApprovalWorkFlowTask = new ProjectAccessRequestApprovalWorkFlowTask( - projectRequester, notifier); + serviceUrl, notifier); projectAccessRequestApprovalWorkFlowTask .setWorkFlowCheckers(List.of(projectAccessRequestApprovalWorkFlowChecker)); return projectAccessRequestApprovalWorkFlowTask; diff --git a/workflow-service/src/main/java/com/redhat/parodos/client/ProjectRequesterClient.java b/workflow-service/src/main/java/com/redhat/parodos/client/ProjectRequesterClient.java deleted file mode 100644 index 1e28ae311..000000000 --- a/workflow-service/src/main/java/com/redhat/parodos/client/ProjectRequesterClient.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.redhat.parodos.client; - -import java.util.Base64; -import java.util.UUID; - -import com.redhat.parodos.infrastructure.ProjectRequester; -import com.redhat.parodos.sdk.api.ProjectAccessApi; -import com.redhat.parodos.sdk.api.ProjectApi; -import com.redhat.parodos.sdk.invoker.ApiClient; -import com.redhat.parodos.sdk.invoker.ApiException; -import com.redhat.parodos.sdk.model.AccessRequestDTO; -import com.redhat.parodos.sdk.model.AccessResponseDTO; -import com.redhat.parodos.sdk.model.AccessStatusResponseDTO; -import lombok.extern.slf4j.Slf4j; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpHeaders; -import org.springframework.stereotype.Component; - -@Slf4j -@Component -public class ProjectRequesterClient implements ProjectRequester { - - private final ProjectApi projectApi; - - private final ProjectAccessApi projectAccessApi; - - public ProjectRequesterClient(@Value("${workflow.url:test}") String url, - @Value("${workflow.auth.basic.user:test}") String user, - @Value("${workflow.auth.basic.password:test}") String password) { - ApiClient apiClient = new ApiClient().setBasePath(url).addDefaultHeader(HttpHeaders.AUTHORIZATION, - "Basic " + Base64.getEncoder().encodeToString((user + ":" + password).getBytes())); - projectApi = new ProjectApi(apiClient); - projectAccessApi = new ProjectAccessApi(apiClient); - } - - @Override - public String getBasePath() { - return projectApi.getApiClient().getBasePath(); - } - - @Override - public AccessResponseDTO createAccess(UUID id, AccessRequestDTO accessRequestDTO) throws ApiException { - return projectApi.createAccessRequestToProject(id, accessRequestDTO); - } - - @Override - public AccessStatusResponseDTO getAccessStatus(UUID id) throws ApiException { - return projectAccessApi.getProjectAccessStatus(id); - } - -} diff --git a/workflow-service/src/main/resources/application-local.yml b/workflow-service/src/main/resources/application-local.yml index db7709c30..49bc93d88 100644 --- a/workflow-service/src/main/resources/application-local.yml +++ b/workflow-service/src/main/resources/application-local.yml @@ -40,13 +40,6 @@ notification: user: test password: test -workflow: - url: "${WORKFLOW_SERVER_URL:http://localhost:8080}" - auth: - basic: - user: test - password: test - workflows: mta: url: "${MTA_URL:https://mta-openshift-mta.apps.parodos-dev.projects.ecosystem.sysdeseng.com}" From 08ff41898ef72be6b58da49cb2561c616e85485c Mon Sep 17 00:00:00 2001 From: Annel Ketcha Date: Wed, 2 Aug 2023 22:03:47 -0400 Subject: [PATCH 2/3] fix run endpoint and api call --- .../ProjectAccessRequestApprovalWorkFlowCheckerTask.java | 2 +- .../redhat/parodos/tasks/project/dto/AccessResponseDTO.java | 6 +++++- .../parodos/tasks/project/dto/AccessStatusResponseDTO.java | 6 +++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/checker/ProjectAccessRequestApprovalWorkFlowCheckerTask.java b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/checker/ProjectAccessRequestApprovalWorkFlowCheckerTask.java index affd9b930..6673bd58b 100644 --- a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/checker/ProjectAccessRequestApprovalWorkFlowCheckerTask.java +++ b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/checker/ProjectAccessRequestApprovalWorkFlowCheckerTask.java @@ -69,7 +69,7 @@ public WorkReport checkWorkFlowStatus(WorkContext workContext) { } try { - String urlString = "%s/api/v1/projects/access/%s".formatted(serviceUrl, accessRequestId); + String urlString = "%s/api/v1/projects/access/%s/status".formatted(serviceUrl, accessRequestId); ResponseEntity responseDTO = RestUtils.restExchange(urlString, serviceUsername, servicePassword, AccessStatusResponseDTO.class); if (!responseDTO.getStatusCode().is2xxSuccessful()) { diff --git a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/dto/AccessResponseDTO.java b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/dto/AccessResponseDTO.java index f89cf2d41..a6763e0b8 100644 --- a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/dto/AccessResponseDTO.java +++ b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/dto/AccessResponseDTO.java @@ -3,11 +3,15 @@ import java.util.List; import java.util.UUID; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; -@Builder @Data +@Builder +@AllArgsConstructor +@NoArgsConstructor public class AccessResponseDTO { private UUID accessRequestId; diff --git a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/dto/AccessStatusResponseDTO.java b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/dto/AccessStatusResponseDTO.java index 63d5c7939..d3b4825b4 100644 --- a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/dto/AccessStatusResponseDTO.java +++ b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/dto/AccessStatusResponseDTO.java @@ -3,11 +3,15 @@ import java.util.UUID; import com.redhat.parodos.project.enums.ProjectAccessStatus; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; -@Builder @Data +@Builder +@AllArgsConstructor +@NoArgsConstructor public class AccessStatusResponseDTO { private UUID accessRequestId; From 4caf1768d57b5dd8793f98670dac2bb1bc8b0878 Mon Sep 17 00:00:00 2001 From: Annel Ketcha Date: Thu, 3 Aug 2023 06:55:26 -0400 Subject: [PATCH 3/3] fix code review comments --- ...jectAccessRequestApprovalWorkFlowTask.java | 10 +++++---- .../ProjectAccessRequestWorkFlowTask.java | 19 ++++++++++------- ...essRequestApprovalWorkFlowCheckerTask.java | 4 ++-- .../consts/ProjectAccessRequestConstant.java | 21 ------------------- ...ctAccessRequestEscalationWorkFlowTask.java | 10 +++++---- 5 files changed, 26 insertions(+), 38 deletions(-) delete mode 100644 prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/consts/ProjectAccessRequestConstant.java diff --git a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/ProjectAccessRequestApprovalWorkFlowTask.java b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/ProjectAccessRequestApprovalWorkFlowTask.java index 16db4b419..1c6c2e74a 100644 --- a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/ProjectAccessRequestApprovalWorkFlowTask.java +++ b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/ProjectAccessRequestApprovalWorkFlowTask.java @@ -28,10 +28,6 @@ import com.redhat.parodos.workflows.work.WorkStatus; import lombok.extern.slf4j.Slf4j; -import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.ACCESS_REQUEST_APPROVAL_USERNAMES; -import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.ACCESS_REQUEST_ID; -import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.NOTIFICATION_SUBJECT_ACCESS_REQUEST_APPROVAL; - /** * Project access request approval workflow task * @@ -41,6 +37,12 @@ @Slf4j public class ProjectAccessRequestApprovalWorkFlowTask extends BaseWorkFlowTask { + private static final String ACCESS_REQUEST_ID = "ACCESS_REQUEST_ID"; + + private static final String ACCESS_REQUEST_APPROVAL_USERNAMES = "ACCESS_REQUEST_APPROVAL_USERNAMES"; + + private static final String NOTIFICATION_SUBJECT_ACCESS_REQUEST_APPROVAL = "Project Access Request Approval"; + private final String serviceUrl; private final Notifier notifier; diff --git a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/ProjectAccessRequestWorkFlowTask.java b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/ProjectAccessRequestWorkFlowTask.java index d935b02ad..8d5b7563e 100644 --- a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/ProjectAccessRequestWorkFlowTask.java +++ b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/ProjectAccessRequestWorkFlowTask.java @@ -20,16 +20,21 @@ import org.springframework.http.ResponseEntity; -import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.ACCESS_REQUEST_APPROVAL_USERNAMES; -import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.ACCESS_REQUEST_ESCALATION_USERNAME; -import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.ACCESS_REQUEST_ID; -import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.PARAMETER_ROLE; -import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.PARAMETER_ROLE_DEFAULT; -import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.PARAMETER_USERNAME; - @Slf4j public class ProjectAccessRequestWorkFlowTask extends BaseWorkFlowTask { + private static final String PARAMETER_USERNAME = "USERNAME"; + + private static final String PARAMETER_ROLE = "ROLE"; + + private static final String PARAMETER_ROLE_DEFAULT = "DEVELOPER"; + + private static final String ACCESS_REQUEST_ID = "ACCESS_REQUEST_ID"; + + private static final String ACCESS_REQUEST_APPROVAL_USERNAMES = "ACCESS_REQUEST_APPROVAL_USERNAMES"; + + private static final String ACCESS_REQUEST_ESCALATION_USERNAME = "ACCESS_REQUEST_ESCALATION_USERNAME"; + private final String serviceUrl; private final String serviceUsername; diff --git a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/checker/ProjectAccessRequestApprovalWorkFlowCheckerTask.java b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/checker/ProjectAccessRequestApprovalWorkFlowCheckerTask.java index 6673bd58b..8c896c6c8 100644 --- a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/checker/ProjectAccessRequestApprovalWorkFlowCheckerTask.java +++ b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/checker/ProjectAccessRequestApprovalWorkFlowCheckerTask.java @@ -31,8 +31,6 @@ import org.springframework.http.ResponseEntity; -import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.ACCESS_REQUEST_ID; - /** * Project access request approval workflow checker task * @@ -42,6 +40,8 @@ @Slf4j public class ProjectAccessRequestApprovalWorkFlowCheckerTask extends BaseWorkFlowCheckerTask { + private static final String ACCESS_REQUEST_ID = "ACCESS_REQUEST_ID"; + private final String serviceUrl; private final String serviceUsername; diff --git a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/consts/ProjectAccessRequestConstant.java b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/consts/ProjectAccessRequestConstant.java deleted file mode 100644 index 4df41b892..000000000 --- a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/consts/ProjectAccessRequestConstant.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.redhat.parodos.tasks.project.consts; - -public class ProjectAccessRequestConstant { - - public final static String PARAMETER_USERNAME = "USERNAME"; - - public final static String PARAMETER_ROLE = "ROLE"; - - public final static String PARAMETER_ROLE_DEFAULT = "DEVELOPER"; - - public final static String ACCESS_REQUEST_ID = "ACCESS_REQUEST_ID"; - - public final static String ACCESS_REQUEST_APPROVAL_USERNAMES = "ACCESS_REQUEST_APPROVAL_USERNAMES"; - - public final static String ACCESS_REQUEST_ESCALATION_USERNAME = "ACCESS_REQUEST_ESCALATION_USERNAME"; - - public final static String NOTIFICATION_SUBJECT_ACCESS_REQUEST_APPROVAL = "Project Access Request Approval"; - - public final static String NOTIFICATION_SUBJECT_ACCESS_REQUEST_ESCALATION = "Project Access Request Escalation"; - -} diff --git a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/escalation/ProjectAccessRequestEscalationWorkFlowTask.java b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/escalation/ProjectAccessRequestEscalationWorkFlowTask.java index 2eaf60317..177376134 100644 --- a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/escalation/ProjectAccessRequestEscalationWorkFlowTask.java +++ b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/project/escalation/ProjectAccessRequestEscalationWorkFlowTask.java @@ -27,10 +27,6 @@ import com.redhat.parodos.workflows.work.WorkStatus; import lombok.extern.slf4j.Slf4j; -import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.ACCESS_REQUEST_ESCALATION_USERNAME; -import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.ACCESS_REQUEST_ID; -import static com.redhat.parodos.tasks.project.consts.ProjectAccessRequestConstant.NOTIFICATION_SUBJECT_ACCESS_REQUEST_ESCALATION; - /** * Project access request escalation workflow task * @@ -40,6 +36,12 @@ @Slf4j public class ProjectAccessRequestEscalationWorkFlowTask extends BaseWorkFlowTask { + private static final String ACCESS_REQUEST_ID = "ACCESS_REQUEST_ID"; + + private static final String ACCESS_REQUEST_ESCALATION_USERNAME = "ACCESS_REQUEST_ESCALATION_USERNAME"; + + private static final String NOTIFICATION_SUBJECT_ACCESS_REQUEST_ESCALATION = "Project Access Request Escalation"; + private final String serviceUrl; private final Notifier notifier;