From e7dc2ae0d29fe0137b37397251c8596a67ec212a Mon Sep 17 00:00:00 2001 From: IsharaSilva Date: Tue, 26 Jul 2022 15:03:12 +0530 Subject: [PATCH] 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"/>