From 962141bad08e93cd64fc78e46a00c71a42e97938 Mon Sep 17 00:00:00 2001 From: Sanjay Dalal Date: Mon, 16 Nov 2009 23:33:04 +0000 Subject: [PATCH] NOJIRA refactoring of DocumentWrapper. It is now a generic type. Does not require creating derived types. M services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectDocumentModelHandler.java M services/common/src/main/java/org/collectionspace/services/common/document/DocumentWrapper.java M services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandler.java A services/common/src/main/java/org/collectionspace/services/common/document/DocumentWrapperImpl.java M services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java D services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelWrapper.java M services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClient.java M services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandler.java D services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelListWrapper.java M services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java M services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/nuxeo/AcquisitionDocumentModelHandler.java M services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyDocumentModelHandler.java _M services/vocabulary/import M services/intake/service/src/main/java/org/collectionspace/services/intake/nuxeo/IntakeDocumentModelHandler.java M services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java --- .../AcquisitionDocumentModelHandler.java | 15 ++-- .../CollectionObjectDocumentModelHandler.java | 14 ++-- .../document/AbstractDocumentHandler.java | 40 +++++------ .../common/document/DocumentHandler.java | 28 ++++---- .../common/document/DocumentWrapper.java | 4 +- .../document/DocumentWrapperImpl.java} | 29 +++----- .../client/java/DocumentModelHandler.java | 24 ++++--- .../client/java/DocumentModelListWrapper.java | 49 ------------- .../java/RemoteDocumentModelHandler.java | 12 ++-- .../client/java/RepositoryJavaClient.java | 69 +++++++++---------- .../nuxeo/IntakeDocumentModelHandler.java | 8 +-- .../nuxeo/RelationDocumentModelHandler.java | 14 ++-- .../nuxeo/VocabularyDocumentModelHandler.java | 8 +-- 13 files changed, 126 insertions(+), 188 deletions(-) rename services/common/src/main/java/org/collectionspace/services/{nuxeo/client/java/DocumentModelWrapper.java => common/document/DocumentWrapperImpl.java} (62%) delete mode 100644 services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelListWrapper.java diff --git a/services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/nuxeo/AcquisitionDocumentModelHandler.java b/services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/nuxeo/AcquisitionDocumentModelHandler.java index 2ffea0a22..a86fdb849 100644 --- a/services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/nuxeo/AcquisitionDocumentModelHandler.java +++ b/services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/nuxeo/AcquisitionDocumentModelHandler.java @@ -99,20 +99,19 @@ public class AcquisitionDocumentModelHandler } @Override - public AcquisitionsCommon extractCommonPart(DocumentWrapper wrapDoc) + public AcquisitionsCommon extractCommonPart(DocumentWrapper wrapDoc) throws Exception { throw new UnsupportedOperationException(); } @Override - public void fillCommonPart(AcquisitionsCommon acquisitionObject, DocumentWrapper wrapDoc) throws Exception { + public void fillCommonPart(AcquisitionsCommon acquisitionObject, DocumentWrapper wrapDoc) throws Exception { throw new UnsupportedOperationException(); } @Override - public AcquisitionsCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception { - DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject(); - + public AcquisitionsCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception { + DocumentModelList docList = wrapDoc.getWrappedObject(); AcquisitionsCommonList coList = new AcquisitionsCommonList(); List list = coList.getAcquisitionListItem(); @@ -135,14 +134,14 @@ public class AcquisitionDocumentModelHandler } @Override - public void fillAllParts(DocumentWrapper wrapDoc) throws Exception { + public void fillAllParts(DocumentWrapper wrapDoc) throws Exception { super.fillAllParts(wrapDoc); fillDublinCoreObject(wrapDoc); //dublincore might not be needed in future } - private void fillDublinCoreObject(DocumentWrapper wrapDoc) throws Exception { - DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject(); + private void fillDublinCoreObject(DocumentWrapper wrapDoc) throws Exception { + DocumentModel docModel = wrapDoc.getWrappedObject(); //FIXME property setter should be dynamically set using schema inspection //so it does not require hard coding // a default title for the Dublin Core schema diff --git a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectDocumentModelHandler.java b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectDocumentModelHandler.java index eea06dde5..f57c35630 100644 --- a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectDocumentModelHandler.java +++ b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectDocumentModelHandler.java @@ -92,19 +92,19 @@ public class CollectionObjectDocumentModelHandler } @Override - public CollectionobjectsCommon extractCommonPart(DocumentWrapper wrapDoc) + public CollectionobjectsCommon extractCommonPart(DocumentWrapper wrapDoc) throws Exception { throw new UnsupportedOperationException(); } @Override - public void fillCommonPart(CollectionobjectsCommon co, DocumentWrapper wrapDoc) throws Exception { + public void fillCommonPart(CollectionobjectsCommon co, DocumentWrapper wrapDoc) throws Exception { throw new UnsupportedOperationException(); } @Override - public CollectionobjectsCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception { - DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject(); + public CollectionobjectsCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception { + DocumentModelList docList = wrapDoc.getWrappedObject(); CollectionobjectsCommonList coList = new CollectionobjectsCommonList(); List list = coList.getCollectionObjectListItem(); @@ -127,14 +127,14 @@ public class CollectionObjectDocumentModelHandler } @Override - public void fillAllParts(DocumentWrapper wrapDoc) throws Exception { + public void fillAllParts(DocumentWrapper wrapDoc) throws Exception { super.fillAllParts(wrapDoc); fillDublinCoreObject(wrapDoc); //dublincore might not be needed in future } - private void fillDublinCoreObject(DocumentWrapper wrapDoc) throws Exception { - DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject(); + private void fillDublinCoreObject(DocumentWrapper wrapDoc) throws Exception { + DocumentModel docModel = wrapDoc.getWrappedObject(); //FIXME property setter should be dynamically set using schema inspection //so it does not require hard coding // a default title for the Dublin Core schema diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandler.java b/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandler.java index 4dbab9200..bb9690a1b 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandler.java @@ -38,8 +38,8 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: $ * $LastChangedDate: $ */ -public abstract class AbstractDocumentHandler - implements DocumentHandler { +public abstract class AbstractDocumentHandler + implements DocumentHandler { private final Logger logger = LoggerFactory.getLogger(AbstractDocumentHandler.class); private Map properties = new HashMap(); @@ -97,76 +97,76 @@ public abstract class AbstractDocumentHandler } @Override - public void handle(Action action, DocumentWrapper wrapDoc) throws Exception { + public void handle(Action action, DocumentWrapper wrapDoc) throws Exception { switch(action){ case CREATE: - handleCreate(wrapDoc); + handleCreate((DocumentWrapper)wrapDoc); break; case UPDATE: - handleUpdate(wrapDoc); + handleUpdate((DocumentWrapper)wrapDoc); break; case GET: - handleGet(wrapDoc); + handleGet((DocumentWrapper)wrapDoc); break; case GET_ALL: - handleGetAll(wrapDoc); + handleGetAll((DocumentWrapper)wrapDoc); break; } } @Override - public abstract void handleCreate(DocumentWrapper wrapDoc) throws Exception; + public abstract void handleCreate(DocumentWrapper wrapDoc) throws Exception; @Override - public abstract void handleUpdate(DocumentWrapper wrapDoc) throws Exception; + public abstract void handleUpdate(DocumentWrapper wrapDoc) throws Exception; @Override - public abstract void handleGet(DocumentWrapper wrapDoc) throws Exception; + public abstract void handleGet(DocumentWrapper wrapDoc) throws Exception; @Override - public abstract void handleGetAll(DocumentWrapper wrapDoc) throws Exception; + public abstract void handleGetAll(DocumentWrapper wrapDoc) throws Exception; @Override - public void complete(Action action, DocumentWrapper wrapDoc) throws Exception { + public void complete(Action action, DocumentWrapper wrapDoc) throws Exception { switch(action){ //TODO: add more actions if needed case UPDATE: - completeUpdate(wrapDoc); + completeUpdate((DocumentWrapper)wrapDoc); break; } } @Override - public void completeUpdate(DocumentWrapper wrapDoc) throws Exception { + public void completeUpdate(DocumentWrapper wrapDoc) throws Exception { //no specific action needed } @Override - public abstract void extractAllParts(DocumentWrapper wrapDoc) + public abstract void extractAllParts(DocumentWrapper wrapDoc) throws Exception; @Override - public abstract void fillAllParts(DocumentWrapper wrapDoc) + public abstract void fillAllParts(DocumentWrapper wrapDoc) throws Exception; @Override - public abstract T extractCommonPart(DocumentWrapper wrapDoc) + public abstract T extractCommonPart(DocumentWrapper wrapDoc) throws Exception; @Override - public abstract void fillCommonPart(T obj, DocumentWrapper wrapDoc) + public abstract void fillCommonPart(T obj, DocumentWrapper wrapDoc) throws Exception; @Override - public abstract TL extractCommonPartList(DocumentWrapper wrapDoc) + public abstract TL extractCommonPartList(DocumentWrapper wrapDoc) throws Exception; @Override - final public void fillCommonPartList(TL obj, DocumentWrapper wrapDoc) throws Exception { + final public void fillCommonPartList(TL obj, DocumentWrapper wrapDoc) throws Exception { throw new UnsupportedOperationException("bulk create/update not yet supported"); } diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java index 0972256bc..5fbda3564 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java @@ -33,7 +33,7 @@ import org.collectionspace.services.common.context.ServiceContext; * The repository client then calls handle on the handler * */ -public interface DocumentHandler { +public interface DocumentHandler { public enum Action { @@ -73,35 +73,35 @@ public interface DocumentHandler { * @param doc wrapped doc * @throws Exception */ - public void handle(Action action, DocumentWrapper docWrap) throws Exception; + public void handle(Action action, DocumentWrapper docWrap) throws Exception; /** * handleCreate processes documents before creating document in repository * @param wrapDoc * @throws Exception */ - public void handleCreate(DocumentWrapper wrapDoc) throws Exception; + public void handleCreate(DocumentWrapper wrapDoc) throws Exception; /** * handleUpdate processes documents for the update of document in repository * @param wrapDoc * @throws Exception */ - public void handleUpdate(DocumentWrapper wrapDoc) throws Exception; + public void handleUpdate(DocumentWrapper wrapDoc) throws Exception; /** * handleGet processes documents from repository before responding to consumer * @param wrapDoc * @throws Exception */ - public void handleGet(DocumentWrapper wrapDoc) throws Exception; + public void handleGet(DocumentWrapper wrapDoc) throws Exception; /** * handleGetAll processes documents from repository before responding to consumer * @param wrapDoc * @throws Exception */ - public void handleGetAll(DocumentWrapper wrapDoc) throws Exception; + public void handleGetAll(DocumentWrapper wrapDoc) throws Exception; /** * complete is called by the client to provide an opportunity to the handler @@ -110,7 +110,7 @@ public interface DocumentHandler { * @param wrapDoc * @throws Exception */ - public void complete(Action action, DocumentWrapper wrapDoc) throws Exception; + public void complete(Action action, DocumentWrapper wrapDoc) throws Exception; /** * completeUpdate is called by the client to indicate completion of the update call. @@ -118,7 +118,7 @@ public interface DocumentHandler { * @param wrapDoc * @throws Exception */ - public void completeUpdate(DocumentWrapper wrapDoc) throws Exception; + public void completeUpdate(DocumentWrapper wrapDoc) throws Exception; /** * extractAllParts extracts all parts of a CS object from given document. @@ -127,7 +127,7 @@ public interface DocumentHandler { * @param docWrap document * @throws Exception */ - public void extractAllParts(DocumentWrapper docWrap) throws Exception; + public void extractAllParts(DocumentWrapper docWrap) throws Exception; /** * fillAllParts sets parts of CS object into given document @@ -137,7 +137,7 @@ public interface DocumentHandler { * @param docWrap target document * @throws Exception */ - public void fillAllParts(DocumentWrapper docWrap) throws Exception; + public void fillAllParts(DocumentWrapper docWrap) throws Exception; /** * extractCommonPart extracts common part of a CS object from given document. @@ -147,7 +147,7 @@ public interface DocumentHandler { * @return common part of CS object * @throws Exception */ - public T extractCommonPart(DocumentWrapper docWrap) throws Exception; + public T extractCommonPart(DocumentWrapper docWrap) throws Exception; /** * fillCommonPart sets common part of CS object into given document @@ -157,7 +157,7 @@ public interface DocumentHandler { * @param docWrap target document * @throws Exception */ - public void fillCommonPart(T obj, DocumentWrapper docWrap) throws Exception; + public void fillCommonPart(T obj, DocumentWrapper docWrap) throws Exception; /** * extractCommonPart extracts common part of a CS object from given document. @@ -167,7 +167,7 @@ public interface DocumentHandler { * @return common part of CS object * @throws Exception */ - public TL extractCommonPartList(DocumentWrapper docWrap) throws Exception; + public TL extractCommonPartList(DocumentWrapper docWrap) throws Exception; /** * fillCommonPartList sets list common part of CS object into given document @@ -177,7 +177,7 @@ public interface DocumentHandler { * @param docWrap target document * @throws Exception */ - public void fillCommonPartList(TL obj, DocumentWrapper docWrap) throws Exception; + public void fillCommonPartList(TL obj, DocumentWrapper docWrap) throws Exception; /** diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentWrapper.java b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentWrapper.java index 76e0d3a5b..b5ca45f1e 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentWrapper.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentWrapper.java @@ -29,12 +29,12 @@ package org.collectionspace.services.common.document; * DocumentWrapper wraps DocumentModel (java) or Representation (REST) * */ -public interface DocumentWrapper { +public interface DocumentWrapper { /** * getWrappedObject * @return wrapped object */ - public Object getWrappedObject(); + public T getWrappedObject(); } diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelWrapper.java b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentWrapperImpl.java similarity index 62% rename from services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelWrapper.java rename to services/common/src/main/java/org/collectionspace/services/common/document/DocumentWrapperImpl.java index d12a93202..e3083b79e 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelWrapper.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentWrapperImpl.java @@ -22,28 +22,17 @@ * limitations under the License. */ -package org.collectionspace.services.nuxeo.client.java; +package org.collectionspace.services.common.document; -import org.collectionspace.services.common.document.DocumentWrapper; -import org.nuxeo.ecm.core.api.DocumentModel; +public class DocumentWrapperImpl implements DocumentWrapper{ -/** -* DocumentModelWrapper wraps Nuxeo DocumentModel -* -* $LastChangedRevision: $ -* $LastChangedDate: $ -*/ -public class DocumentModelWrapper implements DocumentWrapper { - - private DocumentModel docModel; + private T wrappedObject; - public DocumentModelWrapper(DocumentModel docModel) { - this.docModel = docModel; - } - - @Override - public Object getWrappedObject() { - return docModel; + public DocumentWrapperImpl(T obj) { + this.wrappedObject = obj; } -} + public T getWrappedObject() { + return wrappedObject; + } +} \ No newline at end of file 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 ec5cec310..d929813aa 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 @@ -26,6 +26,8 @@ package org.collectionspace.services.nuxeo.client.java; import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.common.document.AbstractDocumentHandler; import org.collectionspace.services.nuxeo.client.*; +import org.nuxeo.ecm.core.api.DocumentModel; +import org.nuxeo.ecm.core.api.DocumentModelList; import org.nuxeo.ecm.core.api.repository.RepositoryInstance; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,7 +40,7 @@ import org.slf4j.LoggerFactory; * $LastChangedDate: $ */ public abstract class DocumentModelHandler - extends AbstractDocumentHandler { + extends AbstractDocumentHandler { private final Logger logger = LoggerFactory.getLogger(DocumentModelHandler.class); private RepositoryInstance repositorySession; @@ -61,42 +63,42 @@ public abstract class DocumentModelHandler } @Override - public void handleCreate(DocumentWrapper wrapDoc) throws Exception { + public void handleCreate(DocumentWrapper wrapDoc) throws Exception { fillAllParts(wrapDoc); } @Override - public void handleUpdate(DocumentWrapper wrapDoc) throws Exception { + public void handleUpdate(DocumentWrapper wrapDoc) throws Exception { fillAllParts(wrapDoc); } @Override - public void handleGet(DocumentWrapper wrapDoc) throws Exception { + public void handleGet(DocumentWrapper wrapDoc) throws Exception { extractAllParts(wrapDoc); } @Override - public void handleGetAll(DocumentWrapper wrapDoc) throws Exception { + public void handleGetAll(DocumentWrapper wrapDoc) throws Exception { setCommonPartList(extractCommonPartList(wrapDoc)); } @Override - public abstract void completeUpdate(DocumentWrapper wrapDoc) throws Exception; + public abstract void completeUpdate(DocumentWrapper wrapDoc) throws Exception; @Override - public abstract void extractAllParts(DocumentWrapper wrapDoc) throws Exception; + public abstract void extractAllParts(DocumentWrapper wrapDoc) throws Exception; @Override - public abstract T extractCommonPart(DocumentWrapper wrapDoc) throws Exception; + public abstract T extractCommonPart(DocumentWrapper wrapDoc) throws Exception; @Override - public abstract void fillAllParts(DocumentWrapper wrapDoc) throws Exception; + public abstract void fillAllParts(DocumentWrapper wrapDoc) throws Exception; @Override - public abstract void fillCommonPart(T obj, DocumentWrapper wrapDoc) throws Exception; + public abstract void fillCommonPart(T obj, DocumentWrapper wrapDoc) throws Exception; @Override - public abstract TL extractCommonPartList(DocumentWrapper wrapDoc) throws Exception; + public abstract TL extractCommonPartList(DocumentWrapper wrapDoc) throws Exception; @Override public abstract T getCommonPart(); diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelListWrapper.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelListWrapper.java deleted file mode 100644 index c2b0096d1..000000000 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelListWrapper.java +++ /dev/null @@ -1,49 +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 org.collectionspace.services.common.document.DocumentWrapper; -import org.nuxeo.ecm.core.api.DocumentModelList; - -/** -* DocumentModelListWrapper wraps Nuxeo DocumentModel -* -* $LastChangedRevision: $ -* $LastChangedDate: $ -*/ -public class DocumentModelListWrapper implements DocumentWrapper { - - private DocumentModelList docModelList; - - public DocumentModelListWrapper(DocumentModelList docModelList) { - this.docModelList = docModelList; - } - - @Override - public Object getWrappedObject() { - return docModelList; - } - -} diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandler.java index ffb96279f..af09b2427 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandler.java @@ -68,8 +68,8 @@ public abstract class RemoteDocumentModelHandler public abstract String getDocumentType(); @Override - public void completeUpdate(DocumentWrapper wrapDoc) throws Exception { - DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject(); + public void completeUpdate(DocumentWrapper wrapDoc) throws Exception { + DocumentModel docModel = wrapDoc.getWrappedObject(); //return at least those document part(s) that were received Map partsMetaMap = getServiceContext().getPartsMetadata(); RemoteServiceContext ctx = (RemoteServiceContext) getServiceContext(); @@ -82,9 +82,9 @@ public abstract class RemoteDocumentModelHandler } @Override - public void extractAllParts(DocumentWrapper wrapDoc) throws Exception { + public void extractAllParts(DocumentWrapper wrapDoc) throws Exception { - DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject(); + DocumentModel docModel = wrapDoc.getWrappedObject(); String[] schemas = docModel.getDeclaredSchemas(); Map partsMetaMap = getServiceContext().getPartsMetadata(); for(String schema : schemas){ @@ -97,12 +97,12 @@ public abstract class RemoteDocumentModelHandler } @Override - public void fillAllParts(DocumentWrapper wrapDoc) throws Exception { + public void fillAllParts(DocumentWrapper wrapDoc) throws Exception { //TODO filling extension parts should be dynamic //Nuxeo APIs lack to support stream/byte[] input, get/setting properties is //not an ideal way of populating objects. - DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject(); + DocumentModel docModel = wrapDoc.getWrappedObject(); RemoteServiceContext ctx = (RemoteServiceContext) getServiceContext(); MultipartInput input = ctx.getInput(); if(input.getParts().isEmpty()){ diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClient.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClient.java index 1a521eb6b..9ccb51be1 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClient.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClient.java @@ -17,7 +17,6 @@ */ package org.collectionspace.services.nuxeo.client.java; - import java.util.UUID; import org.collectionspace.services.common.context.ServiceContext; @@ -28,6 +27,8 @@ import org.collectionspace.services.common.document.DocumentHandler; import org.collectionspace.services.common.document.DocumentNotFoundException; import org.collectionspace.services.common.repository.RepositoryClient; import org.collectionspace.services.common.document.DocumentHandler.Action; +import org.collectionspace.services.common.document.DocumentWrapper; +import org.collectionspace.services.common.document.DocumentWrapperImpl; import org.collectionspace.services.nuxeo.util.NuxeoUtils; import org.nuxeo.common.utils.IdUtils; import org.nuxeo.ecm.core.api.ClientException; @@ -99,7 +100,7 @@ public class RepositoryJavaClient implements RepositoryClient { DocumentModel doc = repoSession.createDocumentModel(wspacePath, id, ctx.getDocumentType()); ((DocumentModelHandler) handler).setRepositorySession(repoSession); - DocumentModelWrapper wrapDoc = new DocumentModelWrapper(doc); + DocumentWrapper wrapDoc = new DocumentWrapperImpl(doc); handler.handle(Action.CREATE, wrapDoc); // create document with documentmodel doc = repoSession.createDocument(doc); @@ -153,7 +154,7 @@ public class RepositoryJavaClient implements RepositoryClient { } //set reposession to handle the document ((DocumentModelHandler) handler).setRepositorySession(repoSession); - DocumentModelWrapper wrapDoc = new DocumentModelWrapper(doc); + DocumentWrapper wrapDoc = new DocumentWrapperImpl(doc); handler.handle(Action.GET, wrapDoc); handler.complete(Action.GET, wrapDoc); } catch (IllegalArgumentException iae) { @@ -205,8 +206,7 @@ public class RepositoryJavaClient implements RepositoryClient { DocumentModelList docList = repoSession.getChildren(wsDocRef); //set reposession to handle the document ((DocumentModelHandler) handler).setRepositorySession(repoSession); - DocumentModelListWrapper wrapDoc = new DocumentModelListWrapper( - docList); + DocumentWrapper wrapDoc = new DocumentWrapperImpl(docList); handler.handle(Action.GET_ALL, wrapDoc); handler.complete(Action.GET_ALL, wrapDoc); } catch (DocumentException de) { @@ -222,7 +222,7 @@ public class RepositoryJavaClient implements RepositoryClient { } } } - + /** * getFiltered get all documents for an entity service from the Document repository, * given filter parameters specified by the handler. @@ -231,8 +231,8 @@ public class RepositoryJavaClient implements RepositoryClient { * @throws DocumentNotFoundException if workspace not found * @throws DocumentException */ - public void getFiltered(ServiceContext ctx, DocumentHandler handler) - throws DocumentNotFoundException, DocumentException { + public void getFiltered(ServiceContext ctx, DocumentHandler handler) + throws DocumentNotFoundException, DocumentException { if (handler == null) { throw new IllegalArgumentException( "RemoteRepositoryClient.getFiltered: handler is missing"); @@ -258,23 +258,23 @@ public class RepositoryJavaClient implements RepositoryClient { repoSession = getRepositorySession(); StringBuilder query = new StringBuilder("SELECT * FROM "); query.append(docType); - String where = docFilter.getWhereClause(); + String where = docFilter.getWhereClause(); // TODO This is a slow method for tenant-filter // We should make this a property that is indexed. - query.append(" WHERE ecm:path STARTSWITH '/"+domain+"'"); - if((null!=where)&&(where.length()>0)) - query.append(" AND "+where); + query.append(" WHERE ecm:path STARTSWITH '/" + domain + "'"); + if ((null != where) && (where.length() > 0)) { + query.append(" AND " + where); + } DocumentModelList docList = null; - if((docFilter.getOffset()>0)||(docFilter.getPageSize()>0)) { - docList = repoSession.query(query.toString(), null, - docFilter.getPageSize(), docFilter.getOffset(), false); + if ((docFilter.getOffset() > 0) || (docFilter.getPageSize() > 0)) { + docList = repoSession.query(query.toString(), null, + docFilter.getPageSize(), docFilter.getOffset(), false); } else { - docList = repoSession.query(query.toString()); + docList = repoSession.query(query.toString()); } //set repoSession to handle the document ((DocumentModelHandler) handler).setRepositorySession(repoSession); - DocumentModelListWrapper wrapDoc = new DocumentModelListWrapper( - docList); + DocumentWrapper wrapDoc = new DocumentWrapperImpl(docList); handler.handle(Action.GET_ALL, wrapDoc); handler.complete(Action.GET_ALL, wrapDoc); } catch (DocumentException de) { @@ -291,8 +291,6 @@ public class RepositoryJavaClient implements RepositoryClient { } } - - /** * update given document in the Nuxeo repository * @@ -331,7 +329,7 @@ public class RepositoryJavaClient implements RepositoryClient { } //set reposession to handle the document ((DocumentModelHandler) handler).setRepositorySession(repoSession); - DocumentModelWrapper wrapDoc = new DocumentModelWrapper(doc); + DocumentWrapper wrapDoc = new DocumentWrapperImpl(doc); handler.handle(Action.UPDATE, wrapDoc); repoSession.saveDocument(doc); repoSession.save(); @@ -394,8 +392,8 @@ public class RepositoryJavaClient implements RepositoryClient { public String createWorkspace(String tenantDomain, String workspaceName) throws Exception { RepositoryInstance repoSession = null; String workspaceId = null; - try{ - repoSession= getRepositorySession(); + try { + repoSession = getRepositorySession(); DocumentRef docRef = new PathRef( "/" + tenantDomain + "/" + "workspaces"); @@ -408,17 +406,17 @@ public class RepositoryJavaClient implements RepositoryClient { doc = repoSession.createDocument(doc); workspaceId = doc.getId(); repoSession.save(); - if(logger.isDebugEnabled()){ + if (logger.isDebugEnabled()) { logger.debug("created workspace name=" + workspaceName + " id=" + workspaceId); } - }catch(Exception e){ - if(logger.isDebugEnabled()){ + } catch (Exception e) { + if (logger.isDebugEnabled()) { logger.debug("createWorkspace caught exception ", e); } throw e; - }finally{ - if(repoSession != null){ + } finally { + if (repoSession != null) { releaseRepositorySession(repoSession); } } @@ -429,7 +427,7 @@ public class RepositoryJavaClient implements RepositoryClient { public String getWorkspaceId(String tenantDomain, String workspaceName) throws Exception { String workspaceId = null; RepositoryInstance repoSession = null; - try{ + try { repoSession = getRepositorySession(); DocumentRef docRef = new PathRef( "/" + tenantDomain + @@ -437,15 +435,15 @@ public class RepositoryJavaClient implements RepositoryClient { "/" + workspaceName); DocumentModel workspace = repoSession.getDocument(docRef); workspaceId = workspace.getId(); - }catch(DocumentException de){ + } catch (DocumentException de) { throw de; - }catch(Exception e){ - if(logger.isDebugEnabled()){ + } catch (Exception e) { + if (logger.isDebugEnabled()) { logger.debug("Caught exception ", e); } throw new DocumentException(e); - }finally{ - if(repoSession != null){ + } finally { + if (repoSession != null) { releaseRepositorySession(repoSession); } } @@ -470,8 +468,7 @@ public class RepositoryJavaClient implements RepositoryClient { client.releaseRepository(repoSession); } catch (Exception e) { logger.error("Could not close the repository session", e); - // no need to throw this service specific exception + // no need to throw this service specific exception } } - } diff --git a/services/intake/service/src/main/java/org/collectionspace/services/intake/nuxeo/IntakeDocumentModelHandler.java b/services/intake/service/src/main/java/org/collectionspace/services/intake/nuxeo/IntakeDocumentModelHandler.java index f3057a2ff..2a6e36fe0 100644 --- a/services/intake/service/src/main/java/org/collectionspace/services/intake/nuxeo/IntakeDocumentModelHandler.java +++ b/services/intake/service/src/main/java/org/collectionspace/services/intake/nuxeo/IntakeDocumentModelHandler.java @@ -99,19 +99,19 @@ public class IntakeDocumentModelHandler } @Override - public IntakesCommon extractCommonPart(DocumentWrapper wrapDoc) + public IntakesCommon extractCommonPart(DocumentWrapper wrapDoc) throws Exception { throw new UnsupportedOperationException(); } @Override - public void fillCommonPart(IntakesCommon intakeObject, DocumentWrapper wrapDoc) throws Exception { + public void fillCommonPart(IntakesCommon intakeObject, DocumentWrapper wrapDoc) throws Exception { throw new UnsupportedOperationException(); } @Override - public IntakesCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception { - DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject(); + public IntakesCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception { + DocumentModelList docList = wrapDoc.getWrappedObject(); IntakesCommonList coList = new IntakesCommonList(); List list = coList.getIntakeListItem(); 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 1c12971e8..aabd73ce5 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 @@ -102,19 +102,19 @@ public class RelationDocumentModelHandler } @Override - public RelationsCommon extractCommonPart(DocumentWrapper wrapDoc) + public RelationsCommon extractCommonPart(DocumentWrapper wrapDoc) throws Exception { throw new UnsupportedOperationException(); } @Override - public void fillCommonPart(RelationsCommon relation, DocumentWrapper wrapDoc) throws Exception { + public void fillCommonPart(RelationsCommon relation, DocumentWrapper wrapDoc) throws Exception { throw new UnsupportedOperationException(); } @Override - public RelationsCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception { - DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject(); + public RelationsCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception { + DocumentModelList docList = wrapDoc.getWrappedObject(); Map propsFromResource = this.getProperties(); String subjectCsid = (String) propsFromResource.get(IRelationsManager.SUBJECT); @@ -142,13 +142,13 @@ public class RelationDocumentModelHandler @Override - public void fillAllParts(DocumentWrapper wrapDoc) throws Exception { + public void fillAllParts(DocumentWrapper wrapDoc) throws Exception { super.fillAllParts(wrapDoc); fillDublinCoreObject(wrapDoc); //dublincore might not be needed in future } - private void fillDublinCoreObject(DocumentWrapper wrapDoc) throws Exception { - DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject(); + private void fillDublinCoreObject(DocumentWrapper wrapDoc) throws Exception { + DocumentModel docModel = wrapDoc.getWrappedObject(); //FIXME property setter should be dynamically set using schema inspection //so it does not require hard coding // a default title for the Dublin Core schema diff --git a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyDocumentModelHandler.java b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyDocumentModelHandler.java index a6fc7845b..4dbf3c87b 100644 --- a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyDocumentModelHandler.java +++ b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyDocumentModelHandler.java @@ -99,19 +99,19 @@ public class VocabularyDocumentModelHandler } @Override - public VocabulariesCommon extractCommonPart(DocumentWrapper wrapDoc) + public VocabulariesCommon extractCommonPart(DocumentWrapper wrapDoc) throws Exception { throw new UnsupportedOperationException(); } @Override - public void fillCommonPart(VocabulariesCommon vocabularyObject, DocumentWrapper wrapDoc) throws Exception { + public void fillCommonPart(VocabulariesCommon vocabularyObject, DocumentWrapper wrapDoc) throws Exception { throw new UnsupportedOperationException(); } @Override - public VocabulariesCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception { - DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject(); + public VocabulariesCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception { + DocumentModelList docList = wrapDoc.getWrappedObject(); VocabulariesCommonList coList = new VocabulariesCommonList(); List list = coList.getVocabularyListItem(); -- 2.47.3