List of usage examples for javax.transaction UserTransaction commit
void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException;
From source file:org.alfresco.web.bean.users.UserShortcutsBean.java
/** * Action handler bound to the user shortcuts Shelf component called when a node is removed *///from w w w .j a v a 2 s .c o m public void removeShortcut(ActionEvent event) { UIShortcutsShelfItem.ShortcutEvent shortcutEvent = (UIShortcutsShelfItem.ShortcutEvent) event; // remove from persistent store UserTransaction tx = null; try { FacesContext context = FacesContext.getCurrentInstance(); tx = Repository.getUserTransaction(context); tx.begin(); List<String> shortcuts = getShortcutList(context); if (shortcuts.size() > shortcutEvent.Index) { // remove the shortcut from the saved list and persist back shortcuts.remove(shortcutEvent.Index); PreferencesService.getPreferences(context).setValue(PREF_SHORTCUTS, (Serializable) shortcuts); // commit the transaction tx.commit(); // remove shortcut Node from the in-memory list Node node = getShortcuts().remove(shortcutEvent.Index); if (logger.isDebugEnabled()) logger.debug("Removed node: " + node.getName() + " from the user shortcuts list."); } } catch (Throwable err) { Utils.addErrorMessage(MessageFormat.format( Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err); try { if (tx != null) { tx.rollback(); } } catch (Exception tex) { } } }
From source file:org.alfresco.web.bean.users.UserShortcutsBean.java
/** * Action handler bound to the user shortcuts Shelf component called when a node is clicked *//*from ww w . j a v a2 s.c o m*/ public void click(ActionEvent event) { // work out which node was clicked from the event data UIShortcutsShelfItem.ShortcutEvent shortcutEvent = (UIShortcutsShelfItem.ShortcutEvent) event; Node selectedNode = getShortcuts().get(shortcutEvent.Index); try { if (getPermissionService().hasPermission(selectedNode.getNodeRef(), PermissionService.READ) == AccessStatus.ALLOWED) { if (getNodeService().exists(selectedNode.getNodeRef()) == false) { throw new InvalidNodeRefException(selectedNode.getNodeRef()); } DictionaryService dd = Repository.getServiceRegistry(FacesContext.getCurrentInstance()) .getDictionaryService(); if (dd.isSubClass(selectedNode.getType(), ContentModel.TYPE_FOLDER)) { // then navigate to the appropriate node in UI // use browse bean functionality for this as it will update the breadcrumb for us this.browseBean.updateUILocation(selectedNode.getNodeRef()); } else if (dd.isSubClass(selectedNode.getType(), ContentModel.TYPE_CONTENT)) { // view details for document this.browseBean.setupContentAction(selectedNode.getId(), true); FacesContext fc = FacesContext.getCurrentInstance(); fc.getApplication().getNavigationHandler().handleNavigation(fc, null, "dialog:showDocDetails"); } } else { Utils.addErrorMessage( Application.getMessage(FacesContext.getCurrentInstance(), "error_shortcut_permissions")); } } catch (InvalidNodeRefException refErr) { Utils.addErrorMessage(MessageFormat.format( Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { selectedNode.getId() })); // remove item from the shortcut list UserTransaction tx = null; try { FacesContext context = FacesContext.getCurrentInstance(); tx = Repository.getUserTransaction(context); tx.begin(); List<String> shortcuts = getShortcutList(context); if (shortcuts.size() > shortcutEvent.Index) { // remove the shortcut from the saved list and persist back shortcuts.remove(shortcutEvent.Index); PreferencesService.getPreferences(context).setValue(PREF_SHORTCUTS, (Serializable) shortcuts); // commit the transaction tx.commit(); // remove shortcut Node from the in-memory list Node node = getShortcuts().remove(shortcutEvent.Index); if (logger.isDebugEnabled()) logger.debug("Removed deleted node: " + node.getName() + " from the user shortcuts list."); } } catch (Throwable err) { try { if (tx != null) { tx.rollback(); } } catch (Exception tex) { } } } }
From source file:org.alfresco.web.bean.wcm.AVMBrowseBean.java
/** * Build the lists of files and folders within the current browsing path in a website space *//*from w w w . j a va 2 s . c o m*/ private void buildDirectoryNodes() { UserTransaction tx = null; try { FacesContext context = FacesContext.getCurrentInstance(); tx = Repository.getUserTransaction(context, true); tx.begin(); Map<String, AVMNodeDescriptor> nodes = getAvmService().getDirectoryListing(-1, getCurrentPath()); this.files = new ArrayList<Map>(nodes.size()); this.folders = new ArrayList<Map>(nodes.size()); for (String name : nodes.keySet()) { AVMNodeDescriptor avmRef = nodes.get(name); // build and add the client representation of the AVM node addAVMNodeResult(avmRef); } // commit the transaction tx.commit(); } catch (Throwable err) { Utils.addErrorMessage(MessageFormat.format( Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err); this.folders = Collections.<Map>emptyList(); this.files = Collections.<Map>emptyList(); try { if (tx != null) { tx.rollback(); } } catch (Exception tex) { } } }
From source file:org.alfresco.web.bean.wcm.AVMBrowseBean.java
/** * Build the lists of files and folders from the current search context in a website space */// w w w . j av a 2 s . c om private void buildSearchNodes() { String query = this.searchContext.buildQuery(getMinimumSearchLength()); if (query == null) { this.folders = Collections.<Map>emptyList(); this.files = Collections.<Map>emptyList(); return; } UserTransaction tx = null; ResultSet results = null; try { FacesContext context = FacesContext.getCurrentInstance(); tx = Repository.getUserTransaction(context, true); tx.begin(); // build up the search parameters SearchParameters sp = new SearchParameters(); sp.setLanguage(SearchService.LANGUAGE_LUCENE); sp.setQuery(query); // add the Staging Store for this website - it is the only searchable store for now sp.addStore(new StoreRef(StoreRef.PROTOCOL_AVM, getStagingStore())); // limit search results size as configured int searchLimit = Application.getClientConfig(context).getSearchMaxResults(); if (searchLimit > 0) { sp.setLimitBy(LimitBy.FINAL_SIZE); sp.setLimit(searchLimit); } results = getSearchService().query(sp); if (logger.isDebugEnabled()) { logger.debug("Search results returned: " + results.length()); } // filter hidden folders above the web app boolean isStagingStore = getIsStagingStore(); int sandboxPathLength = AVMUtil.getSandboxPath(getCurrentPath()).length(); this.files = new ArrayList<Map>(results.length()); this.folders = new ArrayList<Map>(results.length()); for (ResultSetRow row : results) { NodeRef nodeRef = row.getNodeRef(); // Modify the path to point to the current user sandbox - this change is performed so // that any action permission evaluators will correctly resolve for the current user. // Therefore deleted node will be filtered out by the lookup() call, but some text based // results may be incorrect - however a note is provided in the search UI to indicate this. String path = AVMNodeConverter.ToAVMVersionPath(nodeRef).getSecond(); if (isStagingStore == false) { path = getSandbox() + ':' + AVMUtil.getStoreRelativePath(path); } if (path.length() > sandboxPathLength) { AVMNodeDescriptor avmRef = getAvmService().lookup(-1, path); if (avmRef != null) { AVMNode node = addAVMNodeResult(avmRef); // add extra properties for search results lists node.addPropertyResolver("displayPath", AVMNode.RESOLVER_DISPLAY_PATH); node.addPropertyResolver("parentPath", AVMNode.RESOLVER_PARENT_PATH); } } } // commit the transaction tx.commit(); } catch (Throwable err) { Utils.addErrorMessage(MessageFormat.format( Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err); this.folders = Collections.<Map>emptyList(); this.files = Collections.<Map>emptyList(); try { if (tx != null) { tx.rollback(); } } catch (Exception tex) { } } finally { if (results != null) { results.close(); } } }
From source file:org.alfresco.web.bean.wcm.AVMBrowseBean.java
/** * Undo changes to a single node/*from w ww . j a v a 2 s. c o m*/ */ public void revertNode(ActionEvent event) { String avmPath = getPathFromEventArgs(event); String sbStoreId = WCMUtil.getSandboxStoreId(avmPath); List<String> namesForDisplayMsg = new LinkedList<String>(); UserTransaction tx = null; final FacesContext context = FacesContext.getCurrentInstance(); try { tx = Repository.getUserTransaction(context, false); tx.begin(); AVMNodeDescriptor node = getAvmService().lookup(-1, avmPath, true); if (node != null) { FormInstanceData fid = null; if (getAvmService().hasAspect(-1, avmPath, WCMAppModel.ASPECT_RENDITION)) { fid = this.getFormsService().getRendition(-1, avmPath).getPrimaryFormInstanceData(); } else if (getAvmService().hasAspect(-1, avmPath, WCMAppModel.ASPECT_FORM_INSTANCE_DATA)) { fid = this.getFormsService().getFormInstanceData(-1, avmPath); } List<String> paths = new ArrayList<String>(); if (fid != null) { paths.add(WCMUtil.getStoreRelativePath(fid.getPath())); namesForDisplayMsg.add(fid.getName()); for (Rendition r : fid.getRenditions()) { paths.add(WCMUtil.getStoreRelativePath(r.getPath())); namesForDisplayMsg.add(r.getName()); } } else { paths.add(WCMUtil.getStoreRelativePath(avmPath)); namesForDisplayMsg.add(node.getName()); } getSandboxService().revertList(sbStoreId, paths); } // commit the transaction tx.commit(); // if we get here, all was well - output friendly status message to the user this.displayStatusMessage(context, MessageFormat.format(Application.getMessage(context, MSG_REVERT_SUCCESS), StringUtils.join(namesForDisplayMsg.toArray(), ", "), namesForDisplayMsg.size())); } catch (Throwable err) { err.printStackTrace(System.err); Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_GENERIC), err.getMessage()), err); try { if (tx != null) { tx.rollback(); } } catch (Exception tex) { } } }
From source file:org.alfresco.web.bean.wcm.AVMBrowseBean.java
/** * Event handler that transitions a 'submitpending' task to effectively * bypass the lauch date and immediately submit the items. * //from ww w . j ava 2 s . c o m * @param event The event */ public void promotePendingSubmission(ActionEvent event) { UIActionLink link = (UIActionLink) event.getComponent(); Map<String, String> params = link.getParameterMap(); String taskId = params.get("taskId"); UserTransaction tx = null; try { FacesContext context = FacesContext.getCurrentInstance(); tx = Repository.getUserTransaction(context, false); tx.begin(); // transition the task this.getWorkflowService().endTask(taskId, "launch"); // commit the transaction tx.commit(); } catch (Throwable err) { Utils.addErrorMessage(MessageFormat.format( Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err); try { if (tx != null) { tx.rollback(); } } catch (Exception tex) { } } }
From source file:org.alfresco.web.bean.wcm.AVMBrowseBean.java
/** * Event handler that cancels a pending submission. * //from w w w . j av a 2 s . c o m * @param event The event */ public void cancelPendingSubmission(ActionEvent event) { UIActionLink link = (UIActionLink) event.getComponent(); Map<String, String> params = link.getParameterMap(); String workflowId = params.get("workflowInstanceId"); UserTransaction tx = null; try { FacesContext context = FacesContext.getCurrentInstance(); tx = Repository.getUserTransaction(context, false); tx.begin(); // cancel the workflow this.getWorkflowService().cancelWorkflow(workflowId); // commit the transaction tx.commit(); } catch (Throwable err) { Utils.addErrorMessage(MessageFormat.format( Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err); try { if (tx != null) { tx.rollback(); } } catch (Exception tex) { } } }
From source file:org.alfresco.web.bean.wcm.AVMEditBean.java
/** * Action called upon completion of the Update File page *//*from w w w . j av a 2 s.c o m*/ public String updateFileOK() { String outcome = null; UserTransaction tx = null; AVMNode node = getAvmNode(); if (node != null && this.getFileName() != null) { try { FacesContext context = FacesContext.getCurrentInstance(); tx = Repository.getUserTransaction(context); tx.begin(); // get an updating writer that we can use to modify the content on the current node final ContentWriter writer = this.getAvmService().getContentWriter(node.getPath(), true); // also update the mime type in case a different type of file is uploaded String mimeType = Repository.getMimeTypeForFileName(context, this.fileName); writer.setMimetype(mimeType); writer.putContent(this.file); // commit the transaction tx.commit(); if (this.getAvmService().hasAspect(-1, node.getPath(), WCMAppModel.ASPECT_FORM_INSTANCE_DATA)) { this.regenerateRenditions(); } // Possibly notify virt server AVMUtil.updateVServerWebapp(node.getPath(), false); // clear action context resetState(); outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME; } catch (Throwable err) { // rollback the transaction try { if (tx != null) { tx.rollback(); } } catch (Exception tex) { } Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_UPDATE) + err.getMessage(), err); } } return outcome; }
From source file:org.alfresco.web.bean.wcm.ManageReviewTaskDialog.java
@Override public void init(Map<String, String> parameters) { super.init(parameters); FacesContext context = FacesContext.getCurrentInstance(); UserTransaction tx = null; try {/* w ww.jav a 2 s .co m*/ tx = Repository.getUserTransaction(context, true); tx.begin(); // try and retrieve the link validation report from the workflow // store, if present setup the validation state on AVMBrowseBean this.store = this.workflowPackage.getStoreRef().getIdentifier(); // get the web project noderef for the workflow store String wpStoreId = WCMUtil.getWebProjectStoreId(this.store); this.webProjectRef = getWebProjectService() .getWebProjectNodeFromStore(WCMUtil.getWebProjectStoreId(this.store)); if (this.webProjectRef == null) { String mesg = MessageFormat.format(Application.getMessage(context, MSG_WEB_PRJ_DOES_NOT_EXIST), wpStoreId); throw new AlfrescoRuntimeException(mesg); } // 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); } }
From source file:org.alfresco.web.bean.wcm.SetPermissionsDialog.java
/** * Query callback method executed by the Generic Picker component. This method is part of the contract to the Generic Picker, it is up to the backing bean to execute whatever * query is appropriate and return the results. * //from w w w . j av a 2s .c om * @param filterIndex Index of the filter drop-down selection * @param contains Text from the contains textbox * @return An array of SelectItem objects containing the results to display in the picker. */ public SelectItem[] pickerCallback(int filterIndex, String contains) { FacesContext context = FacesContext.getCurrentInstance(); SelectItem[] items; UserTransaction tx = null; try { tx = Repository.getUserTransaction(context, true); tx.begin(); List<SelectItem> results = new ArrayList<SelectItem>(); if (filterIndex == 0) { List<PersonInfo> persons = getPersonService().getPeople(Utils.generatePersonFilter(contains.trim()), true, Utils.generatePersonSort(), new PagingRequest(Utils.getPersonMaxResults(), null)) .getPage(); for (int index = 0; index < persons.size(); index++) { PersonInfo person = persons.get(index); String firstName = person.getFirstName(); String lastName = person.getLastName(); String username = person.getUserName(); if (username != null) { SelectItem item = new SortableSelectItem(username, firstName + " " + lastName + " [" + username + "]", lastName); results.add(item); } } } else { Set<String> groups; if (contains != null && contains.startsWith("*")) { // if the search term starts with a wildcard use Lucene based search to find groups (results will be inconsistent) String term = contains.trim() + "*"; groups = getAuthorityService().findAuthorities(AuthorityType.GROUP, null, false, term, AuthorityService.ZONE_APP_DEFAULT); } else { // all other searches use the canned query so search results are consistent PagingResults<String> pagedResults = getAuthorityService().getAuthorities(AuthorityType.GROUP, AuthorityService.ZONE_APP_DEFAULT, contains, true, true, new PagingRequest(10000)); groups = new LinkedHashSet<String>(pagedResults.getPage()); } // add the EVERYONE group to the results groups.addAll(getAuthorityService().getAllAuthorities(AuthorityType.EVERYONE)); String groupDisplayName; for (String group : groups) { // get display name, if not present strip prefix from group id groupDisplayName = getAuthorityService().getAuthorityDisplayName(group); if (groupDisplayName == null || groupDisplayName.length() == 0) { groupDisplayName = group.substring(PermissionService.GROUP_PREFIX.length()); } results.add(new SortableSelectItem(group, groupDisplayName, groupDisplayName)); } } items = new SelectItem[results.size()]; results.toArray(items); Arrays.sort(items); // commit the transaction tx.commit(); } catch (Throwable err) { Utils.addErrorMessage(MessageFormat.format( Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err); try { if (tx != null) { tx.rollback(); } } catch (Exception tex) { } items = new SelectItem[0]; } return items; }