Search in sources :

Example 51 with UserTransaction

use of javax.transaction.UserTransaction in project acs-community-packaging by Alfresco.

the class SpaceDetailsDialog method applyClassifiable.

/**
 * Applies the classifiable aspect to the current document
 */
public void applyClassifiable() {
    UserTransaction tx = null;
    try {
        tx = Repository.getUserTransaction(FacesContext.getCurrentInstance());
        tx.begin();
        // add the general classifiable aspect to the node
        getNodeService().addAspect(getSpace().getNodeRef(), ContentModel.ASPECT_GEN_CLASSIFIABLE, null);
        // commit the transaction
        tx.commit();
        // reset the state of the current document
        getSpace().reset();
    } catch (Throwable e) {
        // rollback the transaction
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception ex) {
        }
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_ASPECT_CLASSIFY), e.getMessage()), e);
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction)

Example 52 with UserTransaction

use of javax.transaction.UserTransaction in project acs-community-packaging by Alfresco.

the class RulesDialog method reapplyRules.

/**
 * Reapply the currently defines rules to the
 * @param event ActionEvent
 */
public void reapplyRules(ActionEvent event) {
    boolean toChildren = false;
    UIActionLink link = (UIActionLink) event.getComponent();
    Map<String, String> params = link.getParameterMap();
    String toChildrenStr = params.get("toChildren");
    if (toChildrenStr != null) {
        toChildren = new Boolean(toChildrenStr).booleanValue();
    }
    FacesContext fc = FacesContext.getCurrentInstance();
    UserTransaction tx = null;
    try {
        tx = Repository.getUserTransaction(fc);
        tx.begin();
        // Set the include inherited parameter to match the current filter value
        boolean executeInherited = true;
        if (this.filterModeMode.equals(LOCAL)) {
            executeInherited = false;
        }
        // Reapply the rules
        reapplyRules(this.getSpace().getNodeRef(), executeInherited, toChildren);
        // TODO how do I get the message here ...
        String msg = Application.getMessage(fc, MSG_REAPPLY_RULES_SUCCESS);
        FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg);
        String formId = Utils.getParentForm(fc, event.getComponent()).getClientId(fc);
        fc.addMessage(formId + ":rulesList", facesMsg);
        // commit the transaction
        tx.commit();
    } catch (Throwable e) {
        // rollback the transaction
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception ex) {
        }
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(fc, Repository.ERROR_GENERIC), e.getMessage()), e);
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) UIActionLink(org.alfresco.web.ui.common.component.UIActionLink) FacesMessage(javax.faces.application.FacesMessage)

Example 53 with UserTransaction

use of javax.transaction.UserTransaction in project acs-community-packaging by Alfresco.

the class UserMembersBean method finishOK.

/**
 * Action handler called when the Finish button is clicked on the Edit User Roles page
 */
public String finishOK() {
    String outcome = OUTCOME_FINISH;
    FacesContext context = FacesContext.getCurrentInstance();
    // persist new user permissions
    if (this.personRoles != null && getPersonAuthority() != null) {
        UserTransaction tx = null;
        try {
            tx = Repository.getUserTransaction(context);
            tx.begin();
            // clear the currently set permissions for this user
            // and add each of the new permissions in turn
            final NodeRef nodeRef = getNode().getNodeRef();
            if (this.getPermissionService().hasPermission(nodeRef, PermissionService.CHANGE_PERMISSIONS) == AccessStatus.ALLOWED) {
                AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>() {

                    public Object doWork() throws Exception {
                        getPermissionService().clearPermission(nodeRef, getPersonAuthority());
                        for (PermissionWrapper wrapper : personRoles) {
                            getPermissionService().setPermission(nodeRef, getPersonAuthority(), wrapper.getPermission(), true);
                        }
                        return null;
                    }
                }, AuthenticationUtil.getSystemUserName());
            }
            tx.commit();
        } catch (Exception err) {
            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_GENERIC), err.getMessage()), err);
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
            outcome = null;
        }
    }
    return outcome;
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Example 54 with UserTransaction

use of javax.transaction.UserTransaction in project acs-community-packaging by Alfresco.

the class UserShortcutsBean method createShortcut.

// ------------------------------------------------------------------------------
// Action method handlers
/**
 * Action handler called when a new shortcut is to be added to the list
 */
public void createShortcut(ActionEvent event) {
    // TODO: add this action to the Details screen for Space and Document
    UIActionLink link = (UIActionLink) event.getComponent();
    Map<String, String> params = link.getParameterMap();
    String id = params.get("id");
    if (id != null && id.length() != 0) {
        try {
            NodeRef ref = new NodeRef(Repository.getStoreRef(), id);
            Node node = new Node(ref);
            boolean foundShortcut = false;
            for (int i = 0; i < getShortcuts().size(); i++) {
                if (node.getId().equals(getShortcuts().get(i).getId())) {
                    // found same node already in the list - so we don't need to add it again
                    foundShortcut = true;
                    break;
                }
            }
            if (foundShortcut == false) {
                // add to persistent store
                UserTransaction tx = null;
                try {
                    FacesContext context = FacesContext.getCurrentInstance();
                    tx = Repository.getUserTransaction(context);
                    tx.begin();
                    List<String> shortcuts = getShortcutList(context);
                    shortcuts.add(node.getNodeRef().getId());
                    PreferencesService.getPreferences(context).setValue(PREF_SHORTCUTS, (Serializable) shortcuts);
                    // commit the transaction
                    tx.commit();
                    // add our new shortcut Node to the in-memory list
                    getShortcuts().add(node);
                    if (logger.isDebugEnabled())
                        logger.debug("Added node: " + node.getName() + " to 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) {
                    }
                }
            }
        } catch (InvalidNodeRefException refErr) {
            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { id }));
        }
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) UIActionLink(org.alfresco.web.ui.common.component.UIActionLink) Node(org.alfresco.web.bean.repository.Node) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Example 55 with UserTransaction

use of javax.transaction.UserTransaction in project acs-community-packaging by Alfresco.

the class UserShortcutsBean method getShortcuts.

/**
 * @return the List of shortcut Nodes
 */
public List<Node> getShortcuts() {
    if (this.shortcuts == null) {
        List<String> shortcuts = null;
        NodeRef prefRef = null;
        UserTransaction tx = null;
        boolean rollback = false;
        try {
            FacesContext context = FacesContext.getCurrentInstance();
            tx = Repository.getUserTransaction(context);
            tx.begin();
            // get the shortcuts from the preferences for this user
            shortcuts = getShortcutList(context);
            if (shortcuts.size() != 0) {
                // each shortcut node ID is persisted as a list item in a well known property
                this.shortcuts = new ArrayList<Node>(shortcuts.size());
                for (int i = 0; i < shortcuts.size(); i++) {
                    NodeRef ref = new NodeRef(Repository.getStoreRef(), shortcuts.get(i));
                    try {
                        if (this.getNodeService().exists(ref) == true) {
                            Node node = new Node(ref);
                            // quick init properties while in the usertransaction
                            node.getProperties();
                            // save ref to the Node for rendering
                            this.shortcuts.add(node);
                        } else {
                            // we write the node list back again afterwards to correct this
                            if (logger.isDebugEnabled())
                                logger.debug("Found invalid shortcut node Id: " + ref.getId());
                        }
                    } catch (AccessDeniedException accessErr) {
                        // we write the node list back again afterwards to correct this
                        if (logger.isDebugEnabled())
                            logger.debug("Found invalid shortcut node Id: " + ref.getId());
                        rollback = true;
                    }
                }
            } else {
                this.shortcuts = new ArrayList<Node>(5);
            }
            if (rollback == false) {
                tx.commit();
            } else {
                tx.rollback();
            }
        } 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) {
            }
        }
        // write the valid shortcut IDs back to correct invalid node refs
        if (shortcuts != null && shortcuts.size() != this.shortcuts.size()) {
            try {
                shortcuts = new ArrayList<String>(this.shortcuts.size());
                for (int i = 0; i < this.shortcuts.size(); i++) {
                    shortcuts.add(this.shortcuts.get(i).getId());
                }
                PreferencesService.getPreferences().setValue(PREF_SHORTCUTS, (Serializable) shortcuts);
            } catch (Exception err) {
                Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
            }
        }
    }
    return this.shortcuts;
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) Node(org.alfresco.web.bean.repository.Node) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) NodeRef(org.alfresco.service.cmr.repository.NodeRef)

Aggregations

UserTransaction (javax.transaction.UserTransaction)642 EntityManager (javax.persistence.EntityManager)244 Test (org.testng.annotations.Test)187 Test (org.junit.Test)157 JPATest (org.jpwh.env.JPATest)138 InitialContext (javax.naming.InitialContext)62 BigDecimal (java.math.BigDecimal)53 HashMap (java.util.HashMap)52 IOException (java.io.IOException)50 Context (javax.naming.Context)49 List (java.util.List)47 FacesContext (javax.faces.context.FacesContext)43 NamingException (javax.naming.NamingException)43 NodeRef (org.alfresco.service.cmr.repository.NodeRef)43 Node (javax.jcr.Node)42 KieSession (org.kie.api.runtime.KieSession)42 Query (javax.persistence.Query)38 QueryingTest (org.jpwh.test.querying.QueryingTest)36 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)35 Item (org.jpwh.model.querying.Item)35