Search in sources :

Example 1 with CategoryBreadcrumbHandler

use of org.alfresco.web.bean.categories.CategoriesDialog.CategoryBreadcrumbHandler 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 2 with CategoryBreadcrumbHandler

use of org.alfresco.web.bean.categories.CategoriesDialog.CategoryBreadcrumbHandler in project acs-community-packaging by Alfresco.

the class EditCategoryDialog method finishEdit.

public String finishEdit() {
    String outcome = DEFAULT_OUTCOME;
    try {
        // update the category node
        NodeRef nodeRef = getActionCategory().getNodeRef();
        getNodeService().setProperty(nodeRef, ContentModel.PROP_NAME, getName());
        // ALF-1788 Need to rename the association
        ChildAssociationRef assocRef = getNodeService().getPrimaryParent(nodeRef);
        QName qname = QName.createQName(assocRef.getQName().getNamespaceURI(), QName.createValidLocalName(name));
        getNodeService().moveNode(assocRef.getChildRef(), assocRef.getParentRef(), assocRef.getTypeQName(), qname);
        // apply the titled aspect - for description
        if (getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_TITLED) == false) {
            Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(1, 1.0f);
            titledProps.put(ContentModel.PROP_DESCRIPTION, getDescription());
            getNodeService().addAspect(nodeRef, ContentModel.ASPECT_TITLED, titledProps);
        } else {
            getNodeService().setProperty(nodeRef, ContentModel.PROP_DESCRIPTION, getDescription());
        }
        // Figure out if the editing 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);
        if (!handler.toString().equals(getCategory().getName())) {
            setCategoryFlag(true);
        } else {
            setCategoryFlag(false);
        }
        Node categoryNode = new Node(nodeRef);
        setCategory(categoryNode);
    } 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 : Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) IBreadcrumbHandler(org.alfresco.web.ui.common.component.IBreadcrumbHandler) Node(org.alfresco.web.bean.repository.Node) CategoryBreadcrumbHandler(org.alfresco.web.bean.categories.CategoriesDialog.CategoryBreadcrumbHandler) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef)

Aggregations

ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 CategoryBreadcrumbHandler (org.alfresco.web.bean.categories.CategoriesDialog.CategoryBreadcrumbHandler)2 IBreadcrumbHandler (org.alfresco.web.ui.common.component.IBreadcrumbHandler)2 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 FacesContext (javax.faces.context.FacesContext)1 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)1 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)1 QName (org.alfresco.service.namespace.QName)1 Node (org.alfresco.web.bean.repository.Node)1