Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"orders-storage.titles.collection.get",
"orders-storage.order-invoice-relationships.collection.get",
"orders-storage.settings.collection.get",
"mod-settings.global.read.stripes-core.prefs.manage",
"locale.item.get",
"acquisitions-units-storage.units.collection.get",
"acquisitions-units-storage.memberships.collection.get",
"invoice.invoices.collection.get",
Expand Down Expand Up @@ -192,7 +192,7 @@
"orders-storage.po-lines.collection.get",
"orders-storage.po-lines.item.post",
"orders-storage.settings.collection.get",
"mod-settings.global.read.stripes-core.prefs.manage",
"locale.item.get",
"acquisitions-units-storage.units.collection.get",
"acquisitions-units-storage.memberships.collection.get",
"inventory.instances.item.get",
Expand All @@ -219,7 +219,7 @@
"orders-storage.purchase-orders.item.get",
"orders-storage.titles.collection.get",
"orders-storage.settings.collection.get",
"mod-settings.global.read.stripes-core.prefs.manage",
"locale.item.get",
"acquisitions-units-storage.units.collection.get",
"acquisitions-units-storage.memberships.collection.get"
]
Expand Down Expand Up @@ -264,7 +264,7 @@
"orders-storage.purchase-orders.item.put",
"orders-storage.titles.collection.get",
"orders-storage.settings.collection.get",
"mod-settings.global.read.stripes-core.prefs.manage",
"locale.item.get",
"inventory-storage.identifier-types.collection.get",
"inventory.items.item.put",
"inventory.items.collection.get",
Expand Down Expand Up @@ -330,7 +330,7 @@
"user-tenants.collection.get",
"consortia.sharing-instances.item.post",
"orders-storage.settings.collection.get",
"mod-settings.global.read.stripes-core.prefs.manage"
"locale.item.get"
]
},
{
Expand Down Expand Up @@ -419,7 +419,7 @@
"acquisitions-units-storage.units.collection.get",
"acquisitions-units-storage.memberships.collection.get",
"orders-storage.settings.collection.get",
"mod-settings.global.read.stripes-core.prefs.manage",
"locale.item.get",
"inventory.instances.item.get",
"inventory.instances.item.post",
"inventory.instances.collection.get",
Expand Down Expand Up @@ -515,7 +515,7 @@
"acquisitions-units-storage.units.collection.get",
"acquisitions-units-storage.memberships.collection.get",
"orders-storage.settings.collection.get",
"mod-settings.global.read.stripes-core.prefs.manage",
"locale.item.get",
"inventory.items.item.put",
"inventory.items.collection.get",
"inventory-storage.holdings-sources.collection.get",
Expand Down Expand Up @@ -563,7 +563,7 @@
"acquisitions-units-storage.units.collection.get",
"acquisitions-units-storage.memberships.collection.get",
"orders-storage.settings.collection.get",
"mod-settings.global.read.stripes-core.prefs.manage",
"locale.item.get",
"inventory.instances.collection.get",
"inventory.instances.item.get",
"inventory.instances.item.post",
Expand Down Expand Up @@ -638,7 +638,7 @@
"acquisitions-units-storage.units.collection.get",
"acquisitions-units-storage.memberships.collection.get",
"orders-storage.settings.collection.get",
"mod-settings.global.read.stripes-core.prefs.manage",
"locale.item.get",
"inventory.items.item.put",
"inventory.items.collection.get",
"inventory-storage.holdings-sources.collection.get",
Expand Down Expand Up @@ -921,7 +921,7 @@
"acquisitions-units-storage.units.collection.get",
"acquisitions-units-storage.memberships.collection.get",
"orders-storage.settings.collection.get",
"mod-settings.global.read.stripes-core.prefs.manage"
"locale.item.get"
]
},
{
Expand All @@ -946,7 +946,7 @@
"inventory-storage.contributor-name-types.collection.get",
"user-tenants.collection.get",
"orders-storage.settings.collection.get",
"mod-settings.global.read.stripes-core.prefs.manage",
"locale.item.get",
"consortia.sharing-instances.item.post",
"acquisitions-units-storage.units.collection.get",
"acquisitions-units-storage.memberships.collection.get"
Expand All @@ -967,7 +967,7 @@
"inventory-storage.items.collection.get",
"inventory-storage.items.collection.delete",
"orders-storage.settings.collection.get",
"mod-settings.global.read.stripes-core.prefs.manage",
"locale.item.get",
"orders-storage.settings.collection.get",
"user-tenants.collection.get",
"acquisitions-units-storage.units.collection.get",
Expand Down Expand Up @@ -1106,7 +1106,7 @@
],
"modulePermissions": [
"orders-storage.settings.collection.get",
"mod-settings.global.read.stripes-core.prefs.manage",
"locale.item.get",
"finance-storage.funds.collection.get",
"finance.exchange-rate.item.get",
"finance.transactions.batch.execute",
Expand Down Expand Up @@ -1297,7 +1297,7 @@
"pieces.send-claims.collection.post"
],
"modulePermissions": [
"mod-settings.global.read.stripes-core.prefs.manage",
"locale.item.get",
"orders-storage.pieces.collection.get",
"orders-storage.pieces.item.put",
"orders-storage.po-lines.item.get",
Expand Down Expand Up @@ -1354,8 +1354,8 @@
"version": "1.0"
},
{
"id": "settings",
"version": "1.2"
"id": "locale",
"version": "1.0"
},
{
"id": "configuration",
Expand Down Expand Up @@ -2268,7 +2268,7 @@
"orders-storage.titles.item.get",
"orders-storage.order-invoice-relationships.collection.get",
"orders-storage.settings.collection.get",
"mod-settings.global.read.stripes-core.prefs.manage",
"locale.item.get",
"finance.funds.budget.item.get",
"finance.funds.collection.get",
"finance.funds.item.get",
Expand Down Expand Up @@ -2338,7 +2338,7 @@
"orders-storage.po-lines.item.get",
"orders-storage.purchase-orders.item.get",
"orders-storage.settings.collection.get",
"mod-settings.global.read.stripes-core.prefs.manage",
"locale.item.get",
"finance.funds.budget.item.get",
"finance.funds.collection.get",
"finance.budgets.collection.get",
Expand Down Expand Up @@ -2402,7 +2402,7 @@
"permissions": [
"converter-storage.jobprofilesnapshots.get",
"orders-storage.settings.collection.get",
"mod-settings.global.read.stripes-core.prefs.manage",
"locale.item.get",
"finance-storage.fiscal-years.item.get",
"acquisitions-units.memberships.collection.get",
"acquisitions-units.units.collection.get",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class ResourcePathResolver {
public static final String FINANCE_EXCHANGE_RATE = "finance/exchange-rate";
public static final String EXPENSE_CLASSES_URL = "finance.expense-classes";
public static final String CONFIGURATION_ENTRIES = "configurations.entries";
public static final String SETTINGS_ENTRIES = "settings.entries";
public static final String LOCALE = "locale";
public static final String LEDGER_FY_ROLLOVERS = "finance.ledger-rollovers";
public static final String LEDGER_FY_ROLLOVER_ERRORS = "finance.ledger-rollovers-errors";
public static final String LEDGER_CURRENT_FISCAL_YEAR = "finance.ledger.current-fiscal-year";
Expand Down Expand Up @@ -105,7 +105,7 @@ public class ResourcePathResolver {
apis.put(FINANCE_EXCHANGE_RATE, "/finance/exchange-rate");
apis.put(EXPENSE_CLASSES_URL, "/finance/expense-classes");
apis.put(CONFIGURATION_ENTRIES, "/configurations/entries");
apis.put(SETTINGS_ENTRIES, "/settings/entries");
apis.put(LOCALE, "/locale");
apis.put(LEDGER_FY_ROLLOVERS, "/finance/ledger-rollovers");
apis.put(LEDGER_FY_ROLLOVER_ERRORS, "/finance/ledger-rollovers-errors");
apis.put(LEDGER_CURRENT_FISCAL_YEAR, "/finance/ledgers/{id}/current-fiscal-year");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,15 @@
import org.springframework.stereotype.Component;

import static org.folio.orders.utils.CacheUtils.buildAsyncCache;
import static org.folio.orders.utils.ResourcePathResolver.LOCALE;
import static org.folio.orders.utils.ResourcePathResolver.ORDER_SETTINGS;
import static org.folio.orders.utils.ResourcePathResolver.SETTINGS_ENTRIES;
import static org.folio.orders.utils.ResourcePathResolver.resourcesPath;

@Log4j2
@Component
@RequiredArgsConstructor
public class CommonSettingsCache extends AbstractConfigCache {

public static final String GLOBAL_SETTINGS_QUERY = "(scope==stripes-core.prefs.manage and key==tenantLocaleSettings)";
public static final String TENANT_LOCALE_SETTINGS = "tenantLocaleSettings";

private final CommonSettingsRetriever commonSettingsRetriever;
private AsyncCache<String, JsonObject> settingsCache;
private AsyncCache<String, String> systemCurrencyCache;
Expand All @@ -49,12 +46,12 @@ public Future<JsonObject> loadSettings(RequestContext requestContext) {
}

public Future<String> getSystemCurrency(RequestContext requestContext) {
return cacheData(resourcesPath(SETTINGS_ENTRIES), GLOBAL_SETTINGS_QUERY, systemCurrencyCache,
return cacheData(resourcesPath(LOCALE), null, systemCurrencyCache,
commonSettingsRetriever::getSystemCurrency, byPassCache, requestContext);
}

public Future<String> getSystemTimeZone(RequestContext requestContext) {
return cacheData(resourcesPath(SETTINGS_ENTRIES), GLOBAL_SETTINGS_QUERY, systemTimezoneCache,
return cacheData(resourcesPath(LOCALE), null, systemTimezoneCache,
commonSettingsRetriever::getSystemTimeZone, byPassCache, requestContext);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@

import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.folio.rest.acq.model.SettingCollection;
import org.folio.rest.acq.model.settings.CommonSetting;
import org.folio.rest.acq.model.settings.CommonSettingsCollection;
import org.folio.rest.acq.model.settings.Value;
import org.folio.rest.core.RestClient;
import org.folio.rest.core.models.RequestContext;
import org.folio.rest.core.models.RequestEntry;
import org.folio.rest.jaxrs.model.Configs;

import io.vertx.core.Future;
import io.vertx.core.json.JsonObject;

import java.util.List;
import java.util.Optional;

/**
* This service class is used to fetch settings from <code>mod-settings</code>. Unlike {@link SettingsRetriever}, this class does not fetch
* settings from the <code>mod-orders-storage</code> database. It is intended to be used for common settings that are not specific to orders.
Expand All @@ -33,33 +27,23 @@ public class CommonSettingsRetriever {

private final RestClient restClient;

public Future<JsonObject> loadConfigurations(RequestEntry requestEntry, RequestContext requestContext) {
return restClient.get(requestEntry, Configs.class, requestContext)
.map(configs -> {
var config = new JsonObject();
configs.getConfigs().forEach(entry -> config.put(entry.getConfigName(), entry.getValue()));
return config;
});
}

public Future<String> getSystemCurrency(RequestEntry requestEntry, RequestContext requestContext) {
return getGlobalSetting(CURRENCY_KEY, CURRENCY_DEFAULT, requestEntry, requestContext);
return getLocaleSetting(CURRENCY_KEY, CURRENCY_DEFAULT, requestEntry, requestContext);
}

public Future<String> getSystemTimeZone(RequestEntry requestEntry, RequestContext requestContext) {
return getGlobalSetting(TZ_KEY, TZ_DEFAULT, requestEntry, requestContext);
return getLocaleSetting(TZ_KEY, TZ_DEFAULT, requestEntry, requestContext);
}

private Future<String> getGlobalSetting(String key, String defaultValue, RequestEntry requestEntry, RequestContext requestContext) {
return restClient.get(requestEntry, CommonSettingsCollection.class, requestContext)
.map(settingsCollection -> Optional.ofNullable(settingsCollection.getItems()).orElse(List.of()))
.map(settings -> settings.stream()
.findFirst()
.map(CommonSetting::getValue)
.map(Value::getAdditionalProperties)
.map(properties -> properties.get(key))
.map(Object::toString)
.orElse(defaultValue));
private Future<String> getLocaleSetting(String key, String defaultValue, RequestEntry requestEntry, RequestContext requestContext) {
return restClient.getAsJsonObject(requestEntry, requestContext)
.map(jsonObject -> {
if (jsonObject == null) {
return defaultValue;
}
var value = jsonObject.getString(key);
return StringUtils.isNotBlank(value) ? value : defaultValue;
});
}

public Future<JsonObject> getLocalSettings(RequestEntry requestEntry, RequestContext requestContext) {
Expand Down
15 changes: 3 additions & 12 deletions src/test/java/org/folio/rest/impl/MockServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
import static org.folio.orders.utils.ResourcePathResolver.REASONS_FOR_CLOSURE;
import static org.folio.orders.utils.ResourcePathResolver.RECEIVING_HISTORY;
import static org.folio.orders.utils.ResourcePathResolver.ROUTING_LISTS;
import static org.folio.orders.utils.ResourcePathResolver.SETTINGS_ENTRIES;
import static org.folio.orders.utils.ResourcePathResolver.LOCALE;
import static org.folio.orders.utils.ResourcePathResolver.SUFFIXES;
import static org.folio.orders.utils.ResourcePathResolver.TAGS;
import static org.folio.orders.utils.ResourcePathResolver.TITLES;
Expand Down Expand Up @@ -250,7 +250,7 @@ public class MockServer {
public static final String BASE_MOCK_DATA_PATH = "mockdata/";
private static final String CONTRIBUTOR_NAME_TYPES_PATH = BASE_MOCK_DATA_PATH + "contributorNameTypes/contributorPersonalNameType.json";
public static final String CONFIG_MOCK_PATH = BASE_MOCK_DATA_PATH + "configurations.entries/%s.json";
public static final String SETTINGS_MOCK_PATH = BASE_MOCK_DATA_PATH + "settings.entries/%s.json";
public static final String LOCALE_MOCK_PATH = BASE_MOCK_DATA_PATH + "locale/locale.json";
public static final String ORDER_SETTINGS_MOCK_PATH = BASE_MOCK_DATA_PATH + "order-settings/%s.json";
public static final String EXPORT_CONFIG_MOCK_PATH = BASE_MOCK_DATA_PATH + "data-export-spring/export-config.json";
public static final String LOAN_TYPES_MOCK_DATA_PATH = BASE_MOCK_DATA_PATH + "loanTypes/";
Expand Down Expand Up @@ -702,7 +702,7 @@ private Router defineRoutes() {
router.get(resourcesPath(WRAPPER_PIECES_STORAGE) + "/:id").handler(ctx -> handleGetJsonResource(ctx, MOCK_DATA_WRAPPER_PIECES_BY_ID_JSON));
router.get(resourcesPath(CONFIGURATION_ENTRIES)).handler(ctx -> handleConfigurationOrSettingResponse(CONFIG_MOCK_PATH, ctx));
router.get(resourcesPath(ORDER_SETTINGS)).handler(ctx -> handleConfigurationOrSettingResponse(ORDER_SETTINGS_MOCK_PATH, ctx));
router.get(resourcesPath(SETTINGS_ENTRIES)).handler(this::handleSettingResponse);
router.get(resourcesPath(LOCALE)).handler(ctx -> handleGetJsonResource(ctx, LOCALE_MOCK_PATH));
router.get(resourcesPath(DATA_EXPORT_SPRING_CONFIGURATIONS)).handler(this::handleExportConfigsResponse);
// PUT
router.put(resourcePath(PURCHASE_ORDER_STORAGE)).handler(ctx -> handlePutGenericSubObj(ctx, PURCHASE_ORDER_STORAGE));
Expand Down Expand Up @@ -1670,15 +1670,6 @@ private void handleConfigurationOrSettingResponse(String mockPath, RoutingContex
}
}

private void handleSettingResponse(RoutingContext ctx) {
try {
var mockData = getMockData(SETTINGS_MOCK_PATH.formatted(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10.getValue()));
serverResponse(ctx, 200, APPLICATION_JSON, mockData);
} catch (IOException e) {
serverResponse(ctx, 500, APPLICATION_JSON, INTERNAL_SERVER_ERROR.getReasonPhrase());
}
}

private void handleExportConfigsResponse(RoutingContext ctx) {
try {
var config = new JsonObject(getMockData(EXPORT_CONFIG_MOCK_PATH));
Expand Down
Loading