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;
}
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;
}
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;
}
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;
}
Aggregations