Skip to content

Commit 6f0e87b

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 6f0e87b

File tree

2 files changed

+442
-441
lines changed

2 files changed

+442
-441
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();

0 commit comments

Comments
 (0)