-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into MODEXPW-489
- Loading branch information
Showing
15 changed files
with
222 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 31 additions & 16 deletions
47
src/main/java/org/folio/dew/batch/acquisitions/edifact/services/ConfigurationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,50 @@ | ||
package org.folio.dew.batch.acquisitions.edifact.services; | ||
|
||
import java.util.UUID; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.folio.dew.client.ConfigurationClient; | ||
import org.folio.dew.domain.dto.ConfigurationCollection; | ||
import org.springframework.stereotype.Service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.folio.dew.client.ConfigurationClient; | ||
import org.folio.dew.domain.dto.ModelConfiguration; | ||
import org.springframework.cache.annotation.Cacheable; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ConfigurationService { | ||
|
||
private static final Logger logger = LogManager.getLogger(); | ||
|
||
private final ConfigurationClient configurationClient; | ||
private final ObjectMapper objectMapper; | ||
|
||
private ConfigurationCollection getLocaleSettings() { | ||
return configurationClient.getConfigurations("(module==ORG and configName==localeSettings)"); | ||
private ModelConfiguration getConfigById(String configId) { | ||
return configurationClient.getConfigById(configId); | ||
} | ||
|
||
public String getSystemCurrency() { | ||
ConfigurationCollection configs = getLocaleSettings(); | ||
|
||
if (configs == null || configs.getTotalRecords() == 0) { | ||
return "USD"; | ||
@Cacheable(cacheNames = "addressConfiguration") | ||
public String getAddressConfig(UUID shipToConfigId) { | ||
if (shipToConfigId == null) { | ||
logger.warn("getAddressConfig:: 'shipTo' field of composite purchase order is null"); | ||
return ""; | ||
} | ||
|
||
var jsonObject = objectMapper.valueToTree(configs.getConfigs().get(0).getValue()); | ||
|
||
if (!jsonObject.has("currency")) { | ||
return "USD"; | ||
var addressConfig = getConfigById(shipToConfigId.toString()); | ||
if (addressConfig.getValue() == null) { | ||
logger.warn("getAddressConfig:: 'address config with id '{}' is not found", shipToConfigId); | ||
return ""; | ||
} | ||
try { | ||
JsonNode valueJsonObject = objectMapper.readTree(addressConfig.getValue()); | ||
return valueJsonObject.has("address") ? valueJsonObject.get("address").asText() : ""; | ||
} catch (JsonProcessingException e) { | ||
logger.error("getAddressConfig:: Couldn't convert configValue: {} to json", addressConfig, e); | ||
return ""; | ||
} | ||
|
||
return String.valueOf(jsonObject.get("currency")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.