use of org.wso2.carbon.identity.workflow.mgt.extension.WorkflowRequestHandler in project carbon-identity-framework by wso2.
the class WorkflowManagementServiceImpl method getAssociationsForWorkflow.
@Override
public List<Association> getAssociationsForWorkflow(String workflowId) throws WorkflowException {
List<WorkflowListener> workflowListenerList = WorkflowServiceDataHolder.getInstance().getWorkflowListenerList();
for (WorkflowListener workflowListener : workflowListenerList) {
if (workflowListener.isEnable()) {
workflowListener.doPreGetAssociationsForWorkflow(workflowId);
}
}
List<Association> associations = associationDAO.listAssociationsForWorkflow(workflowId);
for (Iterator<Association> iterator = associations.iterator(); iterator.hasNext(); ) {
Association association = iterator.next();
WorkflowRequestHandler requestHandler = WorkflowServiceDataHolder.getInstance().getRequestHandler(association.getEventId());
if (requestHandler != null) {
association.setEventName(requestHandler.getFriendlyName());
} else {
// invalid reference, probably event id is renamed or removed
iterator.remove();
}
}
for (WorkflowListener workflowListener : workflowListenerList) {
if (workflowListener.isEnable()) {
workflowListener.doPostGetAssociationsForWorkflow(workflowId, associations);
}
}
return associations;
}
use of org.wso2.carbon.identity.workflow.mgt.extension.WorkflowRequestHandler in project carbon-identity-framework by wso2.
the class WorkflowManagementServiceImpl method listWorkflowEvents.
@Override
public List<WorkflowEvent> listWorkflowEvents() {
List<WorkflowListener> workflowListenerList = WorkflowServiceDataHolder.getInstance().getWorkflowListenerList();
for (WorkflowListener workflowListener : workflowListenerList) {
if (workflowListener.isEnable()) {
workflowListener.doPreListWorkflowEvents();
}
}
List<WorkflowRequestHandler> workflowRequestHandlers = WorkflowServiceDataHolder.getInstance().listRequestHandlers();
List<WorkflowEvent> eventList = new ArrayList<>();
if (workflowRequestHandlers != null) {
for (WorkflowRequestHandler requestHandler : workflowRequestHandlers) {
WorkflowEvent event = new WorkflowEvent();
event.setEventId(requestHandler.getEventId());
event.setEventFriendlyName(requestHandler.getFriendlyName());
event.setEventDescription(requestHandler.getDescription());
event.setEventCategory(requestHandler.getCategory());
// note: parameters are not set at here in list operation. It's set only at get operation
if (requestHandler.getParamDefinitions() != null) {
Parameter[] parameterDTOs = new Parameter[requestHandler.getParamDefinitions().size()];
int i = 0;
for (Map.Entry<String, String> paramEntry : requestHandler.getParamDefinitions().entrySet()) {
Parameter parameterDTO = new Parameter();
parameterDTO.setParamName(paramEntry.getKey());
parameterDTO.setParamValue(paramEntry.getValue());
parameterDTOs[i] = parameterDTO;
i++;
}
event.setParameters(parameterDTOs);
}
eventList.add(event);
}
}
for (WorkflowListener workflowListener : workflowListenerList) {
if (workflowListener.isEnable()) {
if (workflowListener.isEnable()) {
workflowListener.doPostListWorkflowEvents(eventList);
}
}
}
return eventList;
}
use of org.wso2.carbon.identity.workflow.mgt.extension.WorkflowRequestHandler in project carbon-identity-framework by wso2.
the class WorkflowManagementServiceImpl method listAllAssociations.
@Override
public List<Association> listAllAssociations(int tenantId) throws WorkflowException {
List<WorkflowListener> workflowListenerList = WorkflowServiceDataHolder.getInstance().getWorkflowListenerList();
for (WorkflowListener workflowListener : workflowListenerList) {
if (workflowListener.isEnable()) {
workflowListener.doPreListAllAssociations(tenantId);
}
}
List<Association> associations = associationDAO.listAssociations(tenantId);
for (Iterator<Association> iterator = associations.iterator(); iterator.hasNext(); ) {
Association association = iterator.next();
WorkflowRequestHandler requestHandler = WorkflowServiceDataHolder.getInstance().getRequestHandler(association.getEventId());
if (requestHandler != null) {
association.setEventName(requestHandler.getFriendlyName());
} else {
// invalid reference, probably event id is renamed or removed
iterator.remove();
}
}
for (WorkflowListener workflowListener : workflowListenerList) {
if (workflowListener.isEnable()) {
workflowListener.doPostListAllAssociations(tenantId, associations);
}
}
return associations;
}
use of org.wso2.carbon.identity.workflow.mgt.extension.WorkflowRequestHandler in project carbon-identity-framework by wso2.
the class WorkFlowExecutorManager method handleCallback.
private void handleCallback(WorkflowRequest request, String status, Map<String, Object> additionalParams, String requestWorkflowId) throws WorkflowException {
WorkflowRequestAssociationDAO workflowRequestAssociationDAO = new WorkflowRequestAssociationDAO();
if (request != null) {
WorkflowRequestDAO workflowRequestDAO = new WorkflowRequestDAO();
String requestId = request.getUuid();
workflowRequestAssociationDAO.updateStatusOfRelationship(requestWorkflowId, status);
workflowRequestDAO.updateLastUpdatedTimeOfRequest(requestId);
if (StringUtils.isNotBlank(requestWorkflowId) && WorkflowRequestStatus.DELETED.toString().equals(workflowRequestDAO.retrieveStatusOfWorkflow(request.getUuid()))) {
log.info("Callback received for request " + requestId + " which is already deleted by user. ");
return;
}
if (status.equals(WorkflowRequestStatus.APPROVED.toString()) && !isAllWorkflowsCompleted(workflowRequestAssociationDAO, requestId)) {
return;
}
String eventId = request.getEventType();
WorkflowRequestHandler requestHandler = WorkflowServiceDataHolder.getInstance().getRequestHandler(eventId);
if (requestHandler == null) {
throw new InternalWorkflowException("No request handlers registered for the id: " + eventId);
}
if (request.getTenantId() == MultitenantConstants.INVALID_TENANT_ID) {
throw new InternalWorkflowException("Invalid tenant id for request " + eventId + " with id" + requestId);
}
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
try {
String tenantDomain = WorkflowServiceDataHolder.getInstance().getRealmService().getTenantManager().getDomain(request.getTenantId());
carbonContext.setTenantId(request.getTenantId());
carbonContext.setTenantDomain(tenantDomain);
requestHandler.onWorkflowCompletion(status, request, additionalParams);
updateDBAtWorkflowCompletion(requestId, status);
} catch (WorkflowException e) {
updateDBAtWorkflowCompletion(requestId, WorkflowRequestStatus.FAILED.toString());
throw e;
} catch (UserStoreException e) {
updateDBAtWorkflowCompletion(requestId, WorkflowRequestStatus.FAILED.toString());
throw new InternalWorkflowException("Error when getting tenant domain for tenant id " + request.getTenantId());
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
}
use of org.wso2.carbon.identity.workflow.mgt.extension.WorkflowRequestHandler in project carbon-identity-framework by wso2.
the class WorkflowManagementServiceImpl method getEvent.
@Override
public WorkflowEvent getEvent(String id) {
List<WorkflowListener> workflowListenerList = WorkflowServiceDataHolder.getInstance().getWorkflowListenerList();
for (WorkflowListener workflowListener : workflowListenerList) {
if (workflowListener.isEnable()) {
workflowListener.doPreGetEvent(id);
}
}
WorkflowRequestHandler requestHandler = WorkflowServiceDataHolder.getInstance().getRequestHandler(id);
WorkflowEvent event = null;
if (requestHandler != null) {
event = new WorkflowEvent();
event.setEventId(requestHandler.getEventId());
event.setEventFriendlyName(requestHandler.getFriendlyName());
event.setEventDescription(requestHandler.getDescription());
event.setEventCategory(requestHandler.getCategory());
if (requestHandler.getParamDefinitions() != null) {
Parameter[] parameters = new Parameter[requestHandler.getParamDefinitions().size()];
int i = 0;
for (Map.Entry<String, String> paramEntry : requestHandler.getParamDefinitions().entrySet()) {
Parameter parameter = new Parameter();
parameter.setParamName(paramEntry.getKey());
parameter.setParamValue(paramEntry.getValue());
parameters[i] = parameter;
i++;
}
event.setParameters(parameters);
}
}
for (WorkflowListener workflowListener : workflowListenerList) {
if (workflowListener.isEnable()) {
workflowListener.doPostGetEvent(id, event);
}
}
return event;
}
Aggregations