Search in sources :

Example 1 with WorkflowRequestHandler

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;
}
Also used : WorkflowRequestAssociation(org.wso2.carbon.identity.workflow.mgt.bean.WorkflowRequestAssociation) Association(org.wso2.carbon.identity.workflow.mgt.dto.Association) WorkflowAssociation(org.wso2.carbon.identity.workflow.mgt.bean.WorkflowAssociation) WorkflowListener(org.wso2.carbon.identity.workflow.mgt.listener.WorkflowListener) WorkflowRequestHandler(org.wso2.carbon.identity.workflow.mgt.extension.WorkflowRequestHandler)

Example 2 with WorkflowRequestHandler

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;
}
Also used : ArrayList(java.util.ArrayList) WorkflowListener(org.wso2.carbon.identity.workflow.mgt.listener.WorkflowListener) WorkflowEvent(org.wso2.carbon.identity.workflow.mgt.dto.WorkflowEvent) Parameter(org.wso2.carbon.identity.workflow.mgt.bean.Parameter) Map(java.util.Map) WorkflowRequestHandler(org.wso2.carbon.identity.workflow.mgt.extension.WorkflowRequestHandler)

Example 3 with WorkflowRequestHandler

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;
}
Also used : WorkflowRequestAssociation(org.wso2.carbon.identity.workflow.mgt.bean.WorkflowRequestAssociation) Association(org.wso2.carbon.identity.workflow.mgt.dto.Association) WorkflowAssociation(org.wso2.carbon.identity.workflow.mgt.bean.WorkflowAssociation) WorkflowListener(org.wso2.carbon.identity.workflow.mgt.listener.WorkflowListener) WorkflowRequestHandler(org.wso2.carbon.identity.workflow.mgt.extension.WorkflowRequestHandler)

Example 4 with WorkflowRequestHandler

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();
        }
    }
}
Also used : WorkflowRequestDAO(org.wso2.carbon.identity.workflow.mgt.dao.WorkflowRequestDAO) InternalWorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException) WorkflowRequestAssociationDAO(org.wso2.carbon.identity.workflow.mgt.dao.WorkflowRequestAssociationDAO) InternalWorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException) WorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.WorkflowException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) WorkflowRequestHandler(org.wso2.carbon.identity.workflow.mgt.extension.WorkflowRequestHandler)

Example 5 with WorkflowRequestHandler

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;
}
Also used : WorkflowEvent(org.wso2.carbon.identity.workflow.mgt.dto.WorkflowEvent) Parameter(org.wso2.carbon.identity.workflow.mgt.bean.Parameter) WorkflowListener(org.wso2.carbon.identity.workflow.mgt.listener.WorkflowListener) Map(java.util.Map) WorkflowRequestHandler(org.wso2.carbon.identity.workflow.mgt.extension.WorkflowRequestHandler)

Aggregations

WorkflowRequestHandler (org.wso2.carbon.identity.workflow.mgt.extension.WorkflowRequestHandler)5 WorkflowListener (org.wso2.carbon.identity.workflow.mgt.listener.WorkflowListener)4 Map (java.util.Map)2 Parameter (org.wso2.carbon.identity.workflow.mgt.bean.Parameter)2 WorkflowAssociation (org.wso2.carbon.identity.workflow.mgt.bean.WorkflowAssociation)2 WorkflowRequestAssociation (org.wso2.carbon.identity.workflow.mgt.bean.WorkflowRequestAssociation)2 Association (org.wso2.carbon.identity.workflow.mgt.dto.Association)2 WorkflowEvent (org.wso2.carbon.identity.workflow.mgt.dto.WorkflowEvent)2 ArrayList (java.util.ArrayList)1 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)1 WorkflowRequestAssociationDAO (org.wso2.carbon.identity.workflow.mgt.dao.WorkflowRequestAssociationDAO)1 WorkflowRequestDAO (org.wso2.carbon.identity.workflow.mgt.dao.WorkflowRequestDAO)1 InternalWorkflowException (org.wso2.carbon.identity.workflow.mgt.exception.InternalWorkflowException)1 WorkflowException (org.wso2.carbon.identity.workflow.mgt.exception.WorkflowException)1 UserStoreException (org.wso2.carbon.user.api.UserStoreException)1