Make content node primary parent of node - java

I try to use the Alfresco NodeService to make a content node (QName cm:content) the primary parent of another content node. NodeService provides a method
public ChildAssociationRef moveNode(
NodeRef nodeToMoveRef,
NodeRef newParentRef,
QName assocTypeQName,
QName assocQName)
throws InvalidNodeRefException;
Let's say the current primary parent of the node theNodeToMove is a folder and the primary parent assoc reference of the node in the folder is primaryAssocRef. Let theTargetContentNode be the target content node.
Calling the above message like this
nodeService.moveNode(theNodeToMove,
theTargetContentNode,
primaryAssocRef.getTypeQName(),
primaryAssocRef.getQName());
fails. Alfresco reporst an integrity violation:
The association source type is incorrect:
Source Node: workspace://SpacesStore/27a97736-222c-4bac-8610-f15ce312b074
Association: Association[ class=ClassDef[name={http://www.alfresco.org/model/content/1.0}folder], name={http://www.alfresco.org/model/content/1.0}contains, target class={http://www.alfresco.org/model/system/1.0}base, source role=null, target role=null]
Required Source Type: {http://www.alfresco.org/model/content/1.0}folder
Actual Source Type: {http://www.alfresco.org/model/content/1.0}content
Is it even possible to make a content node the primary parent of an existing content node?

Yes and no. Yes because content node can have children, and no because you can't use the "contains" association.
Basically, when you create a "parent-child" relation, you need to state it's association type. You can have as many of these, for instance rm:rendition is one of these types.
The "main" association type used when you create a document under a folder is cm:contains, and is setup in a way that does not allow content nodes to have children. This is done through model definition, and looks something like this:
<type name="cm:folder">
<title>Folder</title>
<parent>cm:cmobject</parent>
<archive>true</archive>
<associations>
<child-association name="cm:contains">
<source>
<mandatory>false</mandatory>
<many>true</many>
</source>
<target>
<class>sys:base</class>
<mandatory>false</mandatory>
<many>true</many>
</target>
<duplicate>false</duplicate>
<propagateTimestamps>true</propagateTimestamps>
</child-association>
</associations>
</type>

Related

#XMLRootElement element or array name

I am currently trying to unmarshall a xml get response into one intricate java object. That java object has other classes as fields, so it goes very deep. Now, I am using the JaxbMarshaller2 for this job. So far everything has been going well, but now I am have a question:
Basically one of the tags in the XML stream is called "images" and contains an array of individual image items, each enclosed in the "item" tag.
<images>
<item>
<name></name>
</item>
<item>
<name></name>
</item>
</images>
Now, in my root java class, I have a property called images, which is a list of these image items (I made a custom class for these items.)
#XmlElement(name = "images")
private List<ProductImage> images;
Ok, now inside the ProductImage class, would the XML root element above the class name be #XmlRootElement(name="images") or #XmlRootElement(name="item")?
Thanks for your responses.
The #XmlRootElement annotation is only necessary for the root element of your xml file. Each parent always defines the names of the tags of its children. But since the root element has no parent, there is an additional annotation necessary to define its name (i.e. #XmlRootElement).
Option1:
Assuming that the <images> node is your root node of your xml file.
Create a class ProductImageCollection which has the #XmlRootElement(name="images") annotation.
Inside this class there should be a List<ProductImage> which has an annotation #XmlElement(name="image")
Option2:
Assuming that your <images> node is part of a bigger xml structure, which already has correct annotations.
Then you don't need any additional #XmlRootElement annotations. You can directly annotate your list with #XmlElementWrapper(name="images").

How to convert attributes to nodes of an xml in java?

I am parsing an XML file like
<STRUCTURE ID="EV_Se96ffb9a-df1f-44e7-a4f8-818688cf8d3b">
<SHORT-NAME>STRUCT</SHORT-NAME>
<LONG-NAME>Structure</LONG-NAME>
</STRUCTURE>
where I am getting the child nodes of STRUCTURE and adding it to a nodeList.
Can I have an option to add the attributes of STRUCTURE i.e, ID to a nodeList ?
How to convert the attributes to a node and add it to a nodelist ?
Please help me out.
I am using the DOM parsing strategy
The Node class has a method getAttributes() which returns a NamedNodeMap. Of course, only elements will return an appropriate named node map (as only elements can have attributes).
On such a NamedNodeMap you can then retrieve the attribute node via a call to getNamedItem(String) or via a call to item(int). Note, that the return type of these methods is a Node, which - in case of attributes - will in fact be an Attr.

Create documents in CMIS

Could you tell me if there is any possibility to create documents which parent would be another document.
ObjectId parentId = session.createObjectId(someDocumentStringId);
session.createDocument(properties, parentId, stream, VersioningState.None);
Now I get error: Operation not supported by the repository for this object!
Documents are not containers in CMIS. Only a folder can be a parent of a document.
Have a look at CMIS relationships. They may solve your problem.

Store Parent/Child in a Batch Put on Appengine with Objectify

I'd like to store 2 new entities in a batch put. However, one entity is the parent of the other. If I have a a field in the child object that looks like:
#Parent
private Key parent
How do I fill in a value for this field in the child object if the parent hasn't been stored yet (and thus has no key yet).
Allocate the id of the parent in advance. Then you can save the parent and the child (with a parent key reference) in a single batch put.
Yo can not do it that way (as one batch).
If your question is more concerned with data integrity, then you may use transactions.
Example:
from google.appengine.ext import db
from app.models import ParentModel, ChildModel
class ARequestHandler(BaseHandler):
def get(self):
def create_parent_and_child():
parent_entity = ParentModel(...)
parent_entity.put()
child_entity = ChildModel(Parent=parent_entity, ...)
child_entity.put()
db.run_in_transaction(create_parent_and_child)

JAXB: a parent contain a list of a same child, how to obtain this list

I have a XML format that I want to marshal using JAXB and it looks a bit odd to me. Here is the XML
<root>
<parent>
<child>1</child>
<child>2</child>
<child>10</child>
</parent>
</root>
I want to get the List of child back. Usually if the parent has multiples different child, I would make parent a class, and use #XmlElement to refer to parent from root, but in this case parent only have 1 child, and it repeat multiple times, so it is a bit odd to me. The XML format can be changed.
You could do the following leveraging #XmlElementWrapper:
#XmlRootElement
public class Root {
#XmlElementWrapper(name="parent")
#XmlElement(name="child")
private List<String> children;
}
For More Information
http://blog.bdoughan.com/2010/09/jaxb-collection-properties.html
Have you considered adding List in your Parent class and annotating it with #XmlElement?
#XmlElement
protected List<Child> child;

Categories