jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mark Herman" <MHer...@NBME.org>
Subject RE: How to add unversioned metadata to a versioned node?
Date Mon, 23 Jan 2012 23:12:18 GMT
Feel like I should warn you. If the node type already exists, this will
unregister it in order to create the new one.  If your repository already has
content of that type, the unregister will turn them into their super types
and you'll lose your customizations.

-----Original Message-----
From: Mark Herman 
Sent: Monday, January 23, 2012 6:08 PM
To: users@jackrabbit.apache.org
Subject: RE: How to add unversioned metadata to a versioned node?

Ah ha, that's right, I forgot you will need to create a custom file node type
instead of resource.  In our env, I've created custom node types for folder,
file and resource to allow any custom properties we want.  I just happened to
have the code right in front of me....


//if not already registered you'll have to register the namespace //

public void register(Session ses) throws Exception {

public void registerNodeType(Session ses, String name, String superType,
boolean versionable) throws Exception {
    NodeTypeManager ntm =  ses.getWorkspace().getNodeTypeManager();
    NodeTypeTemplate ntt = createNodeType(ses,name, superType,versionable);


public NodeTypeTemplate createNodeType(Session ses, String name, String
superType, boolean versionable) throws Exception{
    NodeTypeManager ntm =  ses.getWorkspace().getNodeTypeManager();
    PropertyDefinitionTemplate pdts = ntm.createPropertyDefinitionTemplate();
    PropertyDefinitionTemplate pdtm = ntm.createPropertyDefinitionTemplate();
    NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();

        ntt.setDeclaredSuperTypeNames(new String[] {superType,
        ntt.setDeclaredSuperTypeNames(new String[] {superType});
    return ntt;


One other note. From your initial question it sounded like you register every
time create a new session? It should be a onetime thing, then the node types
will just be available to new sessions.

-----Original Message-----
From: Lee F [mailto:bajasands@gmail.com]
Sent: Monday, January 23, 2012 5:20 PM
To: users@jackrabbit.apache.org
Subject: Re: How to add unversioned metadata to a versioned node?

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");
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();

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 <MHerman@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:bajasands@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());
> ----------------------------------------------------------------------
> -------
> --------------------

View raw message