From: Aron Roberts Date: Mon, 7 May 2012 19:31:41 +0000 (-0700) Subject: CSPACE-5121,CSPACE-4844,CSPACE-5137: Updated Storage Location schema with repeatable... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=c5bc5ad843838966f2a79e862db3db1b9b4ab10a;p=tmp%2Fjakarta-migration.git CSPACE-5121,CSPACE-4844,CSPACE-5137: Updated Storage Location schema with repeatable term info group. Location now builds if tests aren't compiled; e.g. via 'mvn install -Dmaven.test.skip=true'. Minor updates to client utils, validator handlers in Person and Org, for consistency across all authority services. --- diff --git a/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locations_common.xsd b/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locations_common.xsd index d0c24796d..88c1fe827 100644 --- a/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locations_common.xsd +++ b/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locations_common.xsd @@ -6,39 +6,31 @@ Entity : Location Part : Common Used for: Nuxeo EP core document type - - $LastChangedRevision: 860 $ - $LastChangedDate: 2009-10-14 14:48:05 -0700 (Wed, 14 Oct 2009) $ --> - + - - - - - - - - + + + + + + - - - @@ -48,8 +40,33 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 26270907f..9fe643945 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,25 +1,22 @@ -/** +/** * LocationAuthorityClient.java * * {Purpose of This Class} * * {Other Notes Relating to This Class (Optional)} * - * $LastChangedBy: $ - * $LastChangedRevision: $ - * $LastChangedDate: $ + * $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} * - * 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 @@ -32,28 +29,29 @@ import org.collectionspace.services.location.LocationsCommon; * The Class LocationAuthorityClient. */ public class LocationAuthorityClient extends AuthorityClientImpl { - public static final String SERVICE_NAME = "locationauthorities"; - 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 = "locationTermGroup"; - // - // Subitem constants - // - public static final String SERVICE_ITEM_NAME = "locations"; - 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 = "locationauthorities"; + 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 = "locTermGroupList"; + // + // Subitem constants + // + public static final String SERVICE_ITEM_NAME = "locations"; + 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() { @@ -65,18 +63,18 @@ public class LocationAuthorityClient extends AuthorityClientImpl getProxyClass() { - return LocationAuthorityProxy.class; - } + @Override + public Class getProxyClass() { + return LocationAuthorityProxy.class; + } - @Override - public String getInAuthority(LocationsCommon item) { - return item.getInAuthority(); - } + @Override + public String getInAuthority(LocationsCommon item) { + return item.getInAuthority(); + } - @Override - public void setInAuthority(LocationsCommon item, String inAuthorityCsid) { - item.setInAuthority(inAuthorityCsid); - } + @Override + public void setInAuthority(LocationsCommon item, String inAuthorityCsid) { + item.setInAuthority(inAuthorityCsid); + } } 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 649004550..992cedae8 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 @@ -2,20 +2,16 @@ package org.collectionspace.services.client; import java.io.File; import java.util.ArrayList; +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.LocationJAXBSchema; import org.collectionspace.services.client.test.ServiceRequestType; -import org.collectionspace.services.location.LocationsCommon; -import org.collectionspace.services.location.ConditionGroupList; -import org.collectionspace.services.location.ConditionGroup; -import org.collectionspace.services.location.LocationauthoritiesCommon; +import org.collectionspace.services.location.*; import org.dom4j.DocumentException; import org.jboss.resteasy.client.ClientResponse; import org.slf4j.Logger; @@ -62,7 +58,7 @@ public class LocationAuthorityClientUtils { */ public static PoxPayloadOut createLocationInstance( String locationAuthRefName, Map locationInfo, - String headerLabel){ + List terms, String headerLabel){ LocationsCommon location = new LocationsCommon(); String shortId = locationInfo.get(LocationJAXBSchema.SHORT_IDENTIFIER); String displayName = locationInfo.get(LocationJAXBSchema.DISPLAY_NAME); @@ -71,10 +67,16 @@ public class LocationAuthorityClientUtils { // location.setRefName(locationRefName); String value = null; value = locationInfo.get(LocationJAXBSchema.DISPLAY_NAME_COMPUTED); - boolean displayNameComputed = (value==null) || value.equalsIgnoreCase("true"); - location.setDisplayNameComputed(displayNameComputed); - if((value = (String)locationInfo.get(LocationJAXBSchema.NAME))!=null) - location.setName(value); + boolean displayNameComputed = (value==null) || value.equalsIgnoreCase("true"); + + // Set values in the Term Information Group + LocTermGroupList termList = new LocTermGroupList(); + if (terms == null || terms.isEmpty()) { + terms = getTermGroupInstance(getGeneratedIdentifier()); + } + termList.getLocTermGroup().addAll(terms); + location.setLocTermGroupList(termList); + if((value = (String)locationInfo.get(LocationJAXBSchema.CONDITION_NOTE))!=null) { ConditionGroupList conditionGroupList = new ConditionGroupList(); List conditionGroups = conditionGroupList.getConditionGroup(); @@ -93,8 +95,6 @@ public class LocationAuthorityClientUtils { location.setLocationType(value); if((value = (String)locationInfo.get(LocationJAXBSchema.ADDRESS))!=null) location.setAddress(value); - if((value = (String)locationInfo.get(LocationJAXBSchema.TERM_STATUS))!=null) - location.setTermStatus(value); PoxPayloadOut multipart = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME); PayloadOutputPart commonPart = multipart.addPart(location, @@ -117,32 +117,25 @@ public class LocationAuthorityClientUtils { */ public static String createItemInAuthority(String vcsid, String locationAuthorityRefName, Map locationMap, - LocationAuthorityClient client ) { + List terms, LocationAuthorityClient 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 = locationMap.get(LocationJAXBSchema.DISPLAY_NAME); - String displayNameComputedStr = locationMap.get(LocationJAXBSchema.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."); - } - displayName = - prepareDefaultDisplayName( - locationMap.get(LocationJAXBSchema.NAME)); - } + + String displayName = ""; + if (terms !=null && terms.size() > 0) { + displayName = terms.get(0).getTermDisplayName(); + } if(logger.isDebugEnabled()){ - logger.debug("Import: Create Item: \""+displayName - +"\" in locationAuthority: \"" + locationAuthorityRefName +"\""); + logger.debug("Creating item with display name: \"" + displayName + +"\" in locationAuthority: \"" + vcsid +"\""); } + PoxPayloadOut multipart = createLocationInstance( locationAuthorityRefName, - locationMap, client.getItemCommonPartName() ); + locationMap, terms, client.getItemCommonPartName() ); String newID = null; ClientResponse res = client.createItem(vcsid, multipart); try { @@ -306,6 +299,17 @@ public class LocationAuthorityClientUtils { return newStr.toString(); } - + public static List getTermGroupInstance(String identifier) { + List terms = new ArrayList(); + LocTermGroup term = new LocTermGroup(); + term.setTermDisplayName(identifier); + term.setTermName(identifier); + terms.add(term); + return terms; + } + + private static String getGeneratedIdentifier() { + return "id" + new Date().getTime(); + } } diff --git a/services/location/jaxb/src/main/resources/location_common.xsd b/services/location/jaxb/src/main/resources/location_common.xsd index a6f77b668..eaa7294b2 100644 --- a/services/location/jaxb/src/main/resources/location_common.xsd +++ b/services/location/jaxb/src/main/resources/location_common.xsd @@ -7,7 +7,7 @@ xmlns="http://collectionspace.org/services/location" targetNamespace="http://collectionspace.org/services/location" version="0.1" - > +> @@ -21,22 +21,18 @@ + - - - - - - - - - - - + + + + + + @@ -50,8 +46,33 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationValidatorHandler.java b/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationValidatorHandler.java index 5c120d5f4..0c6345969 100644 --- a/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationValidatorHandler.java +++ b/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationValidatorHandler.java @@ -23,14 +23,14 @@ */ package org.collectionspace.services.location.nuxeo; +import java.util.List; import java.util.regex.Pattern; - -import org.collectionspace.services.location.LocationsCommon; -import org.collectionspace.services.common.context.MultipartServiceContext; -import org.collectionspace.services.common.context.ServiceContext; -import org.collectionspace.services.common.document.DocumentHandler.Action; +import org.collectionspace.services.common.api.Tools; import org.collectionspace.services.common.document.InvalidDocumentException; -import org.collectionspace.services.common.document.ValidatorHandler; +import org.collectionspace.services.common.document.ValidatorHandlerImpl; +import org.collectionspace.services.location.LocTermGroup; +import org.collectionspace.services.location.LocTermGroupList; +import org.collectionspace.services.location.LocationsCommon; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,63 +38,108 @@ import org.slf4j.LoggerFactory; * LocationValidatorHandler * * Validates data supplied when attempting to create and/or update Location records. - * - * $LastChangedRevision: $ - * $LastChangedDate: $ */ -public class LocationValidatorHandler implements ValidatorHandler { +public class LocationValidatorHandler extends ValidatorHandlerImpl { final Logger logger = LoggerFactory.getLogger(LocationValidatorHandler.class); - private static final Pattern shortIdBadPattern = Pattern.compile("[\\W]"); //.matcher(input).matches() + // 'Bad pattern' for shortIdentifiers matches any non-word characters + private static final Pattern SHORT_ID_BAD_PATTERN = Pattern.compile("[\\W]"); //.matcher(input).matches() + private static final String VALIDATION_ERROR = "The record payload was invalid. See log file for more details."; + private static final String SHORT_ID_BAD_CHARS_ERROR = + "shortIdentifier must only contain standard word characters"; + private static final String HAS_NO_TERMS_ERROR = + "Authority items must contain at least one term."; + private static final String HAS_AN_EMPTY_TERM_ERROR = + "Each term group in an authority item must contain " + + "a non-empty term name or " + + "a non-empty term display name."; @Override - public void validate(Action action, ServiceContext ctx) - throws InvalidDocumentException { - if (logger.isDebugEnabled()) { - logger.debug("validate() action=" + action.name()); - } - - // Bail out if the validation action is for delete. - if (action.equals(Action.DELETE)) { - return; - } - - try { - MultipartServiceContext mctx = (MultipartServiceContext) ctx; - LocationsCommon location = (LocationsCommon) mctx.getInputPart(mctx.getCommonPartLabel(), - LocationsCommon.class); - String msg = ""; - boolean invalid = false; - - // Validation occurring on both creates and updates - String displayName = location.getDisplayName(); - if (!location.isDisplayNameComputed() && ((displayName == null) || displayName.trim().isEmpty())) { - invalid = true; - msg += "displayName must be non-null and non-blank if displayNameComputed is false"; - } + protected Class getCommonPartClass() { + return LocationsCommon.class; + } - // Validation specific to creates or updates - if (action.equals(Action.CREATE)) { + @Override + protected void handleCreate() throws InvalidDocumentException { + LocationsCommon location = (LocationsCommon) getCommonPart(); + // No guarantee that there is a common part in every post/update. + if (location != null) { + try { String shortId = location.getShortIdentifier(); - // Per CSPACE-2215, shortIdentifier values that are null (missing) - // oe the empty string are now legally accepted in create payloads. - // In either of those cases, a short identifier will be synthesized from - // a display name or supplied in another manner. - if ((shortId != null) && (shortIdBadPattern.matcher(shortId).find())) { - invalid = true; - msg += "shortIdentifier must only contain standard word characters"; + if (shortId != null) { + CS_ASSERT(shortIdentifierContainsOnlyValidChars(shortId), SHORT_ID_BAD_CHARS_ERROR); + } + CS_ASSERT(containsAtLeastOneTerm(location), HAS_NO_TERMS_ERROR); + CS_ASSERT(allTermsContainNameOrDisplayName(location), HAS_AN_EMPTY_TERM_ERROR); + } catch (AssertionError e) { + if (logger.isErrorEnabled()) { + logger.error(e.getMessage(), e); + } + throw new InvalidDocumentException(VALIDATION_ERROR, e); + } + } + } + + @Override + protected void handleGet() throws InvalidDocumentException { + } + + @Override + protected void handleGetAll() throws InvalidDocumentException { + } + + @Override + protected void handleUpdate() throws InvalidDocumentException { + LocationsCommon location = (LocationsCommon) getCommonPart(); + // No guarantee that there is a common part in every post/update. + if (location != null) { + try { + // shortIdentifier is among a set of fields that are + // prevented from being changed on an update, and thus + // we don't need to check its value here. + CS_ASSERT(containsAtLeastOneTerm(location), HAS_NO_TERMS_ERROR); + CS_ASSERT(allTermsContainNameOrDisplayName(location), HAS_AN_EMPTY_TERM_ERROR); + } catch (AssertionError e) { + if (logger.isErrorEnabled()) { + logger.error(e.getMessage(), e); } - } else if (action.equals(Action.UPDATE)) { + throw new InvalidDocumentException(VALIDATION_ERROR, e); } + } + } + + @Override + protected void handleDelete() throws InvalidDocumentException { + } + + private boolean shortIdentifierContainsOnlyValidChars(String shortId) { + // Check whether any characters match the 'bad' pattern + if (SHORT_ID_BAD_PATTERN.matcher(shortId).find()) { + return false; + } + return true; + } + + private boolean containsAtLeastOneTerm(LocationsCommon person) { + LocTermGroupList termGroupList = person.getLocTermGroupList(); + if (termGroupList == null) { + return false; + } + List termGroups = termGroupList.getLocTermGroup(); + if ((termGroups == null) || (termGroups.isEmpty())) { + return false; + } + return true; + } - if (invalid) { - logger.error(msg); - throw new InvalidDocumentException(msg); + private boolean allTermsContainNameOrDisplayName(LocationsCommon person) { + LocTermGroupList termGroupList = person.getLocTermGroupList(); + List termGroups = termGroupList.getLocTermGroup(); + for (LocTermGroup termGroup : termGroups) { + if (Tools.isBlank(termGroup.getTermName()) || Tools.isBlank(termGroup.getTermDisplayName())) { + return false; } - } catch (InvalidDocumentException ide) { - throw ide; - } catch (Exception e) { - throw new InvalidDocumentException(e); } + return true; } -} +} \ No newline at end of file diff --git a/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java index 79f5f5f0b..eab94bc62 100644 --- a/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java +++ b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java @@ -1,25 +1,22 @@ -/** +/** * OrgAuthorityClient.java * * {Purpose of This Class} * * {Other Notes Relating to This Class (Optional)} * - * $LastChangedBy: $ - * $LastChangedRevision$ - * $LastChangedDate$ + * $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} * - * 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 @@ -32,51 +29,52 @@ import org.collectionspace.services.organization.OrganizationsCommon; * The Class OrgAuthorityClient. */ public class OrgAuthorityClient extends AuthorityWithContactsClientImpl { - public static final String SERVICE_NAME = "orgauthorities"; - 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 SERVICE_NAME = "orgauthorities"; + 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 = "orgTermGroupList"; - // - // Subitem constants - // - public static final String SERVICE_ITEM_NAME = "organizations"; - 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; - + // + // Subitem constants + // + public static final String SERVICE_ITEM_NAME = "organizations"; + 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 getServiceName() { - return SERVICE_NAME; - } - - @Override public String getServicePathComponent() { return SERVICE_PATH_COMPONENT; } - - @Override - public Class getProxyClass() { - return OrgAuthorityProxy.class; - } - - @Override + + @Override + public Class getProxyClass() { + return OrgAuthorityProxy.class; + } + + @Override public String getItemCommonPartName() { return getCommonPartName(SERVICE_ITEM_NAME); } - @Override - public String getInAuthority(OrganizationsCommon item) { - return item.getInAuthority(); - } + @Override + public String getInAuthority(OrganizationsCommon item) { + return item.getInAuthority(); + } - @Override - public void setInAuthority(OrganizationsCommon item, String inAuthorityCsid) { - item.setInAuthority(inAuthorityCsid); - } + @Override + public void setInAuthority(OrganizationsCommon item, String inAuthorityCsid) { + item.setInAuthority(inAuthorityCsid); + } } 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 38a8e6cf7..8c60df3b7 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 @@ -17,14 +17,13 @@ package org.collectionspace.services.client; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; 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.collectionspace.services.OrganizationJAXBSchema; import org.collectionspace.services.client.test.ServiceRequestType; import org.collectionspace.services.organization.ContactNameList; @@ -239,7 +238,10 @@ public class OrgAuthorityClientUtils { // Set values in the Term Information Group OrgTermGroupList termList = new OrgTermGroupList(); - termList.getOrgTermGroup().addAll(terms); + if (terms == null || terms.isEmpty()) { + terms = getTermGroupInstance(getGeneratedIdentifier()); + } + termList.getOrgTermGroup().addAll(terms); organization.setOrgTermGroupList(termList); if((values = (List)orgRepeatablesInfo.get(OrganizationJAXBSchema.CONTACT_NAMES))!=null) { @@ -395,4 +397,8 @@ public class OrgAuthorityClientUtils { return terms; } + private static String getGeneratedIdentifier() { + return "id" + new Date().getTime(); + } + } diff --git a/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationValidatorHandler.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationValidatorHandler.java index 10ea216f9..524e2ee71 100644 --- a/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationValidatorHandler.java +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationValidatorHandler.java @@ -53,8 +53,6 @@ public class OrganizationValidatorHandler extends ValidatorHandlerImpl { "Each term group in an authority item must contain " + "a non-empty term name or " + "a non-empty term display name."; - boolean invalid = false; - String msg = ""; @Override protected Class getCommonPartClass() { @@ -63,16 +61,16 @@ public class OrganizationValidatorHandler extends ValidatorHandlerImpl { @Override protected void handleCreate() throws InvalidDocumentException { - OrganizationsCommon person = (OrganizationsCommon) getCommonPart(); + OrganizationsCommon organization = (OrganizationsCommon) getCommonPart(); // No guarantee that there is a common part in every post/update. - if (person != null) { + if (organization != null) { try { - String shortId = person.getShortIdentifier(); + String shortId = organization.getShortIdentifier(); if (shortId != null) { CS_ASSERT(shortIdentifierContainsOnlyValidChars(shortId), SHORT_ID_BAD_CHARS_ERROR); } - CS_ASSERT(containsAtLeastOneTerm(person), HAS_NO_TERMS_ERROR); - CS_ASSERT(allTermsContainNameOrDisplayName(person), HAS_AN_EMPTY_TERM_ERROR); + CS_ASSERT(containsAtLeastOneTerm(organization), HAS_NO_TERMS_ERROR); + CS_ASSERT(allTermsContainNameOrDisplayName(organization), HAS_AN_EMPTY_TERM_ERROR); } catch (AssertionError e) { if (logger.isErrorEnabled()) { logger.error(e.getMessage(), e); @@ -92,15 +90,15 @@ public class OrganizationValidatorHandler extends ValidatorHandlerImpl { @Override protected void handleUpdate() throws InvalidDocumentException { - OrganizationsCommon person = (OrganizationsCommon) getCommonPart(); + OrganizationsCommon organization = (OrganizationsCommon) getCommonPart(); // No guarantee that there is a common part in every post/update. - if (person != null) { + if (organization != null) { try { // shortIdentifier is among a set of fields that are // prevented from being changed on an update, and thus // we don't need to check its value here. - CS_ASSERT(containsAtLeastOneTerm(person), HAS_NO_TERMS_ERROR); - CS_ASSERT(allTermsContainNameOrDisplayName(person), HAS_AN_EMPTY_TERM_ERROR); + CS_ASSERT(containsAtLeastOneTerm(organization), HAS_NO_TERMS_ERROR); + CS_ASSERT(allTermsContainNameOrDisplayName(organization), HAS_AN_EMPTY_TERM_ERROR); } catch (AssertionError e) { if (logger.isErrorEnabled()) { logger.error(e.getMessage(), e); @@ -122,20 +120,20 @@ public class OrganizationValidatorHandler extends ValidatorHandlerImpl { return true; } - private boolean containsAtLeastOneTerm(OrganizationsCommon person) { - OrgTermGroupList termGroupList = person.getOrgTermGroupList(); + private boolean containsAtLeastOneTerm(OrganizationsCommon organization) { + OrgTermGroupList termGroupList = organization.getOrgTermGroupList(); if (termGroupList == null) { return false; } List termGroups = termGroupList.getOrgTermGroup(); - if ((termGroups == null) || (termGroups.size() == 0)) { + if ((termGroups == null) || (termGroups.isEmpty())){ return false; } return true; } - private boolean allTermsContainNameOrDisplayName(OrganizationsCommon person) { - OrgTermGroupList termGroupList = person.getOrgTermGroupList(); + private boolean allTermsContainNameOrDisplayName(OrganizationsCommon organization) { + OrgTermGroupList termGroupList = organization.getOrgTermGroupList(); List termGroups = termGroupList.getOrgTermGroup(); for (OrgTermGroup termGroup : termGroups) { if (Tools.isBlank(termGroup.getTermName()) || Tools.isBlank(termGroup.getTermDisplayName())) { diff --git a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java index ac2b502ca..47c12677f 100644 --- a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java +++ b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java @@ -1,17 +1,16 @@ -/** +/** * PersonAuthorityClient.java * - * 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 University of California, Berkeley * - * 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 @@ -24,56 +23,57 @@ import org.collectionspace.services.person.PersonsCommon; * The Class PersonAuthorityClient. */ public class PersonAuthorityClient extends AuthorityWithContactsClientImpl { - public static final String SERVICE_NAME = "personauthorities"; - 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 = "personTermGroupList"; - // - // Subitem constants - // - public static final String SERVICE_ITEM_NAME = "persons"; - 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; - + + public static final String SERVICE_NAME = "personauthorities"; + 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 = "personTermGroupList"; + // + // Subitem constants + // + public static final String SERVICE_ITEM_NAME = "persons"; + 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 getServiceName() { - return SERVICE_NAME; - } - - @Override public String getServicePathComponent() { return SERVICE_PATH_COMPONENT; } - @Override + @Override public String getItemCommonPartName() { return getCommonPartName(SERVICE_ITEM_PAYLOAD_NAME); } - - @Deprecated // Use getItemCommonPartName() instead + + @Deprecated // Use getItemCommonPartName() instead public String getCommonPartItemName() { return getCommonPartName(SERVICE_ITEM_PAYLOAD_NAME); } - - @Override - public Class getProxyClass() { - return PersonAuthorityProxy.class; - } - @Override - public String getInAuthority(PersonsCommon item) { - return item.getInAuthority(); - } + @Override + public Class getProxyClass() { + return PersonAuthorityProxy.class; + } - @Override - public void setInAuthority(PersonsCommon item, String inAuthorityCsid) { - item.setInAuthority(inAuthorityCsid); - } + @Override + public String getInAuthority(PersonsCommon item) { + return item.getInAuthority(); + } + + @Override + public void setInAuthority(PersonsCommon item, String inAuthorityCsid) { + item.setInAuthority(inAuthorityCsid); + } } diff --git a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java index 6507fbece..50563e42c 100644 --- a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java +++ b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java @@ -167,11 +167,11 @@ public class PersonAuthorityClientUtils { Map personInfo, List terms, String headerLabel){ - final Map> EMPTY_PERSON_REPEATABLES_INFO = - new HashMap>(); - if (terms == null || terms.size() == 0) { + if (terms == null || terms.isEmpty()) { terms = getTermGroupInstance(getGeneratedIdentifier()); } + final Map> EMPTY_PERSON_REPEATABLES_INFO = + new HashMap>(); return createPersonInstance(inAuthority, null /*personAuthRefName*/, personInfo, terms, EMPTY_PERSON_REPEATABLES_INFO, headerLabel); } @@ -219,10 +219,12 @@ public class PersonAuthorityClientUtils { // Set values in the Term Information Group PersonTermGroupList termList = new PersonTermGroupList(); - termList.getPersonTermGroup().addAll(terms); + if (terms == null || terms.isEmpty()) { + terms = getTermGroupInstance(getGeneratedIdentifier()); + } + termList.getPersonTermGroup().addAll(terms); person.setPersonTermGroupList(termList); - if (personRepeatablesInfo != null) { if((values = (List)personRepeatablesInfo.get(PersonJAXBSchema.GROUPS))!=null) { GroupList groupsList = new GroupList(); diff --git a/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonValidatorHandler.java b/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonValidatorHandler.java index b088b4e90..19ba74b1a 100644 --- a/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonValidatorHandler.java +++ b/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonValidatorHandler.java @@ -55,8 +55,6 @@ public class PersonValidatorHandler extends ValidatorHandlerImpl { "Each term group in an authority item must contain " + "a non-empty term name or " + "a non-empty term display name."; - boolean invalid = false; - String msg = ""; @Override protected Class getCommonPartClass() { @@ -130,7 +128,7 @@ public class PersonValidatorHandler extends ValidatorHandlerImpl { return false; } List termGroups = termGroupList.getPersonTermGroup(); - if ((termGroups == null) || (termGroups.size() == 0)) { + if ((termGroups == null) || (termGroups.isEmpty())) { return false; } return true;