Search in sources :

Example 26 with User

use of org.alfresco.web.bean.repository.User in project acs-community-packaging by Alfresco.

the class ManageTaskDialog method takeOwnership.

// ------------------------------------------------------------------------------
// Event handlers
@SuppressWarnings("deprecation")
public String takeOwnership() {
    String outcome = getDefaultFinishOutcome();
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Taking ownership of task: " + this.getWorkflowTask().id);
    FacesContext context = FacesContext.getCurrentInstance();
    // before taking ownership check the task still exists and is not
    // completed
    WorkflowTask checkTask = this.getWorkflowService().getTaskById(this.getWorkflowTask().id);
    if (checkTask == null || checkTask.state == WorkflowTaskState.COMPLETED) {
        Utils.addErrorMessage(Application.getMessage(context, "invalid_task"));
        return outcome;
    }
    UserTransaction tx = null;
    try {
        tx = Repository.getUserTransaction(context);
        tx.begin();
        // prepare the edited parameters for saving
        User user = Application.getCurrentUser(context);
        String userName = user.getUserName();
        Map<QName, Serializable> params = new HashMap<QName, Serializable>();
        params.put(ContentModel.PROP_OWNER, userName);
        // update the task with the updated parameters and resources
        updateResources();
        this.getWorkflowService().updateTask(this.getWorkflowTask().id, params, null, null);
        // commit the changes
        tx.commit();
    } catch (Throwable e) {
        // rollback the transaction
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception ex) {
        }
        Utils.addErrorMessage(formatErrorMessage(e), e);
        outcome = this.getErrorOutcome(e);
    }
    return outcome;
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) Serializable(java.io.Serializable) User(org.alfresco.web.bean.repository.User) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask)

Example 27 with User

use of org.alfresco.web.bean.repository.User in project acs-community-packaging by Alfresco.

the class WorkflowBean method getAllActiveTasks.

// ------------------------------------------------------------------------------
// Bean Getters and Setters
/**
 * Returns a list of nodes representing the "all" active tasks.
 *
 * @return List of all active tasks
 */
public List<Node> getAllActiveTasks() {
    if (this.activeTasks == null) {
        // get the current username
        FacesContext context = FacesContext.getCurrentInstance();
        User user = Application.getCurrentUser(context);
        String userName = user.getUserName();
        UserTransaction tx = null;
        try {
            tx = Repository.getUserTransaction(context, true);
            tx.begin();
            // query for all active tasks
            WorkflowTaskQuery query = new WorkflowTaskQuery();
            List<WorkflowTask> tasks = this.getWorkflowService().queryTasks(query);
            // create a list of transient nodes to represent
            this.activeTasks = new ArrayList<Node>(tasks.size());
            for (WorkflowTask task : tasks) {
                Node node = createTask(task);
                this.activeTasks.add(node);
                if (logger.isDebugEnabled())
                    logger.debug("Added active task: " + node);
            }
            // commit the changes
            tx.commit();
        } catch (Throwable e) {
            // rollback the transaction
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception ex) {
            }
            Utils.addErrorMessage("Failed to get all active tasks: " + e.toString(), e);
        }
    }
    return this.activeTasks;
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) User(org.alfresco.web.bean.repository.User) Node(org.alfresco.web.bean.repository.Node) TransientNode(org.alfresco.web.bean.repository.TransientNode) TransientMapNode(org.alfresco.web.bean.repository.TransientMapNode) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) WorkflowTaskQuery(org.alfresco.service.cmr.workflow.WorkflowTaskQuery)

Example 28 with User

use of org.alfresco.web.bean.repository.User in project acs-community-packaging by Alfresco.

the class CancelWorkflowEvaluator method evaluate.

/**
 * @see org.alfresco.web.action.ActionEvaluator#evaluate(org.alfresco.web.bean.repository.Node)
 */
public boolean evaluate(Node node) {
    boolean result = false;
    FacesContext context = FacesContext.getCurrentInstance();
    // get the task from the node
    WorkflowTask task = (WorkflowTask) node.getProperties().get("workflowTask");
    if (task != null) {
        NodeRef initiator = task.path.instance.initiator;
        if (initiator != null) {
            // find the current username
            User user = Application.getCurrentUser(context);
            String currentUserName = user.getUserName();
            // get the username of the initiator
            NodeService nodeSvc = Repository.getServiceRegistry(context).getNodeService();
            String userName = (String) nodeSvc.getProperty(initiator, ContentModel.PROP_USERNAME);
            // if the current user started the workflow allow the cancel action
            if (currentUserName.equals(userName)) {
                result = true;
            }
        }
    }
    return result;
}
Also used : FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) User(org.alfresco.web.bean.repository.User) NodeService(org.alfresco.service.cmr.repository.NodeService) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask)

Example 29 with User

use of org.alfresco.web.bean.repository.User in project acs-community-packaging by Alfresco.

the class KerberosAuthenticationHandler method createUserObject.

/* (non-Javadoc)
     * @see org.alfresco.repo.webdav.auth.BaseAuthenticationFilter#createUserObject(java.lang.String, java.lang.String, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
     */
@Override
protected SessionUser createUserObject(String userName, String ticket, NodeRef personNode, NodeRef homeSpaceRef) {
    // Create a web client user object
    User user = new User(userName, ticket, personNode);
    user.setHomeSpaceId(homeSpaceRef.getId());
    return user;
}
Also used : SessionUser(org.alfresco.repo.SessionUser) User(org.alfresco.web.bean.repository.User)

Aggregations

User (org.alfresco.web.bean.repository.User)29 SessionUser (org.alfresco.repo.SessionUser)14 FacesContext (javax.faces.context.FacesContext)9 AuthenticationException (org.alfresco.repo.security.authentication.AuthenticationException)8 NodeRef (org.alfresco.service.cmr.repository.NodeRef)8 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)6 UserTransaction (javax.transaction.UserTransaction)5 AuthenticationService (org.alfresco.service.cmr.security.AuthenticationService)5 Node (org.alfresco.web.bean.repository.Node)5 WebApplicationContext (org.springframework.web.context.WebApplicationContext)5 HttpSession (javax.servlet.http.HttpSession)4 TransientMapNode (org.alfresco.web.bean.repository.TransientMapNode)4 TransientNode (org.alfresco.web.bean.repository.TransientNode)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 NodeService (org.alfresco.service.cmr.repository.NodeService)3 Map (java.util.Map)2 Set (java.util.Set)2 PortletException (javax.portlet.PortletException)2 PortletSession (javax.portlet.PortletSession)2