Expand my Community achievements bar.

Write PDF document to JCR path by AssetManager

Avatar

Level 2

Hi,

 

I am trying to write generated PDF document from XML Form Service to JCR by using below line of code. but i am getting below error intermittently while running couple of transactions. Please help.

 

Code:

com.day.cq.dam.api.AssetManager assetMgr = resourceResolver.adaptTo(com.day.cq.dam.api.AssetManager.class);
Asset asset = assetMgr.createAsset(path + "/" + destinationVal, sourceVal.getInputStream(), "application/pdf", true);

Here sourceVal is Document object

 

Error:

javax.jcr.InvalidItemStateException: OakState0001: Unresolved conflicts in /content/dam/documentgeneration
at org.apache.jackrabbit.oak.api.CommitFailedException.asRepositoryException(CommitFailedException.java:238) [org.apache.jackrabbit.oak-api:1.22.9]
at org.apache.jackrabbit.oak.api.CommitFailedException.asRepositoryException(CommitFailedException.java:213) [org.apache.jackrabbit.oak-api:1.22.9]
at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.newRepositoryException(SessionDelegate.java:669) [org.apache.jackrabbit.oak-jcr:1.22.9]
at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.save(SessionDelegate.java:495) [org.apache.jackrabbit.oak-jcr:1.22.9]
at org.apache.jackrabbit.oak.jcr.session.SessionImpl$8.performVoid(SessionImpl.java:424) [org.apache.jackrabbit.oak-jcr:1.22.9]
at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.performVoid(SessionDelegate.java:273) [org.apache.jackrabbit.oak-jcr:1.22.9]
at org.apache.jackrabbit.oak.jcr.session.SessionImpl.save(SessionImpl.java:421) [org.apache.jackrabbit.oak-jcr:1.22.9]
at com.adobe.granite.repository.impl.CRX3SessionImpl.save(CRX3SessionImpl.java:208) [com.adobe.granite.repository:1.6.28.CQ650-B0001]
at com.day.cq.dam.core.impl.AssetManagerImpl.createOrUpdateAsset(AssetManagerImpl.java:314) [com.day.cq.dam.cq-dam-core:5.12.320]
at com.day.cq.dam.core.impl.AssetManagerImpl.createAsset(AssetManagerImpl.java:249) [com.day.cq.dam.cq-dam-core:5.12.320]
at com.wellsfargo.wimt.ofp.capabilities.core.documentgeneration.workflows.StoreGeneratedPDFToJCR.execute(StoreGeneratedPDFToJCR.java:84) [ofpcapabilities.core:1.0.0.SNAPSHOT]
at com.adobe.granite.workflow.core.job.HandlerBase.executeProcess(HandlerBase.java:195) [com.adobe.granite.workflow.core:2.0.240.CQ654-B0017]
at com.adobe.granite.workflow.core.job.JobHandler.process(JobHandler.java:260) [com.adobe.granite.workflow.core:2.0.240.CQ654-B0017]
at org.apache.sling.event.impl.jobs.JobConsumerManager$JobConsumerWrapper.process(JobConsumerManager.java:502) [org.apache.sling.event:4.2.12]
at org.apache.sling.event.impl.jobs.queues.JobQueueImpl.startJob(JobQueueImpl.java:293) [org.apache.sling.event:4.2.12]
at org.apache.sling.event.impl.jobs.queues.JobQueueImpl.access$100(JobQueueImpl.java:60) [org.apache.sling.event:4.2.12]
at org.apache.sling.event.impl.jobs.queues.JobQueueImpl$1.run(JobQueueImpl.java:229) [org.apache.sling.event:4.2.12]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:750)


Caused by: org.apache.jackrabbit.oak.api.CommitFailedException: OakState0001: Unresolved conflicts in /content/dam/documentgeneration

at org.apache.jackrabbit.oak.plugins.commit.ConflictValidator.failOnMergeConflict(ConflictValidator.java:115) [org.apache.jackrabbit.oak-core:1.22.9]
at org.apache.jackrabbit.oak.plugins.commit.ConflictValidator.propertyAdded(ConflictValidator.java:84) [org.apache.jackrabbit.oak-core:1.22.9]
at org.apache.jackrabbit.oak.spi.commit.CompositeEditor.propertyAdded(CompositeEditor.java:82) [org.apache.jackrabbit.oak-store-spi:1.22.9]
at org.apache.jackrabbit.oak.spi.commit.EditorDiff.propertyAdded(EditorDiff.java:81) [org.apache.jackrabbit.oak-store-spi:1.22.9]
at org.apache.jackrabbit.oak.segment.SegmentNodeState.compareProperties(SegmentNodeState.java:660) [org.apache.jackrabbit.oak-segment-tar:1.22.9]
at org.apache.jackrabbit.oak.segment.SegmentNodeState.compareAgainstBaseState(SegmentNodeState.java:523) [org.apache.jackrabbit.oak-segment-tar:1.22.9]
at org.apache.jackrabbit.oak.spi.commit.EditorDiff.childNodeChanged(EditorDiff.java:147) [org.apache.jackrabbit.oak-store-spi:1.22.9]
at org.apache.jackrabbit.oak.segment.MapRecord.compare(MapRecord.java:444) [org.apache.jackrabbit.oak-segment-tar:1.22.9]
at org.apache.jackrabbit.oak.segment.SegmentNodeState.compareAgainstBaseState(SegmentNodeState.java:651) [org.apache.jackrabbit.oak-segment-tar:1.22.9]
at org.apache.jackrabbit.oak.spi.commit.EditorDiff.childNodeChanged(EditorDiff.java:147) [org.apache.jackrabbit.oak-store-spi:1.22.9]
at org.apache.jackrabbit.oak.segment.MapRecord.compare(MapRecord.java:444) [org.apache.jackrabbit.oak-segment-tar:1.22.9]
at org.apache.jackrabbit.oak.segment.SegmentNodeState.compareAgainstBaseState(SegmentNodeState.java:651) [org.apache.jackrabbit.oak-segment-tar:1.22.9]
at org.apache.jackrabbit.oak.spi.commit.EditorDiff.childNodeChanged(EditorDiff.java:147) [org.apache.jackrabbit.oak-store-spi:1.22.9]
at org.apache.jackrabbit.oak.segment.MapRecord.compare(MapRecord.java:444) [org.apache.jackrabbit.oak-segment-tar:1.22.9]
at org.apache.jackrabbit.oak.segment.SegmentNodeState.compareAgainstBaseState(SegmentNodeState.java:651) [org.apache.jackrabbit.oak-segment-tar:1.22.9]
at org.apache.jackrabbit.oak.spi.commit.EditorDiff.process(EditorDiff.java:51) [org.apache.jackrabbit.oak-store-spi:1.22.9]
at org.apache.jackrabbit.oak.spi.commit.EditorHook.processCommit(EditorHook.java:54) [org.apache.jackrabbit.oak-store-spi:1.22.9]
at org.apache.jackrabbit.oak.spi.commit.CompositeHook.processCommit(CompositeHook.java:60) [org.apache.jackrabbit.oak-store-spi:1.22.9]
at org.apache.jackrabbit.oak.spi.commit.CompositeHook.processCommit(CompositeHook.java:60) [org.apache.jackrabbit.oak-store-spi:1.22.9]
at org.apache.jackrabbit.oak.segment.scheduler.Commit.apply(Commit.java:105) [org.apache.jackrabbit.oak-segment-tar:1.22.9]
at org.apache.jackrabbit.oak.segment.scheduler.LockBasedScheduler.execute(LockBasedScheduler.java:299) [org.apache.jackrabbit.oak-segment-tar:1.22.9]
at org.apache.jackrabbit.oak.segment.scheduler.LockBasedScheduler.schedule(LockBasedScheduler.java:270) [org.apache.jackrabbit.oak-segment-tar:1.22.9]
at org.apache.jackrabbit.oak.segment.SegmentNodeStore.merge(SegmentNodeStore.java:211) [org.apache.jackrabbit.oak-segment-tar:1.22.9]
at org.apache.jackrabbit.oak.core.MutableRoot.commit(MutableRoot.java:251) [org.apache.jackrabbit.oak-core:1.22.9]
at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.commit(SessionDelegate.java:346) [org.apache.jackrabbit.oak-jcr:1.22.9]
at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.save(SessionDelegate.java:493) [org.apache.jackrabbit.oak-jcr:1.22.9]
... 16 common frames omitted

 

Regards,

Sridhar

1 Reply

Avatar

Level 1

Most notable is the CommitFailedException 

 

Based Exclusively on the interment errors from your code, I would suggest converting the ResourceResolver to Session first as the 'Session' is used to manage transactions to make use of the 'refresh' method.

Doing so should at least elminate the CommitFailedException  by updating the session  with the latest committed changes from the repository. There is no built-in solution to handle concurrent modifications, this is just one graceful suggestion. 


import javax.jcr.Session;
Session session = resourceResolver.adaptTo(Session.class);