-
Notifications
You must be signed in to change notification settings - Fork 93
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
base: feature-workflow-engine-simple
Are you sure you want to change the base?
Changes from 4 commits
9f71095
850c4fa
c0a8683
4553925
e7dc2ae
b89af13
52008da
4de9b56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. switch variable name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed with this commit e7dc2ae |
||
|
||
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; | ||
} | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.wso2.carbon.identity.api.user.approval.common.factory; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add license header There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add class comment There was a problem hiding this comment. Choose a reason for hiding this commentThe 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."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change into run time exception There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
---|---|---|
|
@@ -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> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fix variable name There was a problem hiding this comment. Choose a reason for hiding this commentThe 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."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add run time exception There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
---|---|---|
|
@@ -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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check if these imports can be removed There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
---|---|---|
|
@@ -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; | ||
|
@@ -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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check if this can be moved to a constant class There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove if not needed There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
---|---|---|
|
@@ -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"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fix bean id There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. get the version through a property There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed with this commit b89af13 |
||
</dependency> | ||
|
||
<!-- Kernel Dependencies--> | ||
<dependency> | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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