Skip to content

Commit

Permalink
Merge pull request #421 from folio-org/MODORDSTOR-408-upgrade-skips-data
Browse files Browse the repository at this point in the history
MODORDSTOR-408: Upgrading tenant resets reference and sample records
  • Loading branch information
julianladisch authored Jun 28, 2024
2 parents 2e7fc81 + 53b1d69 commit 577f0ab
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 7 deletions.
34 changes: 27 additions & 7 deletions src/main/java/org/folio/rest/impl/TenantReferenceAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.folio.dbschema.Versioned;
import org.folio.rest.jaxrs.model.Parameter;
import org.folio.rest.jaxrs.model.TenantAttributes;
import org.folio.rest.persist.PostgresClient;
Expand Down Expand Up @@ -60,13 +61,19 @@ public Future<Integer> loadData(TenantAttributes attributes, String tenantId, Ma
.onFailure(throwable -> Future.failedFuture(throwable.getCause()));
}

private void buildDataLoadingParameters(TenantAttributes tenantAttributes, TenantLoading tl) {
if (isNew(tenantAttributes, "13.5.0")) {
tl.withKey(PARAMETER_LOAD_SYSTEM)
.withLead("data/system")
.add("reasons-for-closure", "orders-storage/configuration/reasons-for-closure")
.add("acquisition-methods", "orders-storage/acquisition-methods");
}

if (!isLoadSample(tenantAttributes)) {
return;
}

private boolean buildDataLoadingParameters(TenantAttributes tenantAttributes, TenantLoading tl) {
tl.withKey(PARAMETER_LOAD_SYSTEM)
.withLead("data/system")
.add("reasons-for-closure", "orders-storage/configuration/reasons-for-closure")
.add("acquisition-methods", "orders-storage/acquisition-methods");
if (isLoadSample(tenantAttributes)) {
if (isNew(tenantAttributes, "13.7.0")) {
tl.withKey(PARAMETER_LOAD_SAMPLE)
.withLead("data")
.add("alerts", "orders-storage/alerts")
Expand All @@ -82,7 +89,20 @@ private boolean buildDataLoadingParameters(TenantAttributes tenantAttributes, Te
.add("configuration/prefixes", "orders-storage/configuration/prefixes")
.add("configuration/suffixes", "orders-storage/configuration/suffixes");
}
return true;
}

/**
* Returns attributes.getModuleFrom() < featureVersion or
* attributes.getModuleFrom() is null.
*/
static boolean isNew(TenantAttributes attributes, String featureVersion) {
if (attributes.getModuleFrom() == null) {
return true;
}
var since = new Versioned() {
};
since.setFromModuleVersion(featureVersion);
return since.isNewForThisInstall(attributes.getModuleFrom());
}

private boolean isLoadSample(TenantAttributes tenantAttributes) {
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/org/folio/StorageTestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.folio.rest.impl.PurchaseOrderNumberUniquenessTest;
import org.folio.rest.impl.ReceivingHistoryTest;
import org.folio.rest.impl.SearchOrderLinesTest;
import org.folio.rest.impl.TenantReferenceDataTest;
import org.folio.rest.impl.TenantSampleDataTest;
import org.folio.rest.jaxrs.model.TenantJob;
import org.folio.rest.persist.DBClientTest;
Expand Down Expand Up @@ -245,6 +246,8 @@ class ReceivingHistoryTestNested extends ReceivingHistoryTest {}
@Nested
class SearchOrderLinesTestNested extends SearchOrderLinesTest {}
@Nested
class TenantRefereceDataTestNested extends TenantReferenceDataTest {}
@Nested
class TenantSampleDataTestNested extends TenantSampleDataTest {}
@Nested
class HelperUtilsTestNested extends HelperUtilsTest {}
Expand Down
46 changes: 46 additions & 0 deletions src/test/java/org/folio/rest/impl/TenantReferenceDataTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.folio.rest.impl;

import static org.folio.rest.RestVerticle.OKAPI_HEADER_TENANT;
import static org.folio.rest.utils.TenantApiTestUtil.postTenant;
import static org.hamcrest.Matchers.is;

import io.restassured.http.Header;
import io.restassured.http.Headers;
import lombok.SneakyThrows;
import org.folio.rest.jaxrs.model.TenantAttributes;
import org.folio.rest.utils.TenantApiTestUtil;
import org.junit.jupiter.api.Test;

public class TenantReferenceDataTest extends TestBase {
private static final Header REF_HEADER = new Header(OKAPI_HEADER_TENANT, "ref");

@Test
@SneakyThrows
public void referenceData() {
var url = "/orders-storage/acquisition-methods/{id}";
TenantAttributes tenantAttributes = TenantApiTestUtil.prepareTenantBody(false, true);
postTenant(REF_HEADER, tenantAttributes);
deleteData(url, "da6703b1-81fe-44af-927a-94f24d1ab8ee", REF_HEADER)
.then().statusCode(204);
// translate English "Gift" to German "Geschenk"
putData(url, "0a4163a5-d225-4007-ad90-2fb41b73efab",
"""
{
"id": "0a4163a5-d225-4007-ad90-2fb41b73efab",
"value": "Geschenk",
"source": "System"
}
""", Headers.headers(REF_HEADER))
.then().statusCode(204);

// migrate from Orchid (13.5.0), the two acquisition methods exist in that version
// and therefore should not be reinstalled when migrating to any later version
tenantAttributes = tenantAttributes.withModuleFrom("13.5.0");
postTenant(REF_HEADER, tenantAttributes);

getDataById(url, "da6703b1-81fe-44af-927a-94f24d1ab8ee", REF_HEADER)
.then().statusCode(404);
getDataById(url, "0a4163a5-d225-4007-ad90-2fb41b73efab", REF_HEADER)
.then().statusCode(200).body("value", is("Geschenk"));
}
}

0 comments on commit 577f0ab

Please sign in to comment.