Skip to content
Closed
3 changes: 1 addition & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: '17'
java-package: 'jdk+fx'
java-version: '21'
distribution: 'zulu'

- name: Build OIE (signed)
Expand Down
128 changes: 72 additions & 56 deletions client/src/com/mirth/connect/client/ui/MessageExportDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import javax.swing.JButton;
import javax.swing.JSeparator;
import javax.swing.SwingWorker;

import net.miginfocom.swing.MigLayout;

Expand Down Expand Up @@ -129,15 +130,14 @@ private void initLayout() {
add(cancelButton, "width 60");
}

private void export() {
private void export() {
String errorMessage = messageExportPanel.validate(true);
if (StringUtils.isNotEmpty(errorMessage)) {
parent.alertError(this, errorMessage);
return;
}

int exportCount = 0;
MessageWriterOptions writerOptions = messageExportPanel.getMessageWriterOptions();
final MessageWriterOptions writerOptions = messageExportPanel.getMessageWriterOptions();

if (StringUtils.isBlank(writerOptions.getRootFolder())) {
parent.alertError(parent, "Please enter a valid root path to store exported files.");
Expand All @@ -146,65 +146,81 @@ private void export() {
}

setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
exportButton.setEnabled(false);

try {
if (!isChannelMessagesPanelFirstLoadSearch) {
LinkedHashMap<String, String> auditMessageAttributesMap = new LinkedHashMap<String, String>();
parent.mirthClient.auditExportMessages(auditMessageAttributesMap);
if (messageExportPanel.isExportLocal()) {
PaginatedMessageList messageList = messages;

writerOptions.setBaseFolder(SystemUtils.getUserHome().getAbsolutePath());

MessageWriter messageWriter = MessageWriterFactory.getInstance().getMessageWriter(writerOptions, encryptor);

AttachmentSource attachmentSource = null;
if (writerOptions.includeAttachments()) {
attachmentSource = new AttachmentSource() {
@Override
public List<Attachment> getMessageAttachments(Message message) throws ClientException {
return PlatformUI.MIRTH_FRAME.mirthClient.getAttachmentsByMessageId(message.getChannelId(), message.getMessageId());
}
};
}

try {
exportCount = new MessageExporter().exportMessages(messageList, messageWriter, attachmentSource, writerOptions);
messageWriter.finishWrite();
} finally {
messageWriter.close();
new SwingWorker<Integer, Void>() {
@Override
protected Integer doInBackground() throws Exception {
int exportCount = 0;

if (!isChannelMessagesPanelFirstLoadSearch) {
LinkedHashMap<String, String> auditMessageAttributesMap = new LinkedHashMap<String, String>();
parent.mirthClient.auditExportMessages(auditMessageAttributesMap);
if (messageExportPanel.isExportLocal()) {
PaginatedMessageList messageList = messages;

writerOptions.setBaseFolder(SystemUtils.getUserHome().getAbsolutePath());

MessageWriter messageWriter = MessageWriterFactory.getInstance().getMessageWriter(writerOptions, encryptor);

AttachmentSource attachmentSource = null;
if (writerOptions.includeAttachments()) {
attachmentSource = new AttachmentSource() {
@Override
public List<Attachment> getMessageAttachments(Message message) throws ClientException {
return PlatformUI.MIRTH_FRAME.mirthClient.getAttachmentsByMessageId(message.getChannelId(), message.getMessageId());
}
};
}

try {
exportCount = new MessageExporter().exportMessages(messageList, messageWriter, attachmentSource, writerOptions);
messageWriter.finishWrite();
} finally {
messageWriter.close();
}
} else {
exportCount = exportToServer(writerOptions);
}
} else {
exportCount = exportToServer(writerOptions);
}

return exportCount;
}

setVisible(false);
setCursor(Cursor.getDefaultCursor());

if (isChannelMessagesPanelFirstLoadSearch) {
parent.alertInformation(parent, "There are no messages to export. Please perform a search before exporting.");
} else if (exportCount == 0) {
parent.alertInformation(parent, "There are no messages to export.");
} else {
LinkedHashMap<String, String> auditMessageAttributesMap = new LinkedHashMap<String, String>();
auditMessageAttributesMap.put("rootPath", writerOptions.getRootFolder());
auditMessageAttributesMap.put("filePattern", writerOptions.getFilePattern());
auditMessageAttributesMap.put("exportCount", String.valueOf(exportCount));
auditMessageAttributesMap.put("contentType", writerOptions.getContentType() != null ? writerOptions.getContentType().toString() : "");
auditMessageAttributesMap.put("encrypted", String.valueOf(writerOptions.isEncrypt()));
auditMessageAttributesMap.put("includeAttachments", String.valueOf(writerOptions.includeAttachments()));
auditMessageAttributesMap.put("compressionFormat", writerOptions.getArchiveFormat() != null ? getArchiveExtension(writerOptions.getArchiveFormat(), writerOptions.getCompressFormat()) : "");
auditMessageAttributesMap.put("passwordProtected", String.valueOf(writerOptions.isPasswordEnabled()));
parent.mirthClient.auditExportMessagesSuccess(auditMessageAttributesMap);

parent.alertInformation(parent, exportCount + " message" + ((exportCount == 1) ? " has" : "s have") + " been successfully exported to: " + writerOptions.getRootFolder());
@Override
protected void done() {
exportButton.setEnabled(true);
setCursor(Cursor.getDefaultCursor());

try {
int exportCount = get();

setVisible(false);

if (isChannelMessagesPanelFirstLoadSearch) {
parent.alertInformation(parent, "There are no messages to export. Please perform a search before exporting.");
} else if (exportCount == 0) {
parent.alertInformation(parent, "There are no messages to export.");
} else {
LinkedHashMap<String, String> auditMessageAttributesMap = new LinkedHashMap<String, String>();
auditMessageAttributesMap.put("rootPath", writerOptions.getRootFolder());
auditMessageAttributesMap.put("filePattern", writerOptions.getFilePattern());
auditMessageAttributesMap.put("exportCount", String.valueOf(exportCount));
auditMessageAttributesMap.put("contentType", writerOptions.getContentType() != null ? writerOptions.getContentType().toString() : "");
auditMessageAttributesMap.put("encrypted", String.valueOf(writerOptions.isEncrypt()));
auditMessageAttributesMap.put("includeAttachments", String.valueOf(writerOptions.includeAttachments()));
auditMessageAttributesMap.put("compressionFormat", writerOptions.getArchiveFormat() != null ? getArchiveExtension(writerOptions.getArchiveFormat(), writerOptions.getCompressFormat()) : "");
auditMessageAttributesMap.put("passwordProtected", String.valueOf(writerOptions.isPasswordEnabled()));
parent.mirthClient.auditExportMessagesSuccess(auditMessageAttributesMap);

parent.alertInformation(parent, exportCount + " message" + ((exportCount == 1) ? " has" : "s have") + " been successfully exported to: " + writerOptions.getRootFolder());
}
} catch (Exception e) {
Throwable cause = (e.getCause() == null) ? e : e.getCause();
parent.alertThrowable(parent, cause);
}
}
} catch (Exception e) {
setCursor(Cursor.getDefaultCursor());
Throwable cause = (e.getCause() == null) ? e : e.getCause();
parent.alertThrowable(parent, cause);
}
}.execute();
}

protected int exportToServer(MessageWriterOptions writerOptions) throws ClientException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ public String getURLContents(String address) {

try {
URL url = new URL(address);
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str = null;
try (BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()))) {
String str;

while ((str = in.readLine()) != null) {
builder.append(str);
builder.append("\r\n");
while ((str = in.readLine()) != null) {
builder.append(str);
builder.append("\r\n");
}
}

in.close();
} catch (Exception e) {
// could not load page contents
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public class Channel implements Runnable {
private String contextFactoryId;

private DeployedState initialState;
private DeployedState currentState = DeployedState.STOPPED;
private volatile DeployedState currentState = DeployedState.STOPPED;

private StorageSettings storageSettings = new StorageSettings();
private DonkeyDaoFactory daoFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ private void commit() throws InterruptedException {
if (!statistics.isEmpty() && daoFactory != null) {
Statistics tempStats = new Statistics(false, true);

Map<String, Map<Integer, Map<Status, Long>>> stats = statistics.getStats();
tempStats.update(stats);
Map<String, Map<Integer, Map<Status, Long>>> stats;
synchronized (statistics) {
stats = statistics.getStats();
tempStats.update(stats);
}

DonkeyDao dao = daoFactory.getDao();
boolean commitSuccess = false;
Expand All @@ -90,15 +93,20 @@ private void commit() throws InterruptedException {
dao.commit();
commitSuccess = true;

// Invert the stats and update them on the Statistics object
for (Map<Integer, Map<Status, Long>> channelMap : stats.values()) {
for (Map<Status, Long> connectorMap : channelMap.values()) {
for (Entry<Status, Long> entry : connectorMap.entrySet()) {
entry.setValue(-entry.getValue());
// Invert the stats and update them on the Statistics object.
// Synchronized on statistics so that update() calls from other threads
// cannot slip in between the snapshot and the inversion, which would
// cause those increments to be silently cancelled.
synchronized (statistics) {
for (Map<Integer, Map<Status, Long>> channelMap : stats.values()) {
for (Map<Status, Long> connectorMap : channelMap.values()) {
for (Entry<Status, Long> entry : connectorMap.entrySet()) {
entry.setValue(-entry.getValue());
}
}
}
statistics.update(stats);
}
statistics.update(stats);
} catch (Throwable t) {
if (t instanceof InterruptedException) {
throw (InterruptedException) t;
Expand Down Expand Up @@ -130,7 +138,9 @@ private void commit() throws InterruptedException {
@Override
public void update(Statistics statistics) {
if (!statistics.isEmpty()) {
this.statistics.update(statistics);
synchronized (this.statistics) {
this.statistics.update(statistics);
}
}
}
}
Loading
Loading