Search in sources :

Example 1 with WorkflowParameters

use of com.tremolosecurity.provisioning.objects.WorkflowParameters in project OpenUnison by TremoloSecurity.

the class WorkflowImpl method executeWorkflow.

/* (non-Javadoc)
	 * @see com.tremolosecurity.provisioning.core.Workflow#executeWorkflow(com.tremolosecurity.provisioning.core.User, java.util.Map)
	 */
@Override
public Map<String, Object> executeWorkflow(User user, Map<String, Object> params, String requesterUID) throws ProvisioningException {
    request = new HashMap<String, Object>();
    if (params != null) {
        request.putAll(params);
    // request = (HashMap<String, Object>) params;
    }
    this.user = user;
    Session session = null;
    try {
        if (this.cfgMgr.getProvisioningEngine().getHibernateSessionFactory() != null) {
            session = this.cfgMgr.getProvisioningEngine().getHibernateSessionFactory().openSession();
            this.userNum = getUserNum(user, session, this.cfgMgr);
            if (requesterUID == null) {
                this.requester = this.user;
                this.requesterNum = this.userNum;
            } else {
                this.requester = getRequester(requesterUID, session, cfgMgr);
                this.requesterNum = getUserNum(requester, session, this.cfgMgr);
            }
            Workflows workflow = session.load(Workflows.class, this.getId());
            workflow.setUsers(session.load(Users.class, this.userNum));
            workflow.setRequester(session.load(Users.class, this.requesterNum));
            workflow.setRequestReason(user.getRequestReason());
            ST st = new ST(this.description, '$', '$');
            for (String key : request.keySet()) {
                st.add(key.replaceAll("[.]", "_"), request.get(key));
            }
            workflow.setDescription(st.render());
            if (this.label != null) {
                st = new ST(this.label, '$', '$');
                for (String key : request.keySet()) {
                    st.add(key.replaceAll("[.]", "_"), request.get(key));
                }
                workflow.setLabel(st.render());
            } else {
                workflow.setLabel("");
            }
            session.beginTransaction();
            session.save(workflow);
            for (String paramName : params.keySet()) {
                WorkflowParameters param = new WorkflowParameters();
                param.setName(paramName);
                Object o = params.get(paramName);
                if (o != null) {
                    param.setValue(o.toString());
                } else {
                    param.setValue("");
                }
                param.setWorkflows(workflow);
                session.save(param);
            }
            session.getTransaction().commit();
        }
    } catch (SQLException e) {
        throw new ProvisioningException("Could not set workflow user key", e);
    } catch (LDAPException e) {
        throw new ProvisioningException("Could not set workflow user key", e);
    } finally {
        if (session != null) {
            if (session.getTransaction() != null && session.getTransaction().getStatus() == TransactionStatus.ACTIVE) {
                session.getTransaction().rollback();
            }
            session.close();
        }
    }
    if (request.get(ProvisioningParams.UNISON_EXEC_TYPE) != null && request.get(ProvisioningParams.UNISON_EXEC_TYPE).equals(ProvisioningParams.UNISON_EXEC_SYNC)) {
        Iterator<WorkflowTask> it = this.tasks.iterator();
        while (it.hasNext()) {
            boolean doContinue = it.next().doTask(user, request);
            if (!doContinue) {
                return request;
            }
        }
        this.completeWorkflow();
    } else {
        WorkflowHolder wfHolder = new WorkflowHolder(this, user, request);
        TaskHolder root = new TaskHolder();
        root.setParent(this.tasks);
        root.setPosition(0);
        wfHolder.getWfStack().push(root);
        ((ProvisioningEngineImpl) this.cfgMgr.getProvisioningEngine()).enqueue(wfHolder);
    }
    return request;
}
Also used : WorkflowParameters(com.tremolosecurity.provisioning.objects.WorkflowParameters) ST(org.stringtemplate.v4.ST) Workflows(com.tremolosecurity.provisioning.objects.Workflows) SQLException(java.sql.SQLException) TaskHolder(com.tremolosecurity.provisioning.util.TaskHolder) Users(com.tremolosecurity.provisioning.objects.Users) LDAPException(com.novell.ldap.LDAPException) Session(org.hibernate.Session)

Aggregations

LDAPException (com.novell.ldap.LDAPException)1 Users (com.tremolosecurity.provisioning.objects.Users)1 WorkflowParameters (com.tremolosecurity.provisioning.objects.WorkflowParameters)1 Workflows (com.tremolosecurity.provisioning.objects.Workflows)1 TaskHolder (com.tremolosecurity.provisioning.util.TaskHolder)1 SQLException (java.sql.SQLException)1 Session (org.hibernate.Session)1 ST (org.stringtemplate.v4.ST)1