diff --git a/storage-core/src/main/java/org/opengroup/osdu/storage/service/LegalServiceImpl.java b/storage-core/src/main/java/org/opengroup/osdu/storage/service/LegalServiceImpl.java index 4ab5225b8675b07cdb202062fd6cf6b734e65e90..c4e3c2a6194bba9a26dab59f9e124b1e4500f3d5 100644 --- a/storage-core/src/main/java/org/opengroup/osdu/storage/service/LegalServiceImpl.java +++ b/storage-core/src/main/java/org/opengroup/osdu/storage/service/LegalServiceImpl.java @@ -37,6 +37,7 @@ import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -48,7 +49,7 @@ public class LegalServiceImpl implements ILegalService { protected static final String LEGAL_PROPERTIES_KEY = "@legal-properties"; protected static final String DEFAULT_DATA_COUNTRY = "US"; private static final int LEGALTAG_PARTITION_COUNT = 25; - public static Map<String, String> validCountryCodes; + public static Map<String, Set<String>> validCountryCodes = new HashMap<>(); @Autowired private DpsHeaders headers; @Autowired @@ -79,12 +80,12 @@ public class LegalServiceImpl implements ILegalService { @Override public void validateOtherRelevantDataCountries(Set<String> ordc) { - Map<String, String> validCountries = this.getValidCountryCodes(); + Set<String> validCountries = this.getValidCountryCodes(this.headers.getPartitionId()); ordc.add(DEFAULT_DATA_COUNTRY); for (String country : ordc) { - if (!validCountries.containsKey(country)) { + if (!validCountries.contains(country)) { throw new AppException(HttpStatus.SC_BAD_REQUEST, "Invalid other relevant data countries", String.format("The country code '%s' is invalid", country)); } @@ -120,19 +121,20 @@ public class LegalServiceImpl implements ILegalService { } } - public Map<String, String> getValidCountryCodes() { - if (validCountryCodes == null) { + public Set<String> getValidCountryCodes(String dataPartitionId) { + if (validCountryCodes.get(dataPartitionId) == null) { try { ILegalProvider legalService = this.factory.create(this.headers); LegalTagProperties legalTagProperties = legalService.getLegalTagProperties(); - return validCountryCodes = legalTagProperties.getOtherRelevantDataCountries(); + Set<String> validCountryCodeSet = legalTagProperties.getOtherRelevantDataCountries().keySet(); + validCountryCodes.put(dataPartitionId, validCountryCodeSet); } catch (LegalException e) { throw new AppException(e.getHttpResponse().getResponseCode(), "Error getting legal tag properties", "An unexpected error occurred when getting legal tag properties", e); } } - return validCountryCodes; + return validCountryCodes.get(dataPartitionId); } @Override diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/service/LegalServiceImplTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/service/LegalServiceImplTest.java index e3b4049af343ec2f585f40961ca0e5329d00d4b4..491721aa366b7820bb6eb7c6e276150702e31478 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/service/LegalServiceImplTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/service/LegalServiceImplTest.java @@ -198,11 +198,10 @@ public class LegalServiceImplTest { LegalException legalException = new LegalException("service crashed", response); + when(this.headers.getPartitionId()).thenReturn("dp1"); when(this.legalService.getLegalTagProperties()).thenThrow(legalException); try { - LegalServiceImpl.validCountryCodes = null; - this.sut.validateOtherRelevantDataCountries(countries); fail("Should not succeed");