use of org.alfresco.service.cmr.repository.ChildAssociationRef in project acs-community-packaging by Alfresco.
the class NavigatorPluginBean method getMyHomeRootNodes.
/**
* Returns the root nodes for the my home panel.
* <p>
* As the user expands and collapses nodes in the client this
* cache will be updated with the appropriate nodes and states.
* </p>
*
* @return List of root nodes for the my home panel
*/
public List<TreeNode> getMyHomeRootNodes() {
if (this.myHomeRootNodes == null) {
this.myHomeRootNodes = new ArrayList<TreeNode>();
this.myHomeNodes = new HashMap<String, TreeNode>();
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true);
tx.begin();
// query for the child nodes of the user's home
NodeRef root = new NodeRef(Repository.getStoreRef(), Application.getCurrentUser(FacesContext.getCurrentInstance()).getHomeSpaceId());
List<ChildAssociationRef> childRefs = this.getNodeService().getChildAssocs(root, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
for (ChildAssociationRef ref : childRefs) {
NodeRef child = ref.getChildRef();
if (isAddableChild(child)) {
TreeNode node = createTreeNode(child);
this.myHomeRootNodes.add(node);
this.myHomeNodes.put(node.getNodeRef(), node);
}
}
tx.commit();
} catch (Throwable err) {
Utils.addErrorMessage("NavigatorPluginBean exception in getMyHomeRootNodes()", err);
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
}
}
return this.myHomeRootNodes;
}
use of org.alfresco.service.cmr.repository.ChildAssociationRef in project acs-community-packaging by Alfresco.
the class PickerBean method getTagNodes.
/**
* Return the JSON objects representing a list of cm:folder nodes.
*
* IN: "parent" - noderef (can be null) of the parent to retrieve the child folder nodes for. Null is valid
* and specifies the Company Home root as the parent.
* IN: "child" - non-null value of the child noderef to retrieve the siblings for - the parent value returned
* in the JSON response will be the parent of the specified child.
*
* The 16x16 pixel folder icon path is output as the 'icon' property for each child folder.
*/
@InvokeCommand.ResponseMimetype(value = MimetypeMap.MIMETYPE_HTML)
public void getTagNodes() throws Exception {
FacesContext fc = FacesContext.getCurrentInstance();
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true);
tx.begin();
Collection<ChildAssociationRef> childRefs;
NodeRef parentRef = null;
Map params = fc.getExternalContext().getRequestParameterMap();
String strParentRef = Utils.encode((String) params.get(ID_PARENT));
if (strParentRef == null || strParentRef.length() == 0) {
childRefs = this.getCategoryService().getRootCategories(Repository.getStoreRef(), ContentModel.ASPECT_TAGGABLE);
} else {
parentRef = new NodeRef(strParentRef);
childRefs = this.getCategoryService().getChildren(parentRef, CategoryService.Mode.SUB_CATEGORIES, CategoryService.Depth.IMMEDIATE);
}
JSONWriter out = new JSONWriter(fc.getResponseWriter());
out.startObject();
out.startValue(ID_PARENT);
out.startObject();
if (parentRef == null) {
out.writeNullValue(ID_ID);
out.writeValue(ID_NAME, Application.getMessage(fc, MSG_TAGS));
out.writeValue(ID_ISROOT, true);
out.writeValue(ID_SELECTABLE, false);
} else {
out.writeValue(ID_ID, strParentRef);
out.writeValue(ID_NAME, Repository.getNameForNode(this.getInternalNodeService(), parentRef));
}
out.endObject();
out.endValue();
out.startValue(ID_CHILDREN);
out.startArray();
for (ChildAssociationRef ref : childRefs) {
NodeRef nodeRef = ref.getChildRef();
out.startObject();
out.writeValue(ID_ID, nodeRef.toString());
out.writeValue(ID_NAME, Repository.getNameForNode(this.getInternalNodeService(), nodeRef));
out.endObject();
}
out.endArray();
out.endValue();
out.endObject();
tx.commit();
} catch (Throwable err) {
Utils.addErrorMessage("PickerBean exception in getTagNodes()", err);
fc.getResponseWriter().write("ERROR: " + err.getMessage());
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
}
}
use of org.alfresco.service.cmr.repository.ChildAssociationRef in project acs-community-packaging by Alfresco.
the class CategoriesDialog method getCategories.
/**
* @return The list of categories Nodes to display. Returns the list root categories or the
* list of sub-categories for the current category if set.
*/
public List<Node> getCategories() {
List<Node> categories;
UserTransaction tx = null;
try {
FacesContext context = FacesContext.getCurrentInstance();
tx = Repository.getUserTransaction(context, true);
tx.begin();
Collection<ChildAssociationRef> refs;
if (getCategoryRef() == null) {
// root categories
refs = getCategoryService().getCategories(Repository.getStoreRef(), ContentModel.ASPECT_GEN_CLASSIFIABLE, Depth.IMMEDIATE);
} else {
// sub-categories of an existing category
refs = getCategoryService().getChildren(getCategoryRef(), Mode.SUB_CATEGORIES, Depth.IMMEDIATE);
}
categories = new ArrayList<Node>(refs.size());
for (ChildAssociationRef child : refs) {
Node categoryNode = new Node(child.getChildRef());
// force early props init within transaction
categoryNode.getProperties();
categories.add(categoryNode);
}
// commit the transaction
tx.commit();
} catch (InvalidNodeRefException refErr) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { refErr.getNodeRef() }));
categories = 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);
categories = Collections.<Node>emptyList();
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
}
return categories;
}
use of org.alfresco.service.cmr.repository.ChildAssociationRef in project acs-community-packaging by Alfresco.
the class WorkspaceClipboardItem method paste.
/**
* @see org.alfresco.web.bean.clipboard.ClipboardItem#paste(javax.faces.context.FacesContext, java.lang.String, int)
*/
public boolean paste(final FacesContext fc, String viewId, final int action) {
final ServiceRegistry serviceRegistry = getServiceRegistry();
final RetryingTransactionHelper retryingTransactionHelper = serviceRegistry.getTransactionService().getRetryingTransactionHelper();
if (super.canCopyToViewId(viewId) || WORKSPACE_PASTE_VIEW_ID.equals(viewId) || FORUMS_PASTE_VIEW_ID.equals(viewId) || FORUM_PASTE_VIEW_ID.equals(viewId)) {
NavigationBean navigator = (NavigationBean) FacesHelper.getManagedBean(fc, NavigationBean.BEAN_NAME);
final NodeRef destRef = new NodeRef(Repository.getStoreRef(), navigator.getCurrentNodeId());
final DictionaryService dd = serviceRegistry.getDictionaryService();
final NodeService nodeService = serviceRegistry.getNodeService();
final FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
final CopyService copyService = serviceRegistry.getCopyService();
final MultilingualContentService multilingualContentService = serviceRegistry.getMultilingualContentService();
final boolean isPrimaryParent;
final ChildAssociationRef assocRef;
if (getParent() == null) {
assocRef = nodeService.getPrimaryParent(getNodeRef());
isPrimaryParent = true;
} else {
NodeRef parentNodeRef = getParent();
List<ChildAssociationRef> assocList = nodeService.getParentAssocs(getNodeRef());
ChildAssociationRef foundRef = null;
if (assocList != null) {
for (ChildAssociationRef assocListEntry : assocList) {
if (parentNodeRef.equals(assocListEntry.getParentRef())) {
foundRef = assocListEntry;
break;
}
}
}
assocRef = foundRef;
isPrimaryParent = parentNodeRef.equals(nodeService.getPrimaryParent(getNodeRef()).getParentRef());
}
// initial name to attempt the copy of the item with
String name = getName();
String translationPrefix = "";
if (action == UIClipboardShelfItem.ACTION_PASTE_LINK) {
// copy as link was specifically requested by the user
String linkTo = Application.getMessage(fc, MSG_LINK_TO);
name = linkTo + ' ' + name;
}
// Loop until we find a target name that doesn't exist
for (; ; ) {
try {
final String currentTranslationPrefix = translationPrefix;
final String currentName = name;
// attempt each copy/paste in its own transaction
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
if (getMode() == ClipboardStatus.COPY) {
if (action == UIClipboardShelfItem.ACTION_PASTE_LINK) {
// LINK operation
if (logger.isDebugEnabled())
logger.debug("Attempting to link node ID: " + getNodeRef() + " into node: " + destRef.toString());
// create the node using the nodeService (can only use FileFolderService for content)
if (checkExists(currentName + LINK_NODE_EXTENSION, destRef) == false) {
Map<QName, Serializable> props = new HashMap<QName, Serializable>(2, 1.0f);
String newName = currentName + LINK_NODE_EXTENSION;
props.put(ContentModel.PROP_NAME, newName);
props.put(ContentModel.PROP_LINK_DESTINATION, getNodeRef());
if (dd.isSubClass(getType(), ContentModel.TYPE_CONTENT)) {
// create File Link node
ChildAssociationRef childRef = nodeService.createNode(destRef, ContentModel.ASSOC_CONTAINS, QName.createQName(assocRef.getQName().getNamespaceURI(), newName), ApplicationModel.TYPE_FILELINK, props);
// apply the titled aspect - title and description
Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(2, 1.0f);
titledProps.put(ContentModel.PROP_TITLE, currentName);
titledProps.put(ContentModel.PROP_DESCRIPTION, currentName);
nodeService.addAspect(childRef.getChildRef(), ContentModel.ASPECT_TITLED, titledProps);
} else {
// create Folder link node
ChildAssociationRef childRef = nodeService.createNode(destRef, ContentModel.ASSOC_CONTAINS, assocRef.getQName(), ApplicationModel.TYPE_FOLDERLINK, props);
// apply the uifacets aspect - icon, title and description props
Map<QName, Serializable> uiFacetsProps = new HashMap<QName, Serializable>(4, 1.0f);
uiFacetsProps.put(ApplicationModel.PROP_ICON, "space-icon-link");
uiFacetsProps.put(ContentModel.PROP_TITLE, currentName);
uiFacetsProps.put(ContentModel.PROP_DESCRIPTION, currentName);
nodeService.addAspect(childRef.getChildRef(), ApplicationModel.ASPECT_UIFACETS, uiFacetsProps);
}
}
} else {
// COPY operation
if (logger.isDebugEnabled())
logger.debug("Attempting to copy node: " + getNodeRef() + " into node ID: " + destRef.toString());
// first check that we are not attempting to copy a duplicate into the same parent
if (destRef.equals(assocRef.getParentRef()) && currentName.equals(getName())) {
// manually change the name if this occurs
throw new FileExistsException(destRef, currentName);
}
if (dd.isSubClass(getType(), ContentModel.TYPE_CONTENT) || dd.isSubClass(getType(), ContentModel.TYPE_FOLDER)) {
// copy the file/folder
fileFolderService.copy(getNodeRef(), destRef, currentName);
} else if (dd.isSubClass(getType(), ContentModel.TYPE_MULTILINGUAL_CONTAINER)) {
// copy the mlContainer and its translations
multilingualContentService.copyTranslationContainer(getNodeRef(), destRef, currentTranslationPrefix);
} else {
// copy the node
if (checkExists(currentName, destRef) == false) {
copyService.copyAndRename(getNodeRef(), destRef, ContentModel.ASSOC_CONTAINS, assocRef.getQName(), true);
}
}
}
} else {
// MOVE operation
if (logger.isDebugEnabled())
logger.debug("Attempting to move node: " + getNodeRef() + " into node ID: " + destRef.toString());
if (dd.isSubClass(getType(), ContentModel.TYPE_CONTENT) || dd.isSubClass(getType(), ContentModel.TYPE_FOLDER)) {
// move the file/folder
fileFolderService.moveFrom(getNodeRef(), getParent(), destRef, currentName);
} else if (dd.isSubClass(getType(), ContentModel.TYPE_MULTILINGUAL_CONTAINER)) {
// copy the mlContainer and its translations
multilingualContentService.moveTranslationContainer(getNodeRef(), destRef);
} else {
if (isPrimaryParent) {
// move the node
nodeService.moveNode(getNodeRef(), destRef, ContentModel.ASSOC_CONTAINS, assocRef.getQName());
} else {
nodeService.removeChild(getParent(), getNodeRef());
nodeService.addChild(destRef, getNodeRef(), assocRef.getTypeQName(), assocRef.getQName());
}
}
}
return null;
}
});
// We got here without error, so no need to loop with a new name
break;
} catch (FileExistsException fileExistsErr) {
// If mode is COPY, have another go around the loop with a new name
if (getMode() == ClipboardStatus.COPY) {
String copyOf = Application.getMessage(fc, MSG_COPY_OF);
name = copyOf + ' ' + name;
translationPrefix = copyOf + ' ' + translationPrefix;
} else {
// we should not rename an item when it is being moved - so exit
throw fileExistsErr;
}
}
}
return true;
} else {
return false;
}
}
use of org.alfresco.service.cmr.repository.ChildAssociationRef in project acs-community-packaging by Alfresco.
the class CCCheckoutFileDialog method checkoutFile.
/**
* Action called upon completion of the Check Out file page
*/
public String checkoutFile(FacesContext context, String outcome) {
boolean checkoutSuccessful = false;
final Node node = property.getDocument();
if (node != null) {
try {
if (logger.isDebugEnabled())
logger.debug("Trying to checkout content node Id: " + node.getId());
// checkout the node content to create a working copy
if (logger.isDebugEnabled()) {
logger.debug("Checkout copy location: " + property.getCopyLocation());
logger.debug("Selected Space Id: " + property.getSelectedSpaceId());
}
NodeRef workingCopyRef = null;
if (property.getCopyLocation().equals(CCProperties.COPYLOCATION_OTHER) && property.getSelectedSpaceId() != null) {
// checkout to a arbituary parent Space
NodeRef destRef = property.getSelectedSpaceId();
ChildAssociationRef childAssocRef = getNodeService().getPrimaryParent(destRef);
workingCopyRef = property.getVersionOperationsService().checkout(node.getNodeRef(), destRef, ContentModel.ASSOC_CONTAINS, childAssocRef.getQName());
} else {
// checkout the content to the current space
workingCopyRef = property.getVersionOperationsService().checkout(node.getNodeRef());
// in the resources panel in the manage task dialog
if (property.isWorkflowAction() && property.getWorkflowTaskId() != null && (property.getWorkflowTaskId().equals("null") == false)) {
WorkflowTask task = property.getWorkflowService().getTaskById(property.getWorkflowTaskId());
if (task != null) {
NodeRef workflowPackage = (NodeRef) task.properties.get(WorkflowModel.ASSOC_PACKAGE);
if (workflowPackage != null) {
getNodeService().addChild(workflowPackage, workingCopyRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName((String) getNodeService().getProperty(workingCopyRef, ContentModel.PROP_NAME))));
if (logger.isDebugEnabled())
logger.debug("Added working copy to workflow package: " + workflowPackage);
}
}
}
}
// 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
// the myfile part will be ignored by the servlet but gives the
// browser a hint
String url = DownloadContentServlet.generateDownloadURL(workingCopyRef, workingCopy.getName());
workingCopy.getProperties().put("url", url);
workingCopy.getProperties().put("fileType32", FileTypeImageUtils.getFileTypeImage(workingCopy.getName(), false));
// mark as successful
checkoutSuccessful = true;
} catch (Throwable err) {
Utils.addErrorMessage(Application.getMessage(context, MSG_ERROR_CHECKOUT) + err.getMessage(), err);
ReportedException.throwIfNecessary(err);
}
} else {
logger.warn("WARNING: checkoutFile called without a current Document!");
}
// determine which page to show next if the checkout was successful.
if (checkoutSuccessful) {
// already disappeared!
if (getNodeService().exists(property.getWorkingDocument().getNodeRef())) {
// go to the page that allows the user to download the content
// for editing
// "checkoutFileLink";
outcome = "dialog:checkoutFileLink";
// //checkout-file-link.jsp
// currentAction = Action.CHECKOUT_FILE_LINK;
} else {
// show a page telling the user that the content has already
// been checked in
// "workingCopyMissing";
outcome = "dialog:workingCopyMissing";
// //
// working-copy-missing.jsp
// currentAction = Action.WORKING_COPY_MISSING;
}
}
return outcome;
}
Aggregations