Skip to content

Commit 993b615

Browse files
committed
Moved handleSuccess to Mirth.java - boots app, not related to panel
Signed-off-by: Mitch Gaffigan <mitch.gaffigan@comcast.net>
1 parent b5c3de3 commit 993b615

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
@@ -9,38 +9,27 @@
99

1010
package com.mirth.connect.client.ui;
1111

12-
import static com.mirth.connect.client.core.BrandingConstants.CHECK_FOR_NOTIFICATIONS;
13-
1412
import java.awt.Color;
1513
import java.awt.Cursor;
1614
import java.util.Collections;
1715
import java.util.HashMap;
18-
import java.util.HashSet;
1916
import java.util.List;
2017
import java.util.Map;
21-
import java.util.Properties;
2218
import java.util.Set;
23-
import java.util.prefs.Preferences;
2419

2520
import javax.swing.ImageIcon;
2621
import javax.swing.SwingWorker;
2722

28-
import org.apache.commons.lang3.BooleanUtils;
2923
import org.apache.commons.lang3.StringUtils;
3024

3125
import com.mirth.connect.client.core.Client;
3226
import com.mirth.connect.client.core.ClientException;
33-
import com.mirth.connect.client.core.ConnectServiceUtil;
3427
import com.mirth.connect.client.core.UnauthorizedException;
3528
import com.mirth.connect.client.core.api.servlets.UserServletInterface;
3629
import com.mirth.connect.client.ui.util.DisplayUtil;
3730
import com.mirth.connect.model.ExtendedLoginStatus;
3831
import com.mirth.connect.model.LoginStatus;
39-
import com.mirth.connect.model.PublicServerSettings;
40-
import com.mirth.connect.model.User;
41-
import com.mirth.connect.model.converters.ObjectXMLSerializer;
4232
import com.mirth.connect.plugins.MultiFactorAuthenticationClientPlugin;
43-
import com.mirth.connect.util.MirthSSLUtil;
4433

4534
public class LoginPanel extends javax.swing.JFrame {
4635

@@ -102,8 +91,6 @@ public void initialize(String mirthServer, String version, String user, String p
10291
return;
10392
}
10493

105-
PlatformUI.CLIENT_VERSION = version;
106-
10794
setTitle(String.format("%s %s - Login", BrandingConstants.PRODUCT_NAME, version));
10895
setIconImage(BrandingConstants.FAVICON.getImage());
10996

@@ -452,7 +439,7 @@ public Void doInBackground() {
452439

453440
// If SUCCESS or SUCCESS_GRACE_PERIOD
454441
if (loginStatus != null && loginStatus.isSuccess()) {
455-
if (!handleSuccess(loginStatus)) {
442+
if (!Mirth.handleLoginSuccess(client, loginStatus, username.getText())) {
456443
LoginPanel.getInstance().setVisible(false);
457444
LoginPanel.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", "");
458445
}
@@ -471,7 +458,7 @@ public Void doInBackground() {
471458

472459
if (loginStatus != null && loginStatus.isSuccess()) {
473460
errorOccurred = false;
474-
if (!handleSuccess(loginStatus)) {
461+
if (!Mirth.handleLoginSuccess(client, loginStatus, username.getText())) {
475462
LoginPanel.getInstance().setVisible(false);
476463
LoginPanel.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", "");
477464
}
@@ -504,141 +491,6 @@ public Void doInBackground() {
504491
return null;
505492
}
506493

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

1010
package com.mirth.connect.client.ui;
1111

12+
import static com.mirth.connect.client.core.BrandingConstants.CHECK_FOR_NOTIFICATIONS;
13+
1214
import java.awt.Color;
1315
import java.awt.Toolkit;
1416
import java.awt.event.InputEvent;
1517
import java.awt.event.KeyEvent;
1618
import java.io.IOException;
1719
import java.util.prefs.Preferences;
20+
import java.util.Map;
21+
import java.util.Set;
22+
import java.util.Properties;
23+
import java.util.HashSet;
1824

1925
import javax.imageio.ImageIO;
2026
import javax.swing.ImageIcon;
@@ -28,6 +34,7 @@
2834
import javax.swing.text.JTextComponent;
2935
import javax.swing.text.JTextComponent.KeyBinding;
3036

37+
import org.apache.commons.lang3.BooleanUtils;
3138
import org.apache.commons.lang3.StringUtils;
3239
import org.apache.commons.lang3.SystemUtils;
3340
import org.apache.logging.log4j.Level;
@@ -42,6 +49,12 @@
4249
import com.jgoodies.looks.plastic.PlasticXPLookAndFeel;
4350
import com.mirth.connect.client.core.Client;
4451
import com.mirth.connect.client.core.ClientException;
52+
import com.mirth.connect.client.core.ConnectServiceUtil;
53+
import com.mirth.connect.model.LoginStatus;
54+
import com.mirth.connect.model.PublicServerSettings;
55+
import com.mirth.connect.model.User;
56+
import com.mirth.connect.model.converters.ObjectXMLSerializer;
57+
import com.mirth.connect.util.MirthSSLUtil;
4558

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

0 commit comments

Comments
 (0)