From 9f71095b633e6ead4f186b07c62e533eb62b8daa Mon Sep 17 00:00:00 2001 From: IsharaSilva Date: Mon, 20 Jun 2022 11:34:42 +0530 Subject: [PATCH 1/8] add new approval service --- .../approval/common/factory/OSGIServiceFactory.java | 3 +++ .../pom.xml | 5 +++++ .../user/approval/v1/core/UserApprovalService.java | 11 +++++++++-- .../api/user/approval/v1/impl/MeApiServiceImpl.java | 8 ++++++-- pom.xml | 5 +++++ 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGIServiceFactory.java b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGIServiceFactory.java index dc37df4a4..5eae3da52 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGIServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGIServiceFactory.java @@ -16,6 +16,9 @@ package org.wso2.carbon.identity.api.user.approval.common.factory; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.component.annotations.ReferenceCardinality; +import org.osgi.service.component.annotations.ReferencePolicy; import org.springframework.beans.factory.config.AbstractFactoryBean; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.humantask.core.TaskOperationService; diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/pom.xml b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/pom.xml index c4e3544b6..527c8db14 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/pom.xml @@ -170,5 +170,10 @@ org.wso2.carbon.humantask.skeleton provided + + org.wso2.carbon.identity.workflow.engine + workflow.engine + 1.0-SNAPSHOT + diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/core/UserApprovalService.java b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/core/UserApprovalService.java index 8b8ca3ae1..16149623f 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/core/UserApprovalService.java +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/core/UserApprovalService.java @@ -44,8 +44,10 @@ import org.wso2.carbon.identity.rest.api.user.approval.v1.dto.StateDTO; import org.wso2.carbon.identity.rest.api.user.approval.v1.dto.TaskDataDTO; import org.wso2.carbon.identity.rest.api.user.approval.v1.dto.TaskSummaryDTO; +import org.wso2.carbon.identity.workflow.engine.ApprovalEventService; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import javax.ws.rs.core.Response; @@ -60,8 +62,6 @@ import static org.wso2.carbon.identity.api.user.approval.common.ApprovalConstant.ErrorMessage.USER_ERROR_NON_EXISTING_TASK_ID; import static org.wso2.carbon.identity.api.user.approval.common.ApprovalConstant.ErrorMessage.USER_ERROR_NOT_ACCEPTABLE_INPUT_FOR_NEXT_STATE; import static org.wso2.carbon.identity.api.user.approval.common.ApprovalConstant.ErrorMessage.USER_ERROR_UNAUTHORIZED_USER; -import static org.wso2.carbon.identity.rest.api.user.approval.v1.dto.StateDTO.ActionEnum.APPROVE; -import static org.wso2.carbon.identity.rest.api.user.approval.v1.dto.StateDTO.ActionEnum.REJECT; /** * Call internal osgi services to perform user's approval task related operations @@ -109,10 +109,15 @@ public List listTasks(Integer limit, Integer offset, List taskSummaryDTOList=approvalEventService.listTasks(limit,offset,status); + + return Collections.singletonList((TaskSummaryDTO) taskSummaryDTOList);*/ } /** * Get details of a task identified by the taskId + * * @param taskId * @return */ @@ -144,6 +149,8 @@ public TaskDataDTO getTaskData(String taskId) { } catch (Exception e) { throw handleException(e, SERVER_ERROR_RETRIEVING_APPROVAL_OF_USER); } + /* ApprovalEventService approvalEventService=new ApprovalEventService(); + return approvalEventService.getTaskData(taskId);*/ } private URI getUri(String taskId) { diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java index ade491351..0b959fc30 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java @@ -20,6 +20,7 @@ import org.wso2.carbon.identity.rest.api.user.approval.v1.MeApiService; import org.wso2.carbon.identity.rest.api.user.approval.v1.core.UserApprovalService; import org.wso2.carbon.identity.rest.api.user.approval.v1.dto.StateDTO; +import org.wso2.carbon.identity.workflow.engine.ApprovalEventService; import java.util.List; import javax.ws.rs.core.Response; @@ -31,17 +32,20 @@ public class MeApiServiceImpl extends MeApiService { @Autowired UserApprovalService userApprovalService; + ApprovalEventService approvalEventService; @Override public Response getApprovalTaskInfo(String taskId) { - return Response.ok().entity(userApprovalService.getTaskData(taskId)).build(); + //return Response.ok().entity(userApprovalService.getTaskData(taskId)).build(); + return Response.ok().entity(approvalEventService.getTaskData(taskId)).build(); } @Override public Response listApprovalTasksForLoggedInUser(Integer limit, Integer offset, List status) { - return Response.ok().entity(userApprovalService.listTasks(limit, offset, status)).build(); + //return Response.ok().entity(userApprovalService.listTasks(limit, offset, status)).build(); + return Response.ok().entity(approvalEventService.listTasks(limit, offset, status)).build(); } @Override diff --git a/pom.xml b/pom.xml index 76a75631e..d8f5d66f4 100644 --- a/pom.xml +++ b/pom.xml @@ -311,6 +311,11 @@ commons-lang ${commons-lang.wso2.version} + + org.wso2.carbon.identity.workflow.engine + workflow.engine + 1.0-SNAPSHOT + From 850c4fa9810cd75d6a57a9c7706d65e26c573df3 Mon Sep 17 00:00:00 2001 From: IsharaSilva Date: Tue, 28 Jun 2022 11:44:14 +0530 Subject: [PATCH 2/8] add new approval service --- .../pom.xml | 4 +++ .../common/UserApprovalServiceHolder.java | 14 ++++++++++ .../common/factory/OSGIServiceFactory.java | 26 ++++++++----------- .../rest/api/user/approval/v1/MeApi.java | 21 +++++---------- .../api/user/approval/v1/MeApiService.java | 14 ++-------- .../approval/v1/core/UserApprovalService.java | 8 ------ .../approval/v1/impl/MeApiServiceImpl.java | 8 ++---- .../META-INF/cxf/user-approval-v1-cxf.xml | 4 +-- 8 files changed, 42 insertions(+), 57 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/pom.xml b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/pom.xml index dd4c87fc5..5e1e7f04b 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/pom.xml @@ -125,6 +125,10 @@ org.wso2.carbon.humantask provided + + org.wso2.carbon.identity.workflow.engine + workflow.engine + diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/UserApprovalServiceHolder.java b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/UserApprovalServiceHolder.java index 1ff85a87e..3df747a79 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/UserApprovalServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/UserApprovalServiceHolder.java @@ -17,6 +17,7 @@ package org.wso2.carbon.identity.api.user.approval.common; import org.wso2.carbon.humantask.core.TaskOperationService; +import org.wso2.carbon.identity.workflow.engine.ApprovalEventService; /** * Service holder class for user approvals. @@ -24,11 +25,18 @@ public class UserApprovalServiceHolder { private static TaskOperationService taskOperationService; + private static ApprovalEventService approvalEventService; public static void setTaskOperationService(TaskOperationService taskOperationService) { + UserApprovalServiceHolder.taskOperationService = taskOperationService; } + public static void setApprovalEventService(ApprovalEventService approvalEventService1) { + + UserApprovalServiceHolder.approvalEventService = approvalEventService1; + } + /** * Get TaskOperationService osgi service. * @@ -37,5 +45,11 @@ public static void setTaskOperationService(TaskOperationService taskOperationSer public static TaskOperationService getTaskOperationService() { return taskOperationService; } + + public static ApprovalEventService getApprovalEventService() { + + return approvalEventService; + } + } diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGIServiceFactory.java b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGIServiceFactory.java index 5eae3da52..292a13ada 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGIServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGIServiceFactory.java @@ -16,20 +16,17 @@ package org.wso2.carbon.identity.api.user.approval.common.factory; -import org.osgi.service.component.annotations.Reference; -import org.osgi.service.component.annotations.ReferenceCardinality; -import org.osgi.service.component.annotations.ReferencePolicy; import org.springframework.beans.factory.config.AbstractFactoryBean; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.humantask.core.TaskOperationService; +import org.wso2.carbon.identity.workflow.engine.ApprovalEventService; /** * Factory Beans serves as a factory for creating other beans within the IOC container. This factory bean is used to * instantiate the TaskOperationService type of object inside the container. */ -public class OSGIServiceFactory extends AbstractFactoryBean { +public class OSGIServiceFactory extends AbstractFactoryBean { - private TaskOperationService taskOperationService; + private ApprovalEventService approvalEventService; @Override public Class getObjectType() { @@ -37,18 +34,17 @@ public Class getObjectType() { } @Override - protected TaskOperationService createInstance() throws Exception { + protected ApprovalEventService createInstance() throws Exception { - if (this.taskOperationService == null) { - TaskOperationService taskOperationService = (TaskOperationService) PrivilegedCarbonContext. - getThreadLocalCarbonContext().getOSGiService(TaskOperationService.class, null); - if (taskOperationService != null) { - this.taskOperationService = taskOperationService; + if (this.approvalEventService == null) { + ApprovalEventService approvalEventService1 = (ApprovalEventService) PrivilegedCarbonContext. + getThreadLocalCarbonContext().getOSGiService(ApprovalEventService.class, null); + if (approvalEventService1 != null) { + this.approvalEventService = approvalEventService1; } else { - throw new Exception("Unable to retrieve TaskOperationService service."); + throw new Exception("Unable to retrieve ApprovalEvent service."); } } - return this.taskOperationService; + return this.approvalEventService; } - } diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/approval/v1/MeApi.java b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/approval/v1/MeApi.java index 4f9b0a7db..516a95f2c 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/approval/v1/MeApi.java +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/approval/v1/MeApi.java @@ -16,26 +16,19 @@ package org.wso2.carbon.identity.rest.api.user.approval.v1; -import org.springframework.beans.factory.annotation.Autowired; -import org.wso2.carbon.identity.rest.api.user.approval.v1.dto.*; -import org.wso2.carbon.identity.rest.api.user.approval.v1.MeApiService; -import org.wso2.carbon.identity.rest.api.user.approval.v1.factories.MeApiServiceFactory; - import io.swagger.annotations.ApiParam; - +import org.springframework.beans.factory.annotation.Autowired; import org.wso2.carbon.identity.rest.api.user.approval.v1.dto.TaskDataDTO; -import org.wso2.carbon.identity.rest.api.user.approval.v1.dto.ErrorDTO; import org.wso2.carbon.identity.rest.api.user.approval.v1.dto.TaskSummaryDTO; -import org.wso2.carbon.identity.rest.api.user.approval.v1.dto.StateDTO; +import org.wso2.carbon.identity.workflow.engine.dto.StateDTO; import java.util.List; - -import java.io.InputStream; -import org.apache.cxf.jaxrs.ext.multipart.Attachment; -import org.apache.cxf.jaxrs.ext.multipart.Multipart; - +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; -import javax.ws.rs.*; @Path("/me") diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/approval/v1/MeApiService.java b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/approval/v1/MeApiService.java index b6f6180b6..52bdfb2d6 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/approval/v1/MeApiService.java +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/approval/v1/MeApiService.java @@ -16,24 +16,14 @@ package org.wso2.carbon.identity.rest.api.user.approval.v1; -import org.wso2.carbon.identity.rest.api.user.approval.v1.*; -import org.wso2.carbon.identity.rest.api.user.approval.v1.dto.*; - -import org.wso2.carbon.identity.rest.api.user.approval.v1.dto.TaskDataDTO; -import org.wso2.carbon.identity.rest.api.user.approval.v1.dto.ErrorDTO; -import org.wso2.carbon.identity.rest.api.user.approval.v1.dto.TaskSummaryDTO; -import org.wso2.carbon.identity.rest.api.user.approval.v1.dto.StateDTO; +import org.wso2.carbon.identity.workflow.engine.dto.StateDTO; import java.util.List; - -import java.io.InputStream; -import org.apache.cxf.jaxrs.ext.multipart.Attachment; - import javax.ws.rs.core.Response; public abstract class MeApiService { public abstract Response getApprovalTaskInfo(String taskId); public abstract Response listApprovalTasksForLoggedInUser(Integer limit,Integer offset,List status); - public abstract Response updateStateOfTask(String taskId,StateDTO nextState); + public abstract Response updateStateOfTask(String taskId, StateDTO nextState); } diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/core/UserApprovalService.java b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/core/UserApprovalService.java index 16149623f..de1416196 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/core/UserApprovalService.java +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/core/UserApprovalService.java @@ -44,10 +44,8 @@ import org.wso2.carbon.identity.rest.api.user.approval.v1.dto.StateDTO; import org.wso2.carbon.identity.rest.api.user.approval.v1.dto.TaskDataDTO; import org.wso2.carbon.identity.rest.api.user.approval.v1.dto.TaskSummaryDTO; -import org.wso2.carbon.identity.workflow.engine.ApprovalEventService; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import javax.ws.rs.core.Response; @@ -109,10 +107,6 @@ public List listTasks(Integer limit, Integer offset, List taskSummaryDTOList=approvalEventService.listTasks(limit,offset,status); - - return Collections.singletonList((TaskSummaryDTO) taskSummaryDTOList);*/ } /** @@ -149,8 +143,6 @@ public TaskDataDTO getTaskData(String taskId) { } catch (Exception e) { throw handleException(e, SERVER_ERROR_RETRIEVING_APPROVAL_OF_USER); } - /* ApprovalEventService approvalEventService=new ApprovalEventService(); - return approvalEventService.getTaskData(taskId);*/ } private URI getUri(String taskId) { diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java index 0b959fc30..27cd676a9 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java @@ -18,9 +18,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.wso2.carbon.identity.rest.api.user.approval.v1.MeApiService; -import org.wso2.carbon.identity.rest.api.user.approval.v1.core.UserApprovalService; -import org.wso2.carbon.identity.rest.api.user.approval.v1.dto.StateDTO; import org.wso2.carbon.identity.workflow.engine.ApprovalEventService; +import org.wso2.carbon.identity.workflow.engine.dto.StateDTO; import java.util.List; import javax.ws.rs.core.Response; @@ -31,27 +30,24 @@ public class MeApiServiceImpl extends MeApiService { @Autowired - UserApprovalService userApprovalService; ApprovalEventService approvalEventService; @Override public Response getApprovalTaskInfo(String taskId) { - //return Response.ok().entity(userApprovalService.getTaskData(taskId)).build(); return Response.ok().entity(approvalEventService.getTaskData(taskId)).build(); } @Override public Response listApprovalTasksForLoggedInUser(Integer limit, Integer offset, List status) { - //return Response.ok().entity(userApprovalService.listTasks(limit, offset, status)).build(); return Response.ok().entity(approvalEventService.listTasks(limit, offset, status)).build(); } @Override public Response updateStateOfTask(String taskId, StateDTO nextState) { - userApprovalService.updateStatus(taskId, nextState); + approvalEventService.updateStatus(taskId, nextState ); return Response.ok().build(); } } diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/resources/META-INF/cxf/user-approval-v1-cxf.xml b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/resources/META-INF/cxf/user-approval-v1-cxf.xml index b99bf8dca..b5a929dd5 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/resources/META-INF/cxf/user-approval-v1-cxf.xml +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/resources/META-INF/cxf/user-approval-v1-cxf.xml @@ -16,10 +16,10 @@ --> - + - + From c0a8683bc1549130754e74fea4538e6b0177417c Mon Sep 17 00:00:00 2001 From: IsharaSilva Date: Fri, 22 Jul 2022 15:16:32 +0530 Subject: [PATCH 3/8] add new approval service --- .../common/factory/OSGIBpelService.java | 30 +++++++++++++ .../approval/v1/core/UserApprovalService.java | 2 +- .../approval/v1/impl/MeApiServiceImpl.java | 45 +++++++++++++++++-- .../META-INF/cxf/user-approval-v1-cxf.xml | 10 ++++- 4 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGIBpelService.java diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGIBpelService.java b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGIBpelService.java new file mode 100644 index 000000000..c6f144651 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGIBpelService.java @@ -0,0 +1,30 @@ +package org.wso2.carbon.identity.api.user.approval.common.factory; + +import org.springframework.beans.factory.config.AbstractFactoryBean; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.humantask.core.TaskOperationService; + +public class OSGIBpelService extends AbstractFactoryBean { + + private TaskOperationService taskOperationService; + + @Override + public Class getObjectType() { + return Object.class; + } + + @Override + protected TaskOperationService createInstance() throws Exception { + + if (this.taskOperationService == null) { + TaskOperationService taskOperationService = (TaskOperationService) PrivilegedCarbonContext. + getThreadLocalCarbonContext().getOSGiService(TaskOperationService.class, null); + if (taskOperationService != null) { + this.taskOperationService = taskOperationService; + } else { + throw new Exception("Unable to retrieve TaskOperationService service."); + } + } + return this.taskOperationService; + } +} diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/core/UserApprovalService.java b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/core/UserApprovalService.java index de1416196..b0dff6c8e 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/core/UserApprovalService.java +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/core/UserApprovalService.java @@ -41,9 +41,9 @@ import org.wso2.carbon.identity.rest.api.user.approval.v1.core.functions.TTaskSimpleQueryResultRowToExternal; import org.wso2.carbon.identity.rest.api.user.approval.v1.core.functions.TaskModelToExternal; import org.wso2.carbon.identity.rest.api.user.approval.v1.core.model.TaskModel; -import org.wso2.carbon.identity.rest.api.user.approval.v1.dto.StateDTO; import org.wso2.carbon.identity.rest.api.user.approval.v1.dto.TaskDataDTO; import org.wso2.carbon.identity.rest.api.user.approval.v1.dto.TaskSummaryDTO; +import org.wso2.carbon.identity.workflow.engine.dto.StateDTO; import java.util.Arrays; import java.util.List; diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java index 27cd676a9..50836882e 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java @@ -16,8 +16,11 @@ package org.wso2.carbon.identity.rest.api.user.approval.v1.impl; +import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.wso2.carbon.identity.core.util.IdentityUtil; import org.wso2.carbon.identity.rest.api.user.approval.v1.MeApiService; +import org.wso2.carbon.identity.rest.api.user.approval.v1.core.UserApprovalService; import org.wso2.carbon.identity.workflow.engine.ApprovalEventService; import org.wso2.carbon.identity.workflow.engine.dto.StateDTO; @@ -29,25 +32,59 @@ */ public class MeApiServiceImpl extends MeApiService { + private ApprovalEventService approvalEventService; + private UserApprovalService userApprovalService; + private static boolean simpleWorkflow; + public static final String SIMPLE_WORKFLOW_ENGINE = "Workflow.SimpleWorkflow.Enable"; + String enableSimpleWorkflowEngine = IdentityUtil.getProperty(SIMPLE_WORKFLOW_ENGINE); + + public MeApiServiceImpl() { + + } + @Autowired - ApprovalEventService approvalEventService; + public MeApiServiceImpl(ApprovalEventService approvalEventService, UserApprovalService userApprovalService) { + + super(); + this.approvalEventService = approvalEventService; + this.userApprovalService = userApprovalService; + } @Override public Response getApprovalTaskInfo(String taskId) { - return Response.ok().entity(approvalEventService.getTaskData(taskId)).build(); + if (StringUtils.isNotBlank(enableSimpleWorkflowEngine)) { + simpleWorkflow = Boolean.parseBoolean(enableSimpleWorkflowEngine); + } + if (simpleWorkflow == true) { + return Response.ok().entity(approvalEventService.getTaskData(taskId)).build(); + } + return Response.ok().entity(userApprovalService.getTaskData(taskId)).build(); } @Override public Response listApprovalTasksForLoggedInUser(Integer limit, Integer offset, List status) { - return Response.ok().entity(approvalEventService.listTasks(limit, offset, status)).build(); + if (StringUtils.isNotBlank(enableSimpleWorkflowEngine)) { + simpleWorkflow = Boolean.parseBoolean(enableSimpleWorkflowEngine); + } + if (simpleWorkflow == true) { + return Response.ok().entity(approvalEventService.listTasks(limit, offset, status)).build(); + } + return Response.ok().entity(userApprovalService.listTasks(limit, offset, status)).build(); } @Override public Response updateStateOfTask(String taskId, StateDTO nextState) { - approvalEventService.updateStatus(taskId, nextState ); + if (StringUtils.isNotBlank(enableSimpleWorkflowEngine)) { + simpleWorkflow = Boolean.parseBoolean(enableSimpleWorkflowEngine); + } + if (simpleWorkflow == true) { + approvalEventService.updateStatus(taskId, nextState ); + return Response.ok().build(); + } + new UserApprovalService().updateStatus(taskId, nextState); return Response.ok().build(); } } diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/resources/META-INF/cxf/user-approval-v1-cxf.xml b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/resources/META-INF/cxf/user-approval-v1-cxf.xml index b5a929dd5..b910a7a0f 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/resources/META-INF/cxf/user-approval-v1-cxf.xml +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/resources/META-INF/cxf/user-approval-v1-cxf.xml @@ -17,10 +17,16 @@ + - + - + + + + From 45539252fd0edbaad62aec1066e77609ade830fc Mon Sep 17 00:00:00 2001 From: IsharaSilva Date: Mon, 25 Jul 2022 18:34:04 +0530 Subject: [PATCH 4/8] add new approval service --- .../approval/v1/impl/MeApiServiceImpl.java | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java index 50836882e..8205ee536 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java @@ -34,9 +34,8 @@ public class MeApiServiceImpl extends MeApiService { private ApprovalEventService approvalEventService; private UserApprovalService userApprovalService; - private static boolean simpleWorkflow; public static final String SIMPLE_WORKFLOW_ENGINE = "Workflow.SimpleWorkflow.Enable"; - String enableSimpleWorkflowEngine = IdentityUtil.getProperty(SIMPLE_WORKFLOW_ENGINE); + private static boolean enableSimpleWorkflowEngine = Boolean.parseBoolean(IdentityUtil.getProperty(SIMPLE_WORKFLOW_ENGINE)); public MeApiServiceImpl() { @@ -53,10 +52,7 @@ public MeApiServiceImpl(ApprovalEventService approvalEventService, UserApprovalS @Override public Response getApprovalTaskInfo(String taskId) { - if (StringUtils.isNotBlank(enableSimpleWorkflowEngine)) { - simpleWorkflow = Boolean.parseBoolean(enableSimpleWorkflowEngine); - } - if (simpleWorkflow == true) { + if (enableSimpleWorkflowEngine) { return Response.ok().entity(approvalEventService.getTaskData(taskId)).build(); } return Response.ok().entity(userApprovalService.getTaskData(taskId)).build(); @@ -65,10 +61,7 @@ public Response getApprovalTaskInfo(String taskId) { @Override public Response listApprovalTasksForLoggedInUser(Integer limit, Integer offset, List status) { - if (StringUtils.isNotBlank(enableSimpleWorkflowEngine)) { - simpleWorkflow = Boolean.parseBoolean(enableSimpleWorkflowEngine); - } - if (simpleWorkflow == true) { + if (enableSimpleWorkflowEngine) { return Response.ok().entity(approvalEventService.listTasks(limit, offset, status)).build(); } return Response.ok().entity(userApprovalService.listTasks(limit, offset, status)).build(); @@ -77,10 +70,7 @@ public Response listApprovalTasksForLoggedInUser(Integer limit, Integer offset, @Override public Response updateStateOfTask(String taskId, StateDTO nextState) { - if (StringUtils.isNotBlank(enableSimpleWorkflowEngine)) { - simpleWorkflow = Boolean.parseBoolean(enableSimpleWorkflowEngine); - } - if (simpleWorkflow == true) { + if (enableSimpleWorkflowEngine) { approvalEventService.updateStatus(taskId, nextState ); return Response.ok().build(); } From e7dc2ae0d29fe0137b37397251c8596a67ec212a Mon Sep 17 00:00:00 2001 From: IsharaSilva Date: Tue, 26 Jul 2022 15:03:12 +0530 Subject: [PATCH 5/8] add new approval service --- .../approval/common/ApprovalConstant.java | 1 + .../common/UserApprovalServiceHolder.java | 20 ++++++- .../common/factory/OSGIBpelService.java | 30 ----------- .../common/factory/OSGIServiceFactory.java | 22 ++++---- .../OSGISimpleWorkflowEngineService.java | 53 +++++++++++++++++++ .../pom.xml | 1 - .../approval/v1/impl/MeApiServiceImpl.java | 6 +-- .../META-INF/cxf/user-approval-v1-cxf.xml | 6 +-- 8 files changed, 89 insertions(+), 50 deletions(-) delete mode 100644 components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGIBpelService.java create mode 100644 components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGISimpleWorkflowEngineService.java diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/ApprovalConstant.java b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/ApprovalConstant.java index 0bb8532ab..a4b9966c3 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/ApprovalConstant.java +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/ApprovalConstant.java @@ -25,6 +25,7 @@ public class ApprovalConstant { public static final String USER_APPROVAL_TASK_PATH_COMPONENT = "/%s/approval-tasks"; public static final String V1_API_PATH_COMPONENT = "/v1"; public static final String ME_CONTEXT = "me"; + public static final String SIMPLE_WORKFLOW_ENGINE = "Workflow.SimpleWorkflow.Enable"; /** * Enum for user's pending approval related errors in the format of diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/UserApprovalServiceHolder.java b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/UserApprovalServiceHolder.java index 3df747a79..21aa6940f 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/UserApprovalServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/UserApprovalServiceHolder.java @@ -27,14 +27,24 @@ public class UserApprovalServiceHolder { private static TaskOperationService taskOperationService; private static ApprovalEventService approvalEventService; + /** + * Set TaskOperationService as OSGI service. + * + * @param taskOperationService taskOperationService. + */ public static void setTaskOperationService(TaskOperationService taskOperationService) { UserApprovalServiceHolder.taskOperationService = taskOperationService; } - public static void setApprovalEventService(ApprovalEventService approvalEventService1) { + /** + * Set ApprovalEventService as OSGI service. + * + * @param approvalEventService approvalEventService. + */ + public static void setApprovalEventService(ApprovalEventService approvalEventService) { - UserApprovalServiceHolder.approvalEventService = approvalEventService1; + UserApprovalServiceHolder.approvalEventService = approvalEventService; } /** @@ -43,9 +53,15 @@ public static void setApprovalEventService(ApprovalEventService approvalEventSer * @return TaskOperationService */ public static TaskOperationService getTaskOperationService() { + return taskOperationService; } + /** + * Get ApprovalEventService osgi service. + * + * @return ApprovalEventService + */ public static ApprovalEventService getApprovalEventService() { return approvalEventService; diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGIBpelService.java b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGIBpelService.java deleted file mode 100644 index c6f144651..000000000 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGIBpelService.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.wso2.carbon.identity.api.user.approval.common.factory; - -import org.springframework.beans.factory.config.AbstractFactoryBean; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.humantask.core.TaskOperationService; - -public class OSGIBpelService extends AbstractFactoryBean { - - private TaskOperationService taskOperationService; - - @Override - public Class getObjectType() { - return Object.class; - } - - @Override - protected TaskOperationService createInstance() throws Exception { - - if (this.taskOperationService == null) { - TaskOperationService taskOperationService = (TaskOperationService) PrivilegedCarbonContext. - getThreadLocalCarbonContext().getOSGiService(TaskOperationService.class, null); - if (taskOperationService != null) { - this.taskOperationService = taskOperationService; - } else { - throw new Exception("Unable to retrieve TaskOperationService service."); - } - } - return this.taskOperationService; - } -} diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGIServiceFactory.java b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGIServiceFactory.java index 292a13ada..9e43bdbce 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGIServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGIServiceFactory.java @@ -18,15 +18,15 @@ import org.springframework.beans.factory.config.AbstractFactoryBean; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.identity.workflow.engine.ApprovalEventService; +import org.wso2.carbon.humantask.core.TaskOperationService; /** * Factory Beans serves as a factory for creating other beans within the IOC container. This factory bean is used to * instantiate the TaskOperationService type of object inside the container. */ -public class OSGIServiceFactory extends AbstractFactoryBean { +public class OSGIServiceFactory extends AbstractFactoryBean { - private ApprovalEventService approvalEventService; + private TaskOperationService taskOperationService; @Override public Class getObjectType() { @@ -34,17 +34,17 @@ public Class getObjectType() { } @Override - protected ApprovalEventService createInstance() throws Exception { + protected TaskOperationService createInstance() throws RuntimeException { - if (this.approvalEventService == null) { - ApprovalEventService approvalEventService1 = (ApprovalEventService) PrivilegedCarbonContext. - getThreadLocalCarbonContext().getOSGiService(ApprovalEventService.class, null); - if (approvalEventService1 != null) { - this.approvalEventService = approvalEventService1; + if (this.taskOperationService == null) { + TaskOperationService taskOperationService = (TaskOperationService) PrivilegedCarbonContext. + getThreadLocalCarbonContext().getOSGiService(TaskOperationService.class, null); + if (taskOperationService != null) { + this.taskOperationService = taskOperationService; } else { - throw new Exception("Unable to retrieve ApprovalEvent service."); + throw new RuntimeException("Unable to retrieve TaskOperationService service."); } } - return this.approvalEventService; + return this.taskOperationService; } } diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGISimpleWorkflowEngineService.java b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGISimpleWorkflowEngineService.java new file mode 100644 index 000000000..41949193c --- /dev/null +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGISimpleWorkflowEngineService.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2022, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.api.user.approval.common.factory; + +import org.springframework.beans.factory.config.AbstractFactoryBean; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.identity.workflow.engine.ApprovalEventService; + +/** + * Factory Beans serves as a factory for creating other beans within the IOC container. This factory bean is used to + * instantiate the ApprovalEventService type of object inside the container. + */ +public class OSGISimpleWorkflowEngineService extends AbstractFactoryBean { + + private ApprovalEventService approvalEventService; + + @Override + public Class getObjectType() { + + return Object.class; + } + + @Override + protected ApprovalEventService createInstance() throws RuntimeException { + + if (this.approvalEventService == null) { + ApprovalEventService approvalEventService = (ApprovalEventService) PrivilegedCarbonContext. + getThreadLocalCarbonContext().getOSGiService(ApprovalEventService.class, null); + if (approvalEventService != null) { + this.approvalEventService = approvalEventService; + } else { + throw new RuntimeException("Unable to retrieve ApprovalEvent service."); + } + } + return this.approvalEventService; + } +} diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/pom.xml b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/pom.xml index 527c8db14..66b47df18 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/pom.xml @@ -173,7 +173,6 @@ org.wso2.carbon.identity.workflow.engine workflow.engine - 1.0-SNAPSHOT diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java index 8205ee536..bc42caabe 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java @@ -16,8 +16,8 @@ package org.wso2.carbon.identity.rest.api.user.approval.v1.impl; -import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.wso2.carbon.identity.api.user.approval.common.ApprovalConstant; import org.wso2.carbon.identity.core.util.IdentityUtil; import org.wso2.carbon.identity.rest.api.user.approval.v1.MeApiService; import org.wso2.carbon.identity.rest.api.user.approval.v1.core.UserApprovalService; @@ -34,8 +34,8 @@ public class MeApiServiceImpl extends MeApiService { private ApprovalEventService approvalEventService; private UserApprovalService userApprovalService; - public static final String SIMPLE_WORKFLOW_ENGINE = "Workflow.SimpleWorkflow.Enable"; - private static boolean enableSimpleWorkflowEngine = Boolean.parseBoolean(IdentityUtil.getProperty(SIMPLE_WORKFLOW_ENGINE)); + private static boolean enableSimpleWorkflowEngine = Boolean.parseBoolean(IdentityUtil.getProperty( + ApprovalConstant.SIMPLE_WORKFLOW_ENGINE)); public MeApiServiceImpl() { diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/resources/META-INF/cxf/user-approval-v1-cxf.xml b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/resources/META-INF/cxf/user-approval-v1-cxf.xml index b910a7a0f..7faaa2385 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/resources/META-INF/cxf/user-approval-v1-cxf.xml +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/resources/META-INF/cxf/user-approval-v1-cxf.xml @@ -23,10 +23,10 @@ - + class="org.wso2.carbon.identity.api.user.approval.common.factory.OSGISimpleWorkflowEngineService"/> + + class="org.wso2.carbon.identity.api.user.approval.common.factory.OSGIServiceFactory"/> From b89af137d560446151732000630311dcb4cb9b41 Mon Sep 17 00:00:00 2001 From: IsharaSilva Date: Tue, 26 Jul 2022 15:10:10 +0530 Subject: [PATCH 6/8] add new approval service --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d8f5d66f4..5c6cbf02d 100644 --- a/pom.xml +++ b/pom.xml @@ -314,7 +314,7 @@ org.wso2.carbon.identity.workflow.engine workflow.engine - 1.0-SNAPSHOT + ${workflow.engine.version} @@ -445,6 +445,7 @@ **/gen/**/* 2.6.0.wso2v1 findbugs-exclude-filter.xml + 1.0-SNAPSHOT From 52008daaedea131fdb9c1d71778fdba5cb007dab Mon Sep 17 00:00:00 2001 From: IsharaSilva Date: Thu, 28 Jul 2022 21:46:42 +0530 Subject: [PATCH 7/8] add new approval service --- .../approval/common/ApprovalConstant.java | 3 +- .../common/UserApprovalServiceHolder.java | 14 +++--- .../OSGISimpleWorkflowEngineService.java | 20 ++++---- .../approval/v1/impl/MeApiServiceImpl.java | 48 ++++++++++++++----- .../META-INF/cxf/user-approval-v1-cxf.xml | 6 +-- 5 files changed, 57 insertions(+), 34 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/ApprovalConstant.java b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/ApprovalConstant.java index a4b9966c3..c51d6d25c 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/ApprovalConstant.java +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/ApprovalConstant.java @@ -25,7 +25,8 @@ public class ApprovalConstant { public static final String USER_APPROVAL_TASK_PATH_COMPONENT = "/%s/approval-tasks"; public static final String V1_API_PATH_COMPONENT = "/v1"; public static final String ME_CONTEXT = "me"; - public static final String SIMPLE_WORKFLOW_ENGINE = "Workflow.SimpleWorkflow.Enable"; + public static final String SIMPLE_WORKFLOW_ENGINE_APPROVALS = "WorkflowEngines.SimpleWorkflowEngine.AllowApprovals"; + public static final String BPEL_ENGINE_APPROVALS = "WorkflowEngines.BPELEngine.AllowApprovals"; /** * Enum for user's pending approval related errors in the format of diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/UserApprovalServiceHolder.java b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/UserApprovalServiceHolder.java index 21aa6940f..01a17a932 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/UserApprovalServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/UserApprovalServiceHolder.java @@ -17,7 +17,7 @@ package org.wso2.carbon.identity.api.user.approval.common; import org.wso2.carbon.humantask.core.TaskOperationService; -import org.wso2.carbon.identity.workflow.engine.ApprovalEventService; +import org.wso2.carbon.identity.workflow.engine.SimpleWorkflowEngineApprovalService; /** * Service holder class for user approvals. @@ -25,7 +25,7 @@ public class UserApprovalServiceHolder { private static TaskOperationService taskOperationService; - private static ApprovalEventService approvalEventService; + private static SimpleWorkflowEngineApprovalService simpleWorkflowEngineApprovalService; /** * Set TaskOperationService as OSGI service. @@ -40,11 +40,11 @@ public static void setTaskOperationService(TaskOperationService taskOperationSer /** * Set ApprovalEventService as OSGI service. * - * @param approvalEventService approvalEventService. + * @param simpleWorkflowEngineApprovalService approvalEventService. */ - public static void setApprovalEventService(ApprovalEventService approvalEventService) { + public static void setSimpleWorkflowEngineApprovalService(SimpleWorkflowEngineApprovalService simpleWorkflowEngineApprovalService) { - UserApprovalServiceHolder.approvalEventService = approvalEventService; + UserApprovalServiceHolder.simpleWorkflowEngineApprovalService = simpleWorkflowEngineApprovalService; } /** @@ -62,9 +62,9 @@ public static TaskOperationService getTaskOperationService() { * * @return ApprovalEventService */ - public static ApprovalEventService getApprovalEventService() { + public static SimpleWorkflowEngineApprovalService getSimpleWorkflowEngineApprovalService() { - return approvalEventService; + return simpleWorkflowEngineApprovalService; } } diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGISimpleWorkflowEngineService.java b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGISimpleWorkflowEngineService.java index 41949193c..3da9dc76d 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGISimpleWorkflowEngineService.java +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.api.user.approval.common/src/main/java/org/wso2/carbon/identity/api/user/approval/common/factory/OSGISimpleWorkflowEngineService.java @@ -20,15 +20,15 @@ import org.springframework.beans.factory.config.AbstractFactoryBean; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.identity.workflow.engine.ApprovalEventService; +import org.wso2.carbon.identity.workflow.engine.SimpleWorkflowEngineApprovalService; /** * Factory Beans serves as a factory for creating other beans within the IOC container. This factory bean is used to * instantiate the ApprovalEventService type of object inside the container. */ -public class OSGISimpleWorkflowEngineService extends AbstractFactoryBean { +public class OSGISimpleWorkflowEngineService extends AbstractFactoryBean { - private ApprovalEventService approvalEventService; + private SimpleWorkflowEngineApprovalService simpleWorkflowEngineApprovalService; @Override public Class getObjectType() { @@ -37,17 +37,17 @@ public Class getObjectType() { } @Override - protected ApprovalEventService createInstance() throws RuntimeException { + protected SimpleWorkflowEngineApprovalService createInstance() throws RuntimeException { - if (this.approvalEventService == null) { - ApprovalEventService approvalEventService = (ApprovalEventService) PrivilegedCarbonContext. - getThreadLocalCarbonContext().getOSGiService(ApprovalEventService.class, null); - if (approvalEventService != null) { - this.approvalEventService = approvalEventService; + if (this.simpleWorkflowEngineApprovalService == null) { + SimpleWorkflowEngineApprovalService simpleWorkflowEngineApprovalService = (SimpleWorkflowEngineApprovalService) PrivilegedCarbonContext. + getThreadLocalCarbonContext().getOSGiService(SimpleWorkflowEngineApprovalService.class, null); + if (simpleWorkflowEngineApprovalService != null) { + this.simpleWorkflowEngineApprovalService = simpleWorkflowEngineApprovalService; } else { throw new RuntimeException("Unable to retrieve ApprovalEvent service."); } } - return this.approvalEventService; + return this.simpleWorkflowEngineApprovalService; } } diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java index bc42caabe..06fa479d5 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java @@ -16,15 +16,26 @@ package org.wso2.carbon.identity.rest.api.user.approval.v1.impl; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.wso2.carbon.identity.api.user.approval.common.ApprovalConstant; import org.wso2.carbon.identity.core.util.IdentityUtil; import org.wso2.carbon.identity.rest.api.user.approval.v1.MeApiService; import org.wso2.carbon.identity.rest.api.user.approval.v1.core.UserApprovalService; -import org.wso2.carbon.identity.workflow.engine.ApprovalEventService; +import org.wso2.carbon.identity.rest.api.user.approval.v1.dto.TaskSummaryDTO; +import org.wso2.carbon.identity.workflow.engine.SimpleWorkflowEngineApprovalService; import org.wso2.carbon.identity.workflow.engine.dto.StateDTO; +import org.wso2.carbon.identity.workflow.engine.dto.TaskDataDTO; +import org.wso2.carbon.identity.workflow.engine.internal.dao.WorkflowEventRequestDAO; +import org.wso2.carbon.identity.workflow.engine.internal.dao.impl.WorkflowEventRequestDAOImpl; +import org.wso2.carbon.identity.workflow.mgt.bean.Workflow; +import org.wso2.carbon.identity.workflow.mgt.dao.WorkflowDAO; import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.ws.rs.core.Response; /** @@ -32,28 +43,30 @@ */ public class MeApiServiceImpl extends MeApiService { - private ApprovalEventService approvalEventService; + private SimpleWorkflowEngineApprovalService simpleWorkflowEngineApprovalService; private UserApprovalService userApprovalService; - private static boolean enableSimpleWorkflowEngine = Boolean.parseBoolean(IdentityUtil.getProperty( - ApprovalConstant.SIMPLE_WORKFLOW_ENGINE)); + private static boolean enableApprovalsFromSimpleWorkflowEngine = Boolean.parseBoolean(IdentityUtil.getProperty(ApprovalConstant.SIMPLE_WORKFLOW_ENGINE_APPROVALS)); + private static boolean enableApprovalsFromBPEL = Boolean.parseBoolean(IdentityUtil.getProperty(ApprovalConstant.BPEL_ENGINE_APPROVALS)); public MeApiServiceImpl() { } @Autowired - public MeApiServiceImpl(ApprovalEventService approvalEventService, UserApprovalService userApprovalService) { + public MeApiServiceImpl(SimpleWorkflowEngineApprovalService simpleWorkflowEngineApprovalService, UserApprovalService userApprovalService) { super(); - this.approvalEventService = approvalEventService; + this.simpleWorkflowEngineApprovalService = simpleWorkflowEngineApprovalService; this.userApprovalService = userApprovalService; } @Override public Response getApprovalTaskInfo(String taskId) { - if (enableSimpleWorkflowEngine) { - return Response.ok().entity(approvalEventService.getTaskData(taskId)).build(); + WorkflowEventRequestDAO workflowEventRequestDAO = new WorkflowEventRequestDAOImpl(); + String taskDataDTO = workflowEventRequestDAO.getTask(taskId); + if (taskDataDTO != null) { + return Response.ok().entity(simpleWorkflowEngineApprovalService.getTaskData(taskId)).build(); } return Response.ok().entity(userApprovalService.getTaskData(taskId)).build(); } @@ -61,17 +74,26 @@ public Response getApprovalTaskInfo(String taskId) { @Override public Response listApprovalTasksForLoggedInUser(Integer limit, Integer offset, List status) { - if (enableSimpleWorkflowEngine) { - return Response.ok().entity(approvalEventService.listTasks(limit, offset, status)).build(); + if (enableApprovalsFromSimpleWorkflowEngine && !enableApprovalsFromBPEL) { + return Response.ok().entity(simpleWorkflowEngineApprovalService.listTasks(limit, offset, status)).build(); + } else if (enableApprovalsFromBPEL && !enableApprovalsFromSimpleWorkflowEngine) { + return Response.ok().entity(userApprovalService.listTasks(limit, offset, status)).build(); } - return Response.ok().entity(userApprovalService.listTasks(limit, offset, status)).build(); + List BPELApprovalList = userApprovalService.listTasks(limit, offset, status); + List simpleWorkflowEngineApprovalList = + simpleWorkflowEngineApprovalService.listTasks(limit, offset, status); + List allPendingList = Stream.concat(BPELApprovalList.stream(), simpleWorkflowEngineApprovalList. + stream()).collect(Collectors.toList()); + return Response.ok().entity(allPendingList).build(); } @Override public Response updateStateOfTask(String taskId, StateDTO nextState) { - if (enableSimpleWorkflowEngine) { - approvalEventService.updateStatus(taskId, nextState ); + WorkflowEventRequestDAO workflowEventRequestDAO = new WorkflowEventRequestDAOImpl(); + String taskDataDTO = workflowEventRequestDAO.getTask(taskId); + if (taskDataDTO != null) { + simpleWorkflowEngineApprovalService.updateStatus(taskId, nextState); return Response.ok().build(); } new UserApprovalService().updateStatus(taskId, nextState); diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/resources/META-INF/cxf/user-approval-v1-cxf.xml b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/resources/META-INF/cxf/user-approval-v1-cxf.xml index 7faaa2385..9575a953d 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/resources/META-INF/cxf/user-approval-v1-cxf.xml +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/resources/META-INF/cxf/user-approval-v1-cxf.xml @@ -16,13 +16,13 @@ --> - + - + - From 4de9b563a509bd4fb32c5041c380369c8da73264 Mon Sep 17 00:00:00 2001 From: IsharaSilva Date: Fri, 29 Jul 2022 03:26:22 +0530 Subject: [PATCH 8/8] add new approval service --- .../user/approval/v1/impl/MeApiServiceImpl.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java index 06fa479d5..50e93672c 100644 --- a/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.user.approval/org.wso2.carbon.identity.rest.api.user.approval.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/approval/v1/impl/MeApiServiceImpl.java @@ -16,8 +16,6 @@ package org.wso2.carbon.identity.rest.api.user.approval.v1.impl; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.wso2.carbon.identity.api.user.approval.common.ApprovalConstant; import org.wso2.carbon.identity.core.util.IdentityUtil; @@ -26,34 +24,33 @@ import org.wso2.carbon.identity.rest.api.user.approval.v1.dto.TaskSummaryDTO; import org.wso2.carbon.identity.workflow.engine.SimpleWorkflowEngineApprovalService; import org.wso2.carbon.identity.workflow.engine.dto.StateDTO; -import org.wso2.carbon.identity.workflow.engine.dto.TaskDataDTO; import org.wso2.carbon.identity.workflow.engine.internal.dao.WorkflowEventRequestDAO; import org.wso2.carbon.identity.workflow.engine.internal.dao.impl.WorkflowEventRequestDAOImpl; -import org.wso2.carbon.identity.workflow.mgt.bean.Workflow; -import org.wso2.carbon.identity.workflow.mgt.dao.WorkflowDAO; import java.util.List; -import java.util.Objects; import java.util.stream.Collectors; import java.util.stream.Stream; import javax.ws.rs.core.Response; /** - * API service implementation of a logged in user's approval operations + * API service implementation of a logged-in user's approval operations */ public class MeApiServiceImpl extends MeApiService { private SimpleWorkflowEngineApprovalService simpleWorkflowEngineApprovalService; private UserApprovalService userApprovalService; - private static boolean enableApprovalsFromSimpleWorkflowEngine = Boolean.parseBoolean(IdentityUtil.getProperty(ApprovalConstant.SIMPLE_WORKFLOW_ENGINE_APPROVALS)); - private static boolean enableApprovalsFromBPEL = Boolean.parseBoolean(IdentityUtil.getProperty(ApprovalConstant.BPEL_ENGINE_APPROVALS)); + private static boolean enableApprovalsFromSimpleWorkflowEngine = Boolean.parseBoolean(IdentityUtil.getProperty( + ApprovalConstant.SIMPLE_WORKFLOW_ENGINE_APPROVALS)); + private static boolean enableApprovalsFromBPEL = Boolean.parseBoolean(IdentityUtil.getProperty( + ApprovalConstant.BPEL_ENGINE_APPROVALS)); public MeApiServiceImpl() { } @Autowired - public MeApiServiceImpl(SimpleWorkflowEngineApprovalService simpleWorkflowEngineApprovalService, UserApprovalService userApprovalService) { + public MeApiServiceImpl(SimpleWorkflowEngineApprovalService simpleWorkflowEngineApprovalService, + UserApprovalService userApprovalService) { super(); this.simpleWorkflowEngineApprovalService = simpleWorkflowEngineApprovalService;