10-04-2017 08:24 AM
The operation AddEntryToMultivaluedProperty generates the error in the method "run". There is a problem in the line:
List<Serializable> array = p.getValue() != null ? Arrays.asList((Serializable[]) p.getValue()) : null;
It returns an exception:
Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to [Ljava.io.Serializable;
In general, the problem is casting ArrayList returned by p.getValue() to Serializable[].
Schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.nuxeo.org/ecm/schemas/mytest"
xmlns:nxs="http://www.nuxeo.org/ecm/schemas/mytest">
<xs:include schemaLocation="base.xsd" />
<xs:element name="industries" type="nxs:stringList"/>
</xs:schema>
Document definition:
<?xml version="1.0" encoding="UTF-8"?>
<component name="org.nuxeo.mytest.default.types">
<require>org.nuxeo.ecm.core.schema.TypeService</require>
<require>org.nuxeo.ecm.core.CoreExtensions</require>
<require>org.nuxeo.ecm.platform.search.CoreExtensions</require>
<require>org.nuxeo.ecm.platform.search.default.types</require>
<require>org.nuxeo.ecm.platform.types.TypeService</require>
<extension target="org.nuxeo.ecm.core.schema.TypeService" point="schema">
<schema name="myschema" prefix="myschema" src="schemas/myschema.xsd" />
</extension>
<extension target="org.nuxeo.ecm.core.schema.TypeService" point="doctype">
<doctype name="MyDocument" extends="Document">
<schema name="common" />
<schema name="dublincore"/>
<schema name="uid"/>
<schema name="myschema" />
</doctype>
</extension>
<extension target="org.nuxeo.ecm.core.lifecycle.LifeCycleService" point="types">
<types>
<type name="MyDocument">default</type>
</types>
</extension>
<extension target="org.nuxeo.ecm.platform.types.TypeService" point="types">
<type id="MyDocument">
<label>MyDocument</label>
<icon>/icons/file.gif</icon>
<bigIcon>/icons/file_100.png</bigIcon>
<category>SimpleDocument</category>
<default-view>view_documents</default-view>
<layouts mode="any">
<layout>heading</layout>
</layouts>
<layouts mode="edit">
<layout>heading</layout>
</layouts>
<layouts mode="view">
<layout>heading</layout>
</layouts>
</type>
<type id="Folder">
<subtypes>
<type>MyDocument</type>
</subtypes>
</type>
</extension>
</component>
PHP code:
$doc["industries"] = "electrical";
$result = $session->newRequest("AddEntryToMultivaluedProperty")
->set('input', 'doc:'.$mydoc->getPath())
->set('params', 'xpath', 'myschema:industries')
->set('params', 'value', $doc["industries"])
->sendRequest();
10-04-2017 08:38 AM
p.getValue() should always return an array when p is a multi-value property. What is your property exactly?
10-05-2017 05:06 AM
It works in my tests. Nuxeo normalizes simples lists to arrays very early.
The following test, modified from TestSQLRepositoryProperties, succeeds:
@Test
public void testStringArray() throws Exception {
String[] values = { "foo", "bar" };
doc.setPropertyValue("tp:stringArray", values);
// doc.setPropertyValue("tp:stringArray", (Serializable) Arrays.asList(values)); // works too
assertTrue(Arrays.equals(values, (Object[]) doc.getPropertyValue("tp:stringArray")));
doc = session.saveDocument(doc);
assertTrue(Arrays.equals(values, (Object[]) doc.getPropertyValue("tp:stringArray")));
}
Where tp:stringArray is defined as:
<xs:element name="stringArray" type="nxs:stringArrayType" />
<xs:simpleType name="stringArrayType">
<xs:list itemType="xs:string" />
</xs:simpleType>
10-05-2017 09:44 AM
Yes, it works, but it is not the same case. Could you try call the operation ? You can also try execute the equivalent code
10-05-2017 09:49 AM
I understand that you're saying that p.getValue() returns an ArrayList but what I'm saying is that should not be the case and it does not happen in unit tests. Please provide a reproduction case so that we can understand what is happening.
10-05-2017 10:14 AM
I checked it in debugger that it crashes in the line i wroted. The same means the error description, but as you wish I provide the code.
Attention: Blogs & Forums are in READ-ONLY mode from Oct 9-19 as we transition to our new platform. Learn more.
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.