Expand my Community achievements bar.

SOLVED

Setting node properties programatically throwing exceptions

Avatar

Level 9

I am trying to set dc:title property from metadataNode somehow it is throwing exception, I am able to set other properties without any problem

My code is like this

 metadataNode.setProperty("dc:title", "My title" ); // doesn't work throws exception Multivalued property can not be set to a single value (an array of length one is OK): property 

 metadataNode.setProperty("dc:description", " My description"); //works fine no problem  

 originalContentNode.setProperty("jcr:mimeType", "application/pdf");//  throws version exception com.day.cq.dam.core.impl.handler.xmp.NCommXMPHandler Stack Trace: com.adobe.granite.asset.api.AssetException: Unable to create version for asset [ /content/dam/mypdfs/es/MYMail.pdf]: 

 

23.10.2013 23:41:41.331 *WARN* [JobHandler: /etc/workflow/instances/2013-10-23/model_7321294166569:/content/dam/mypdfs/MyPA2.pdf/jcr:content/renditions/original] com.day.cq.dam.commons.metadata.SimpleXmpToJcrMetadataBuilder Cannot set xmp property (dc:title): Multivalued property can not be set to a single value (an array of length one is OK): property /content/dam/mypdfs/MyPA2.pdf/jcr:content/metadata/dc:title javax.jcr.ValueFormatException: Multivalued property can not be set to a single value (an array of length one is OK): property /content/dam/mypdfs/MyPA2.pdf/jcr:content/metadata/dc:title
    at org.apache.jackrabbit.core.PropertyImpl.checkSetValue(PropertyImpl.java:274)
    at org.apache.jackrabbit.core.PropertyImpl.setValue(PropertyImpl.java:726)
    at org.apache.jackrabbit.core.NodeImpl$SetPropertyOperation.perform(NodeImpl.java:2054)
    at org.apache.jackrabbit.core.NodeImpl$SetPropertyOperation.perform(NodeImpl.java:1998)
    at org.apache.jackrabbit.core.session.SessionState.perform(SessionState.java:216)
    at org.apache.jackrabbit.core.NodeImpl.setProperty(NodeImpl.java:1920)
    at org.apache.jackrabbit.core.NodeImpl.setProperty(NodeImpl.java:1890)
    at com.day.cq.dam.commons.metadata.SimpleXmpToJcrMetadataBuilder.setProperty(SimpleXmpToJcrMetadataBuilder.java:767)
    at com.day.cq.dam.commons.metadata.SimpleXmpToJcrMetadataBuilder.storeXmp(SimpleXmpToJcrMetadataBuilder.java:149)
    at com.day.cq.dam.commons.metadata.SimpleXmpToJcrMetadataBuilder.storeAsXmp(SimpleXmpToJcrMetadataBuilder.java:594)
    at com.day.cq.dam.core.process.ExtractMetadataProcess.saveMetadata(ExtractMetadataProcess.java:158)
    at com.day.cq.dam.core.process.ExtractMetadataProcess.execute(ExtractMetadataProcess.java:125)
    at com.day.cq.workflow.compatibility.CQWorkflowProcessRunner.execute(CQWorkflowProcessRunner.java:93)
    at com.adobe.granite.workflow.core.job.HandlerBase.executeProcess(HandlerBase.java:208)
    at com.adobe.granite.workflow.core.job.JobHandler.process(JobHandler.java:139)
    at org.apache.sling.event.jobs.JobUtil$1.run(JobUtil.java:378)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

 

 

23.10.2013 23:41:40.307 *ERROR* [JobHandler: /etc/workflow/instances/2013-10-23/model_7320686838388:/content/dam/mypdfs/es/MYMail.pdf/jcr:content/metadata] com.day.cq.dam.core.impl.handler.xmp.NCommXMPHandler Stack Trace: com.adobe.granite.asset.api.AssetException: Unable to create version for asset [ /content/dam/mypdfs/es/MYMail.pdf]: 
    at com.adobe.granite.asset.core.impl.AssetVersionManagerImpl.createVersion(AssetVersionManagerImpl.java:83)
    at com.day.cq.dam.core.impl.AssetManagerImpl.createRevision(AssetManagerImpl.java:336)
    at com.day.cq.dam.core.impl.AssetImpl.createRevision(AssetImpl.java:401)
    at com.day.cq.dam.core.impl.handler.xmp.NCommXMPHandler.version(NCommXMPHandler.java:212)
    at com.day.cq.dam.core.impl.handler.xmp.NCommXMPHandler.writeXmp(NCommXMPHandler.java:147)
    at com.day.cq.dam.core.impl.handler.xmp.NCommXMPHandler.writeXmp(NCommXMPHandler.java:129)
    at com.day.cq.dam.core.process.XMPWritebackProcess.writeXmp(XMPWritebackProcess.java:192)
    at com.day.cq.dam.core.process.XMPWritebackProcess.execute(XMPWritebackProcess.java:131)
    at com.day.cq.workflow.compatibility.CQWorkflowProcessRunner.execute(CQWorkflowProcessRunner.java:93)
    at com.adobe.granite.workflow.core.job.HandlerBase.executeProcess(HandlerBase.java:208)
    at com.adobe.granite.workflow.core.job.JobHandler.process(JobHandler.java:139)
    at org.apache.sling.event.jobs.JobUtil$1.run(JobUtil.java:378)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: javax.jcr.RepositoryException: org.apache.jackrabbit.core.state.ItemStateException: Failed to store bundle: 45b1e6f9-1201-4c15-8224-4b6b65888303: java.io.IOException: Unexpected error while writing NAME value.
    at org.apache.jackrabbit.core.version.InternalVersionManagerBase.checkin(InternalVersionManagerBase.java:621)
    at org.apache.jackrabbit.core.version.InternalVersionManagerImpl$4.run(InternalVersionManagerImpl.java:416)
    at org.apache.jackrabbit.core.version.InternalVersionManagerImpl$DynamicESCFactory.doSourced(InternalVersionManagerImpl.java:724)
    at org.apache.jackrabbit.core.version.InternalVersionManagerImpl.checkin(InternalVersionManagerImpl.java:412)
    at org.apache.jackrabbit.core.version.InternalXAVersionManager.checkin(InternalXAVersionManager.java:238)
    at org.apache.jackrabbit.core.version.VersionManagerImplBase.checkoutCheckin(VersionManagerImplBase.java:188)
    at org.apache.jackrabbit.core.VersionManagerImpl.access$100(VersionManagerImpl.java:73)
    at org.apache.jackrabbit.core.VersionManagerImpl$1.perform(VersionManagerImpl.java:122)
    at org.apache.jackrabbit.core.VersionManagerImpl$1.perform(VersionManagerImpl.java:115)
    at org.apache.jackrabbit.core.session.SessionState.perform(SessionState.java:216)
    at org.apache.jackrabbit.core.VersionManagerImpl.perform(VersionManagerImpl.java:96)
    at org.apache.jackrabbit.core.VersionManagerImpl.checkin(VersionManagerImpl.java:115)
    at org.apache.jackrabbit.core.VersionManagerImpl.checkin(VersionManagerImpl.java:101)
    at com.adobe.granite.asset.core.impl.AssetVersionManagerImpl.createVersion(AssetVersionManagerImpl.java:66)
    ... 14 more
Caused by: org.apache.jackrabbit.core.state.ItemStateException: Failed to store bundle: 45b1e6f9-1201-4c15-8224-4b6b65888303: java.io.IOException: Unexpected error while writing NAME value.
    at com.day.crx.persistence.tar.PersistenceManagerUtils.serializeBundle(PersistenceManagerUtils.java:125)
    at com.day.crx.persistence.tar.TarPersistenceManager.storeBundle(TarPersistenceManager.java:372)
    at org.apache.jackrabbit.core.persistence.bundle.AbstractBundlePersistenceManager.putBundle(AbstractBundlePersistenceManager.java:799)
    at org.apache.jackrabbit.core.persistence.bundle.AbstractBundlePersistenceManager.storeInternal(AbstractBundlePersistenceManager.java:714)
    at org.apache.jackrabbit.core.persistence.bundle.AbstractBundlePersistenceManager.store(AbstractBundlePersistenceManager.java:590)
    at com.day.crx.persistence.tar.TarPersistenceManager.access$001(TarPersistenceManager.java:180)
    at com.day.crx.persistence.tar.TarPersistenceManager$1.store(TarPersistenceManager.java:539)
    at com.day.crx.persistence.tar.TarPersistenceManager.tryStore(TarPersistenceManager.java:586)
    at com.day.crx.persistence.tar.TarPersistenceManager.storeTransaction(TarPersistenceManager.java:549)
    at com.day.crx.persistence.tar.TarPersistenceManager.store(TarPersistenceManager.java:536)
    at org.apache.jackrabbit.core.state.SharedItemStateManager$Update.end(SharedItemStateManager.java:788)
    at org.apache.jackrabbit.core.state.SharedItemStateManager.update(SharedItemStateManager.java:1537)
    at org.apache.jackrabbit.core.state.LocalItemStateManager.update(LocalItemStateManager.java:400)
    at org.apache.jackrabbit.core.state.LocalItemStateManager.update(LocalItemStateManager.java:375)
    at org.apache.jackrabbit.core.version.InternalVersionManagerBase$WriteOperation.save(InternalVersionManagerBase.java:248)
    at org.apache.jackrabbit.core.version.InternalVersionManagerBase.checkin(InternalVersionManagerBase.java:618)
    ... 27 more
Caused by: java.io.IOException: Unexpected error while writing NAME value.
    at org.apache.jackrabbit.core.persistence.util.BundleWriter.writeState(BundleWriter.java:312)
    at org.apache.jackrabbit.core.persistence.util.BundleWriter.writeBundle(BundleWriter.java:131)
    at org.apache.jackrabbit.core.persistence.util.BundleBinding.writeBundle(BundleBinding.java:164)
    at com.day.crx.persistence.tar.PersistenceManagerUtils.serializeBundle(PersistenceManagerUtils.java:120)
    ... 42 more

1 Accepted Solution

Avatar

Correct answer by
Level 2

dc:title property might have defined as multi-valued property. otherwise you can try even  String []title={"My title"}; metadataNode.setProperty("dc:title", title ).

Hope this helps.

Thanks

Jv

View solution in original post

5 Replies

Avatar

Community Advisor

Hi

   As far as i coould analyze, i guess you are trying to set a multivalued property to a node. May be u try setting a String variable as

 

String title = "My title" and if you do metadataNode.setProperty("dc:title", title ); 

this issue may get resolved 

 

Thanks

Veena 

Avatar

Level 9

I tried everything it is updating the property and saving it in CRXDE, but I see the exception in error.log.

Any property starting with dc:  ( dublin core ) standards is throwing this exception, rest of the properties look fine. Program is working fine but internally it is throwing this exception when session.save is called.

Avatar

Correct answer by
Level 2

dc:title property might have defined as multi-valued property. otherwise you can try even  String []title={"My title"}; metadataNode.setProperty("dc:title", title ).

Hope this helps.

Thanks

Jv

Avatar

Level 1

you can check whether the property a multiple one like this:

final Property property = metadataNode.getProperty("dc:title");
      if (property.isMultiple()) {

metadataNode.setProperty("dc:title", new String[]{"My title"} );

} else {

metadataNode.setProperty("dc:title", "My title" );

}

Avatar

Level 9

I already have the following methods but still it is throwing the exception

  private void setMetadata(Node node, String property, String value, ValueFactory vf)
      throws Exception {

    if (node.hasProperty(property)) {
      javax.jcr.Property prop = node.getProperty(property);
      Value propValue = vf.createValue(value);
      if (prop.isMultiple()) {

        List updatedVals = new ArrayList();
        updatedVals.addAll(Arrays.asList(propValue));
        node.setProperty(property, (Value[]) updatedVals.toArray(new Value[updatedVals.size()]),
            prop.getType());
      } else {
        node.setProperty(property, propValue, prop.getType());
      }
    } else {
      node.setProperty(property, value);
    }

 

  }