You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-dev@jackrabbit.apache.org by Ciro Santos <cs...@gmail.com> on 2016/05/18 23:09:21 UTC

[OAK] - Problem to version Node when adding versionable mixin

Hello Guys,

I'm working in a project that uses JCR with 2 versions, one using
jackrabbit and one using OAK. Right now I'm implementing versioning on
documents.

I was able to make it work using jackrabbit. But when I try to use the code
in the OAK version, I'm getting an error.

We use OSGI to create bundles and the JCR (JackRabbit and OAK) are also
bundles, which means that we create the OAK repository when starting the
OSGI felix. Also, the repository is created in the AWS S3.

The odd thing is that we have integration tests that creates a transient
repository in memory, and it works correctly too.

Here is the creation of the document part of my method:

userSession =
repository.getUserSession(currentUser.getUserId(),tenantManager.getWorkspaceFromTenant(currentUser.getTenantId()));

folderNode =  userSession.getNodeByIdentifier(parentFolderId);
String documentName = Text.escapeIllegalJcrChars(name);
final Node fileNode = folderNode.addNode(documentName,
JcrConstants.NT_FILE);
final Node contentNode = fileNode.addNode(JcrConstants.JCR_CONTENT,
JcrConstants.NT_RESOURCE);
contentNode.addMixin(NodeType.MIX_VERSIONABLE);
contentNode.setProperty(JcrConstants.JCR_MIMETYPE, mimeType);

try {
    contentNode.setProperty(JcrConstants.JCR_DATA,
userSession.getValueFactory().createBinary(document));
} finally {
    document.close();
}

contentNode.setProperty(Property.JCR_LAST_MODIFIED,
Calendar.getInstance().getTimeInMillis());
userSession.save();
userSession.getWorkspace().getVersionManager().checkin(contentNode.getPath());

And here is the exception:

Caused by: javax.jcr.nodetype.ConstraintViolationException:
OakConstraint0021:
/0/00/00000185-24a6-3bd1-b232-d7ff21f33b6a/home/a/ad/ad50ee6d-60a3-4689-9f90-4aa6326a4f45/root/document_to_test_11/jcr:content[[nt:resource,
mix:versionable]]: Mandatory property jcr:versionHistory not found in a new
node
    at
org.apache.jackrabbit.oak.api.CommitFailedException.asRepositoryException(CommitFailedException.java:225)
    at
org.apache.jackrabbit.oak.api.CommitFailedException.asRepositoryException(CommitFailedException.java:212)
    at
org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.newRepositoryException(SessionDelegate.java:670)
    at
org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.save(SessionDelegate.java:496)
    at
org.apache.jackrabbit.oak.jcr.session.SessionImpl$8.performVoid(SessionImpl.java:419)
    at
org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.performVoid(SessionDelegate.java:274)
    at
org.apache.jackrabbit.oak.jcr.session.SessionImpl.save(SessionImpl.java:416)
    at com.hp.ccp.jcr.impl.JCRDAO.addDocument(JCRDAO.java:887)
    ... 99 more

If I add a mixin and save, I already get the error. I dont understand why
is saying that I dont have this jcr:versionHistory property.

The oak version that we are using is 1.4.0

Is there anything else to consider?

Could anyone help me out please? I tried some things without success, right
now I don't know how to proccedd.

Thanks in Advance
Ciro Santos

Re: [OAK] - Problem to version Node when adding versionable mixin

Posted by Ciro Santos <cs...@gmail.com>.
Hi Marcel, Thanks for answering!

We are using OSGI to build the repository.

Do I need to provide some settings on OAK build to enable versioning?
Because in the documentation only says to add a MIXIN to the node that I'm
versioning, it looks like OAK would take care of everything needed to
create it. But it looks like something is making the versionHistory not
been created (or missing).

Do you have any idea?
Thanks

On Thu, May 19, 2016 at 4:22 AM Marcel Reutegger <mr...@adobe.com> wrote:

> Hi,
>
> how do you construct the repository? Maybe something is wrong
> with how you use the Jcr or Oak builder and the commit hook
> for JCR versioning is missing?
>
> Regards
>  Marcel
>
> On 19/05/16 01:09, "Ciro Santos" wrote:
>
> >Hello Guys,
> >
> >I'm working in a project that uses JCR with 2 versions, one using
> >jackrabbit and one using OAK. Right now I'm implementing versioning on
> >documents.
> >
> >I was able to make it work using jackrabbit. But when I try to use the
> >code
> >in the OAK version, I'm getting an error.
> >
> >We use OSGI to create bundles and the JCR (JackRabbit and OAK) are also
> >bundles, which means that we create the OAK repository when starting the
> >OSGI felix. Also, the repository is created in the AWS S3.
> >
> >The odd thing is that we have integration tests that creates a transient
> >repository in memory, and it works correctly too.
> >
> >Here is the creation of the document part of my method:
> >
> >userSession =
> >repository.getUserSession(currentUser.getUserId(),tenantManager.getWorkspa
> >ceFromTenant(currentUser.getTenantId()));
> >
> >folderNode =  userSession.getNodeByIdentifier(parentFolderId);
> >String documentName = Text.escapeIllegalJcrChars(name);
> >final Node fileNode = folderNode.addNode(documentName,
> >JcrConstants.NT_FILE);
> >final Node contentNode = fileNode.addNode(JcrConstants.JCR_CONTENT,
> >JcrConstants.NT_RESOURCE);
> >contentNode.addMixin(NodeType.MIX_VERSIONABLE);
> >contentNode.setProperty(JcrConstants.JCR_MIMETYPE, mimeType);
> >
> >try {
> >    contentNode.setProperty(JcrConstants.JCR_DATA,
> >userSession.getValueFactory().createBinary(document));
> >} finally {
> >    document.close();
> >}
> >
> >contentNode.setProperty(Property.JCR_LAST_MODIFIED,
> >Calendar.getInstance().getTimeInMillis());
> >userSession.save();
> >userSession.getWorkspace().getVersionManager().checkin(contentNode.getPath
> >());
> >
> >And here is the exception:
> >
> >Caused by: javax.jcr.nodetype.ConstraintViolationException:
> >OakConstraint0021:
> >/0/00/00000185-24a6-3bd1-b232-d7ff21f33b6a/home/a/ad/ad50ee6d-60a3-4689-9f
> >90-4aa6326a4f45/root/document_to_test_11/jcr:content[[nt:resource,
> >mix:versionable]]: Mandatory property jcr:versionHistory not found in a
> >new
> >node
> >    at
> >org.apache.jackrabbit.oak.api.CommitFailedException.asRepositoryException(
> >CommitFailedException.java:225)
> >    at
> >org.apache.jackrabbit.oak.api.CommitFailedException.asRepositoryException(
> >CommitFailedException.java:212)
> >    at
> >org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.newRepositoryExcept
> >ion(SessionDelegate.java:670)
> >    at
> >org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.save(SessionDelegat
> >e.java:496)
> >    at
> >org.apache.jackrabbit.oak.jcr.session.SessionImpl$8.performVoid(SessionImp
> >l.java:419)
> >    at
> >org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.performVoid(Session
> >Delegate.java:274)
> >    at
> >org.apache.jackrabbit.oak.jcr.session.SessionImpl.save(SessionImpl.java:41
> >6)
> >    at com.hp.ccp.jcr.impl.JCRDAO.addDocument(JCRDAO.java:887)
> >    ... 99 more
> >
> >If I add a mixin and save, I already get the error. I dont understand why
> >is saying that I dont have this jcr:versionHistory property.
> >
> >The oak version that we are using is 1.4.0
> >
> >Is there anything else to consider?
> >
> >Could anyone help me out please? I tried some things without success,
> >right
> >now I don't know how to proccedd.
> >
> >Thanks in Advance
> >Ciro Santos
>
>

Re: [OAK] - Problem to version Node when adding versionable mixin

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,

On Mon, Jun 20, 2016 at 5:25 PM, Ciro Santos <cs...@gmail.com> wrote:
> ...I don't know if i need to add something to the OSGI configuration. I also
> cannot find any proper documentation on how to set up oak bundles using
> OSGI....

Sling is a good example that uses Oak in an OSGi enviromment.

If you want to try it [1] has build instructions and you can then
execute the runnable jar built by the launchpad/builder module.

The main bundle that relates to Oak is under bundles/jcr/oak-server,
you might be able to run it in your OSGi environment but it will
require some Sling bundles as dependencies so it's probably quicker to
test it using the Sling launchpad jar.

HTH,
-Bertrand

[1] http://sling.apache.org/documentation/development/getting-and-building-sling.html

Re: [OAK] - Problem to version Node when adding versionable mixin

Posted by Ciro Santos <cs...@gmail.com>.
Hello Guys,

Can you guys help me out on this?

I don't know if i need to add something to the OSGI configuration. I also
cannot find any proper documentation on how to set up oak bundles using
OSGI.

Thanks in Advance
Ciro

On Thu, May 19, 2016 at 4:22 AM Marcel Reutegger <mr...@adobe.com> wrote:

> Hi,
>
> how do you construct the repository? Maybe something is wrong
> with how you use the Jcr or Oak builder and the commit hook
> for JCR versioning is missing?
>
> Regards
>  Marcel
>
> On 19/05/16 01:09, "Ciro Santos" wrote:
>
> >Hello Guys,
> >
> >I'm working in a project that uses JCR with 2 versions, one using
> >jackrabbit and one using OAK. Right now I'm implementing versioning on
> >documents.
> >
> >I was able to make it work using jackrabbit. But when I try to use the
> >code
> >in the OAK version, I'm getting an error.
> >
> >We use OSGI to create bundles and the JCR (JackRabbit and OAK) are also
> >bundles, which means that we create the OAK repository when starting the
> >OSGI felix. Also, the repository is created in the AWS S3.
> >
> >The odd thing is that we have integration tests that creates a transient
> >repository in memory, and it works correctly too.
> >
> >Here is the creation of the document part of my method:
> >
> >userSession =
> >repository.getUserSession(currentUser.getUserId(),tenantManager.getWorkspa
> >ceFromTenant(currentUser.getTenantId()));
> >
> >folderNode =  userSession.getNodeByIdentifier(parentFolderId);
> >String documentName = Text.escapeIllegalJcrChars(name);
> >final Node fileNode = folderNode.addNode(documentName,
> >JcrConstants.NT_FILE);
> >final Node contentNode = fileNode.addNode(JcrConstants.JCR_CONTENT,
> >JcrConstants.NT_RESOURCE);
> >contentNode.addMixin(NodeType.MIX_VERSIONABLE);
> >contentNode.setProperty(JcrConstants.JCR_MIMETYPE, mimeType);
> >
> >try {
> >    contentNode.setProperty(JcrConstants.JCR_DATA,
> >userSession.getValueFactory().createBinary(document));
> >} finally {
> >    document.close();
> >}
> >
> >contentNode.setProperty(Property.JCR_LAST_MODIFIED,
> >Calendar.getInstance().getTimeInMillis());
> >userSession.save();
> >userSession.getWorkspace().getVersionManager().checkin(contentNode.getPath
> >());
> >
> >And here is the exception:
> >
> >Caused by: javax.jcr.nodetype.ConstraintViolationException:
> >OakConstraint0021:
> >/0/00/00000185-24a6-3bd1-b232-d7ff21f33b6a/home/a/ad/ad50ee6d-60a3-4689-9f
> >90-4aa6326a4f45/root/document_to_test_11/jcr:content[[nt:resource,
> >mix:versionable]]: Mandatory property jcr:versionHistory not found in a
> >new
> >node
> >    at
> >org.apache.jackrabbit.oak.api.CommitFailedException.asRepositoryException(
> >CommitFailedException.java:225)
> >    at
> >org.apache.jackrabbit.oak.api.CommitFailedException.asRepositoryException(
> >CommitFailedException.java:212)
> >    at
> >org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.newRepositoryExcept
> >ion(SessionDelegate.java:670)
> >    at
> >org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.save(SessionDelegat
> >e.java:496)
> >    at
> >org.apache.jackrabbit.oak.jcr.session.SessionImpl$8.performVoid(SessionImp
> >l.java:419)
> >    at
> >org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.performVoid(Session
> >Delegate.java:274)
> >    at
> >org.apache.jackrabbit.oak.jcr.session.SessionImpl.save(SessionImpl.java:41
> >6)
> >    at com.hp.ccp.jcr.impl.JCRDAO.addDocument(JCRDAO.java:887)
> >    ... 99 more
> >
> >If I add a mixin and save, I already get the error. I dont understand why
> >is saying that I dont have this jcr:versionHistory property.
> >
> >The oak version that we are using is 1.4.0
> >
> >Is there anything else to consider?
> >
> >Could anyone help me out please? I tried some things without success,
> >right
> >now I don't know how to proccedd.
> >
> >Thanks in Advance
> >Ciro Santos
>
>

Re: [OAK] - Problem to version Node when adding versionable mixin

Posted by Marcel Reutegger <mr...@adobe.com>.
Hi,

how do you construct the repository? Maybe something is wrong
with how you use the Jcr or Oak builder and the commit hook
for JCR versioning is missing?

Regards
 Marcel 

On 19/05/16 01:09, "Ciro Santos" wrote:

>Hello Guys,
>
>I'm working in a project that uses JCR with 2 versions, one using
>jackrabbit and one using OAK. Right now I'm implementing versioning on
>documents.
>
>I was able to make it work using jackrabbit. But when I try to use the
>code
>in the OAK version, I'm getting an error.
>
>We use OSGI to create bundles and the JCR (JackRabbit and OAK) are also
>bundles, which means that we create the OAK repository when starting the
>OSGI felix. Also, the repository is created in the AWS S3.
>
>The odd thing is that we have integration tests that creates a transient
>repository in memory, and it works correctly too.
>
>Here is the creation of the document part of my method:
>
>userSession =
>repository.getUserSession(currentUser.getUserId(),tenantManager.getWorkspa
>ceFromTenant(currentUser.getTenantId()));
>
>folderNode =  userSession.getNodeByIdentifier(parentFolderId);
>String documentName = Text.escapeIllegalJcrChars(name);
>final Node fileNode = folderNode.addNode(documentName,
>JcrConstants.NT_FILE);
>final Node contentNode = fileNode.addNode(JcrConstants.JCR_CONTENT,
>JcrConstants.NT_RESOURCE);
>contentNode.addMixin(NodeType.MIX_VERSIONABLE);
>contentNode.setProperty(JcrConstants.JCR_MIMETYPE, mimeType);
>
>try {
>    contentNode.setProperty(JcrConstants.JCR_DATA,
>userSession.getValueFactory().createBinary(document));
>} finally {
>    document.close();
>}
>
>contentNode.setProperty(Property.JCR_LAST_MODIFIED,
>Calendar.getInstance().getTimeInMillis());
>userSession.save();
>userSession.getWorkspace().getVersionManager().checkin(contentNode.getPath
>());
>
>And here is the exception:
>
>Caused by: javax.jcr.nodetype.ConstraintViolationException:
>OakConstraint0021:
>/0/00/00000185-24a6-3bd1-b232-d7ff21f33b6a/home/a/ad/ad50ee6d-60a3-4689-9f
>90-4aa6326a4f45/root/document_to_test_11/jcr:content[[nt:resource,
>mix:versionable]]: Mandatory property jcr:versionHistory not found in a
>new
>node
>    at
>org.apache.jackrabbit.oak.api.CommitFailedException.asRepositoryException(
>CommitFailedException.java:225)
>    at
>org.apache.jackrabbit.oak.api.CommitFailedException.asRepositoryException(
>CommitFailedException.java:212)
>    at
>org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.newRepositoryExcept
>ion(SessionDelegate.java:670)
>    at
>org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.save(SessionDelegat
>e.java:496)
>    at
>org.apache.jackrabbit.oak.jcr.session.SessionImpl$8.performVoid(SessionImp
>l.java:419)
>    at
>org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.performVoid(Session
>Delegate.java:274)
>    at
>org.apache.jackrabbit.oak.jcr.session.SessionImpl.save(SessionImpl.java:41
>6)
>    at com.hp.ccp.jcr.impl.JCRDAO.addDocument(JCRDAO.java:887)
>    ... 99 more
>
>If I add a mixin and save, I already get the error. I dont understand why
>is saying that I dont have this jcr:versionHistory property.
>
>The oak version that we are using is 1.4.0
>
>Is there anything else to consider?
>
>Could anyone help me out please? I tried some things without success,
>right
>now I don't know how to proccedd.
>
>Thanks in Advance
>Ciro Santos