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
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2025-XX-XX v1.23.0-SNAPSHOT
* Replace `mod-configuration` with `mod-settings` to get language and locale settings ([MODTEMPENG-117](https://folio-org.atlassian.net/browse/MODTEMPENG-117))

## 2025-03-13 v1.22.0
* Support barcode image generate for HRID tokens (MODTEMPENG-111)
* Upgrade Java and RMB version for Sunflower (FOLIO-4220)
Expand Down
11 changes: 5 additions & 6 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
"id": "${artifactId}-${version}",
"name": "Template engine module",
"requires": [
{
"id": "configuration",
"version": "2.0"
},
{
"id": "patron-notice-policy-storage",
"version": "0.13"
},
{
"id": "settings",
"version": "1.2"
}

],
"provides": [
{
Expand Down Expand Up @@ -49,7 +48,7 @@
"pathPattern": "/template-request",
"permissionsRequired": ["template-request.post"],
"modulePermissions": [
"configuration.entries.collection.get"
"mod-settings.global.read.stripes-core.prefs.manage"
]
}
]
Expand Down
53 changes: 0 additions & 53 deletions ramls/configuration.json

This file was deleted.

29 changes: 0 additions & 29 deletions ramls/configurations.json

This file was deleted.

2 changes: 0 additions & 2 deletions ramls/template-engine.raml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ types:
templateProcessingRequest: !include templateProcessingRequest.json
templateProcessingResult: !include templateProcessingResult.json
errors: !include raml-util/schemas/errors.schema
configuration: !include configuration.json
configurations: !include configurations.json

traits:
pageable: !include ./raml-util/traits/pageable.raml
Expand Down
77 changes: 0 additions & 77 deletions src/main/java/org/folio/template/client/ConfigurationClient.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.folio.template.client;

public class LocaleConfiguration {
public class LocaleSettings {

private final String languageTag;
private final String timeZoneId;

public LocaleConfiguration(String languageTag, String timeZoneId) {
public LocaleSettings(String languageTag, String timeZoneId) {
this.languageTag = languageTag;
this.timeZoneId = timeZoneId;
}
Expand Down
81 changes: 81 additions & 0 deletions src/main/java/org/folio/template/client/SettingsClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.folio.template.client;

import static java.lang.String.format;

import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;
import io.vertx.core.Future;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.folio.HttpStatus;
import org.folio.template.util.OkapiModuleClientException;

public class SettingsClient extends OkapiClient {
private static final Logger LOG = LogManager.getLogger("mod-template-engine");

private static final String DEFAULT_LANGUAGE_TAG = "en-US";
private static final String DEFAULT_TIMEZONE_ID = "UTC";
private static final String LOCALE_SETTINGS_SCOPE = "stripes-core.prefs.manage";
private static final String LOCALE_SETTINGS_KEY = "tenantLocaleSettings";
private final String settingsRequestPath;

public SettingsClient(Vertx vertx, Map<String, String> okapiHeaders) {
super(vertx, okapiHeaders);
this.settingsRequestPath = System.getProperty("config.client.path", "/settings/entries");
}

public Future<LocaleSettings> lookupLocaleSetting() {
LOG.debug("lookupLocaleConfig:: Lookup locale setting");
var configs = lookupSettingsByScopeAndKey(LOCALE_SETTINGS_SCOPE, LOCALE_SETTINGS_KEY, 1, 0)
.map(this::mapToLocaleSettings);
LOG.info("lookupLocaleConfig:: Locale setting looked up successfully");

return configs;
}

private Future<JsonObject> lookupSettingsByScopeAndKey(String scope, String key, int limit, int offset) {

LOG.debug("lookupSettingsByScopeAndKey:: Lookup locale settings by scope {} and key {}", scope, key);
String query = format("scope==%s and key==%s", scope, key);
return lookupSettingsByQuery(query, limit, offset);
}

private Future<JsonObject> lookupSettingsByQuery(String query, int limit, int offset) {
LOG.debug("lookupSettingsByQuery:: Lookup settings by Query {}", query);
return getMany(settingsRequestPath, query, limit, offset).future()
.map(response -> {
if (response.statusCode() != HttpStatus.HTTP_OK.toInt()) {
LOG.warn("lookupSettingsByQuery:: Error getting locale settings. Status: {}, body: {}",
response.statusCode(), response.body());
throw new OkapiModuleClientException(
format("Error getting locale settings. Status: %d, body: %s", response.statusCode(), response.body()));
}
LOG.info("lookupSettingsByQuery:: Locale settings by query looked up successfully.");
return response.bodyAsJsonObject();
});
}

private LocaleSettings mapToLocaleSettings(JsonObject localeSettings) {
LOG.debug("mapToLocaleSettings:: Mapping {} to locale setting", localeSettings);
JsonObject localeSetting = Optional.ofNullable(localeSettings.getJsonArray("items"))
.map(JsonArray::stream)
.orElse(Stream.empty())
.filter(Objects::nonNull)
.map(JsonObject.class::cast)
.findFirst()
.orElse(new JsonObject());
LOG.debug("mapToLocaleSettings:: Found locale setting: {}", localeSetting);

var valueObj = Optional.ofNullable(localeSetting.getJsonObject("value")).orElse(new JsonObject());
String languageTag = valueObj.getString("locale", DEFAULT_LANGUAGE_TAG);
String timezoneId = valueObj.getString("timezone", DEFAULT_TIMEZONE_ID);
LOG.info("mapToLocaleSettings:: Mapped to locale setting with Language Tag: {}, Timezone ID: {}",
languageTag, timezoneId);
return new LocaleSettings(languageTag, timezoneId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import org.folio.rest.jaxrs.model.TemplateProcessingResult;
import org.folio.template.InUseTemplateException;
import org.folio.template.client.CirculationStorageClient;
import org.folio.template.client.ConfigurationClient;
import org.folio.template.client.LocaleConfiguration;
import org.folio.template.client.LocaleSettings;
import org.folio.template.client.SettingsClient;
import org.folio.template.dao.TemplateDao;
import org.folio.template.dao.TemplateDaoImpl;
import org.folio.template.resolver.TemplateResolver;
Expand All @@ -44,7 +44,7 @@ public class TemplateServiceImpl implements TemplateService {
private Vertx vertx;
private TemplateDao templateDao;
private Map<String, String> templateResolverAddressesMap;
private ConfigurationClient configurationClient;
private SettingsClient settingsClient;
private CirculationStorageClient circulationStorageClient;


Expand All @@ -53,7 +53,7 @@ public TemplateServiceImpl(Vertx vertx, Map<String, String> okapiHeaders) {
this.templateDao = new TemplateDaoImpl(vertx, okapiHeaders.get(TENANT));
this.templateResolverAddressesMap = vertx.sharedData().getLocalMap(
TemplateEngineHelper.TEMPLATE_RESOLVERS_LOCAL_MAP);
this.configurationClient = new ConfigurationClient(vertx, okapiHeaders);
this.settingsClient = new SettingsClient(vertx, okapiHeaders);
this.circulationStorageClient = new CirculationStorageClient(vertx, okapiHeaders);
}

Expand Down Expand Up @@ -109,7 +109,7 @@ public Future<TemplateProcessingResult> processTemplate(TemplateProcessingReques
.map(optionalTemplate -> optionalTemplate.orElseThrow(() ->
new BadRequestException(String.format("Template with id %s does not exist", templateRequest.getTemplateId()))));

Future<LocaleConfiguration> localeConfigurationFuture = configurationClient.lookupLocaleConfig();
Future<LocaleSettings> localeConfigurationFuture = settingsClient.lookupLocaleSetting();

return CompositeFuture.all(templateByIdFuture, localeConfigurationFuture)
.compose(compositeFuture -> {
Expand All @@ -123,7 +123,7 @@ public Future<TemplateProcessingResult> processTemplate(TemplateProcessingReques
.map(JsonObject::mapFrom)
.orElse(new JsonObject());

LocaleConfiguration config = compositeFuture.resultAt(1);
LocaleSettings config = compositeFuture.resultAt(1);

TemplateContextPreProcessor preProcessor = new TemplateContextPreProcessor(templateContent, contextObject, config);
preProcessor.process();
Expand All @@ -146,7 +146,9 @@ public Future<TemplateProcessingResult> processTemplate(TemplateProcessingReques
.withDateCreate(new Date())
.withLang(templateRequest.getLang())
.withOutputFormat(templateRequest.getOutputFormat());

LOG.info("processTemplate:: Template processed successfully");

return new TemplateProcessingResult()
.withResult(processedTemplate)
.withMeta(resultMetaInfo)
Expand Down
Loading