Search in sources :

Example 56 with UserTransaction

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

the class ForumsBean method getNodes.

private void getNodes() {
    long startTime = 0;
    if (logger.isDebugEnabled())
        startTime = System.currentTimeMillis();
    UserTransaction tx = null;
    try {
        FacesContext context = FacesContext.getCurrentInstance();
        tx = Repository.getUserTransaction(context, true);
        tx.begin();
        // get the current space from NavigationBean
        String parentNodeId = this.navigator.getCurrentNodeId();
        NodeRef parentRef;
        if (parentNodeId == null) {
            // no specific parent node specified - use the root node
            parentRef = this.getNodeService().getRootNode(Repository.getStoreRef());
        } else {
            // build a NodeRef for the specified Id and our store
            parentRef = new NodeRef(Repository.getStoreRef(), parentNodeId);
        }
        List<ChildAssociationRef> childRefs = this.getNodeService().getChildAssocs(parentRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
        this.forums = new ArrayList<Node>(childRefs.size());
        this.topics = new ArrayList<Node>(childRefs.size());
        this.posts = new ArrayList<Node>(childRefs.size());
        for (ChildAssociationRef ref : childRefs) {
            // create our Node representation from the NodeRef
            NodeRef nodeRef = ref.getChildRef();
            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
                TypeDefinition typeDef = this.getDictionaryService().getType(type);
                if (typeDef != null) {
                    if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
                        if (this.getDictionaryService().isSubClass(type, ForumModel.TYPE_FORUMS) || this.getDictionaryService().isSubClass(type, ForumModel.TYPE_FORUM)) {
                            // create our Node representation
                            MapNode node = new MapNode(nodeRef, this.getNodeService(), true);
                            node.addPropertyResolver("icon", this.browseBean.resolverSpaceIcon);
                            node.addPropertyResolver("smallIcon", this.browseBean.resolverSmallIcon);
                            this.forums.add(node);
                        }
                        if (this.getDictionaryService().isSubClass(type, ForumModel.TYPE_TOPIC)) {
                            // create our Node representation
                            MapNode node = new MapNode(nodeRef, this.getNodeService(), true);
                            node.addPropertyResolver("icon", this.browseBean.resolverSpaceIcon);
                            node.addPropertyResolver("smallIcon", this.browseBean.resolverSmallIcon);
                            node.addPropertyResolver("replies", this.resolverReplies);
                            this.topics.add(node);
                        } else if (this.getDictionaryService().isSubClass(type, ForumModel.TYPE_POST)) {
                            // create our Node representation
                            MapNode node = new MapNode(nodeRef, this.getNodeService(), true);
                            this.browseBean.setupCommonBindingProperties(node);
                            node.addPropertyResolver("smallIcon", this.browseBean.resolverSmallIcon);
                            node.addPropertyResolver("message", this.resolverContent);
                            node.addPropertyResolver("replyTo", this.resolverReplyTo);
                            this.posts.add(node);
                        }
                    }
                } else {
                    if (logger.isWarnEnabled())
                        logger.warn("Found invalid object in database: id = " + nodeRef + ", type = " + type);
                }
            }
        }
        // commit the transaction
        tx.commit();
    } catch (InvalidNodeRefException refErr) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { refErr.getNodeRef() }));
        this.forums = Collections.<Node>emptyList();
        this.topics = Collections.<Node>emptyList();
        this.posts = Collections.<Node>emptyList();
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    } catch (Throwable err) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
        this.forums = Collections.<Node>emptyList();
        this.topics = Collections.<Node>emptyList();
        this.posts = Collections.<Node>emptyList();
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    }
    if (logger.isDebugEnabled()) {
        long endTime = System.currentTimeMillis();
        logger.debug("Time to query and build forums nodes: " + (endTime - startTime) + "ms");
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode) MapNode(org.alfresco.web.bean.repository.MapNode) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Example 57 with UserTransaction

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

the class EditOfflineDialog method checkoutFile.

/**
 * Checkout document to the same space as original one and then add the
 * OFFLINE_EDITING property.
 */
private void checkoutFile(Node node) {
    UserTransaction tx = null;
    FacesContext context = FacesContext.getCurrentInstance();
    if (node != null) {
        try {
            tx = Repository.getUserTransaction(context, false);
            tx.begin();
            if (logger.isDebugEnabled())
                logger.debug("Trying to checkout content node Id: " + node.getId());
            NodeRef workingCopyRef = null;
            // checkout the content to the current space
            workingCopyRef = property.getVersionOperationsService().checkout(node.getNodeRef());
            getNodeService().setProperty(workingCopyRef, ContentModel.PROP_WORKING_COPY_MODE, OFFLINE_EDITING);
            // set the working copy Node instance
            Node workingCopy = new Node(workingCopyRef);
            property.setWorkingDocument(workingCopy);
            // create content URL to the content download servlet with ID and
            // expected filename
            String url = DownloadContentServlet.generateDownloadURL(workingCopyRef, workingCopy.getName());
            workingCopy.getProperties().put("url", url);
            workingCopy.getProperties().put("fileType32", FileTypeImageUtils.getFileTypeImage(workingCopy.getName(), false));
            // commit the transaction
            tx.commit();
        } catch (Throwable err) {
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
            Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_CHECKOUT) + err.getMessage(), err);
        }
    } else {
        logger.warn("WARNING: checkoutFile called without a current Document!");
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Node(org.alfresco.web.bean.repository.Node)

Example 58 with UserTransaction

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

the class EditOnlineDialog method handle.

/**
 * Base handling method.
 *
 * @param event ActionEvent
 */
public void handle(ActionEvent event) {
    super.setupContentAction(event);
    Node node = property.getDocument();
    if (node != null) {
        UserTransaction tx = null;
        FacesContext context = FacesContext.getCurrentInstance();
        try {
            tx = Repository.getUserTransaction(context, false);
            tx.begin();
            // if current content is already working copy then we don't checkout
            if (node.hasAspect(ContentModel.ASPECT_WORKING_COPY) == false) {
                // if checkout is successful, then checkoutFile sets property workingDocument
                checkoutFile(FacesContext.getCurrentInstance(), null);
                Node workingCopyNode = property.getWorkingDocument();
                if (workingCopyNode != null) {
                    getRuleService().disableRules();
                    try {
                        // set working copy node as document for editing
                        property.setDocument(workingCopyNode);
                        getNodeService().setProperty(workingCopyNode.getNodeRef(), ContentModel.PROP_WORKING_COPY_MODE, ONLINE_EDITING);
                    } finally {
                        getRuleService().enableRules();
                    }
                }
            }
            // commit the transaction
            tx.commit();
        } catch (Throwable err) {
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
            property.setDocument(null);
        }
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) Node(org.alfresco.web.bean.repository.Node)

Example 59 with UserTransaction

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

the class WorkflowBean method getTasksCompleted.

/**
 * Returns a list of nodes representing the completed tasks the
 * current user has.
 *
 * @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;
}
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) ClientConfigElement(org.alfresco.web.config.ClientConfigElement) WorkflowTaskQuery(org.alfresco.service.cmr.workflow.WorkflowTaskQuery)

Example 60 with UserTransaction

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

the class WorkflowBean method getPooledTasks.

/**
 * Returns a list of nodes representing the "pooled" to do tasks the
 * current user has.
 *
 * @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;
}
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)

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