use of org.wso2.carbon.identity.workflow.mgt.bean.WorkflowRequest in project carbon-identity-framework by wso2.
the class WorkflowRequestBuilder method buildXMLRequest.
/**
* Create OM Element from workflow request parameters.
*
* @param workFlowRequest Workflow parameters
* @param initParams Non workflow parameters
* @return
* @throws WorkflowRuntimeException
*/
public static OMElement buildXMLRequest(WorkflowRequest workFlowRequest, Map<String, Object> initParams) throws WorkflowRuntimeException {
WorkflowRequestBuilder requestBuilder = new WorkflowRequestBuilder(workFlowRequest.getUuid(), workFlowRequest.getEventType());
for (RequestParameter parameter : workFlowRequest.getRequestParameters()) {
if (parameter.isRequiredInWorkflow()) {
switch(parameter.getValueType()) {
case WorkflowDataType.BOOLEAN_TYPE:
case WorkflowDataType.STRING_TYPE:
case WorkflowDataType.INTEGER_TYPE:
case WorkflowDataType.DOUBLE_TYPE:
requestBuilder.addSingleValuedParam(parameter.getName(), parameter.getValue());
break;
case WorkflowDataType.STRING_LIST_TYPE:
case WorkflowDataType.DOUBLE_LIST_TYPE:
case WorkflowDataType.INTEGER_LIST_TYPE:
case WorkflowDataType.BOOLEAN_LIST_TYPE:
requestBuilder.addListTypeParam(parameter.getName(), (List<Object>) parameter.getValue());
break;
case WorkflowDataType.STRING_STRING_MAP_TYPE:
requestBuilder.addMapTypeParam(parameter.getName(), (Map<String, Object>) parameter.getValue());
break;
}
}
}
requestBuilder.setInitParams(initParams);
return requestBuilder.buildRequest();
}
use of org.wso2.carbon.identity.workflow.mgt.bean.WorkflowRequest in project carbon-identity-framework by wso2.
the class AbstractWorkflowRequestHandler method startWorkFlow.
/**
* Start a new workflow.
*
* @param wfParams Parameters related to workflow
* @param nonWfParams Other parameters
* @param uuid Unique ID of request
* @return
* @throws WorkflowException
*/
public WorkflowExecutorResult startWorkFlow(Map<String, Object> wfParams, Map<String, Object> nonWfParams, String uuid) throws WorkflowException {
if (isWorkflowCompleted()) {
return new WorkflowExecutorResult(ExecutorResultState.COMPLETED);
}
if (!isAssociated()) {
return new WorkflowExecutorResult(ExecutorResultState.NO_ASSOCIATION);
}
WorkflowRequest workFlowRequest = new WorkflowRequest();
List<RequestParameter> parameters = new ArrayList<RequestParameter>(wfParams.size() + nonWfParams.size() + 1);
for (Map.Entry<String, Object> paramEntry : wfParams.entrySet()) {
parameters.add(getParameter(paramEntry.getKey(), paramEntry.getValue(), true));
}
for (Map.Entry<String, Object> paramEntry : nonWfParams.entrySet()) {
parameters.add(getParameter(paramEntry.getKey(), paramEntry.getValue(), false));
}
RequestParameter uuidParameter = new RequestParameter();
uuidParameter.setName(WFConstant.REQUEST_ID);
uuidParameter.setValue(uuid);
uuidParameter.setRequiredInWorkflow(true);
uuidParameter.setValueType(WorkflowDataType.STRING_TYPE);
parameters.add(uuidParameter);
workFlowRequest.setRequestParameters(parameters);
workFlowRequest.setTenantId(CarbonContext.getThreadLocalCarbonContext().getTenantId());
workFlowRequest.setUuid(uuid);
engageWorkflow(workFlowRequest);
WorkflowExecutorResult workflowExecutorResult = WorkFlowExecutorManager.getInstance().executeWorkflow(workFlowRequest);
if (workflowExecutorResult.getExecutorResultState() == ExecutorResultState.FAILED) {
throw new WorkflowException(workflowExecutorResult.getMessage());
}
return workflowExecutorResult;
}
use of org.wso2.carbon.identity.workflow.mgt.bean.WorkflowRequest in project carbon-identity-framework by wso2.
the class WorkflowManagementServiceImpl method deleteWorkflowRequestCreatedByAnyUser.
/**
* Move workflow request created by any user to DELETED state.
*
* @param requestId Request ID
* @throws WorkflowException
*/
@Override
public void deleteWorkflowRequestCreatedByAnyUser(String requestId) throws WorkflowException {
List<WorkflowListener> workflowListenerList = WorkflowServiceDataHolder.getInstance().getWorkflowListenerList();
WorkflowRequest workflowRequest = new WorkflowRequest();
workflowRequest.setRequestId(requestId);
workflowRequest.setCreatedBy(workflowRequestDAO.retrieveCreatedUserOfRequest(requestId));
for (WorkflowListener workflowListener : workflowListenerList) {
if (workflowListener.isEnable()) {
workflowListener.doPreDeleteWorkflowRequest(workflowRequest);
}
}
workflowRequestDAO.updateStatusOfRequest(requestId, WorkflowRequestStatus.DELETED.toString());
workflowRequestAssociationDAO.updateStatusOfRelationshipsOfPendingRequest(requestId, WFConstant.HT_STATE_SKIPPED);
requestEntityRelationshipDAO.deleteRelationshipsOfRequest(requestId);
for (WorkflowListener workflowListener : workflowListenerList) {
if (workflowListener.isEnable()) {
workflowListener.doPostDeleteWorkflowRequest(workflowRequest);
}
}
}
use of org.wso2.carbon.identity.workflow.mgt.bean.WorkflowRequest in project carbon-identity-framework by wso2.
the class WorkflowManagementServiceImpl method getRequestsFromFilter.
/**
* get requests list according to createdUser, createdTime, and lastUpdatedTime
*
* @param user User to get requests of, empty String to retrieve requests of all users
* @param beginDate lower limit of date range to filter
* @param endDate upper limit of date range to filter
* @param dateCategory filter by created time or last updated time ?
* @param tenantId tenant id of currently logged in user
* @return
* @throws WorkflowException
*/
@Override
public WorkflowRequest[] getRequestsFromFilter(String user, String beginDate, String endDate, String dateCategory, int tenantId, String status) throws WorkflowException {
SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT_FOR_FILTERING);
Timestamp beginTime;
Timestamp endTime;
List<WorkflowListener> workflowListenerList = WorkflowServiceDataHolder.getInstance().getWorkflowListenerList();
for (WorkflowListener workflowListener : workflowListenerList) {
if (workflowListener.isEnable()) {
workflowListener.doPreGetRequestsFromFilter(user, beginDate, endDate, dateCategory, tenantId, status);
}
}
try {
Date parsedBeginDate = dateFormat.parse(beginDate);
beginTime = new java.sql.Timestamp(parsedBeginDate.getTime());
} catch (ParseException e) {
long millis = 0;
Date parsedBeginDate = new Date(millis);
beginTime = new java.sql.Timestamp(parsedBeginDate.getTime());
}
try {
Date parsedEndDate = dateFormat.parse(endDate);
endTime = new java.sql.Timestamp(parsedEndDate.getTime());
} catch (ParseException e) {
Date parsedEndDate = new Date();
endTime = new java.sql.Timestamp(parsedEndDate.getTime());
}
WorkflowRequest[] resultList;
if (StringUtils.isBlank(user)) {
resultList = workflowRequestDAO.getRequestsFilteredByTime(beginTime, endTime, dateCategory, tenantId, status);
} else {
resultList = workflowRequestDAO.getRequestsOfUserFilteredByTime(user, beginTime, endTime, dateCategory, tenantId, status);
}
for (WorkflowListener workflowListener : workflowListenerList) {
if (workflowListener.isEnable()) {
workflowListener.doPostGetRequestsFromFilter(user, beginDate, endDate, dateCategory, tenantId, status, resultList);
}
}
return resultList;
}
use of org.wso2.carbon.identity.workflow.mgt.bean.WorkflowRequest in project carbon-identity-framework by wso2.
the class WorkFlowExecutorManager method handleCallback.
/**
* Called when callback received for a pending operation.
*
* @param uuid Unique ID of request
* @param status Status of approval/disapproval
* @param additionalParams Additional parameters required to execute operation.
* @throws WorkflowException
*/
public void handleCallback(String uuid, String status, Map<String, Object> additionalParams) throws WorkflowException {
List<WorkflowExecutorManagerListener> workflowListenerList = WorkflowServiceDataHolder.getInstance().getExecutorListenerList();
for (WorkflowExecutorManagerListener workflowListener : workflowListenerList) {
if (workflowListener.isEnable()) {
workflowListener.doPreHandleCallback(uuid, status, additionalParams);
}
}
WorkflowRequestAssociationDAO workflowRequestAssociationDAO = new WorkflowRequestAssociationDAO();
String requestId = workflowRequestAssociationDAO.getRequestIdOfRelationship(uuid);
WorkflowRequestDAO requestDAO = new WorkflowRequestDAO();
WorkflowRequest request = requestDAO.retrieveWorkflow(requestId);
handleCallback(request, status, additionalParams, uuid);
for (WorkflowExecutorManagerListener workflowListener : workflowListenerList) {
if (workflowListener.isEnable()) {
workflowListener.doPostHandleCallback(uuid, status, additionalParams);
}
}
}
Aggregations