Skip to content

Commit

Permalink
Added Response to SaveSettings message
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelB committed Nov 9, 2023
1 parent 39390f1 commit e1f8f67
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 47 deletions.
10 changes: 9 additions & 1 deletion src/main/java/health/ere/ps/event/SaveSettingsEvent.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package health.ere.ps.event;

import javax.websocket.Session;

import health.ere.ps.model.config.UserConfigurations;

public class SaveSettingsEvent {
public class SaveSettingsEvent extends AbstractEvent {
private UserConfigurations userConfigurations;

public SaveSettingsEvent() {
Expand All @@ -13,6 +15,12 @@ public SaveSettingsEvent(UserConfigurations userConfigurations) {
setUserConfigurations(userConfigurations);
}

public SaveSettingsEvent(UserConfigurations userConfigurations, Session senderSession, String messageId) {
setUserConfigurations(userConfigurations);
setReplyTo(senderSession);
setId(messageId);
}

public UserConfigurations getUserConfigurations() {
return this.userConfigurations;
}
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/health/ere/ps/event/SaveSettingsResponseEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package health.ere.ps.event;

import health.ere.ps.model.config.UserConfigurations;

public class SaveSettingsResponseEvent extends AbstractEvent {
private UserConfigurations userConfigurations;

public SaveSettingsResponseEvent() {

}

public SaveSettingsResponseEvent(UserConfigurations userConfigurations) {
setUserConfigurations(userConfigurations);
}

public UserConfigurations getUserConfigurations() {
return this.userConfigurations;
}

public void setUserConfigurations(UserConfigurations userConfigurations) {
this.userConfigurations = userConfigurations;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import javax.inject.Inject;

import health.ere.ps.event.SaveSettingsEvent;
import health.ere.ps.event.SaveSettingsResponseEvent;
import health.ere.ps.event.config.UserConfigurationsUpdateEvent;
import health.ere.ps.model.config.UserConfigurations;

Expand All @@ -25,6 +26,9 @@ public class UserConfigurationService {
@Inject
Event<UserConfigurationsUpdateEvent> configurationsUpdateEvent;

@Inject
Event<SaveSettingsResponseEvent> saveSettingsResponseEvent;

private String getConfigFilePath() {
// TODO configure proper file path
return "user.properties";
Expand Down Expand Up @@ -90,5 +94,11 @@ public UserConfigurations getConfig() {

public void onSaveSettingsEvent(@ObservesAsync SaveSettingsEvent saveSettingsEvent) {
updateConfig(saveSettingsEvent.getUserConfigurations());
SaveSettingsResponseEvent message = new SaveSettingsResponseEvent(saveSettingsEvent.getUserConfigurations());
message.setReplyTo(saveSettingsEvent.getReplyTo());
message.setReplyToMessageId(saveSettingsEvent.getId());
saveSettingsResponseEvent.fireAsync(message);
}


}
67 changes: 21 additions & 46 deletions src/main/java/health/ere/ps/websocket/Websocket.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package health.ere.ps.websocket;

import java.awt.Desktop;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.math.BigInteger;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -66,6 +63,7 @@
import health.ere.ps.event.ReadyToSignBundlesEvent;
import health.ere.ps.event.RequestStatusEvent;
import health.ere.ps.event.SaveSettingsEvent;
import health.ere.ps.event.SaveSettingsResponseEvent;
import health.ere.ps.event.SignAndUploadBundlesEvent;
import health.ere.ps.event.StatusResponseEvent;
import health.ere.ps.event.UnblockPinEvent;
Expand Down Expand Up @@ -164,8 +162,6 @@ public class Websocket {
.withAdapters(new ThrowableAdapter())
.withAdapters(new DurationAdapter());
public static Jsonb jsonbFactory = JsonbBuilder.create(customConfig);
private static final String CHROME_X86_PATH = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
private static final String CHROME_X64_PATH = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe";
private static final EreLogger ereLog = EreLogger.getLogger(Websocket.class);

private final FhirContext ctx = FhirContext.forR4();
Expand Down Expand Up @@ -332,7 +328,7 @@ public void onMessage(String message, Session senderSession) {
} else if("SaveSettings".equals(object.getString("type"))) {
String userConfiguration = object.getJsonObject("payload").toString();
UserConfigurations userConfigurations = jsonbFactory.fromJson(userConfiguration, UserConfigurations.class);
saveSettingsEvent.fireAsync(new SaveSettingsEvent(userConfigurations));
saveSettingsEvent.fireAsync(new SaveSettingsEvent(userConfigurations, senderSession, messageId));
} else if("RequestStatus".equals(object.getString("type"))) {
requestStatusEvent.fireAsync(new RequestStatusEvent(object, senderSession, messageId));
} else if ("Publish".equals(object.getString("type"))) {
Expand Down Expand Up @@ -387,7 +383,6 @@ Exception simulateException(JsonObject object) {
}

public void onFhirBundle(@ObservesAsync BundlesEvent bundlesEvent) {
assureChromeIsOpen();
String bundlesString = generateJson(bundlesEvent);
Set<Session> localSessions = new HashSet<>();
if(bundlesEvent.getReplyTo() != null) {
Expand All @@ -405,7 +400,7 @@ public void onFhirBundle(@ObservesAsync BundlesEvent bundlesEvent) {
}

public void onAbortTasksStatusEvent(@ObservesAsync AbortTasksStatusEvent abortTasksStatusEvent) {
assureChromeIsOpen();

String abortTasksStatusString = generateJson(abortTasksStatusEvent);

abortTasksStatusEvent.getReplyTo().getAsyncRemote().sendObject(
Expand All @@ -418,7 +413,7 @@ public void onAbortTasksStatusEvent(@ObservesAsync AbortTasksStatusEvent abortTa
}

public void onGetCardsResponseEvent(@ObservesAsync GetCardsResponseEvent getCardsResponseEvent) {
assureChromeIsOpen();

String abortTasksStatusString = generateJson(getCardsResponseEvent);

getCardsResponseEvent.getReplyTo().getAsyncRemote().sendObject(
Expand All @@ -431,7 +426,7 @@ public void onGetCardsResponseEvent(@ObservesAsync GetCardsResponseEvent getCard
}

public void onGetSignatureModeResponseEvent(@ObservesAsync GetSignatureModeResponseEvent getSignatureModeResponseEvent) {
assureChromeIsOpen();

String abortTasksStatusString = generateJson(getSignatureModeResponseEvent);
getSignatureModeResponseEvent.getReplyTo().getAsyncRemote().sendObject(
"{\"type\": \"GetSignatureModeResponse\", \"payload\": " + abortTasksStatusString + ", \"replyToMessageId\": \""+getSignatureModeResponseEvent.getReplyToMessageId()+"\"}",
Expand All @@ -443,7 +438,7 @@ public void onGetSignatureModeResponseEvent(@ObservesAsync GetSignatureModeRespo
}

public void onChangePinResponseEvent(@ObservesAsync ChangePinResponseEvent changePinResponseEvent) {
assureChromeIsOpen();

String changePinResponseString = generateJson(changePinResponseEvent);
changePinResponseEvent.getReplyTo().getAsyncRemote().sendObject(
"{\"type\": \"ChangePinResponse\", \"payload\": " + changePinResponseString + ", \"replyToMessageId\": \""+changePinResponseEvent.getReplyToMessageId()+"\"}",
Expand All @@ -455,7 +450,7 @@ public void onChangePinResponseEvent(@ObservesAsync ChangePinResponseEvent chang
}

public void onStatusResponseEvent(@ObservesAsync StatusResponseEvent statusResponseEvent) {
assureChromeIsOpen();

statusResponseEvent.getReplyTo().getAsyncRemote().sendObject(statusResponseEvent,
result -> {
if (!result.isOK()) {
Expand All @@ -465,7 +460,7 @@ public void onStatusResponseEvent(@ObservesAsync StatusResponseEvent statusRespo
}

public void onVZDSearchResultEvent(@ObservesAsync VZDSearchResultEvent vZDSearchResultEvent) {
assureChromeIsOpen();

vZDSearchResultEvent.getReplyTo().getAsyncRemote().sendObject(vZDSearchResultEvent,
result -> {
if (!result.isOK()) {
Expand All @@ -475,7 +470,7 @@ public void onVZDSearchResultEvent(@ObservesAsync VZDSearchResultEvent vZDSearch
}

public void onVerifyPinResponseEvent(@ObservesAsync VerifyPinResponseEvent verifyPinResponseEvent) {
assureChromeIsOpen();

verifyPinResponseEvent.getReplyTo().getAsyncRemote().sendObject(verifyPinResponseEvent,
result -> {
if (!result.isOK()) {
Expand All @@ -485,7 +480,7 @@ public void onVerifyPinResponseEvent(@ObservesAsync VerifyPinResponseEvent verif
}

public void onUnblockPinResponseEvent(@ObservesAsync UnblockPinResponseEvent unblockPinResponseEvent) {
assureChromeIsOpen();

unblockPinResponseEvent.getReplyTo().getAsyncRemote().sendObject(unblockPinResponseEvent,
result -> {
if (!result.isOK()) {
Expand All @@ -495,7 +490,7 @@ public void onUnblockPinResponseEvent(@ObservesAsync UnblockPinResponseEvent unb
}

public void onGetPinStatusResponseEvent(@ObservesAsync GetPinStatusResponseEvent getPinStatusResponseEvent) {
assureChromeIsOpen();

getPinStatusResponseEvent.getReplyTo().getAsyncRemote().sendObject(getPinStatusResponseEvent,
result -> {
if (!result.isOK()) {
Expand All @@ -504,6 +499,16 @@ public void onGetPinStatusResponseEvent(@ObservesAsync GetPinStatusResponseEvent
});
}

public void onSaveSettingsResponseEvent(@ObservesAsync SaveSettingsResponseEvent saveSettingsResponseEvent) {
saveSettingsResponseEvent.getReplyTo().getAsyncRemote().sendObject(
"{\"type\": \"SaveSettingsResponseEvent\", \"payload\": " + jsonbFactory.toJson(saveSettingsResponseEvent) + ", \"replyToMessageId\": \""+saveSettingsResponseEvent.getReplyToMessageId()+"\"}",
result -> {
if (!result.isOK()) {
ereLog.fatal("Unable to send SaveSettingsResponseEvent: " + result.getException());
}
});
}

String generateJson(GetSignatureModeResponseEvent getSignatureModeResponseEvent) {
return jsonbFactory.toJson(getSignatureModeResponseEvent);
}
Expand Down Expand Up @@ -532,18 +537,6 @@ String generateJson(GetPinStatusResponseEvent getPinStatusResponseEvent) {
return jsonbFactory.toJson(getPinStatusResponseEvent.getGetPinStatusResponse());
}

void assureChromeIsOpen() {
// if nobody is connected to the websocket
if (sessions.size() == 0) {
try {
startWebappInChrome();
Thread.sleep(5000);
} catch (InterruptedException e) {
ereLog.warn("Could not open browser", e);
}
}
}

public void onERezeptDocuments(@ObservesAsync ERezeptWithDocumentsEvent eRezeptDocumentsEvent) {
String jsonPayload = generateJson(eRezeptDocumentsEvent);
ereLog.info("Sending prescription receipt payload to front-end: " +
Expand Down Expand Up @@ -688,22 +681,4 @@ private String processOutgoing(String message) {
return message;
}

private void startWebappInChrome() {
try {
if (Files.exists(Path.of(CHROME_X86_PATH))) {
Runtime.getRuntime().exec(CHROME_X86_PATH + " http://localhost:8080/frontend/app/src/index.html");
} else if (Files.exists(Path.of(CHROME_X64_PATH))) {
Runtime.getRuntime().exec(CHROME_X64_PATH + " http://localhost:8080/frontend/app/src/index.html");
} else {
ereLog.warn("Could not start the webapp on Chrome as no Chrome was detected");
// If you're not on Windows but have Chrome as a default browser
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
Desktop.getDesktop().browse(new URI("http://localhost:8080/frontend/app/src/index.html"));
}
}
} catch (IOException | URISyntaxException e) {
ereLog.error("There was a problem when opening the browser:");
e.printStackTrace();
}
}
}
38 changes: 38 additions & 0 deletions src/test/resources/websocket-messages/SaveSettings-2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"id": "3bda2b78-175a-456a-97c3-49de43aa6e32",
"payload": {
"connector.base-url": "https://192.168.178.75",
"connector.basic-auth-password": null,
"connector.basic-auth-username": null,
"connector.client-certificate": "data:application/octet-stream;base64,MIACAQMwgAYJKoZIhvcNAQcBoIAkgASCA+gwgDCABgkqhkiG9w0BBwGggCSABIID6DCCBVwwggVYBgsqhkiG9w0BDAoBAqCCBPswggT3MCkGCiqGSIb3DQEMAQMwGwQU9roQivabsSumxNEKoLcuZhF0iUUCAwDIAASCBMhmo3uo73f3+InpoXGK20go0kG7t7Eg706/kGdUFRLhU5k+ACkyb5/JIgrsN75nk/X0sT6DBPysDbYuURgvrHbVT+ZtEEYz6acmBkFj71kxd34PsrJq7ogKnq4GF4BtxZg1WIQmHxqHsqQi27sRwuJe9p06B3sgKphkfqBEtjsQ0QQKkzV4PU7BxaqIpGAjbiZJl8YKyXaSnMtE8lpJp/2v6snxd5E7cntMxHdN6/KzOnP6JVvDMazLj1QuHaVc+zIGeWQFS8JUiuPlnGApYJryMRMlMWxbwKgXX6A7S9MECmi5AXjMysCfoL3P1ENbCnscJUk1y3JPoC6kDHSyNstvF2guKZsZnASx15RPWPcuSuQdkQC6juY0SysMcgcENjY1Z3qdVrRyhP2R75w+HDVHjZsFK0/mXrgP9HaQN3GvQMVrTsYqe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3a2288tZkvrjdkUEWDLL3cTTEwbsr4UdZQys52XQLr5OsX/nTm+FWnRFs4gs1h67/v3ltLwyBi15V1y/6vfYeJOERkNBffQ0UctXEGDqXqbSmjxbgO6LISINTk/TnYxFnvvCwzW+Mip9uGuQHTVjdSAmdMQXErjUvIwCmQd4f5yZpcz6mSWkFDtKzF5RKFMuvA/mY/lVe4/SjcfbqbsOt0pUafA5tFvk2G/r7cctksdtkGU6rC9DyXocgvSx0lk8bdcKEpery872/SPorPDLLDG8/ta7yyttn7S49n2Unh69pAAcGb/TIf62uG0DRTbV8suFVubnSK0V09tZnDiqAJNbl0L0lWvr3oumhEZlwmzZ+wHvk7EeR/saxIy7+AtP9sPmQbOqDuj7U3Np4Y1AFkxPPYlLBTdHPWxMRtSRAbrCMEDyg1ej8kJYJD2gPSLskQ32Mb1i4rNn8V7exsHYQdWikCPFuYYKtSY3MEOKSADlz4XNqRQ4galEpUUuoxOYu8SvUwHWdMfB/ifQAAAAAAAAAAAAAAAAAAAAAAAAwPjAhMAkGBSsOAwIaBQAEFIDbJDLyphUEBeH5RE/1ylKtJ5SeBBQX52nWZNE1XOAlHz8dMSH0LWmZCQIDAZAAAAA=",
"connector.client-certificate-password": "****",
"connector.client-system-id": "Incentergy",
"connector.mandant-id": "m",
"connector.tvMode": null,
"connector.user-id": "a",
"connector.version": "PTV4+",
"connector.workplace-id": "a",
"erixa.api.key": null,
"erixa.drugstore.email": null,
"erixa.hotfolder": null,
"erixa.user.email": null,
"erixa.user.password": null,
"extractor.template.profile": null,
"kbv.pruefnummer": null,
"kim.client-system-id": "",
"kim.fromKimAddress": "",
"kim.mandant-id": "",
"kim.smtpFdServer": "",
"kim.smtpHostServer": "",
"kim.smtpPassword": "",
"kim.user-id": "",
"kim.vzd.base-url": "",
"kim.vzd.client-certificate": "",
"kim.vzd.client-certificate-password": "",
"kim.workplace-id": "",
"prefill.bsnr": "",
"prefill.lanr": "",
"prefill.phone": ""
},
"type": "SaveSettings"
}
Loading

0 comments on commit e1f8f67

Please sign in to comment.