From db9f0531252be58ffc75b456583527c1ceea958c Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Mon, 7 May 2012 17:52:07 -0700 Subject: [PATCH] CSPACE-5130,CSPACE-5124: Revised Place authority item schema to reflect repeatable term info group. Minor cleanup of resource classes, client utilities, and client classes, for consistency during preferred / non-preferred term work. --- .../client/LocationAuthorityClient.java | 8 +- .../client/LocationAuthorityClientUtils.java | 2 +- .../location/LocationAuthorityResource.java | 29 ++-- .../client/OrgAuthorityClientUtils.java | 2 +- .../organization/OrgAuthorityResource.java | 39 +++--- .../person/PersonAuthorityResource.java | 66 ++++----- .../main/resources/schemas/places_common.xsd | 95 ++++++++----- .../services/client/PlaceAuthorityClient.java | 79 +++++------ .../client/PlaceAuthorityClientUtils.java | 90 +++++------- .../test/PlaceAuthorityServiceTest.java | 131 +----------------- .../jaxb/src/main/resources/place_common.xsd | 103 +++++++++----- .../place/PlaceAuthorityResource.java | 81 +++++------ 12 files changed, 309 insertions(+), 416 deletions(-) diff --git a/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClient.java b/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClient.java index 9fe643945..1a4c76e9a 100644 --- a/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClient.java +++ b/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClient.java @@ -1,19 +1,13 @@ /** * LocationAuthorityClient.java * - * {Purpose of This Class} - * - * {Other Notes Relating to This Class (Optional)} - * - * $LastChangedBy: $ $LastChangedRevision: $ $LastChangedDate: $ - * * 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 {Contributing Institution} + * Copyright © 2009 The Regents of the University of California * * Licensed under the Educational Community License (ECL), Version 2.0. You may * not use this file except in compliance with this License. diff --git a/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java b/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java index 41f514470..e8ae69ad0 100644 --- a/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java +++ b/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java @@ -125,7 +125,7 @@ public class LocationAuthorityClientUtils { ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE; String displayName = ""; - if (terms !=null && terms.size() > 0) { + if ((terms !=null) && (! terms.isEmpty())) { displayName = terms.get(0).getTermDisplayName(); } diff --git a/services/location/service/src/main/java/org/collectionspace/services/location/LocationAuthorityResource.java b/services/location/service/src/main/java/org/collectionspace/services/location/LocationAuthorityResource.java index 0345d378d..dc6e7c158 100644 --- a/services/location/service/src/main/java/org/collectionspace/services/location/LocationAuthorityResource.java +++ b/services/location/service/src/main/java/org/collectionspace/services/location/LocationAuthorityResource.java @@ -22,45 +22,42 @@ */ package org.collectionspace.services.location; +import javax.ws.rs.Consumes; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; import org.collectionspace.services.client.LocationAuthorityClient; import org.collectionspace.services.common.vocabulary.AuthorityResource; import org.collectionspace.services.location.nuxeo.LocationDocumentModelHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.ws.rs.Consumes; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - +/** + * LocationAuthorityResource + * + * Handles, dispatches, and returns responses to RESTful requests related to + * Location authority-related resources. + */ @Path(LocationAuthorityClient.SERVICE_PATH) @Consumes("application/xml") @Produces("application/xml") public class LocationAuthorityResource extends AuthorityResource { - private final static String locationAuthorityServiceName = "locationauthorities"; - private final static String LOCATIONAUTHORITIES_COMMON = "locationauthorities_common"; - private final static String locationServiceName = "locations"; - private final static String LOCATIONS_COMMON = "locations_common"; final Logger logger = LoggerFactory.getLogger(LocationAuthorityResource.class); public LocationAuthorityResource() { super(LocationauthoritiesCommon.class, LocationAuthorityResource.class, - LOCATIONAUTHORITIES_COMMON, LOCATIONS_COMMON); + LocationAuthorityClient.SERVICE_COMMON_PART_NAME, LocationAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME); } @Override public String getServiceName() { - return locationAuthorityServiceName; - } - - public String getItemServiceName() { - return locationServiceName; + return LocationAuthorityClient.SERVICE_NAME; } @Override - public Class getCommonPartClass() { - return LocationauthoritiesCommon.class; + public String getItemServiceName() { + return LocationAuthorityClient.SERVICE_ITEM_NAME; } @Override diff --git a/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClientUtils.java b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClientUtils.java index 7ada74135..e336b5424 100644 --- a/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClientUtils.java +++ b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClientUtils.java @@ -162,7 +162,7 @@ public class OrgAuthorityClientUtils { ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE; String displayName = ""; - if (terms !=null && terms.size() > 0) { + if ((terms !=null) && (! terms.isEmpty())) { displayName = terms.get(0).getTermDisplayName(); } diff --git a/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java index 51366f161..40373aa91 100644 --- a/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java @@ -23,50 +23,45 @@ */ package org.collectionspace.services.organization; +import javax.ws.rs.Consumes; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; import org.collectionspace.services.client.OrgAuthorityClient; -import org.collectionspace.services.client.PersonAuthorityClient; import org.collectionspace.services.contact.AuthorityResourceWithContacts; import org.collectionspace.services.organization.nuxeo.OrganizationDocumentModelHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.ws.rs.Consumes; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; +/** + * OrgAuthorityResource + * + * Handles, dispatches, and returns responses to RESTful requests + * related to Organization authority-related resources. + */ -@Path("/" + OrgAuthorityClient.SERVICE_PATH_COMPONENT) +@Path(OrgAuthorityClient.SERVICE_PATH) @Consumes("application/xml") @Produces("application/xml") public class OrgAuthorityResource extends - AuthorityResourceWithContacts { + AuthorityResourceWithContacts { - private final static String orgAuthorityServiceName = OrgAuthorityClient.SERVICE_NAME; - private final static String ORGAUTHORITIES_COMMON = "orgauthorities_common"; - - private final static String organizationServiceName = "organizations"; - private final static String ORGANIZATIONS_COMMON = "organizations_common"; - final Logger logger = LoggerFactory.getLogger(OrgAuthorityResource.class); public OrgAuthorityResource() { - super(OrgauthoritiesCommon.class, OrgAuthorityResource.class, - ORGAUTHORITIES_COMMON, ORGANIZATIONS_COMMON); + super(OrgauthoritiesCommon.class, OrgAuthorityResource.class, + OrgAuthorityClient.SERVICE_COMMON_PART_NAME, OrgAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME); } @Override public String getServiceName() { - return orgAuthorityServiceName; - } - - public String getItemServiceName() { - return organizationServiceName; + return OrgAuthorityClient.SERVICE_NAME; } @Override - public Class getCommonPartClass() { - return OrgauthoritiesCommon.class; + public String getItemServiceName() { + return OrgAuthorityClient.SERVICE_ITEM_NAME; } - + @Override public String getItemTermInfoGroupXPathBase() { return OrgAuthorityClient.TERM_INFO_GROUP_XPATH_BASE; diff --git a/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java b/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java index 7da7f2828..2724e8be8 100644 --- a/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java +++ b/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java @@ -1,49 +1,52 @@ /** - * 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. + * 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.person; +import javax.ws.rs.Consumes; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; import org.collectionspace.services.client.PersonAuthorityClient; import org.collectionspace.services.contact.AuthorityResourceWithContacts; import org.collectionspace.services.person.nuxeo.PersonDocumentModelHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.ws.rs.Consumes; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - +/** + * PersonAuthorityResource + * + * Handles, dispatches, and returns responses to RESTful requests related to + * Person authority-related resources. + */ @Path(PersonAuthorityClient.SERVICE_PATH) @Consumes("application/xml") @Produces("application/xml") -public class PersonAuthorityResource extends - AuthorityResourceWithContacts { +public class PersonAuthorityResource extends AuthorityResourceWithContacts { final Logger logger = LoggerFactory.getLogger(PersonAuthorityResource.class); public PersonAuthorityResource() { - super(PersonauthoritiesCommon.class, PersonAuthorityResource.class, - PersonAuthorityClient.SERVICE_COMMON_PART_NAME, PersonAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME); + super(PersonauthoritiesCommon.class, PersonAuthorityResource.class, + PersonAuthorityClient.SERVICE_COMMON_PART_NAME, PersonAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME); } @Override @@ -55,7 +58,7 @@ public class PersonAuthorityResource extends public String getItemServiceName() { return PersonAuthorityClient.SERVICE_ITEM_NAME; } - + @Override public String getItemTermInfoGroupXPathBase() { return PersonAuthorityClient.TERM_INFO_GROUP_XPATH_BASE; @@ -63,7 +66,6 @@ public class PersonAuthorityResource extends @Override public Class getCommonPartClass() { - return PersonauthoritiesCommon.class; + return PersonauthoritiesCommon.class; } - } diff --git a/services/place/3rdparty/nuxeo-platform-cs-place/src/main/resources/schemas/places_common.xsd b/services/place/3rdparty/nuxeo-platform-cs-place/src/main/resources/schemas/places_common.xsd index 393891143..3fbf0ecf6 100644 --- a/services/place/3rdparty/nuxeo-platform-cs-place/src/main/resources/schemas/places_common.xsd +++ b/services/place/3rdparty/nuxeo-platform-cs-place/src/main/resources/schemas/places_common.xsd @@ -12,11 +12,11 @@ --> @@ -24,21 +24,24 @@ - - - - - + + + + + + + + - + + + - - - + @@ -59,7 +62,7 @@ - + @@ -91,9 +95,9 @@ - - - + + + @@ -121,7 +125,7 @@ - + + + + + + + + + + + + + + + + + + + + diff --git a/services/place/client/src/main/java/org/collectionspace/services/client/PlaceAuthorityClient.java b/services/place/client/src/main/java/org/collectionspace/services/client/PlaceAuthorityClient.java index 403969746..6845c36ee 100644 --- a/services/place/client/src/main/java/org/collectionspace/services/client/PlaceAuthorityClient.java +++ b/services/place/client/src/main/java/org/collectionspace/services/client/PlaceAuthorityClient.java @@ -1,25 +1,14 @@ -/** - * PlaceAuthorityClient.java - * - * {Purpose of This Class} - * - * {Other Notes Relating to This Class (Optional)} - * - * $LastChangedBy: $ - * $LastChangedRevision: $ - * $LastChangedDate: $ - * - * 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: +/** + * 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 + * http://www.collectionspace.org http://wiki.collectionspace.org * - * Copyright © 2009 {Contributing Institution} + * Copyright © 2009 The Regents of the University of California * - * Licensed under the Educational Community License (ECL), Version 2.0. - * You may not use this file except in compliance with this License. + * 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 @@ -27,32 +16,34 @@ package org.collectionspace.services.client; import org.collectionspace.services.place.PlacesCommon; + /** * The Class PlaceAuthorityClient. */ public class PlaceAuthorityClient extends AuthorityClientImpl { - public static final String SERVICE_NAME = "placeauthorities"; - public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; - public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT; - public static final String SERVICE_PAYLOAD_NAME = SERVICE_NAME; - public static final String TERM_INFO_GROUP_XPATH_BASE = "placeTermGroup"; - // - // Subitem constants - // - public static final String SERVICE_ITEM_NAME = "places"; - public static final String SERVICE_ITEM_PAYLOAD_NAME = SERVICE_ITEM_NAME; - // - // Payload Part/Schema part names - // - public static final String SERVICE_COMMON_PART_NAME = SERVICE_NAME + - PART_LABEL_SEPARATOR + PART_COMMON_LABEL; - public static final String SERVICE_ITEM_COMMON_PART_NAME = SERVICE_ITEM_NAME + - PART_LABEL_SEPARATOR + PART_COMMON_LABEL; - - @Override - public String getServiceName() { - return SERVICE_NAME; - } + + public static final String SERVICE_NAME = "placeauthorities"; + public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; + public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT; + public static final String SERVICE_PAYLOAD_NAME = SERVICE_NAME; + public static final String TERM_INFO_GROUP_XPATH_BASE = "placeTermGroupList"; + // + // Subitem constants + // + public static final String SERVICE_ITEM_NAME = "places"; + public static final String SERVICE_ITEM_PAYLOAD_NAME = SERVICE_ITEM_NAME; + // + // Payload Part/Schema part names + // + public static final String SERVICE_COMMON_PART_NAME = SERVICE_NAME + + PART_LABEL_SEPARATOR + PART_COMMON_LABEL; + public static final String SERVICE_ITEM_COMMON_PART_NAME = SERVICE_ITEM_NAME + + PART_LABEL_SEPARATOR + PART_COMMON_LABEL; + + @Override + public String getServiceName() { + return SERVICE_NAME; + } @Override public String getServicePathComponent() { @@ -66,16 +57,16 @@ public class PlaceAuthorityClient extends AuthorityClientImpl getProxyClass() { - return PlaceAuthorityProxy.class; + return PlaceAuthorityProxy.class; } @Override public String getInAuthority(PlacesCommon item) { - return item.getInAuthority(); + return item.getInAuthority(); } @Override public void setInAuthority(PlacesCommon item, String inAuthorityCsid) { - item.setInAuthority(inAuthorityCsid); + item.setInAuthority(inAuthorityCsid); } } diff --git a/services/place/client/src/main/java/org/collectionspace/services/client/PlaceAuthorityClientUtils.java b/services/place/client/src/main/java/org/collectionspace/services/client/PlaceAuthorityClientUtils.java index 75a6138a4..7341c4b3c 100644 --- a/services/place/client/src/main/java/org/collectionspace/services/client/PlaceAuthorityClientUtils.java +++ b/services/place/client/src/main/java/org/collectionspace/services/client/PlaceAuthorityClientUtils.java @@ -2,20 +2,19 @@ package org.collectionspace.services.client; import java.io.File; import java.util.ArrayList; -import java.util.Arrays; +import java.util.Date; import java.util.List; import java.util.Map; - import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; - import org.apache.commons.io.FileUtils; import org.collectionspace.services.PlaceJAXBSchema; import org.collectionspace.services.client.test.ServiceRequestType; +import org.collectionspace.services.common.api.Tools; +import org.collectionspace.services.place.PlaceTermGroup; +import org.collectionspace.services.place.PlaceTermGroupList; import org.collectionspace.services.place.PlaceauthoritiesCommon; -import org.collectionspace.services.place.PlaceNameGroup; -import org.collectionspace.services.place.PlaceNameGroupList; import org.collectionspace.services.place.PlacesCommon; import org.dom4j.DocumentException; import org.jboss.resteasy.client.ClientResponse; @@ -62,37 +61,19 @@ public class PlaceAuthorityClientUtils { */ public static PoxPayloadOut createPlaceInstance( String placeAuthRefName, Map placeInfo, - String headerLabel){ + List terms, String headerLabel){ PlacesCommon place = new PlacesCommon(); String shortId = placeInfo.get(PlaceJAXBSchema.SHORT_IDENTIFIER); - String displayName = placeInfo.get(PlaceJAXBSchema.DISPLAY_NAME); place.setShortIdentifier(shortId); - String placeRefName = createPlaceRefName(placeAuthRefName, shortId, displayName); - place.setRefName(placeRefName); - String value = null; - value = placeInfo.get(PlaceJAXBSchema.DISPLAY_NAME_COMPUTED); - boolean displayNameComputed = (value==null) || value.equalsIgnoreCase("true"); - place.setDisplayNameComputed(displayNameComputed); - if((value = (String)placeInfo.get(PlaceJAXBSchema.DISPLAY_NAME))!=null) - place.setDisplayName(value); - value = placeInfo.get(PlaceJAXBSchema.DISPLAY_NAME_COMPUTED); - displayNameComputed = (value==null) || value.equalsIgnoreCase("true"); - place.setDisplayNameComputed(displayNameComputed); - /* TODO - think about how much to support. This approach to the client - * does not scale! We should really favor the document/payload approach. */ - if((value = (String)placeInfo.get(PlaceJAXBSchema.PLACE_NAME))!=null) { - PlaceNameGroupList placeNameGroupList = new PlaceNameGroupList(); - List placeNameGroups = placeNameGroupList.getPlaceNameGroup(); - PlaceNameGroup placeNameGroup = new PlaceNameGroup(); - placeNameGroup.setPlaceName(value); - placeNameGroups.add(placeNameGroup); - place.setPlaceNameGroupList(placeNameGroupList); + + // Set values in the Term Information Group + PlaceTermGroupList termList = new PlaceTermGroupList(); + if (terms == null || terms.isEmpty()) { + terms = getTermGroupInstance(getGeneratedIdentifier()); } + termList.getPlaceTermGroup().addAll(terms); + place.setPlaceTermGroupList(termList); - - if((value = (String)placeInfo.get(PlaceJAXBSchema.TERM_STATUS))!=null) - place.setTermStatus(value); - PoxPayloadOut multipart = new PoxPayloadOut(PlaceAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); PayloadOutputPart commonPart = multipart.addPart(place, MediaType.APPLICATION_XML_TYPE); @@ -106,7 +87,7 @@ public class PlaceAuthorityClientUtils { } /** - * @param vcsid CSID of the authority to create a new placplace + * @param vcsid CSID of the authority to create a new place * @param placeAuthorityRefName The refName for the authority * @param placeMap the properties for the new Place * @param client the service client @@ -114,34 +95,23 @@ public class PlaceAuthorityClientUtils { */ public static String createItemInAuthority(String vcsid, String placeAuthorityRefName, Map placeMap, - PlaceAuthorityClient client ) { + List terms, PlaceAuthorityClient client ) { // Expected status code: 201 Created int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode(); // Type of service request being tested ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE; - String displayName = placeMap.get(PlaceJAXBSchema.DISPLAY_NAME); - String displayNameComputedStr = placeMap.get(PlaceJAXBSchema.DISPLAY_NAME_COMPUTED); - boolean displayNameComputed = (displayNameComputedStr==null) || displayNameComputedStr.equalsIgnoreCase("true"); - if( displayName == null ) { - if(!displayNameComputed) { - throw new RuntimeException( - "CreateItem: Must supply a displayName if displayNameComputed is set to false."); - } - /* Could try to pull name out of first placeNameGroup - displayName = - prepareDefaultDisplayName( - placeMap.get(PlaceJAXBSchema.PLACE_NAME)); - */ - } - + String displayName = ""; + if ((terms !=null) && (! terms.isEmpty())) { + displayName = terms.get(0).getTermDisplayName(); + } if(logger.isDebugEnabled()){ - logger.debug("Import: Create Item: \""+displayName - +"\" in placeAuthority: \"" + placeAuthorityRefName +"\""); + logger.debug("Creating item with display name: \"" + displayName + +"\" in locationAuthority: \"" + vcsid +"\""); } PoxPayloadOut multipart = createPlaceInstance( placeAuthorityRefName, - placeMap, client.getItemCommonPartName() ); + placeMap, terms, client.getItemCommonPartName() ); String newID = null; ClientResponse res = client.createItem(vcsid, multipart); try { @@ -305,6 +275,20 @@ public class PlaceAuthorityClientUtils { return newStr.toString(); } - - + public static List getTermGroupInstance(String identifier) { + if (Tools.isBlank(identifier)) { + identifier = getGeneratedIdentifier(); + } + List terms = new ArrayList(); + PlaceTermGroup term = new PlaceTermGroup(); + term.setTermDisplayName(identifier); + term.setTermName(identifier); + terms.add(term); + return terms; + } + + private static String getGeneratedIdentifier() { + return "id" + new Date().getTime(); + } + } diff --git a/services/place/client/src/test/java/org/collectionspace/services/client/test/PlaceAuthorityServiceTest.java b/services/place/client/src/test/java/org/collectionspace/services/client/test/PlaceAuthorityServiceTest.java index 39cdd1297..07c45e14b 100644 --- a/services/place/client/src/test/java/org/collectionspace/services/client/test/PlaceAuthorityServiceTest.java +++ b/services/place/client/src/test/java/org/collectionspace/services/client/test/PlaceAuthorityServiceTest.java @@ -25,7 +25,6 @@ package org.collectionspace.services.client.test; import java.util.HashMap; import java.util.List; import java.util.Map; - import org.collectionspace.services.PlaceJAXBSchema; import org.collectionspace.services.client.AbstractCommonListUtils; import org.collectionspace.services.client.AuthorityClient; @@ -38,14 +37,9 @@ import org.collectionspace.services.client.PlaceAuthorityClientUtils; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.place.PlaceauthoritiesCommon; import org.collectionspace.services.place.PlacesCommon; -import org.collectionspace.services.place.PlaceNameGroup; -import org.collectionspace.services.place.PlaceNameGroupList; - import org.jboss.resteasy.client.ClientResponse; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; @@ -140,7 +134,7 @@ public class PlaceAuthorityServiceTest extends AbstractAuthorityServiceTest res = client.readItem(knownResourceId, knownItemResourceId); - PlacesCommon place = null; - try { - assertStatusCode(res, testName); - // Check whether place has expected displayName. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - place = (PlacesCommon) extractPart(input, - client.getItemCommonPartName(), PlacesCommon.class); - Assert.assertNotNull(place); - } finally { - if (res != null) { - res.releaseConnection(); - } - } - // - // Now prepare an updated payload. - // - String displayName = place.getDisplayName(); - // Make sure displayName matches computed form - String expectedDisplayName = - PlaceAuthorityClientUtils.prepareDefaultDisplayName(TEST_NAME); - Assert.assertNotNull(displayName, expectedDisplayName); - - // Update the shortName and verify the computed name is updated. - place.setCsid(null); - place.setDisplayNameComputed(true); - - // Verify the contents of this resource - PlaceNameGroupList placeNameGroupList = place.getPlaceNameGroupList(); - Assert.assertNotNull(placeNameGroupList); - List placeNameGroups = placeNameGroupList.getPlaceNameGroup(); - Assert.assertNotNull(placeNameGroups); - Assert.assertTrue(placeNameGroups.size() > 0); - String placeName = placeNameGroups.get(0).getPlaceName(); - Assert.assertNotNull(placeName); - - // Update the contents of this resource. - final String PLACE_NAME_ADDITION = "verify-item-place-name-updated"; - placeNameGroups.get(0).setPlaceName(PLACE_NAME_ADDITION + TEST_NAME); - place.setPlaceNameGroupList(placeNameGroupList); - if (logger.isDebugEnabled()) { - logger.debug("to be updated Place"); - logger.debug(objectAsXmlString(place, - PlacesCommon.class)); - } - expectedDisplayName = - PlaceAuthorityClientUtils.prepareDefaultDisplayName(PLACE_NAME_ADDITION + TEST_NAME); - - // Submit the updated resource to the service and store the response. - PoxPayloadOut output = new PoxPayloadOut(PlaceAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); - PayloadOutputPart commonPart = output.addPart(client.getItemCommonPartName(), place); - - setupUpdate(); - res = client.updateItem(knownResourceId, knownItemResourceId, output); - PlacesCommon updatedPlace = null; - try { - assertStatusCode(res, testName); - // Retrieve the updated resource and verify that its contents exist. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - updatedPlace = (PlacesCommon) extractPart(input, - client.getItemCommonPartName(), PlacesCommon.class); - Assert.assertNotNull(updatedPlace); - } finally { - if (res != null) { - res.releaseConnection(); - } - } - - // Verify that the updated resource computes the right displayName. - Assert.assertEquals(updatedPlace.getDisplayName(), expectedDisplayName, - "Updated DisplayName in Place not reflected in computed DisplayName."); - // - // Now Update the displayName, not computed and verify the computed name is overriden. - // - place.setDisplayNameComputed(false); - expectedDisplayName = "TestName"; - place.setDisplayName(expectedDisplayName); - - // Submit the updated resource to the service and store the response. - output = new PoxPayloadOut(PlaceAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); - commonPart = output.addPart(client.getItemCommonPartName(), place); - setupUpdate(); - res = client.updateItem(knownResourceId, knownItemResourceId, output); - try { - assertStatusCode(res, testName); - // Retrieve the updated resource and verify that its contents exist. - PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); - updatedPlace = (PlacesCommon) extractPart(input, - client.getItemCommonPartName(), PlacesCommon.class); - Assert.assertNotNull(updatedPlace); - } finally { - if (res != null) { - res.releaseConnection(); - } - } - - // Verify that the updated resource received the correct data. - Assert.assertEquals(updatedPlace.isDisplayNameComputed(), false, - "Updated displayNameComputed in Place did not match submitted data."); - // Verify that the updated resource computes the right displayName. - Assert.assertEquals(updatedPlace.getDisplayName(), - expectedDisplayName, - "Updated DisplayName (not computed) in Place not stored."); - } - /** * Verify illegal item display name. * * @param testName the test name * @throws Exception the exception */ - @Test(dataProvider="testName", - dependsOnMethods = {"verifyItemDisplayName"}) + @Test(dataProvider="testName") public void verifyIllegalItemDisplayName(String testName) throws Exception { // Perform setup for read. setupRead(); diff --git a/services/place/jaxb/src/main/resources/place_common.xsd b/services/place/jaxb/src/main/resources/place_common.xsd index ca9e6219b..36257ecda 100644 --- a/services/place/jaxb/src/main/resources/place_common.xsd +++ b/services/place/jaxb/src/main/resources/place_common.xsd @@ -7,7 +7,7 @@ xmlns="http://collectionspace.org/services/place" targetNamespace="http://collectionspace.org/services/place" version="0.1" - > +> @@ -18,51 +18,51 @@ - + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - + + @@ -124,7 +125,7 @@ - + + + + + + + + + + + + + + + + + + + diff --git a/services/place/service/src/main/java/org/collectionspace/services/place/PlaceAuthorityResource.java b/services/place/service/src/main/java/org/collectionspace/services/place/PlaceAuthorityResource.java index 9f63d0b1d..0e432f056 100644 --- a/services/place/service/src/main/java/org/collectionspace/services/place/PlaceAuthorityResource.java +++ b/services/place/service/src/main/java/org/collectionspace/services/place/PlaceAuthorityResource.java @@ -1,74 +1,69 @@ /** - * 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. + * 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.place; +import javax.ws.rs.Consumes; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; import org.collectionspace.services.client.PlaceAuthorityClient; import org.collectionspace.services.common.vocabulary.AuthorityResource; import org.collectionspace.services.place.nuxeo.PlaceDocumentModelHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.ws.rs.Consumes; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; +/** + * PlaceAuthorityResource + * + * Handles, dispatches, and returns responses to RESTful requests + * related to Place authority-related resources. + */ @Path(PlaceAuthorityClient.SERVICE_PATH) @Consumes("application/xml") @Produces("application/xml") -public class PlaceAuthorityResource - extends AuthorityResource { +public class PlaceAuthorityResource + extends AuthorityResource { - private final static String placeAuthorityServiceName = "placeauthorities"; - private final static String PLACEAUTHORITIES_COMMON = "placeauthorities_common"; - - private final static String placeServiceName = "places"; - private final static String PLACES_COMMON = "places_common"; - final Logger logger = LoggerFactory.getLogger(PlaceAuthorityResource.class); public PlaceAuthorityResource() { - super(PlaceauthoritiesCommon.class, PlaceAuthorityResource.class, - PLACEAUTHORITIES_COMMON, PLACES_COMMON); + super(PlaceauthoritiesCommon.class, PlaceAuthorityResource.class, + PlaceAuthorityClient.SERVICE_COMMON_PART_NAME, PlaceAuthorityClient.SERVICE_ITEM_COMMON_PART_NAME); } @Override public String getServiceName() { - return placeAuthorityServiceName; + return PlaceAuthorityClient.SERVICE_NAME; } + @Override public String getItemServiceName() { - return placeServiceName; + return PlaceAuthorityClient.SERVICE_ITEM_NAME; } @Override - public Class getCommonPartClass() { - return PlaceauthoritiesCommon.class; + public String getItemTermInfoGroupXPathBase() { + return PlaceAuthorityClient.TERM_INFO_GROUP_XPATH_BASE; } - @Override - public String getItemTermInfoGroupXPathBase() { - return PlaceAuthorityClient.TERM_INFO_GROUP_XPATH_BASE; - } } -- 2.47.3