List of usage examples for javax.transaction UserTransaction rollback
void rollback() throws IllegalStateException, SecurityException, SystemException;
From source file:org.alfresco.web.bean.wizard.NewUserWizard.java
/** * @see org.alfresco.web.bean.wizard.AbstractWizardBean#finish() *//*from www . ja v a 2s . c o m*/ public String finish() { String outcome = FINISH_OUTCOME; // TODO: implement create new Person object from specified details UserTransaction tx = null; try { FacesContext context = FacesContext.getCurrentInstance(); tx = Repository.getUserTransaction(context); tx.begin(); if (this.editMode) { // update the existing node in the repository NodeRef nodeRef = getPerson().getNodeRef(); Map<QName, Serializable> props = this.getNodeService().getProperties(nodeRef); props.put(ContentModel.PROP_USERNAME, this.userName); props.put(ContentModel.PROP_FIRSTNAME, this.firstName); props.put(ContentModel.PROP_LASTNAME, this.lastName); // calculate whether we need to move the old home space or create new NodeRef newHomeFolderRef; NodeRef oldHomeFolderRef = (NodeRef) this.getNodeService().getProperty(nodeRef, ContentModel.PROP_HOMEFOLDER); boolean moveHomeSpace = false; boolean renameHomeSpace = false; if (oldHomeFolderRef != null && this.getNodeService().exists(oldHomeFolderRef) == true) { // the original home folder ref exists so may need moving if it has been changed ChildAssociationRef childAssocRef = this.getNodeService().getPrimaryParent(oldHomeFolderRef); NodeRef currentHomeSpaceLocation = childAssocRef.getParentRef(); if (this.homeSpaceName.length() != 0) { if (currentHomeSpaceLocation.equals(this.homeSpaceLocation) == false && oldHomeFolderRef.equals(this.homeSpaceLocation) == false && currentHomeSpaceLocation.equals(getCompanyHomeSpace()) == false && currentHomeSpaceLocation.equals(getDefaultHomeSpace()) == false) { moveHomeSpace = true; } String oldHomeSpaceName = Repository.getNameForNode(getNodeService(), oldHomeFolderRef); if (oldHomeSpaceName.equals(this.homeSpaceName) == false && oldHomeFolderRef.equals(this.homeSpaceLocation) == false && oldHomeFolderRef.equals(this.defaultHomeSpaceRef) == false) { renameHomeSpace = true; } } } if (logger.isDebugEnabled()) logger.debug("Moving space: " + moveHomeSpace + " and renaming space: " + renameHomeSpace); if (moveHomeSpace == false && renameHomeSpace == false) { if (this.homeSpaceLocation != null && this.homeSpaceName.length() != 0) { newHomeFolderRef = createHomeSpace(this.homeSpaceLocation.getId(), this.homeSpaceName, false); } else if (this.homeSpaceLocation != null) { // location selected but no home space name entered, // so the home ref should be set to the newly selected space newHomeFolderRef = this.homeSpaceLocation; // set the permissions for this space so the user can access it } else { // nothing selected - use Company Home by default newHomeFolderRef = getCompanyHomeSpace(); } } else { // either move, rename or both required if (moveHomeSpace == true) { this.getNodeService().moveNode(oldHomeFolderRef, this.homeSpaceLocation, ContentModel.ASSOC_CONTAINS, this.getNodeService().getPrimaryParent(oldHomeFolderRef).getQName()); } newHomeFolderRef = oldHomeFolderRef; // ref ID doesn't change if (renameHomeSpace == true) { // change HomeSpace node name this.getNodeService().setProperty(newHomeFolderRef, ContentModel.PROP_NAME, this.homeSpaceName); } } props.put(ContentModel.PROP_HOMEFOLDER, newHomeFolderRef); props.put(ContentModel.PROP_EMAIL, this.email); props.put(ContentModel.PROP_ORGID, this.companyId); this.getNodeService().setProperties(nodeRef, props); // TODO: RESET HomeSpace Ref found in top-level navigation bar! // NOTE: not need cos only admin can do this? } else { if (tenantService.isEnabled()) { String currentDomain = tenantService.getCurrentUserDomain(); if (!currentDomain.equals(TenantService.DEFAULT_DOMAIN)) { if (!tenantService.isTenantUser(this.userName)) { // force domain onto the end of the username this.userName = tenantService.getDomainUser(this.userName, currentDomain); logger.warn("Added domain to username: " + this.userName); } else { try { tenantService.checkDomainUser(this.userName); } catch (RuntimeException re) { throw new AuthenticationException( "User must belong to same domain as admin: " + currentDomain); } } } } if (this.password.equals(this.confirm)) { // create properties for Person type from submitted Form data Map<QName, Serializable> props = new HashMap<QName, Serializable>(7, 1.0f); props.put(ContentModel.PROP_USERNAME, this.userName); props.put(ContentModel.PROP_FIRSTNAME, this.firstName); props.put(ContentModel.PROP_LASTNAME, this.lastName); NodeRef homeSpaceNodeRef; if (this.homeSpaceLocation != null && this.homeSpaceName.length() != 0) { // create new homeSpaceNodeRef = createHomeSpace(this.homeSpaceLocation.getId(), this.homeSpaceName, true); } else if (this.homeSpaceLocation != null) { // set to existing homeSpaceNodeRef = homeSpaceLocation; setupHomeSpacePermissions(homeSpaceNodeRef); } else { // default to Company Home homeSpaceNodeRef = getCompanyHomeSpace(); } props.put(ContentModel.PROP_HOMEFOLDER, homeSpaceNodeRef); props.put(ContentModel.PROP_EMAIL, this.email); props.put(ContentModel.PROP_ORGID, this.companyId); // create the node to represent the Person NodeRef newPerson = this.getPersonService().createPerson(props); // ensure the user can access their own Person object this.getPermissionService().setPermission(newPerson, this.userName, getPermissionService().getAllPermission(), true); if (logger.isDebugEnabled()) logger.debug("Created Person node for username: " + this.userName); // create the ACEGI Authentication instance for the new user this.getAuthenticationService().createAuthentication(this.userName, this.password.toCharArray()); if (logger.isDebugEnabled()) logger.debug("Created User Authentication instance for username: " + this.userName); } else { outcome = null; Utils.addErrorMessage(Application.getMessage(context, UsersDialog.ERROR_PASSWORD_MATCH)); } } // commit the transaction tx.commit(); // reset the richlist component so it rebinds to the users list invalidateUserList(); } catch (Throwable e) { // rollback the transaction try { if (tx != null) { tx.rollback(); } } catch (Exception tex) { } Utils.addErrorMessage(MessageFormat .format(Application.getMessage(FacesContext.getCurrentInstance(), ERROR), e.getMessage()), e); outcome = null; } return outcome; }
From source file:org.alfresco.web.bean.workflow.ManageTaskDialog.java
@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//from ww w . j a v a2 s.c o m 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; }
From source file:org.alfresco.web.bean.workflow.ManageTaskDialog.java
@SuppressWarnings("deprecation") public String returnOwnership() { String outcome = getDefaultFinishOutcome(); if (LOGGER.isDebugEnabled()) LOGGER.debug("Returning ownership of task to pool: " + this.getWorkflowTask().id); FacesContext context = FacesContext.getCurrentInstance(); // before returning ownership check the task still exists and is not // completed//from www .j ava 2 s.com 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 Map<QName, Serializable> params = new HashMap<QName, Serializable>(); params.put(ContentModel.PROP_OWNER, null); // 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; }
From source file:org.alfresco.web.bean.workflow.ManageTaskDialog.java
@SuppressWarnings("deprecation") public String transition() { String outcome = getDefaultFinishOutcome(); if (LOGGER.isDebugEnabled()) LOGGER.debug("Transitioning task: " + this.getWorkflowTask().id); // before transitioning check the task still exists and is not completed FacesContext context = FacesContext.getCurrentInstance(); WorkflowTask checkTask = this.getWorkflowService().getTaskById(this.getWorkflowTask().id); if (checkTask == null || checkTask.state == WorkflowTaskState.COMPLETED) { Utils.addErrorMessage(Application.getMessage(context, "invalid_task")); return outcome; }//from w w w . ja va 2 s . c om // to find out which transition button was pressed we need // to look for the button's id in the request parameters, // the first non-null result is the button that was pressed. Map<?, ?> reqParams = context.getExternalContext().getRequestParameterMap(); String selectedTransition = null; for (WorkflowTransition trans : this.getWorkflowTransitions()) { Object result = reqParams.get(CLIENT_ID_PREFIX + FacesHelper.makeLegalId(trans.title)); if (result != null) { // this was the button that was pressed selectedTransition = trans.id; break; } } UserTransaction tx = null; try { tx = Repository.getUserTransaction(context); tx.begin(); // prepare the edited parameters for saving Map<QName, Serializable> params = WorkflowUtil.prepareTaskParams(this.taskNode); if (LOGGER.isDebugEnabled()) LOGGER.debug("Transitioning task with parameters: " + params); // update the task with the updated parameters and resources updateResources(); this.getWorkflowService().updateTask(this.getWorkflowTask().id, params, null, null); // signal the selected transition to the workflow task this.getWorkflowService().endTask(this.getWorkflowTask().id, selectedTransition); // commit the changes tx.commit(); if (LOGGER.isDebugEnabled()) LOGGER.debug("Ended task with transition: " + selectedTransition); } 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; }
From source file:org.alfresco.web.bean.workflow.ManageTaskDialog.java
/** * Returns a list of resources associated with this task i.e. the children * of the workflow package/*from ww w . j a v a 2 s.com*/ * * @return The list of nodes */ public List<Node> getResources() { this.resources = new ArrayList<Node>(4); if (this.workflowPackage != null) { UserTransaction tx = null; try { FacesContext context = FacesContext.getCurrentInstance(); tx = Repository.getUserTransaction(context, true); tx.begin(); List<NodeRef> contents = this.workflowService.getPackageContents(getWorkflowTask().id); for (NodeRef nodeRef : contents) { if (this.getNodeService().exists(nodeRef)) { // find it's type so we can see if it's a node we // are interested in QName type = this.getNodeService().getType(nodeRef); // make sure the type is defined in the data // dictionary if (this.getDictionaryService().getType(type) != null) { // look for content nodes or links to content // NOTE: folders within workflow packages are // ignored for now if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_CONTENT) || ApplicationModel.TYPE_FILELINK.equals(type)) { // if the node is not in the removed list // then add create the // client side representation and add to the // list if (this.packageItemsToRemove == null || this.packageItemsToRemove.contains(nodeRef.toString()) == false) { createAndAddNode(nodeRef); } } } } } // now iterate through the items to add list and add them to the // list of resources if (this.packageItemsToAdd != null) { for (String newItem : this.packageItemsToAdd) { NodeRef nodeRef = new NodeRef(newItem); if (this.getNodeService().exists(nodeRef)) { // we know the type is correct as this was added as // a result of a query // for all content items so just add the item to the // resources list createAndAddNode(nodeRef); } else { if (LOGGER.isDebugEnabled()) LOGGER.debug("Ignoring " + nodeRef + " as it has been removed from the repository"); } } } // commit the transaction tx.commit(); } catch (Throwable err) { Utils.addErrorMessage(MessageFormat.format( Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err); this.resources = Collections.<Node>emptyList(); try { if (tx != null) { tx.rollback(); } } catch (Exception tex) { } } } else if (LOGGER.isDebugEnabled()) { LOGGER.debug("Failed to find workflow package for task: " + this.getWorkflowTask().id); } return this.resources; }
From source file:org.alfresco.web.bean.workflow.StartWorkflowWizard.java
/** * Returns a list of resources associated with this task * i.e. the children of the workflow package * /*from w w w . j a va 2s . c om*/ * @return The list of nodes */ public List<Node> getResources() { this.resources = new ArrayList<Node>(4); UserTransaction tx = null; try { FacesContext context = FacesContext.getCurrentInstance(); tx = Repository.getUserTransaction(context, true); tx.begin(); for (String newItem : this.packageItemsToAdd) { NodeRef nodeRef = new NodeRef(newItem); if (this.getNodeService().exists(nodeRef)) { // create our Node representation MapNode node = new MapNode(nodeRef, this.getNodeService(), true); this.browseBean.setupCommonBindingProperties(node); // add property resolvers to show path information node.addPropertyResolver("path", this.browseBean.resolverPath); node.addPropertyResolver("displayPath", this.browseBean.resolverDisplayPath); this.resources.add(node); } else { if (logger.isDebugEnabled()) logger.debug("Ignoring " + nodeRef + " as it has been removed from the repository"); } } // commit the transaction tx.commit(); } catch (Throwable err) { Utils.addErrorMessage(MessageFormat.format( Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err); this.resources = Collections.<Node>emptyList(); try { if (tx != null) { tx.rollback(); } } catch (Exception tex) { } } return this.resources; }
From source file:org.alfresco.web.bean.workflow.WorkflowBean.java
/** * Returns a list of nodes representing the "all" active tasks. * //from ww w .j a v a 2 s . c o m * @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; }
From source file:org.alfresco.web.bean.workflow.WorkflowBean.java
/** * Returns a list of nodes representing the "pooled" to do tasks the * current user has./* www. j a v a2 s. com*/ * * @return List of to do tasks */ public List<Node> getPooledTasks() { if (this.pooledTasks == 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(); // get the current pooled tasks for the current user List<WorkflowTask> tasks = this.getWorkflowService().getPooledTasks(userName, true); // create a list of transient nodes to represent this.pooledTasks = new ArrayList<Node>(tasks.size()); for (WorkflowTask task : tasks) { Node node = createTask(task); this.pooledTasks.add(node); if (logger.isDebugEnabled()) logger.debug("Added pooled 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 pooled tasks: " + e.toString(), e); } } return this.pooledTasks; }
From source file:org.alfresco.web.bean.workflow.WorkflowBean.java
/** * Returns a list of nodes representing the to do tasks the * current user has.// ww w .jav a 2s. co m * * @return List of to do tasks */ public List<Node> getTasksToDo() { if (this.tasks == 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(); // get the current in progress tasks for the current user List<WorkflowTask> tasks = this.getWorkflowService().getAssignedTasks(userName, WorkflowTaskState.IN_PROGRESS, true); // create a list of transient nodes to represent this.tasks = new ArrayList<Node>(tasks.size()); for (WorkflowTask task : tasks) { Node node = createTask(task); this.tasks.add(node); if (logger.isDebugEnabled()) logger.debug("Added to do 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 to do tasks: " + e.toString(), e); } } return this.tasks; }
From source file:org.alfresco.web.bean.workflow.WorkflowBean.java
/** * Returns a list of nodes representing the completed tasks the * current user has.//from w w w. j a v a2 s . c o m * * @return List of completed tasks */ public List<Node> getTasksCompleted() { if (this.completedTasks == 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(); // get the current in progress tasks for the current user ClientConfigElement clientConfig = (ClientConfigElement) Application.getConfigService(context) .getGlobalConfig().getConfigElement(ClientConfigElement.CONFIG_ELEMENT_ID); WorkflowTaskQuery query = new WorkflowTaskQuery(); query.setActive(null); query.setActorId(userName); query.setTaskState(WorkflowTaskState.COMPLETED); query.setLimit(clientConfig.getTasksCompletedMaxResults()); List<WorkflowTask> tasks = this.getWorkflowService().queryTasks(query); // create a list of transient nodes to represent this.completedTasks = new ArrayList<Node>(tasks.size()); for (WorkflowTask task : tasks) { Node node = createTask(task); this.completedTasks.add(node); if (logger.isDebugEnabled()) logger.debug("Added completed 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 completed tasks: " + e.toString(), e); } } return this.completedTasks; }