Search in sources :

Example 11 with RetryingTransactionHelper

use of org.alfresco.repo.transaction.RetryingTransactionHelper in project acs-community-packaging by Alfresco.

the class DocumentDetailsDialog method applyClassifiable.

/**
 * Applies the classifiable aspect to the current document
 */
public void applyClassifiable() {
    try {
        RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(FacesContext.getCurrentInstance());
        RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {

            public Object execute() throws Throwable {
                // add the general classifiable aspect to the node
                getNodeService().addAspect(getDocument().getNodeRef(), ContentModel.ASPECT_GEN_CLASSIFIABLE, null);
                return null;
            }
        };
        txnHelper.doInTransaction(callback);
        // reset the state of the current document
        getDocument().reset();
    } catch (Throwable e) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_ASPECT_CLASSIFY), e.getMessage()), e);
        ReportedException.throwIfNecessary(e);
    }
}
Also used : RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)

Example 12 with RetryingTransactionHelper

use of org.alfresco.repo.transaction.RetryingTransactionHelper in project acs-community-packaging by Alfresco.

the class CheckinCheckoutDialog method updateFileOK.

/**
 * Action called upon completion of the Update File page
 */
public String updateFileOK(final FacesContext context, String outcome) {
    // NOTE: for update the document node _is_ the working document!
    final Node node = property.getDocument();
    if (node != null && this.getFileName() != null) {
        try {
            RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(FacesContext.getCurrentInstance());
            RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {

                public Object execute() throws Throwable {
                    if (logger.isDebugEnabled())
                        logger.debug("Trying to update content node Id: " + node.getId());
                    // get an updating writer that we can use to modify the content on the current node
                    ContentWriter writer = property.getContentService().getWriter(node.getNodeRef(), ContentModel.PROP_CONTENT, true);
                    // also update the mime type in case a different type of file is uploaded
                    String mimeType = Repository.getMimeTypeForFileName(context, property.getFileName());
                    writer.setMimetype(mimeType);
                    writer.putContent(property.getFile());
                    return null;
                }
            };
            txnHelper.doInTransaction(callback);
            // clear action context
            property.setDocument(null);
            resetState();
            outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
        } catch (Throwable err) {
            Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_UPDATE) + err.getMessage(), err);
            ReportedException.throwIfNecessary(err);
        }
    } else {
        logger.warn("WARNING: updateFileOK called without a current Document!");
    }
    return outcome;
}
Also used : ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) Node(org.alfresco.web.bean.repository.Node)

Example 13 with RetryingTransactionHelper

use of org.alfresco.repo.transaction.RetryingTransactionHelper in project acs-community-packaging by Alfresco.

the class DocumentDetailsDialog method applyVersionable.

/**
 * Applies the versionable aspect to the current document
 */
public void applyVersionable() {
    try {
        FacesContext context = FacesContext.getCurrentInstance();
        RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(context);
        RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {

            public Object execute() throws Throwable {
                // add the versionable aspect to the node
                getNodeService().addAspect(getDocument().getNodeRef(), ContentModel.ASPECT_VERSIONABLE, null);
                return null;
            }
        };
        txnHelper.doInTransaction(callback);
        // reset the state of the current document
        getDocument().reset();
        // get hold of the main property sheet on the page and remove the children to force a refresh
        UIComponent comp = context.getViewRoot().findComponent("dialog:dialog-body:document-props");
        if (comp != null) {
            comp.getChildren().clear();
        }
    } catch (Throwable e) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_ASPECT_VERSIONING), e.getMessage()), e);
        ReportedException.throwIfNecessary(e);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) UIComponent(javax.faces.component.UIComponent)

Example 14 with RetryingTransactionHelper

use of org.alfresco.repo.transaction.RetryingTransactionHelper in project acs-community-packaging by Alfresco.

the class DeleteCategoryDialog method finishDelete.

public String finishDelete() {
    String outcome = DEFAULT_OUTCOME;
    if (getActionCategory() != null) {
        try {
            FacesContext context = FacesContext.getCurrentInstance();
            RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(context);
            RetryingTransactionCallback<NodeRef> callback = new RetryingTransactionCallback<NodeRef>() {

                @SuppressWarnings("unchecked")
                public NodeRef execute() throws Throwable {
                    // delete the category node using the nodeservice
                    NodeRef categoryNodeRef = getActionCategory().getNodeRef();
                    getCategoryService().deleteCategory(categoryNodeRef);
                    // all the associations to the category should be removed too
                    if (getMembers() != null && getMembers().size() > 0) {
                        for (ChildAssociationRef childRef : getMembers()) {
                            List<NodeRef> list = new ArrayList<NodeRef>(getMembers().size());
                            NodeRef member = childRef.getChildRef();
                            Collection<NodeRef> categories = (Collection<NodeRef>) getNodeService().getProperty(member, ContentModel.PROP_CATEGORIES);
                            for (NodeRef category : categories) {
                                if (category.equals(categoryNodeRef) == false) {
                                    list.add(category);
                                }
                            }
                            // persist the list back to the repository
                            getNodeService().setProperty(member, ContentModel.PROP_CATEGORIES, (Serializable) list);
                        }
                    }
                    return categoryNodeRef;
                }
            };
            NodeRef categoryNodeRef = txnHelper.doInTransaction(callback);
            // Figure out if the deletion is made by an icon or by a list of actions
            CategoriesDialog categoriesDialog = (CategoriesDialog) UIContextService.getInstance(FacesContext.getCurrentInstance()).getRegisteredBean(CategoriesDialog.CATEGORIES_DIALOG_CLASS_NAME);
            setLocation(categoriesDialog.getLocation());
            List<IBreadcrumbHandler> location = getLocation();
            CategoryBreadcrumbHandler handler = (CategoryBreadcrumbHandler) location.get(location.size() - 1);
            setCategoryFlag(!handler.toString().equals(getCategory().getName()));
            // clear action context
            setActionCategory(null);
        } catch (Throwable err) {
            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
            outcome = null;
            ReportedException.throwIfNecessary(err);
        }
    }
    return outcome;
}
Also used : FacesContext(javax.faces.context.FacesContext) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) IBreadcrumbHandler(org.alfresco.web.ui.common.component.IBreadcrumbHandler) ArrayList(java.util.ArrayList) CategoryBreadcrumbHandler(org.alfresco.web.bean.categories.CategoriesDialog.CategoryBreadcrumbHandler) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) Collection(java.util.Collection)

Example 15 with RetryingTransactionHelper

use of org.alfresco.repo.transaction.RetryingTransactionHelper in project acs-community-packaging by Alfresco.

the class BaseDetailsBean method approve.

/**
 * Event handler called to handle the approve step of the simple workflow
 *
 * @param event The event that was triggered
 */
public void approve(ActionEvent event) {
    UIActionLink link = (UIActionLink) event.getComponent();
    Map<String, String> params = link.getParameterMap();
    String id = params.get("id");
    if (id == null || id.length() == 0) {
        throw new AlfrescoRuntimeException("approve called without an id");
    }
    final NodeRef docNodeRef = new NodeRef(Repository.getStoreRef(), id);
    try {
        RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(FacesContext.getCurrentInstance());
        RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {

            public Object execute() throws Throwable {
                // call the service to perform the approve
                WorkflowUtil.approve(docNodeRef, getNodeService(), getCopyService());
                return null;
            }
        };
        txnHelper.doInTransaction(callback);
        // if this was called via the node details dialog we need to reset the node
        if (getNode() != null) {
            getNode().reset();
        }
        // also make sure the UI will get refreshed
        UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans();
    } catch (Throwable e) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_WORKFLOW_APPROVE), e.getMessage()), e);
        ReportedException.throwIfNecessary(e);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) UIActionLink(org.alfresco.web.ui.common.component.UIActionLink) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Aggregations

RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)25 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)20 FacesContext (javax.faces.context.FacesContext)8 NodeRef (org.alfresco.service.cmr.repository.NodeRef)8 Serializable (java.io.Serializable)7 HashMap (java.util.HashMap)5 QName (org.alfresco.service.namespace.QName)5 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)4 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)3 NodeService (org.alfresco.service.cmr.repository.NodeService)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 FacesMessage (javax.faces.application.FacesMessage)2 UserTransaction (javax.transaction.UserTransaction)2 ServiceRegistry (org.alfresco.service.ServiceRegistry)2 ContentData (org.alfresco.service.cmr.repository.ContentData)2 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)2 TransactionService (org.alfresco.service.transaction.TransactionService)2 Node (org.alfresco.web.bean.repository.Node)2