From: Patrick Schmitz Date: Tue, 27 Mar 2012 15:48:29 +0000 (-0700) Subject: CSPACE-4693 - working on using lifesci tenant to prove the merge code works as we... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=5879ef8d03473a70ec320709303fc9e8308efeca;p=tmp%2Fjakarta-migration.git CSPACE-4693 - working on using lifesci tenant to prove the merge code works as we want. Also fixing up some problems with tenant-specific (extended) document types, and functionality in relations, refObjs, serviceGroup search, etc. --- diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java index b5119587d..07d717397 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java @@ -743,14 +743,10 @@ public abstract class AuthorityResource ServiceContext ctx = createServiceContext(getItemServiceName(), queryParams); String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "getReferencingObjects(item)", "GET_ITEM_REF_OBJS", ctx); - String serviceType = ServiceBindingUtils.SERVICE_TYPE_PROCEDURE; - List list = queryParams.remove(ServiceBindingUtils.SERVICE_TYPE_PROP); - if (list != null) { - serviceType = list.get(0); + List serviceTypes = queryParams.remove(ServiceBindingUtils.SERVICE_TYPE_PROP); + if(serviceTypes == null || serviceTypes.isEmpty()) { + serviceTypes = ServiceBindingUtils.getCommonServiceTypes(); } - // Could be smarter about using the list from above, and/or allowing multiple - ArrayList serviceTypes = new ArrayList(1); - serviceTypes.add(serviceType); // Note that we have to create the service context for the Items, not the main service // We omit the parentShortId, only needed when doing a create... diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java index 0daa61835..32f49c451 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java @@ -353,7 +353,7 @@ public abstract class AuthorityItemDocumentModelHandler public AuthorityRefDocList getReferencingObjects( ServiceContext ctx, - ArrayList serviceTypes, + List serviceTypes, String propertyName, String itemcsid) throws Exception { AuthorityRefDocList authRefDocList = null; diff --git a/services/common/src/main/cspace/config/services/tenants/lifesci/tenant-bindings.delta.xml b/services/common/src/main/cspace/config/services/tenants/lifesci/tenant-bindings.delta.xml index 2cd346a9d..3de2dde8a 100644 --- a/services/common/src/main/cspace/config/services/tenants/lifesci/tenant-bindings.delta.xml +++ b/services/common/src/main/cspace/config/services/tenants/lifesci/tenant-bindings.delta.xml @@ -40,10 +40,12 @@ authRef taxonomicIdentGroupList/*/institution + diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceBindingUtils.java b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceBindingUtils.java index 248ad43c8..9d6afc82d 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceBindingUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceBindingUtils.java @@ -3,6 +3,9 @@ package org.collectionspace.services.common.context; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; import org.collectionspace.services.common.config.PropertyItemUtils; import org.collectionspace.services.common.service.ObjectPartType; @@ -32,6 +35,10 @@ public class ServiceBindingUtils { public static final String SERVICE_TYPE_AUTHORITY = "authority"; public static final String SERVICE_TYPE_UTILITY = "utility"; public static final String SERVICE_TYPE_SECURITY = "security"; + + private static final String TENANT_EXTENSION_PATTERN = "(.*)"+ServiceContext.TENANT_SUFFIX+"[\\d]+$"; + private static final String TENANT_REPLACEMENT_PATTERN = "$1"; + private static Pattern tenantSuffixPattern = null; private static final Logger logger = LoggerFactory.getLogger(ServiceBindingUtils.class); @@ -40,6 +47,21 @@ public class ServiceBindingUtils { return result; } + public static String getUnqualifiedTenantDocType(String docType) { + try { + if(tenantSuffixPattern == null ) { + tenantSuffixPattern = Pattern.compile(TENANT_EXTENSION_PATTERN); + } + Matcher tenantSuffixMatcher = tenantSuffixPattern.matcher(docType); + return tenantSuffixMatcher.replaceFirst(TENANT_REPLACEMENT_PATTERN); + } catch (PatternSyntaxException pe) { + logger.warn("TENANT_EXTENSION_PATTERN regex pattern '" + TENANT_EXTENSION_PATTERN + + "' could not be compiled: " + pe.getMessage()); + // If reached, method will return a value of false. + } + return docType; + } + // TODO consider building up a hashTable of the properties for each // service binding. There will be generic properties, as well as // properties on each part. Could build up a key from tenant id, diff --git a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java index 92a016006..d26682120 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java @@ -436,6 +436,7 @@ public class RefNameServiceUtils { AuthorityRefDocList.AuthorityRefDocItem ilistItem; String docType = docModel.getDocumentType().getName(); + docType = ServiceBindingUtils.getUnqualifiedTenantDocType(docType); ServiceBindingType sb = queriedServiceBindings.get(docType); if (sb == null) { throw new RuntimeException( 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 ebd2323fc..cdf35a9d9 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 @@ -261,6 +261,7 @@ public class RelationDocumentModelHandler DocumentModel itemDocModel = NuxeoUtils.getDocFromCsid(ctx, this.getRepositorySession(), itemCsid); //null if not found. if (itemDocModel != null) { String itemDocType = itemDocModel.getDocumentType().getName(); + itemDocType = ServiceBindingUtils.getUnqualifiedTenantDocType(itemDocType); if (Tools.isBlank(documentType)) { item.setDocumentType(itemDocType); } @@ -360,7 +361,8 @@ public class RelationDocumentModelHandler HashMap properties = new HashMap(); try { - String doctype = (String) subjectOrObjectDocModel.getType(); + String doctype = subjectOrObjectDocModel.getDocumentType().getName(); + doctype = ServiceBindingUtils.getUnqualifiedTenantDocType(doctype); properties.put((fSubject?RelationJAXBSchema.SUBJECT_DOCTYPE:RelationJAXBSchema.OBJECT_DOCTYPE), doctype); diff --git a/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java b/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java index 207321b81..3eea303d0 100644 --- a/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java +++ b/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java @@ -212,6 +212,7 @@ public class ServiceGroupDocumentModelHandler while (iter.hasNext()) { DocumentModel docModel = iter.next(); String docType = docModel.getDocumentType().getName(); + docType = ServiceBindingUtils.getUnqualifiedTenantDocType(docType); ServiceBindingType sb = queriedServiceBindings.get(docType); if (sb == null) { throw new RuntimeException(