Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch approval service #154

Open
wants to merge 8 commits into
base: feature-workflow-engine-simple
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@
<artifactId>org.wso2.carbon.humantask</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.workflow.engine</groupId>
<artifactId>workflow.engine</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +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_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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,55 @@
package org.wso2.carbon.identity.api.user.approval.common;

import org.wso2.carbon.humantask.core.TaskOperationService;
import org.wso2.carbon.identity.workflow.engine.SimpleWorkflowEngineApprovalService;

/**
* Service holder class for user approvals.
*/
public class UserApprovalServiceHolder {

private static TaskOperationService taskOperationService;
private static SimpleWorkflowEngineApprovalService simpleWorkflowEngineApprovalService;

/**
* Set TaskOperationService as OSGI service.
*
* @param taskOperationService taskOperationService.
*/
public static void setTaskOperationService(TaskOperationService taskOperationService) {

UserApprovalServiceHolder.taskOperationService = taskOperationService;
}

/**
* Set ApprovalEventService as OSGI service.
*
* @param simpleWorkflowEngineApprovalService approvalEventService.
*/
public static void setSimpleWorkflowEngineApprovalService(SimpleWorkflowEngineApprovalService simpleWorkflowEngineApprovalService) {

UserApprovalServiceHolder.simpleWorkflowEngineApprovalService = simpleWorkflowEngineApprovalService;
}

/**
* Get TaskOperationService osgi service.
*
* @return TaskOperationService
*/
public static TaskOperationService getTaskOperationService() {

return taskOperationService;
}

/**
* Get ApprovalEventService osgi service.
*
* @return ApprovalEventService
*/
public static SimpleWorkflowEngineApprovalService getSimpleWorkflowEngineApprovalService() {

return simpleWorkflowEngineApprovalService;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,17 @@ public Class<?> getObjectType() {
}

@Override
protected TaskOperationService createInstance() throws Exception {
protected TaskOperationService createInstance() throws RuntimeException {

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.");
throw new RuntimeException("Unable to retrieve TaskOperationService service.");
}
}
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.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<SimpleWorkflowEngineApprovalService> {

private SimpleWorkflowEngineApprovalService simpleWorkflowEngineApprovalService;

@Override
public Class<?> getObjectType() {

return Object.class;
}

@Override
protected SimpleWorkflowEngineApprovalService createInstance() throws RuntimeException {

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.simpleWorkflowEngineApprovalService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,9 @@
<artifactId>org.wso2.carbon.humantask.skeleton</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.workflow.engine</groupId>
<artifactId>workflow.engine</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment on lines -22 to -25
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if these imports can be removed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. no need.

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<String> status);
public abstract Response updateStateOfTask(String taskId,StateDTO nextState);
public abstract Response updateStateOfTask(String taskId, StateDTO nextState);
}

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -60,8 +60,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
Expand Down Expand Up @@ -113,6 +111,7 @@ public List<TaskSummaryDTO> listTasks(Integer limit, Integer offset, List<String

/**
* Get details of a task identified by the taskId
*
* @param taskId
* @return
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,83 @@
package org.wso2.carbon.identity.rest.api.user.approval.v1.impl;

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.rest.api.user.approval.v1.dto.StateDTO;
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.internal.dao.WorkflowEventRequestDAO;
import org.wso2.carbon.identity.workflow.engine.internal.dao.impl.WorkflowEventRequestDAOImpl;

import java.util.List;
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));

public MeApiServiceImpl() {

}
Comment on lines +47 to +49
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove if not needed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need it.


@Autowired
UserApprovalService userApprovalService;
public MeApiServiceImpl(SimpleWorkflowEngineApprovalService simpleWorkflowEngineApprovalService,
UserApprovalService userApprovalService) {

super();
this.simpleWorkflowEngineApprovalService = simpleWorkflowEngineApprovalService;
this.userApprovalService = userApprovalService;
}

@Override
public Response getApprovalTaskInfo(String taskId) {

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();
}

@Override
public Response listApprovalTasksForLoggedInUser(Integer limit, Integer offset, List<String> status) {

return Response.ok().entity(userApprovalService.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();
}
List<TaskSummaryDTO> BPELApprovalList = userApprovalService.listTasks(limit, offset, status);
List<org.wso2.carbon.identity.workflow.engine.dto.TaskSummaryDTO> simpleWorkflowEngineApprovalList =
simpleWorkflowEngineApprovalService.listTasks(limit, offset, status);
List<Object> allPendingList = Stream.concat(BPELApprovalList.stream(), simpleWorkflowEngineApprovalList.
stream()).collect(Collectors.toList());
return Response.ok().entity(allPendingList).build();
}

@Override
public Response updateStateOfTask(String taskId, StateDTO nextState) {

userApprovalService.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);
return Response.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@
-->

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
<bean class="org.wso2.carbon.identity.workflow.engine.SimpleWorkflowEngineApprovalService"/>
<bean class="org.wso2.carbon.identity.rest.api.user.approval.v1.core.UserApprovalService"/>
<bean class="org.wso2.carbon.identity.rest.api.user.approval.v1.impl.MeApiServiceImpl"/>
<bean id="UserApprovalServiceHolderBean" class="org.wso2.carbon.identity.api.user.approval.common.UserApprovalServiceHolder">
<property name="simpleWorkflowEngineApprovalService" ref="simpleWorkflowEngineApprovalServiceFactoryBean"/>
</bean>
<bean id="simpleWorkflowEngineApprovalServiceFactoryBean"
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"
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@
<artifactId>commons-lang</artifactId>
<version>${commons-lang.wso2.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.workflow.engine</groupId>
<artifactId>workflow.engine</artifactId>
<version>${workflow.engine.version}</version>
</dependency>

<!-- Kernel Dependencies-->
<dependency>
Expand Down Expand Up @@ -440,6 +445,7 @@
<maven.checkstyleplugin.excludes>**/gen/**/*</maven.checkstyleplugin.excludes>
<commons-lang.wso2.version>2.6.0.wso2v1</commons-lang.wso2.version>
<mavan.findbugsplugin.exclude.file>findbugs-exclude-filter.xml</mavan.findbugsplugin.exclude.file>
<workflow.engine.version>1.0-SNAPSHOT</workflow.engine.version>
</properties>

<modules>
Expand Down