From: Richard Millet Date: Mon, 24 Feb 2014 17:34:07 +0000 (-0800) Subject: PAHMA-963-REM-A: Added an Spring AOP wrapper for the Nuxeo repository instance class. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=342a6e8e52dbe386313e5521590fe8e9cae8cc7c;p=tmp%2Fjakarta-migration.git PAHMA-963-REM-A: Added an Spring AOP wrapper for the Nuxeo repository instance class. --- diff --git a/3rdparty/nuxeo/nuxeo-platform-thumbnail/.gitignore b/3rdparty/nuxeo/nuxeo-platform-thumbnail/.gitignore new file mode 100644 index 000000000..ea8c4bf7f --- /dev/null +++ b/3rdparty/nuxeo/nuxeo-platform-thumbnail/.gitignore @@ -0,0 +1 @@ +/target diff --git a/pom.xml b/pom.xml index d98d4aac9..a1b413387 100644 --- a/pom.xml +++ b/pom.xml @@ -24,8 +24,8 @@ --> 4.1-SNAPSHOT 4.1-SNAPSHOT - 3.0.0.RELEASE - 3.0.2.RELEASE + 3.0.5.RELEASE + 3.0.5.RELEASE diff --git a/services/JaxRsServiceProvider/src/main/resources/log4j.properties b/services/JaxRsServiceProvider/src/main/resources/log4j.properties index 3677268c9..ba0b6ce4f 100644 --- a/services/JaxRsServiceProvider/src/main/resources/log4j.properties +++ b/services/JaxRsServiceProvider/src/main/resources/log4j.properties @@ -53,9 +53,9 @@ log4j.additivity.perf.collectionspace=false # CollectionSpace loggers and default levels - all loggers using the rootLogger if not otherwise specified # log4j.logger.org.collectionspace=INFO -log4j.logger.org.collectionspace.services.nuxeo.client.java=TRACE +log4j.logger.org.collectionspace.services.nuxeo.client.java=ERROR log4j.logger.org.collectionspace.services.common.storage.JDBCTools=ERROR -log4j.logger.org.collectionspace.services.common.profile.CSpaceFilter=DEBUG +log4j.logger.org.collectionspace.services.common.profile.CSpaceFilter=ERROR #log4j.logger.org.collectionspace.services.common.vocabulary.nuxeo=TRACE diff --git a/services/JaxRsServiceProvider/src/main/webapp/WEB-INF/applicationContext-security.xml b/services/JaxRsServiceProvider/src/main/webapp/WEB-INF/applicationContext-security.xml index a6750477b..ca6e36183 100644 --- a/services/JaxRsServiceProvider/src/main/webapp/WEB-INF/applicationContext-security.xml +++ b/services/JaxRsServiceProvider/src/main/webapp/WEB-INF/applicationContext-security.xml @@ -12,9 +12,11 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sec="http://www.springframework.org/schema/security" xmlns:util="http://www.springframework.org/schema/util" - xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd - http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd - http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> + xmlns:aop="http://www.springframework.org/schema/aop" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd + http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd + http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> - /WEB-INF/login.conf + /WEB-INF/login.conf diff --git a/services/JaxRsServiceProvider/src/main/webapp/WEB-INF/web.xml b/services/JaxRsServiceProvider/src/main/webapp/WEB-INF/web.xml index 529f90b59..28714fd3b 100644 --- a/services/JaxRsServiceProvider/src/main/webapp/WEB-INF/web.xml +++ b/services/JaxRsServiceProvider/src/main/webapp/WEB-INF/web.xml @@ -36,7 +36,7 @@ contextConfigLocation @@ -65,6 +65,7 @@ - delayBetweenAttemptsMillis - How long to wait between retries. - --> + + diff --git a/services/authentication/jaxb/.gitignore b/services/authentication/jaxb/.gitignore new file mode 100644 index 000000000..ea8c4bf7f --- /dev/null +++ b/services/authentication/jaxb/.gitignore @@ -0,0 +1 @@ +/target 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 95693d738..d7354748f 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 @@ -79,6 +79,7 @@ import org.collectionspace.services.config.ClientType; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.lifecycle.TransitionDef; import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler; +import org.collectionspace.services.nuxeo.client.java.RepositoryInstanceInterface; import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl; import org.collectionspace.services.nuxeo.util.NuxeoUtils; import org.collectionspace.services.workflow.WorkflowCommon; @@ -326,7 +327,7 @@ public abstract class AuthorityResource * Resource. They then call this method on that resource. */ @Override - public DocumentModel getDocModelForAuthorityItem(RepositoryInstance repoSession, RefName.AuthorityItem item) + public DocumentModel getDocModelForAuthorityItem(RepositoryInstanceInterface repoSession, RefName.AuthorityItem item) throws Exception, DocumentNotFoundException { if(item == null) { return null; diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/VocabManagerImpl.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/VocabManagerImpl.java index d00d923d0..3fbac6ae1 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/VocabManagerImpl.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/VocabManagerImpl.java @@ -8,7 +8,7 @@ import org.nuxeo.ecm.core.api.DocumentModelList; import org.nuxeo.ecm.core.api.repository.RepositoryInstance; import org.nuxeo.ecm.core.client.NuxeoClient; -import org.collectionspace.services.nuxeo.client.java.NuxeoConnector; +//import org.collectionspace.services.nuxeo.client.java.NuxeoConnector; import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl; //import org.collectionspace.services.common.query.IQueryManager; 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 87aca5fdd..0887cf267 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 @@ -38,8 +38,8 @@ import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema; import org.collectionspace.services.config.service.ObjectPartType; - import org.collectionspace.services.nuxeo.client.java.DocHandlerBase; +import org.collectionspace.services.nuxeo.client.java.RepositoryInstanceInterface; import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl; import org.nuxeo.ecm.core.api.ClientException; import org.nuxeo.ecm.core.api.DocumentModel; @@ -159,7 +159,7 @@ public abstract class AuthorityDocumentModelHandler public String getShortIdentifier(String authCSID, String schemaName) throws Exception { String shortIdentifier = null; - RepositoryInstance repoSession = null; + RepositoryInstanceInterface repoSession = null; ServiceContext ctx = this.getServiceContext(); RepositoryJavaClientImpl nuxeoRepoClient = (RepositoryJavaClientImpl)this.getRepositoryClient(ctx); 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 133572b33..8f75f91ac 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 @@ -45,6 +45,7 @@ import org.collectionspace.services.config.service.ListResultField; import org.collectionspace.services.config.service.ObjectPartType; import org.collectionspace.services.nuxeo.client.java.DocHandlerBase; import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentException; +import org.collectionspace.services.nuxeo.client.java.RepositoryInstanceInterface; import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl; import org.collectionspace.services.nuxeo.util.NuxeoUtils; import org.collectionspace.services.relation.RelationsCommonList; @@ -355,7 +356,7 @@ public abstract class AuthorityItemDocumentModelHandler } ServiceContext ctx = getServiceContext(); RepositoryClient repoClient = getRepositoryClient(ctx); - RepositoryInstance repoSession = this.getRepositorySession(); + RepositoryInstanceInterface repoSession = this.getRepositorySession(); // Update all the existing records that have a field with the old refName in it int nUpdated = RefNameServiceUtils.updateAuthorityRefDocs(ctx, repoClient, repoSession, @@ -470,7 +471,7 @@ public abstract class AuthorityItemDocumentModelHandler String propertyName, String itemcsid) throws Exception { AuthorityRefDocList authRefDocList = null; - RepositoryInstance repoSession = null; + RepositoryInstanceInterface repoSession = null; boolean releaseRepoSession = false; try { diff --git a/services/authorization/jaxb/.gitignore b/services/authorization/jaxb/.gitignore new file mode 100644 index 000000000..19f2e002c --- /dev/null +++ b/services/authorization/jaxb/.gitignore @@ -0,0 +1,2 @@ +/target +/target diff --git a/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/BatchDocumentModelHandler.java b/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/BatchDocumentModelHandler.java index 4b2f2608d..3aa4b552d 100644 --- a/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/BatchDocumentModelHandler.java +++ b/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/BatchDocumentModelHandler.java @@ -32,6 +32,7 @@ import javax.ws.rs.core.Response; import org.collectionspace.services.BatchJAXBSchema; import org.collectionspace.services.jaxb.InvocableJAXBSchema; import org.collectionspace.services.nuxeo.client.java.DocHandlerBase; +import org.collectionspace.services.nuxeo.client.java.RepositoryInstanceInterface; import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl; import org.collectionspace.services.batch.BatchCommon; import org.collectionspace.services.batch.BatchInvocable; @@ -68,7 +69,7 @@ public class BatchDocumentModelHandler ResourceMap resourceMap, InvocationContext invContext) throws Exception { - RepositoryInstance repoSession = null; + RepositoryInstanceInterface repoSession = null; boolean releaseRepoSession = false; String invocationMode = invContext.getMode(); diff --git a/services/blob/service/src/main/java/org/collectionspace/services/blob/nuxeo/BlobDocumentModelHandler.java b/services/blob/service/src/main/java/org/collectionspace/services/blob/nuxeo/BlobDocumentModelHandler.java index 9345ab91e..8c0d3a853 100644 --- a/services/blob/service/src/main/java/org/collectionspace/services/blob/nuxeo/BlobDocumentModelHandler.java +++ b/services/blob/service/src/main/java/org/collectionspace/services/blob/nuxeo/BlobDocumentModelHandler.java @@ -42,11 +42,11 @@ import org.collectionspace.services.jaxb.BlobJAXBSchema; import org.collectionspace.services.nuxeo.client.java.CommonList; +import org.collectionspace.services.nuxeo.client.java.RepositoryInstanceInterface; import org.nuxeo.ecm.core.api.ClientException; import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.IdRef; import org.nuxeo.ecm.core.api.repository.RepositoryInstance; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -115,7 +115,7 @@ extends DocHandlerBase { ObjectPartType partMeta = partsMetaMap.get(metadataLabel); if (partMeta != null) { - RepositoryInstance repoSession = this.getRepositorySession(); + RepositoryInstanceInterface repoSession = this.getRepositorySession(); if (nuxeoImageID != null && nuxeoImageID.isEmpty() == false) try { IdRef documentRef = new IdRef(nuxeoImageID); DocumentModel docModel = repoSession.getDocument(documentRef); @@ -139,7 +139,7 @@ extends DocHandlerBase { throws Exception { ServiceContext ctx = this.getServiceContext(); BlobInput blobInput = BlobUtil.getBlobInput(ctx); // the blobInput was set by the Blob JAX-RS resource code and put into the service context - RepositoryInstance repoSession = this.getRepositorySession(); + RepositoryInstanceInterface repoSession = this.getRepositorySession(); DocumentModel docModel = wrapDoc.getWrappedObject(); BlobsCommon blobsCommon = this.getCommonPartProperties(docModel); String blobRepositoryId = blobsCommon.getRepositoryId(); //cache the value to pass to the blob retriever @@ -220,7 +220,7 @@ extends DocHandlerBase { // If blobInput has a file then we just received a multipart/form-data file post or a URI query parameter // DocumentModel documentModel = wrapDoc.getWrappedObject(); - RepositoryInstance repoSession = this.getRepositorySession(); + RepositoryInstanceInterface repoSession = this.getRepositorySession(); BlobsCommon blobsCommon = NuxeoBlobUtils.createBlobInRepository(ctx, repoSession, blobInput, purgeOriginal, true); blobInput.setBlobCsid(documentModel.getName()); //Assumption here is that the documentModel "name" field is storing a CSID diff --git a/services/common-api/.gitignore b/services/common-api/.gitignore new file mode 100644 index 000000000..ea8c4bf7f --- /dev/null +++ b/services/common-api/.gitignore @@ -0,0 +1 @@ +/target diff --git a/services/common/.gitignore b/services/common/.gitignore new file mode 100644 index 000000000..19f2e002c --- /dev/null +++ b/services/common/.gitignore @@ -0,0 +1,2 @@ +/target +/target diff --git a/services/common/pom.xml b/services/common/pom.xml index bc02b04a1..38b714cb5 100644 --- a/services/common/pom.xml +++ b/services/common/pom.xml @@ -384,6 +384,11 @@ ${spring.security.version} provided + + org.springframework + spring-aop + ${spring.version} + 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 58117049f..92bb9d816 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 @@ -26,6 +26,7 @@ package org.collectionspace.services.common; import java.util.HashMap; import java.util.List; import java.util.Map; + import javax.ws.rs.*; import javax.ws.rs.core.*; @@ -33,7 +34,6 @@ import org.collectionspace.services.client.IClientQueryParams; import org.collectionspace.services.client.IQueryManager; 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.authorityref.AuthorityRefList; @@ -47,19 +47,16 @@ import org.collectionspace.services.common.document.DocumentNotFoundException; import org.collectionspace.services.common.query.QueryManager; import org.collectionspace.services.common.vocabulary.RefNameServiceUtils; import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.AuthRefConfigInfo; - import org.collectionspace.services.config.ClientType; import org.collectionspace.services.config.service.DocHandlerParams; import org.collectionspace.services.config.service.ListResultField; import org.collectionspace.services.config.service.ServiceBindingType; - import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler; +import org.collectionspace.services.nuxeo.client.java.RepositoryInstanceInterface; import org.collectionspace.services.nuxeo.util.NuxeoUtils; - import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.jboss.resteasy.util.HttpResponseCodes; - import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.DocumentModelList; import org.nuxeo.ecm.core.api.repository.RepositoryInstance; @@ -506,7 +503,7 @@ public abstract class ResourceBase * for all inheriting resource classes. Just use ServiceContext.getResourceMap() to get * the map, and pass it in. */ - public static DocumentModel getDocModelForRefName(RepositoryInstance repoSession, String refName, ResourceMap resourceMap) + public static DocumentModel getDocModelForRefName(RepositoryInstanceInterface repoSession, String refName, ResourceMap resourceMap) throws Exception, DocumentNotFoundException { RefName.AuthorityItem item = RefName.AuthorityItem.parse(refName); if(item != null) { @@ -529,13 +526,13 @@ public abstract class ResourceBase // THis is ugly, but prevents us parsing the refName twice. Once we make refName a little more // general, and less Authority(Item) specific, this will look better. - public DocumentModel getDocModelForAuthorityItem(RepositoryInstance repoSession, RefName.AuthorityItem item) + public DocumentModel getDocModelForAuthorityItem(RepositoryInstanceInterface repoSession, RefName.AuthorityItem item) throws Exception, DocumentNotFoundException { logger.warn("Default (ResourceBase) getDocModelForAuthorityItem called - should not happen!"); return null; } - public DocumentModel getDocModelForRefName(RepositoryInstance repoSession, String refName) + public DocumentModel getDocModelForRefName(RepositoryInstanceInterface repoSession, String refName) throws Exception, DocumentNotFoundException { return getDocModelForAuthorityItem(repoSession, RefName.AuthorityItem.parse(refName)); } diff --git a/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoBlobUtils.java b/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoBlobUtils.java index d592abab1..a6e514301 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoBlobUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoBlobUtils.java @@ -118,6 +118,7 @@ import org.collectionspace.services.blob.MeasuredPartGroup; import org.collectionspace.services.blob.MeasuredPartGroupList; import org.collectionspace.services.jaxb.BlobJAXBSchema; import org.collectionspace.services.nuxeo.client.java.CommonList; +import org.collectionspace.services.nuxeo.client.java.RepositoryInstanceInterface; import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl; import org.collectionspace.services.nuxeo.extension.thumbnail.ThumbnailConstants; import org.collectionspace.services.nuxeo.util.NuxeoUtils; @@ -297,7 +298,7 @@ public class NuxeoBlobUtils { return result; } - static public CommonList getBlobDerivatives(RepositoryInstance repoSession, + static public CommonList getBlobDerivatives(RepositoryInstanceInterface repoSession, String repositoryId, List resultsFields, String uri) throws Exception { CommonList commonList = new CommonList(); @@ -501,7 +502,7 @@ public class NuxeoBlobUtils { * This is a prototype method that is not currently used as of 1/1/2012. However, * it may be useful now that we've transitioned to using an embedded Nuxeo server. */ - static private File getBlobFile(RepositoryInstance ri, + static private File getBlobFile(RepositoryInstanceInterface ri, DocumentModel documentModel, Blob blob) { DefaultBinaryManager binaryManager = null; RepositoryDescriptor descriptor = null; @@ -576,11 +577,11 @@ public class NuxeoBlobUtils { * the id * @return the blob */ - static private Blob getBlob(RepositoryInstance nuxeoSession, String id) { + static private Blob getBlob(RepositoryInstanceInterface repoSession, String id) { Blob result = null; try { - Repository repository = nuxeoSession.getRepository(); + Repository repository = repoSession.getRepositoryInstance().getRepository(); // binaryManager.initialize(new RepositoryDescriptor()); // binaryManager.getBinary("a4cac052ae0281979f2dcf5ab2e61a6c"); // DocumentResolver.resolveReference(nuxeoSession, documentRef); @@ -876,8 +877,8 @@ public class NuxeoBlobUtils { return result; } - static private RepositoryInstance getRepositorySession(ServiceContext ctx, RepositoryClient repositoryClient) { - RepositoryInstance result = null; + static private RepositoryInstanceInterface getRepositorySession(ServiceContext ctx, RepositoryClient repositoryClient) { + RepositoryInstanceInterface result = null; RepositoryJavaClientImpl nuxeoClient = (RepositoryJavaClientImpl)repositoryClient; try { @@ -889,7 +890,7 @@ public class NuxeoBlobUtils { return result; } - static private void releaseRepositorySession(ServiceContext ctx, RepositoryClient repositoryClient, RepositoryInstance repoSession) throws TransactionException { + static private void releaseRepositorySession(ServiceContext ctx, RepositoryClient repositoryClient, RepositoryInstanceInterface repoSession) throws TransactionException { RepositoryJavaClientImpl nuxeoClient = (RepositoryJavaClientImpl)repositoryClient; nuxeoClient.releaseRepositorySession(ctx, repoSession); } @@ -907,7 +908,7 @@ public class NuxeoBlobUtils { } private static DocumentModel createDocumentFromBlob( - RepositoryInstance repoSession, + RepositoryInstanceInterface repoSession, Blob inputStreamBlob, String blobLocation, boolean overwrite, @@ -922,7 +923,7 @@ public class NuxeoBlobUtils { // image derivatives. // result = getFileManager().createDocumentFromBlob( - repoSession, inputStreamBlob, blobLocation, true, blobName); + repoSession.getRepositoryInstance(), inputStreamBlob, blobLocation, true, blobName); } else { // // User Nuxeo's default file importer/adapter explicitly. This avoids specialized functionality from happening like @@ -936,7 +937,7 @@ public class NuxeoBlobUtils { FileImporter defaultFileImporter = fileManagerService.getPluginByName("DefaultFileImporter"); result = defaultFileImporter.create( - repoSession, inputStreamBlob, blobLocation, true, blobName, getTypeService()); + repoSession.getRepositoryInstance(), inputStreamBlob, blobLocation, true, blobName, getTypeService()); } return result; @@ -951,7 +952,7 @@ public class NuxeoBlobUtils { BlobsCommon result = null; boolean repoSessionCleanup = false; - RepositoryInstance repoSession = (RepositoryInstance)ctx.getCurrentRepositorySession(); + RepositoryInstanceInterface repoSession = (RepositoryInstanceInterface)ctx.getCurrentRepositorySession(); if (repoSession == null) { repoSession = getRepositorySession(ctx, repositoryClient); repoSessionCleanup = true; @@ -998,7 +999,7 @@ public class NuxeoBlobUtils { */ public static BlobsCommon createBlobInRepository( ServiceContext ctx, - RepositoryInstance repoSession, + RepositoryInstanceInterface repoSession, BlobInput blobInput, boolean purgeOriginal, boolean useNuxeoAdaptors) throws Exception { @@ -1084,7 +1085,7 @@ public class NuxeoBlobUtils { * the mime type * @return the string */ - static private BlobsCommon createBlobInRepository(RepositoryInstance nuxeoSession, + static private BlobsCommon createBlobInRepository(RepositoryInstanceInterface nuxeoSession, DocumentModel blobLocation, boolean purgeOriginal, File file, @@ -1178,7 +1179,7 @@ public class NuxeoBlobUtils { BlobOutput result = null; boolean repoSessionCleanup = false; - RepositoryInstance repoSession = (RepositoryInstance)ctx.getCurrentRepositorySession(); + RepositoryInstanceInterface repoSession = (RepositoryInstanceInterface)ctx.getCurrentRepositorySession(); if (repoSession == null) { repoSession = getRepositorySession(ctx, repositoryClient); repoSessionCleanup = true; @@ -1244,7 +1245,7 @@ public class NuxeoBlobUtils { * @return the image */ static public BlobOutput getBlobOutput(ServiceContext ctx, - RepositoryInstance repoSession, + RepositoryInstanceInterface repoSession, String repositoryId, String derivativeTerm, Boolean getContentFlag, diff --git a/services/common/src/main/java/org/collectionspace/services/common/relation/RelationUtils.java b/services/common/src/main/java/org/collectionspace/services/common/relation/RelationUtils.java index 846b589f6..d52778a20 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/relation/RelationUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/relation/RelationUtils.java @@ -9,6 +9,7 @@ import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.DocumentException; import org.collectionspace.services.common.document.DocumentNotFoundException; import org.collectionspace.services.common.repository.RepositoryClient; +import org.collectionspace.services.nuxeo.client.java.RepositoryInstanceInterface; import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl; import org.nuxeo.ecm.core.api.ClientException; import org.nuxeo.ecm.core.api.DocumentModel; @@ -28,7 +29,7 @@ public class RelationUtils { */ private static DocumentModelList findRelationsWithRefName( ServiceContext ctx, - RepositoryInstance repoSession, + RepositoryInstanceInterface repoSession, String refName, String targetField, String orderByField, @@ -73,7 +74,7 @@ public class RelationUtils { public static void updateRefNamesInRelations( ServiceContext ctx, RepositoryClient repoClient, - RepositoryInstance repoSession, + RepositoryInstanceInterface repoSession, String targetField, String oldRefName, String newRefName) { diff --git a/services/common/src/main/java/org/collectionspace/services/common/repository/RepositoryClient.java b/services/common/src/main/java/org/collectionspace/services/common/repository/RepositoryClient.java index c9967c00f..35502c210 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/repository/RepositoryClient.java +++ b/services/common/src/main/java/org/collectionspace/services/common/repository/RepositoryClient.java @@ -32,10 +32,15 @@ import org.collectionspace.services.common.document.DocumentNotFoundException; import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.common.storage.StorageClient; import org.collectionspace.services.config.tenant.RepositoryDomainType; + +import org.collectionspace.services.nuxeo.client.java.RepositoryInstanceInterface; +// +// All of these Nuxeo specific classes should not be here. This is supposed to be +// a repository-neutral interface. +// import org.nuxeo.ecm.core.api.ClientException; import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.DocumentModelList; -import org.nuxeo.ecm.core.api.repository.RepositoryInstance; /** * RepositoryClient is a generic Document Repository client @@ -127,7 +132,7 @@ public interface RepositoryClient extends StorageClient { * @param where NXQL where clause to get the document * @throws DocumentException */ - public String findDocCSID(RepositoryInstance repoSession, + public String findDocCSID(RepositoryInstanceInterface repoSession, ServiceContext ctx, String where) throws DocumentNotFoundException, DocumentException; diff --git a/services/common/src/main/java/org/collectionspace/services/common/repository/RepositoryInstanceWrapperAdvice.java b/services/common/src/main/java/org/collectionspace/services/common/repository/RepositoryInstanceWrapperAdvice.java new file mode 100644 index 000000000..f8e40cfa7 --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/common/repository/RepositoryInstanceWrapperAdvice.java @@ -0,0 +1,23 @@ +package org.collectionspace.services.common.repository; + +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; + + +public class RepositoryInstanceWrapperAdvice implements MethodInterceptor { + + public RepositoryInstanceWrapperAdvice() { + // TODO Auto-generated constructor stub + } + + //@Override + public Object invoke(MethodInvocation methodInvocation) throws Throwable { + try { + // proceed to original method call + Object result = methodInvocation.proceed(); + return result; + } catch (IllegalArgumentException e) { + throw e; + } + } +} 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 96a50c23e..13f47fe5d 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 @@ -38,7 +38,6 @@ 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.CollectionSpaceClient; import org.collectionspace.services.client.IRelationsManager; import org.collectionspace.services.client.PoxPayloadIn; @@ -65,6 +64,7 @@ import org.collectionspace.services.common.query.QueryManager; import org.collectionspace.services.common.relation.RelationUtils; import org.collectionspace.services.common.repository.RepositoryClient; import org.collectionspace.services.nuxeo.client.java.DocHandlerBase; +import org.collectionspace.services.nuxeo.client.java.RepositoryInstanceInterface; import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl; import org.collectionspace.services.common.security.SecurityUtils; import org.collectionspace.services.config.service.ServiceBindingType; @@ -213,7 +213,7 @@ public class RefNameServiceUtils { public static void updateRefNamesInRelations( ServiceContext ctx, RepositoryClient repoClient, - RepositoryInstance repoSession, + RepositoryInstanceInterface repoSession, String oldRefName, String newRefName) { // @@ -240,7 +240,7 @@ public class RefNameServiceUtils { } public static AuthorityRefDocList getAuthorityRefDocs( - RepositoryInstance repoSession, + RepositoryInstanceInterface repoSession, ServiceContext ctx, UriTemplateRegistry uriTemplateRegistry, RepositoryClient repoClient, @@ -395,7 +395,7 @@ public class RefNameServiceUtils { public static int updateAuthorityRefDocs( ServiceContext ctx, RepositoryClient repoClient, - RepositoryInstance repoSession, + RepositoryInstanceInterface repoSession, String oldRefName, String newRefName, String refPropName) throws Exception { @@ -468,7 +468,7 @@ public class RefNameServiceUtils { private static DocumentModelList findAuthorityRefDocs( ServiceContext ctx, RepositoryClient repoClient, - RepositoryInstance repoSession, List serviceTypes, + RepositoryInstanceInterface repoSession, List serviceTypes, String refName, String refPropName, Map queriedServiceBindings, diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocHandlerBase.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocHandlerBase.java index 175c209b3..e60f1ee6a 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocHandlerBase.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocHandlerBase.java @@ -177,7 +177,7 @@ public abstract class DocHandlerBase extends RemoteDocumentModelHandlerImpl wrapDoc) throws Exception { CommonList commonList = new CommonList(); String markRtSbj = null; - RepositoryInstance repoSession = null; + RepositoryInstanceInterface repoSession = null; RepositoryJavaClientImpl repoClient = null; RepositoryJavaClientImpl nuxeoRepoClient = null; boolean releaseRepoSession = false; 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 41fb09664..7559b24ab 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 @@ -77,7 +77,7 @@ public abstract class DocumentModelHandler extends AbstractMultipartDocumentHandlerImpl { private final Logger logger = LoggerFactory.getLogger(DocumentModelHandler.class); - private RepositoryInstance repositorySession; + private RepositoryInstanceInterface repositorySession; protected String oldRefNameOnUpdate = null; // FIXME: REM - We should have setters and getters for these protected String newRefNameOnUpdate = null; // FIXME: two fields. @@ -211,7 +211,7 @@ public abstract class DocumentModelHandler * getRepositorySession returns Nuxeo Repository Session * @return */ - public RepositoryInstance getRepositorySession() { + public RepositoryInstanceInterface getRepositorySession() { return repositorySession; } @@ -220,7 +220,7 @@ public abstract class DocumentModelHandler * setRepositorySession sets repository session * @param repoSession */ - public void setRepositorySession(RepositoryInstance repoSession) { + public void setRepositorySession(RepositoryInstanceInterface repoSession) { this.repositorySession = repoSession; } 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 f7aeb66ef..144450c81 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 @@ -24,10 +24,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map.Entry; -import javax.transaction.TransactionManager; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.collectionspace.services.common.repository.RepositoryInstanceWrapperAdvice; import org.collectionspace.services.config.tenant.RepositoryDomainType; import org.jboss.remoting.InvokerLocator; import org.nuxeo.ecm.core.api.repository.Repository; @@ -36,11 +33,14 @@ import org.nuxeo.ecm.core.api.repository.RepositoryInstanceHandler; import org.nuxeo.ecm.core.api.repository.RepositoryManager; import org.nuxeo.ecm.core.client.DefaultLoginHandler; import org.nuxeo.ecm.core.client.LoginHandler; -//import org.nuxeo.ecm.core.repository.RepositoryDescriptor; import org.nuxeo.runtime.api.Framework; import org.nuxeo.runtime.transaction.TransactionHelper; + +import javax.transaction.TransactionManager; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.aop.framework.ProxyFactory; /** * @author Bogdan Stefanescu @@ -52,26 +52,24 @@ public final class NuxeoClientEmbedded { private LoginHandler loginHandler; - private final HashMap repositoryInstances; + private final HashMap repositoryInstances; private InvokerLocator locator; private RepositoryManager repositoryMgr; private static final NuxeoClientEmbedded instance = new NuxeoClientEmbedded(); - - private static final Log log = LogFactory.getLog(NuxeoClientEmbedded.class); - + /** * Constructs a new NuxeoClient. NOTE: Using {@link #getInstance()} instead * of this constructor is recommended. */ - public NuxeoClientEmbedded() { + private NuxeoClientEmbedded() { loginHandler = loginHandler == null ? new DefaultLoginHandler() : loginHandler; - repositoryInstances = new HashMap(); + repositoryInstances = new HashMap(); } - + public static NuxeoClientEmbedded getInstance() { return instance; } @@ -86,13 +84,13 @@ public final class NuxeoClientEmbedded { private void doDisconnect() throws Exception { locator = null; // close repository sessions if any - Iterator> it = repositoryInstances.entrySet().iterator(); + Iterator> it = repositoryInstances.entrySet().iterator(); while (it.hasNext()) { - Entry repo = it.next(); + Entry repo = it.next(); try { repo.getValue().close(); } catch (Exception e) { - log.debug("Error while trying to close " + repo, e); + logger.debug("Error while trying to close " + repo, e); } it.remove(); } @@ -144,20 +142,23 @@ public final class NuxeoClientEmbedded { /* * Open a Nuxeo repo session using the passed in repoDomain and use the default tx timeout period */ - public RepositoryInstance openRepository(RepositoryDomainType repoDomain) throws Exception { + public RepositoryInstanceInterface openRepository(RepositoryDomainType repoDomain) throws Exception { return openRepository(repoDomain.getRepositoryName(), -1); } /* * Open a Nuxeo repo session using the passed in repoDomain and use the default tx timeout period */ - public RepositoryInstance openRepository(String repoName) throws Exception { + public RepositoryInstanceInterface openRepository(String repoName) throws Exception { return openRepository(repoName, -1); } - public RepositoryInstance openRepository(String repoName, int timeoutSeconds) throws Exception { - RepositoryInstance result = null; + public RepositoryInstanceInterface openRepository(String repoName, int timeoutSeconds) throws Exception { + RepositoryInstanceInterface result = null; + // + // If the called passed in a custom timeout setting, use it to configure Nuxeo's transaction manager. + // if (timeoutSeconds > 0) { TransactionManager transactionMgr = TransactionHelper.lookupTransactionManager(); transactionMgr.setTransactionTimeout(timeoutSeconds); @@ -167,6 +168,9 @@ public final class NuxeoClientEmbedded { } } + // + // Start a new Nuxeo transaction + // boolean startedTransaction = false; if (TransactionHelper.isTransactionActive() == false) { startedTransaction = TransactionHelper.startTransaction(); @@ -179,7 +183,11 @@ public final class NuxeoClientEmbedded { logger.warn("A request to start a new transaction was made, but a transaction is already open."); } - Repository repository = null; + // + // From the repository name that the caller passed in, get an instance of Nuxeo's Repository class. + // The Repository class is just a metadata description of the repository. + // + Repository repository; if (repoName != null) { repository = getRepositoryManager().getRepository(repoName); } else { @@ -187,32 +195,77 @@ public final class NuxeoClientEmbedded { logger.warn(String.format("Using default repository '%s' because no name was specified.", repository.getName())); } + // + // Using the Repository class, get a Spring AOP proxied instance. We use Spring AOP to "wrap" all calls to the + // Nuxeo repository so we can check for network related failures and perform a series of retries. + // if (repository != null) { - result = newRepositoryInstance(repository); - if (result != null) { + result = getRepositoryInstanceWrapper(repository); + logger.trace(String.format("A new transaction was started on thread '%d' : %s.", + Thread.currentThread().getId(), startedTransaction ? "true" : "false")); + logger.trace(String.format("Added a new repository instance to our repo list. Current count is now: %d", + repositoryInstances.size())); + } else { + String errMsg = String.format("Could not open a session to the Nuxeo repository='%s'", repoName); + logger.error(errMsg); + throw new Exception(errMsg); + } + + + return result; + } + + // + // Returns a proxied interface to a Nuxeo repository instance. Our proxy uses Spring AOP to + // wrap each call to the Nuxeo repo with code that catches network related errors/exceptions and + // re-attempts the calls to see if it recovers. + // + private RepositoryInstanceInterface getAOPProxy(RepositoryInstance repositoryInstance) { + RepositoryInstanceInterface result = null; + + try { + ProxyFactory factory = new ProxyFactory(new RepositoryInstanceWrapper(repositoryInstance)); + factory.addAdvice(new RepositoryInstanceWrapperAdvice()); + factory.setExposeProxy(true); + result = (RepositoryInstanceInterface)factory.getProxy(); + } catch (Exception e) { + logger.error("Could not create AOP proxy for: " + RepositoryInstanceWrapper.class.getName(), e); + } + + return result; + } + + /* + * From the Repository object (a description of the repository), get repository instance wrapper. Our wrapper + * will using the Spring AOP mechanism to intercept all calls to the repository. We will wrap all the calls to the + * Nuxeo repository and check for network related failures. We will retry all calls to the Nuxeo repo that fail because + * of network erros. + */ + private RepositoryInstanceInterface getRepositoryInstanceWrapper(Repository repository) throws Exception { + RepositoryInstanceInterface result = null; + + RepositoryInstance repositoryInstance = new RepositoryInstanceHandler(repository).getProxy(); // A Nuxeo repo instance handler proxy + if (repositoryInstance != null) { + result = this.getAOPProxy(repositoryInstance); // This is our AOP proxy + if (result != null) { String key = result.getSessionId(); repositoryInstances.put(key, result); - if (logger.isTraceEnabled()) { - logger.trace(String.format("A new transaction was started on thread '%d' : %s.", - Thread.currentThread().getId(), startedTransaction ? "true" : "false")); - logger.trace(String.format("Added a new repository instance to our repo list. Current count is now: %d", - repositoryInstances.size())); - } - } else { - String errMsg = String.format("Could not create a new repository instance for '%s' repository.", repository.getName()); - logger.error(errMsg); - throw new Exception(errMsg); - } + } else { + String errMsg = String.format("Could not instantiate a Spring AOP proxy for class '%s'.", + RepositoryInstanceWrapper.class.getName()); + logger.error(errMsg); + throw new Exception(errMsg); + } } else { - String errMsg = String.format("Could not open a session to the Nuxeo repository='%s'", repoName); + String errMsg = String.format("Could not create a new repository instance for '%s' repository.", repository.getName()); logger.error(errMsg); throw new Exception(errMsg); } - - return result; + + return result; } - public void releaseRepository(RepositoryInstance repo) throws Exception { + public void releaseRepository(RepositoryInstanceInterface repo) throws Exception { String key = repo.getSessionId(); try { @@ -222,7 +275,7 @@ public final class NuxeoClientEmbedded { logger.error("Possible data loss. Could not save and/or release the repository.", e); throw e; } finally { - RepositoryInstance wasRemoved = repositoryInstances.remove(key); + RepositoryInstanceInterface wasRemoved = repositoryInstances.remove(key); if (logger.isTraceEnabled()) { if (wasRemoved != null) { logger.trace("Removed a repository instance from our repo list. Current count is now: " @@ -237,10 +290,5 @@ public final class NuxeoClientEmbedded { logger.trace(String.format("Transaction closed on thread '%d'", Thread.currentThread().getId())); } } - } - - public static RepositoryInstance newRepositoryInstance(Repository repository) { - return new RepositoryInstanceHandler(repository).getProxy(); // Why a proxy here? - } - + } } diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoConnector.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoConnector.java deleted file mode 100644 index fbb14e66f..000000000 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoConnector.java +++ /dev/null @@ -1,284 +0,0 @@ -/** - * This document is a part of the source code and related artifacts - * for CollectionSpace, an open source collections management system - * for museums and related institutions: - - * http://www.collectionspace.org - * http://wiki.collectionspace.org - - * Copyright 2009 University of California at Berkeley - - * Licensed under the Educational Community License (ECL), Version 2.0. - * You may not use this file except in compliance with this License. - - * You may obtain a copy of the ECL 2.0 License at - - * https://source.collectionspace.org/collection-space/LICENSE.txt - - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.collectionspace.services.nuxeo.client.java; - -import java.io.File; -import java.util.Collection; -import java.util.Hashtable; -import java.util.Iterator; - -import org.collectionspace.services.config.RepositoryClientConfigType; -import org.nuxeo.ecm.core.api.DocumentModel; -import org.nuxeo.ecm.core.api.DocumentModelList; -import org.nuxeo.ecm.core.api.repository.RepositoryInstance; -import org.nuxeo.ecm.core.client.DefaultLoginHandler; -import org.nuxeo.ecm.core.client.NuxeoApp; -import org.nuxeo.ecm.core.client.NuxeoClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * NuxeoConnector creates Nuxeo remoting runtime and provides access to Nuxeo client. - * @author - */ -public class NuxeoConnector { - - public final static String NUXEO_CLIENT_DIR = "nuxeo-client"; - private Logger logger = LoggerFactory.getLogger(NuxeoConnector.class); - private static final NuxeoConnector self = new NuxeoConnector(); - private static final String NUXEO_CLIENT_USERNAME = "NUXEO_CLIENT_USERNAME"; - private static final String NUXEO_CLIENT_PASSWORD = "NUXEO_CLIENT_PASSWORD"; - private NuxeoApp app; - private NuxeoClient client; - private volatile boolean initialized = false; //use volatile for lazy initialization in singleton - private RepositoryClientConfigType repositoryClientConfig; - - private NuxeoConnector() { - } - - public final static NuxeoConnector getInstance() { - return self; - } - - private String getClientUserName(RepositoryClientConfigType repositoryClientConfig) { - String username = System.getenv(NUXEO_CLIENT_USERNAME); - if (username == null) { - username = repositoryClientConfig.getUser(); - } - return username; - } - - private String getClientPassword(RepositoryClientConfigType repositoryClientConfig) { - String password = System.getenv(NUXEO_CLIENT_PASSWORD); - if (password == null) { - password = repositoryClientConfig.getPassword(); - } - return password; - } - - /** - * initialize initialize the Nuxeo connector. It makes sure that the connector - * is initialized in a thread-safe manner and not initialized more than once. - * Initialization involves starting Nuxeo runtime, loading Nuxeo APIs jars - * in OSGI container as well as establishing initial connection. - * @param repositoryClientConfig - * @throws java.lang.Exception - */ - public void initialize(RepositoryClientConfigType repositoryClientConfig) throws Exception { - - if(initialized == false){ - synchronized(this){ - if(initialized == false){ - try{ - this.repositoryClientConfig = repositoryClientConfig; - setProperties(repositoryClientConfig); - app = new NuxeoApp(); - app.start(); - if(logger.isDebugEnabled()){ - logger.debug("initialize() NuxeoApp started"); - } - loadBundles(); - client = NuxeoClient.getInstance(); - String username = getClientUserName(repositoryClientConfig); - String password = getClientPassword(repositoryClientConfig); -// DefaultLoginHandler loginHandler = new DefaultLoginHandler( -// repositoryClientConfig.getUser(), repositoryClientConfig.getPassword()); - DefaultLoginHandler loginHandler = new DefaultLoginHandler(username, password); - client.setLoginHandler(loginHandler); - client.connect(repositoryClientConfig.getHost(), - repositoryClientConfig.getPort()); - if(logger.isDebugEnabled()){ - logger.debug("initialize(): connection successful port=" + - repositoryClientConfig.getPort()); - } - initialized = true; - }catch(Exception e){ - if(logger.isDebugEnabled()){ - logger.debug("Caught exception while initializing", e); - } - } - } - } - } - } - - /** - * release releases resources occupied by Nuxeo remoting client runtime - * @throws java.lang.Exception - */ - public void release() throws Exception { - if(initialized == true){ - client.disconnect(); - app.shutdown(); - } - } - - private void loadBundles() throws Exception { - String bundles = "nuxeo-client/lib/nuxeo-runtime-*:nuxeo-client/lib/nuxeo-*"; -// String serverRootDir = ServiceMain.getInstance().getServerRootDir(); - //can't call ServiceMain here because loadBundles is called within - //the iniitialization context of ServiceMain, recrusion problem - String serverRootDir = System.getProperty("jboss.server.home.dir"); - if(serverRootDir == null){ - serverRootDir = "."; //assume server is started from server root, e.g. server/cspace - } - File clientLibDir = new File(serverRootDir); - if(!clientLibDir.exists()){ - String msg = "Library bundles requried to deploy Nuxeo client not found: " + - " directory named nuxeo-client with bundles does not exist in " + serverRootDir; - logger.error(msg); - throw new IllegalStateException(msg); - } - Collection files = null; - if(bundles != null){ - files = NuxeoApp.getBundleFiles(new File(serverRootDir), bundles, ":"); - } - if(logger.isDebugEnabled()){ - logger.debug("loadBundles(): deploying bundles: " + files); - } - if(files != null){ - app.deployBundles(files); - } - } - - private void setProperties(RepositoryClientConfigType repositoryClientConfig) { - System.setProperty("nuxeo.client.on.jboss", Boolean.TRUE.toString()); - System.setProperty("org.nuxeo.runtime.server.enabled", Boolean.FALSE.toString()); - System.setProperty("org.nuxeo.runtime.server.port", "" + repositoryClientConfig.getPort()); - System.setProperty("org.nuxeo.runtime.server.host", repositoryClientConfig.getHost()); - //System.setProperty("org.nuxeo.runtime.1.3.3.streaming.port", "3233"); - System.setProperty("org.nuxeo.runtime.streaming.serverLocator", "socket://" + repositoryClientConfig.getHost() + ":3233"); - System.setProperty("org.nuxeo.runtime.streaming.isServer", Boolean.FALSE.toString()); - //org.nuxeo.client.remote is part of the fix to Nuxeo Runtime to use Java Remote APIs - //from JBoss - System.setProperty("org.nuxeo.client.remote", Boolean.TRUE.toString()); - } - - /** - * getClient get Nuxeo client for accessing Nuxeo services remotely using - * Nuxeo Java (EJB) Remote APIS - * @return NuxeoClient - * @throws java.lang.Exception - */ - public NuxeoClient getClient() throws Exception { - if(initialized == true){ - if(client.isConnected()){ - client.login(); - return client; - }else{ - client.forceConnect(repositoryClientConfig.getHost(), repositoryClientConfig.getPort()); - if(logger.isDebugEnabled()){ - logger.debug("getClient(): connection successful port=" + - repositoryClientConfig.getPort()); - } - return client; - } - } - String msg = "NuxeoConnector is not initialized!"; - logger.error(msg); - throw new IllegalStateException(msg); - } - - /** - * getRepositorySession get session to default repository - * @return RepositoryInstance - * @throws java.lang.Exception - */ - public RepositoryInstance getRepositorySession() throws Exception { - RepositoryInstance repoSession = getClient().openRepository(); - if(logger.isDebugEnabled()){ - logger.debug("getRepositorySession() opened repository session"); - } - return repoSession; - } - - /** - * releaseRepositorySession releases given repository session - * @param repoSession - * @throws java.lang.Exception - */ - public void releaseRepositorySession(RepositoryInstance repoSession) throws Exception { - if(repoSession != null){ - getClient().releaseRepository(repoSession); - - if(logger.isDebugEnabled()){ - logger.debug("releaseRepositorySession() released repository session"); - } - } - } - - /** - * retrieveWorkspaceIds retrieves all workspace ids from default repository - * @param tenantDomain domain representing tenant - * @return - * @throws java.lang.Exception - */ - public Hashtable retrieveWorkspaceIds(String tenantDomain) throws Exception { - RepositoryInstance repoSession = null; - Hashtable workspaceIds = new Hashtable(); - try{ - repoSession = getRepositorySession(); - DocumentModel rootDoc = repoSession.getRootDocument(); - DocumentModelList rootChildrenList = repoSession.getChildren(rootDoc.getRef()); - Iterator diter = rootChildrenList.iterator(); - while(diter.hasNext()){ - DocumentModel domain = diter.next(); - String domainPath = "/" + tenantDomain; - if(!domain.getPathAsString().equalsIgnoreCase(domainPath)){ - continue; -} - if(logger.isDebugEnabled()){ - logger.debug("domain=" + domain.toString()); - } - DocumentModelList domainChildrenList = repoSession.getChildren(domain.getRef()); - Iterator witer = domainChildrenList.iterator(); - while(witer.hasNext()){ - DocumentModel childNode = witer.next(); - if("Workspaces".equalsIgnoreCase(childNode.getName())){ - DocumentModelList workspaceList = repoSession.getChildren(childNode.getRef()); - Iterator wsiter = workspaceList.iterator(); - while(wsiter.hasNext()){ - DocumentModel workspace = wsiter.next(); - if(logger.isDebugEnabled()){ - logger.debug("workspace name=" + workspace.getName() + - " id=" + workspace.getId()); - } - workspaceIds.put(workspace.getName().toLowerCase(), workspace.getId()); - } - } - } - } - }catch(Exception e){ - if(logger.isDebugEnabled()){ - logger.debug("retrieveWorkspaceIds() caught exception ", e); - } - throw e; - }finally{ - if(repoSession != null){ - releaseRepositorySession(repoSession); - } - } - return workspaceIds; - } -} 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 3da583a9b..e1f509b1a 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 @@ -13,10 +13,10 @@ import org.collectionspace.services.common.api.JEEServerDeployment; import org.collectionspace.services.config.RepositoryClientConfigType; import org.collectionspace.services.config.tenant.RepositoryDomainType; import org.collectionspace.services.nuxeo.util.NuxeoUtils; + import org.nuxeo.ecm.core.NXCore; import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.DocumentModelList; -import org.nuxeo.ecm.core.api.repository.RepositoryInstance; import org.nuxeo.ecm.core.model.Repository; import org.nuxeo.osgi.application.FrameworkBootstrap; import org.nuxeo.ecm.core.repository.RepositoryDescriptor; @@ -145,7 +145,7 @@ public class NuxeoConnectorEmbedded { this.servletContext = servletContext; this.repositoryClientConfig = repositoryClientConfig; startNuxeoEP(serverRootPath); - client = new NuxeoClientEmbedded(); + client = NuxeoClientEmbedded.getInstance(); initialized = true; } } @@ -183,7 +183,7 @@ public class NuxeoConnectorEmbedded { * @param repoSession * @throws java.lang.Exception */ - public void releaseRepositorySession(RepositoryInstance repoSession) + public void releaseRepositorySession(RepositoryInstanceInterface repoSession) throws Exception { if (repoSession != null) { getClient().releaseRepository(repoSession); @@ -200,8 +200,8 @@ public class NuxeoConnectorEmbedded { * @return RepositoryInstance * @throws java.lang.Exception */ - public RepositoryInstance getRepositorySession(RepositoryDomainType repoDomain) throws Exception { - RepositoryInstance repoSession = getClient().openRepository(repoDomain); + public RepositoryInstanceInterface getRepositorySession(RepositoryDomainType repoDomain) throws Exception { + RepositoryInstanceInterface repoSession = getClient().openRepository(repoDomain); if (logger.isDebugEnabled() && repoSession != null) { logger.debug("getRepositorySession() opened repository session"); @@ -288,7 +288,7 @@ public class NuxeoConnectorEmbedded { */ public Hashtable retrieveWorkspaceIds(RepositoryDomainType repoDomain) throws Exception { - RepositoryInstance repoSession = null; + RepositoryInstanceInterface repoSession = null; Hashtable workspaceIds = new Hashtable(); try { repoSession = getRepositorySession(repoDomain); diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoConnectorRemote.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoConnectorRemote.java deleted file mode 100644 index bada25bd7..000000000 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoConnectorRemote.java +++ /dev/null @@ -1,263 +0,0 @@ -package org.collectionspace.services.nuxeo.client.java; - -import java.io.File; -import java.util.Collection; -import java.util.Hashtable; -import java.util.Iterator; - -import org.collectionspace.services.config.RepositoryClientConfigType; -import org.nuxeo.ecm.core.api.CoreInstance; -import org.nuxeo.ecm.core.api.DocumentModel; -import org.nuxeo.ecm.core.api.DocumentModelList; -import org.nuxeo.ecm.core.api.repository.Repository; -import org.nuxeo.ecm.core.api.repository.RepositoryInstance; -import org.nuxeo.ecm.core.api.repository.RepositoryManager; -import org.nuxeo.ecm.core.client.DefaultLoginHandler; -import org.nuxeo.ecm.core.client.NuxeoApp; -import org.nuxeo.ecm.core.client.NuxeoClient; -import org.nuxeo.osgi.application.FrameworkBootstrap; -import org.nuxeo.runtime.api.Framework; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class NuxeoConnectorRemote { - public FrameworkBootstrap fb; - public final static String NUXEO_CLIENT_DIR = "nuxeo-client"; - private Logger logger = LoggerFactory.getLogger(NuxeoConnectorRemote.class); - private static final NuxeoConnectorRemote self = new NuxeoConnectorRemote(); - private static final String NUXEO_CLIENT_USERNAME = "NUXEO_CLIENT_USERNAME"; - private static final String NUXEO_CLIENT_PASSWORD = "NUXEO_CLIENT_PASSWORD"; - private NuxeoClient client; - private volatile boolean initialized = false; // use volatile for lazy - // initialization in - // singleton - private RepositoryClientConfigType repositoryClientConfig; - - private NuxeoConnectorRemote() { - } - - public final static NuxeoConnectorRemote getInstance() { - return self; - } - - private String getClientUserName( - RepositoryClientConfigType repositoryClientConfig) { - String username = System.getenv(NUXEO_CLIENT_USERNAME); - if (username == null) { - username = repositoryClientConfig.getUser(); - } - return username; - } - - private String getClientPassword( - RepositoryClientConfigType repositoryClientConfig) { - String password = System.getenv(NUXEO_CLIENT_PASSWORD); - if (password == null) { - password = repositoryClientConfig.getPassword(); - } - return password; - } - - private void startNuxeoEP() throws Exception { - String nuxeoHome = "nuxeo-client/"; - String serverRootDir = System.getProperty("jboss.server.home.dir"); - if (serverRootDir == null) { - serverRootDir = "."; // assume server is started from server root, - // e.g. server/cspace - } - File nuxeoHomeDir = new File(serverRootDir + File.separator + nuxeoHome); - logger.info("Loading Nuxeo configuration from: " - + nuxeoHomeDir.getAbsolutePath()); - if (nuxeoHomeDir.exists() == false) { - String msg = "Library bundles requried to deploy Nuxeo client not found: " - + " directory named nuxeo-client with bundles does not exist in " - + serverRootDir; - logger.error(msg); - throw new IllegalStateException(msg); - } - fb = new FrameworkBootstrap(NuxeoConnectorRemote.class.getClassLoader(), - nuxeoHomeDir); - fb.initialize(); - fb.start(); - } - - /** - * release releases resources occupied by Nuxeo remoting client runtime - * - * @throws java.lang.Exception - */ - public void release() throws Exception { - if (initialized == true) { - try { - client.tryDisconnect(); - } catch (Exception e) { - logger.error("Failed to disconnect Nuxeo connection.", e); - throw e; - } - } - } - - public void initialize(RepositoryClientConfigType repositoryClientConfig) - throws Exception { - if (initialized == false) { - synchronized (this) { - if (initialized == false) { - try { - this.repositoryClientConfig = repositoryClientConfig; - startNuxeoEP(); - // client = NuxeoClient.getInstance(); - client = new NuxeoClient(); - String username = getClientUserName(repositoryClientConfig); - String password = getClientPassword(repositoryClientConfig); - DefaultLoginHandler loginHandler = new DefaultLoginHandler( - username, password); - client.setLoginHandler(loginHandler); - client.tryConnect(repositoryClientConfig.getHost(), - repositoryClientConfig.getPort()); - if (logger.isDebugEnabled()) { - logger.debug("initialize(): connection successful port=" - + repositoryClientConfig.getPort()); - } - initialized = true; - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception while initializing", - e); - } - } - } - } - } - } - - /** - * releaseRepositorySession releases given repository session - * - * @param repoSession - * @throws java.lang.Exception - */ - public void releaseRepositorySession(RepositoryInstance repoSession) - throws Exception { - if (repoSession != null) { - getClient().releaseRepository(repoSession); - - if (logger.isDebugEnabled()) { - logger.debug("releaseRepositorySession() released repository session"); - } - } - } - - /** - * getRepositorySession get session to default repository - * - * @return RepositoryInstance - * @throws java.lang.Exception - */ - public RepositoryInstance getRepositorySession() throws Exception { - RepositoryInstance repoSession = getClient().openRepository(); - if (logger.isDebugEnabled()) { - logger.debug("getRepositorySession() opened repository session"); - } - return repoSession; - - // Repository repository = - // Framework.getService(RepositoryManager.class).getDefaultRepository(); - // session = repository.open(); - - } - - /** - * getClient get Nuxeo client for accessing Nuxeo services remotely using - * Nuxeo Java (EJB) Remote APIS - * - * @return NuxeoClient - * @throws java.lang.Exception - */ - public NuxeoClient getClient() throws Exception { - if (initialized == true) { - if (client.isConnected()) { - client.login(); - return client; - } else { - client.forceConnect(repositoryClientConfig.getHost(), - repositoryClientConfig.getPort()); - if (logger.isDebugEnabled()) { - logger.debug("getClient(): connection successful port=" - + repositoryClientConfig.getPort()); - } - return client; - } - } - String msg = "NuxeoConnector is not initialized!"; - logger.error(msg); - throw new IllegalStateException(msg); - } - - /** - * retrieveWorkspaceIds retrieves all workspace ids from default repository - * - * @param tenantDomain - * domain representing tenant - * @return - * @throws java.lang.Exception - */ - public Hashtable retrieveWorkspaceIds(String tenantDomain) - throws Exception { - RepositoryInstance repoSession = null; - Hashtable workspaceIds = new Hashtable(); - try { - repoSession = getRepositorySession(); - DocumentModel rootDoc = repoSession.getRootDocument(); - DocumentModelList rootChildrenList = repoSession - .getChildren(rootDoc.getRef()); - Iterator diter = rootChildrenList.iterator(); - while (diter.hasNext()) { - DocumentModel domain = diter.next(); - String domainPath = "/" + tenantDomain; - if (!domain.getPathAsString().equalsIgnoreCase(domainPath)) { - continue; - } - if (logger.isDebugEnabled()) { - logger.debug("domain=" + domain.toString()); - } - DocumentModelList domainChildrenList = repoSession - .getChildren(domain.getRef()); - Iterator witer = domainChildrenList.iterator(); - while (witer.hasNext()) { - DocumentModel childNode = witer.next(); - if ("Workspaces".equalsIgnoreCase(childNode.getName())) { - DocumentModelList workspaceList = repoSession - .getChildren(childNode.getRef()); - Iterator wsiter = workspaceList - .iterator(); - while (wsiter.hasNext()) { - DocumentModel workspace = wsiter.next(); - if (logger.isDebugEnabled()) { - logger.debug("workspace name=" - + workspace.getName() + " id=" - + workspace.getId()); - } - workspaceIds.put(workspace.getName().toLowerCase(), - workspace.getId()); - } - } - } - } - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("retrieveWorkspaceIds() caught exception ", e); - } - throw e; - } finally { - if (repoSession != null) { - releaseRepositorySession(repoSession); - } - } - return workspaceIds; - } - - @Deprecated - private void loadBundles() throws Exception { - } - -} 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 1cbbb33c2..6cc3b95a0 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 @@ -619,7 +619,7 @@ public abstract class RemoteDocumentModelHandlerImpl boolean releaseRepoSession = false; ServiceContext ctx = this.getServiceContext(); RepositoryJavaClientImpl repoClient = (RepositoryJavaClientImpl)this.getRepositoryClient(ctx); - RepositoryInstance repoSession = this.getRepositorySession(); + RepositoryInstanceInterface repoSession = this.getRepositorySession(); if (repoSession == null) { repoSession = repoClient.getRepositorySession(ctx); releaseRepoSession = true; @@ -1431,7 +1431,7 @@ public abstract class RemoteDocumentModelHandlerImpl if (hasRefNameUpdate() == true) { ServiceContext ctx = getServiceContext(); RepositoryClient repoClient = getRepositoryClient(ctx); - RepositoryInstance repoSession = this.getRepositorySession(); + RepositoryInstanceInterface repoSession = this.getRepositorySession(); // Update all the relationship records that referred to the old refName RefNameServiceUtils.updateRefNamesInRelations(ctx, repoClient, repoSession, diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryInstanceInterface.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryInstanceInterface.java new file mode 100644 index 000000000..2537811a2 --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryInstanceInterface.java @@ -0,0 +1,152 @@ +package org.collectionspace.services.nuxeo.client.java; + +import java.security.Principal; + +import org.nuxeo.ecm.core.api.ClientException; +import org.nuxeo.ecm.core.api.DocumentModel; +import org.nuxeo.ecm.core.api.DocumentModelList; +import org.nuxeo.ecm.core.api.DocumentRef; +import org.nuxeo.ecm.core.api.Filter; +import org.nuxeo.ecm.core.api.IterableQueryResult; +import org.nuxeo.ecm.core.api.event.DocumentEventTypes; +import org.nuxeo.ecm.core.api.repository.RepositoryInstance; + +public interface RepositoryInstanceInterface { + + public RepositoryInstance getRepositoryInstance(); + + /** + * Gets the root document of this repository. + * + * @return the root document. cannot be null + * @throws ClientException + * @throws SecurityException + */ + public DocumentModel getRootDocument() throws ClientException; + + /** + * Gets the current session id. + *

+ * If the client is not connected returns null. + * + * @return the session id or null if not connected + */ + public String getSessionId(); + + /** + * + * @throws Exception + */ + public void close() throws Exception; + + /** + * Returns the repository name against which this core session is bound. + * + * @return the repository name used currently used as an identifier + */ + public String getRepositoryName(); + + /** + * Gets the principal that created the client session. + * + * @return the principal + */ + public Principal getPrincipal(); + + public IterableQueryResult queryAndFetch(String query, String queryType, + Object... params) throws ClientException; + + public DocumentModelList query(String query, Filter filter, long limit, + long offset, boolean countTotal) throws ClientException; + + public DocumentModelList query(String query) throws ClientException; + + /** + * Executes the given NXQL query an returns the result. + * + * @param query the query to execute + * @param max number of document to retrieve + * @return the query result + * @throws ClientException + */ + public DocumentModelList query(String query, int max) throws ClientException; + + /** + * Gets a document model given its reference. + *

+ * The default schemas are used to populate the returned document model. + * Default schemas are configured via the document type manager. + *

+ * Any other data model not part of the default schemas will be lazily + * loaded as needed. + * + * @param docRef the document reference + * @return the document + * @throws ClientException + * @throws SecurityException + */ + public DocumentModel getDocument(DocumentRef docRef) throws ClientException; + + public DocumentModel saveDocument(DocumentModel docModel) throws ClientException; + + public void save() throws ClientException; + + /** + * Bulk document saving. + * + * @param docModels the document models that needs to be saved + * @throws ClientException + */ + public void saveDocuments(DocumentModel[] docModels) throws ClientException; + + /** + * Removes this document and all its children, if any. + * + * @param docRef the reference to the document to remove + * @throws ClientException + */ + public void removeDocument(DocumentRef docRef) throws ClientException; + + /** + * Creates a document model using required information. + *

+ * Used to fetch initial datamodels from the type definition. + *

+ * DocumentModel creation notifies a + * {@link DocumentEventTypes.EMPTY_DOCUMENTMODEL_CREATED} so that core event + * listener can initialize its content with computed properties. + * + * @param parentPath + * @param id + * @param typeName + * @return the initial document model + * @throws ClientException + */ + public DocumentModel createDocumentModel(String parentPath, String id, + String typeName) throws ClientException; + + /** + * Creates a document using given document model for initialization. + *

+ * The model contains path of the new document, its type and optionally the + * initial data models of the document. + *

+ * + * @param model the document model to use for initialization + * @return the created document + * @throws ClientException + */ + public DocumentModel createDocument(DocumentModel model) throws ClientException; + + /** + * Gets the children of the given parent. + * + * @param parent the parent reference + * @return the children if any, an empty list if no children or null if the + * specified parent document is not a folder + * @throws ClientException + */ + public DocumentModelList getChildren(DocumentRef parent) throws ClientException; + + +} diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryInstanceWrapper.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryInstanceWrapper.java new file mode 100644 index 000000000..797805a0e --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryInstanceWrapper.java @@ -0,0 +1,197 @@ +package org.collectionspace.services.nuxeo.client.java; + +import java.security.Principal; + +import org.nuxeo.ecm.core.api.ClientException; +import org.nuxeo.ecm.core.api.DocumentModel; +import org.nuxeo.ecm.core.api.DocumentModelList; +import org.nuxeo.ecm.core.api.DocumentRef; +import org.nuxeo.ecm.core.api.Filter; +import org.nuxeo.ecm.core.api.IterableQueryResult; +import org.nuxeo.ecm.core.api.NoRollbackOnException; +import org.nuxeo.ecm.core.api.event.DocumentEventTypes; +import org.nuxeo.ecm.core.api.repository.RepositoryInstance; + +public class RepositoryInstanceWrapper implements RepositoryInstanceInterface { + + private RepositoryInstance repoSession; + + public RepositoryInstanceWrapper(RepositoryInstance repoSession) { + this.repoSession = repoSession; + } + + @Override + public RepositoryInstance getRepositoryInstance() { + return repoSession; + } + + @Override + public String getSessionId() { + return repoSession.getSessionId(); + } + + @Override + public void close() throws Exception { + repoSession.close(); + } + + /** + * Gets the root document of this repository. + * + * @return the root document. cannot be null + * @throws ClientException + * @throws SecurityException + */ + @Override + public DocumentModel getRootDocument() throws ClientException { + return repoSession.getRootDocument(); + } + + /** + * Returns the repository name against which this core session is bound. + * + * @return the repository name used currently used as an identifier + */ + @Override + public String getRepositoryName() { + return repoSession.getRepositoryName(); + } + + /** + * Gets the principal that created the client session. + * + * @return the principal + */ + @Override + public Principal getPrincipal() { + return repoSession.getPrincipal(); + } + + @Override + public IterableQueryResult queryAndFetch(String query, String queryType, + Object... params) throws ClientException { + return repoSession.queryAndFetch(query, queryType, params); + } + + @Override + public DocumentModelList query(String query, Filter filter, long limit, + long offset, boolean countTotal) throws ClientException { + return repoSession.query(query, filter, limit, offset, countTotal); + } + + @Override + public DocumentModelList query(String query, int max) throws ClientException { + return repoSession.query(query, max); + } + + @Override + public DocumentModelList query(String query) throws ClientException { + return repoSession.query(query); + } + + /** + * Gets a document model given its reference. + *

+ * The default schemas are used to populate the returned document model. + * Default schemas are configured via the document type manager. + *

+ * Any other data model not part of the default schemas will be lazily + * loaded as needed. + * + * @param docRef the document reference + * @return the document + * @throws ClientException + * @throws SecurityException + */ + @NoRollbackOnException + @Override + public DocumentModel getDocument(DocumentRef docRef) throws ClientException { + return repoSession.getDocument(docRef); + } + + @Override + public DocumentModel saveDocument(DocumentModel docModel) throws ClientException { + return repoSession.saveDocument(docModel); + } + + @Override + public void save() throws ClientException { + repoSession.save(); + } + + /** + * Bulk document saving. + * + * @param docModels the document models that needs to be saved + * @throws ClientException + */ + @Override + public void saveDocuments(DocumentModel[] docModels) throws ClientException { + repoSession.saveDocuments(docModels); + } + + /** + * Removes this document and all its children, if any. + * + * @param docRef the reference to the document to remove + * @throws ClientException + */ + @Override + public void removeDocument(DocumentRef docRef) throws ClientException { + repoSession.removeDocument(docRef); + } + + /** + * Creates a document model using required information. + *

+ * Used to fetch initial datamodels from the type definition. + *

+ * DocumentModel creation notifies a + * {@link DocumentEventTypes.EMPTY_DOCUMENTMODEL_CREATED} so that core event + * listener can initialize its content with computed properties. + * + * @param parentPath + * @param id + * @param typeName + * @return the initial document model + * @throws ClientException + */ + @Override + public DocumentModel createDocumentModel(String parentPath, String id, + String typeName) throws ClientException { + return repoSession.createDocumentModel(parentPath, id, typeName); + } + + /** + * Creates a document using given document model for initialization. + *

+ * The model contains path of the new document, its type and optionally the + * initial data models of the document. + *

+ * + * @param model the document model to use for initialization + * @return the created document + * @throws ClientException + */ + @Override + public DocumentModel createDocument(DocumentModel model) throws ClientException { + return repoSession.createDocument(model); + } + + /** + * Gets the children of the given parent. + * + * @param parent the parent reference + * @return the children if any, an empty list if no children or null if the + * specified parent document is not a folder + * @throws ClientException + */ + @NoRollbackOnException + @Override + public DocumentModelList getChildren(DocumentRef parent) throws ClientException { + return repoSession.getChildren(parent); + } + + + +} 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 86bcd01f7..4af1eeca5 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 @@ -55,6 +55,7 @@ import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.common.document.DocumentWrapperImpl; import org.collectionspace.services.common.document.TransactionException; import org.collectionspace.services.config.tenant.RepositoryDomainType; + import org.nuxeo.common.utils.IdUtils; import org.nuxeo.ecm.core.api.ClientException; import org.nuxeo.ecm.core.api.DocumentModel; @@ -65,7 +66,6 @@ import org.nuxeo.ecm.core.api.impl.DocumentModelListImpl; import org.nuxeo.ecm.core.api.DocumentRef; 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.runtime.transaction.TransactionRuntimeException; // @@ -95,7 +95,7 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: $ $LastChangedDate: $ */ public class RepositoryJavaClientImpl implements RepositoryClient { - + /** * The logger. */ @@ -174,7 +174,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient getDoc( - RepositoryInstance repoSession, + RepositoryInstanceInterface repoSession, ServiceContext ctx, String csid) throws DocumentNotFoundException, DocumentException { DocumentWrapper wrapDoc = null; @@ -367,7 +367,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient getDoc( ServiceContext ctx, String csid) throws DocumentNotFoundException, TransactionException, DocumentException { - RepositoryInstance repoSession = null; + RepositoryInstanceInterface repoSession = null; DocumentWrapper wrapDoc = null; try { @@ -396,7 +396,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient findDoc( - RepositoryInstance repoSession, + RepositoryInstanceInterface repoSession, ServiceContext ctx, String whereClause) throws DocumentNotFoundException, DocumentException { @@ -450,7 +450,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient ctx, String whereClause) throws DocumentNotFoundException, TransactionException, DocumentException { - RepositoryInstance repoSession = null; + RepositoryInstanceInterface repoSession = null; DocumentWrapper wrapDoc = null; try { @@ -483,7 +483,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient ctx, String whereClause) throws DocumentNotFoundException, TransactionException, DocumentException { String csid = null; @@ -517,7 +517,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient findDocs( ServiceContext ctx, - RepositoryInstance repoSession, + RepositoryInstanceInterface repoSession, List docTypes, String whereClause, String orderByClause, @@ -573,7 +573,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient findDocs( ServiceContext ctx, DocumentHandler handler, - RepositoryInstance repoSession, + RepositoryInstanceInterface repoSession, List docTypes) throws DocumentNotFoundException, DocumentException { DocumentWrapper wrapDoc = null; @@ -632,7 +632,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient wrapDoc = null; try { @@ -670,7 +670,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient getDocFromCsid( ServiceContext ctx, - RepositoryInstance repoSession, + RepositoryInstanceInterface repoSession, String csid) throws Exception { DocumentWrapper result = null; @@ -784,7 +784,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient result = null; - RepositoryInstance repoSession = null; + RepositoryInstanceInterface repoSession = null; try { repoSession = getRepositorySession(ctx); result = getDocFromCsid(ctx, repoSession, csid); @@ -819,7 +819,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient ctx, - RepositoryInstance repoSession, + RepositoryInstanceInterface repoSession, DocumentModel docModel, boolean fSaveSession) throws ClientException, DocumentException { @@ -1418,7 +1418,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient ctx, - RepositoryInstance repoSession, + RepositoryInstanceInterface repoSession, DocumentModelList docList, boolean fSaveSession) throws ClientException, DocumentException { @@ -1457,7 +1457,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient ctx, - RepositoryInstance repoSession, + RepositoryInstanceInterface repoSession, String csid) throws Exception { DocumentModel result = null; @@ -623,7 +621,7 @@ public class NuxeoUtils { return id; } - public static boolean documentExists(RepositoryInstance repoSession, + public static boolean documentExists(RepositoryInstanceInterface repoSession, String csid) throws ClientException { boolean result = false; diff --git a/services/config/.gitignore b/services/config/.gitignore new file mode 100644 index 000000000..19f2e002c --- /dev/null +++ b/services/config/.gitignore @@ -0,0 +1,2 @@ +/target +/target diff --git a/services/hyperjaxb/.gitignore b/services/hyperjaxb/.gitignore new file mode 100644 index 000000000..ea8c4bf7f --- /dev/null +++ b/services/hyperjaxb/.gitignore @@ -0,0 +1 @@ +/target diff --git a/services/imports/service/src/main/java/org/collectionspace/services/imports/nuxeo/ImportCommand.java b/services/imports/service/src/main/java/org/collectionspace/services/imports/nuxeo/ImportCommand.java index 53d39f0f9..32d6dc5c3 100644 --- a/services/imports/service/src/main/java/org/collectionspace/services/imports/nuxeo/ImportCommand.java +++ b/services/imports/service/src/main/java/org/collectionspace/services/imports/nuxeo/ImportCommand.java @@ -5,9 +5,11 @@ import java.util.Calendar; import java.util.HashMap; import java.util.Map; import java.util.TreeSet; + import org.collectionspace.services.common.api.Tools; import org.collectionspace.services.nuxeo.client.java.NuxeoClientEmbedded; import org.collectionspace.services.nuxeo.client.java.NuxeoConnectorEmbedded; +import org.collectionspace.services.nuxeo.client.java.RepositoryInstanceInterface; import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.DocumentRef; import org.nuxeo.ecm.core.api.repository.RepositoryInstance; @@ -30,7 +32,7 @@ public class ImportCommand { File file = new File(src); ///cspace way of configuring client and auth: NuxeoClientEmbedded client = NuxeoConnectorEmbedded.getInstance().getClient(); - RepositoryInstance repoSession = null; + RepositoryInstanceInterface repoSession = null; try { repoSession = client.openRepository(repoName, timeOut); if (logger.isDebugEnabled()) { @@ -49,7 +51,7 @@ public class ImportCommand { } } - String importTree(RepositoryInstance repoSession, File file, String toPath) throws Exception { + String importTree(RepositoryInstanceInterface repoSession, File file, String toPath) throws Exception { Exception failed = null; DocumentReader reader = null; DocumentWriter writer = null; @@ -65,7 +67,7 @@ public class ImportCommand { logger.info("importTree reading file: " + file + (file != null ? " exists? " + file.exists() : " file param is null")); } reader = new LoggedXMLDirectoryReader(file); //our overload of XMLDirectoryReader. - writer = new DocumentModelWriter(repoSession, toPath, 10); + writer = new DocumentModelWriter(repoSession.getRepositoryInstance(), toPath, 10); DocumentPipe pipe = new DocumentPipeImpl(10); // pipe.addTransformer(transformer); pipe.setReader(reader); diff --git a/services/jaxb/.gitignore b/services/jaxb/.gitignore new file mode 100644 index 000000000..ea8c4bf7f --- /dev/null +++ b/services/jaxb/.gitignore @@ -0,0 +1 @@ +/target diff --git a/services/movement/jaxb/.gitignore b/services/movement/jaxb/.gitignore new file mode 100644 index 000000000..ea8c4bf7f --- /dev/null +++ b/services/movement/jaxb/.gitignore @@ -0,0 +1 @@ +/target diff --git a/services/objectexit/jaxb/.gitignore b/services/objectexit/jaxb/.gitignore new file mode 100644 index 000000000..ea8c4bf7f --- /dev/null +++ b/services/objectexit/jaxb/.gitignore @@ -0,0 +1 @@ +/target diff --git a/services/organization/jaxb/.gitignore b/services/organization/jaxb/.gitignore new file mode 100644 index 000000000..ea8c4bf7f --- /dev/null +++ b/services/organization/jaxb/.gitignore @@ -0,0 +1 @@ +/target 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 8f82b6e0a..2d34e46ba 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 @@ -60,9 +60,9 @@ import org.collectionspace.services.client.PlaceAuthorityClient; import org.collectionspace.services.client.WorkAuthorityClient; import org.collectionspace.services.client.ConceptAuthorityClient; import org.collectionspace.services.client.workflow.WorkflowClient; - import org.collectionspace.services.config.service.ServiceBindingType; import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; +import org.collectionspace.services.nuxeo.client.java.RepositoryInstanceInterface; import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl; import org.nuxeo.ecm.core.api.ClientException; import org.nuxeo.ecm.core.api.DocumentModel; @@ -101,7 +101,7 @@ public class RelationDocumentModelHandler DocumentModel relationDocModel = wrapDoc.getWrappedObject(); String errMsg = ERROR_TERMS_IN_WORKFLOWSTATE + workflowState; - RepositoryInstance repoSession = this.getRepositorySession(); + RepositoryInstanceInterface repoSession = this.getRepositorySession(); try { DocumentModel subjectDocModel = getSubjectOrObjectDocModel(repoSession, relationDocModel, SUBJ_DOC_MODEL); DocumentModel objectDocModel = getSubjectOrObjectDocModel(repoSession, relationDocModel, OBJ_DOC_MODEL); @@ -178,7 +178,7 @@ public class RelationDocumentModelHandler // Note that this introduces another caching problem... DocumentModel relationDocModel = wrapDoc.getWrappedObject(); ServiceContext ctx = this.getServiceContext(); - RepositoryInstance repoSession = this.getRepositorySession(); + RepositoryInstanceInterface repoSession = this.getRepositorySession(); DocumentModel subjectDocModel = getSubjectOrObjectDocModel(repoSession, relationDocModel, SUBJ_DOC_MODEL); DocumentModel objectDocModel = getSubjectOrObjectDocModel(repoSession, relationDocModel, OBJ_DOC_MODEL); @@ -376,7 +376,7 @@ public class RelationDocumentModelHandler private final boolean OBJ_DOC_MODEL = false; private DocumentModel getSubjectOrObjectDocModel( - RepositoryInstance repoSession, + RepositoryInstanceInterface repoSession, DocumentModel relationDocModel, boolean fSubject) throws Exception { ServiceContext ctx = this.getServiceContext(); diff --git a/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java b/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java index 104f33d68..ecd7764db 100644 --- a/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java +++ b/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java @@ -78,6 +78,7 @@ import org.collectionspace.services.common.invocable.InvocationContext; import org.collectionspace.services.common.storage.JDBCTools; import org.collectionspace.services.jaxb.InvocableJAXBSchema; import org.collectionspace.services.nuxeo.client.java.DocHandlerBase; +import org.collectionspace.services.nuxeo.client.java.RepositoryInstanceInterface; import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl; import org.jfree.util.Log; import org.nuxeo.ecm.core.api.DocumentModel; @@ -108,7 +109,7 @@ public class ReportDocumentModelHandler extends DocHandlerBase { InvocationContext invContext, StringBuffer outMimeType, StringBuffer outReportFileName) throws Exception { - RepositoryInstance repoSession = null; + RepositoryInstanceInterface repoSession = null; boolean releaseRepoSession = false; String invocationMode = invContext.getMode(); 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 874ad0995..257dc729a 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 @@ -35,6 +35,7 @@ import javax.ws.rs.core.Response; import org.collectionspace.services.ServiceGroupListItemJAXBSchema; import org.collectionspace.services.nuxeo.client.java.CommonList; import org.collectionspace.services.nuxeo.client.java.DocHandlerBase; +import org.collectionspace.services.nuxeo.client.java.RepositoryInstanceInterface; import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl; import org.collectionspace.services.nuxeo.util.NuxeoUtils; import org.collectionspace.services.jaxb.AbstractCommonList; @@ -84,7 +85,7 @@ public class ServiceGroupDocumentModelHandler List serviceGroupNames) throws Exception { CommonList commonList = new CommonList(); AbstractCommonList list = (AbstractCommonList)commonList; - RepositoryInstance repoSession = null; + RepositoryInstanceInterface repoSession = null; boolean releaseRepoSession = false; try { diff --git a/services/taxonomy/jaxb/.gitignore b/services/taxonomy/jaxb/.gitignore new file mode 100644 index 000000000..ea8c4bf7f --- /dev/null +++ b/services/taxonomy/jaxb/.gitignore @@ -0,0 +1 @@ +/target diff --git a/services/vocabulary/jaxb/.gitignore b/services/vocabulary/jaxb/.gitignore new file mode 100644 index 000000000..ea8c4bf7f --- /dev/null +++ b/services/vocabulary/jaxb/.gitignore @@ -0,0 +1 @@ +/target