From 1a94d3420d34e9748d28064a8bd09fee79717440 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Tue, 6 Dec 2011 20:16:03 +0000 Subject: [PATCH] CSPACE-4639: Added more support for better session and transaction management with Nuxeo EP. --- 3rdparty/nuxeo/build.xml | 2 +- ...rage-sql-management-5.5-I20111104_1115.jar | Bin 0 -> 12055 bytes .../config/datasources-config.xml | 20 +- .../config/default-repo-config.xml | 789 ++++++++++-------- .../CollectionSpaceJaxRsApplication.java | 2 +- .../common/vocabulary/AuthorityResource.java | 11 +- .../nuxeo/AuthorityDocumentModelHandler.java | 20 +- .../AuthorityItemDocumentModelHandler.java | 2 +- .../services/common/ResourceBase.java | 3 +- .../repository/RepositoryClientFactory.java | 12 +- .../common/security/SecurityInterceptor.java | 125 ++- .../vocabulary/RefNameServiceUtils.java | 103 ++- .../client/java/DocumentModelHandler.java | 15 +- .../client/java/NuxeoClientEmbedded.java | 49 +- .../client/java/NuxeoConnectorEmbedded.java | 29 +- .../java/RemoteDocumentModelHandlerImpl.java | 45 +- .../client/java/RepositoryJavaClientImpl.java | 234 ++++-- .../nuxeo/client/java/TenantRepository.java | 18 +- .../services/nuxeo/util/NuxeoUtils.java | 3 +- .../nuxeo/RelationDocumentModelHandler.java | 31 +- 20 files changed, 927 insertions(+), 586 deletions(-) create mode 100644 3rdparty/nuxeo/nuxeo-server/5.5-I20111104_1115/bundles/nuxeo-core-storage-sql-management-5.5-I20111104_1115.jar diff --git a/3rdparty/nuxeo/build.xml b/3rdparty/nuxeo/build.xml index b60b55686..c970aa706 100644 --- a/3rdparty/nuxeo/build.xml +++ b/3rdparty/nuxeo/build.xml @@ -122,7 +122,7 @@ - + diff --git a/3rdparty/nuxeo/nuxeo-server/5.5-I20111104_1115/bundles/nuxeo-core-storage-sql-management-5.5-I20111104_1115.jar b/3rdparty/nuxeo/nuxeo-server/5.5-I20111104_1115/bundles/nuxeo-core-storage-sql-management-5.5-I20111104_1115.jar new file mode 100644 index 0000000000000000000000000000000000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zKRhFT zG>AV+!mrBL(tl8 - - - - nuxeo - @NUXEO_USER@ - @NUXEO_PW@ - - + + + + nuxeo + @NUXEO_USER@ + @NUXEO_PW@ + + diff --git a/3rdparty/nuxeo/nuxeo-server/5.5-I20111104_1115/config/default-repo-config.xml b/3rdparty/nuxeo/nuxeo-server/5.5-I20111104_1115/config/default-repo-config.xml index bc4fab556..62fb50b10 100644 --- a/3rdparty/nuxeo/nuxeo-server/5.5-I20111104_1115/config/default-repo-config.xml +++ b/3rdparty/nuxeo/nuxeo-server/5.5-I20111104_1115/config/default-repo-config.xml @@ -1,372 +1,423 @@ - - - - - @XA_DATASOURCE@ - @DB_URL@ - nuxeo - @NUXEO_USER@ - @NUXEO_PW@ - - imd:user_comment - note - webp:content - webc:welcomeText - comment:comment - post - mail:mail - - - - - - - - - - acquisitionFundingSourceProvisos - acquisitions_common:acquisitionNote - acquisitions_common:acquisitionProvisos - acquisitions_common:acquisitionReason - acquisitions_common:creditLine - - - - - - - - - - - - - - - - - - - collectionobjects_common:otherNumber - - - numberValue - - - collectionobjects_common:briefDescriptions - - - collectionobjects_common:comments - - collectionobjects_common:distinguishingFeatures - - objectNameNote - - title - titleTranslation - - - - - collectionobjects_common:ageQualifier - collectionobjects_common:color - collectionobjects_common:contentDescription - collectionobjects_common:contentNote - collectionobjects_common:contentObject - collectionobjects_common:copyNumber - collectionobjects_common:editionNumber - - - - collectionobjects_common:inscriptionContent - collectionobjects_common:inscriptionContentInterpretation - collectionobjects_common:inscriptionContentTranslation - collectionobjects_common:inscriptionContentTransliteration - - - - collectionobjects_common:inscriptionDescriptionInterpretation - - materialComponentNote - materialName - - - collectionobjects_common:physicalDescription - - objectComponentInformation - - - - - collectionobjects_common:objectProductionNote - - - collectionobjects_common:objectProductionReason - - - - - assocActivityNote - assocConceptNote - assocCulturalContextNote - assocDateNote - - - - collectionobjects_common:assocEventName - collectionobjects_common:assocEventNote - collectionobjects_common:assocEventType - - assocObject - assocOrganizationNote - assocPeopleNote - assocPersonNote - assocPlaceNote - - collectionobjects_common:objectHistoryNote - collectionobjects_common:ownershipExchangeNote - usageNote - - - - - collectionobjects_common:ownersPersonalExperience - collectionobjects_common:ownersPersonalResponse - - - collectionobjects_common:ownersReference - - collectionobjects_common:ownersContributionNote - - - - - collectionobjects_common:viewersRole - collectionobjects_common:viewersPersonalExperience - collectionobjects_common:viewersPersonalResponse - - - collectionobjects_common:viewersReference - - collectionobjects_common:viewersContributionNote - - - - - collectionobjects_common:catalogNumber - - - - - collectionobjects_common:fieldCollectionNote - collectionobjects_common:fieldCollectionNumber - - - - collectionobjects_common:objectNumber - collectionobjects_common:otherNumber - collectionobjects_common:otherNumberType - collectionobjects_common:numberOfObjects - collectionobjects_common:collection - collectionobjects_common:recordStatus - collectionobjects_common:age - collectionobjects_common:ageQualifier - collectionobjects_common:ageUnit - - collectionobjects_common:contentDate - collectionobjects_common:contentLanguages - collectionobjects_common:contentOrganizations - - collectionobjects_common:dimensionSummary - - - - - collectionobjects_common:dimension - collectionobjects_common:dimensionMeasuredPart - collectionobjects_common:dimensionMeasurementUnit - collectionobjects_common:dimensionValue - collectionobjects_common:dimensionValueDate - collectionobjects_common:dimensionValueQualifier - - collectionobjects_common:editionNumber - - collectionobjects_common:inscriptionContentInscriber - collectionobjects_common:inscriptionContentDate - collectionobjects_common:inscriptionContentLanguage - collectionobjects_common:inscriptionContentMethod - collectionobjects_common:inscriptionContentPosition - collectionobjects_common:inscriptionContentScript - collectionobjects_common:inscriptionContentType - - collectionobjects_common:inscriptionDescription - collectionobjects_common:inscriptionDescriptionInscriber - collectionobjects_common:inscriptionDescriptionDate - collectionobjects_common:inscriptionDescriptionMethod - collectionobjects_common:inscriptionDescriptionPosition - collectionobjects_common:inscriptionDescriptionType - - collectionobjects_common:objectStatus - collectionobjects_common:phase - collectionobjects_common:sex - collectionobjects_common:ownershipAccess - collectionobjects_common:ownershipCategory - collectionobjects_common:ownershipDates - collectionobjects_common:ownershipExchangeMethod - collectionobjects_common:ownershipExchangePriceCurrency - collectionobjects_common:ownershipExchangePriceValue - collectionobjects_common:ownershipPlace - collectionobjects_common:fieldCollectionNumber - collectionobjects_common:fieldCollectionMethod - collectionobjects_common:fieldCollectionPlace - collectionobjects_common:fieldCollectionDate - - - - - collectionobjects_common:dateAssociation - collectionobjects_common:dateEarliestSingle - collectionobjects_common:dateEarliestSingleCertainty - collectionobjects_common:dateEarliestSingleQualifier - collectionobjects_common:dateLatest - collectionobjects_common:dateLatestCertainty - collectionobjects_common:dateLatestQualifier - collectionobjects_common:datePeriod - collectionobjects_common:dateText - - - - - - contacts_common:addressPlace - - - - - - groups_common:scopeNote - - - - - - - intakes_common:entryNote - intakes_common:packingNote - intakes_common:fieldCollectionNote - intakes_common:insuranceNote - intakes_common:conditionCheckNote - currentLocationNote - - - - - - - loansin_common:loanInConditions - loansin_common:loanInNote - - - - - - - loansout_common:specialConditionsOfLoan - loansout_common:loanOutNote - loansout_common:loanPurpose - loanedObjectStatusNote - - - - - - - movements_common:currentLocationNote - movements_common:movementNote - - - - - - - media_common:copyrightStatement - media_common:description - media_common:title - - - - - - - notes_common:content - - - - - - - objectexit_common:exitNote - objectexit_common:packingNote - - - - - - - shortName - longName - nameAdditions - historyNote - - - - - - persons_common:bioNote - persons_common:nameNote - - - - - - - - - - - - - locations_common:name - - locations_common:conditionNote - locations_common:securityNote - locations_common:accessNote - - - - - - - - The default repository - - + + + + + @XA_DATASOURCE@ + @DB_URL@ + nuxeo + @NUXEO_USER@ + @NUXEO_PW@ + + imd:user_comment + note + webp:content + webc:welcomeText + comment:comment + post + mail:mail + + + + + + + + + + acquisitionFundingSourceProvisos + acquisitions_common:acquisitionNote + acquisitions_common:acquisitionProvisos + acquisitions_common:acquisitionReason + acquisitions_common:creditLine + + + + + + + + + + + + + + + + + + + collectionobjects_common:otherNumber + + + numberValue + + + collectionobjects_common:briefDescriptions + + + + collectionobjects_common:comments + + collectionobjects_common:distinguishingFeatures + + + objectNameNote + + title + titleTranslation + + + + + collectionobjects_common:ageQualifier + collectionobjects_common:color + collectionobjects_common:contentDescription + + collectionobjects_common:contentNote + collectionobjects_common:contentObject + collectionobjects_common:copyNumber + collectionobjects_common:editionNumber + + + + collectionobjects_common:inscriptionContent + + collectionobjects_common:inscriptionContentInterpretation + + collectionobjects_common:inscriptionContentTranslation + + collectionobjects_common:inscriptionContentTransliteration + + + + + collectionobjects_common:inscriptionDescriptionInterpretation + + + materialComponentNote + materialName + + + collectionobjects_common:physicalDescription + + + objectComponentInformation + + + + + collectionobjects_common:objectProductionNote + + + + collectionobjects_common:objectProductionReason + + + + + + assocActivityNote + assocConceptNote + assocCulturalContextNote + assocDateNote + + + + collectionobjects_common:assocEventName + collectionobjects_common:assocEventNote + collectionobjects_common:assocEventType + + assocObject + assocOrganizationNote + assocPeopleNote + assocPersonNote + assocPlaceNote + + collectionobjects_common:objectHistoryNote + + collectionobjects_common:ownershipExchangeNote + + usageNote + + + + + collectionobjects_common:ownersPersonalExperience + + collectionobjects_common:ownersPersonalResponse + + + + collectionobjects_common:ownersReference + + collectionobjects_common:ownersContributionNote + + + + + + collectionobjects_common:viewersRole + collectionobjects_common:viewersPersonalExperience + + collectionobjects_common:viewersPersonalResponse + + + + collectionobjects_common:viewersReference + + collectionobjects_common:viewersContributionNote + + + + + + collectionobjects_common:catalogNumber + + + + + collectionobjects_common:fieldCollectionNote + + collectionobjects_common:fieldCollectionNumber + + + + + collectionobjects_common:objectNumber + collectionobjects_common:otherNumber + collectionobjects_common:otherNumberType + collectionobjects_common:numberOfObjects + collectionobjects_common:collection + collectionobjects_common:recordStatus + collectionobjects_common:age + collectionobjects_common:ageQualifier + collectionobjects_common:ageUnit + + collectionobjects_common:contentDate + collectionobjects_common:contentLanguages + collectionobjects_common:contentOrganizations + + + collectionobjects_common:dimensionSummary + + + + + collectionobjects_common:dimension + collectionobjects_common:dimensionMeasuredPart + + collectionobjects_common:dimensionMeasurementUnit + + collectionobjects_common:dimensionValue + collectionobjects_common:dimensionValueDate + + collectionobjects_common:dimensionValueQualifier + + + collectionobjects_common:editionNumber + + collectionobjects_common:inscriptionContentInscriber + + collectionobjects_common:inscriptionContentDate + + collectionobjects_common:inscriptionContentLanguage + + collectionobjects_common:inscriptionContentMethod + + collectionobjects_common:inscriptionContentPosition + + collectionobjects_common:inscriptionContentScript + + collectionobjects_common:inscriptionContentType + + + collectionobjects_common:inscriptionDescription + + collectionobjects_common:inscriptionDescriptionInscriber + + collectionobjects_common:inscriptionDescriptionDate + + collectionobjects_common:inscriptionDescriptionMethod + + collectionobjects_common:inscriptionDescriptionPosition + + collectionobjects_common:inscriptionDescriptionType + + + collectionobjects_common:objectStatus + collectionobjects_common:phase + collectionobjects_common:sex + collectionobjects_common:ownershipAccess + collectionobjects_common:ownershipCategory + + collectionobjects_common:ownershipDates + collectionobjects_common:ownershipExchangeMethod + + collectionobjects_common:ownershipExchangePriceCurrency + + collectionobjects_common:ownershipExchangePriceValue + + collectionobjects_common:ownershipPlace + collectionobjects_common:fieldCollectionNumber + + collectionobjects_common:fieldCollectionMethod + + collectionobjects_common:fieldCollectionPlace + + collectionobjects_common:fieldCollectionDate + + + + + + collectionobjects_common:dateAssociation + collectionobjects_common:dateEarliestSingle + + collectionobjects_common:dateEarliestSingleCertainty + + collectionobjects_common:dateEarliestSingleQualifier + + collectionobjects_common:dateLatest + collectionobjects_common:dateLatestCertainty + + collectionobjects_common:dateLatestQualifier + + collectionobjects_common:datePeriod + collectionobjects_common:dateText + + + + + + contacts_common:addressPlace + + + + + + groups_common:scopeNote + + + + + + + intakes_common:entryNote + intakes_common:packingNote + intakes_common:fieldCollectionNote + intakes_common:insuranceNote + intakes_common:conditionCheckNote + currentLocationNote + + + + + + + loansin_common:loanInConditions + loansin_common:loanInNote + + + + + + + loansout_common:specialConditionsOfLoan + loansout_common:loanOutNote + loansout_common:loanPurpose + loanedObjectStatusNote + + + + + + + movements_common:currentLocationNote + movements_common:movementNote + + + + + + + media_common:copyrightStatement + media_common:description + media_common:title + + + + + + + notes_common:content + + + + + + + objectexit_common:exitNote + objectexit_common:packingNote + + + + + + + shortName + longName + nameAdditions + historyNote + + + + + + persons_common:bioNote + persons_common:nameNote + + + + + + + + + + + + + locations_common:name + + locations_common:conditionNote + locations_common:securityNote + locations_common:accessNote + + + + + + + + The default repository + + diff --git a/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java b/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java index 7abd3df33..7509f2328 100644 --- a/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java +++ b/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java @@ -92,8 +92,8 @@ public class CollectionSpaceJaxRsApplication extends Application // // Instantiate all our JaxRS resources // - ResourceBase resource; singletons.add(new SecurityInterceptor()); + singletons.add(new AccountResource()); singletons.add(new RoleResource()); singletons.add(new PermissionResource()); 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 61ecbed59..caf493758 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 @@ -56,6 +56,7 @@ import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityDocumentMod import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler; import org.collectionspace.services.common.workflow.service.nuxeo.WorkflowDocumentModelHandler; import org.collectionspace.services.jaxb.AbstractCommonList; +import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler; import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; import org.collectionspace.services.relation.RelationResource; import org.collectionspace.services.relation.RelationsCommonList; @@ -234,10 +235,9 @@ public abstract class AuthorityResource throws DocumentNotFoundException, DocumentException { String shortIdentifier = null; try { - DocumentWrapper wrapDoc = getRepositoryClient(ctx).getDocFromCsid(ctx, authCSID); AuthorityDocumentModelHandler handler = (AuthorityDocumentModelHandler) createDocumentHandler(ctx); - shortIdentifier = handler.getShortIdentifier(wrapDoc, authorityCommonSchemaName); + shortIdentifier = handler.getShortIdentifier(authCSID, authorityCommonSchemaName); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("Caught exception ", e); @@ -801,14 +801,13 @@ public abstract class AuthorityResource ctx = createServiceContext(getItemServiceName(), queryParams); // We omit the parentShortId, only needed when doing a create... - RemoteDocumentModelHandlerImpl handler = - (RemoteDocumentModelHandlerImpl) createItemDocumentHandler(ctx, parentcsid, null); + DocumentModelHandler handler = + (DocumentModelHandler)createItemDocumentHandler(ctx, parentcsid, null); String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "getAuthorityItemAuthRefs(item)", "GET_ITEM_AUTH_REFS", ctx); - DocumentWrapper docWrapper = getRepositoryClient(ctx).getDoc(ctx, itemcsid); List authRefsInfo = RefNameServiceUtils.getConfiguredAuthorityRefs(ctx); - authRefList = handler.getAuthorityRefs(docWrapper, authRefsInfo); + authRefList = handler.getAuthorityRefs(itemcsid, authRefsInfo); } catch (Exception e) { throw bigReThrow(e, ServiceMessages.GET_FAILED + " parentspecifier: " + parentspecifier + " itemspecifier:" + itemspecifier); } diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java index 84cb9cfa1..7ddb66a17 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java @@ -25,16 +25,21 @@ package org.collectionspace.services.common.vocabulary.nuxeo; import java.util.Map; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.api.RefName; import org.collectionspace.services.common.api.Tools; import org.collectionspace.services.common.context.MultipartServiceContext; +import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.common.service.ObjectPartType; import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema; import org.collectionspace.services.nuxeo.client.java.DocHandlerBase; +import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl; import org.nuxeo.ecm.core.api.ClientException; import org.nuxeo.ecm.core.api.DocumentModel; +import org.nuxeo.ecm.core.api.repository.RepositoryInstance; /** * AuthorityDocumentModelHandler @@ -118,14 +123,25 @@ public abstract class AuthorityDocumentModelHandler docModel.setProperty(schemaName, AuthorityJAXBSchema.REF_NAME, refName); } - public String getShortIdentifier(DocumentWrapper wrapDoc, String schemaName) { - DocumentModel docModel = wrapDoc.getWrappedObject(); + public String getShortIdentifier(String authCSID, String schemaName) throws Exception { String shortIdentifier = null; + RepositoryInstance repoSession = null; + + ServiceContext ctx = this.getServiceContext(); + RepositoryJavaClientImpl nuxeoRepoClient = (RepositoryJavaClientImpl)this.getRepositoryClient(ctx); try { + repoSession = nuxeoRepoClient.getRepositorySession(); + DocumentWrapper wrapDoc = nuxeoRepoClient.getDocFromCsid(ctx, repoSession, authCSID); + DocumentModel docModel = wrapDoc.getWrappedObject(); shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER); } catch (ClientException ce) { throw new RuntimeException("AuthorityDocHandler Internal Error: cannot get shortId!", ce); + } finally { + if (repoSession != null) { + nuxeoRepoClient.releaseRepositorySession(repoSession); + } } + return shortIdentifier; } 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 40f0b1249..8fdf55360 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 @@ -269,7 +269,7 @@ public abstract class AuthorityItemDocumentModelHandler // AuthorityResource.getRefPropName() String refNameProp = ServiceBindingUtils.AUTH_REF_PROP; - int nUpdated = RefNameServiceUtils.updateAuthorityRefDocs(ctx, repoClient, + int nUpdated = RefNameServiceUtils.updateAuthorityRefDocs(ctx, repoClient, this.getRepositorySession(), oldRefNameOnUpdate, newRefNameOnUpdate, refNameProp); if (logger.isDebugEnabled()) { logger.debug("Updated " + nUpdated + " instances of oldRefName to newRefName"); diff --git a/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java b/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java index 3bf2cbb45..5cb29bf8b 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java +++ b/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java @@ -342,10 +342,9 @@ public abstract class ResourceBase try { MultivaluedMap queryParams = ui.getQueryParameters(); ServiceContext ctx = createServiceContext(queryParams); - DocumentWrapper docWrapper = getRepositoryClient(ctx).getDoc(ctx, csid); DocumentModelHandler handler = (DocumentModelHandler) createDocumentHandler(ctx); List authRefsInfo = RefNameServiceUtils.getConfiguredAuthorityRefs(ctx); - authRefList = handler.getAuthorityRefs(docWrapper, authRefsInfo); + authRefList = handler.getAuthorityRefs(csid, authRefsInfo); } catch (Exception e) { throw bigReThrow(e, ServiceMessages.AUTH_REFS_FAILED, csid); } diff --git a/services/common/src/main/java/org/collectionspace/services/common/repository/RepositoryClientFactory.java b/services/common/src/main/java/org/collectionspace/services/common/repository/RepositoryClientFactory.java index 4db266ded..64af8a48c 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/repository/RepositoryClientFactory.java +++ b/services/common/src/main/java/org/collectionspace/services/common/repository/RepositoryClientFactory.java @@ -37,12 +37,12 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: $ * $LastChangedDate: $ */ -public class RepositoryClientFactory { +public class RepositoryClientFactory { private static final RepositoryClientFactory self = new RepositoryClientFactory(); final Logger logger = LoggerFactory.getLogger(RepositoryClientFactory.class); //clients key=client name, value=repository client - private Hashtable clients = new Hashtable(); + private Hashtable> clients = new Hashtable>(); private RepositoryClientFactory() { try{ @@ -53,10 +53,10 @@ public class RepositoryClientFactory { ClassLoader cloader = Thread.currentThread().getContextClassLoader(); Class jclazz = cloader.loadClass(clientClassName); - Object jclient = jclazz.newInstance(); - clients.put(clientName, (RepositoryClient) jclient); + RepositoryClient jclient = (RepositoryClient)jclazz.newInstance(); + clients.put(clientName, jclient); - }catch(Exception e){ + } catch(Exception e){ throw new RuntimeException(e); } } @@ -70,7 +70,7 @@ public class RepositoryClientFactory { * @param clientName name of the client as found in service binding * @return */ - public RepositoryClient getClient(String clientName) { + public RepositoryClient getClient(String clientName) { return clients.get(clientName); } } diff --git a/services/common/src/main/java/org/collectionspace/services/common/security/SecurityInterceptor.java b/services/common/src/main/java/org/collectionspace/services/common/security/SecurityInterceptor.java index 995218baa..15b8c8c60 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/security/SecurityInterceptor.java +++ b/services/common/src/main/java/org/collectionspace/services/common/security/SecurityInterceptor.java @@ -27,16 +27,23 @@ */ package org.collectionspace.services.common.security; +import java.security.Principal; import java.util.HashMap; +import java.util.Set; import org.jboss.resteasy.core.ResourceMethod; import org.jboss.resteasy.core.ServerResponse; +import org.jboss.resteasy.spi.interception.PostProcessInterceptor; import org.jboss.resteasy.spi.interception.PreProcessInterceptor; import org.jboss.resteasy.annotations.interception.SecurityPrecedence; import org.jboss.resteasy.annotations.interception.ServerInterceptor; import org.jboss.resteasy.spi.Failure; import org.jboss.resteasy.spi.HttpRequest; +import org.nuxeo.runtime.api.Framework; +import javax.security.auth.Subject; +import javax.security.auth.login.LoginContext; +import javax.security.auth.login.LoginException; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Response; import javax.ws.rs.ext.Provider; @@ -58,11 +65,26 @@ import org.slf4j.LoggerFactory; @SecurityPrecedence @ServerInterceptor @Provider -public class SecurityInterceptor implements PreProcessInterceptor { +public class SecurityInterceptor implements PreProcessInterceptor, PostProcessInterceptor { + + static { + System.err.println("Static initializtion of: " + SecurityInterceptor.class.getCanonicalName()); + } /** The Constant logger. */ private static final Logger logger = LoggerFactory.getLogger(SecurityInterceptor.class); private static final String ACCOUNT_PERMISSIONS = "accounts/*/accountperms"; + // + // Use this thread specific member instance to hold our login context with Nuxeo + // + private static ThreadLocal threadLocalLoginContext = null; + private static int frameworkLogins = 0; + // + // Error messages + // + private static final String ERROR_NUXEO_LOGOUT = "Attempt to logout when Nuxeo login context was null"; + private static final String ERROR_UNBALANCED_LOGINS = "The number of Logins vs Logouts to the Nuxeo framework was unbalanced."; + /* (non-Javadoc) * @see org.jboss.resteasy.spi.interception.PreProcessInterceptor#preProcess(org.jboss.resteasy.spi.HttpRequest, org.jboss.resteasy.core.ResourceMethod) @@ -120,6 +142,11 @@ public class SecurityInterceptor implements PreProcessInterceptor { } } } + // + // Login to Nuxeo + // + nuxeoPreProcess(request, method); + // // We've passed all the checks. Now just log the results // @@ -132,6 +159,14 @@ public class SecurityInterceptor implements PreProcessInterceptor { return null; } + + @Override + public void postProcess(ServerResponse arg0) { + // + // Log out of the Nuxeo framework + // + nuxeoPostProcess(arg0); + } /** * checkActive check if account is active @@ -173,4 +208,92 @@ public class SecurityInterceptor implements PreProcessInterceptor { throw new WebApplicationException(response); } } + // + // Nuxeo login support + // + public ServerResponse nuxeoPreProcess(HttpRequest arg0, ResourceMethod arg1) + throws Failure, WebApplicationException { + try { + nuxeoLogin(); + } catch (LoginException e) { + String msg = "Unable to login to the Nuxeo framework"; + logger.error(msg, e); + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type("text/plain").build(); + throw new WebApplicationException(response); + } + + return null; + } + + public void nuxeoPostProcess(ServerResponse arg0) { + try { + nuxeoLogout(); + } catch (LoginException e) { + String msg = "Unable to logout of the Nuxeo framework"; + logger.error(msg, e); + } + } + + private synchronized void nuxeoLogin() throws LoginException { + // + // Login as the Nuxeo system/admin user + nuxeoLogin(null); + } + + private void logLoginContext(LoginContext loginContext) { + logger.info("CollectionSpace services now logged in to Nuxeo with LoginContext: " + + loginContext); + Subject subject = loginContext.getSubject(); + Set principals = subject.getPrincipals(); + logger.debug("Nuxeo login performed with principals: "); + for (Principal principal : principals) { + logger.debug("[" + principal.getName() + "]"); + } + } + + /* + * Login to Nuxeo and save the LoginContext instance in a thread local variable + */ + private synchronized void nuxeoLogin(String user) throws LoginException { + // + // Use a ThreadLocal instance to keep track of the Nuxeo login context + // + if (threadLocalLoginContext == null) { + threadLocalLoginContext = new ThreadLocal(); + System.err.println("Created ThreadLocal instance: " + + threadLocalLoginContext.getClass().getCanonicalName() + + " - " + + threadLocalLoginContext.get()); + } + LoginContext loginContext = threadLocalLoginContext.get(); + if (loginContext == null) { + loginContext = Framework.loginAs(user); + frameworkLogins++; + threadLocalLoginContext.set(loginContext); + System.err.println("Setting ThreadLocal instance: " + + threadLocalLoginContext.getClass().getCanonicalName() + + " - " + + threadLocalLoginContext.get()); + // + // Debug message + // + if (logger.isDebugEnabled() == true) { + logLoginContext(loginContext); + } + } + } + + public synchronized void nuxeoLogout() throws LoginException { + LoginContext loginContext = threadLocalLoginContext != null ? threadLocalLoginContext.get() : null; + if (loginContext != null) { + loginContext.logout(); + frameworkLogins--; + + } else { + logger.warn(ERROR_NUXEO_LOGOUT); + } + + threadLocalLoginContext = null; //Clear the ThreadLocal to void Tomcat warnings associated with thread pools. + } } 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 781f43e06..4841eb4d6 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 @@ -37,9 +37,12 @@ import org.nuxeo.ecm.core.api.model.Property; import org.nuxeo.ecm.core.api.model.PropertyException; import org.nuxeo.ecm.core.api.model.PropertyNotFoundException; import org.nuxeo.ecm.core.api.model.impl.primitives.StringProperty; +import org.nuxeo.ecm.core.api.repository.RepositoryInstance; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.ServiceMain; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.context.AbstractServiceContextImpl; @@ -188,7 +191,7 @@ public class RefNameServiceUtils { private static ArrayList refNameServiceTypes = null; - public static List getConfiguredAuthorityRefs(ServiceContext ctx) { + public static List getConfiguredAuthorityRefs(ServiceContext ctx) { List authRefFields = ((AbstractServiceContextImpl) ctx).getAllPartsPropertyValues( ServiceBindingUtils.AUTH_REF_PROP, ServiceBindingUtils.QUALIFIED_PROP_NAMES); @@ -200,14 +203,15 @@ public class RefNameServiceUtils { return authRefsInfo; } - - public static AuthorityRefDocList getAuthorityRefDocs(ServiceContext ctx, - RepositoryClient repoClient, + public static AuthorityRefDocList getAuthorityRefDocs( + ServiceContext ctx, + RepositoryClient repoClient, List serviceTypes, String refName, String refPropName, - int pageSize, int pageNum, boolean computeTotal) throws DocumentException, DocumentNotFoundException { - AuthorityRefDocList wrapperList = new AuthorityRefDocList(); + int pageSize, int pageNum, boolean computeTotal) + throws DocumentException, DocumentNotFoundException { + AuthorityRefDocList wrapperList = new AuthorityRefDocList(); AbstractCommonList commonList = (AbstractCommonList) wrapperList; commonList.setPageNum(pageNum); commonList.setPageSize(pageSize); @@ -217,23 +221,36 @@ public class RefNameServiceUtils { Map queriedServiceBindings = new HashMap(); Map> authRefFieldsByService = new HashMap>(); - DocumentModelList docList = findAuthorityRefDocs(ctx, repoClient, serviceTypes, refName, refPropName, - queriedServiceBindings, authRefFieldsByService, pageSize, pageNum, computeTotal); - - if (docList == null) { // found no authRef fields - nothing to process - return wrapperList; - } - // Set num of items in list. this is useful to our testing framework. - commonList.setItemsInPage(docList.size()); - // set the total result size - commonList.setTotalItems(docList.totalSize()); - - int nRefsFound = processRefObjsDocList(docList, refName, queriedServiceBindings, authRefFieldsByService, - list, null); - if(logger.isDebugEnabled() && (nRefsFound < docList.size())) { - logger.debug("Internal curiosity: got fewer matches of refs than # docs matched..."); - } - return wrapperList; + RepositoryJavaClientImpl nuxeoRepoClient = (RepositoryJavaClientImpl)repoClient; + RepositoryInstance repoSession = null; + try { + repoSession = nuxeoRepoClient.getRepositorySession(); + DocumentModelList docList = findAuthorityRefDocs(ctx, repoClient, repoSession, + serviceTypes, refName, refPropName, queriedServiceBindings, authRefFieldsByService, pageSize, pageNum, computeTotal); + + if (docList == null) { // found no authRef fields - nothing to process + return wrapperList; + } + // Set num of items in list. this is useful to our testing framework. + commonList.setItemsInPage(docList.size()); + // set the total result size + commonList.setTotalItems(docList.totalSize()); + + int nRefsFound = processRefObjsDocList(docList, refName, queriedServiceBindings, authRefFieldsByService, + list, null); + if(logger.isDebugEnabled() && (nRefsFound < docList.size())) { + logger.debug("Internal curiosity: got fewer matches of refs than # docs matched..."); + } + } catch (Exception e) { + logger.error("Could not retrieve the Nuxeo repository", e); + wrapperList = null; + } finally { + if (repoSession != null) { + nuxeoRepoClient.releaseRepositorySession(repoSession); + } + } + + return wrapperList; } private static ArrayList getRefNameServiceTypes() { @@ -249,8 +266,10 @@ public class RefNameServiceUtils { // Seems like a good value - no real data to set this well. private static final int N_OBJS_TO_UPDATE_PER_LOOP = 100; - public static int updateAuthorityRefDocs(ServiceContext ctx, - RepositoryClient repoClient, + public static int updateAuthorityRefDocs( + ServiceContext ctx, + RepositoryClient repoClient, + RepositoryInstance repoSession, String oldRefName, String newRefName, String refPropName ) { @@ -268,7 +287,8 @@ public class RefNameServiceUtils { // Note that we always ask the Repo for the first page, since each page we process // should not be found in successive searches. Slightly inefficient, but more // reliable (stateless). - DocumentModelList docList = findAuthorityRefDocs(ctx, repoClient, getRefNameServiceTypes(), oldRefName, refPropName, + DocumentModelList docList = findAuthorityRefDocs(ctx, repoClient, repoSession, + getRefNameServiceTypes(), oldRefName, refPropName, queriedServiceBindings, authRefFieldsByService, pageSize, 0, false); if((docList == null) // found no authRef fields - nothing to do @@ -280,7 +300,7 @@ public class RefNameServiceUtils { int nRefsFoundThisPage = processRefObjsDocList(docList, oldRefName, queriedServiceBindings, authRefFieldsByService, null, newRefName); if(nRefsFoundThisPage>0) { - ((RepositoryJavaClientImpl)repoClient).saveDocListWithoutHandlerProcessing(ctx, docList, true); + ((RepositoryJavaClientImpl)repoClient).saveDocListWithoutHandlerProcessing(ctx, repoSession, docList, true); nRefsFound += nRefsFoundThisPage; } pageNumProcessed++; @@ -293,8 +313,10 @@ public class RefNameServiceUtils { return nRefsFound; } - private static DocumentModelList findAuthorityRefDocs(ServiceContext ctx, - RepositoryClient repoClient, + private static DocumentModelList findAuthorityRefDocs( + ServiceContext ctx, + RepositoryClient repoClient, + RepositoryInstance repoSession, List serviceTypes, String refName, String refPropName, @@ -323,7 +345,8 @@ public class RefNameServiceUtils { return null; } // Now we have to issue the search - DocumentWrapper docListWrapper = repoClient.findDocs(ctx, + RepositoryJavaClientImpl nuxeoRepoClient = (RepositoryJavaClientImpl)repoClient; + DocumentWrapper docListWrapper = nuxeoRepoClient.findDocs(ctx, repoSession, docTypes, query, pageSize, pageNum, computeTotal); // Now we gather the info for each document into the list and return DocumentModelList docList = docListWrapper.getWrappedObject(); @@ -379,7 +402,12 @@ public class RefNameServiceUtils { whereClause.append("'"); } } + String whereClauseStr = whereClause.toString(); // for debugging + if (logger.isTraceEnabled()) { + logger.trace("The 'where' clause of the xyz method is: ", whereClauseStr); + } + if (fFirst) { // found no authRef fields - nothing to query return null; } else { @@ -534,17 +562,19 @@ public class RefNameServiceUtils { int pathStartIndex, // Supports recursion and we work down the path String refNameToMatch ) { - if(pathStartIndex >= arci.pathEls.length) { + if (pathStartIndex >= arci.pathEls.length) { throw new ArrayIndexOutOfBoundsException("Index = "+pathStartIndex+" for path: " +arci.pathEls.toString()); } AuthRefInfo ari = null; - if(prop == null) + if (prop == null) { return foundProps; - if(prop instanceof StringProperty) { // scalar string + } + + if (prop instanceof StringProperty) { // scalar string addARIifMatches(refNameToMatch, arci, prop, foundProps); } else if(prop instanceof List) { - List propList = (List)prop; + List propList = (List)prop; // run through list. Must either be list of Strings, or Complex for (Property listItemProp : propList) { if(listItemProp instanceof StringProperty) { @@ -583,9 +613,10 @@ public class RefNameServiceUtils { +arci.pathEls.toString()); } - if(ari != null) { - foundProps.add(ari); + if (ari != null) { + foundProps.add(ari); //FIXME: REM - This is dead code. 'ari' is never touched after being initalized to null. Why? } + return foundProps; } diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java index 02e3e9a06..4619f6196 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java @@ -83,10 +83,9 @@ public abstract class DocumentModelHandler public String getUri(DocumentModel docModel) { return getServiceContextPath()+getCsid(docModel); } - - - public RepositoryClient getRepositoryClient(ServiceContext ctx) { - RepositoryClient repositoryClient = RepositoryClientFactory.getInstance().getClient(ctx.getRepositoryClientName()); + + public RepositoryClient getRepositoryClient(ServiceContext ctx) { + RepositoryClient repositoryClient = RepositoryClientFactory.getInstance().getClient(ctx.getRepositoryClientName()); return repositoryClient; } @@ -95,6 +94,7 @@ public abstract class DocumentModelHandler * @return */ public RepositoryInstance getRepositorySession() { + return repositorySession; } @@ -184,15 +184,14 @@ public abstract class DocumentModelHandler * @return the authority refs * @throws PropertyException the property exception */ - abstract public AuthorityRefList getAuthorityRefs( - DocumentWrapper docWrapper, - List authRefsInfo) throws PropertyException; + abstract public AuthorityRefList getAuthorityRefs(String csid, + List authRefsInfo) throws PropertyException; private void handleCoreValues(DocumentWrapper docWrapper, Action action) throws ClientException { DocumentModel documentModel = docWrapper.getWrappedObject(); String now = GregorianCalendarDateTimeUtils.timestampUTC(); - ServiceContext ctx = getServiceContext(); + ServiceContext ctx = getServiceContext(); String userId = ctx.getUserId(); if(action==Action.CREATE) { // diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoClientEmbedded.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoClientEmbedded.java index 821ded217..43d657198 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoClientEmbedded.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoClientEmbedded.java @@ -59,6 +59,7 @@ import org.nuxeo.runtime.api.login.SecurityDomain; import org.nuxeo.runtime.config.AutoConfigurationService; import org.nuxeo.runtime.remoting.RemotingService; import org.nuxeo.runtime.services.streaming.StreamingService; +import org.nuxeo.runtime.transaction.TransactionHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -71,8 +72,6 @@ public final class NuxeoClientEmbedded { private Logger logger = LoggerFactory.getLogger(NuxeoClientEmbedded.class); private LoginHandler loginHandler; - - private LoginContext loginContext = null; private final List repositoryInstances; @@ -182,6 +181,7 @@ public final class NuxeoClientEmbedded { doConnect(locator); } + @Deprecated private void doConnect(InvokerLocator locator) throws Exception { this.locator = locator; try { @@ -218,7 +218,10 @@ public final class NuxeoClientEmbedded { adaptClientSecurityDomain(clientDomain); } // ---------------- - login(); +// login(); + if (!multiThreadedLogin) { + throw new RuntimeException("This coode is dead and should never be called?"); //FIXME: REM - If you're reading this, this was left here by mistake and should be removed. + } } catch (Exception e) { this.locator = null; throw e; @@ -272,6 +275,7 @@ public final class NuxeoClientEmbedded { doDisconnect(); } + @Deprecated private void doDisconnect() throws Exception { locator = null; serverName = null; @@ -287,7 +291,10 @@ public final class NuxeoClientEmbedded { it.remove(); } // logout - logout(); +// logout(); + if (!multiThreadedLogin) { + throw new RuntimeException("This coode is dead and should never be called?"); //FIXME: REM - If you're reading this, this was left here by mistake and should be removed. + } repositoryMgr = null; fireDisconnected(this); } @@ -350,31 +357,6 @@ public final class NuxeoClientEmbedded { this.loginHandler = loginHandler; } - public synchronized void login() throws LoginException { - // - // Login as the Nuxeo system/admin user - this.login(null); - } - - public synchronized void login(String user) throws LoginException { - loginContext = Framework.loginAs(user); - if (logger.isDebugEnabled() == true) { - Subject subject = loginContext.getSubject(); - Set principals = subject.getPrincipals(); - logger.debug("Nuxeo login performed with principals: "); - for (Principal principal : principals) { - logger.debug("[" + principal.getName() + "]"); - } - } - } - - public synchronized void logout() throws LoginException { - if (loginContext != null) { - loginContext.logout(); - loginContext = null; - } - } - public RepositoryManager getRepositoryManager() throws Exception { if (repositoryMgr == null) { repositoryMgr = Framework.getService(RepositoryManager.class); @@ -405,6 +387,11 @@ public final class NuxeoClientEmbedded { } public RepositoryInstance openRepository(String name) throws Exception { + boolean startTransaction = TransactionHelper.startTransaction(); + if (startTransaction == false) { + logger.warn("Could not start a Nuxeo transaction with the TransactionHelper class."); + } + Repository repository = null; if (name != null) { repository = getRepositoryManager().getRepository(name); @@ -422,6 +409,7 @@ public final class NuxeoClientEmbedded { repo.close(); } finally { repositoryInstances.remove(repo); + TransactionHelper.commitOrRollbackTransaction(); } } @@ -457,6 +445,5 @@ public final class NuxeoClientEmbedded { for (Object listener : listeners) { // ((ConnectionListener) listener).connected(client); } - } - + } } diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoConnectorEmbedded.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoConnectorEmbedded.java index af7c65aa2..1fdf95492 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoConnectorEmbedded.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoConnectorEmbedded.java @@ -35,6 +35,8 @@ public class NuxeoConnectorEmbedded { public final static String NUXEO_CLIENT_DIR = "nuxeo-client"; public final static String NUXEO_SERVER_DIR = "nuxeo-server"; + private final static String ERROR_CONNECTOR_NOT_INITIALIZED = "NuxeoConnector is not initialized!"; + private static final String HOST = "127.0.0.1"; private static final int PORT = 62474; @@ -212,11 +214,6 @@ public class NuxeoConnectorEmbedded { logger.debug("getRepositorySession() opened repository session"); } return repoSession; - - // Repository repository = - // Framework.getService(RepositoryManager.class).getDefaultRepository(); - // session = repository.open(); - } /** @@ -229,7 +226,7 @@ public class NuxeoConnectorEmbedded { public NuxeoClientEmbedded getClient() throws Exception { if (initialized == true) { if (client.isConnected()) { - client.login(); +// client.login(); return client; } else { client.forceConnect(this.HOST, @@ -241,9 +238,23 @@ public class NuxeoConnectorEmbedded { return client; } } - String msg = "NuxeoConnector is not initialized!"; - logger.error(msg); - throw new IllegalStateException(msg); + // + // Nuxeo connection was not initialized + // + logger.error(ERROR_CONNECTOR_NOT_INITIALIZED); + throw new IllegalStateException(ERROR_CONNECTOR_NOT_INITIALIZED); + } + + void releaseClient() throws Exception { + if (initialized == true) { +// client.logout(); + } else { + // + // Nuxeo connection was not initialized + // + logger.error(ERROR_CONNECTOR_NOT_INITIALIZED); + throw new IllegalStateException(ERROR_CONNECTOR_NOT_INITIALIZED); + } } /** diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java index 6c374b855..ca7ff53a1 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java @@ -67,6 +67,7 @@ import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.DocumentModelList; import org.nuxeo.ecm.core.api.model.Property; import org.nuxeo.ecm.core.api.model.PropertyException; +import org.nuxeo.ecm.core.api.repository.RepositoryInstance; import org.nuxeo.ecm.core.schema.types.Schema; @@ -388,7 +389,7 @@ public abstract class RemoteDocumentModelHandlerImpl */ @Override public AuthorityRefList getAuthorityRefs( - DocumentWrapper docWrapper, + String csid, List authRefsInfo) throws PropertyException { AuthorityRefList authRefList = new AuthorityRefList(); @@ -402,7 +403,6 @@ public abstract class RemoteDocumentModelHandlerImpl commonList.setPageSize(pageSize); List list = authRefList.getAuthorityRefItem(); - DocumentModel docModel = docWrapper.getWrappedObject(); try { int iFirstToUse = (int)(pageSize*pageNum); @@ -411,18 +411,35 @@ public abstract class RemoteDocumentModelHandlerImpl ArrayList foundProps = new ArrayList(); - RefNameServiceUtils.findAuthRefPropertiesInDoc(docModel, authRefsInfo, null, foundProps); - // Slightly goofy pagination support - how many refs do we expect from one object? - for(RefNameServiceUtils.AuthRefInfo ari:foundProps) { - if((nFoundTotal >= iFirstToUse) && (nFoundInPage < pageSize)) { - if(appendToAuthRefsList(ari, list)) { - nFoundInPage++; - nFoundTotal++; - } - } else { - nFoundTotal++; - } - } + + boolean releaseRepoSession = false; + ServiceContext ctx = this.getServiceContext(); + RepositoryJavaClientImpl repoClient = (RepositoryJavaClientImpl)this.getRepositoryClient(ctx); + RepositoryInstance repoSession = this.getRepositorySession(); + if (repoSession == null) { + repoSession = repoClient.getRepositorySession(); + releaseRepoSession = true; + } + + try { + DocumentModel docModel = repoClient.getDoc(repoSession, ctx, csid).getWrappedObject(); + RefNameServiceUtils.findAuthRefPropertiesInDoc(docModel, authRefsInfo, null, foundProps); + // Slightly goofy pagination support - how many refs do we expect from one object? + for(RefNameServiceUtils.AuthRefInfo ari:foundProps) { + if((nFoundTotal >= iFirstToUse) && (nFoundInPage < pageSize)) { + if(appendToAuthRefsList(ari, list)) { + nFoundInPage++; + nFoundTotal++; + } + } else { + nFoundTotal++; + } + } + } finally { + if (releaseRepoSession == true) { + repoClient.releaseRepositorySession(repoSession); + } + } // Set num of items in list. this is useful to our testing framework. commonList.setItemsInPage(nFoundInPage); 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 2e4f76501..b127360a8 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 @@ -145,6 +145,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient getDoc( + RepositoryInstance repoSession, + ServiceContext ctx, + String csid) throws DocumentNotFoundException, DocumentException { + DocumentWrapper wrapDoc = null; + + try { + DocumentRef docRef = NuxeoUtils.createPathRef(ctx, csid); + DocumentModel doc = null; + try { + doc = repoSession.getDocument(docRef); + } catch (ClientException ce) { + String msg = "Could not find document with CSID=" + csid; + logger.error(msg, ce); + throw new DocumentNotFoundException(msg, ce); + } + wrapDoc = new DocumentWrapperImpl(doc); + } catch (IllegalArgumentException iae) { + throw iae; + } catch (DocumentException de) { + throw de; + } + + return wrapDoc; + } + /** * Get wrapped documentModel from the Nuxeo repository. The search is restricted to the workspace * of the current context. @@ -298,23 +325,15 @@ public class RepositoryJavaClientImpl implements RepositoryClient getDoc( - ServiceContext ctx, String csid) - throws DocumentNotFoundException, DocumentException { + ServiceContext ctx, + String csid) throws DocumentNotFoundException, DocumentException { RepositoryInstance repoSession = null; DocumentWrapper wrapDoc = null; try { + // Open a new repository session repoSession = getRepositorySession(); - DocumentRef docRef = NuxeoUtils.createPathRef(ctx, csid); - DocumentModel doc = null; - try { - doc = repoSession.getDocument(docRef); - } catch (ClientException ce) { - String msg = "could not find document with id=" + csid; - logger.error(msg, ce); - throw new DocumentNotFoundException(msg, ce); - } - wrapDoc = new DocumentWrapperImpl(doc); + wrapDoc = getDoc(repoSession, ctx, csid); } catch (IllegalArgumentException iae) { throw iae; } catch (DocumentException de) { @@ -329,25 +348,22 @@ public class RepositoryJavaClientImpl implements RepositoryClient findDoc( - ServiceContext ctx, String whereClause) + ServiceContext ctx, + RepositoryInstance repoSession, + String whereClause) throws DocumentNotFoundException, DocumentException { - RepositoryInstance repoSession = null; DocumentWrapper wrapDoc = null; try { QueryContext queryContext = new QueryContext(ctx, whereClause); - repoSession = getRepositorySession(); DocumentModelList docList = null; // force limit to 1, and ignore totalSize String query = NuxeoUtils.buildNXQLQuery(ctx, queryContext); @@ -374,11 +390,40 @@ public class RepositoryJavaClientImpl implements RepositoryClient findDoc( + ServiceContext ctx, + String whereClause) + throws DocumentNotFoundException, DocumentException { + RepositoryInstance repoSession = null; + DocumentWrapper wrapDoc = null; + + try { + repoSession = getRepositorySession(); + wrapDoc = findDoc(ctx, repoSession, whereClause); + } catch (Exception e) { + throw new DocumentException("Unable to create a Nuxeo repository session.", e); + } finally { if (repoSession != null) { releaseRepositorySession(repoSession); } } + + if (logger.isWarnEnabled() == true) { + logger.warn("Returned DocumentModel instance was created with a repository session that is now closed."); + } + return wrapDoc; } @@ -393,8 +438,10 @@ public class RepositoryJavaClientImpl implements RepositoryClient ctx, String whereClause) throws DocumentNotFoundException, DocumentException { String csid = null; + RepositoryInstance repoSession = null; try { - DocumentWrapper wrapDoc = findDoc(ctx, whereClause); + repoSession = this.getRepositorySession(); + DocumentWrapper wrapDoc = findDoc(ctx, repoSession, whereClause); DocumentModel docModel = wrapDoc.getWrappedObject(); csid = NuxeoUtils.getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString()); } catch (DocumentNotFoundException dnfe) { @@ -408,24 +455,21 @@ public class RepositoryJavaClientImpl implements RepositoryClient findDocs( ServiceContext ctx, + RepositoryInstance repoSession, List docTypes, String whereClause, int pageSize, int pageNum, boolean computeTotal) - throws DocumentNotFoundException, DocumentException { - RepositoryInstance repoSession = null; + throws DocumentNotFoundException, DocumentException { DocumentWrapper wrapDoc = null; try { @@ -433,7 +477,6 @@ public class RepositoryJavaClientImpl implements RepositoryClient findDocs( + ServiceContext ctx, + List docTypes, + String whereClause, + int pageSize, int pageNum, boolean computeTotal) + throws DocumentNotFoundException, DocumentException { + RepositoryInstance repoSession = null; + DocumentWrapper wrapDoc = null; + + try { + repoSession = getRepositorySession(); + wrapDoc = findDocs(ctx, repoSession, docTypes, whereClause, + pageSize, pageNum, computeTotal); + } catch (IllegalArgumentException iae) { + throw iae; + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception ", e); + } + throw new DocumentException(e); } finally { if (repoSession != null) { releaseRepositorySession(repoSession); } } + + if (logger.isWarnEnabled() == true) { + logger.warn("Returned DocumentModelList instance was created with a repository session that is now closed."); + } + return wrapDoc; } @@ -467,7 +547,6 @@ public class RepositoryJavaClientImpl implements RepositoryClient getDocFromCsid( + ServiceContext ctx, + RepositoryInstance repoSession, + String csid) + throws Exception { + DocumentWrapper result = null; + + result = new DocumentWrapperImpl(NuxeoUtils.getDocFromCsid(ctx, repoSession, csid)); + + return result; + } /* * A method to find a CollectionSpace document (of any type) given just a service context and @@ -568,14 +659,20 @@ public class RepositoryJavaClientImpl implements RepositoryClient result = null; - RepositoryInstance repoSession = getRepositorySession(); + RepositoryInstance repoSession = null; try { - result = new DocumentWrapperImpl(NuxeoUtils.getDocFromCsid(repoSession, ctx, csid)); + repoSession = getRepositorySession(); + result = getDocFromCsid(ctx, repoSession, csid); } finally { if (repoSession != null) { releaseRepositorySession(repoSession); } } + + if (logger.isWarnEnabled() == true) { + logger.warn("Returned DocumentModel instance was created with a repository session that is now closed."); + } + return result; } @@ -612,6 +709,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient ctx, + RepositoryInstance repoSession, + DocumentModel docModel, + boolean fSaveSession) throws ClientException, DocumentException { - RepositoryInstance repoSession = null; - DocumentWrapper wrapDoc = null; try { - repoSession = getRepositorySession(); repoSession.saveDocument(docModel); - if(fSaveSession) + if (fSaveSession) { repoSession.save(); + } } catch (ClientException ce) { throw ce; } catch (Exception e) { @@ -749,13 +842,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient ctx, + RepositoryInstance repoSession, + DocumentModelList docList, + boolean fSaveSession) throws ClientException, DocumentException { - RepositoryInstance repoSession = null; - DocumentWrapper wrapDoc = null; - try { repoSession = getRepositorySession(); DocumentModel[] docModelArray = new DocumentModel[docList.size()]; repoSession.saveDocuments(docList.toArray(docModelArray)); - if(fSaveSession) + if (fSaveSession) { repoSession.save(); + } } catch (ClientException ce) { throw ce; } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception ", e); - } + logger.error("Caught exception ", e); throw new DocumentException(e); } } - - /** * delete a document from the Nuxeo repository * @param ctx service context under which this method is invoked @@ -961,6 +1045,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient tenantBindings) throws Exception { - for (TenantBindingType tenantBinding : tenantBindings.values()) { - setup(tenantBinding); - } + LoginContext loginContext = null; + try { + loginContext = Framework.login(); + for (TenantBindingType tenantBinding : tenantBindings.values()) { + setup(tenantBinding); + } + } finally { + if (loginContext != null) { + loginContext.logout(); + } + } } /** diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java index 5c7a93d04..7888850c1 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java @@ -391,8 +391,9 @@ public class NuxeoUtils { return query.toString(); } - static public DocumentModel getDocFromCsid(RepositoryInstance repoSession, + static public DocumentModel getDocFromCsid( ServiceContext ctx, + RepositoryInstance repoSession, String csid) throws Exception { DocumentModel result = null; 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 9c9827691..e6531db60 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 @@ -57,8 +57,10 @@ import org.collectionspace.services.client.TaxonomyAuthorityClient; 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.client.java.RepositoryJavaClientImpl; import org.collectionspace.services.relation.RelationsDocListItem; import org.nuxeo.ecm.core.api.ClientException; +import org.nuxeo.ecm.core.api.CoreSession; import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.DocumentModelList; import org.nuxeo.ecm.core.api.model.PropertyException; @@ -111,17 +113,19 @@ public class RelationDocumentModelHandler // we will also set those. // Note that this introduces another caching problem... DocumentModel relationDocModel = wrapDoc.getWrappedObject(); - ServiceContext ctx = getServiceContext(); - DocumentModel subjectDocModel = getSubjectOrObjectDocModel(relationDocModel, ctx, SUBJ_DOC_MODEL); - DocumentModel objectDocModel = getSubjectOrObjectDocModel(relationDocModel, ctx, OBJ_DOC_MODEL); + ServiceContext ctx = this.getServiceContext(); + RepositoryInstance repoSession = this.getRepositorySession(); + + DocumentModel subjectDocModel = getSubjectOrObjectDocModel(relationDocModel, SUBJ_DOC_MODEL); + DocumentModel objectDocModel = getSubjectOrObjectDocModel(relationDocModel, OBJ_DOC_MODEL); // Use values from the subject and object document models to populate the // relevant fields of the relation's own document model. if (subjectDocModel != null) { - populateSubjectOrObjectValues(relationDocModel, subjectDocModel, ctx, SUBJ_DOC_MODEL); + populateSubjectOrObjectValues(relationDocModel, subjectDocModel, SUBJ_DOC_MODEL); } if (objectDocModel != null) { - populateSubjectOrObjectValues(relationDocModel, objectDocModel, ctx, OBJ_DOC_MODEL); + populateSubjectOrObjectValues(relationDocModel, objectDocModel, OBJ_DOC_MODEL); } } @@ -243,7 +247,8 @@ public class RelationDocumentModelHandler } // DocumentModel itemDocModel = docModelFromCSID(ctx, itemCsid); - protected RelationsDocListItem createRelationsDocListItem(ServiceContext ctx, + protected RelationsDocListItem createRelationsDocListItem( + ServiceContext ctx, ServiceBindingType sbt, String itemCsid, TenantBindingConfigReaderImpl tReader, @@ -252,7 +257,7 @@ public class RelationDocumentModelHandler item.setDocumentType(documentType);//this one comes from the record, as subjectDocumentType, objectDocumentType. item.setCsid(itemCsid); - DocumentModel itemDocModel = NuxeoUtils.getDocFromCsid(getRepositorySession(), ctx, itemCsid); //null if not found. + DocumentModel itemDocModel = NuxeoUtils.getDocFromCsid(ctx, this.getRepositorySession(), itemCsid); //null if not found. if (itemDocModel != null) { String itemDocType = itemDocModel.getDocumentType().getName(); if (Tools.isBlank(documentType)) { @@ -304,7 +309,10 @@ public class RelationDocumentModelHandler private final boolean OBJ_DOC_MODEL = false; private DocumentModel getSubjectOrObjectDocModel( - DocumentModel relationDocModel, ServiceContext ctx, boolean fSubject) throws Exception { + DocumentModel relationDocModel, + boolean fSubject) throws Exception { + ServiceContext ctx = this.getServiceContext(); + // Get the document model for the object of the relation. String commonPartLabel = ctx.getCommonPartLabel(); String csid = ""; @@ -322,7 +330,8 @@ public class RelationDocumentModelHandler // provided as an alternate identifier. } if (Tools.notBlank(csid)) { - DocumentWrapper docWrapper = getRepositoryClient(ctx).getDocFromCsid(ctx, csid); + RepositoryJavaClientImpl nuxeoRepoClient = (RepositoryJavaClientImpl)getRepositoryClient(ctx); + DocumentWrapper docWrapper = nuxeoRepoClient.getDocFromCsid(ctx, this.getRepositorySession(), csid); docModel = docWrapper.getWrappedObject(); } else { // if (Tools.isBlank(objectCsid)) { try { @@ -344,10 +353,10 @@ public class RelationDocumentModelHandler private void populateSubjectOrObjectValues( DocumentModel relationDocModel, DocumentModel subjectOrObjectDocModel, - ServiceContext ctx, boolean fSubject ) { + ServiceContext ctx = this.getServiceContext(); + HashMap properties = new HashMap(); - try { String doctype = (String) subjectOrObjectDocModel.getType(); properties.put((fSubject?RelationJAXBSchema.SUBJECT_DOCTYPE:RelationJAXBSchema.OBJECT_DOCTYPE), -- 2.47.3