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
14 changes: 11 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<!-- define sonar exclusions here -->
src/main/java/org/folio/template/FolioSpringTemplateApplication.java
</sonar.exclusions>
<argLine />
<argLine>-Dfile.encoding=UTF-8</argLine>
</properties>


Expand Down Expand Up @@ -360,14 +360,22 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
<argLine>@{argLine} -Dfile.encoding=UTF-8</argLine>
<systemProperties>
<!-- Docker API version to use for testcontainers -->
<api.version>1.41</api.version>
</systemProperties>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<systemProperties>
<!-- Docker API version to use for testcontainers -->
<api.version>1.41</api.version>
</systemProperties>
Comment thread
mweaver-ebsco marked this conversation as resolved.
</configuration>
</plugin>

<plugin>
Expand Down
63 changes: 63 additions & 0 deletions src/main/java/org/folio/fqm/client/LocaleClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.folio.fqm.client;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import feign.FeignException;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;

import java.time.DateTimeException;
import java.time.ZoneId;

/**
* Client for the /locale API.
*
* @implNote This is a separate class from the internal LocaleClientRaw interface because Feign clients must be interfaces, disallowing any injection.
*/
@Log4j2
@Component
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class LocaleClient {

private final ObjectMapper objectMapper;
private final LocaleClientRaw underlyingClient;

/**
* Provides raw access to the /locale API.
*/
@FeignClient(name = "locale")
interface LocaleClientRaw {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same basic idea as with SettingsClient and SettingsClientRaw, except I hid the raw version inside this one, to keep things a little simpler

@GetMapping("/locale")
String getLocaleSettings();
}

public record LocaleSettings(
String locale,
String currency,
String timezone,
String numberingSystem
) {
public ZoneId getZoneId() {
try {
return ZoneId.of(timezone);
} catch (DateTimeException e) {
log.error("Invalid timezone '{}', defaulting to UTC.", timezone, e);
return ZoneId.of("UTC");
}
}
}

public LocaleSettings getLocaleSettings() {
try {
String response = underlyingClient.getLocaleSettings();
return objectMapper.readValue(response, LocaleSettings.class);
} catch (JsonProcessingException | FeignException | NullPointerException e) {
log.error("Failed to retrieve locale information. Defaulting to en-US, USD, UTC, latn.", e);
return new LocaleSettings("en-US", "USD", "UTC", "latn");
}
}
}
43 changes: 0 additions & 43 deletions src/main/java/org/folio/fqm/client/SettingsClient.java

This file was deleted.

15 changes: 0 additions & 15 deletions src/main/java/org/folio/fqm/client/SettingsClientRaw.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.folio.fqm.client.ModesOfIssuanceClient;
import org.folio.fqm.client.OrganizationsClient;
import org.folio.fqm.client.PatronGroupsClient;
import org.folio.fqm.client.SettingsClient;
import org.folio.fqm.client.LocaleClient;
import org.folio.fqm.migration.strategies.MigrationStrategy;
import org.folio.fqm.migration.strategies.impl.V0POCMigration;
import org.folio.fqm.migration.strategies.impl.V10OrganizationStatusValueChange;
Expand All @@ -24,6 +24,7 @@
import org.folio.fqm.migration.strategies.impl.V21NotContainsAllToNeqOperatorMigration;
import org.folio.fqm.migration.strategies.impl.V22UserCustomFieldMigration;
import org.folio.fqm.migration.strategies.impl.V23UserCreatedUpdatedDateFieldDeprecation;
import org.folio.fqm.migration.strategies.impl.V24InvoiceSimpleToCompositeMigration;
import org.folio.fqm.migration.strategies.impl.V2ResourceTypeConsolidation;
import org.folio.fqm.migration.strategies.impl.V3RamsonsFieldCleanup;
import org.folio.fqm.migration.strategies.impl.V4DateFieldTimezoneAddition;
Expand All @@ -42,7 +43,7 @@ public class MigrationStrategyRepository {
private final List<MigrationStrategy> migrationStrategies;

public MigrationStrategyRepository(
SettingsClient settingsClient,
LocaleClient localeClient,
LocationsClient locationsClient,
LocationUnitsClient locationUnitsClient,
ModesOfIssuanceClient modesOfIssuanceClient,
Expand All @@ -57,7 +58,7 @@ public MigrationStrategyRepository(
new V1ModeOfIssuanceConsolidation(),
new V2ResourceTypeConsolidation(),
new V3RamsonsFieldCleanup(),
new V4DateFieldTimezoneAddition(settingsClient),
new V4DateFieldTimezoneAddition(localeClient),
new V5UUIDNotEqualOperatorRemoval(),
new V6ModeOfIssuanceValueChange(modesOfIssuanceClient),
new V7PatronGroupsValueChange(patronGroupsClient),
Expand All @@ -76,7 +77,8 @@ public MigrationStrategyRepository(
new V20ContainsAllToEqOperatorMigration(),
new V21NotContainsAllToNeqOperatorMigration(),
new V22UserCustomFieldMigration(),
new V23UserCreatedUpdatedDateFieldDeprecation()
new V23UserCreatedUpdatedDateFieldDeprecation(),
new V24InvoiceSimpleToCompositeMigration()
// adding a strategy? be sure to update the `CURRENT_VERSION` in MigrationConfiguration!
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@ public MigratableQueryInformation additionalChanges(Void v, MigratableQueryInfor
protected static String getNewFieldName(Map<String, String> fieldChanges, String oldFieldName) {
if (MigrationConfiguration.VERSION_KEY.equals(oldFieldName)) {
return oldFieldName;
} else if (fieldChanges.containsKey(oldFieldName)) { // specific field changes take priority over wildcards
return fieldChanges.get(oldFieldName);
} else if (fieldChanges.containsKey("*")) {
return fieldChanges.get("*").formatted(oldFieldName);
} else {
return fieldChanges.getOrDefault(oldFieldName, oldFieldName);
return oldFieldName;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.folio.fqm.migration.strategies.impl;

import java.util.Map;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.folio.fqm.migration.strategies.AbstractSimpleMigrationStrategy;
import org.folio.fqm.migration.warnings.FieldWarningFactory;
import org.folio.fqm.migration.warnings.RemovedFieldWarning;

/**
* Version 24, migrates from simple_invoice to composite_invoice entity type.
* All fields from simple_invoice get "invoice." prepended to their names.
* The (now non-existent) bill_to field is specifically migrated to bill_to.address.
* For other composites containing simple_invoice, a warning is issued for bill_to references.
*/
@Log4j2
@RequiredArgsConstructor
public class V24InvoiceSimpleToCompositeMigration extends AbstractSimpleMigrationStrategy {

private static final UUID SIMPLE_INVOICE_ID = UUID.fromString("4d626ce1-1880-48d2-9d4c-81667fdc5dbb");
private static final UUID COMPOSITE_INVOICE_ID = UUID.fromString("5c4cb0c9-c8bf-4fe5-b844-4de90ca445dc");
private static final UUID COMPOSITE_INVOICE_LINE_ID = UUID.fromString("a2ea9d7a-3ed3-41c7-9cdd-f433e029ea0f");
private static final UUID COMPOSITE_ORDER_INVOICE_ANALYTICS_ID = UUID.fromString("f3ccbf49-8e3e-4f5c-a60e-04ad80543a4a");
private static final UUID COMPOSITE_INVOICE_VOUCHER_LINE_LEDGER_FUND_ORG_ID = UUID.fromString("8ddd1e32-5c85-46ab-8bf3-1ec9a76c18cf");
private static final UUID COMPOSITE_INVOICE_VOUCHER_LINE_ORG_ID = UUID.fromString("2028a343-5603-4e86-99d5-c7de322c1709");

@Override
public String getMaximumApplicableVersion() {
return "24";
}

@Override
public String getLabel() {
return "V24 Invoice simple to composite migration";
}

@Override
public Map<UUID, Map<String, FieldWarningFactory>> getFieldWarnings() {
FieldWarningFactory billToWarning = RemovedFieldWarning.withoutAlternative();
return Map.of(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need all of these enumerated anymore! Take a look at the new overridable method in the migration docs; specify the composite entity IDs and source aliases and it'll auto-resolve any composite parent changes

COMPOSITE_INVOICE_LINE_ID,
Map.of("invoice.bill_to", billToWarning),
COMPOSITE_ORDER_INVOICE_ANALYTICS_ID,
Map.of("invoice.bill_to", billToWarning),
COMPOSITE_INVOICE_VOUCHER_LINE_LEDGER_FUND_ORG_ID,
Map.of("invoice.bill_to", billToWarning),
COMPOSITE_INVOICE_VOUCHER_LINE_ORG_ID,
Map.of("invoice.bill_to", billToWarning)
);
}

@Override
public Map<UUID, UUID> getEntityTypeChanges() {
return Map.of(SIMPLE_INVOICE_ID, COMPOSITE_INVOICE_ID);
}

@Override
public Map<UUID, Map<String, String>> getFieldChanges() {
return Map.of(
SIMPLE_INVOICE_ID,
Map.of(
"*", "invoice.%s",
"bill_to", "bill_to.address"
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.function.Supplier;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.folio.fqm.client.SettingsClient;
import org.folio.fqm.client.LocaleClient;
import org.folio.fqm.migration.MigrationUtils;
import org.folio.fqm.migration.strategies.AbstractRegularMigrationStrategy;
import org.folio.fqm.migration.types.MigratableFqlFieldAndCondition;
Expand Down Expand Up @@ -86,7 +86,7 @@ public String getMaximumApplicableVersion() {
"users.user_updated_date"
);

private final SettingsClient settingsClient;
private final LocaleClient localeClient;

@Override
public String getLabel() {
Expand All @@ -113,7 +113,7 @@ public SingleFieldMigrationResult<MigratableFqlFieldAndCondition> migrateFql(
}

if (state.get() == null) {
state.set(settingsClient.getTenantTimezone());
state.set(localeClient.getLocaleSettings().getZoneId());
}

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package org.folio.fqm.repository;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.folio.fqm.client.LocaleClient;
import org.folio.fqm.client.SimpleHttpClient;
import org.folio.fqm.service.SourceViewService;
import org.jooq.DSLContext;
Expand All @@ -31,10 +30,6 @@ public class DataRefreshRepository {
public static final Field<Double> EXCHANGE_RATE_FIELD = field("exchange_rate", Double.class);
public static final String EXCHANGE_RATE_TABLE = "currency_exchange_rates";
private static final String GET_EXCHANGE_RATE_PATH = "finance/exchange-rate";
private static final String GET_LOCALE_SETTINGS_PATH = "configurations/entries";
private static final Map<String, String> GET_LOCALE_SETTINGS_PARAMS = Map.of(
"query", "(module==ORG and configName==localeSettings)"
);

private static final List<String> SYSTEM_SUPPORTED_CURRENCIES = List.of(
"USD",
Expand Down Expand Up @@ -75,6 +70,7 @@ public class DataRefreshRepository {
private final DSLContext jooqContext;
private final SourceViewService sourceViewService;
private final SimpleHttpClient simpleHttpClient;
private final LocaleClient localeClient;

/**
* Refresh the currency exchange rates for a tenant, based on the tenant's default system currency.
Expand Down Expand Up @@ -119,21 +115,7 @@ public boolean refreshExchangeRates(String tenantId) {

private String getSystemCurrencyCode() {
log.info("Getting system currency");
try {
String localeSettingsResponse = simpleHttpClient.get(GET_LOCALE_SETTINGS_PATH, GET_LOCALE_SETTINGS_PARAMS);
ObjectMapper objectMapper = new ObjectMapper();
JsonNode localeSettingsNode = objectMapper.readTree(localeSettingsResponse);
String valueString = localeSettingsNode
.path("configs")
.get(0)
.path("value")
.asText();
JsonNode valueNode = objectMapper.readTree(valueString);
return valueNode.path("currency").asText();
} catch (Exception e) {
log.info("No system currency defined, defaulting to USD");
return "USD";
}
return localeClient.getLocaleSettings().currency();
}

private Double getExchangeRate(String fromCurrency, String toCurrency) {
Expand Down
Loading
Loading