Skip to content

Commit 6e3bda7

Browse files
mgaffigantonygermano
authored andcommitted
Moved handleSuccess to Mirth.java - boots app, not related to panel
Signed-off-by: Mitch Gaffigan <mitch.gaffigan@comcast.net>
1 parent d268252 commit 6e3bda7

File tree

2 files changed

+151
-150
lines changed

2 files changed

+151
-150
lines changed

client/src/com/mirth/connect/client/ui/LoginPanel.java

Lines changed: 2 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,27 @@
44

55
package com.mirth.connect.client.ui;
66

7-
import static com.mirth.connect.client.core.BrandingConstants.CHECK_FOR_NOTIFICATIONS;
8-
97
import java.awt.Color;
108
import java.awt.Cursor;
119
import java.util.Collections;
1210
import java.util.HashMap;
13-
import java.util.HashSet;
1411
import java.util.List;
1512
import java.util.Map;
16-
import java.util.Properties;
1713
import java.util.Set;
18-
import java.util.prefs.Preferences;
1914

2015
import javax.swing.ImageIcon;
2116
import javax.swing.SwingWorker;
2217

23-
import org.apache.commons.lang3.BooleanUtils;
2418
import org.apache.commons.lang3.StringUtils;
2519

2620
import com.mirth.connect.client.core.Client;
2721
import com.mirth.connect.client.core.ClientException;
28-
import com.mirth.connect.client.core.ConnectServiceUtil;
2922
import com.mirth.connect.client.core.UnauthorizedException;
3023
import com.mirth.connect.client.core.api.servlets.UserServletInterface;
3124
import com.mirth.connect.client.ui.util.DisplayUtil;
3225
import com.mirth.connect.model.ExtendedLoginStatus;
3326
import com.mirth.connect.model.LoginStatus;
34-
import com.mirth.connect.model.PublicServerSettings;
35-
import com.mirth.connect.model.User;
36-
import com.mirth.connect.model.converters.ObjectXMLSerializer;
3727
import com.mirth.connect.plugins.MultiFactorAuthenticationClientPlugin;
38-
import com.mirth.connect.util.MirthSSLUtil;
3928

4029
public class LoginPanel extends javax.swing.JFrame {
4130

@@ -97,8 +86,6 @@ public void initialize(String mirthServer, String version, String user, String p
9786
return;
9887
}
9988

100-
PlatformUI.CLIENT_VERSION = version;
101-
10289
setTitle(String.format("%s %s - Login", BrandingConstants.PRODUCT_NAME, version));
10390
setIconImage(BrandingConstants.FAVICON.getImage());
10491

@@ -447,7 +434,7 @@ public Void doInBackground() {
447434

448435
// If SUCCESS or SUCCESS_GRACE_PERIOD
449436
if (loginStatus != null && loginStatus.isSuccess()) {
450-
if (!handleSuccess(loginStatus)) {
437+
if (!Mirth.handleLoginSuccess(client, loginStatus, username.getText())) {
451438
LoginPanel.getInstance().setVisible(false);
452439
LoginPanel.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", "");
453440
}
@@ -466,7 +453,7 @@ public Void doInBackground() {
466453

467454
if (loginStatus != null && loginStatus.isSuccess()) {
468455
errorOccurred = false;
469-
if (!handleSuccess(loginStatus)) {
456+
if (!Mirth.handleLoginSuccess(client, loginStatus, username.getText())) {
470457
LoginPanel.getInstance().setVisible(false);
471458
LoginPanel.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", "");
472459
}
@@ -499,141 +486,6 @@ public Void doInBackground() {
499486
return null;
500487
}
501488

502-
private boolean handleSuccess(LoginStatus loginStatus) throws ClientException {
503-
try {
504-
PublicServerSettings publicServerSettings = client.getPublicServerSettings();
505-
506-
if (publicServerSettings.getLoginNotificationEnabled() == true) {
507-
CustomBannerPanelDialog customBannerPanelDialog = new CustomBannerPanelDialog(LoginPanel.getInstance(), "Login Notification", publicServerSettings.getLoginNotificationMessage());
508-
boolean isAccepted = customBannerPanelDialog.isAccepted();
509-
510-
if (isAccepted == true) {
511-
client.setUserNotificationAcknowledged(client.getCurrentUser().getId());
512-
}
513-
else {
514-
return false;
515-
}
516-
}
517-
518-
String environmentName = publicServerSettings.getEnvironmentName();
519-
if (!StringUtils.isBlank(environmentName)) {
520-
PlatformUI.ENVIRONMENT_NAME = environmentName;
521-
}
522-
523-
String serverName = publicServerSettings.getServerName();
524-
if (!StringUtils.isBlank(serverName)) {
525-
PlatformUI.SERVER_NAME = serverName;
526-
} else {
527-
PlatformUI.SERVER_NAME = null;
528-
}
529-
530-
Color defaultBackgroundColor = publicServerSettings.getDefaultAdministratorBackgroundColor();
531-
if (defaultBackgroundColor != null) {
532-
PlatformUI.DEFAULT_BACKGROUND_COLOR = defaultBackgroundColor;
533-
}
534-
} catch (ClientException e) {
535-
PlatformUI.SERVER_NAME = null;
536-
}
537-
538-
try {
539-
String database = (String) client.getAbout().get("database");
540-
if (!StringUtils.isBlank(database)) {
541-
PlatformUI.SERVER_DATABASE = database;
542-
} else {
543-
PlatformUI.SERVER_DATABASE = null;
544-
}
545-
} catch (ClientException e) {
546-
PlatformUI.SERVER_DATABASE = null;
547-
}
548-
549-
try {
550-
Map<String, String[]> map = client.getProtocolsAndCipherSuites();
551-
PlatformUI.SERVER_HTTPS_SUPPORTED_PROTOCOLS = map.get(MirthSSLUtil.KEY_SUPPORTED_PROTOCOLS);
552-
PlatformUI.SERVER_HTTPS_ENABLED_CLIENT_PROTOCOLS = map.get(MirthSSLUtil.KEY_ENABLED_CLIENT_PROTOCOLS);
553-
PlatformUI.SERVER_HTTPS_ENABLED_SERVER_PROTOCOLS = map.get(MirthSSLUtil.KEY_ENABLED_SERVER_PROTOCOLS);
554-
PlatformUI.SERVER_HTTPS_SUPPORTED_CIPHER_SUITES = map.get(MirthSSLUtil.KEY_SUPPORTED_CIPHER_SUITES);
555-
PlatformUI.SERVER_HTTPS_ENABLED_CIPHER_SUITES = map.get(MirthSSLUtil.KEY_ENABLED_CIPHER_SUITES);
556-
} catch (ClientException e) {
557-
}
558-
559-
PlatformUI.USER_NAME = StringUtils.defaultString(loginStatus.getUpdatedUsername(), username.getText());
560-
setStatus("Authenticated...");
561-
new Mirth(client);
562-
LoginPanel.getInstance().setVisible(false);
563-
564-
User currentUser = PlatformUI.MIRTH_FRAME.getCurrentUser(PlatformUI.MIRTH_FRAME);
565-
Properties userPreferences = new Properties();
566-
Set<String> preferenceNames = new HashSet<String>();
567-
preferenceNames.add("firstlogin");
568-
preferenceNames.add("checkForNotifications");
569-
preferenceNames.add("showNotificationPopup");
570-
preferenceNames.add("archivedNotifications");
571-
try {
572-
userPreferences = client.getUserPreferences(currentUser.getId(), preferenceNames);
573-
574-
// Display registration dialog if it's the user's first time logging in
575-
String firstlogin = userPreferences.getProperty("firstlogin");
576-
if (firstlogin == null || BooleanUtils.toBoolean(firstlogin)) {
577-
if (Integer.valueOf(currentUser.getId()) == 1) {
578-
// if current user is user 1:
579-
// 1. check system preferences for user information
580-
// 2. if system preferences exist, populate screen using currentUser
581-
Preferences preferences = Preferences.userNodeForPackage(Mirth.class);
582-
String systemUserInfo = preferences.get("userLoginInfo", null);
583-
if (systemUserInfo != null) {
584-
String info[] = systemUserInfo.split(",", 0);
585-
currentUser.setUsername(info[0]);
586-
currentUser.setFirstName(info[1]);
587-
currentUser.setLastName(info[2]);
588-
currentUser.setEmail(info[3]);
589-
currentUser.setCountry(info[4]);
590-
currentUser.setStateTerritory(info[5]);
591-
currentUser.setPhoneNumber(info[6]);
592-
currentUser.setOrganization(info[7]);
593-
currentUser.setRole(info[8]);
594-
currentUser.setIndustry(info[9]);
595-
currentUser.setDescription(info[10]);
596-
}
597-
}
598-
FirstLoginDialog firstLoginDialog = new FirstLoginDialog(currentUser);
599-
// if leaving the first login dialog without saving
600-
if (!firstLoginDialog.getResult()) {
601-
return false;
602-
}
603-
} else if (loginStatus.getStatus() == LoginStatus.Status.SUCCESS_GRACE_PERIOD) {
604-
new ChangePasswordDialog(currentUser, loginStatus.getMessage());
605-
}
606-
607-
// Check for new notifications from update server if enabled
608-
String checkForNotifications = userPreferences.getProperty("checkForNotifications");
609-
if (CHECK_FOR_NOTIFICATIONS
610-
&& (checkForNotifications == null || BooleanUtils.toBoolean(checkForNotifications))) {
611-
Set<Integer> archivedNotifications = new HashSet<Integer>();
612-
String archivedNotificationString = userPreferences.getProperty("archivedNotifications");
613-
if (archivedNotificationString != null) {
614-
archivedNotifications = ObjectXMLSerializer.getInstance().deserialize(archivedNotificationString, Set.class);
615-
}
616-
// Update the Other Tasks pane with the unarchived notification count
617-
int unarchivedNotifications = ConnectServiceUtil.getNotificationCount(PlatformUI.SERVER_ID, PlatformUI.SERVER_VERSION, LoadedExtensions.getInstance().getExtensionVersions(), archivedNotifications, PlatformUI.HTTPS_PROTOCOLS, PlatformUI.HTTPS_CIPHER_SUITES);
618-
PlatformUI.MIRTH_FRAME.updateNotificationTaskName(unarchivedNotifications);
619-
620-
// Display notification dialog if enabled and if there are new notifications
621-
String showNotificationPopup = userPreferences.getProperty("showNotificationPopup");
622-
if (showNotificationPopup == null || BooleanUtils.toBoolean(showNotificationPopup)) {
623-
if (unarchivedNotifications > 0) {
624-
new NotificationDialog();
625-
}
626-
}
627-
}
628-
} catch (ClientException e) {
629-
PlatformUI.MIRTH_FRAME.alertThrowable(PlatformUI.MIRTH_FRAME, e);
630-
}
631-
632-
PlatformUI.MIRTH_FRAME.sendUsageStatistics();
633-
634-
return true;
635-
}
636-
637489
public void done() {}
638490
};
639491
worker.execute();

client/src/com/mirth/connect/client/ui/Mirth.java

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33

44
package com.mirth.connect.client.ui;
55

6+
import static com.mirth.connect.client.core.BrandingConstants.CHECK_FOR_NOTIFICATIONS;
7+
68
import java.awt.Color;
79
import java.awt.Toolkit;
810
import java.awt.event.InputEvent;
911
import java.awt.event.KeyEvent;
1012
import java.io.IOException;
1113
import java.util.prefs.Preferences;
14+
import java.util.Map;
15+
import java.util.Set;
16+
import java.util.Properties;
17+
import java.util.HashSet;
1218

1319
import javax.imageio.ImageIO;
1420
import javax.swing.ImageIcon;
@@ -22,6 +28,7 @@
2228
import javax.swing.text.JTextComponent;
2329
import javax.swing.text.JTextComponent.KeyBinding;
2430

31+
import org.apache.commons.lang3.BooleanUtils;
2532
import org.apache.commons.lang3.StringUtils;
2633
import org.apache.commons.lang3.SystemUtils;
2734
import org.apache.logging.log4j.Level;
@@ -36,6 +43,12 @@
3643
import com.jgoodies.looks.plastic.PlasticXPLookAndFeel;
3744
import com.mirth.connect.client.core.Client;
3845
import com.mirth.connect.client.core.ClientException;
46+
import com.mirth.connect.client.core.ConnectServiceUtil;
47+
import com.mirth.connect.model.LoginStatus;
48+
import com.mirth.connect.model.PublicServerSettings;
49+
import com.mirth.connect.model.User;
50+
import com.mirth.connect.model.converters.ObjectXMLSerializer;
51+
import com.mirth.connect.util.MirthSSLUtil;
3952

4053
/**
4154
* The main mirth class. Sets up the login and then authenticates the login information and sets up
@@ -282,4 +295,140 @@ public void run() {
282295
}
283296
});
284297
}
298+
299+
public static boolean handleLoginSuccess(Client client, LoginStatus loginStatus, String userName) throws ClientException {
300+
AbstractLoginPanel loginPanel = LoginPanelFactory.getInstance();
301+
try {
302+
PublicServerSettings publicServerSettings = client.getPublicServerSettings();
303+
304+
if (publicServerSettings.getLoginNotificationEnabled() == true) {
305+
CustomBannerPanelDialog customBannerPanelDialog = new CustomBannerPanelDialog(loginPanel, "Login Notification", publicServerSettings.getLoginNotificationMessage());
306+
boolean isAccepted = customBannerPanelDialog.isAccepted();
307+
308+
if (isAccepted == true) {
309+
client.setUserNotificationAcknowledged(client.getCurrentUser().getId());
310+
}
311+
else {
312+
return false;
313+
}
314+
}
315+
316+
String environmentName = publicServerSettings.getEnvironmentName();
317+
if (!StringUtils.isBlank(environmentName)) {
318+
PlatformUI.ENVIRONMENT_NAME = environmentName;
319+
}
320+
321+
String serverName = publicServerSettings.getServerName();
322+
if (!StringUtils.isBlank(serverName)) {
323+
PlatformUI.SERVER_NAME = serverName;
324+
} else {
325+
PlatformUI.SERVER_NAME = null;
326+
}
327+
328+
Color defaultBackgroundColor = publicServerSettings.getDefaultAdministratorBackgroundColor();
329+
if (defaultBackgroundColor != null) {
330+
PlatformUI.DEFAULT_BACKGROUND_COLOR = defaultBackgroundColor;
331+
}
332+
} catch (ClientException e) {
333+
PlatformUI.SERVER_NAME = null;
334+
}
335+
336+
try {
337+
String database = (String) client.getAbout().get("database");
338+
if (!StringUtils.isBlank(database)) {
339+
PlatformUI.SERVER_DATABASE = database;
340+
} else {
341+
PlatformUI.SERVER_DATABASE = null;
342+
}
343+
} catch (ClientException e) {
344+
PlatformUI.SERVER_DATABASE = null;
345+
}
346+
347+
try {
348+
Map<String, String[]> map = client.getProtocolsAndCipherSuites();
349+
PlatformUI.SERVER_HTTPS_SUPPORTED_PROTOCOLS = map.get(MirthSSLUtil.KEY_SUPPORTED_PROTOCOLS);
350+
PlatformUI.SERVER_HTTPS_ENABLED_CLIENT_PROTOCOLS = map.get(MirthSSLUtil.KEY_ENABLED_CLIENT_PROTOCOLS);
351+
PlatformUI.SERVER_HTTPS_ENABLED_SERVER_PROTOCOLS = map.get(MirthSSLUtil.KEY_ENABLED_SERVER_PROTOCOLS);
352+
PlatformUI.SERVER_HTTPS_SUPPORTED_CIPHER_SUITES = map.get(MirthSSLUtil.KEY_SUPPORTED_CIPHER_SUITES);
353+
PlatformUI.SERVER_HTTPS_ENABLED_CIPHER_SUITES = map.get(MirthSSLUtil.KEY_ENABLED_CIPHER_SUITES);
354+
} catch (ClientException e) {
355+
}
356+
357+
PlatformUI.USER_NAME = StringUtils.defaultString(loginStatus.getUpdatedUsername(), userName);
358+
loginPanel.setStatus("Authenticated...");
359+
new Mirth(client);
360+
loginPanel.setVisible(false);
361+
362+
User currentUser = PlatformUI.MIRTH_FRAME.getCurrentUser(PlatformUI.MIRTH_FRAME);
363+
Properties userPreferences = new Properties();
364+
Set<String> preferenceNames = new HashSet<String>();
365+
preferenceNames.add("firstlogin");
366+
preferenceNames.add("checkForNotifications");
367+
preferenceNames.add("showNotificationPopup");
368+
preferenceNames.add("archivedNotifications");
369+
try {
370+
userPreferences = client.getUserPreferences(currentUser.getId(), preferenceNames);
371+
372+
// Display registration dialog if it's the user's first time logging in
373+
String firstlogin = userPreferences.getProperty("firstlogin");
374+
if (firstlogin == null || BooleanUtils.toBoolean(firstlogin)) {
375+
if (Integer.valueOf(currentUser.getId()) == 1) {
376+
// if current user is user 1:
377+
// 1. check system preferences for user information
378+
// 2. if system preferences exist, populate screen using currentUser
379+
Preferences preferences = Preferences.userNodeForPackage(Mirth.class);
380+
String systemUserInfo = preferences.get("userLoginInfo", null);
381+
if (systemUserInfo != null) {
382+
String info[] = systemUserInfo.split(",", 0);
383+
currentUser.setUsername(info[0]);
384+
currentUser.setFirstName(info[1]);
385+
currentUser.setLastName(info[2]);
386+
currentUser.setEmail(info[3]);
387+
currentUser.setCountry(info[4]);
388+
currentUser.setStateTerritory(info[5]);
389+
currentUser.setPhoneNumber(info[6]);
390+
currentUser.setOrganization(info[7]);
391+
currentUser.setRole(info[8]);
392+
currentUser.setIndustry(info[9]);
393+
currentUser.setDescription(info[10]);
394+
}
395+
}
396+
FirstLoginDialog firstLoginDialog = new FirstLoginDialog(currentUser);
397+
// if leaving the first login dialog without saving
398+
if (!firstLoginDialog.getResult()) {
399+
return false;
400+
}
401+
} else if (loginStatus.getStatus() == LoginStatus.Status.SUCCESS_GRACE_PERIOD) {
402+
new ChangePasswordDialog(currentUser, loginStatus.getMessage());
403+
}
404+
405+
// Check for new notifications from update server if enabled
406+
String checkForNotifications = userPreferences.getProperty("checkForNotifications");
407+
if (CHECK_FOR_NOTIFICATIONS
408+
&& (checkForNotifications == null || BooleanUtils.toBoolean(checkForNotifications))) {
409+
Set<Integer> archivedNotifications = new HashSet<Integer>();
410+
String archivedNotificationString = userPreferences.getProperty("archivedNotifications");
411+
if (archivedNotificationString != null) {
412+
archivedNotifications = ObjectXMLSerializer.getInstance().deserialize(archivedNotificationString, Set.class);
413+
}
414+
// Update the Other Tasks pane with the unarchived notification count
415+
int unarchivedNotifications = ConnectServiceUtil.getNotificationCount(PlatformUI.SERVER_ID, PlatformUI.SERVER_VERSION, LoadedExtensions.getInstance().getExtensionVersions(), archivedNotifications, PlatformUI.HTTPS_PROTOCOLS, PlatformUI.HTTPS_CIPHER_SUITES);
416+
PlatformUI.MIRTH_FRAME.updateNotificationTaskName(unarchivedNotifications);
417+
418+
// Display notification dialog if enabled and if there are new notifications
419+
String showNotificationPopup = userPreferences.getProperty("showNotificationPopup");
420+
if (showNotificationPopup == null || BooleanUtils.toBoolean(showNotificationPopup)) {
421+
if (unarchivedNotifications > 0) {
422+
new NotificationDialog();
423+
}
424+
}
425+
}
426+
} catch (ClientException e) {
427+
PlatformUI.MIRTH_FRAME.alertThrowable(PlatformUI.MIRTH_FRAME, e);
428+
}
429+
430+
PlatformUI.MIRTH_FRAME.sendUsageStatistics();
431+
432+
return true;
433+
}
285434
}

0 commit comments

Comments
 (0)