<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: An operation AddEntryToMultivaluedProperty generates an error in Nuxeo Forum</title>
    <link>https://connect.hyland.com/t5/nuxeo-forum/an-operation-addentrytomultivaluedproperty-generates-an-error/m-p/326178#M13179</link>
    <description>&lt;P&gt;It works in my tests. Nuxeo normalizes simples lists to arrays very early.
The following test, modified from &lt;CODE&gt;TestSQLRepositoryProperties&lt;/CODE&gt;, succeeds:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;@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")));
}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Where &lt;CODE&gt;tp:stringArray&lt;/CODE&gt; is defined as:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;&amp;lt;xs:element name="stringArray" type="nxs:stringArrayType" /&amp;gt;
&amp;lt;xs:simpleType name="stringArrayType"&amp;gt;
  &amp;lt;xs:list itemType="xs:string" /&amp;gt;
&amp;lt;/xs:simpleType&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 05 Oct 2017 09:06:59 GMT</pubDate>
    <dc:creator>Florent_Guillau</dc:creator>
    <dc:date>2017-10-05T09:06:59Z</dc:date>
    <item>
      <title>An operation AddEntryToMultivaluedProperty generates an error</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/an-operation-addentrytomultivaluedproperty-generates-an-error/m-p/326175#M13176</link>
      <description>&lt;P&gt;The operation AddEntryToMultivaluedProperty generates the error in the method "run".
There is a problem in the line:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;List&amp;lt;Serializable&amp;gt; array = p.getValue() != null ? Arrays.asList((Serializable[]) p.getValue()) : null;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It returns an exception:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to [Ljava.io.Serializable;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In general, the problem is casting ArrayList returned by p.getValue() to Serializable[].&lt;/P&gt;
&lt;P&gt;Schema:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;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"&amp;gt;
&amp;lt;xs:include schemaLocation="base.xsd" /&amp;gt;
&amp;lt;xs:element name="industries" type="nxs:stringList"/&amp;gt;
&amp;lt;/xs:schema&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Document definition:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;component name="org.nuxeo.mytest.default.types"&amp;gt;
&amp;lt;require&amp;gt;org.nuxeo.ecm.core.schema.TypeService&amp;lt;/require&amp;gt;
&amp;lt;require&amp;gt;org.nuxeo.ecm.core.CoreExtensions&amp;lt;/require&amp;gt;
&amp;lt;require&amp;gt;org.nuxeo.ecm.platform.search.CoreExtensions&amp;lt;/require&amp;gt;
&amp;lt;require&amp;gt;org.nuxeo.ecm.platform.search.default.types&amp;lt;/require&amp;gt;
&amp;lt;require&amp;gt;org.nuxeo.ecm.platform.types.TypeService&amp;lt;/require&amp;gt;
&amp;lt;extension target="org.nuxeo.ecm.core.schema.TypeService" point="schema"&amp;gt;
&amp;lt;schema name="myschema" prefix="myschema" src="schemas/myschema.xsd" /&amp;gt;
&amp;lt;/extension&amp;gt;
&amp;lt;extension target="org.nuxeo.ecm.core.schema.TypeService" point="doctype"&amp;gt;
&amp;lt;doctype name="MyDocument" extends="Document"&amp;gt;
&amp;lt;schema name="common" /&amp;gt;
&amp;lt;schema name="dublincore"/&amp;gt;
&amp;lt;schema name="uid"/&amp;gt;
&amp;lt;schema name="myschema" /&amp;gt;
&amp;lt;/doctype&amp;gt;
&amp;lt;/extension&amp;gt;
&amp;lt;extension target="org.nuxeo.ecm.core.lifecycle.LifeCycleService" point="types"&amp;gt;
&amp;lt;types&amp;gt;
&amp;lt;type name="MyDocument"&amp;gt;default&amp;lt;/type&amp;gt;
&amp;lt;/types&amp;gt;
&amp;lt;/extension&amp;gt;
&amp;lt;extension target="org.nuxeo.ecm.platform.types.TypeService" point="types"&amp;gt;
&amp;lt;type id="MyDocument"&amp;gt;
&amp;lt;label&amp;gt;MyDocument&amp;lt;/label&amp;gt;
&amp;lt;icon&amp;gt;/icons/file.gif&amp;lt;/icon&amp;gt;
&amp;lt;bigIcon&amp;gt;/icons/file_100.png&amp;lt;/bigIcon&amp;gt;
&amp;lt;category&amp;gt;SimpleDocument&amp;lt;/category&amp;gt;
&amp;lt;default-view&amp;gt;view_documents&amp;lt;/default-view&amp;gt;
&amp;lt;layouts mode="any"&amp;gt;
&amp;lt;layout&amp;gt;heading&amp;lt;/layout&amp;gt;
&amp;lt;/layouts&amp;gt;
&amp;lt;layouts mode="edit"&amp;gt;
&amp;lt;layout&amp;gt;heading&amp;lt;/layout&amp;gt;
&amp;lt;/layouts&amp;gt;
&amp;lt;layouts mode="view"&amp;gt;
&amp;lt;layout&amp;gt;heading&amp;lt;/layout&amp;gt;
&amp;lt;/layouts&amp;gt;
&amp;lt;/type&amp;gt;
&amp;lt;type id="Folder"&amp;gt;
&amp;lt;subtypes&amp;gt;
&amp;lt;type&amp;gt;MyDocument&amp;lt;/type&amp;gt;
&amp;lt;/subtypes&amp;gt;
&amp;lt;/type&amp;gt;
&amp;lt;/extension&amp;gt;
&amp;lt;/component&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;PHP code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;$doc["industries"] = "electrical";
$result = $session-&amp;gt;newRequest("AddEntryToMultivaluedProperty")
-&amp;gt;set('input', 'doc:'.$mydoc-&amp;gt;getPath())
-&amp;gt;set('params', 'xpath', 'myschema:industries')
-&amp;gt;set('params', 'value', $doc["industries"])
-&amp;gt;sendRequest();
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Oct 2017 12:24:01 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/an-operation-addentrytomultivaluedproperty-generates-an-error/m-p/326175#M13176</guid>
      <dc:creator>adam_bo_</dc:creator>
      <dc:date>2017-10-04T12:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: An operation AddEntryToMultivaluedProperty generates an error</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/an-operation-addentrytomultivaluedproperty-generates-an-error/m-p/326176#M13177</link>
      <description>&lt;P&gt;&lt;CODE&gt;p.getValue()&lt;/CODE&gt; should always return an array when &lt;CODE&gt;p&lt;/CODE&gt; is a multi-value property. What is your property exactly?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2017 12:38:38 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/an-operation-addentrytomultivaluedproperty-generates-an-error/m-p/326176#M13177</guid>
      <dc:creator>Florent_Guillau</dc:creator>
      <dc:date>2017-10-04T12:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: An operation AddEntryToMultivaluedProperty generates an error</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/an-operation-addentrytomultivaluedproperty-generates-an-error/m-p/326177#M13178</link>
      <description>&lt;P&gt;It is nxs&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2017 06:58:14 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/an-operation-addentrytomultivaluedproperty-generates-an-error/m-p/326177#M13178</guid>
      <dc:creator>adam_bo_</dc:creator>
      <dc:date>2017-10-05T06:58:14Z</dc:date>
    </item>
    <item>
      <title>Re: An operation AddEntryToMultivaluedProperty generates an error</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/an-operation-addentrytomultivaluedproperty-generates-an-error/m-p/326178#M13179</link>
      <description>&lt;P&gt;It works in my tests. Nuxeo normalizes simples lists to arrays very early.
The following test, modified from &lt;CODE&gt;TestSQLRepositoryProperties&lt;/CODE&gt;, succeeds:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;@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")));
}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Where &lt;CODE&gt;tp:stringArray&lt;/CODE&gt; is defined as:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;&amp;lt;xs:element name="stringArray" type="nxs:stringArrayType" /&amp;gt;
&amp;lt;xs:simpleType name="stringArrayType"&amp;gt;
  &amp;lt;xs:list itemType="xs:string" /&amp;gt;
&amp;lt;/xs:simpleType&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Oct 2017 09:06:59 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/an-operation-addentrytomultivaluedproperty-generates-an-error/m-p/326178#M13179</guid>
      <dc:creator>Florent_Guillau</dc:creator>
      <dc:date>2017-10-05T09:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: An operation AddEntryToMultivaluedProperty generates an error</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/an-operation-addentrytomultivaluedproperty-generates-an-error/m-p/326179#M13180</link>
      <description>&lt;P&gt;Yes, it works, but it is not the same case. Could you try call the operation ? You can also try execute the equivalent code&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2017 13:44:52 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/an-operation-addentrytomultivaluedproperty-generates-an-error/m-p/326179#M13180</guid>
      <dc:creator>adam_bo_</dc:creator>
      <dc:date>2017-10-05T13:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: An operation AddEntryToMultivaluedProperty generates an error</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/an-operation-addentrytomultivaluedproperty-generates-an-error/m-p/326180#M13181</link>
      <description>&lt;P&gt;I understand that you're saying that &lt;CODE&gt;p.getValue()&lt;/CODE&gt; returns an &lt;CODE&gt;ArrayList&lt;/CODE&gt; 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.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2017 13:49:30 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/an-operation-addentrytomultivaluedproperty-generates-an-error/m-p/326180#M13181</guid>
      <dc:creator>Florent_Guillau</dc:creator>
      <dc:date>2017-10-05T13:49:30Z</dc:date>
    </item>
    <item>
      <title>Re: An operation AddEntryToMultivaluedProperty generates an error</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/an-operation-addentrytomultivaluedproperty-generates-an-error/m-p/326181#M13182</link>
      <description>&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2017 14:14:30 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/an-operation-addentrytomultivaluedproperty-generates-an-error/m-p/326181#M13182</guid>
      <dc:creator>adam_bo_</dc:creator>
      <dc:date>2017-10-05T14:14:30Z</dc:date>
    </item>
  </channel>
</rss>

