From dbce84b077c42d89412eb17c5842af43bb5fe9f4 Mon Sep 17 00:00:00 2001 From: Laramie Crocker Date: Tue, 10 May 2011 12:37:37 +0000 Subject: [PATCH] CSPACE-3932 Fixed AuthorityItemDocumentModelHandler.java to correctly insert the cspace-services uri where the uri is not the same as the servicename, e.g. persons vs. personauthorities. Applies to personauthorities, orgauthorities, locationauthorities --- .../xmlreplay/ServiceResult.java | 2 +- .../xmlreplay/XmlReplayEval.java | 1 + .../xmlreplay/XmlCompareJdom/3-left.xml | 80 ++++++++++++ .../xmlreplay/XmlCompareJdom/3-right.xml | 122 ++++++++++++++++++ .../test-data/xmlreplay/dev-master.xml | 10 +- .../hierarchy/3-locations_w_relations.xml | 16 +-- .../xmlreplay/location/location-hierarchy.xml | 3 +- .../organization/organization-hierarchy.xml | 1 + .../test-data/xmlreplay/person/person.xml | 2 +- .../test-data/xmlreplay/xml-replay-master.xml | 2 + .../AuthorityItemDocumentModelHandler.java | 22 +++- .../nuxeo/RelationDocumentModelHandler.java | 23 +++- 12 files changed, 269 insertions(+), 15 deletions(-) create mode 100644 services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/3-left.xml create mode 100644 services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/3-right.xml diff --git a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/ServiceResult.java b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/ServiceResult.java index 38b20a42e..26b877cec 100755 --- a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/ServiceResult.java +++ b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/ServiceResult.java @@ -246,7 +246,7 @@ public class ServiceResult { + (expectedCodes.size()>0 ? "; expected:"+expectedCodes : "") + ( Tools.notEmpty(responseMessage) ? "; msg:"+responseMessage : "" ) +"; URL:"+fullURL - +"; auth: "+auth + //for auth, see detail() +"; auth: "+auth + ( Tools.notEmpty(error) ? "; ERROR:"+error : "" ) + (verbosePartsSummary ? partsSummary(true) : partsSummary(false) ) +"}"; diff --git a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayEval.java b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayEval.java index 2662413b2..bd34f2fa4 100755 --- a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayEval.java +++ b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayEval.java @@ -60,6 +60,7 @@ public class XmlReplayEval { //System.out.println("\r\n---- REPLACE.init-uri: "+inputJexlExpression); String result; try { + jc.set("itemCSID", "${itemCSID}"); //noiseless passthru. //System.out.println("eval :: serviceResultsMap "+serviceResultsMap.size()); for (ServiceResult serviceResult : serviceResultsMap.values()) { jc.set(serviceResult.testID, serviceResult); diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/3-left.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/3-left.xml new file mode 100644 index 000000000..4a2963e4e --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/3-left.xml @@ -0,0 +1,80 @@ + + + + + + + 4 + + + + + e6ee870c-0846-4f02-af9f + e65d0867-3d10-4d2e-8eed + hasBroader + + e6ee870c-0846-4f02-af9f + + + e65d0867-3d10-4d2e-8eed + + + + + ba0c9e5f-0c00-4deb-b29d + e6ee870c-0846-4f02-af9f + hasBroader + + ba0c9e5f-0c00-4deb-b29d + + + e6ee870c-0846-4f02-af9f + + + + + + + + + + + 73487157-5110-4292-9cf8 + e6ee870c-0846-4f02-af9f + hasBroader + + 73487157-5110-4292-9cf8 + + + e6ee870c-0846-4f02-af9f + + + + + 6884ecdc-e205-4407-b3f3 + e6ee870c-0846-4f02-af9f + hasBroader + + 6884ecdc-e205-4407-b3f3 + + + e6ee870c-0846-4f02-af9f + + + + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/3-right.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/3-right.xml new file mode 100644 index 000000000..aca90034b --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/XmlCompareJdom/3-right.xml @@ -0,0 +1,122 @@ + + + + + + + + + 0 + 40 + 4 + 4 + subjectCsid|relationshipType|predicateDisplayName|objectCsid|uri|csid|subject|object + + /relations/9fb18981-01b8-486f-8cf6 + 9fb18981-01b8-486f-8cf6 + e6ee870c-0846-4f02-af9f + hasBroader + hasBroader + e65d0867-3d10-4d2e-8eed + + /organizations/e0a427ce-c8b5-4727-8077/items/e6ee870c-0846-4f02-af9f + e6ee870c-0846-4f02-af9f + Organization + Organization + Organization + + + /cspace-services/orgauthorities/urn:cspace:name(CSPACE3739OrganizationAuthority)/items/e65d0867-3d10-4d2e-8eed + e65d0867-3d10-4d2e-8eed + Organization + Organization + Organization + + + + + + + /relations/a9c7f9f0-6cc6-4eaf-9b41 + a9c7f9f0-6cc6-4eaf-9b41 + ba0c9e5f-0c00-4deb-b29d + hasBroader + hasBroader + e6ee870c-0846-4f02-af9f + + /cspace-services/orgauthorities/urn:cspace:name(CSPACE3739OrganizationAuthority)/items/ba0c9e5f-0c00-4deb-b29d + ba0c9e5f-0c00-4deb-b29d + Organization + Organization + Organization + + + /organizations/e0a427ce-c8b5-4727-8077/items/e6ee870c-0846-4f02-af9f + e6ee870c-0846-4f02-af9f + Organization + Organization + Organization + + + + + + + + + /relations/c882dfc1-1b72-4038-88f3 + c882dfc1-1b72-4038-88f3 + 6884ecdc-e205-4407-b3f3 + hasBroader + hasBroader + e6ee870c-0846-4f02-af9f + + /cspace-services/orgauthorities/urn:cspace:name(CSPACE3739OrganizationAuthority)/items/6884ecdc-e205-4407-b3f3 + 6884ecdc-e205-4407-b3f3 + Organization + Organization + Organization + + + /organizations/e0a427ce-c8b5-4727-8077/items/e6ee870c-0846-4f02-af9f + e6ee870c-0846-4f02-af9f + Organization + Organization + Organization + + + + /relations/0793210a-a48c-4d26-a47b + 0793210a-a48c-4d26-a47b + 73487157-5110-4292-9cf8 + hasBroader + hasBroader + e6ee870c-0846-4f02-af9f + + /cspace-services/orgauthorities/urn:cspace:name(CSPACE3739OrganizationAuthority)/items/73487157-5110-4292-9cf8 + 73487157-5110-4292-9cf8 + Organization + Organization + Organization + + + /organizations/e0a427ce-c8b5-4727-8077/items/e6ee870c-0846-4f02-af9f + e6ee870c-0846-4f02-af9f + Organization + Organization + Organization + + + + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/dev-master.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/dev-master.xml index ea2cc929b..bcaa26c93 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/dev-master.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/dev-master.xml @@ -12,7 +12,7 @@ http://localhost:8180 - + YWRtaW5AY29sbGVjdGlvbnNwYWNlLm9yZzpBZG1pbmlzdHJhdG9y @@ -93,8 +93,16 @@ + + + + + + + --> + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/hierarchy/3-locations_w_relations.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/hierarchy/3-locations_w_relations.xml index 53d565663..766a8458e 100755 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/hierarchy/3-locations_w_relations.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/hierarchy/3-locations_w_relations.xml @@ -17,12 +17,12 @@ hasBroader ${itemCSID} - Location + Locationitem ${parentCSID} ${parentUri} - Location + Locationitem @@ -30,11 +30,11 @@ ${childCSID} ${childUri} - Location + Locationitem ${itemCSID} - Location + Locationitem @@ -42,11 +42,11 @@ ${child2Uri} ${child2CSID} - Location + Locationitem ${itemCSID} - Location + Locationitem @@ -54,11 +54,11 @@ ${child3Uri} ${child3CSID} - Location + Locationitem ${itemCSID} - Location + Locationitem diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/location-hierarchy.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/location-hierarchy.xml index cffe39885..0902c69ea 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/location-hierarchy.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/location-hierarchy.xml @@ -1,6 +1,6 @@ - + POST @@ -8,6 +8,7 @@ location/hierarchy/1-authority.xml CSPACE3739LocationAuthority + LocationAuth1-displayName diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/organization/organization-hierarchy.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/organization/organization-hierarchy.xml index 724908b4c..b3ac368a8 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/organization/organization-hierarchy.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/organization/organization-hierarchy.xml @@ -8,6 +8,7 @@ organization/hierarchy/1-authority.xml CSPACE3739OrganizationAuthority + OrganizationAuth1-displayName diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person.xml index 840bbc84e..b13b339cd 100755 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person.xml @@ -238,7 +238,7 @@ !-- ========================= POST a person ===================================================== --> - + POST /cspace-services/personauthorities/ diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/xml-replay-master.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/xml-replay-master.xml index a267c3692..547d2ad29 100755 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/xml-replay-master.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/xml-replay-master.xml @@ -43,6 +43,8 @@ + + diff --git a/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java b/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java index 63244eebd..8bbfd41cf 100644 --- a/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java +++ b/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java @@ -25,6 +25,7 @@ package org.collectionspace.services.common.vocabulary.nuxeo; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.ListIterator; @@ -104,9 +105,28 @@ public abstract class AuthorityItemDocumentModelHandler this.inAuthority = inAuthority; } + // Laramie20110510 CSPACE-3932 + public static final String HACK_VOCABULARIES = "vocabularies"; //TODO: get rid of these. + //public static final String HACK_ORGANIZATIONS = "Organizations"; //TODO: get rid of these. + public static final String HACK_ORGAUTHORITIES = "orgauthorities"; //TODO: get rid of these. + public static final String HACK_PERSONAUTHORITIES = "personauthorities"; //TODO: get rid of these. + public static final String HACK_LOCATIONAUTHORITIES = "locationauthorities"; //TODO: get rid of these. + private final static Map hackMap = new HashMap(); + static { + hackMap.put("persons", HACK_PERSONAUTHORITIES); + hackMap.put("organizations", HACK_ORGAUTHORITIES); + hackMap.put("vocabularies", HACK_VOCABULARIES); + hackMap.put("locations", HACK_LOCATIONAUTHORITIES); + } @Override public String getUri(DocumentModel docModel) { - return getServiceContextPath()+inAuthority+"/"+ AuthorityClient.ITEMS+"/"+getCsid(docModel); + // Laramie20110510 CSPACE-3932 + String serviceContextName = getServiceContext().getServiceName().toLowerCase(); + String displayContextPath = hackMap.get(serviceContextName); + if (Tools.isEmpty(displayContextPath)){ + displayContextPath = serviceContextName; + } + return "/"+displayContextPath+'/'+inAuthority+'/'+ AuthorityClient.ITEMS+'/'+getCsid(docModel); } diff --git a/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java b/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java index e6d08e973..5e48687dd 100644 --- a/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java +++ b/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java @@ -28,6 +28,7 @@ import java.util.Iterator; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.ServiceMain; +import org.collectionspace.services.common.api.Tools; import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl; import org.collectionspace.services.common.context.ServiceBindingUtils; import org.collectionspace.services.common.relation.RelationJAXBSchema; @@ -168,8 +169,8 @@ public class RelationDocumentModelHandler relationListItem.setSubject(subject); String objectCsid = relationListItem.getObjectCsid(); - documentType = (String) docModel.getProperty(ctx.getCommonPartLabel(), RelationJAXBSchema.DOCUMENT_TYPE_2); - RelationsDocListItem object = createRelationsDocListItem(ctx, sbt, objectCsid, tReader, documentType); + String documentType2 = (String) docModel.getProperty(ctx.getCommonPartLabel(), RelationJAXBSchema.DOCUMENT_TYPE_2); + RelationsDocListItem object = createRelationsDocListItem(ctx, sbt, objectCsid, tReader, documentType2); String objectUri = (String) docModel.getProperty(ctx.getCommonPartLabel(), RelationJAXBSchema.objectUri); object.setUri(objectUri); @@ -195,6 +196,22 @@ public class RelationDocumentModelHandler String itemDocType = itemDocModel.getDocumentType().getName(); item.setDocumentTypeFromModel(itemDocType); //this one comes from the nuxeo documentType + System.out.println("\r\n******** AuthorityItemDocumentModelHandlder documentType **************\r\n\tdocModel: "+itemDocType+"\r\n\tpayload: "+documentType); + boolean usedDocumentTypeFromPayload = true; + if ( ! Tools.isBlank(documentType)){ + if (documentType.equals(itemDocType)){ + usedDocumentTypeFromPayload = true; + } else { + // Laramie20110510 CSPACE-3739 throw the exception for 3739, otherwise, don't throw it. + //throw new Exception("documentType supplied was wrong. supplied: "+documentType+" required: "+itemDocType+ " itemCsid: "+itemCsid ); + } + } else { + usedDocumentTypeFromPayload = false; + item.setDocumentType(itemDocType); + + } + + //TODO: ensure that itemDocType is really the entry point, i.e. servicename==doctype //ServiceBindingType itemSbt2 = tReader.getServiceBinding(ctx.getTenantId(), itemDocType); ServiceBindingType itemSbt = tReader.getServiceBindingForDocType(ctx.getTenantId(), itemDocType); @@ -214,6 +231,8 @@ public class RelationDocumentModelHandler } } else { item.setError("INVALID: related object is absent"); + // Laramie20110510 CSPACE-3739 throw the exception for 3739, otherwise, don't throw it. + //throw new Exception("INVALID: related object is absent "+itemCsid); } return item; } -- 2.47.3