]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-3739 added Relation service list elements
authorLaramie Crocker <laramie@berkeley.edu>
Wed, 6 Apr 2011 16:13:08 +0000 (16:13 +0000)
committerLaramie Crocker <laramie@berkeley.edu>
Wed, 6 Apr 2011 16:13:08 +0000 (16:13 +0000)
15 files changed:
services/common-api/src/main/java/org/collectionspace/services/common/api/Tools.java
services/common/src/main/cspace/config/services/tenant-bindings-proto.xml
services/common/src/main/cspace/config/services/tenants/collectionspace/tenant-bindings.xml
services/common/src/main/cspace/config/services/tenants/hearstmuseum/tenant-bindings.xml
services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java
services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingConfigReaderImpl.java
services/common/src/main/java/org/collectionspace/services/common/context/ServiceBindingUtils.java
services/imports/build.xml
services/imports/service/src/main/java/org/collectionspace/services/imports/ImportsResource.java
services/jaxb/src/main/resources/relations_common.xsd
services/pom.xml
services/relation/3rdparty/nuxeo-platform-cs-relation/src/main/resources/schemas/relations_common.xsd
services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java
services/relation/service/src/main/java/org/collectionspace/services/relation/RelationResource.java
services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java

index 0df8fba6de5d24c3f264c645781d1fb21c4d2120..f2eb1fa5fbcdd6e067ebd395560e53109b03464a 100755 (executable)
@@ -160,6 +160,16 @@ public class Tools {
             return "";\r
         }\r
         String s = e.toString() + "\r\n  -- message: " + e.getMessage();\r
+\r
+        StringBuffer causeBuffer = new StringBuffer();\r
+        Throwable cause = e.getCause();\r
+        while (cause != null){\r
+            causeBuffer.append(cause.getClass().getName()+"::"+cause.getMessage()+"\r\n");\r
+            cause = cause.getCause();\r
+        }\r
+        if (causeBuffer.length()>0) s = s + "\r\n  -- Causes: "+causeBuffer.toString();\r
+\r
+\r
         s = s + "\r\n  -- Stack Trace: \r\n  --      " + getStackTrace(e);\r
         return s;\r
     }\r
index d706160535c534e6d7525254a5ab68054265e449..a17acfc22eee3e04b25f79a3424e12c41d2150ce 100644 (file)
             <service:validatorHandler xmlns:service='http://collectionspace.org/services/common/service'>
                 org.collectionspace.services.relation.nuxeo.RelationValidatorHandler
             </service:validatorHandler>
+
+            <service:properties xmlns:service='http://collectionspace.org/services/common/service'>
+                <types:item><types:key>objectNameProperty</types:key><types:value>subjectID</types:value></types:item>
+                <types:item><types:key>objectNumberProperty</types:key><types:value>predicateDisplayName</types:value></types:item>
+            </service:properties>
+
             <service:object name="Relation" version="0.1"
                             xmlns:service='http://collectionspace.org/services/common/service'>
                 <service:part id="0" control_group="Managed"
index aa0ff82d6f3505df52ef69cb3fdffe21b814369f..baa1574fa0ec8b47c3db2cf6d17cf196a351d1e8 100644 (file)
             <service:validatorHandler xmlns:service='http://collectionspace.org/services/common/service'>
                 org.collectionspace.services.objectexit.nuxeo.ObjectExitValidatorHandler
             </service:validatorHandler>
+            <service:properties xmlns:service='http://collectionspace.org/services/common/service'>
+                <types:item><types:key>objectNameProperty</types:key><types:value>currentOwner</types:value></types:item>
+                <types:item><types:key>objectNumberProperty</types:key><types:value>exitNumber</types:value></types:item>
+            </service:properties>
             <service:object name="ObjectExit" version="0.1"
                             xmlns:service='http://collectionspace.org/services/common/service'>
                 <service:part id="0" control_group="Managed"
         </tenant:serviceBindings>
         <!-- end objectexit service meta-data -->
 
+        <!-- begin imports service meta-data -->
+        <tenant:serviceBindings name="Imports" type="procedure" version="0.1">
+            <service:repositoryDomain xmlns:service='http://collectionspace.org/services/common/service'>
+                default-domain
+            </service:repositoryDomain>
+            <service:documentHandler xmlns:service='http://collectionspace.org/services/common/service'>
+                org.collectionspace.services.imports.nuxeo.ImportsDocumentModelHandler
+            </service:documentHandler>
+            <service:DocHandlerParams xmlns:service='http://collectionspace.org/services/common/service'>
+                <service:classname>org.collectionspace.services.imports.nuxeo.ImportsDocumentModelHandler</service:classname>
+                <service:params>
+                    <service:SchemaName>imports</service:SchemaName>
+                    <service:DublinCoreTitle>imports</service:DublinCoreTitle>
+                    <service:SummaryFields>importsField|uri|csid</service:SummaryFields>
+                    <service:AbstractCommonListClassname>org.collectionspace.services.imports.ImportsCommonList</service:AbstractCommonListClassname>
+                    <service:CommonListItemClassname>org.collectionspace.services.imports.ImportsCommonList$ImportsListItem
+                    </service:CommonListItemClassname>
+                    <service:ListResultsItemMethodName>getImportsListItem</service:ListResultsItemMethodName>
+                    <service:ListResultsFields>
+                        <service:ListResultField>
+                            <service:element>importsField</service:element>
+                            <service:xpath>importsField</service:xpath>
+                        </service:ListResultField>
+                    </service:ListResultsFields>
+                </service:params>
+            </service:DocHandlerParams>
+            <service:object name="Imports" version="0.1"
+                            xmlns:service='http://collectionspace.org/services/common/service'>
+                <service:part id="0" control_group="Managed"
+                              versionable="true" auditable="false"
+                              label="imports-system" updated="" order="0">
+                    <service:content contentType="application/xml">
+                        <service:xmlContent
+                                namespaceURI="http://collectionspace.org/services/common/system"
+                                schemaLocation="http://collectionspace.org/services/common/system http://collectionspace.org/services/common/system/system-response.xsd">
+                        </service:xmlContent>
+                    </service:content>
+                </service:part>
+                <service:part id="1" control_group="Managed"
+                              versionable="true" auditable="false"
+                              label="imports_common" updated="" order="1">
+                    <service:content contentType="application/xml">
+                        <service:xmlContent
+                                namespaceURI="http://collectionspace.org/services/imports"
+                                schemaLocation="http://collectionspace.org/services/imports http://services.collectionspace.org/imports/imports_common.xsd">
+                        </service:xmlContent>
+                    </service:content>
+                </service:part>
+                <service:part id="2" control_group="Managed"
+                              versionable="true" auditable="false"
+                              label="collectionspace_core" updated="" order="2">
+                    <service:content contentType="application/xml">
+                        <service:xmlContent
+                                namespaceURI="http://collectionspace.org/collectionspace_core/"
+                                schemaLocation="http://collectionspace.org/collectionspace_core/ http://services.collectionspace.org/collectionspace_core.xsd">
+                        </service:xmlContent>
+                    </service:content>
+                </service:part>
+            </service:object>
+        </tenant:serviceBindings>
+        <!-- end imports service meta-data -->
+
         <!-- begin media service meta-data -->
         <tenant:serviceBindings name="Media" type="procedure" version="0.1">
             <service:repositoryDomain xmlns:service='http://collectionspace.org/services/common/service'>
             <service:validatorHandler xmlns:service='http://collectionspace.org/services/common/service'>
                 org.collectionspace.services.relation.nuxeo.RelationValidatorHandler
             </service:validatorHandler>
+            <service:properties xmlns:service='http://collectionspace.org/services/common/service'>
+                <types:item><types:key>objectNameProperty</types:key><types:value>documentId1</types:value></types:item>
+                <types:item><types:key>objectNumberProperty</types:key><types:value>predicateDisplayName</types:value></types:item>
+            </service:properties>
+
             <service:object name="Relation" version="0.1"
                             xmlns:service='http://collectionspace.org/services/common/service'>
                 <service:part id="0" control_group="Managed"
index da96035321f978633a868283e52c2c41c0a0f365..40da882fcd5f58dcd992b8d4d3d34c49c050ab35 100644 (file)
         </tenant:serviceBindings>
         <!-- end objectexit service meta-data -->
 
+        <!-- begin imports service meta-data -->
+        <tenant:serviceBindings name="Imports" type="procedure" version="0.1">
+            <service:repositoryDomain xmlns:service='http://collectionspace.org/services/common/service'>
+                default-domain
+            </service:repositoryDomain>
+            <service:documentHandler xmlns:service='http://collectionspace.org/services/common/service'>
+                org.collectionspace.services.imports.nuxeo.ImportsDocumentModelHandler
+            </service:documentHandler>
+            <service:DocHandlerParams xmlns:service='http://collectionspace.org/services/common/service'>
+                <service:classname>org.collectionspace.services.imports.nuxeo.ImportsDocumentModelHandler</service:classname>
+                <service:params>
+                    <service:SchemaName>imports</service:SchemaName>
+                    <service:DublinCoreTitle>imports</service:DublinCoreTitle>
+                    <service:SummaryFields>importsField|uri|csid</service:SummaryFields>
+                    <service:AbstractCommonListClassname>org.collectionspace.services.imports.ImportsCommonList</service:AbstractCommonListClassname>
+                    <service:CommonListItemClassname>org.collectionspace.services.imports.ImportsCommonList$ImportsListItem
+                    </service:CommonListItemClassname>
+                    <service:ListResultsItemMethodName>getImportsListItem</service:ListResultsItemMethodName>
+                    <service:ListResultsFields>
+                        <service:ListResultField>
+                            <service:element>importsField</service:element>
+                            <service:xpath>importsField</service:xpath>
+                        </service:ListResultField>
+                    </service:ListResultsFields>
+                </service:params>
+            </service:DocHandlerParams>
+            <service:object name="Imports" version="0.1"
+                            xmlns:service='http://collectionspace.org/services/common/service'>
+                <service:part id="0" control_group="Managed"
+                              versionable="true" auditable="false"
+                              label="imports-system" updated="" order="0">
+                    <service:content contentType="application/xml">
+                        <service:xmlContent
+                                namespaceURI="http://collectionspace.org/services/common/system"
+                                schemaLocation="http://collectionspace.org/services/common/system http://collectionspace.org/services/common/system/system-response.xsd">
+                        </service:xmlContent>
+                    </service:content>
+                </service:part>
+                <service:part id="1" control_group="Managed"
+                              versionable="true" auditable="false"
+                              label="imports_common" updated="" order="1">
+                    <service:content contentType="application/xml">
+                        <service:xmlContent
+                                namespaceURI="http://collectionspace.org/services/imports"
+                                schemaLocation="http://collectionspace.org/services/imports http://services.collectionspace.org/imports/imports_common.xsd">
+                        </service:xmlContent>
+                    </service:content>
+                </service:part>
+                <service:part id="2" control_group="Managed"
+                              versionable="true" auditable="false"
+                              label="collectionspace_core" updated="" order="2">
+                    <service:content contentType="application/xml">
+                        <service:xmlContent
+                                namespaceURI="http://collectionspace.org/collectionspace_core/"
+                                schemaLocation="http://collectionspace.org/collectionspace_core/ http://services.collectionspace.org/collectionspace_core.xsd">
+                        </service:xmlContent>
+                    </service:content>
+                </service:part>
+            </service:object>
+        </tenant:serviceBindings>
+        <!-- end imports service meta-data -->
+
         <!-- begin media service meta-data -->
         <tenant:serviceBindings name="Media" type="procedure" version="0.1">
             <service:repositoryDomain xmlns:service='http://collectionspace.org/services/common/service'>
             <service:validatorHandler xmlns:service='http://collectionspace.org/services/common/service'>
                 org.collectionspace.services.relation.nuxeo.RelationValidatorHandler
             </service:validatorHandler>
+
+            <service:properties xmlns:service='http://collectionspace.org/services/common/service'>
+                <types:item><types:key>objectNameProperty</types:key><types:value>subjectID</types:value></types:item>
+                <types:item><types:key>objectNumberProperty</types:key><types:value>predicateDisplayName</types:value></types:item>
+            </service:properties>
+
             <service:object name="Relation" version="0.1"
                             xmlns:service='http://collectionspace.org/services/common/service'>
                 <service:part id="0" control_group="Managed"
index 5f8e5ae879299c5eb848845b487bad58e0ea4f8f..c1bee552b8085ce72aa29c2e8ef464adcfc1b9c0 100644 (file)
@@ -38,6 +38,7 @@ import javax.ws.rs.core.Response;
 import org.collectionspace.services.client.PoxPayloadIn;\r
 import org.collectionspace.services.client.PoxPayloadOut;\r
 import org.collectionspace.services.client.workflow.WorkflowClient;\r
+import org.collectionspace.services.common.api.Tools;\r
 import org.collectionspace.services.common.context.MultipartServiceContext;\r
 import org.collectionspace.services.common.context.MultipartServiceContextFactory;\r
 import org.collectionspace.services.common.context.ServiceContext;\r
@@ -93,8 +94,9 @@ public abstract class AbstractMultiPartCollectionSpaceResourceImpl extends
                        // so just pass it on\r
                        return (WebApplicationException)e;\r
                } else { // e is now instanceof Exception\r
+            String detail = Tools.errorToString(e, true);\r
                        response = Response.status(Response.Status.INTERNAL_SERVER_ERROR)\r
-                                       .entity(serviceMsg).type("text/plain").build();\r
+                                       .entity(serviceMsg+" detail: "+detail).type("text/plain").build();\r
                        return new WebApplicationException(response);\r
                }\r
        }\r
index f956f674fe0ce058f7e48955ead6e3b8979af7ad..b819b823495a23337b49f67a723ff2ad6d77b00b 100644 (file)
@@ -30,6 +30,7 @@ import java.util.Hashtable;
 import java.util.List;
 
 import org.collectionspace.services.common.service.ServiceBindingType;
+import org.collectionspace.services.common.service.ServiceObjectType;
 import org.collectionspace.services.common.tenant.RepositoryDomainType;
 import org.collectionspace.services.common.tenant.TenantBindingType;
 import org.collectionspace.services.common.tenant.TenantBindingConfig;
@@ -61,6 +62,11 @@ public class TenantBindingConfigReaderImpl
     private Hashtable<String, ServiceBindingType> serviceBindings =
             new Hashtable<String, ServiceBindingType>();
 
+    //tenant-qualified service object name to service name, service binding
+    private Hashtable<String, ServiceBindingType> docTypes =
+            new Hashtable<String, ServiceBindingType>();
+
+
     public TenantBindingConfigReaderImpl(String serverRootDir) {
         super(serverRootDir);
     }
@@ -161,6 +167,15 @@ public class TenantBindingConfigReaderImpl
             String key = getTenantQualifiedServiceName(tenantBinding.getId(),
                     serviceBinding.getName());
             serviceBindings.put(key, serviceBinding);
+
+            if (serviceBinding!=null){
+                ServiceObjectType objectType = serviceBinding.getObject();
+                if (objectType!=null){
+                    String docType = objectType.getName();
+                    String docTypeKey = getTenantQualifiedIdentifier(tenantBinding.getId(), docType);
+                    docTypes.put(docTypeKey, serviceBinding);
+                }
+            }
             if (logger.isDebugEnabled()) {
                 logger.debug("readServiceBindings() added service "
                         + " name=" + key
@@ -239,6 +254,17 @@ public class TenantBindingConfigReaderImpl
         return serviceBindings.get(key);
     }
 
+    /**
+     * getServiceBinding gets service binding for given tenant for a given service
+     * @param tenantId
+     * @param docType
+     * @return
+     */
+    public ServiceBindingType getServiceBindingForDocType (String tenantId, String docType) {
+        String key = getTenantQualifiedIdentifier(tenantId, docType);
+        return docTypes.get(key);
+    }
+
     /**
      * getServiceBinding gets service binding for given tenant for a given service
      * @param tenantId
@@ -272,6 +298,9 @@ public class TenantBindingConfigReaderImpl
         return tenantId + "." + serviceName.toLowerCase();
     }
 
+    public static String getTenantQualifiedIdentifier(String tenantId, String identifier) {
+        return tenantId + "." + identifier;
+    }
     /**
      * Sets properties in the passed list on the local properties for this TenantBinding.
      * Note: will only set properties not already set on the TenantBinding.
@@ -297,4 +326,8 @@ public class TenantBindingConfigReaderImpl
             }
         }
     }
+
+    public String getResourcesDir(){
+        return getConfigRootDir() + File.separator + "resources";
+    }
 }
index 8edfecbd0a8f7aecd951e6687f024cd905e4d5ac..f3587a53fdd6a0b7cec7d40a17c052820a74f04c 100644 (file)
@@ -145,7 +145,7 @@ public class ServiceBindingUtils {
                return (String)docModel.getPropertyValue(propName);\r
        } catch(ClientException ce) {\r
                throw new RuntimeException(\r
-                               "getMappedFieldInDoc: Problem fetching: "+propName, ce);\r
+                               "getMappedFieldInDoc: Problem fetching: "+propName+" logicalfieldName: "+logicalFieldName+" docModel: "+docModel, ce);\r
        }\r
     } \r
 \r
index 6307d113eb578ca53efd54598cb8cbdaeed1ba80..59ec3f0ee8cbd15974d0be7a7f1aabceaa0c7f82 100755 (executable)
     <target name="deploy" depends="install"
     description="deploy imports service">
         <ant antfile="3rdparty/build.xml" target="deploy" inheritall="false"/>
+        <copy todir="${jboss.server.cspace}/cspace/config/resources/templates">
+            <fileset dir="${basedir}/service/src/main/resources/templates"/>
+        </copy>
     </target>
 
     <target name="undeploy"
index ce6c85815f59108fa65bf46ea7ae7a2eabbc4d4b..15e393261135c7d7ce0cec7dfcf0d78056a85dff 100755 (executable)
@@ -25,12 +25,14 @@ package org.collectionspace.services.imports;
 
 import org.collectionspace.services.common.FileUtils;
 import org.collectionspace.services.common.ResourceBase;
+import org.collectionspace.services.common.ServiceMain;
 import org.collectionspace.services.common.ServiceMessages;
 import org.collectionspace.services.common.api.FileTools;
 import org.collectionspace.services.common.api.Tools;
 import org.collectionspace.services.common.api.ZipTools;
 
 // The modified Nuxeo ImportCommand from nuxeo's shell:
+import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;
 import org.collectionspace.services.imports.nuxeo.ImportCommand;
 import org.jboss.resteasy.plugins.providers.multipart.InputPart;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
@@ -96,7 +98,16 @@ public class ImportsResource extends ResourceBase {
     */
 
 
-    public static final String TEMPLATE_DIR = "/src/trunk/services/imports/service/src/main/resources/templates";
+    //public static final String TEMPLATE_DIR = "/src/trunk/services/imports/service/src/main/resources/templates";
+
+    private static String _templateDir = null;
+    public static String getTemplateDir(){
+        if (_templateDir == null){
+            TenantBindingConfigReaderImpl tReader = ServiceMain.getInstance().getTenantBindingConfigReader();
+            _templateDir = tReader.getResourcesDir()+File.separator+"templates";
+        }
+        return _templateDir;
+    }
 
     /** you can test this with something like:
      * curl -X POST http://localhost:8180/cspace-services/imports -i  -u "Admin@collectionspace.org:Administrator" -H "Content-Type: application/xml" -T in.xml
@@ -123,7 +134,7 @@ public class ImportsResource extends ResourceBase {
     public static String createFromInputSource(InputSource inputSource) throws Exception {
         // We must expand the request and wrap it with all kinds of Nuxeo baggage, which expandXmlPayloadToDir knows how to do.
         String outputDir = FileTools.createTmpDir("imports-").getCanonicalPath();
-        expandXmlPayloadToDir(inputSource, TEMPLATE_DIR, outputDir);
+        expandXmlPayloadToDir(inputSource, getTemplateDir(), outputDir);
 
         // Next, call the nuxeo import service, pointing it to our local directory that has the expanded request.
         ImportCommand importCommand = new ImportCommand();
index 58f91f10af0dae6a8c950731d1390dae0538a4d3..d56054346c15b7f94885f1156f53ce869d34205a 100644 (file)
                 <!-- type of relationship between two entities -->\r
                 <xs:element name="relationshipType" type="xs:string" minOccurs="1"/>\r
                 <xs:element name="predicateDisplayName" type="xs:string" minOccurs="1"/>\r
+                <!--- New Names -->\r
+                <xs:element name="subjectCsid" type="xs:string"  minOccurs="1" maxOccurs="1"/>     <!-- new name for documentId1 -->\r
+                <xs:element name="objectCsid" type="xs:string"  minOccurs="1" maxOccurs="1"/>        <!-- new name for documentId2 -->\r
+                <xs:element name="predicate" type="rel:RelationshipType" minOccurs="1" maxOccurs="1"/>   <!-- new name for relationshipType -->\r
             </xs:sequence>\r
         </xs:complexType>\r
     </xs:element>\r
             </xs:appinfo>\r
         </xs:annotation>\r
     </xs:complexType>\r
-    \r
+\r
+\r
+    <xs:complexType name="relationsDocListItem">\r
+        <xs:sequence>\r
+            <xs:element name="uri" type="xs:anyURI" minOccurs="1"/>\r
+            <xs:element name="csid" type="xs:string" minOccurs="1"/>\r
+            <xs:element name="type" type="xs:string" minOccurs="1"/>\r
+            <xs:element name="name" type="xs:string" minOccurs="1"/>\r
+            <xs:element name="number" type="xs:string" minOccurs="1"/>\r
+        </xs:sequence>\r
+    </xs:complexType>\r
+\r
+\r
     <!-- collection objects as in nuxeo repository -->\r
     <xs:element name="relations-common-list">\r
         <xs:complexType>\r
                         <xs:element name="relation-list-item" maxOccurs="unbounded">\r
                             <xs:complexType>\r
                                 <xs:sequence>\r
-                                    <!-- uri to retrive collection object details -->\r
+                                    <!-- uri to retrieve collection object details -->\r
                                     <xs:element name="uri" type="xs:anyURI" minOccurs="1"/>\r
                                     <xs:element name="csid" type="xs:string" minOccurs="1"/>\r
                                     <xs:element name="subjectCsid" type="xs:string" minOccurs="1"/>\r
                                     <xs:element name="relationshipType" type="xs:string" minOccurs="1"/>\r
+                                    <xs:element name="predicate" type="xs:string" minOccurs="1"/>\r
                                     <xs:element name="predicateDisplayName" type="xs:string" minOccurs="1"/>\r
                                     <xs:element name="objectCsid" type="xs:string" minOccurs="1"/>\r
+                                    <xs:element name="subject" type="relationsDocListItem" minOccurs="1"/>\r
+                                    <xs:element name="object" type="relationsDocListItem" minOccurs="1"/>\r
                                 </xs:sequence>\r
                             </xs:complexType>\r
                         </xs:element>\r
index 35fd25fbe1f3e10028570cd22113adc0fa37c7aa..c25091c1446a1fd688b5ed9e97adc5b84c60e6ca 100644 (file)
@@ -20,6 +20,7 @@
     be built after the security module and common modules are built
     -->
     <modules>
+        <module>common-api</module>
         <module>authentication</module>
         <module>authorization</module>
         <module>blob</module>
@@ -28,7 +29,6 @@
         <module>hyperjaxb</module>
         <module>common</module>
         <module>authorization-mgt</module> <!-- relies on authorization -->
-        <module>common-api</module>
         <module>common-test</module>
         <module>account</module> <!-- relies on authorization-mgt.import -->
         <module>note</module>
index 3c9a420b0ab91ed3d72b12d7b0b850c4106b89d2..abfb09147d30a88ac9137275f8eba260aff431b8 100644 (file)
             <!-- document-id-2 would be the id of the contained (or child) collectionobject -->\r
             <!-- document-type-2 would be the doc-type of the collectionobejct -->\r
     <xs:element name="documentId1" type="xs:string"  minOccurs="1" maxOccurs="1"/>\r
+    <xs:element name="subjectCsid" type="xs:string"  minOccurs="1" maxOccurs="1"/>     <!-- new name for documentId1 -->\r
     <xs:element name="documentType1" type="xs:string"  minOccurs="1" maxOccurs="1"/>\r
     <xs:element name="documentId2" type="xs:string"  minOccurs="1" maxOccurs="1"/>\r
+    <xs:element name="objectCsid" type="xs:string"  minOccurs="1" maxOccurs="1"/>        <!-- new name for documentId2 -->\r
     <xs:element name="documentType2" type="xs:string"  minOccurs="1" maxOccurs="1"/>\r
 \r
             <!-- type of relatinoship between two entities -->\r
     <xs:element name="relationshipType" type="rel:RelationshipType" minOccurs="1" maxOccurs="1"/>\r
+    <xs:element name="predicate" type="rel:RelationshipType" minOccurs="1" maxOccurs="1"/>   <!-- new name for relationshipType -->\r
     <xs:element name="predicateDisplayName" type="xs:string" minOccurs="1"/>\r
 \r
     <!-- enumeration defining the type of relationship between two entities -->\r
index 95799715c9138f708f285783f1ac2ce73cfa835e..bfce67d258b78e10331921aa25ee5353d4c7c8e1 100644 (file)
@@ -175,7 +175,7 @@ public class RelationServiceTest extends AbstractServiceTestImpl {
         }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
-        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+        Assert.assertEquals(statusCode, STATUS_INTERNAL_SERVER_ERROR);   //should be an error: same objectID and subjectID are not allowed by validator.
     }
 
     // Failure outcomes
@@ -825,7 +825,7 @@ public class RelationServiceTest extends AbstractServiceTestImpl {
         fillRelation(relationCommon, identifier);
         return relationCommon;
     }
-    
+
     private PoxPayloadOut createRelationInstance(RelationsCommon relation) {
         PoxPayloadOut result = new PoxPayloadOut(this.getServicePathComponent());
         PayloadOutputPart commonPart =
@@ -853,7 +853,7 @@ public class RelationServiceTest extends AbstractServiceTestImpl {
     /**
      * Fills the relation.
      *
-     * @param relation the relation
+     * @param relationCommon the relation
      * @param identifier the identifier
      */
     private void fillRelation(RelationsCommon relationCommon, String identifier) {
@@ -868,7 +868,7 @@ public class RelationServiceTest extends AbstractServiceTestImpl {
     /**
      * Fills the relation.
      *
-     * @param relation the relation
+     * @param relationCommon the relation
      * @param documentId1 the document id1
      * @param documentType1 the document type1
      * @param documentId2 the document id2
index e92eebce92dd5e41a00bd6eb5e7b8a4142b290b5..de01767269b6b6609f3306da9a346d9eac726958 100644 (file)
@@ -42,10 +42,10 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 
-import org.collectionspace.services.client.IQueryManager;
 import org.collectionspace.services.client.PoxPayloadIn;
 import org.collectionspace.services.client.PoxPayloadOut;
-//import org.collectionspace.services.common.query.IQueryManager;
+import org.collectionspace.services.common.context.ServiceBindingUtils;
+import org.collectionspace.services.common.query.IQueryManager;
 import org.collectionspace.services.common.relation.IRelationsManager;
 import org.collectionspace.services.common.relation.nuxeo.RelationsUtils;
 import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl;
@@ -55,11 +55,14 @@ import org.collectionspace.services.common.document.DocumentNotFoundException;
 import org.collectionspace.services.common.document.DocumentHandler;
 import org.collectionspace.services.common.security.UnauthorizedException;
 
+import org.collectionspace.services.common.service.ServiceBindingType;
 import org.jboss.resteasy.util.HttpResponseCodes;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.List;
+
 /**
  * The Class RelationResource.
  */
@@ -104,8 +107,7 @@ public class RelationResource extends
        /**
         * Creates the relation.
         * 
-        * @param input the input
-        * 
+        *
         * @return the response
         */
        @POST
@@ -231,8 +233,7 @@ public class RelationResource extends
         * Update relation.
         * 
         * @param csid the csid
-        * @param theUpdate the the update
-        * 
+        *
         * @return the multipart output
         */
        @PUT
@@ -353,6 +354,17 @@ public class RelationResource extends
                        handler.getDocumentFilter().appendWhereClause(relationClause, IQueryManager.SEARCH_QUALIFIER_AND);                      
                        getRepositoryClient(ctx).getFiltered(ctx, handler);
                        relationList = (RelationsCommonList)handler.getCommonPartList();
+
+
+
+            /*handler.
+            int i=0;
+            for (RelationsCommonList.RelationListItem item: relationList.getRelationListItem()){
+                i++;
+                item.setSubjectDocumentNumber("FooSubjectDocumentNumber" + i);
+                item.setDoc
+            }
+            */
                } catch (UnauthorizedException ue) {
                        Response response = Response.status(Response.Status.UNAUTHORIZED).entity(
                                        "Get relations failed reason " +
@@ -369,5 +381,25 @@ public class RelationResource extends
                }
                
                return relationList;
-       }
+    }
+
+             /*
+    private void fillListItem(){
+        String docType = docModel.getDocumentType().getName();
+        ServiceBindingType sb = queriedServiceBindings.get(docType);
+        if (sb == null) { throw new RuntimeException( "getAuthorityRefDocs: No Service Binding for docType: " + docType); }
+        String serviceContextPath = "/" + sb.getName().toLowerCase() + "/";
+        // The id and URI are the same on all doctypes
+        ilistItem.setDocId(csid);
+        ilistItem.setUri(serviceContextPath + csid);
+        ilistItem.setDocType(docType);
+        ilistItem.setDocNumber(
+        ServiceBindingUtils.getMappedFieldInDoc(sb, ServiceBindingUtils.OBJ_NUMBER_PROP, docModel));
+        ilistItem.setDocName(
+        ServiceBindingUtils.getMappedFieldInDoc(sb,
+        ServiceBindingUtils.OBJ_NAME_PROP, docModel));
+
+    }
+    */
 }
+
index 17ab12de09386195979b6f750e0fd14167e7ad0f..3996c8ec3b62c17bc7af454d44003efd500b93ae 100644 (file)
 package org.collectionspace.services.relation.nuxeo;
 
 import java.util.Iterator;
-import java.util.List;
 
 import org.collectionspace.services.client.PoxPayloadIn;
 import org.collectionspace.services.client.PoxPayloadOut;
+import org.collectionspace.services.common.ServiceMain;
+import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;
+import org.collectionspace.services.common.context.ServiceBindingUtils;
 import org.collectionspace.services.common.relation.RelationJAXBSchema;
 import org.collectionspace.services.common.relation.nuxeo.RelationConstants;
 import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.repository.RepositoryClient;
+import org.collectionspace.services.common.repository.RepositoryClientFactory;
+import org.collectionspace.services.common.service.ServiceBindingType;
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.collectionspace.services.relation.RelationsCommon;
 import org.collectionspace.services.relation.RelationsCommonList;
 import org.collectionspace.services.relation.RelationsCommonList.RelationListItem;
@@ -38,11 +44,10 @@ import org.collectionspace.services.relation.RelationsCommonList.RelationListIte
 import org.collectionspace.services.common.document.DocumentWrapper;
 import org.collectionspace.services.jaxb.AbstractCommonList;
 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
-import org.collectionspace.services.nuxeo.util.NuxeoUtils;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
+import org.collectionspace.services.relation.RelationsDocListItem;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.DocumentModelList;
+import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -55,7 +60,6 @@ import org.slf4j.LoggerFactory;
 public class RelationDocumentModelHandler
         extends RemoteDocumentModelHandlerImpl<RelationsCommon, RelationsCommonList> {
 
-    /** The logger. */
     private final Logger logger = LoggerFactory.getLogger(RelationDocumentModelHandler.class);
     /**
      * relation is used to stash JAXB object to use when handle is called
@@ -68,128 +72,139 @@ public class RelationDocumentModelHandler
      */
     private RelationsCommonList relationList;
 
-
-    /**
-     * getCommonObject get associated Relation
-     * @return relation
-     */
     @Override
     public RelationsCommon getCommonPart() {
         return relation;
     }
 
-    /**
-     * setCommonObject set associated relation
-     * @param relation
-     */
     @Override
     public void setCommonPart(RelationsCommon theRelation) {
         this.relation = theRelation;
     }
 
-    /**
-     * getRelationList get associated Relation (for index/GET_ALL)
-     * @return relationCommonList
+    /**get associated Relation (for index/GET_ALL)
      */
     @Override
     public RelationsCommonList getCommonPartList() {
         return relationList;
     }
 
-    /* (non-Javadoc)
-     * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object)
-     */
     @Override
     public void setCommonPartList(RelationsCommonList theRelationList) {
         this.relationList = theRelationList;
     }
 
-    /* (non-Javadoc)
-     * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper)
-     */
     @Override
     public RelationsCommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
             throws Exception {
         throw new UnsupportedOperationException();
     }
 
-    /* (non-Javadoc)
-     * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
-     */
     @Override
     public void fillCommonPart(RelationsCommon theRelation, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
         throw new UnsupportedOperationException();
     }
 
-    /* (non-Javadoc)
-     * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper)
-     */
     @Override
     public RelationsCommonList extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
         RelationsCommonList relList = this.extractPagingInfo(new RelationsCommonList(), wrapDoc) ;
-        AbstractCommonList commonList = (AbstractCommonList) relList;
-        commonList.setFieldsReturned("subjectCsid|relationshipType|predicateDisplayName|objectCsid|uri|csid");
-        List<RelationsCommonList.RelationListItem> itemList = relList.getRelationListItem();
+        relList.setFieldsReturned("subjectCsid|relationshipType|predicateDisplayName|objectCsid|uri|csid|subject|object");
+        ServiceContext ctx = getServiceContext();
+        String serviceContextPath = getServiceContextPath();
+
+        TenantBindingConfigReaderImpl tReader = ServiceMain.getInstance().getTenantBindingConfigReader();
+        String serviceName = getServiceContext().getServiceName().toLowerCase();
+        ServiceBindingType sbt = tReader.getServiceBinding(ctx.getTenantId(), serviceName);
+
         Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
         while(iter.hasNext()){
             DocumentModel docModel = iter.next();
-            RelationListItem relListItem = getRelationListItem(getServiceContext(),
-                    docModel, getServiceContextPath());
-            itemList.add(relListItem);
+            RelationListItem relListItem = getRelationListItem(ctx, sbt, tReader, docModel, serviceContextPath);
+            relList.getRelationListItem().add(relListItem);
         }
         return relList;
     }
 
-  
-
-    /* (non-Javadoc)
-     * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#fillAllParts(org.collectionspace.services.common.document.DocumentWrapper)
-    @Override
-    public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
-        super.fillAllParts(wrapDoc);
-    }
-     */
-
-    /**
-     * Gets the relation list item.
-     *
+    /** Gets the relation list item, looking up the subject and object documents, and getting summary
+     *  info via the objectName and objectNumber properties in tenant-bindings.
      * @param ctx the ctx
+     * @param sbt the ServiceBindingType of Relations service
+     * @param tReader the tenant-bindings reader, for looking up docnumber and docname
      * @param docModel the doc model
      * @param serviceContextPath the service context path
-     * @return the relation list item
+     * @return the relation list item, with nested subject and object summary info.
      * @throws Exception the exception
      */
     private RelationListItem getRelationListItem(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
-               DocumentModel docModel,
-            String serviceContextPath) throws Exception {
+                                                                        ServiceBindingType sbt,
+                                                                        TenantBindingConfigReaderImpl tReader,
+                                                                        DocumentModel docModel,
+                                                                        String serviceContextPath) throws Exception {
         RelationListItem relationListItem = new RelationListItem();
-        String id = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());
+        String id = getCsid(docModel);
         relationListItem.setCsid(id);
-        //
-        // Subject
-        //
-        relationListItem.setSubjectCsid((String) docModel.getProperty(ctx.getCommonPartLabel(),
-                       RelationJAXBSchema.DOCUMENT_ID_1));
-        //
-        // Predicate
-        //
-        relationListItem.setRelationshipType((String) docModel.getProperty(ctx.getCommonPartLabel(),
-                       RelationJAXBSchema.RELATIONSHIP_TYPE));
-        relationListItem.setPredicateDisplayName((String) docModel.getProperty(ctx.getCommonPartLabel(),
-                       RelationJAXBSchema.RELATIONSHIP_TYPE_DISPLAYNAME));
-        //
-        // Object
-        //
-        relationListItem.setObjectCsid((String) docModel.getProperty(ctx.getCommonPartLabel(),
-                       RelationJAXBSchema.DOCUMENT_ID_2));
+
+        relationListItem.setSubjectCsid((String) docModel.getProperty(ctx.getCommonPartLabel(), RelationJAXBSchema.DOCUMENT_ID_1));
+
+        String predicate = (String) docModel.getProperty(ctx.getCommonPartLabel(), RelationJAXBSchema.RELATIONSHIP_TYPE);
+        relationListItem.setRelationshipType(predicate);
+        relationListItem.setPredicate(predicate); //predicate is new name for relationshipType.
+        relationListItem.setPredicateDisplayName((String) docModel.getProperty(ctx.getCommonPartLabel(), RelationJAXBSchema.RELATIONSHIP_TYPE_DISPLAYNAME));
+
+        relationListItem.setObjectCsid((String) docModel.getProperty(ctx.getCommonPartLabel(), RelationJAXBSchema.DOCUMENT_ID_2));
         
         relationListItem.setUri(serviceContextPath + id);
+
+        //Now fill in summary info for the related docs: subject and object.
+        String subjectCsid = relationListItem.getSubjectCsid();
+        RelationsDocListItem subject = createRelationsDocListItem(ctx, sbt, subjectCsid, tReader);
+        relationListItem.setSubject(subject);
+
+        String objectCsid = relationListItem.getObjectCsid();
+        RelationsDocListItem object = createRelationsDocListItem(ctx, sbt, objectCsid, tReader);
+        relationListItem.setObject(object);
+
         return relationListItem;
     }
 
-    /* (non-Javadoc)
-     * @see org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl#getQProperty(java.lang.String)
-     */
+    protected RelationsDocListItem createRelationsDocListItem(ServiceContext  ctx, 
+                                                                                                 ServiceBindingType sbt,
+                                                                                                 String itemCsid,
+                                                                                                 TenantBindingConfigReaderImpl tReader) throws Exception {
+        RelationsDocListItem item = new RelationsDocListItem();
+       // DocumentModel itemDocModel = docModelFromCSID(ctx, itemCsid);
+        DocumentModel itemDocModel =  NuxeoUtils.getDocFromCsid(getRepositorySession(), ctx, itemCsid);    //null if not found.
+        if (itemDocModel!=null){
+            String itemDocType = itemDocModel.getDocumentType().getName();
+
+            //TODO: ensure that itemDocType is really the entry point, i.e. servicename==doctype
+            //ServiceBindingType itemSbt = tReader.getServiceBinding(ctx.getTenantId(), itemDocType);
+            ServiceBindingType itemSbt = tReader.getServiceBindingForDocType(ctx.getTenantId(), itemDocType);
+            //String bar = "\r\n=======================\r\n";
+            //System.out.println(bar+"itemDocType: "+itemDocType);
+            //System.out.println(bar+"ServiceBindingType: "+itemSbt);
+            //System.out.println(bar);
+
+            try {
+                String itemDocname = ServiceBindingUtils.getMappedFieldInDoc(itemSbt, ServiceBindingUtils.OBJ_NAME_PROP, itemDocModel);
+                item.setName(itemDocname);
+                //System.out.println("\r\n\r\n\r\n=================\r\n~~found prop : "+ServiceBindingUtils.OBJ_NAME_PROP+" in :"+itemDocname);
+            } catch (Throwable t){
+                 System.out.println("\r\n\r\n\r\n=================\r\n NOTE: "+itemDocModel+" field "+ServiceBindingUtils.OBJ_NAME_PROP+" not found in DocModel: "+itemDocModel.getName()+" inner: "+t.getMessage());
+            }
+            try {
+                String itemDocnumber = ServiceBindingUtils.getMappedFieldInDoc(itemSbt, ServiceBindingUtils.OBJ_NUMBER_PROP, itemDocModel);
+                item.setNumber(itemDocnumber);
+                //System.out.println("\r\n\r\n\r\n=================\r\n~~found prop : "+ServiceBindingUtils.OBJ_NUMBER_PROP+" in :"+itemDocnumber);
+            } catch (Throwable t){
+                System.out.println("\r\n\r\n\r\n=================\r\n NOTE:  field "+ServiceBindingUtils.OBJ_NUMBER_PROP+" not found in DocModel: "+itemDocModel.getName()+" inner: "+t.getMessage());
+            }
+            item.setType(itemDocType);
+        }
+        item.setCsid(itemCsid);
+        return item;
+    }
+
     @Override
     public String getQProperty(String prop) {
         return "/" + RelationConstants.NUXEO_SCHEMA_ROOT_ELEMENT + "/" + prop;