cancel
Showing results for 
Search instead for 
Did you mean: 

existing node as a new version for another node

gokceng
Champ in-the-making
Champ in-the-making
I have two nodes: nodeA and nodeB, I want nodeB to have a new version which is nodeA, I mean how can I make nodeA nodeB's new version?
7 REPLIES 7

invictus9
Champ in-the-making
Champ in-the-making
First, check out the wiki:

http://wiki.alfresco.com/wiki/JavaScript_API_Cookbook#Create_Document.2C_Make_it_Versionable.2C_Modi...

Then, you may need to copy the contents of the newer node into the older file. You will have to use the writer() function to do the copy, since just using the cm:content attribute only works on strictly text files.

gokceng
Champ in-the-making
Champ in-the-making
thanks for your reply. I've used something like that:

workingCopy = nodeA.checkout();
workingCopy.content.write(nodeB.content);
workingCopy.checkin();

but i want to do something like that.

workingCopy = nodeA.checkout();
workingCopy.content.write(nodeB.content);
workingCopy.properties = nodeB.properties;
workingCopy.save();

workingCopy.checkin();

so i make nodeA to have 'all properties' or 'all properties of a specific aspect' of nodeB. How can i do that?

invictus9
Champ in-the-making
Champ in-the-making
The "properties" property is a map, so you can iterate over all of the keys in the source map and set them in the destination map.

for ( k in keys(nodeB.properties) ) {
   workingCopy.properties[k] = nodeB.properties[k];
}

You may need to filter some items to prevent error messages (I think) as some properties may not be settable.

gyro_gearless
Champ in-the-making
Champ in-the-making
Hi,

I don't see why copying the cm:content property should only work for text files? As a matter of fact, i'm frequently doing this to make copies of nodes without duplicating the actual content, and Alfresco's CopyService is doing similar.
The cm:content property is only a pointer into the actual content store, so having two nodes with same cm:content property is similar to having two or more hardlinked files on Unix. (Well, this analogy is a bit lame: if one the nodes' content is updated, it gets its cm:content property pointing to a fresh location, so the nodes have different content then).

An alternative approach might be to use app:filelink objects, however, your mileage may vary  :roll:

Cheers
Gyro

invictus9
Champ in-the-making
Champ in-the-making
I don't see why copying the cm:content property should only work for text files?

I don't see why, either. However, the documentation is pretty clear that cm:content is for text, which is why I recommend using the 'writer' approach. In a Unix world, everything is bytes, but everyone forgets that this was a major breakthrough in computer input and output. Previous computer systems had specialized input and output systems for different kinds of data, and different kinds of media. When you understand that "text" is a different interpretation of "bytes", a lot of your I/O system gets simpler. However, at some point, multi-byte characters became the norm, and you could end up with anomalies that meant that "text" (as in a series of textual characters) did not mean the same as "bytes".

So, when the documentation puts limits on the way material can be interpreted, I tend to trust that they know what might go wrong. The mechanism is there to do the copying, and (I hope) the mechanism does not depend on it being text.

mrogers
Star Contributor
Star Contributor
cm:content is binary data.    You can store, for example, an image in a content property.

Depending upon which interface you use it may make sense to return the data as a String of characters.     However the JavaScript interfaces you are looking at are a little challenged since JavaScript can't deal with streaming, however it can handle strings.    

And its also worth noting that as well as the binary content cm:content also contains the mime type and the character set so its possible to reliably pull out Japanese text or application specific data files.

gokceng
Champ in-the-making
Champ in-the-making
The "properties" property is a map, so you can iterate over all of the keys in the source map and set them in the destination map.

for ( k in keys(nodeB.properties) ) {
   workingCopy.properties[k] = nodeB.properties[k];
}

You may need to filter some items to prevent error messages (I think) as some properties may not be settable.

thanks invictus9 it helped me..