Skip to content

Commit

Permalink
SDK-342 - SDK fails if distro.properties supplies type or group for c…
Browse files Browse the repository at this point in the history
…ontent package (#302)
  • Loading branch information
mseaton authored Nov 8, 2024
1 parent b4160cf commit 0d54196
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ spa.frontendModules.@openmrs/esm-login-app=5.6.0
spa.frontendModules.@openmrs/esm-patient-chart-app=8.0.0
spa.apiUrl=notopenmrs
spa.configUrls=foo
content.hiv.groupId=org.openmrs.content
content.hiv.type=zip
content.hiv=1.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,14 @@ public List<Artifact> getContentArtifacts() {
List<Artifact> artifacts = new ArrayList<>();
for (Object keyObject : getAllKeys()) {
String key = keyObject.toString();
if (key.startsWith(TYPE_CONTENT + ".")) {
artifacts.add(new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key),
checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE)));
String artifactType = getArtifactType(key);
if (artifactType.equals(TYPE_CONTENT)) {
artifacts.add(new Artifact(
checkIfOverwritten(key, ARTIFACT_ID),
getParam(key),
checkIfOverwritten(key, GROUP_ID),
checkIfOverwritten(key, TYPE)
));
}
}
return artifacts;
Expand All @@ -166,7 +171,7 @@ protected Set<Object> getAllKeys() {
return properties.keySet();
}

protected String getArtifactType(String key){
protected String getArtifactType(String key) {
String[] wordsArray = key.split("\\.");
if(!(wordsArray[wordsArray.length-1].equals(TYPE) || wordsArray[wordsArray.length-1].equals(ARTIFACT_ID) || wordsArray[wordsArray.length-1].equals(GROUP_ID))){
if(key.contains(".")){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,23 +641,16 @@ public void parseContentProperties(DistroProperties distroProperties) throws Moj
*/
public void downloadContentPackages(File contentPackageZipFile, DistroProperties distroProperties)
throws MojoExecutionException {
Properties contentProperties = new Properties();

for (Object key : distroProperties.getAllKeys()) {
String keyOb = key.toString();
if (!keyOb.startsWith(CONTENT_PREFIX)) {
continue;
}
Properties contentProperties = new Properties();

Artifact artifact = new Artifact(distroProperties.checkIfOverwritten(keyOb.replace(CONTENT_PREFIX, ""), ARTIFACT_ID), distroProperties.getParam(keyOb),
distroProperties.checkIfOverwritten(keyOb, GROUP_ID), distroProperties.checkIfOverwritten(keyOb, TYPE));
for (Artifact artifact : distroProperties.getContentArtifacts()) {

String version = distroProperties.get(keyOb);
String zipFileName = keyOb.replace(CONTENT_PREFIX, "") + "-" + version + ".zip";
String zipFileName = artifact.getArtifactId() + "-" + artifact.getVersion() + ".zip";
File zipFile = downloadDistro(contentPackageZipFile, artifact, zipFileName);

if (zipFile == null) {
log.warn("ZIP file not found for content package: {}", keyOb);
log.warn("ZIP file not found for content package: {}", artifact.getArtifactId());
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import java.util.List;
import java.util.Properties;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;

Expand Down Expand Up @@ -50,6 +52,42 @@ public void resolvePlaceholders_shouldReplaceVersions() throws MojoExecutionExce
assertThat(distro.getPlatformVersion(), is("222"));
}

@Test
public void shouldGetContentPropertiesWithDefaults() {
Properties properties = new Properties();
properties.setProperty("content.hiv", "1.0.0");
properties.setProperty("content.tb", "2.3.4-SNAPSHOT");
DistroProperties distro = new DistroProperties(properties);
List<Artifact> contentArtifacts = distro.getContentArtifacts();
assertThat(contentArtifacts, hasSize(2));
Artifact hiv = findArtifactByArtifactId(contentArtifacts, "hiv");
assertThat(hiv, notNullValue());
assertThat(hiv, hasVersion("1.0.0"));
assertThat(hiv.getGroupId(), equalTo(Artifact.GROUP_CONTENT));
assertThat(hiv.getType(), equalTo(Artifact.TYPE_ZIP));
Artifact tb = findArtifactByArtifactId(contentArtifacts, "tb");
assertThat(tb, notNullValue());
assertThat(tb, hasVersion("2.3.4-SNAPSHOT"));
assertThat(tb.getGroupId(), equalTo(Artifact.GROUP_CONTENT));
assertThat(tb.getType(), equalTo(Artifact.TYPE_ZIP));
}

@Test
public void shouldGetContentPropertiesWithOverrides() {
Properties properties = new Properties();
properties.setProperty("content.hiv", "1.0.0");
properties.setProperty("content.hiv.groupId", "org.openmrs.new");
properties.setProperty("content.hiv.type", "gzip");
DistroProperties distro = new DistroProperties(properties);
List<Artifact> contentArtifacts = distro.getContentArtifacts();
assertThat(contentArtifacts, hasSize(1));
Artifact hiv = findArtifactByArtifactId(contentArtifacts, "hiv");
assertThat(hiv, notNullValue());
assertThat(hiv, hasVersion("1.0.0"));
assertThat(hiv.getGroupId(), equalTo("org.openmrs.new"));
assertThat(hiv.getType(), equalTo("gzip"));
}

@Test(expected = MojoExecutionException.class)
public void resolvePlaceholders_shouldFailIfNoPropertyForPlaceholderFound() throws MojoExecutionException {
Properties properties = new Properties();
Expand Down

0 comments on commit 0d54196

Please sign in to comment.