Hi Mark,
Thanks for the reply. What you say makes sense, but I'm having a hard time
figuring out how to do it. I mean, I can see by looking at my code why it's
doing what it's doing.  But I'm not quite able to wrap my head around some
of these node-type concepts enough to change it to what I want.
If you have a moment, could you look at this piece of code and tell me if
you have any quick pointers? Maybe some quick pseudo-code?

In addition to the code I provided previously, here's a sample of what I
currently have for creating a node for a new file....
----------------------------------------------------------------------------------------------------------------------------------------
Node folderNode = session.getNode(folderPath);
Node fileNode = folderNode.addNode(fileName, "nt:file");
fileNode.addMixin("mix:versionable");
Node resNode = fileNode.addNode("jcr:content", "fileContent");
resNode.setProperty("jcr:mimeType", mimeType);
resNode.setProperty("jcr:data", stream);
resNode.setProperty("jcr:lastModified", Calendar.getInstance());
resNode.setProperty("description", description);
session.save();
vman.checkin(fileNode.getPath());
------------------------------------------------------------------------------------------------------------------------------------



It seems to me that I should (conceptually) change the code from above to
something like the following....
However, I can't figure out to add custom properties to that top-level node.
----------------------------------------------------------------------------------------------------------------------------------------
Node folderNode = session.getNode(folderPath);
Node fileNode = folderNode.addNode(fileName, "nt:file");
fileNode.setProperty("description", description);
Node contentNode = fileNode.addNode("jcr:content", "fileContent");
contentNode.addMixin("mix:versionable");
contentNode.setProperty("jcr:mimeType", mimeType);
contentNode.setProperty("jcr:data", stream);
contentNode.setProperty("jcr:lastModified", Calendar.getInstance());
session.save();
vman.checkin( contentNode.getPath());
------------------------------------------------------------------------------------------------------------------------------------





On Mon, Jan 23, 2012 at 2:12 PM, Mark Herman <mher...@nbme.org> wrote:

> I would suggest that you don't make your "fileNode" versionable.  Where you
> define your "fileContent" nodetype, add the mix:versionable there.  Then
> the
> metadata of your fileNode can change all you want, but your resource has
> its
> own independent versioning.
>
> -----Original Message-----
> From: Lee F [mailto:bajasa...@gmail.com]
> Sent: Monday, January 23, 2012 3:42 PM
> To: users@jackrabbit.apache.org
> Subject: How to add unversioned metadata to a versioned node?
>
> Hello,
> I have an app that allows users to upload binary files to a Jackrabbit
> repository.  There are also a few pieces of metadata that I am tracking
> withing each file.  For example, description, document id, user, etc. The
> other requirement is that the files be versioned and have access to
> historical versions.  This is all working beautifully except for one small
> problem...
>
> Whenever the user changes something like the description, the version
> number
> for the file goes up one.  I really only want a new version to occur when
> the
> actual file is replaced with a new one.
> Can someone tell me how I can store unversioned metadata with my versioned
> node?  Would be much appreciated.  Thanks!
>
>
> Here is some sample code to illustrate how I am doing it now....
>
>
> When the session starts, I register a custom property type....
>
> -----------------------------------------------------------------------------
> --------------------
> NodeTypeManager nodeTypeManager = (NodeTypeManager)
> session.getWorkspace().getNodeTypeManager();
> NodeTypeTemplate nodeType = nodeTypeManager.createNodeTypeTemplate();
> nodeType.setDeclaredSuperTypeNames(new String[] {"nt:resource"});
> nodeType.setName("fileContent");
>
> PropertyDefinitionTemplate property =
> nodeTypeManager.createPropertyDefinitionTemplate();
> property.setName("description");
> property.setMultiple(false);
> property.setRequiredType(type);
> template.getPropertyDefinitionTemplates().add(property);
> nodeTypeManager.registerNodeType(nodeType, true);
>
> -----------------------------------------------------------------------------
> --------------------
>
>
>
> To change property value....
>
> -----------------------------------------------------------------------------
> --------------------
>
> VersionManager vman = session.getWorkspace().getVersionManager();
> Node fileNode = session.getNodeByIdentifier(id); Node resNode =
> fileNode.getNode("jcr:content"); vman.checkout(fileNode.getPath());
> resNode.setProperty("description", description); session.save();
> vman.checkin(fileNode.getPath());
>
> -----------------------------------------------------------------------------
> --------------------
>

Reply via email to