Skip to content

Commit

Permalink
SDK-346, SDK-363, SDK-364 - Improvements to content package loading (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mseaton authored Dec 9, 2024
1 parent 7954240 commit e9477b0
Show file tree
Hide file tree
Showing 16 changed files with 432 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,28 @@ public void testBuildDistroWithSpaArtifacts() throws Exception {
assertFilePresent("target/web/openmrs-distro.properties");
assertSuccess();
}

@Test
public void testBuildDistroWithContentPackage() throws Exception {
includeDistroPropertiesFile("openmrs-distro-content-package.properties");
addTaskParam("dir", "target");
addTaskParam("ignorePeerDependencies", "false");
executeTask("build-distro");
assertFilePresent( "target", "web", "openmrs_core", "openmrs.war");
assertFilePresent("target", "web", "openmrs_config", "conceptclasses", "hiv", "conceptclasses.csv");
assertFilePresent("target", "web", "openmrs_config", "conceptsources", "hiv", "conceptsources.csv");
assertFilePresent("target", "web", "openmrs_config", "encountertypes", "hiv", "encountertypes.csv");
}

@Test
public void testBuildDistroWithWithContentPackageWithNoNamespace() throws Exception {
includeDistroPropertiesFile("openmrs-distro-content-package-no-namespace.properties");
addTaskParam("dir", "target");
addTaskParam("ignorePeerDependencies", "false");
executeTask("build-distro");
assertFilePresent( "target", "web", "openmrs_core", "openmrs.war");
assertFilePresent("target", "web", "openmrs_config", "conceptclasses", "conceptclasses.csv");
assertFilePresent("target", "web", "openmrs_config", "conceptsources", "conceptsources.csv");
assertFilePresent("target", "web", "openmrs_config", "encountertypes", "encountertypes.csv");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,21 @@ public void deploy_shouldUpgradeDistroWithContentPackage() throws Exception {
assertLogContains("+ Adds content package hiv 1.0.0");
}

@Test
public void deploy_shouldUpgradeDistroWithContentPackageWithoutNamespace() throws Exception {
testServerId = setupTestServer("referenceapplication:2.2");
includeDistroPropertiesFile("openmrs-distro-content-package-no-namespace.properties");
addAnswer(testServerId);
addAnswer("y");
addAnswer("y");
executeTask("deploy");
assertSuccess();
assertFilePresent(testServerId, "configuration", "conceptclasses", "conceptclasses.csv");
assertFilePresent(testServerId, "configuration", "conceptsources", "conceptsources.csv");
assertFilePresent(testServerId, "configuration", "encountertypes", "encountertypes.csv");
assertLogContains("+ Adds content package hiv 1.0.0");
}

@Test
public void deploy_shouldReplaceConfigurationAndContentIfChanged() throws Exception {
testServerId = setupTestServer("referenceapplication:2.2");
Expand All @@ -205,7 +220,7 @@ public void deploy_shouldReplaceConfigurationAndContentIfChanged() throws Except
assertNotNull(server);
assertThat(server.getConfigArtifacts().size(), equalTo(1));
assertThat(server.getConfigArtifacts().get(0).getArtifactId(), equalTo("distro-emr-configuration"));
assertThat(server.getContentArtifacts().size(), equalTo(0));
assertThat(server.getContentPackages().size(), equalTo(0));

includeDistroPropertiesFile("openmrs-distro-content-package.properties");
addAnswer(testServerId);
Expand All @@ -226,8 +241,8 @@ public void deploy_shouldReplaceConfigurationAndContentIfChanged() throws Except
server = Server.loadServer(testDirectoryPath.resolve(testServerId));
assertNotNull(server);
assertThat(server.getConfigArtifacts().size(), equalTo(0));
assertThat(server.getContentArtifacts().size(), equalTo(1));
assertThat(server.getContentArtifacts().get(0).getArtifactId(), equalTo("hiv"));
assertThat(server.getContentPackages().size(), equalTo(1));
assertThat(server.getContentPackages().get(0).getArtifactId(), equalTo("hiv"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,44 @@ public void setup_shouldInstallWithSpaSpecifiedAsMavenArtifacts() throws Excepti
assertFileContains("@openmrs/esm-dispensing-app", serverId, "frontend", "importmap.json");
}

@Test
public void setup_shouldInstallWithContentPackage() throws Exception {
includeDistroPropertiesFile("openmrs-distro-content-package.properties");
addTaskParam("distro", testDirectory.toString() + File.separator + "openmrs-distro.properties");
addMockDbSettings();

String serverId = UUID.randomUUID().toString();
addAnswer(serverId);
addAnswer("1044");
addAnswer("8080");

executeTask("setup");

assertFilePresent( serverId, "openmrs-2.6.9.war");
assertFilePresent(serverId, "configuration", "conceptclasses", "hiv", "conceptclasses.csv");
assertFilePresent(serverId, "configuration", "conceptsources", "hiv", "conceptsources.csv");
assertFilePresent(serverId, "configuration", "encountertypes", "hiv", "encountertypes.csv");
}

@Test
public void setup_shouldInstallWithContentPackageWithNoNamespace() throws Exception {
includeDistroPropertiesFile("openmrs-distro-content-package-no-namespace.properties");
addTaskParam("distro", testDirectory.toString() + File.separator + "openmrs-distro.properties");
addMockDbSettings();

String serverId = UUID.randomUUID().toString();
addAnswer(serverId);
addAnswer("1044");
addAnswer("8080");

executeTask("setup");

assertFilePresent( serverId, "openmrs-2.6.9.war");
assertFilePresent(serverId, "configuration", "conceptclasses", "conceptclasses.csv");
assertFilePresent(serverId, "configuration", "conceptsources", "conceptsources.csv");
assertFilePresent(serverId, "configuration", "encountertypes", "encountertypes.csv");
}

private String readValueFromPropertyKey(File propertiesFile, String key) throws Exception {

InputStream in = new FileInputStream(propertiesFile);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name=Content Package Example
version=1.0.0
war.openmrs=2.6.9
content.hiv.groupId=org.openmrs.content
content.hiv.type=zip
content.hiv=1.0.0
content.hiv.namespace=
db.h2.supported=true
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,7 @@ private String buildDistro(File targetDirectory, Distribution distribution) thro

File configDir = new File(web, SDKConstants.OPENMRS_SERVER_CONFIGURATION);
configurationInstaller.installToDirectory(configDir, distroProperties);

contentHelper.downloadAndMoveContentBackendConfig(web, distroProperties);

contentHelper.installBackendConfig(distroProperties, configDir);
spaInstaller.installFromDistroProperties(web, distroProperties, ignorePeerDependencies, overrideReuseNodeCache);

File owasDir = new File(web, "owa");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.apache.maven.shared.utils.StringUtils;
import org.openmrs.maven.plugins.model.Artifact;
import org.openmrs.maven.plugins.model.BaseSdkProperties;
import org.openmrs.maven.plugins.model.ContentPackage;
import org.openmrs.maven.plugins.model.Distribution;
import org.openmrs.maven.plugins.model.DistroProperties;
import org.openmrs.maven.plugins.model.Server;
Expand All @@ -15,6 +16,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -120,15 +122,6 @@ public void upgradeToDistro(Server server, Distribution distribution, boolean ig
}
}

// Upgrade spa
UpgradeDifferential.ArtifactChanges spaArtifactChanges = upgradeDifferential.getSpaArtifactChanges();
UpgradeDifferential.PropertyChanges spaBuildChanges = upgradeDifferential.getSpaBuildChanges();
boolean updateSpa = spaArtifactChanges.hasChanges() || spaBuildChanges.hasChanges();
if (updateSpa) {
parentTask.spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, ignorePeerDependencies, overrideReuseNodeCache);
server.replaceSpaProperties(distroProperties.getSpaProperties());
}

// Upgrade config and content
UpgradeDifferential.ArtifactChanges configChanges = upgradeDifferential.getConfigChanges();
UpgradeDifferential.ArtifactChanges contentChanges = upgradeDifferential.getContentChanges();
Expand Down Expand Up @@ -160,8 +153,7 @@ public void upgradeToDistro(Server server, Distribution distribution, boolean ig
}

if (contentChanges.hasChanges()) {
parentTask.contentHelper.downloadAndMoveContentBackendConfig(server.getServerDirectory(), distroProperties);
// TODO: Where is the frontend config installation?
parentTask.contentHelper.installBackendConfig(distroProperties, configDir);
for (Artifact artifact : contentChanges.getArtifactsToRemove()) {
server.removePropertiesForArtifact(BaseSdkProperties.TYPE_CONTENT, artifact);
}
Expand All @@ -171,6 +163,15 @@ public void upgradeToDistro(Server server, Distribution distribution, boolean ig
}
}

// Upgrade spa if any of the spa artifacts, build properties, or content packages have changes
UpgradeDifferential.ArtifactChanges spaArtifactChanges = upgradeDifferential.getSpaArtifactChanges();
UpgradeDifferential.PropertyChanges spaBuildChanges = upgradeDifferential.getSpaBuildChanges();
boolean updateSpa = spaArtifactChanges.hasChanges() || spaBuildChanges.hasChanges() || contentChanges.hasChanges();
if (updateSpa) {
parentTask.spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, ignorePeerDependencies, overrideReuseNodeCache);
server.replaceSpaProperties(distroProperties.getSpaProperties());
}

server.setVersion(distroProperties.getVersion());
server.setName(distroProperties.getName());
if (server.getDistroPropertiesFile().delete()) {
Expand Down Expand Up @@ -225,8 +226,14 @@ public UpgradeDifferential calculateUpdateDifferential(Server server, Distributi
upgradeDifferential.setConfigChanges(new UpgradeDifferential.ArtifactChanges(oldConfig, newConfig));

// Content
List<Artifact> oldContent = server.getContentArtifacts();
List<Artifact> newContent = distroProperties.getContentArtifacts();
List<Artifact> oldContent = new ArrayList<>();
for (ContentPackage contentPackage : server.getContentPackages()) {
oldContent.add(contentPackage.getArtifact());
}
List<Artifact> newContent = new ArrayList<>();
for (ContentPackage contentPackage : distroProperties.getContentPackages()) {
newContent.add(contentPackage.getArtifact());
}
upgradeDifferential.setContentChanges(new UpgradeDifferential.ArtifactChanges(oldContent, newContent));

return upgradeDifferential;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ public void setup(Server server, DistroProperties distroProperties) throws MojoE
distroHelper.parseContentProperties(distroProperties);
moduleInstaller.installModulesForDistro(server, distroProperties);

contentHelper.downloadAndMoveContentBackendConfig(server.getServerDirectory(), distroProperties);
File configurationDir = new File(server.getServerDirectory(), SDKConstants.OPENMRS_SERVER_CONFIGURATION);
contentHelper.installBackendConfig(distroProperties, configurationDir);

if (spaInstaller != null) {
spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, ignorePeerDependencies, overrideReuseNodeCache);
Expand Down
Loading

0 comments on commit e9477b0

Please sign in to comment.