Skip to content

Commit

Permalink
ATLAS-195: Tweak the atlas module to work with atlas
Browse files Browse the repository at this point in the history
  • Loading branch information
HelioStrike committed Aug 7, 2019
1 parent 6cd4f8f commit 3e95deb
Show file tree
Hide file tree
Showing 17 changed files with 258 additions and 133 deletions.
6 changes: 6 additions & 0 deletions .project
Expand Up @@ -30,8 +30,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
@@ -1,3 +1,4 @@
language: java
jdk:
- oraclejdk8
- oraclejdk8
dist: trusty
220 changes: 132 additions & 88 deletions api/.classpath

Large diffs are not rendered by default.

34 changes: 22 additions & 12 deletions api/.project
@@ -1,13 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>atlas-api</name>
<comment>API project for Atlas Module. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
<projects/>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
<name>atlas-api</name>
<comment>API project for Atlas Module. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
12 changes: 8 additions & 4 deletions api/.settings/org.eclipse.jdt.core.prefs
@@ -1,5 +1,9 @@
#Mon Jun 27 21:31:19 EEST 2011
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.source=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.6
Expand Up @@ -20,7 +20,9 @@
public class AtlasConstants {

public final static String GLOBALPROPERTY_ID = "atlas.id";


public final static String GLOBALPROPERTY_TOKEN = "atlas.token";

public final static String GLOBALPROPERTY_NUMBER_OF_PATIENTS = "atlas.numberOfPatients";

public final static String GLOBALPROPERTY_NUMBER_OF_OBSERVATIONS = "atlas.numberOfObservations";
Expand All @@ -41,7 +43,7 @@ public class AtlasConstants {

public final static String POST_ATLAS_DATA_TASK_DESCRIPTION = "Send Atlas information to OpenMRS on a weekly basis.";

public final static String SERVER_PING_URL = "https://atlas.openmrs.org/module/ping.php";
public final static String SERVER_PING_URL = "https://atlas.openmrs.org/api/module/ping";

public final static String SERVER_URL = "https://atlas.openmrs.org/module";

Expand Down
26 changes: 19 additions & 7 deletions api/src/main/java/org/openmrs/module/atlas/AtlasData.java
Expand Up @@ -22,7 +22,9 @@
public class AtlasData {

private UUID id;


private UUID token;

/* /Bubble data */
private String numberOfPatients;

Expand All @@ -41,6 +43,7 @@ public class AtlasData {
public AtlasData() {

this.id = null;
this.token = null;
this.numberOfObservations = "?";
this.numberOfPatients = "?";
this.numberOfEncounters = "?";
Expand Down Expand Up @@ -71,6 +74,20 @@ public void setId(UUID id) {
this.id = id;
}

/**
* @return the token
*/
public UUID getToken() {
return token;
}

/**
* @param id the token to set
*/
public void setToken(UUID token) {
this.token = token;
}

/**
* @return the numberOfObservations
*/
Expand Down Expand Up @@ -161,12 +178,7 @@ public String getServerUrl() {
* @return the serverUrlEncoded
*/
public String getServerUrlEncoded() {
String patients = (getNumberOfPatients().equals("?")) ? "" : getNumberOfPatients();
String encounters = (getNumberOfEncounters().equals("?")) ? "" : getNumberOfEncounters();
String observations = (getNumberOfObservations().equals("?")) ? "" : getNumberOfObservations();

return serverUrl+"?uuid="+id+"&patients=" + patients + "&encounters="
+ encounters+"&observations=" + observations + "&sendCounts=" + sendCounts;
return serverUrl;
}
/**
* @param serverUrl the serverUrl to set
Expand Down
Expand Up @@ -41,19 +41,33 @@ public void willStart() {
@Override
public void started() {
log.info("Setting implementation id");
AdministrationService svc = Context.getAdministrationService();

try {
AdministrationService svc = Context.getAdministrationService();
String idString = svc.getGlobalProperty(AtlasConstants.GLOBALPROPERTY_ID);

//if not found, generate UUID for Atlas ID
//if id is not found, generate UUID for Atlas ID
if (idString == null || idString.trim().equals("")) {
svc.saveGlobalProperty(new GlobalProperty(AtlasConstants.GLOBALPROPERTY_ID, UUID.randomUUID().toString()));
}
}
}
catch (APIException apiEx) {
if (log.isErrorEnabled())
log.error("Could not set atlas id. Exception:" + apiEx.getMessage());
}

try {
String token = svc.getGlobalProperty(AtlasConstants.GLOBALPROPERTY_TOKEN);

//if token is not found, generate UUID for Atlas ID
if (token == null || token.trim().equals("")) {
svc.saveGlobalProperty(new GlobalProperty(AtlasConstants.GLOBALPROPERTY_TOKEN, UUID.randomUUID().toString()));
}
}
catch (APIException apiEx) {
if (log.isErrorEnabled())
log.error("Could not set atlas token. Exception:" + apiEx.getMessage());
}

}

Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.openmrs.api.db.hibernate.DbSessionFactory;

/**
* Hibernate implementation of the Statistics DAO
Expand All @@ -36,7 +37,7 @@ public class HibernateStatisticsDAO implements StatisticsDAO {
/**
* Hibernate session factory
*/
private SessionFactory sessionFactory;
private DbSessionFactory sessionFactory;

/**
* Default public constructor
Expand All @@ -49,7 +50,7 @@ public HibernateStatisticsDAO() {
*
* @param sessionFactory
*/
public void setSessionFactory(SessionFactory sessionFactory) {
public void setSessionFactory(DbSessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}

Expand Down
Expand Up @@ -74,9 +74,11 @@ public AtlasData getAtlasData() throws APIException {
try {
svc = Context.getAdministrationService();
String globalProperty = svc.getGlobalProperty(AtlasConstants.GLOBALPROPERTY_ID);

atlasData.setId(UUID.fromString(globalProperty));

globalProperty = svc.getGlobalProperty(AtlasConstants.GLOBALPROPERTY_TOKEN);
atlasData.setToken(UUID.fromString(globalProperty));

if ((globalProperty = svc.getGlobalProperty(AtlasConstants.GLOBALPROPERTY_NUMBER_OF_OBSERVATIONS)) != null) {
atlasData.setNumberOfObservations(globalProperty);
}
Expand Down Expand Up @@ -218,7 +220,6 @@ public void setAtlasBubbleData(AtlasData data) throws APIException {
AdministrationService svc = null;
try {
svc = Context.getAdministrationService();
String idString = svc.getGlobalProperty(AtlasConstants.GLOBALPROPERTY_ID);
setIsDirty(true);
}
catch (APIException apiEx) {
Expand Down Expand Up @@ -287,14 +288,13 @@ public void postAtlasData() throws APIException {
public String getJson(Boolean isPreview) throws APIException {
AtlasData data = getAtlasData();
StringBuilder sb = new StringBuilder();
String atlasVersion = ModuleFactory.getModuleById("atlas").getVersion();
String openMRSVersion = getOpenMRSVersion();
sb.append("{\"id\" : \"" + data.getId() + "\", ");
sb.append("\"token\" : \"" + data.getToken() + "\",");
sb.append("\"patients\" : \"" + data.getNumberOfPatients() + "\",");
sb.append("\"observations\" : \"" + data.getNumberOfObservations() + "\",");
sb.append("\"encounters\" : \"" + data.getNumberOfEncounters() + "\",");
sb.append("\"atlasVersion\" : \"" + atlasVersion + "\"");
sb.append(", \"data\" : {");
sb.append("\"data\" : {");
sb.append("\"version\" : \"" + openMRSVersion + "\",");
Collection<Module> modules = ModuleFactory.getLoadedModules();
sb.append("\"modules\" : [");
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/resources/moduleApplicationContext.xml
Expand Up @@ -13,7 +13,7 @@
<bean class="org.openmrs.module.atlas.impl.AtlasServiceImpl">
<property name="statisticsDAO">
<bean class="org.openmrs.module.atlas.db.hibernate.HibernateStatisticsDAO">
<property name="sessionFactory"><ref bean="sessionFactory"/></property>
<property name="sessionFactory"><ref bean="dbSessionFactory"/></property>
</bean>
</property>
</bean>
Expand Down
Expand Up @@ -19,7 +19,9 @@
public class AtlasServiceTest extends BaseModuleContextSensitiveTest {

String id = "73b13680-c4a0-11e0-962b-0800200c9a66";


String token = "fcd9ad8f-6d0d-4853-bd28-cfab30ffc4a6";

AtlasService atlasSrv;

AtlasData data;
Expand All @@ -34,13 +36,15 @@ public void runBeforeEachTest() throws Exception {
public AtlasData getTestAtlasData() {
AtlasData data = new AtlasData();
data.setId(UUID.fromString(id));
data.setToken(UUID.fromString(token));
return data;
}

public void saveTestAtlasDataToGlobalProperties(AtlasData data) {
AdministrationService svc = Context.getAdministrationService();

svc.saveGlobalProperty(new GlobalProperty(AtlasConstants.GLOBALPROPERTY_ID, data.getId().toString()));
svc.saveGlobalProperty(new GlobalProperty(AtlasConstants.GLOBALPROPERTY_TOKEN, data.getToken().toString()));
svc.saveGlobalProperty(new GlobalProperty(AtlasConstants.GLOBALPROPERTY_MODULE_ENABLED, data.getModuleEnabled()
.toString()));
}
Expand Down
6 changes: 6 additions & 0 deletions omod/.project
Expand Up @@ -15,8 +15,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
</natures>
Expand Down
12 changes: 11 additions & 1 deletion omod/src/main/webapp/managemarker.jsp
Expand Up @@ -13,7 +13,7 @@
var jq = jQuery.noConflict();
var connected;
function updateModulefromServer() {
connected = isModuleConnect("${atlasData.serverUrl}/auth?uuid=${atlasData.id}&callback=getAuth");
connected = isModuleConnect("${atlasData.serverUrl}", "${atlasData.id}", "${atlasData.token}");
}
function receiveMessage(event) {
updateModulefromServer();
Expand Down Expand Up @@ -115,5 +115,15 @@
style="resize: none;"></textarea>
</div>

<script>
window.addEventListener("message", function(event) {
if(event.data === "atlas loaded") {
var atlasFrame = document.getElementsByTagName('iframe')[0].contentWindow;
atlasFrame.postMessage("module_id:${atlasData.id}", "*");
atlasFrame.postMessage("token:${atlasData.token}", "*");
atlasFrame.postMessage("has_site:"+connected, "*");
}
}, false);
</script>

<%@ include file="/WEB-INF/template/footer.jsp" %>
13 changes: 12 additions & 1 deletion omod/src/main/webapp/pages/map.gsp
Expand Up @@ -14,7 +14,7 @@ ui.includeCss("atlas", "atlas-2.0.css")
];
var connected;
function updateModulefromServer() {
connected = isModuleConnect("${data.serverUrl}/auth?uuid=${data.id}&callback=getAuth");
connected = isModuleConnect("${atlasData.serverUrl}", "${atlasData.id}", "${atlasData.token}");
}
function receiveMessage(event){
updateModulefromServer();
Expand Down Expand Up @@ -97,6 +97,17 @@ ui.includeCss("atlas", "atlas-2.0.css")
</div>
</div>

<script>
window.addEventListener("message", function(event) {
if(event.data === "atlas loaded") {
var atlasFrame = document.getElementsByTagName('iframe')[0].contentWindow;
atlasFrame.postMessage("module_id:${atlasData.id}", "*");
atlasFrame.postMessage("token:${atlasData.token}", "*");
atlasFrame.postMessage("has_site:"+connected, "*");
}
}, false);
</script>

<% if (!data.moduleEnabled && !stopAskingToConfigure) { %>
<div>
<a href="?stopAskingToConfigure=true">${ ui.message("atlas.stopAskingToConfigure") }</a>
Expand Down
8 changes: 4 additions & 4 deletions omod/src/main/webapp/resources/scripts/atlas.js
Expand Up @@ -18,15 +18,15 @@ function initializeDialog() {
dialog.close();
});
}
function isModuleConnect(url) {
function isModuleConnect(url, module_id, token) {
$j.ajax({
url: url,
type: "GET",
dataType: "jsonp"
type: "POST",
data: encodeURIComponent("module_id")+"="+encodeURIComponent(module_id)+"&"+encodeURIComponent("token")+"="+encodeURIComponent(token)
})
.done(function(response) {
auth = response;
if (auth.length > 0) {
if (auth) {
$j('#unlinked').hide();
$j('#module-control').show();
return (connected = true);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -79,7 +79,7 @@
</dependencyManagement>

<properties>
<openMRSVersion>1.7.4</openMRSVersion>
<openMRSVersion>1.9.9</openMRSVersion>
</properties>

<build>
Expand Down

0 comments on commit 3e95deb

Please sign in to comment.