Skip to content

Commit

Permalink
Merge pull request #76 from openmymed/vue-migration
Browse files Browse the repository at this point in the history
Vue migration
  • Loading branch information
TareqK authored Jan 22, 2021
2 parents 0332ef8 + f1d5313 commit 7e59f52
Show file tree
Hide file tree
Showing 67 changed files with 27,669 additions and 185 deletions.
80 changes: 17 additions & 63 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<dependency>
<groupId>io.javalin</groupId>
<artifactId>javalin</artifactId>
<version>3.7.0</version>
<version>3.11.0</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
Expand Down Expand Up @@ -103,7 +103,22 @@
<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>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>chartjs</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>font-awesome</artifactId>
<version>5.14.0</version>
</dependency>
</dependencies>
<build>
Expand All @@ -122,67 +137,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
203 changes: 107 additions & 96 deletions core/src/main/java/org/openmymed/accessmd/app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import static io.javalin.apibuilder.ApiBuilder.put;
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.JavalinVue;
import io.javalin.plugin.rendering.vue.VueComponent;
import java.io.File;
import java.sql.DriverManager;
import java.sql.SQLException;
Expand Down Expand Up @@ -105,8 +106,10 @@ public void run() {

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

app.config.enableWebjars();
// Set the access-manager that Javalin should use
JavalinVue.optimizeDependencies = true;
//JavalinVue.isDevFunction = (ctx)->{return false;};
app.config.accessManager((handler, ctx, permittedRoles) -> {
if (!permittedRoles.contains(NONE)) {
UserRole userRole = getUserRole(ctx);
Expand All @@ -123,114 +126,127 @@ public static void startServer() {
ICPCRestService icpcService = new ICPCRestService();
DoctorRestService doctorService = new DoctorRestService();
NotificationRestService notificationService = new NotificationRestService();
app.error(403, new VueComponent("<login></login>"));
app.error(401, new VueComponent("<login></login>"));
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-profile></patient-profile>"), roles(ROLE_DOCTOR));
app.get("/patient/:patientId/question", new VueComponent("<patient-questions></patient-questions>"), roles(ROLE_DOCTOR));
app.get("/patient/:patientId/question/new", new VueComponent("<add-patient-question></add-patient-question>"), roles(ROLE_DOCTOR));
app.get("/patient/:patientId/question/:questionId", new VueComponent("<edit-patient-question></edit-patient-question>"), 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,12 +256,7 @@ 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);
}

app.config.addStaticFiles("/web");
}

private static SessionHandler fileSessionHandler() {
Expand Down Expand Up @@ -277,7 +288,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 7e59f52

Please sign in to comment.