AnsweredAssumed Answered

defining your own basic data types

Question asked by multi_io on Sep 27, 2007
Latest reply on Sep 28, 2007 by davidc
I'm trying to define my own basic data types using <data-type> elements in my model schema XML file (is this supported officially?). Anyway, I'm getting a "Property type not recognised" repository fault when trying to create a node with properties having one of the newly defined data types. A stripped-down example follows:

Model definition (all data types are just mapped to java.lang.String for now):

<model name="s:simpleModel" xmlns="http://www.alfresco.org/model/dictionary/1.0">

   <imports>
        <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm" />
   </imports>

   <namespaces>
      <namespace uri="http://example.com/model/mymodel/simple" prefix="s" />
   </namespaces>

   <data-types>
      <data-type name="s:PN">
         <analyser-class>org.alfresco.repo.search.impl.lucene.analysis.AlfrescoStandardAnalyser</analyser-class>
         <java-class>java.lang.String</java-class>
      </data-type>
      <data-type name="s:SH">
         <analyser-class>org.alfresco.repo.search.impl.lucene.analysis.AlfrescoStandardAnalyser</analyser-class>
         <java-class>java.lang.String</java-class>
      </data-type>
   </data-types>


   <types>

      <type name="s:myObject">
         <parent>cm:content</parent>
         <properties>
            <property name="s:AccessionNumber">
               <type>s:SH</type>
            </property>
            <property name="s:PatientName">
               <type>s:PN</type>
            </property>
         </properties>
      </type>

   </types>


</model>

Creating an instance of s:myObject via the web service API (logged in as admin; compHome is an org.alfresco.webservice.types.Node referring to the "Company Home" folder):

String SIMPLE="http://example.com/model/mymodel/simple";
Store STORE = new Store(Constants.WORKSPACE_STORE, "SpacesStore");

ParentReference pr = new ParentReference(STORE, null, compHome.getReference().getPath(), Constants.ASSOC_CONTAINS, Constants.createQNameString(SIMPLE, "testobj1"));
nameValue = Utils.createNamedValue(Constants.PROP_NAME, "My Test Object 1");
accNumberValue = Utils.createNamedValue(Constants.createQNameString(SIMPLE, "AccessionNumber"), "123456acc1");
patientNameValue =
Utils.createNamedValue(Constants.createQNameString(SIMPLE, "PatientName"), "John Doe");
contentProps = new NamedValue[] {nameValue, accNumberValue, patientNameValue};
createObj = new CMLCreate("ref1", pr, null, null, null, Constants.createQNameString(SIMPLE, "myObject"), contentProps);
cml = new CML();
cml.setCreate(new CMLCreate[] {createObj});
results = repoSvc.update(cml);

This results in:

AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.generalException
faultSubcode:
faultString:
faultActor:
faultNode:
faultDetail:
   {http://www.alfresco.org/ws/service/repository/1.0}RepositoryFault:<ns1:errorCode>0</ns1:errorCode><ns1:message>org.alfresco.error.AlfrescoRuntimeException: Property type not recognised:
   type: {http://example.com/model/mymodel/simple}SH</ns1:message>
   {http://xml.apache.org/axis/}exceptionName:org.alfresco.repo.webservice.repository.RepositoryFault
   {http://xml.apache.org/axis/}stackTrace:
   at org.alfresco.repo.webservice.repository.RepositoryWebService.update(RepositoryWebService.java:518)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)

Why does this happen? Is defining your own data-types verboten? Are there performance penalties involved when doing this? It appears that the data-types/data-type elements aren't defined in modelSchema.xsd even though  dictionaryModel.xml uses them (to define all the standard data types).

Outcomes