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 4 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 @@ -17,18 +17,26 @@
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.
*/
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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

add method comments to public methods. Fix other places as well.

Copy link
Author

Choose a reason for hiding this comment

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

Addressed with this commit e7dc2ae

Copy link
Author

Choose a reason for hiding this comment

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

switch variable name

Copy link
Author

Choose a reason for hiding this comment

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

Addressed with this commit e7dc2ae


UserApprovalServiceHolder.approvalEventService = approvalEventService1;
}

/**
* Get TaskOperationService osgi service.
*
Expand All @@ -37,5 +45,11 @@ public static void setTaskOperationService(TaskOperationService taskOperationSer
public static TaskOperationService getTaskOperationService() {
return taskOperationService;
}

public static ApprovalEventService getApprovalEventService() {

return approvalEventService;
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.wso2.carbon.identity.api.user.approval.common.factory;
Copy link
Author

Choose a reason for hiding this comment

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

add license header

Copy link
Author

Choose a reason for hiding this comment

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

Addressed with this commit e7dc2ae


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<TaskOperationService> {
Copy link
Author

Choose a reason for hiding this comment

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

add class comment

Copy link
Author

Choose a reason for hiding this comment

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

Addressed with this commit e7dc2ae


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.");
Copy link
Author

Choose a reason for hiding this comment

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

change into run time exception

Copy link
Author

Choose a reason for hiding this comment

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

Addressed with this commit e7dc2ae

}
}
return this.taskOperationService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,33 @@

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

Choose a reason for hiding this comment

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

keep this class as it is and add a new class as a OSGI service

Copy link
Author

Choose a reason for hiding this comment

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

Addressed with this commit e7dc2ae


private TaskOperationService taskOperationService;
private ApprovalEventService approvalEventService;

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

@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.
Copy link
Author

Choose a reason for hiding this comment

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

fix variable name

Copy link
Author

Choose a reason for hiding this comment

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

Addressed with this commit e7dc2ae

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.");
Copy link
Author

Choose a reason for hiding this comment

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

add run time exception

Copy link
Author

Choose a reason for hiding this comment

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

Addressed with this commit e7dc2ae

}
}
return this.taskOperationService;
return this.approvalEventService;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,10 @@
<artifactId>org.wso2.carbon.humantask.skeleton</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.workflow.engine</groupId>
<artifactId>workflow.engine</artifactId>
<version>1.0-SNAPSHOT</version>
Copy link
Author

Choose a reason for hiding this comment

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

add the dependency to the root pom and get the version from property

Copy link
Author

Choose a reason for hiding this comment

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

Addressed with this commit e7dc2ae

</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 @@ -16,10 +16,13 @@

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.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;
Expand All @@ -29,25 +32,49 @@
*/
public class MeApiServiceImpl extends MeApiService {

private ApprovalEventService approvalEventService;
private UserApprovalService userApprovalService;
public static final String SIMPLE_WORKFLOW_ENGINE = "Workflow.SimpleWorkflow.Enable";
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 this can be moved to a constant class

Copy link
Author

Choose a reason for hiding this comment

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

Addressed with this commit e7dc2ae

private static boolean enableSimpleWorkflowEngine = Boolean.parseBoolean(IdentityUtil.getProperty(SIMPLE_WORKFLOW_ENGINE));

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(ApprovalEventService approvalEventService, UserApprovalService userApprovalService) {

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

@Override
public Response getApprovalTaskInfo(String taskId) {

if (enableSimpleWorkflowEngine) {
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<String> status) {

if (enableSimpleWorkflowEngine) {
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) {

userApprovalService.updateStatus(taskId, nextState);
if (enableSimpleWorkflowEngine) {
approvalEventService.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,11 +16,17 @@
-->

<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.ApprovalEventService"/>
<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="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">
Copy link
Author

Choose a reason for hiding this comment

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

fix bean id

Copy link
Author

Choose a reason for hiding this comment

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

Addressed with this commit e7dc2ae

<property name="taskOperationService" ref="taskOperationServiceFactoryBean"/>
</bean>
<bean id="taskOperationServiceFactoryBean"
class="org.wso2.carbon.identity.api.user.approval.common.factory.OSGIServiceFactory"/>
class="org.wso2.carbon.identity.api.user.approval.common.factory.OSGIBpelService"/>
</beans>
5 changes: 5 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>1.0-SNAPSHOT</version>
Copy link
Author

Choose a reason for hiding this comment

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

get the version through a property

Copy link
Author

@IsharaSilva IsharaSilva Jul 26, 2022

Choose a reason for hiding this comment

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

Addressed with this commit b89af13

</dependency>

<!-- Kernel Dependencies-->
<dependency>
Expand Down