Skip to content

Commit

Permalink
add new approval service
Browse files Browse the repository at this point in the history
  • Loading branch information
IsharaSilva committed Jul 26, 2022
1 parent 4553925 commit e7dc2ae
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,33 @@

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<ApprovalEventService> {
public class OSGIServiceFactory extends AbstractFactoryBean<TaskOperationService> {

private ApprovalEventService approvalEventService;
private TaskOperationService taskOperationService;

@Override
public Class<?> getObjectType() {
return Object.class;
}

@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;
}
}
Original file line number Diff line number Diff line change
@@ -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<ApprovalEventService> {

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@
<dependency>
<groupId>org.wso2.carbon.identity.workflow.engine</groupId>
<artifactId>workflow.engine</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
<property name="approvalEventService" ref="approvalEventServiceFactoryBean"/>
</bean>
<bean id="approvalEventServiceFactoryBean"
class="org.wso2.carbon.identity.api.user.approval.common.factory.OSGIServiceFactory"/>
<bean id="UserApprovalServiceHolderBean1" class="org.wso2.carbon.identity.api.user.approval.common.UserApprovalServiceHolder">
class="org.wso2.carbon.identity.api.user.approval.common.factory.OSGISimpleWorkflowEngineService"/>
<bean id="UserApprovalServiceBPELHolderBean" class="org.wso2.carbon.identity.api.user.approval.common.UserApprovalServiceHolder">
<property name="taskOperationService" ref="taskOperationServiceFactoryBean"/>
</bean>
<bean id="taskOperationServiceFactoryBean"
class="org.wso2.carbon.identity.api.user.approval.common.factory.OSGIBpelService"/>
class="org.wso2.carbon.identity.api.user.approval.common.factory.OSGIServiceFactory"/>
</beans>

0 comments on commit e7dc2ae

Please sign in to comment.