From: Aron Roberts Date: Mon, 9 Jul 2012 18:21:04 +0000 (-0700) Subject: CSPACE-5227: Improved error messages when attempting to save an authority item record... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=d53194181309ac8dea3177fc340c0cd0ac1818b7;p=tmp%2Fjakarta-migration.git CSPACE-5227: Improved error messages when attempting to save an authority item record with an invalid payload, such as when containing a term with a missing display name. --- diff --git a/services/concept/service/src/main/java/org/collectionspace/services/concept/nuxeo/ConceptValidatorHandler.java b/services/concept/service/src/main/java/org/collectionspace/services/concept/nuxeo/ConceptValidatorHandler.java index 100c4cdd6..926c1bb3c 100644 --- a/services/concept/service/src/main/java/org/collectionspace/services/concept/nuxeo/ConceptValidatorHandler.java +++ b/services/concept/service/src/main/java/org/collectionspace/services/concept/nuxeo/ConceptValidatorHandler.java @@ -46,15 +46,13 @@ public class ConceptValidatorHandler extends ValidatorHandlerImpl { final Logger logger = LoggerFactory.getLogger(ConceptValidatorHandler.class); // 'Bad pattern' for shortIdentifiers matches any non-word characters private static final Pattern SHORT_ID_BAD_PATTERN = Pattern.compile("[\\W]"); - 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 TERM_HAS_EMPTY_DISPLAYNAME_ERROR = - "Each term group in an authority item must contain " - + "a non-empty term display name."; + "Each term in an authority item must contain " + + "a non-empty display name."; @Override protected Class getCommonPartClass() { @@ -77,7 +75,7 @@ public class ConceptValidatorHandler extends ValidatorHandlerImpl { if (logger.isErrorEnabled()) { logger.error(e.getMessage(), e); } - throw new InvalidDocumentException(VALIDATION_ERROR, e); + throw new InvalidDocumentException(e.getMessage(), e); } } } @@ -105,7 +103,7 @@ public class ConceptValidatorHandler extends ValidatorHandlerImpl { if (logger.isErrorEnabled()) { logger.error(e.getMessage(), e); } - throw new InvalidDocumentException(VALIDATION_ERROR, e); + throw new InvalidDocumentException(e.getMessage(), e); } } } 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 d2dc263ae..cca8f5cd4 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 @@ -46,15 +46,13 @@ public class LocationValidatorHandler extends ValidatorHandlerImpl { final Logger logger = LoggerFactory.getLogger(LocationValidatorHandler.class); // 'Bad pattern' for shortIdentifiers matches any non-word characters private static final Pattern SHORT_ID_BAD_PATTERN = Pattern.compile("[\\W]"); - 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 TERM_HAS_EMPTY_DISPLAYNAME_ERROR = - "Each term group in an authority item must contain " - + "a non-empty term display name."; + "Each term in an authority item must contain " + + "a non-empty display name."; @Override protected Class getCommonPartClass() { @@ -77,7 +75,7 @@ public class LocationValidatorHandler extends ValidatorHandlerImpl { if (logger.isErrorEnabled()) { logger.error(e.getMessage(), e); } - throw new InvalidDocumentException(VALIDATION_ERROR, e); + throw new InvalidDocumentException(e.getMessage(), e); } } } @@ -105,7 +103,7 @@ public class LocationValidatorHandler extends ValidatorHandlerImpl { if (logger.isErrorEnabled()) { logger.error(e.getMessage(), e); } - throw new InvalidDocumentException(VALIDATION_ERROR, e); + throw new InvalidDocumentException(e.getMessage(), e); } } } 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 26ae057cf..bb6c2574a 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 @@ -46,15 +46,13 @@ public class OrganizationValidatorHandler extends ValidatorHandlerImpl { final Logger logger = LoggerFactory.getLogger(OrganizationValidatorHandler.class); // 'Bad pattern' for shortIdentifiers matches any non-word characters private static final Pattern SHORT_ID_BAD_PATTERN = Pattern.compile("[\\W]"); - 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 TERM_HAS_EMPTY_DISPLAYNAME_ERROR = - "Each term group in an authority item must contain " - + "a non-empty term display name."; + "Each term in an authority item must contain " + + "a non-empty display name."; @Override protected Class getCommonPartClass() { @@ -77,7 +75,7 @@ public class OrganizationValidatorHandler extends ValidatorHandlerImpl { if (logger.isErrorEnabled()) { logger.error(e.getMessage(), e); } - throw new InvalidDocumentException(VALIDATION_ERROR, e); + throw new InvalidDocumentException(e.getMessage(), e); } } } @@ -105,7 +103,7 @@ public class OrganizationValidatorHandler extends ValidatorHandlerImpl { if (logger.isErrorEnabled()) { logger.error(e.getMessage(), e); } - throw new InvalidDocumentException(VALIDATION_ERROR, e); + throw new InvalidDocumentException(e.getMessage(), e); } } } 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 6c80dbe04..3c6f814aa 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 @@ -45,15 +45,13 @@ public class PersonValidatorHandler extends ValidatorHandlerImpl { final Logger logger = LoggerFactory.getLogger(PersonValidatorHandler.class); // 'Bad pattern' for shortIdentifiers matches any non-word characters private static final Pattern SHORT_ID_BAD_PATTERN = Pattern.compile("[\\W]"); - 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 TERM_HAS_EMPTY_DISPLAYNAME_ERROR = - "Each term group in an authority item must contain " - + "a non-empty term display name."; + "Each term in an authority item must contain " + + "a non-empty display name."; @Override protected Class getCommonPartClass() { @@ -76,7 +74,7 @@ public class PersonValidatorHandler extends ValidatorHandlerImpl { if (logger.isErrorEnabled()) { logger.error(e.getMessage(), e); } - throw new InvalidDocumentException(VALIDATION_ERROR, e); + throw new InvalidDocumentException(e.getMessage(), e); } } } @@ -104,7 +102,7 @@ public class PersonValidatorHandler extends ValidatorHandlerImpl { if (logger.isErrorEnabled()) { logger.error(e.getMessage(), e); } - throw new InvalidDocumentException(VALIDATION_ERROR, e); + throw new InvalidDocumentException(e.getMessage(), e); } } } diff --git a/services/place/service/src/main/java/org/collectionspace/services/place/nuxeo/PlaceValidatorHandler.java b/services/place/service/src/main/java/org/collectionspace/services/place/nuxeo/PlaceValidatorHandler.java index e8401602b..11995de3c 100644 --- a/services/place/service/src/main/java/org/collectionspace/services/place/nuxeo/PlaceValidatorHandler.java +++ b/services/place/service/src/main/java/org/collectionspace/services/place/nuxeo/PlaceValidatorHandler.java @@ -47,15 +47,13 @@ public class PlaceValidatorHandler extends ValidatorHandlerImpl { final Logger logger = LoggerFactory.getLogger(PlaceValidatorHandler.class); // 'Bad pattern' for shortIdentifiers matches any non-word characters private static final Pattern SHORT_ID_BAD_PATTERN = Pattern.compile("[\\W]"); - 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 TERM_HAS_EMPTY_DISPLAYNAME_ERROR = - "Each term group in an authority item must contain " - + "a non-empty term display name."; + "Each term in an authority item must contain " + + "a non-empty display name."; @Override protected Class getCommonPartClass() { @@ -78,7 +76,7 @@ public class PlaceValidatorHandler extends ValidatorHandlerImpl { if (logger.isErrorEnabled()) { logger.error(e.getMessage(), e); } - throw new InvalidDocumentException(VALIDATION_ERROR, e); + throw new InvalidDocumentException(e.getMessage(), e); } } } @@ -106,7 +104,7 @@ public class PlaceValidatorHandler extends ValidatorHandlerImpl { if (logger.isErrorEnabled()) { logger.error(e.getMessage(), e); } - throw new InvalidDocumentException(VALIDATION_ERROR, e); + throw new InvalidDocumentException(e.getMessage(), e); } } } diff --git a/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonValidatorHandler.java b/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonValidatorHandler.java index 2849df8f9..31464394a 100644 --- a/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonValidatorHandler.java +++ b/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonValidatorHandler.java @@ -46,15 +46,13 @@ public class TaxonValidatorHandler extends ValidatorHandlerImpl { final Logger logger = LoggerFactory.getLogger(TaxonValidatorHandler.class); // 'Bad pattern' for shortIdentifiers matches any non-word characters private static final Pattern SHORT_ID_BAD_PATTERN = Pattern.compile("[\\W]"); - 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 TERM_HAS_EMPTY_DISPLAYNAME_ERROR = - "Each term group in an authority item must contain " - + "a non-empty term display name."; + "Each term in an authority item must contain " + + "a non-empty display name."; @Override protected Class getCommonPartClass() { @@ -63,21 +61,21 @@ public class TaxonValidatorHandler extends ValidatorHandlerImpl { @Override protected void handleCreate() throws InvalidDocumentException { - TaxonCommon organization = (TaxonCommon) getCommonPart(); + TaxonCommon taxon = (TaxonCommon) getCommonPart(); // No guarantee that there is a common part in every post/update. - if (organization != null) { + if (taxon != null) { try { - String shortId = organization.getShortIdentifier(); + String shortId = taxon.getShortIdentifier(); if (shortId != null) { CS_ASSERT(shortIdentifierContainsOnlyValidChars(shortId), SHORT_ID_BAD_CHARS_ERROR); } - CS_ASSERT(containsAtLeastOneTerm(organization), HAS_NO_TERMS_ERROR); - CS_ASSERT(allTermsContainDisplayName(organization), TERM_HAS_EMPTY_DISPLAYNAME_ERROR); + CS_ASSERT(containsAtLeastOneTerm(taxon), HAS_NO_TERMS_ERROR); + CS_ASSERT(allTermsContainDisplayName(taxon), TERM_HAS_EMPTY_DISPLAYNAME_ERROR); } catch (AssertionError e) { if (logger.isErrorEnabled()) { logger.error(e.getMessage(), e); } - throw new InvalidDocumentException(VALIDATION_ERROR, e); + throw new InvalidDocumentException(e.getMessage(), e); } } } @@ -92,20 +90,20 @@ public class TaxonValidatorHandler extends ValidatorHandlerImpl { @Override protected void handleUpdate() throws InvalidDocumentException { - TaxonCommon organization = (TaxonCommon) getCommonPart(); + TaxonCommon taxon = (TaxonCommon) getCommonPart(); // No guarantee that there is a common part in every post/update. - if (organization != null) { + if (taxon != 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(organization), HAS_NO_TERMS_ERROR); - CS_ASSERT(allTermsContainDisplayName(organization), TERM_HAS_EMPTY_DISPLAYNAME_ERROR); + CS_ASSERT(containsAtLeastOneTerm(taxon), HAS_NO_TERMS_ERROR); + CS_ASSERT(allTermsContainDisplayName(taxon), TERM_HAS_EMPTY_DISPLAYNAME_ERROR); } catch (AssertionError e) { if (logger.isErrorEnabled()) { logger.error(e.getMessage(), e); } - throw new InvalidDocumentException(VALIDATION_ERROR, e); + throw new InvalidDocumentException(e.getMessage(), e); } } } @@ -122,8 +120,8 @@ public class TaxonValidatorHandler extends ValidatorHandlerImpl { return true; } - private boolean containsAtLeastOneTerm(TaxonCommon organization) { - TaxonTermGroupList termGroupList = organization.getTaxonTermGroupList(); + private boolean containsAtLeastOneTerm(TaxonCommon taxon) { + TaxonTermGroupList termGroupList = taxon.getTaxonTermGroupList(); if (termGroupList == null) { return false; } @@ -134,8 +132,8 @@ public class TaxonValidatorHandler extends ValidatorHandlerImpl { return true; } - private boolean allTermsContainDisplayName(TaxonCommon organization) { - TaxonTermGroupList termGroupList = organization.getTaxonTermGroupList(); + private boolean allTermsContainDisplayName(TaxonCommon taxon) { + TaxonTermGroupList termGroupList = taxon.getTaxonTermGroupList(); List termGroups = termGroupList.getTaxonTermGroup(); for (TaxonTermGroup termGroup : termGroups) { if (Tools.isBlank(termGroup.getTermDisplayName())) {