ALIADA / aliada-tool

Aliada tool implementation
GNU General Public License v3.0
35 stars 14 forks source link

RDFizer: $xpath.many fails when processing a <blahblah/> tag #122

Closed idoiamurua closed 9 years ago

idoiamurua commented 9 years ago

@agazzarini I was just trying to RDFize one LIDO record that Cristina has sent to me, which contains tags of the following type:

<lido:objectDescriptionWrap/>

that is, tags that are empty but that according to the LIDO mapping, the RDFizer tries to process them with sentences of the following type:

#set($descriptions = $xpath.many("descriptiveMetadata/objectIdentificationWrap/objectDescriptionWrap/objectDescriptionSet/descriptiveNoteValue",$root))

The tag is empty, so the "many" function throws an exception because it cannot convert to a NodeList. The exception thrown by the RDFizer is the following:

org.apache.velocity.exception.MethodInvocationException: Invocation of method 'many' in  class eu.aliada.rdfizer.pipeline.format.xml.OXPath threw exception java.lang.ClassCastException: eu.aliada.rdfizer.pipeline.format.xml.ImmutableNodeList cannot be cast to org.w3c.dom.NodeList at lido.n3.vm[line 395, column 29]
    at org.apache.velocity.runtime.parser.node.ASTMethod.handleInvocationException(ASTMethod.java:243)
    at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:187)
    at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:280)
    at org.apache.velocity.runtime.parser.node.ASTReference.value(ASTReference.java:567)
    at org.apache.velocity.runtime.parser.node.ASTExpression.value(ASTExpression.java:71)
    at org.apache.velocity.runtime.parser.node.ASTSetDirective.render(ASTSetDirective.java:142)
    at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:342)
    at org.apache.velocity.Template.merge(Template.java:356)
    at org.apache.velocity.Template.merge(Template.java:260)
    at eu.aliada.rdfizer.pipeline.format.xml.SynchXmlDocumentTranslator.process(SynchXmlDocumentTranslator.java:140)
    at org.apache.camel.processor.DelegateSyncProcessor.process(DelegateSyncProcessor.java:63)
    at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
    at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:163)
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
    at org.apache.camel.component.seda.SedaConsumer.sendToConsumers(SedaConsumer.java:291)
    at org.apache.camel.component.seda.SedaConsumer.doRun(SedaConsumer.java:200)
    at org.apache.camel.component.seda.SedaConsumer.run(SedaConsumer.java:147)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassCastException: eu.aliada.rdfizer.pipeline.format.xml.ImmutableNodeList cannot be cast to org.w3c.dom.NodeList
    at eu.aliada.rdfizer.pipeline.format.xml.OXPath.select(OXPath.java:275)
    at eu.aliada.rdfizer.pipeline.format.xml.OXPath.many(OXPath.java:336)
    at sun.reflect.GeneratedMethodAccessor78.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.doInvoke(UberspectImpl.java:395)
    at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:384)
    at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:173)

Any idea on how to avoid this situation?

idoiamurua commented 9 years ago

The same applies to $xpath.one function. If the input LIDO record contains <lido:inscriptionsWrap/>:

...
         <lido:objectIdentificationWrap>
            <lido:titleWrap>
               <lido:titleSet>
                  <lido:appellationValue lido:pref="preferred">La Primavera / Spring</lido:appellationValue>
                  <lido:appellationValue lido:pref="preferred" xml:lang="en">La Primavera / Spring</lido:appellationValue>
               </lido:titleSet>
            </lido:titleWrap>
            <lido:inscriptionsWrap/>
            <lido:repositoryWrap>
...

and I place in the mapping file:

## OBJECT INSCRIPTIONS BEGIN
#set($inscriptionsWrap = $xpath.one("descriptiveMetadata/objectIdentificationWrap/inscriptionsWrap",$root))
#if ($inscriptionsWrap)
    #set($inscriptions = $xpath.many("descriptiveMetadata/objectIdentificationWrap/inscriptionsWrap/inscriptions/inscriptionDescription/descriptiveNoteValue",$root))

it throws the same mapping exception, but in the second set (the one with xpath.many)

If I place in the mapping file:

## OBJECT INSCRIPTIONS BEGIN
#set($inscriptionsWrap = $xpath.one("descriptiveMetadata/objectIdentificationWrap/inscriptionsWrap/inscriptions",$root))
#if ($inscriptionsWrap)
    #set($inscriptions = $xpath.many("descriptiveMetadata/objectIdentificationWrap/inscriptionsWrap/inscriptions/inscriptionDescription/descriptiveNoteValue",$root))

it throws the same mapping exception, but in the first set (the one with xpath.one)

org.apache.velocity.exception.MethodInvocationException: Invocation of method 'one' in  class eu.aliada.rdfizer.pipeline.format.xml.OXPath threw exception java.lang.ClassCastException: eu.aliada.rdfizer.pipeline.format.xml.ImmutableNodeList cannot be cast to org.w3c.dom.NodeList at lido.n3.vm[line 49, column 33]
idoiamurua commented 9 years ago

@agazzarini I have just updated the LIDO mapping template to check for the following empty tags:

<lido:inscriptionsWrap/>
<lido:displayStateEditionWrap/>
<lido:objectDescriptionWrap/>
<lido:rightsWorkWrap/>

in the following way:

#set($inscriptionsWrap = $xpath.one("descriptiveMetadata/objectIdentificationWrap/inscriptionsWrap",$root))
#set($inscriptionsWrapValue = $inscriptionsWrap.textContent)
#if ($function.isNotNullAndNotEmpty($inscriptionsWrapValue))
agazzarini commented 9 years ago

Ok, many thanks (sorry for the absence, I'm fighting with a production issue)

On 09/25/2015 12:20 PM, Idoia wrote:

@agazzarini https://github.com/agazzarini I have just updated the LIDO mapping template to check for the following empty tags:

|lido:inscriptionsWrap/ lido:displayStateEditionWrap/ lido:objectDescriptionWrap/ lido:rightsWorkWrap/ |

in the following way:

|#set($inscriptionsWrap = $xpath.one("descriptiveMetadata/objectIdentificationWrap/inscriptionsWrap",$root))

set($inscriptionsWrapValue = $inscriptionsWrap.textContent) #if

($function.isNotNullAndNotEmpty($inscriptionsWrapValue)) |

— Reply to this email directly or view it on GitHub https://github.com/ALIADA/aliada-tool/issues/122#issuecomment-143181954.