From a261e2bacfc43d9408cbef0e9ad1120399d5f673 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Fri, 17 Jun 2011 05:18:21 +0000 Subject: [PATCH] CSPACE-3441: Added final support in the Services core for tenant specifc document types. --- services/collectionobject/3rdparty/build.xml | 19 ++- .../build.xml | 151 +++++++++++++++++ .../pom.xml | 37 ++++ .../src/main/resources/META-INF/MANIFEST.MF | 17 ++ .../resources/OSGI-INF/core-types-contrib.xml | 15 ++ .../OSGI-INF/deployment-fragment.xml | 10 ++ .../resources/OSGI-INF/ecm-types-contrib.xml | 28 +++ .../resources/OSGI-INF/layouts-contrib.xml | 160 ++++++++++++++++++ .../resources/OSGI-INF/life-cycle-contrib.xml | 9 + .../schemas/collectionobjects_common.xsd | 4 +- .../build.xml | 4 +- .../pom.xml | 9 +- .../src/main/resources/META-INF/MANIFEST.MF | 9 +- .../resources/OSGI-INF/core-types-contrib.xml | 13 +- .../resources/OSGI-INF/ecm-types-contrib.xml | 13 +- .../resources/OSGI-INF/layouts-contrib.xml | 145 +--------------- .../resources/OSGI-INF/life-cycle-contrib.xml | 4 +- .../collectionobjects_naturalhistory.xsd | 143 ---------------- services/collectionobject/3rdparty/pom.xml | 4 +- .../context/AbstractServiceContextImpl.java | 15 ++ .../common/context/ServiceContext.java | 15 ++ .../services/common/query/QueryContext.java | 4 +- .../client/java/RepositoryJavaClientImpl.java | 16 +- .../services/nuxeo/util/NuxeoUtils.java | 70 +++++++- 24 files changed, 582 insertions(+), 332 deletions(-) create mode 100644 services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/build.xml create mode 100644 services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/pom.xml create mode 100644 services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/META-INF/MANIFEST.MF create mode 100644 services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/OSGI-INF/core-types-contrib.xml create mode 100644 services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/OSGI-INF/deployment-fragment.xml create mode 100644 services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/OSGI-INF/ecm-types-contrib.xml create mode 100644 services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/OSGI-INF/layouts-contrib.xml create mode 100644 services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/OSGI-INF/life-cycle-contrib.xml rename services/collectionobject/3rdparty/{nuxeo-platform-cs-collectionobject => nuxeo-platform-collectionobjects_common}/src/main/resources/schemas/collectionobjects_common.xsd (97%) delete mode 100644 services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/schemas/collectionobjects_naturalhistory.xsd diff --git a/services/collectionobject/3rdparty/build.xml b/services/collectionobject/3rdparty/build.xml index b3c70a12a..de0e27d3c 100644 --- a/services/collectionobject/3rdparty/build.xml +++ b/services/collectionobject/3rdparty/build.xml @@ -8,6 +8,9 @@ + + + @@ -112,22 +115,30 @@ - + + + - + + + - + + + - + + + diff --git a/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/build.xml b/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/build.xml new file mode 100644 index 000000000..1df4e901c --- /dev/null +++ b/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/build.xml @@ -0,0 +1,151 @@ + + + + CollectionobjectsCommon Nuxeo document type + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/pom.xml b/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/pom.xml new file mode 100644 index 000000000..b711ec2fe --- /dev/null +++ b/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/pom.xml @@ -0,0 +1,37 @@ + + + org.collectionspace.services + org.collectionspace.services.collectionobject.3rdparty + 1.8-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.collectionobject.collectionobjects_common.nuxeo + org.collectionspace.services.collectionobject.collectionobjects_common.nuxeo + jar + + CollectionObject Common Nuxeo document type + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + src/main/resources/META-INF/MANIFEST.MF + + ${eclipseVersion} + 2 + + + + + + + + diff --git a/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/META-INF/MANIFEST.MF b/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 000000000..d1b213446 --- /dev/null +++ b/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 1 +Bundle-Name: org.collectionspace.collectionobject +Bundle-SymbolicName: org.collectionspace.collectionobject;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Localization: plugin +Bundle-Vendor: Nuxeo +Require-Bundle: org.nuxeo.runtime, + org.nuxeo.ecm.core.api, + org.nuxeo.ecm.core, + org.nuxeo.ecm.webapp.core, + org.collectionspace.collectionspace_core +Provide-Package: org.collectionspace.collectionobject +Nuxeo-Component: OSGI-INF/core-types-contrib.xml, + OSGI-INF/life-cycle-contrib.xml, + OSGI-INF/ecm-types-contrib.xml, + OSGI-INF/layouts-contrib.xml diff --git a/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/OSGI-INF/core-types-contrib.xml b/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/OSGI-INF/core-types-contrib.xml new file mode 100644 index 000000000..21ae46491 --- /dev/null +++ b/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/OSGI-INF/core-types-contrib.xml @@ -0,0 +1,15 @@ + + + + + + + + + collectionobjects_common:objectNumber + collectionobjects_common:objectNameList + collectionobjects_common:responsibleDepartments + + + + diff --git a/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/OSGI-INF/deployment-fragment.xml b/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/OSGI-INF/deployment-fragment.xml new file mode 100644 index 000000000..06404c6a0 --- /dev/null +++ b/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/OSGI-INF/deployment-fragment.xml @@ -0,0 +1,10 @@ + + + + + + ${bundle.fileName} + + + + diff --git a/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/OSGI-INF/ecm-types-contrib.xml b/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/OSGI-INF/ecm-types-contrib.xml new file mode 100644 index 000000000..14b98e49b --- /dev/null +++ b/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/OSGI-INF/ecm-types-contrib.xml @@ -0,0 +1,28 @@ + + + + + + + view_documents + + + heading + collectionspace_core + collectionobjects_common + + + + + + CollectionObject + + + + + + CollectionObject + + + + diff --git a/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/OSGI-INF/layouts-contrib.xml b/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/OSGI-INF/layouts-contrib.xml new file mode 100644 index 000000000..c53e7d2d2 --- /dev/null +++ b/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/OSGI-INF/layouts-contrib.xml @@ -0,0 +1,160 @@ + + + + + + + + + + + objectNumber + otherNumber + otherNumberType + + + + + + distinguishingFeatures + numberOfObjects + + objectName + objectNameCurrency + objectNameLevel + objectNameNote + objectNameSystem + objectNameType + objectNameLanguage + + + title + objectTitleLanguage + titleTranslation + titleType + + + + + + + true + + objectNumber + + + dataInputText + + + + + + + + true + + otherNumber + + + dataInputText + + + + + + + + true + + otherNumberType + + + dataInputText + + + + + + + + + true + + distinguishingFeatures + + + dataInputText + + + + + + + + true + + objectName + + + dataInputText + + + + + + + + + true + + title + + + dataInputText + + + + + + diff --git a/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/OSGI-INF/life-cycle-contrib.xml b/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/OSGI-INF/life-cycle-contrib.xml new file mode 100644 index 000000000..ca558a2f6 --- /dev/null +++ b/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/OSGI-INF/life-cycle-contrib.xml @@ -0,0 +1,9 @@ + + + + + default + + + diff --git a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/schemas/collectionobjects_common.xsd b/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/schemas/collectionobjects_common.xsd similarity index 97% rename from services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/schemas/collectionobjects_common.xsd rename to services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/schemas/collectionobjects_common.xsd index 06605323e..3bc0d7258 100644 --- a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/schemas/collectionobjects_common.xsd +++ b/services/collectionobject/3rdparty/nuxeo-platform-collectionobjects_common/src/main/resources/schemas/collectionobjects_common.xsd @@ -7,8 +7,8 @@ Part : Common Used for: Nuxeo EP core document type - $LastChangedRevision$ - $LastChangedDate$ + $LastChangedRevision: 4736 $ + $LastChangedDate: 2011-05-12 17:36:23 -0700 (Thu, 12 May 2011) $ --> diff --git a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/build.xml b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/build.xml index a8213066f..5ea651d08 100644 --- a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/build.xml +++ b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/build.xml @@ -13,9 +13,9 @@ + value="org.collectionspace.services.collectionobject.CollectionObjectTenant1.nuxeo-${cspace.release}.jar"/> + value="org.collectionspace.services.collectionobject.CollectionObjectTenant1.nuxeo-*.jar"/> diff --git a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/pom.xml b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/pom.xml index 55321ff67..183a03700 100644 --- a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/pom.xml +++ b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/pom.xml @@ -9,11 +9,11 @@ 4.0.0 org.collectionspace.services - org.collectionspace.services.collectionobject.3rdparty.nuxeo - services.collectionobject.3rdparty.nuxeo + org.collectionspace.services.collectionobject.CollectionObjectTenant1.nuxeo + services.collectionobject.CollectionObjectTenant1.nuxeo jar - CollectionObject Nuxeo document type + CollectionObject Nuxeo document type for Tenant ID = "1" @@ -22,9 +22,6 @@ org.apache.maven.plugins maven-jar-plugin - src/main/resources/META-INF/MANIFEST.MF diff --git a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/META-INF/MANIFEST.MF b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/META-INF/MANIFEST.MF index 1a49e9936..97efbb62f 100644 --- a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/META-INF/MANIFEST.MF +++ b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 1 -Bundle-Name: NuxeoCS -Bundle-SymbolicName: org.collectionspace.collectionobject;singleton:=true +Bundle-Name: org.collectionspace.collectionobjecttenant1 +Bundle-SymbolicName: org.collectionspace.collectionobjecttenant1;singleton:=true Bundle-Version: 1.0.0 Bundle-Localization: plugin Bundle-Vendor: Nuxeo @@ -9,8 +9,9 @@ Require-Bundle: org.nuxeo.runtime, org.nuxeo.ecm.core.api, org.nuxeo.ecm.core, org.nuxeo.ecm.webapp.core, - org.collectionspace.collectionspace_core -Provide-Package: org.collectionspace.collectionobject + org.collectionspace.collectionspace_core, + org.collectionspace.collectionobject +Provide-Package: org.collectionspace.collectionobjecttenant1 Nuxeo-Component: OSGI-INF/core-types-contrib.xml, OSGI-INF/life-cycle-contrib.xml, OSGI-INF/ecm-types-contrib.xml, diff --git a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/core-types-contrib.xml b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/core-types-contrib.xml index ae91a1580..8dbaede9c 100644 --- a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/core-types-contrib.xml +++ b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/core-types-contrib.xml @@ -1,20 +1,11 @@ - - - - - + - + - - - collectionobjects_common:objectNumber - collectionobjects_common:objectNameList - collectionobjects_common:responsibleDepartments diff --git a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/ecm-types-contrib.xml b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/ecm-types-contrib.xml index 1627222b9..cc831e163 100644 --- a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/ecm-types-contrib.xml +++ b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/ecm-types-contrib.xml @@ -1,27 +1,28 @@ - + - - + + + view_documents heading collectionspace_core - collectionobject + CollectionObjectTenant1 - CollectionObject + "CollectionObjectTenant1" - CollectionObject + "CollectionObjectTenant1" diff --git a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/layouts-contrib.xml b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/layouts-contrib.xml index 0267b47a5..64369fd09 100644 --- a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/layouts-contrib.xml +++ b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/layouts-contrib.xml @@ -1,161 +1,32 @@ - + - + + - - - - - distinguishingFeatures - numberOfObjects - - objectName - objectNameCurrency - objectNameLevel - objectNameNote - objectNameSystem - objectNameType - objectNameLanguage - - - title - objectTitleLanguage - titleTranslation - titleType + exampleField - + - + true - objectNumber + exampleField dataInputText - - - - - - true - - otherNumber - - - dataInputText - - - - - - - - true - - otherNumberType - - - dataInputText - - - - - - - - - true - - distinguishingFeatures - - - dataInputText - - - - - - - - true - - objectName - - - dataInputText - - - - - - - - - true - - title - - - dataInputText - - - + --> diff --git a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/life-cycle-contrib.xml b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/life-cycle-contrib.xml index 4fa5e8832..3b710368f 100644 --- a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/life-cycle-contrib.xml +++ b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/life-cycle-contrib.xml @@ -1,10 +1,10 @@ - + - default + default diff --git a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/schemas/collectionobjects_naturalhistory.xsd b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/schemas/collectionobjects_naturalhistory.xsd deleted file mode 100644 index 606f5eb4d..000000000 --- a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/schemas/collectionobjects_naturalhistory.xsd +++ /dev/null @@ -1,143 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/services/collectionobject/3rdparty/pom.xml b/services/collectionobject/3rdparty/pom.xml index 4c2f2e227..ef1a30ac6 100644 --- a/services/collectionobject/3rdparty/pom.xml +++ b/services/collectionobject/3rdparty/pom.xml @@ -18,7 +18,9 @@ - nuxeo-platform-cs-collectionobject + nuxeo-platform-collectionobjects_common + nuxeo-platform-cs-collectionobject + nuxeo-platform-collectionobject-hearst diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java b/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java index 2dc344b09..3a611d7dd 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java @@ -336,6 +336,21 @@ public abstract class AbstractServiceContextImpl // object. return (overrideDocumentType != null) ? overrideDocumentType : serviceBinding.getObject().getName(); } + + @Override + public String getTenantQualifiedDoctype(String docType) { + // If they have not overridden the setting, use the type of the service + // object. + String result = docType + ServiceContext.TENANT_SUFFIX + this.getTenantId(); + + return result; + } + + @Override + public String getTenantQualifiedDoctype() { + String docType = (overrideDocumentType != null) ? overrideDocumentType : serviceBinding.getObject().getName(); + return getTenantQualifiedDoctype(docType); + } /* (non-Javadoc) * @see org.collectionspace.services.common.context.ServiceContext#setDocumentType(java.lang.String) diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java index cd0fb5b31..ccfdb588c 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java @@ -32,6 +32,7 @@ import javax.ws.rs.core.UriInfo; import org.collectionspace.services.common.ClientType; import org.collectionspace.services.common.document.DocumentHandler; import org.collectionspace.services.common.document.ValidatorHandler; +import org.collectionspace.services.common.query.QueryContext; import org.collectionspace.services.common.security.SecurityContext; import org.collectionspace.services.common.security.UnauthorizedException; import org.collectionspace.services.common.service.ObjectPartType; @@ -51,6 +52,8 @@ public interface ServiceContext { public static final String PART_LABEL_SEPARATOR = "_"; /** The Constant PART_COMMON_LABEL. */ public static final String PART_COMMON_LABEL = "common"; + /** Used to qualify document types **/ + public static final String TENANT_SUFFIX = "Tenant"; /** * getSecurityContext is contains security info. for the service layer @@ -92,6 +95,18 @@ public interface ServiceContext { * @return service name */ public String getDocumentType(); + + /** + * Returns a tenant qualified document type. + * + */ + public String getTenantQualifiedDoctype(); + + /** + * Returns a tenant qualified document type. + * + */ + public String getTenantQualifiedDoctype(String docType); /** * setDocumentType sets the name of the Document Type for this service diff --git a/services/common/src/main/java/org/collectionspace/services/common/query/QueryContext.java b/services/common/src/main/java/org/collectionspace/services/common/query/QueryContext.java index 1ba06a4f1..f23e1786b 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/query/QueryContext.java +++ b/services/common/src/main/java/org/collectionspace/services/common/query/QueryContext.java @@ -31,9 +31,7 @@ public class QueryContext { String tenantId; static public final String getTenantQualifiedDoctype(QueryContext queryContext, String docType) { -// return queryContext.getTenantId() + "_" + docType; - return docType; //FIXME: Need to use the line above to get a qualified doctype name - + return docType + ServiceContext.TENANT_SUFFIX + queryContext.getTenantId(); } /** diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java index 20bcf75e2..3eadf6ed7 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java @@ -19,6 +19,7 @@ package org.collectionspace.services.nuxeo.client.java; import java.util.Hashtable; import java.util.List; +import java.util.Set; import java.util.UUID; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -58,6 +59,8 @@ import org.nuxeo.ecm.core.api.IdRef; import org.nuxeo.ecm.core.api.PathRef; import org.nuxeo.ecm.core.api.repository.RepositoryInstance; import org.nuxeo.ecm.core.client.NuxeoClient; +import org.nuxeo.ecm.core.schema.SchemaManager; +import org.nuxeo.runtime.api.Framework; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -123,10 +126,12 @@ public class RepositoryJavaClientImpl implements RepositoryClient wrapDoc = new DocumentWrapperImpl(doc); handler.handle(Action.CREATE, wrapDoc); @@ -248,7 +252,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient docTypes, QueryContext queryContext) { + static public final String buildNXQLQuery(List docTypes, QueryContext queryContext) throws Exception { StringBuilder query = new StringBuilder("SELECT * FROM "); boolean fFirst = true; for (String docType : docTypes) { @@ -373,7 +377,7 @@ public class NuxeoUtils { } else { query.append(","); } - String tqDocType = QueryContext.getTenantQualifiedDoctype(queryContext, docType); + String tqDocType = getTenantQualifiedDocType(queryContext, docType); query.append(tqDocType); // Nuxeo doctype must be tenant qualified. } appendNXQLWhere(query, queryContext); @@ -396,7 +400,7 @@ public class NuxeoUtils { // // Since we're doing a query, we get back a list so we need to make sure there is only // a single result since CSID values are supposed to be unique. - String query = buildNXQLQuery(queryContext); + String query = buildNXQLQuery(ctx, queryContext); docModelList = repoSession.query(query); long resultSize = docModelList.totalSize(); if (resultSize == 1) { @@ -511,4 +515,60 @@ public class NuxeoUtils { return result; } + + public static String getTenantQualifiedDocType(ServiceContext ctx, String docType) throws Exception { + String result = docType; + + String tenantQualifiedDocType = ctx.getTenantQualifiedDoctype(docType); + if (docTypeExists(tenantQualifiedDocType) == true) { + result = tenantQualifiedDocType; + } + + return result; + } + + public static String getTenantQualifiedDocType(ServiceContext ctx) { + String result = null; + try { + String docType = ctx.getDocumentType(); + result = getTenantQualifiedDocType(ctx, docType); + } catch (Exception e) { + logger.error("Could not get tentant qualified doctype.", e); + } + return result; + } + + public static String getTenantQualifiedDocType(QueryContext queryCtx, String docType) throws Exception { + String result = docType; + + String tenantQualifiedDocType = queryCtx.getTenantQualifiedDoctype(); + if (docTypeExists(tenantQualifiedDocType) == true) { + result = tenantQualifiedDocType; + } + + return result; + } + + public static String getTenantQualifiedDocType(QueryContext queryCtx) throws Exception { + return getTenantQualifiedDocType(queryCtx, queryCtx.getDocType()); + } + + static private boolean docTypeExists(String docType) throws Exception { + boolean result = false; + + SchemaManager schemaManager = null; + try { + schemaManager = Framework.getService(org.nuxeo.ecm.core.schema.SchemaManager.class); + } catch (Exception e1) { + // TODO Auto-generated catch block + logger.error("Could not get Nuxeo SchemaManager instance.", e1); + throw e1; + } + Set docTypes = schemaManager.getDocumentTypeNamesExtending(docType); + if (docTypes != null && docTypes.contains(docType)) { + result = true; + } + + return result; + } } -- 2.47.3