Skip to content

Commit

Permalink
O3-3438: Update SPA module to load the bundled frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
wikumChamith committed Aug 16, 2024
1 parent 490ad71 commit 1db7ddb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
22 changes: 21 additions & 1 deletion omod/src/main/java/org/openmrs/module/spa/SpaActivator.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,35 @@
import org.openmrs.api.context.Context;
import org.openmrs.module.BaseModuleActivator;

import javax.servlet.ServletContext;
import java.nio.file.Path;
import java.nio.file.Paths;

import static org.openmrs.module.spa.SpaConstants.BUNDLED_FRONTEND_DIRECTORY;
import static org.openmrs.module.spa.SpaConstants.GP_LOCAL_DIRECTORY;

@Slf4j
public class SpaActivator extends BaseModuleActivator {

// here so we can register the listener on load and de-register it when stopped
private GlobalPropertyListener spaDirectoryResolver = null;

public static ServletContext servletContext;

@Override
public void started() {
log.info("SPA module started");
spaDirectoryResolver = new SpaDirectoryResolver();
}

@Override
public void contextRefreshed() {
SpaDirectoryResolver spaDirectoryResolver = new SpaDirectoryResolver();
if (!Paths.get(SpaDirectoryResolver.getSpaDirectory(), "index.html").toFile().exists()) {
Path bundledFrontend = Paths.get(servletContext.getRealPath("/"), "WEB-INF", BUNDLED_FRONTEND_DIRECTORY);
if (bundledFrontend.resolve("index.html").toFile().exists()) {
Context.getAdministrationService().setGlobalProperty(GP_LOCAL_DIRECTORY, bundledFrontend.toAbsolutePath().toString());
}
}
Context.getAdministrationService().addGlobalPropertyListener(spaDirectoryResolver);
}

Expand All @@ -33,4 +52,5 @@ public void stopped() {
spaDirectoryResolver = null;
log.info("SPA module stopped");
}

}
2 changes: 2 additions & 0 deletions omod/src/main/java/org/openmrs/module/spa/SpaConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ private SpaConstants() {}

public static final String DEFAULT_FRONTEND_DIRECTORY = "frontend";

public static final String BUNDLED_FRONTEND_DIRECTORY = "bundledFrontend";

public static final String GP_LOCAL_DIRECTORY = "spa.local.directory";
}

Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ private static void resolveDirectory(String spaDirectory) {
SpaDirectoryResolver.spaDirectory.set(Paths.get(OpenmrsUtil.getApplicationDataDirectory(), DEFAULT_FRONTEND_DIRECTORY).normalize().toAbsolutePath().toString());
}
SpaDirectoryResolver.spaDirectory.set(spaDirectoryPath.normalize().toString());
} else {
SpaDirectoryResolver.spaDirectory.set(spaDirectory);
}
}
}

0 comments on commit 1db7ddb

Please sign in to comment.