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
<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"
<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"
</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"
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
// 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
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;
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);
}
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
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
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.
}
}
}
+
+ public String getResourcesDir(){
+ return getConfigRootDir() + File.separator + "resources";
+ }
}
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
<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"
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;
*/
- 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
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();
<!-- 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
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>
<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>
<!-- 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
}
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
fillRelation(relationCommon, identifier);
return relationCommon;
}
-
+
private PoxPayloadOut createRelationInstance(RelationsCommon relation) {
PoxPayloadOut result = new PoxPayloadOut(this.getServicePathComponent());
PayloadOutputPart commonPart =
/**
* Fills the relation.
*
- * @param relation the relation
+ * @param relationCommon the relation
* @param identifier the identifier
*/
private void fillRelation(RelationsCommon relationCommon, String identifier) {
/**
* 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
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;
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.
*/
/**
* Creates the relation.
*
- * @param input the input
- *
+ *
* @return the response
*/
@POST
* Update relation.
*
* @param csid the csid
- * @param theUpdate the the update
- *
+ *
* @return the multipart output
*/
@PUT
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 " +
}
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));
+
+ }
+ */
}
+
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;
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;
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
*/
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;