From f9e30bda65e1edbcfd7e52f799483cae980803ba Mon Sep 17 00:00:00 2001 From: Mingyang Zhu <mzhu9@slb.com> Date: Tue, 12 Jan 2021 17:00:44 -0600 Subject: [PATCH] to populate the correct error message thrown by the bottom layer when validating the legal tag --- .../legal/tags/validation/rules/DefaultRule.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/legal-core/src/main/java/org/opengroup/osdu/legal/tags/validation/rules/DefaultRule.java b/legal-core/src/main/java/org/opengroup/osdu/legal/tags/validation/rules/DefaultRule.java index 0ad0f8e8e..6b1083dde 100644 --- a/legal-core/src/main/java/org/opengroup/osdu/legal/tags/validation/rules/DefaultRule.java +++ b/legal-core/src/main/java/org/opengroup/osdu/legal/tags/validation/rules/DefaultRule.java @@ -1,6 +1,7 @@ package org.opengroup.osdu.legal.tags.validation.rules; import com.fasterxml.jackson.annotation.JsonIgnore; +import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.legal.validation.rules.Rule; import org.opengroup.osdu.legal.countries.LegalTagCountriesService; import org.opengroup.osdu.core.common.model.legal.Properties; @@ -25,11 +26,15 @@ public class DefaultRule extends Rule { @Override protected String hasError(Properties properties) { String output = ""; - if(!properties.hasContractId() && !properties.isUnknownOrNonExistantContractId()) { - output = String.format("Invalid Contract Id given. Only '%s' '%s' or the real contract ID are allowed values. The contract ID must be between 3 and 40 characters and only include alphanumeric values and hyphens,", Properties.UNKNOWN_CONTRACT_ID, Properties.NO_CONTRACT_ID); - } - else if(!isAllowedCOO(properties)){ - output = String.format("Invalid country of origin set. It should match one of the ISO alpha 2 codes and be a country with no restriction on data residency. Found: %s.", properties.getCountryOfOrigin()); + try { + if(!properties.hasContractId() && !properties.isUnknownOrNonExistantContractId()) { + output = String.format("Invalid Contract Id given. Only '%s' '%s' or the real contract ID are allowed values. The contract ID must be between 3 and 40 characters and only include alphanumeric values and hyphens,", Properties.UNKNOWN_CONTRACT_ID, Properties.NO_CONTRACT_ID); + } + else if(!isAllowedCOO(properties)){ + output = String.format("Invalid country of origin set. It should match one of the ISO alpha 2 codes and be a country with no restriction on data residency. Found: %s.", properties.getCountryOfOrigin()); + } + } catch (AppException ex) { + output = ex.getError().getMessage(); } return output; } -- GitLab