Nuxeo 5.6 to 5.8 => RUN SCRIPT - REGRESSION on set list of blob - is it still an Array of Blob ???

Hello,

I got a multi-value blob document property that was perfectly set by a run script such as :

if (WorkflowVariables["newFile"] != null){
java.util.Collections.addAll(Context["listBlob"], Document.getProperty("xpathofme:listBlobsOfMe"));
Context["listBlob"].add( WorkflowVariables["newFile"]  );
//THIS CODE FAILED IN 5.8
Document.doc.setPropertyValue("xpathofme:listBlobsOfMe", Context["listBlob"].toArray());
}

New exception in 5.8 :

Caused by: org.nuxeo.ecm.core.api.model.PropertyConversionException: Property Conversion failed from class java.util.ArrayList to interface org.nuxeo.ecm.core.api.Blob
    at org.nuxeo.ecm.core.api.model.impl.primitives.BlobProperty.normalize(BlobProperty.java:75)
    at org.nuxeo.ecm.core.api.model.impl.AbstractProperty.setValue(AbstractProperty.java:329)
    at org.nuxeo.ecm.core.api.model.impl.ComplexProperty.setValue(ComplexProperty.java:206)
    at org.nuxeo.ecm.core.api.model.impl.osm.ComplexMemberProperty.setValue(ComplexMemberProperty.java:69)
    at org.nuxeo.ecm.core.api.model.impl.ListProperty.setValue(ListProperty.java:253)
    at org.nuxeo.ecm.core.api.impl.DocumentModelImpl.setPropertyValue(DocumentModelImpl.java:1498) 

NOTHING changed in Nuxeo Studio… we just increase version from 5.6 to 5.8 and this list is STILL a blob-list. Do you know why the code doesn't works anymore ?

Thanks

0 votes

1 answers

2146 views

ANSWER



Document.getProperty("xpathofme:listBlobsOfMe") now consistently returns an array for array-like values, whereas in Nuxeo 5.6 it may have returned a list.

So your first addAll adds to Context["listBlob"] a single element which is an array, instead of adding all the elements of the array. You should rework that part.

BTW you don't need the .toArray() in the last statement, Nuxeo will work fine if you pass either an array or a list to setPropertyValue and will normalize the value passed.

0 votes



Hello,

thanks you very much for answering.

After trying to understand what to do, I finally got the solution for this problem in nuxeo 5.8 ->

if (test){

java.util.ArrayList listBlob2 = new java.util.ArrayList(); listBlob2.add( WorkflowVariables["newFile"] );

for(int i=0; i < Document.getProperty("xpathofme:listBlobsOfMe").size(); i++){ listBlob2.add( Document.getProperty("xpathofme:listBlobsOfMe").get(i) ); }

Document.doc.setPropertyValue("xpathofme:listBlobsOfMe", listBlob2 ); }

02/14/2014