Skip to content

Commit

Permalink
#73 Vue loading enabled, api.js and icpc.js moved to webjar-like loca…
Browse files Browse the repository at this point in the history
…tion

for access.
  • Loading branch information
TareqK committed Sep 25, 2020
1 parent 0332ef8 commit 2759656
Show file tree
Hide file tree
Showing 7 changed files with 382 additions and 156 deletions.
68 changes: 6 additions & 62 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.8.0-beta4</version>
<version>1.7.26</version>
</dependency>
<dependency>
<groupId>org.webjars.npm</groupId>
<artifactId>vue</artifactId>
<version>2.6.10</version>
</dependency>
</dependencies>
<build>
Expand All @@ -122,67 +127,6 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<nodeVersion>${node.version}</nodeVersion>
<workingDirectory>${basedir}/src/main/webapp</workingDirectory>
</configuration>
<executions>
<execution>
<id>install node</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<phase>validate</phase>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<phase>validate</phase>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>npm run build</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/webapp</outputDirectory>
<resources>
<resource>
<directory>src/main/webapp/dist</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
Expand Down
193 changes: 99 additions & 94 deletions core/src/main/java/org/openmymed/accessmd/app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static io.javalin.core.security.SecurityUtil.roles;
import io.javalin.http.Context;
import io.javalin.http.staticfiles.Location;
import io.javalin.plugin.rendering.vue.VueComponent;
import java.io.File;
import java.sql.DriverManager;
import java.sql.SQLException;
Expand Down Expand Up @@ -105,7 +106,7 @@ public void run() {

public static void startServer() {
app = Javalin.create().start(7000);

app.config.enableWebjars();
// Set the access-manager that Javalin should use
app.config.accessManager((handler, ctx, permittedRoles) -> {
if (!permittedRoles.contains(NONE)) {
Expand All @@ -123,114 +124,123 @@ public static void startServer() {
ICPCRestService icpcService = new ICPCRestService();
DoctorRestService doctorService = new DoctorRestService();
NotificationRestService notificationService = new NotificationRestService();
app.get("/", new VueComponent("<login></login>"), roles(NONE));
app.get("/dashboard", new VueComponent("<doctor-home></doctor-home>"), roles(ROLE_DOCTOR));
app.get("/patient", new VueComponent("<patient-list></patient-list>"), roles(ROLE_DOCTOR));
app.get("/patient/:patientId", new VueComponent("<patient-details></patient-details>"), roles(ROLE_DOCTOR));

app.get("/admin/dashboard", new VueComponent("<admin-home></admin-home>"), roles(ROLE_ADMIN));

app.routes(() -> {
path("login", () -> {
post(userService::signIn, roles(NONE));
});
path("symptom", () -> {
path("codes", () -> {
get(icpcService::getICPCSymptoms, roles(NONE));
});
});
path("notification", () -> {
get(notificationService::getNotifications, roles(ROLE_PATIENT, ROLE_DOCTOR));
});
path("patient", () -> {
path("doctor", () -> {
get(patientService::getDoctor, roles(ROLE_PATIENT));
});
path("signup", () -> {
post(patientService::signUp, roles(NONE));
});
path("profile", () -> {
put(patientService::updateMedicalProfile, roles(ROLE_PATIENT));
get(patientService::getMedicalProfile, roles(ROLE_PATIENT));
});
path("reccomendation", () -> {
get(patientService::getReccomendations, roles(ROLE_PATIENT));
});
path("question", () -> {
get(patientService::getUnansweredQuestions, roles(ROLE_PATIENT));
path(":id", () -> {
path("answer", () -> {
put(patientService::answerQuestion, roles(ROLE_PATIENT));
});
});
});
path("code", () -> {
get(patientService::getSecurityCode, roles(ROLE_PATIENT));
path("/api", () -> {
path("login", () -> {
post(userService::signIn, roles(NONE));
});
path("symptom", () -> {
post(patientService::addSymptom, roles(ROLE_PATIENT));
});
path("vitals", () -> {
post(patientService::addVitalsMeasurment, roles(ROLE_PATIENT));
path("codes", () -> {
get(icpcService::getICPCSymptoms, roles(NONE));
});
});
});
path("doctor", () -> {
path("feed", () -> {
get(doctorService::getPatientsFeed, roles(ROLE_DOCTOR));
path("notification", () -> {
get(notificationService::getNotifications, roles(ROLE_PATIENT, ROLE_DOCTOR));
});
path("patient", () -> {
path("symptom", () -> {
path("count", () -> {
get(doctorService::getUnseenSymptomCount, roles(ROLE_DOCTOR));
});
path("doctor", () -> {
get(patientService::getDoctor, roles(ROLE_PATIENT));
});
path("answer", () -> {
path("count", () -> {
get(doctorService::getUnseenAnswerCount, roles(ROLE_DOCTOR));
});
path("signup", () -> {
post(patientService::signUp, roles(NONE));
});

path("count", () -> {
get(doctorService::getPatientCount, roles(ROLE_DOCTOR));
path("profile", () -> {
put(patientService::updateMedicalProfile, roles(ROLE_PATIENT));
get(patientService::getMedicalProfile, roles(ROLE_PATIENT));
});
get(doctorService::listPatients, roles(ROLE_DOCTOR));
path("add", () -> {
post(doctorService::consumePatientCode, roles(ROLE_DOCTOR));
path("reccomendation", () -> {
get(patientService::getReccomendations, roles(ROLE_PATIENT));
});
path(":id", () -> {
get(doctorService::getPatient, roles(ROLE_DOCTOR));
path("profile", () -> {
get(doctorService::getPatientProfile, roles(ROLE_DOCTOR));
});
path("vitals", () -> {
get(doctorService::getPatientVitalsMeasurments, roles(ROLE_DOCTOR));
path("question", () -> {
get(patientService::getUnansweredQuestions, roles(ROLE_PATIENT));
path(":id", () -> {
path("answer", () -> {
put(patientService::answerQuestion, roles(ROLE_PATIENT));
});
});
});
path("code", () -> {
get(patientService::getSecurityCode, roles(ROLE_PATIENT));
});
path("symptom", () -> {
post(patientService::addSymptom, roles(ROLE_PATIENT));
});
path("vitals", () -> {
post(patientService::addVitalsMeasurment, roles(ROLE_PATIENT));
});
});
path("doctor", () -> {
path("feed", () -> {
get(doctorService::getPatientsFeed, roles(ROLE_DOCTOR));
});
path("patient", () -> {
path("symptom", () -> {
get(doctorService::listPatientSymptoms, roles(ROLE_DOCTOR));
path(":symptom_id", () -> {
path("seen", () -> {
put(doctorService::markSymptomSeen, roles(ROLE_DOCTOR));
});
path("count", () -> {
get(doctorService::getUnseenSymptomCount, roles(ROLE_DOCTOR));
});
});
path("answer", () -> {
get(doctorService::listPatientAnswers, roles(ROLE_DOCTOR));
path(":answer_id", () -> {
path("seen", () -> {
put(doctorService::markAnswerSeen, roles(ROLE_DOCTOR));
});
path("count", () -> {
get(doctorService::getUnseenAnswerCount, roles(ROLE_DOCTOR));
});
});
path("question", () -> {
get(doctorService::listPatientQuestions, roles(ROLE_DOCTOR));
post(doctorService::createPatientQuestion, roles(ROLE_DOCTOR));
path(":question_id", () -> {
delete(doctorService::deletePatientQuestion, roles(ROLE_DOCTOR));
put(doctorService::updatePatientQuestion, roles(ROLE_DOCTOR));
get(doctorService::getPatientQuestion, roles(ROLE_DOCTOR));

path("count", () -> {
get(doctorService::getPatientCount, roles(ROLE_DOCTOR));
});
get(doctorService::listPatients, roles(ROLE_DOCTOR));
path("add", () -> {
post(doctorService::consumePatientCode, roles(ROLE_DOCTOR));
});
path(":id", () -> {
get(doctorService::getPatient, roles(ROLE_DOCTOR));
path("profile", () -> {
get(doctorService::getPatientProfile, roles(ROLE_DOCTOR));
});
path("vitals", () -> {
get(doctorService::getPatientVitalsMeasurments, roles(ROLE_DOCTOR));
});
path("symptom", () -> {
get(doctorService::listPatientSymptoms, roles(ROLE_DOCTOR));
path(":symptom_id", () -> {
path("seen", () -> {
put(doctorService::markSymptomSeen, roles(ROLE_DOCTOR));
});
});
});
path("answer", () -> {
get(doctorService::listPatientAnswers, roles(ROLE_DOCTOR));
path(":answer_id", () -> {
path("seen", () -> {
put(doctorService::markAnswerSeen, roles(ROLE_DOCTOR));
});
});
});
path("question", () -> {
get(doctorService::listPatientQuestions, roles(ROLE_DOCTOR));
post(doctorService::createPatientQuestion, roles(ROLE_DOCTOR));
path(":question_id", () -> {
delete(doctorService::deletePatientQuestion, roles(ROLE_DOCTOR));
put(doctorService::updatePatientQuestion, roles(ROLE_DOCTOR));
get(doctorService::getPatientQuestion, roles(ROLE_DOCTOR));
});
});
});
});
});

});
path("admin", () -> {
path("doctor", () -> {
post(doctorService::createDoctor, roles(ROLE_ADMIN));
get(doctorService::getDoctors, roles(ROLE_ADMIN));
});
path("admin", () -> {
path("doctor", () -> {
post(doctorService::createDoctor, roles(ROLE_ADMIN));
get(doctorService::getDoctors, roles(ROLE_ADMIN));
});
});
});
});
Expand All @@ -240,11 +250,6 @@ public static void startServer() {
ctx.result(e.getMessage());
});
app.config.sessionHandler(() -> fileSessionHandler());
if (Boolean.valueOf(System.getProperty("app.production", "false"))) {
app.config.addStaticFiles("/webapp");
} else {
app.config.addStaticFiles("./src/main/webapp/dist", Location.EXTERNAL);
}

}

Expand Down Expand Up @@ -277,7 +282,7 @@ public static void stopServer() {
}

private static void createAdminIfNotFound() {
try (UserRepository repo = UserRepositoryFactory.getInstance().get()) {
try ( UserRepository repo = UserRepositoryFactory.getInstance().get()) {
if (repo.getUsersByRole(ROLE_ADMIN).isEmpty()) {
log.info("No Admins Found; Creating one now");
String password = RandomStringUtils.random(16, true, true);
Expand Down
Loading

0 comments on commit 2759656

Please sign in to comment.