From: Patrick Schmitz Date: Tue, 29 Jun 2010 16:33:18 +0000 (+0000) Subject: CSPACE-600, preparation for CSPACE-849, and fixed CSPACE-2291. This refactors the... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=fc4622c8f61e2f9bc1a85328cb8a9d2353a32b8b;p=tmp%2Fjakarta-migration.git CSPACE-600, preparation for CSPACE-849, and fixed CSPACE-2291. This refactors the bulk of the vocabulary doc handlers into a superclass. Will port these changes to Person, Org, and Location, to simplify the maintenance of these services. Also aligns vocabulary to the other Authority services, to provide a more consistent API. --- diff --git a/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/META-INF/MANIFEST.MF b/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/META-INF/MANIFEST.MF index 716581666..2c0df61dd 100644 --- a/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/META-INF/MANIFEST.MF +++ b/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/META-INF/MANIFEST.MF @@ -18,5 +18,7 @@ Require-Bundle: org.nuxeo.runtime, Provide-Package: org.collectionspace.collectionspace_core Nuxeo-Component: OSGI-INF/core-types-contrib.xml, OSGI-INF/ecm-types-contrib.xml, - OSGI-INF/layouts-contrib.xml + OSGI-INF/layouts-contrib.xml, + OSGI-INF/querymodel-contrib.xml + diff --git a/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/OSGI-INF/querymodel-contrib.xml b/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/OSGI-INF/querymodel-contrib.xml new file mode 100644 index 000000000..ecbed6c09 --- /dev/null +++ b/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/OSGI-INF/querymodel-contrib.xml @@ -0,0 +1,21 @@ + + + + org.nuxeo.ecm.webapp.querymodel.DefaultQueryModels + + + + SELECT * FROM Document WHERE ecm:parentId = ? AND + ecm:isCheckedInVersion = 0 AND ecm:mixinType != 'HiddenInNavigation' + AND ecm:currentLifeCycleState != 'deleted' AND ecm:isProxy = 0 + + + 50 + + + + + 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 ca01cc5ee..f0e54a5c1 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 @@ -142,9 +142,9 @@ public class AcquisitionDocumentModelHandler } @Override - public void fillAllParts(DocumentWrapper wrapDoc) throws Exception { + public void fillAllParts(DocumentWrapper wrapDoc, Action action) throws Exception { - super.fillAllParts(wrapDoc); + super.fillAllParts(wrapDoc, action); fillDublinCoreObject(wrapDoc); //dublincore might not be needed in future } 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 b2d934876..1f763a4bd 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 @@ -143,9 +143,9 @@ public class CollectionObjectDocumentModelHandler * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#fillAllParts(org.collectionspace.services.common.document.DocumentWrapper) */ @Override - public void fillAllParts(DocumentWrapper wrapDoc) throws Exception { + public void fillAllParts(DocumentWrapper wrapDoc, Action action) throws Exception { - super.fillAllParts(wrapDoc); + super.fillAllParts(wrapDoc, action); fillDublinCoreObject(wrapDoc); //dublincore might not be needed in future } diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/AbstractMultipartDocumentHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/common/document/AbstractMultipartDocumentHandlerImpl.java index 847055dbf..322c40bbe 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/AbstractMultipartDocumentHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/AbstractMultipartDocumentHandlerImpl.java @@ -68,7 +68,7 @@ public abstract class AbstractMultipartDocumentHandlerImpl throws Exception; @Override - public abstract void fillAllParts(DocumentWrapper wrapDoc) + public abstract void fillAllParts(DocumentWrapper wrapDoc, Action action) throws Exception; @Override diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/MultipartDocumentHandler.java b/services/common/src/main/java/org/collectionspace/services/common/document/MultipartDocumentHandler.java index 2a84a045f..7617e7c68 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/MultipartDocumentHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/MultipartDocumentHandler.java @@ -17,6 +17,8 @@ */ package org.collectionspace.services.common.document; +import org.collectionspace.services.common.document.DocumentHandler.Action; + /** * MultipartDocumentHandler is a DocumentHandler provides document processing * methods for entities using schema extension that are mapped to multipart @@ -45,7 +47,8 @@ public interface MultipartDocumentHandler * repository. Called in handle CREATE/UPDATE actions. * @param obj input object * @param docWrap target document + * @param action one of Action.CREATE or Action.UPDATE * @throws Exception */ - public void fillAllParts(DocumentWrapper docWrap) throws Exception; + public void fillAllParts(DocumentWrapper docWrap, Action action) throws Exception; } \ No newline at end of file diff --git a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityItemJAXBSchema.java b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityItemJAXBSchema.java new file mode 100644 index 000000000..8b71d644e --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityItemJAXBSchema.java @@ -0,0 +1,39 @@ +/** + * 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.common.vocabulary; + +/** + * @author pschmitz + * + */ +public interface AuthorityItemJAXBSchema { + final static String DISPLAY_NAME = "displayName"; + final static String IN_AUTHORITY = "inAuthority"; + final static String REF_NAME = "refName"; + final static String SHORT_IDENTIFIER = "shortIdentifier"; + final static String STATUS = "status"; + final static String CSID = "csid"; +} + + diff --git a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityItemListItemJAXBSchema.java b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityItemListItemJAXBSchema.java new file mode 100644 index 000000000..f9ccecc77 --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityItemListItemJAXBSchema.java @@ -0,0 +1,32 @@ +/** + * 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.common.vocabulary; + +public interface AuthorityItemListItemJAXBSchema { + final static String DISPLAY_NAME = "displayName"; + final static String REF_NAME = "refName"; + final static String SHORT_IDENTIFIER = "shortIdentifier"; + final static String CSID = "csid"; + final static String URI = "url"; +} diff --git a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityJAXBSchema.java b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityJAXBSchema.java new file mode 100644 index 000000000..456ea65e0 --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityJAXBSchema.java @@ -0,0 +1,38 @@ +/** + * 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.common.vocabulary; + +/** + * @author pschmitz + * + */ +public interface AuthorityJAXBSchema { + final static String DISPLAY_NAME = "displayName"; + final static String SHORT_IDENTIFIER = "shortIdentifier"; + final static String REF_NAME = "refName"; + final static String VOCAB_TYPE = "vocabType"; + final static String CSID = "csid"; +} + + diff --git a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityListItemJAXBSchema.java b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityListItemJAXBSchema.java new file mode 100644 index 000000000..b02c59a34 --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityListItemJAXBSchema.java @@ -0,0 +1,33 @@ +/** + * 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.common.vocabulary; + +public interface AuthorityListItemJAXBSchema { + final static String DISPLAY_NAME = "displayName"; + final static String REF_NAME = "refName"; + final static String SHORT_IDENTIFIER = "shortIdentifier"; + final static String VOCAB_TYPE = "vocabType"; + final static String CSID = "csid"; + final static String URI = "url"; +} diff --git a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java new file mode 100644 index 000000000..a3df7b584 --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java @@ -0,0 +1,105 @@ +/** + * 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.common.vocabulary.nuxeo; + +import org.collectionspace.services.common.document.DocumentWrapper; + +import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; +import org.nuxeo.ecm.core.api.DocumentModel; + +/** + * AuthorityDocumentModelHandler + * + * $LastChangedRevision: $ + * $LastChangedDate: $ + */ +public abstract class AuthorityDocumentModelHandler + extends RemoteDocumentModelHandlerImpl { + + /** + * authority is used to stash JAXB object to use when handle is called + * for Action.CREATE, Action.UPDATE or Action.GET + */ + private AuthCommon authority; + /** + * authorityList is stashed when handle is called + * for ACTION.GET_ALL + */ + private AuthCommonList authorityList; + + + /** + * getCommonPart get associated authority + * @return + */ + @Override + public AuthCommon getCommonPart() { + return authority; + } + + /** + * setCommonPart set associated authority + * @param authority + */ + @Override + public void setCommonPart(AuthCommon authority) { + this.authority = authority; + } + + /** + * getCommonPartList get associated authority (for index/GET_ALL) + * @return + */ + @Override + public AuthCommonList getCommonPartList() { + return authorityList; + } + + /* (non-Javadoc) + * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object) + */ + @Override + public void setCommonPartList(AuthCommonList authorityList) { + this.authorityList = authorityList; + } + + /* (non-Javadoc) + * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper) + */ + @Override + public AuthCommon extractCommonPart(DocumentWrapper wrapDoc) + throws Exception { + throw new UnsupportedOperationException(); + } + + /* (non-Javadoc) + * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper) + */ + @Override + public void fillCommonPart(AuthCommon vocabularyObject, DocumentWrapper wrapDoc) throws Exception { + throw new UnsupportedOperationException(); + } + +} + diff --git a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java new file mode 100644 index 000000000..3901cc4eb --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java @@ -0,0 +1,126 @@ +/** + * 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.common.vocabulary.nuxeo; + +import java.util.Map; + +import org.collectionspace.services.common.document.DocumentWrapper; +import org.collectionspace.services.common.service.ObjectPartType; +import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; +import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; +import org.nuxeo.ecm.core.api.DocumentModel; + +/** + * AuthorityItemDocumentModelHandler + * + * $LastChangedRevision: $ + * $LastChangedDate: $ + */ +public abstract class AuthorityItemDocumentModelHandler + extends RemoteDocumentModelHandlerImpl { + + //private final Logger logger = LoggerFactory.getLogger(AuthorityItemDocumentModelHandler.class); + /** + * item is used to stash JAXB object to use when handle is called + * for Action.CREATE, Action.UPDATE or Action.GET + */ + protected AICommon item; + /** + * itemList is stashed when handle is called + * for ACTION.GET_ALL + */ + protected AICommonList itemList; + + /** + * inVocabulary is the parent Authority for this context + */ + protected String inAuthority; + + public String getInAuthority() { + return inAuthority; + } + + public void setInAuthority(String inAuthority) { + this.inAuthority = inAuthority; + } + + + /** + * getCommonPart get associated item + * @return + */ + @Override + public AICommon getCommonPart() { + return item; + } + + /** + * setCommonPart set associated item + * @param vocabularyItem + */ + @Override + public void setCommonPart(AICommon item) { + this.item = item; + } + + /** + * getCommonPartList get associated item (for index/GET_ALL) + * @return + */ + @Override + public AICommonList getCommonPartList() { + return itemList; + } + + @Override + public void setCommonPartList(AICommonList itemList) { + this.itemList = itemList; + } + + @Override + public AICommon extractCommonPart(DocumentWrapper wrapDoc) + throws Exception { + throw new UnsupportedOperationException(); + } + + @Override + public void fillCommonPart(AICommon itemObject, DocumentWrapper wrapDoc) throws Exception { + throw new UnsupportedOperationException(); + } + + /** + * Filters out AuthorityItemJAXBSchema.IN_AUTHORITY, to ensure that + * the parent link remains untouched. + * @param objectProps the properties parsed from the update payload + * @param partMeta metadata for the object to fill + */ + @Override + public void filterReadOnlyPropertiesForPart( + Map objectProps, ObjectPartType partMeta) { + super.filterReadOnlyPropertiesForPart(objectProps, partMeta); + objectProps.remove(AuthorityItemJAXBSchema.IN_AUTHORITY); + } + +} + 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 b88b4d85e..a99dec859 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 @@ -30,6 +30,7 @@ import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl; import org.collectionspace.services.common.document.DocumentFilter; import org.collectionspace.services.common.document.DocumentWrapper; +import org.collectionspace.services.common.document.DocumentHandler.Action; import org.collectionspace.services.nuxeo.client.*; import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.DocumentModelList; @@ -75,7 +76,7 @@ public abstract class DocumentModelHandler public void handleCreate(DocumentWrapper wrapDoc) throws Exception { // TODO for sub-docs - check to see if the current service context is a multipart input, // OR a docfragment, and call a variant to fill the DocModel. - fillAllParts(wrapDoc); + fillAllParts(wrapDoc, Action.CREATE); } // TODO for sub-docs - Add completeCreate in which we look for set-aside doc fragments @@ -87,7 +88,7 @@ public abstract class DocumentModelHandler public void handleUpdate(DocumentWrapper wrapDoc) throws Exception { // TODO for sub-docs - check to see if the current service context is a multipart input, // OR a docfragment, and call a variant to fill the DocModel. - fillAllParts(wrapDoc); + fillAllParts(wrapDoc, Action.UPDATE); } @Override @@ -110,7 +111,7 @@ public abstract class DocumentModelHandler public abstract T extractCommonPart(DocumentWrapper wrapDoc) throws Exception; @Override - public abstract void fillAllParts(DocumentWrapper wrapDoc) throws Exception; + public abstract void fillAllParts(DocumentWrapper wrapDoc, Action action) throws Exception; @Override public abstract void fillCommonPart(T obj, DocumentWrapper wrapDoc) 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 14bfe0cce..25efd1c35 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 @@ -42,6 +42,7 @@ import org.collectionspace.services.common.document.BadRequestException; import org.collectionspace.services.common.document.DocumentUtils; import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.common.document.DocumentFilter; +import org.collectionspace.services.common.document.DocumentHandler.Action; import org.collectionspace.services.common.service.ObjectPartType; import org.collectionspace.services.common.vocabulary.RefNameUtils; @@ -171,7 +172,7 @@ public abstract class RemoteDocumentModelHandlerImpl * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillAllParts(org.collectionspace.services.common.document.DocumentWrapper) */ @Override - public void fillAllParts(DocumentWrapper wrapDoc) throws Exception { + public void fillAllParts(DocumentWrapper wrapDoc, Action action) throws Exception { //TODO filling extension parts should be dynamic //Nuxeo APIs lack to support stream/byte[] input, get/setting properties is @@ -199,11 +200,11 @@ public abstract class RemoteDocumentModelHandlerImpl } //skip if the part is not in metadata - if(!partsMetaMap.containsKey(partLabel)){ + ObjectPartType partMeta = partsMetaMap.get(partLabel); + if(partMeta==null){ continue; } - ObjectPartType partMeta = partsMetaMap.get(partLabel); - fillPart(part, docModel, partMeta); + fillPart(part, docModel, partMeta, action); }//rof } @@ -215,7 +216,7 @@ public abstract class RemoteDocumentModelHandlerImpl * @param partMeta metadata for the object to fill * @throws Exception */ - protected void fillPart(InputPart part, DocumentModel docModel, ObjectPartType partMeta) + protected void fillPart(InputPart part, DocumentModel docModel, ObjectPartType partMeta, Action action) throws Exception { InputStream payload = part.getBody(InputStream.class, null); @@ -229,11 +230,25 @@ public abstract class RemoteDocumentModelHandlerImpl //TODO: callback to handler if registered to validate the //document Map objectProps = DocumentUtils.parseProperties(document.getFirstChild()); + if(action==Action.UPDATE) { + this.filterReadOnlyPropertiesForPart(objectProps, partMeta); + } docModel.setProperties(partMeta.getLabel(), objectProps); } } } + /** + * Filters out read only properties, so they cannot be set on update. + * TODO: add configuration support to do this generally + * @param objectProps the properties parsed from the update payload + * @param partMeta metadata for the object to fill + */ + public void filterReadOnlyPropertiesForPart( + Map objectProps, ObjectPartType partMeta) { + // Currently a no-op, but can be overridden in Doc handlers. + } + /** * extractPart extracts an XML object from given DocumentModel * @param docModel diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteSubItemDocumentModelHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteSubItemDocumentModelHandlerImpl.java index 4685928db..9ebc7cd57 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteSubItemDocumentModelHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteSubItemDocumentModelHandlerImpl.java @@ -65,7 +65,8 @@ public abstract class RemoteSubItemDocumentModelHandlerImpl extends * @throws Exception */ @Override - protected void fillPart(InputPart part, DocumentModel docModel, ObjectPartType partMeta) + protected void fillPart(InputPart part, DocumentModel docModel, + ObjectPartType partMeta, Action action) throws Exception { InputStream payload = part.getBody(InputStream.class, null); diff --git a/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java b/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java index dafee9181..b3d0ced69 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 @@ -139,11 +139,11 @@ public class RelationDocumentModelHandler /* (non-Javadoc) * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#fillAllParts(org.collectionspace.services.common.document.DocumentWrapper) - */ @Override public void fillAllParts(DocumentWrapper wrapDoc) throws Exception { super.fillAllParts(wrapDoc); } + */ /** * Gets the relation list item. diff --git a/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/OSGI-INF/layouts-contrib.xml b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/OSGI-INF/layouts-contrib.xml index e76011543..4171bb9da 100644 --- a/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/OSGI-INF/layouts-contrib.xml +++ b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/OSGI-INF/layouts-contrib.xml @@ -12,7 +12,8 @@ displayName shortIdentifier - refName + CSID + refName vocabType @@ -42,6 +43,19 @@ + + + + + true + + ecm:name + + + dataInputText + + + @@ -81,7 +95,7 @@ displayName shortIdentifier refName - inVocabulary + inAuthority status @@ -124,13 +138,13 @@ - + - + true - inVocabulary + inAuthority dataInputText diff --git a/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularyitems_common.xsd b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularyitems_common.xsd index 09bf431f4..0f920f111 100644 --- a/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularyitems_common.xsd +++ b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularyitems_common.xsd @@ -22,7 +22,7 @@ - + diff --git a/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClientUtils.java b/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClientUtils.java index b564c9fb5..ec6c338ab 100644 --- a/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClientUtils.java +++ b/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClientUtils.java @@ -7,7 +7,7 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; -import org.collectionspace.services.VocabularyItemJAXBSchema; +import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; import org.collectionspace.services.client.test.ServiceRequestType; import org.collectionspace.services.vocabulary.VocabularyitemsCommon; import org.collectionspace.services.vocabulary.VocabulariesCommon; @@ -43,12 +43,12 @@ public class VocabularyClientUtils { // Note that we do not use the map, but we will once we add more info to the // items - public static MultipartOutput createVocabularyItemInstance(String inVocabulary, + public static MultipartOutput createVocabularyItemInstance(String inAuthority, String vocabularyRefName, Map vocabItemInfo, String headerLabel){ VocabularyitemsCommon vocabularyItem = new VocabularyitemsCommon(); - vocabularyItem.setInVocabulary(inVocabulary); - String shortId = vocabItemInfo.get(VocabularyItemJAXBSchema.SHORT_IDENTIFIER); - String displayName = vocabItemInfo.get(VocabularyItemJAXBSchema.DISPLAY_NAME); + vocabularyItem.setInAuthority(inAuthority); + String shortId = vocabItemInfo.get(AuthorityItemJAXBSchema.SHORT_IDENTIFIER); + String displayName = vocabItemInfo.get(AuthorityItemJAXBSchema.DISPLAY_NAME); vocabularyItem.setShortIdentifier(shortId); vocabularyItem.setDisplayName(displayName); String refName = createVocabularyItemRefName(vocabularyRefName, shortId, displayName); @@ -74,8 +74,8 @@ public class VocabularyClientUtils { ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE; if(logger.isDebugEnabled()){ - logger.debug("Import: Create Item: \""+itemMap.get(VocabularyItemJAXBSchema.DISPLAY_NAME) - +"\" in personAuthorityulary: \"" + vocabularyRefName +"\""); + logger.debug("Import: Create Item: \""+itemMap.get(AuthorityItemJAXBSchema.SHORT_IDENTIFIER) + +"\" in personAuthority: \"" + vcsid +"\""); } MultipartOutput multipart = createVocabularyItemInstance( vcsid, vocabularyRefName, @@ -85,12 +85,12 @@ public class VocabularyClientUtils { int statusCode = res.getStatus(); if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { - throw new RuntimeException("Could not create Item: \""+itemMap.get(VocabularyItemJAXBSchema.DISPLAY_NAME) + throw new RuntimeException("Could not create Item: \""+itemMap.get(AuthorityItemJAXBSchema.DISPLAY_NAME) +"\" in personAuthority: \"" + vocabularyRefName +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); } if(statusCode != EXPECTED_STATUS_CODE) { - throw new RuntimeException("Unexpected Status when creating Item: \""+itemMap.get(VocabularyItemJAXBSchema.DISPLAY_NAME) + throw new RuntimeException("Unexpected Status when creating Item: \""+itemMap.get(AuthorityItemJAXBSchema.DISPLAY_NAME) +"\" in personAuthority: \"" + vocabularyRefName +"\", Status:"+ statusCode); } diff --git a/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java b/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java index 01c402e22..e47ff29f7 100644 --- a/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java +++ b/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java @@ -29,7 +29,7 @@ import java.util.Map; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import org.collectionspace.services.VocabularyItemJAXBSchema; +import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.VocabularyClient; import org.collectionspace.services.client.VocabularyClientUtils; @@ -69,7 +69,7 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl { private String knownResourceRefName = null; private String knownResourceFullRefName = null; private String knownItemResourceId = null; - private int nItemsToCreateInList = 3; + private int nItemsToCreateInList = 5; private List allResourceIdsCreated = new ArrayList(); private Map allResourceItemIdsCreated = new HashMap(); @@ -157,7 +157,7 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl { dependsOnMethods = {"create"}) public void createItem(String testName) { - if (logger.isDebugEnabled()) { + if (null!=testName && logger.isDebugEnabled()) { logger.debug(testBanner(testName, CLASS_NAME)); } // Perform setup. @@ -166,8 +166,8 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl { VocabularyClient client = new VocabularyClient(); HashMap itemInfo = new HashMap(); String shortId = createIdentifier(); - itemInfo.put(VocabularyItemJAXBSchema.SHORT_IDENTIFIER, shortId); - itemInfo.put(VocabularyItemJAXBSchema.DISPLAY_NAME, "display-"+shortId); + itemInfo.put(AuthorityItemJAXBSchema.SHORT_IDENTIFIER, shortId); + itemInfo.put(AuthorityItemJAXBSchema.DISPLAY_NAME, "display-"+shortId); String newID = VocabularyClientUtils.createItemInVocabulary(knownResourceId, knownResourceRefName, itemInfo, client); @@ -175,7 +175,7 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl { // for additional tests below. if (knownItemResourceId == null){ knownItemResourceId = newID; - if (logger.isDebugEnabled()) { + if (null!=testName && logger.isDebugEnabled()) { logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId); } } @@ -192,10 +192,11 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl { for (int i = 0; i < 3; i++) { // Force create to reset the known resource info setKnownResource(null, null, null, null); + knownItemResourceId = null; create(testName); // Add nItemsToCreateInList items to each vocab for (int j = 0; j < nItemsToCreateInList; j++) { - createItem(testName); + createItem(null); } } } @@ -257,8 +258,8 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. VocabularyClient client = new VocabularyClient(); HashMap itemInfo = new HashMap(); - itemInfo.put(VocabularyItemJAXBSchema.SHORT_IDENTIFIER, "Bad Item Short Id!"); - itemInfo.put(VocabularyItemJAXBSchema.DISPLAY_NAME, "Bad Item!"); + itemInfo.put(AuthorityItemJAXBSchema.SHORT_IDENTIFIER, "Bad Item Short Id!"); + itemInfo.put(AuthorityItemJAXBSchema.DISPLAY_NAME, "Bad Item!"); MultipartOutput multipart = VocabularyClientUtils.createVocabularyItemInstance( knownResourceId, knownResourceRefName, itemInfo, client.getItemCommonPartName() ); @@ -267,12 +268,12 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl { int statusCode = res.getStatus(); if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { - throw new RuntimeException("Could not create Item: \""+itemInfo.get(VocabularyItemJAXBSchema.DISPLAY_NAME) + throw new RuntimeException("Could not create Item: \""+itemInfo.get(AuthorityItemJAXBSchema.DISPLAY_NAME) +"\" in personAuthority: \"" + knownResourceRefName +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); } if(statusCode != EXPECTED_STATUS_CODE) { - throw new RuntimeException("Unexpected Status when creating Item: \""+itemInfo.get(VocabularyItemJAXBSchema.DISPLAY_NAME) + throw new RuntimeException("Unexpected Status when creating Item: \""+itemInfo.get(AuthorityItemJAXBSchema.DISPLAY_NAME) +"\" in personAuthority: \"" + knownResourceRefName +"\", Status:"+ statusCode); } } @@ -514,7 +515,7 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl { VocabularyitemsCommon vocabularyItem = (VocabularyitemsCommon) extractPart(input, client.getItemCommonPartName(), VocabularyitemsCommon.class); Assert.assertNotNull(vocabularyItem); - Assert.assertEquals(vocabularyItem.getInVocabulary(), knownResourceId); + Assert.assertEquals(vocabularyItem.getInAuthority(), knownResourceId); } // Failure outcomes @@ -730,11 +731,12 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl { List items = list.getVocabularyitemListItem(); int nItemsReturned = items.size(); + long nItemsTotal = list.getTotalItems(); if(logger.isDebugEnabled()){ logger.debug(" " + testName + ": Expected " - + nItemsToCreateInList+" items; got: "+nItemsReturned); + + nItemsToCreateInList+" items; got: "+nItemsReturned+" of: "+nItemsTotal); } - Assert.assertEquals( nItemsReturned, nItemsToCreateInList); + Assert.assertEquals( nItemsTotal, nItemsToCreateInList); // Optionally output additional data about list members for debugging. boolean iterateThroughList = true; @@ -824,7 +826,7 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl { } @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"readItem", "update"}) + dependsOnMethods = {"readItem", "update", "verifyIgnoredUpdateWithInAuthority"}) public void updateItem(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -888,6 +890,70 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl { "Data in updated VocabularyItem did not match submitted data."); } + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + dependsOnMethods = {"readItem"}) + public void verifyIgnoredUpdateWithInAuthority(String testName) throws Exception { + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); + } + // Perform setup. + setupUpdate(); + + // Submit the request to the service and store the response. + VocabularyClient client = new VocabularyClient(); + ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + " read Vocab:"+knownResourceId+"/Item:" + +knownItemResourceId+" status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode()); + + MultipartInput input = (MultipartInput) res.getEntity(); + VocabularyitemsCommon vitem = (VocabularyitemsCommon) extractPart(input, + client.getItemCommonPartName(), VocabularyitemsCommon.class); + Assert.assertNotNull(vitem); + // Try to Update with new parent vocab (use self, for test). + Assert.assertEquals(vitem.getInAuthority(), + knownResourceId, + "VocabularyItem inAuthority does not match knownResourceId."); + vitem.setInAuthority(knownItemResourceId); + + // Submit the updated resource to the service and store the response. + MultipartOutput output = new MultipartOutput(); + OutputPart commonPart = output.addPart(vitem, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", client.getItemCommonPartName()); + res = client.updateItem(knownResourceId, knownItemResourceId, output); + statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that the parent did not change + res = client.readItem(knownResourceId, knownItemResourceId); + input = (MultipartInput) res.getEntity(); + VocabularyitemsCommon updatedVocabularyItem = + (VocabularyitemsCommon) extractPart(input, + client.getItemCommonPartName(), VocabularyitemsCommon.class); + Assert.assertNotNull(updatedVocabularyItem); + + // Verify that the updated resource received the correct data. + Assert.assertEquals(updatedVocabularyItem.getInAuthority(), + knownResourceId, + "VocabularyItem allowed update to the parent (inAuthority)."); + } + // Failure outcomes // Placeholders until the three tests below can be uncommented. // See Issue CSPACE-401. @@ -1040,8 +1106,8 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl { // The only relevant ID may be the one used in update(), below. VocabularyClient client = new VocabularyClient(); HashMap itemInfo = new HashMap(); - itemInfo.put(VocabularyItemJAXBSchema.SHORT_IDENTIFIER, "nonex"); - itemInfo.put(VocabularyItemJAXBSchema.DISPLAY_NAME, "display-nonex"); + itemInfo.put(AuthorityItemJAXBSchema.SHORT_IDENTIFIER, "nonex"); + itemInfo.put(AuthorityItemJAXBSchema.DISPLAY_NAME, "display-nonex"); MultipartOutput multipart = VocabularyClientUtils.createVocabularyItemInstance(knownResourceId, VocabularyClientUtils.createVocabularyRefName(NON_EXISTENT_ID, null), @@ -1066,7 +1132,7 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl { // Success outcomes @Override @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) + dependsOnMethods = {"create", "readList", "testSubmitRequest", "update", "deleteItem"}) public void delete(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -1092,7 +1158,7 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl { @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, dependsOnMethods = {"createItem", "readItemList", "testItemSubmitRequest", - "updateItem", "verifyIllegalItemDisplayName"}) + "updateItem", "verifyIllegalItemDisplayName", "verifyIgnoredUpdateWithInAuthority"}) public void deleteItem(String testName) throws Exception { if (logger.isDebugEnabled()) { diff --git a/services/vocabulary/import/src/main/java/org/collectionspace/services/vocabulary/importer/VocabularyBaseImport.java b/services/vocabulary/import/src/main/java/org/collectionspace/services/vocabulary/importer/VocabularyBaseImport.java index 96e8d1346..3a41051d3 100644 --- a/services/vocabulary/import/src/main/java/org/collectionspace/services/vocabulary/importer/VocabularyBaseImport.java +++ b/services/vocabulary/import/src/main/java/org/collectionspace/services/vocabulary/importer/VocabularyBaseImport.java @@ -88,7 +88,7 @@ public class VocabularyBaseImport { } for (String itemName : enumValues) { HashMap itemInfo = new HashMap(); - itemInfo.put(VocabularyItemJAXBSchema.DISPLAY_NAME, itemName); + itemInfo.put(AuthorityItemJAXBSchema.DISPLAY_NAME, itemName); VocabularyClientUtils.createItemInVocabulary(newVocabId, baseVocabRefName, itemInfo, client); } diff --git a/services/vocabulary/jaxb/pom.xml b/services/vocabulary/jaxb/pom.xml index 39114cfb1..bb222abc2 100644 --- a/services/vocabulary/jaxb/pom.xml +++ b/services/vocabulary/jaxb/pom.xml @@ -14,6 +14,13 @@ services.vocabulary.jaxb + + + org.collectionspace.services + org.collectionspace.services.common + ${project.version} + + com.sun.xml.bind jaxb-impl diff --git a/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemJAXBSchema.java b/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemJAXBSchema.java deleted file mode 100644 index ff9c9bd53..000000000 --- a/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemJAXBSchema.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * - */ -package org.collectionspace.services; - -/** - * @author pschmitz - * - */ -public interface VocabularyItemJAXBSchema { - final static String VOCABULARYITEMS_COMMON="vocabularyitems_common"; - final static String DISPLAY_NAME = "displayName"; - final static String IN_VOCABULARY = "inVocabulary"; - final static String REF_NAME = "refName"; - final static String SHORT_IDENTIFIER = "shortIdentifier"; - final static String STATUS = "status"; - final static String CSID = "csid"; -} - - diff --git a/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemListItemJAXBSchema.java b/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemListItemJAXBSchema.java deleted file mode 100644 index 204a4879b..000000000 --- a/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemListItemJAXBSchema.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.collectionspace.services; - -public interface VocabularyItemListItemJAXBSchema { - final static String DISPLAY_NAME = "displayName"; - final static String REF_NAME = "refName"; - final static String CSID = "csid"; - final static String URI = "url"; -} diff --git a/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyJAXBSchema.java b/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyJAXBSchema.java deleted file mode 100644 index 9f3c8f276..000000000 --- a/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyJAXBSchema.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * - */ -package org.collectionspace.services; - -/** - * @author pschmitz - * - */ -public interface VocabularyJAXBSchema { - final static String VOCABULARIES_COMMON = "vocabularies_common"; - final static String DISPLAY_NAME = "displayName"; - final static String SHORT_IDENTIFIER = "shortIdentifier"; - final static String REF_NAME = "refName"; - final static String VOCAB_TYPE = "vocabType"; - final static String CSID = "csid"; -} - - diff --git a/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyListItemJAXBSchema.java b/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyListItemJAXBSchema.java deleted file mode 100644 index 38dbf4821..000000000 --- a/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyListItemJAXBSchema.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.collectionspace.services; - -public interface VocabularyListItemJAXBSchema { - final static String DISPLAY_NAME = "displayName"; - final static String REF_NAME = "refName"; - final static String SHORT_IDENTIFIER = "shortIdentifier"; - final static String VOCAB_TYPE = "vocabType"; - final static String CSID = "csid"; - final static String URI = "url"; -} diff --git a/services/vocabulary/jaxb/src/main/resources/vocabularyitem_common.xsd b/services/vocabulary/jaxb/src/main/resources/vocabularyitem_common.xsd index e9fb1a95f..77211d048 100644 --- a/services/vocabulary/jaxb/src/main/resources/vocabularyitem_common.xsd +++ b/services/vocabulary/jaxb/src/main/resources/vocabularyitem_common.xsd @@ -14,21 +14,21 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java index 522b3aca3..6f285fb76 100644 --- a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java +++ b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java @@ -39,8 +39,8 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; -import org.collectionspace.services.VocabularyJAXBSchema; -import org.collectionspace.services.VocabularyItemJAXBSchema; +import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema; +import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl; import org.collectionspace.services.common.ClientType; import org.collectionspace.services.common.ServiceMain; @@ -69,9 +69,11 @@ public class VocabularyResource extends /** The Constant vocabularyServiceName. */ private final static String vocabularyServiceName = "vocabularies"; + private final static String VOCABULARIES_COMMON = "vocabularies_common"; /** The Constant vocabularyItemServiceName. */ private final static String vocabularyItemServiceName = "vocabularyitems"; + private final static String VOCABULARYITEMS_COMMON = "vocabularyitems_common"; /** The logger. */ final Logger logger = LoggerFactory.getLogger(VocabularyResource.class); @@ -139,8 +141,8 @@ public class VocabularyResource extends docHandler = (VocabularyItemDocumentModelHandler)createDocumentHandler(ctx, ctx.getCommonPartLabel(getItemServiceName()), - VocabularyitemsCommon.class); - docHandler.setInVocabulary(inVocabulary); + VocabularyitemsCommon.class); + docHandler.setInAuthority(inVocabulary); return docHandler; } @@ -257,8 +259,8 @@ public class VocabularyResource extends throw new WebApplicationException(response); } String whereClause = - VocabularyJAXBSchema.VOCABULARIES_COMMON+ - ":"+VocabularyJAXBSchema.SHORT_IDENTIFIER+ + VOCABULARIES_COMMON+ + ":"+AuthorityJAXBSchema.SHORT_IDENTIFIER+ "='"+specifier+"'"; // We only get a single doc - if there are multiple, // it is an error in use. @@ -562,14 +564,14 @@ public class VocabularyResource extends DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); DocumentFilter myFilter = handler.getDocumentFilter(); myFilter.setWhereClause( - VocabularyItemJAXBSchema.VOCABULARYITEMS_COMMON + ":" - + VocabularyItemJAXBSchema.IN_VOCABULARY + "=" + VOCABULARYITEMS_COMMON + ":" + + AuthorityItemJAXBSchema.IN_AUTHORITY + "=" + "'" + parentcsid + "'"); // AND vocabularyitems_common:displayName LIKE '%partialTerm%' if (partialTerm != null && !partialTerm.isEmpty()) { - String ptClause = VocabularyItemJAXBSchema.VOCABULARYITEMS_COMMON + ":" - + VocabularyItemJAXBSchema.DISPLAY_NAME + String ptClause = VOCABULARYITEMS_COMMON + ":" + + AuthorityItemJAXBSchema.DISPLAY_NAME + IQueryManager.SEARCH_LIKE + "'%" + partialTerm + "%'"; myFilter.appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND); @@ -615,8 +617,8 @@ public class VocabularyResource extends try { MultivaluedMap queryParams = ui.getQueryParameters(); String whereClause = - VocabularyJAXBSchema.VOCABULARIES_COMMON+ - ":"+VocabularyJAXBSchema.SHORT_IDENTIFIER+ + VOCABULARIES_COMMON+ + ":"+AuthorityJAXBSchema.SHORT_IDENTIFIER+ "='"+specifier+"'"; // Need to get an Authority by name ServiceContext ctx = createServiceContext(queryParams); 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 1e5a605d4..ecb3222d3 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 @@ -26,15 +26,13 @@ package org.collectionspace.services.vocabulary.nuxeo; import java.util.Iterator; import java.util.List; -import org.collectionspace.services.VocabularyJAXBSchema; -import org.collectionspace.services.common.document.DocumentHandler.Action; -import org.collectionspace.services.common.document.DocumentFilter; +import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema; +import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityDocumentModelHandler; import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.vocabulary.VocabulariesCommon; import org.collectionspace.services.vocabulary.VocabulariesCommonList; import org.collectionspace.services.vocabulary.VocabulariesCommonList.VocabularyListItem; -import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; import org.collectionspace.services.nuxeo.util.NuxeoUtils; import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.DocumentModelList; @@ -48,7 +46,7 @@ import org.slf4j.LoggerFactory; * $LastChangedDate: $ */ public class VocabularyDocumentModelHandler - extends RemoteDocumentModelHandlerImpl { + extends AuthorityDocumentModelHandler { /** The logger. */ private final Logger logger = LoggerFactory.getLogger(VocabularyDocumentModelHandler.class); @@ -56,65 +54,65 @@ public class VocabularyDocumentModelHandler * vocabulary is used to stash JAXB object to use when handle is called * for Action.CREATE, Action.UPDATE or Action.GET */ - private VocabulariesCommon vocabulary; + //private VocabulariesCommon vocabulary; /** * vocabularyList is stashed when handle is called * for ACTION.GET_ALL */ - private VocabulariesCommonList vocabularyList; + //private VocabulariesCommonList vocabularyList; /** * getCommonPart get associated vocabulary * @return - */ @Override public VocabulariesCommon getCommonPart() { return vocabulary; } + */ /** * setCommonPart set associated vocabulary * @param vocabulary - */ @Override public void setCommonPart(VocabulariesCommon vocabulary) { this.vocabulary = vocabulary; } + */ /** * getCommonPartList get associated vocabulary (for index/GET_ALL) * @return - */ @Override public VocabulariesCommonList getCommonPartList() { return vocabularyList; } + */ /* (non-Javadoc) * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object) - */ @Override public void setCommonPartList(VocabulariesCommonList vocabularyList) { this.vocabularyList = vocabularyList; } + */ /* (non-Javadoc) * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper) - */ @Override public VocabulariesCommon extractCommonPart(DocumentWrapper wrapDoc) throws Exception { throw new UnsupportedOperationException(); } + */ /* (non-Javadoc) * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper) - */ @Override public void fillCommonPart(VocabulariesCommon vocabularyObject, DocumentWrapper wrapDoc) throws Exception { throw new UnsupportedOperationException(); } + */ /* (non-Javadoc) * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper) @@ -122,20 +120,21 @@ public class VocabularyDocumentModelHandler @Override public VocabulariesCommonList extractCommonPartList( DocumentWrapper wrapDoc) throws Exception { + String label = getServiceContext().getCommonPartLabel(); VocabulariesCommonList coList = extractPagingInfo(new VocabulariesCommonList(), wrapDoc); List list = coList.getVocabularyListItem(); Iterator iter = wrapDoc.getWrappedObject().iterator(); while(iter.hasNext()){ DocumentModel docModel = iter.next(); VocabularyListItem ilistItem = new VocabularyListItem(); - ilistItem.setDisplayName((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), - VocabularyJAXBSchema.DISPLAY_NAME)); - ilistItem.setRefName((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), - VocabularyJAXBSchema.REF_NAME)); - ilistItem.setShortIdentifier((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), - VocabularyJAXBSchema.SHORT_IDENTIFIER)); - ilistItem.setVocabType((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), - VocabularyJAXBSchema.VOCAB_TYPE)); + ilistItem.setDisplayName((String) docModel.getProperty(label, + AuthorityJAXBSchema.DISPLAY_NAME)); + ilistItem.setRefName((String) docModel.getProperty(label, + AuthorityJAXBSchema.REF_NAME)); + ilistItem.setShortIdentifier((String) docModel.getProperty(label, + AuthorityJAXBSchema.SHORT_IDENTIFIER)); + ilistItem.setVocabType((String) docModel.getProperty(label, + AuthorityJAXBSchema.VOCAB_TYPE)); String id = NuxeoUtils.extractId(docModel.getPathAsString()); ilistItem.setUri(getServiceContextPath() + id); ilistItem.setCsid(id); diff --git a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyItemDocumentModelHandler.java b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyItemDocumentModelHandler.java index 9609083b3..d759a2e68 100644 --- a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyItemDocumentModelHandler.java +++ b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyItemDocumentModelHandler.java @@ -25,11 +25,14 @@ package org.collectionspace.services.vocabulary.nuxeo; import java.util.Iterator; import java.util.List; +//import java.util.Map; -import org.collectionspace.services.VocabularyItemJAXBSchema; -import org.collectionspace.services.common.document.DocumentFilter; +import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; +//import org.collectionspace.services.common.document.DocumentFilter; import org.collectionspace.services.common.document.DocumentWrapper; -import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; +//import org.collectionspace.services.common.service.ObjectPartType; +//import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; +import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler; import org.collectionspace.services.nuxeo.util.NuxeoUtils; import org.collectionspace.services.vocabulary.VocabularyitemsCommon; import org.collectionspace.services.vocabulary.VocabularyitemsCommonList; @@ -46,84 +49,15 @@ import org.slf4j.LoggerFactory; * $LastChangedDate: $ */ public class VocabularyItemDocumentModelHandler - extends RemoteDocumentModelHandlerImpl { + extends AuthorityItemDocumentModelHandler { private final Logger logger = LoggerFactory.getLogger(VocabularyItemDocumentModelHandler.class); - /** - * vocabularyItem is used to stash JAXB object to use when handle is called - * for Action.CREATE, Action.UPDATE or Action.GET - */ - private VocabularyitemsCommon vocabularyItem; - /** - * vocabularyItemList is stashed when handle is called - * for ACTION.GET_ALL - */ - private VocabularyitemsCommonList vocabularyItemList; - /** - * inVocabulary is the parent vocabulary for this context - */ - private String inVocabulary; - - public String getInVocabulary() { - return inVocabulary; - } - - public void setInVocabulary(String inVocabulary) { - this.inVocabulary = inVocabulary; - } - - - /** - * getCommonPart get associated vocabularyItem - * @return - */ - @Override - public VocabularyitemsCommon getCommonPart() { - return vocabularyItem; - } - - /** - * setCommonPart set associated vocabularyItem - * @param vocabularyItem - */ - @Override - public void setCommonPart(VocabularyitemsCommon vocabularyItem) { - this.vocabularyItem = vocabularyItem; - } - - /** - * getCommonPartList get associated vocabularyItem (for index/GET_ALL) - * @return - */ - @Override - public VocabularyitemsCommonList getCommonPartList() { - return vocabularyItemList; - } - - @Override - public void setCommonPartList(VocabularyitemsCommonList vocabularyItemList) { - this.vocabularyItemList = vocabularyItemList; - } - - @Override - public VocabularyitemsCommon extractCommonPart(DocumentWrapper wrapDoc) - throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - public void fillCommonPart(VocabularyitemsCommon vocabularyItemObject, DocumentWrapper wrapDoc) throws Exception { - throw new UnsupportedOperationException(); - } - @Override public VocabularyitemsCommonList extractCommonPartList( DocumentWrapper wrapDoc) throws Exception { VocabularyitemsCommonList coList = extractPagingInfo(new VocabularyitemsCommonList(), wrapDoc); - // FIXME: iterating over a long list of documents is not a long term - // strategy...need to change to more efficient iterating in future List list = coList.getVocabularyitemListItem(); Iterator iter = wrapDoc.getWrappedObject().iterator(); while (iter.hasNext()) { @@ -131,12 +65,12 @@ public class VocabularyItemDocumentModelHandler VocabularyitemListItem ilistItem = new VocabularyitemListItem(); ilistItem.setDisplayName((String) docModel.getProperty( getServiceContext().getCommonPartLabel("vocabularyItems"), - VocabularyItemJAXBSchema.DISPLAY_NAME)); + AuthorityItemJAXBSchema.DISPLAY_NAME)); ilistItem.setRefName((String) docModel.getProperty( getServiceContext().getCommonPartLabel("vocabularyItems"), - VocabularyItemJAXBSchema.REF_NAME)); + AuthorityItemJAXBSchema.REF_NAME)); String id = NuxeoUtils.extractId(docModel.getPathAsString()); - ilistItem.setUri("/vocabularies/" + inVocabulary + "/items/" + id); + ilistItem.setUri("/vocabularies/" + inAuthority + "/items/" + id); ilistItem.setCsid(id); list.add(ilistItem); }