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;
}
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;
}
Aggregations