From 45db346338de2d50582ca36681936819bf94656f Mon Sep 17 00:00:00 2001 From: Stefan Date: Tue, 10 May 2022 14:38:37 +0200 Subject: [PATCH] migrationo of Messages to new structure --- .../service/jmfmessage/IntegrationUtils.java | 57 ++++++++++++++++++- .../cip4/KnownDevicesMessageService.java | 27 +++++++++ .../cip4/KnownMessagesMessageService.java | 27 +++++++++ .../KnownSubscriptionsMessageService.java | 26 +++++++++ .../cip4/QueueStatusMessageService.java | 26 +++++++++ ...QueueStatusSubscriptionMessageService.java | 26 +++++++++ ...rvice.java => ResourceMessageService.java} | 2 +- .../ResubmitQueueEntryMessageService.java | 28 +++++++++ ...Service.java => StatusMessageService.java} | 2 +- .../StopPersistentChannelMessageService.java | 26 +++++++++ .../cip4/SubmitQueueEntryMessageService.java | 50 ++++++++++++++++ .../groovy/org/cip4/tools/alces/ui/Alces.java | 24 +++++++- .../alces/ui/filefilter/JDFFileFilter.java | 23 -------- 13 files changed, 315 insertions(+), 29 deletions(-) create mode 100644 src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/KnownDevicesMessageService.java create mode 100644 src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/KnownMessagesMessageService.java create mode 100644 src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/KnownSubscriptionsMessageService.java create mode 100644 src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/QueueStatusMessageService.java create mode 100644 src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/QueueStatusSubscriptionMessageService.java rename src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/{ResourceQueryMessageService.java => ResourceMessageService.java} (89%) create mode 100644 src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/ResubmitQueueEntryMessageService.java rename src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/{StatusQueryMessageService.java => StatusMessageService.java} (91%) create mode 100644 src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/StopPersistentChannelMessageService.java create mode 100644 src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/SubmitQueueEntryMessageService.java delete mode 100644 src/main/groovy/org/cip4/tools/alces/ui/filefilter/JDFFileFilter.java diff --git a/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/IntegrationUtils.java b/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/IntegrationUtils.java index ef0a67f..a425e5f 100644 --- a/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/IntegrationUtils.java +++ b/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/IntegrationUtils.java @@ -2,19 +2,29 @@ import org.cip4.jdflib.jmf.JMFBuilder; import org.cip4.jdflib.jmf.JMFBuilderFactory; +import org.cip4.tools.alces.service.file.FileService; import org.cip4.tools.alces.service.settings.SettingsService; +import javax.swing.*; +import javax.swing.filechooser.FileFilter; +import java.awt.*; +import java.io.File; + public class IntegrationUtils { private final JMFBuilder jmfBuilder; private final SettingsService settingsService; + private final FileService fileService; + private final Component component; /** * Custom constructor. */ - public IntegrationUtils(SettingsService settingsService) { + public IntegrationUtils(SettingsService settingsService, FileService fileService, Component component) { this.settingsService = settingsService; + this.fileService = fileService; + this.component = component; // create and configure JMF Builder jmfBuilder = JMFBuilderFactory.getJMFBuilder(null); @@ -38,4 +48,49 @@ public JMFBuilder getJmfBuilder() { public String getSubscriberUrl() { return settingsService.getBaseUrl() + "/alces/jmf/"; } + + /** + * Returns Alces' return URL. + * @return The return URL of Alces. + */ + public String getReturnUrl() { + return getSubscriberUrl(); + } + + /** + * Publish a file to external services by an URL. + * @param file The file to be published + * @return The files public URL. + */ + public String publishFile(File file) { + + // publish file + String filename = fileService.publishFile(file); + + // craete and return public URL + return settingsService.getBaseUrl() + "/alces/file/" + filename; + } + + /** + * Select a file from the file system using a dialog. + * @param title The dialogs title. + * @param fileFilter The file filter. + * @return The selected file. + */ + public File selectFile(String title, FileFilter fileFilter) { + + // create JFileChooser dialog + JFileChooser fileChooser = new JFileChooser(settingsService.getLastSelectedDir()); + fileChooser.addChoosableFileFilter(fileFilter); + fileChooser.setDialogTitle(title); + + int returnValue = fileChooser.showOpenDialog(this.component); + + if (returnValue == JFileChooser.APPROVE_OPTION) { + settingsService.setLastSelectedDir(fileChooser.getCurrentDirectory().getAbsolutePath()); + return fileChooser.getSelectedFile(); + } else { + return null; + } + } } diff --git a/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/KnownDevicesMessageService.java b/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/KnownDevicesMessageService.java new file mode 100644 index 0000000..cebf708 --- /dev/null +++ b/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/KnownDevicesMessageService.java @@ -0,0 +1,27 @@ +package org.cip4.tools.alces.service.jmfmessage.cip4; + +import org.cip4.jdflib.auto.JDFAutoDeviceFilter; +import org.cip4.tools.alces.service.jmfmessage.IntegrationUtils; +import org.cip4.tools.alces.service.jmfmessage.JmfMessageService; +import org.springframework.stereotype.Service; + +@Service +public class KnownDevicesMessageService implements JmfMessageService { + + @Override + public String getMessageType() { + return "KnownDevices"; + } + + @Override + public String getButtonTextExtension() { + return null; + } + + @Override + public String createJmfMessage(IntegrationUtils integrationUtils) { + return integrationUtils.getJmfBuilder() + .buildKnownDevicesQuery(JDFAutoDeviceFilter.EnumDeviceDetails.Details) + .toXML(); + } +} diff --git a/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/KnownMessagesMessageService.java b/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/KnownMessagesMessageService.java new file mode 100644 index 0000000..d8a1d80 --- /dev/null +++ b/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/KnownMessagesMessageService.java @@ -0,0 +1,27 @@ +package org.cip4.tools.alces.service.jmfmessage.cip4; + +import org.cip4.jdflib.auto.JDFAutoDeviceFilter; +import org.cip4.tools.alces.service.jmfmessage.IntegrationUtils; +import org.cip4.tools.alces.service.jmfmessage.JmfMessageService; +import org.springframework.stereotype.Service; + +@Service +public class KnownMessagesMessageService implements JmfMessageService { + + @Override + public String getMessageType() { + return "KnownMessages"; + } + + @Override + public String getButtonTextExtension() { + return null; + } + + @Override + public String createJmfMessage(IntegrationUtils integrationUtils) { + return integrationUtils.getJmfBuilder() + .buildKnownMessagesQuery() + .toXML(); + } +} diff --git a/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/KnownSubscriptionsMessageService.java b/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/KnownSubscriptionsMessageService.java new file mode 100644 index 0000000..2d64681 --- /dev/null +++ b/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/KnownSubscriptionsMessageService.java @@ -0,0 +1,26 @@ +package org.cip4.tools.alces.service.jmfmessage.cip4; + +import org.cip4.tools.alces.service.jmfmessage.IntegrationUtils; +import org.cip4.tools.alces.service.jmfmessage.JmfMessageService; +import org.springframework.stereotype.Service; + +@Service +public class KnownSubscriptionsMessageService implements JmfMessageService { + + @Override + public String getMessageType() { + return "KnownSubscriptions"; + } + + @Override + public String getButtonTextExtension() { + return null; + } + + @Override + public String createJmfMessage(IntegrationUtils integrationUtils) { + return integrationUtils.getJmfBuilder() + .buildKnownSubscriptionsQuery(null, null) + .toXML(); + } +} diff --git a/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/QueueStatusMessageService.java b/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/QueueStatusMessageService.java new file mode 100644 index 0000000..f7aa59e --- /dev/null +++ b/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/QueueStatusMessageService.java @@ -0,0 +1,26 @@ +package org.cip4.tools.alces.service.jmfmessage.cip4; + +import org.cip4.tools.alces.service.jmfmessage.IntegrationUtils; +import org.cip4.tools.alces.service.jmfmessage.JmfMessageService; +import org.springframework.stereotype.Service; + +@Service +public class QueueStatusMessageService implements JmfMessageService { + + @Override + public String getMessageType() { + return "QueueStatus"; + } + + @Override + public String getButtonTextExtension() { + return null; + } + + @Override + public String createJmfMessage(IntegrationUtils integrationUtils) { + return integrationUtils.getJmfBuilder() + .buildQueueStatus() + .toXML(); + } +} diff --git a/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/QueueStatusSubscriptionMessageService.java b/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/QueueStatusSubscriptionMessageService.java new file mode 100644 index 0000000..d4e1e79 --- /dev/null +++ b/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/QueueStatusSubscriptionMessageService.java @@ -0,0 +1,26 @@ +package org.cip4.tools.alces.service.jmfmessage.cip4; + +import org.cip4.tools.alces.service.jmfmessage.IntegrationUtils; +import org.cip4.tools.alces.service.jmfmessage.JmfMessageService; +import org.springframework.stereotype.Service; + +@Service +public class QueueStatusSubscriptionMessageService implements JmfMessageService { + + @Override + public String getMessageType() { + return "QueueStatus"; + } + + @Override + public String getButtonTextExtension() { + return "Subscription"; + } + + @Override + public String createJmfMessage(IntegrationUtils integrationUtils) { + return integrationUtils.getJmfBuilder() + .buildQueueStatusSubscription(integrationUtils.getSubscriberUrl()) + .toXML(); + } +} diff --git a/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/ResourceQueryMessageService.java b/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/ResourceMessageService.java similarity index 89% rename from src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/ResourceQueryMessageService.java rename to src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/ResourceMessageService.java index 8a8951b..6e5ff64 100644 --- a/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/ResourceQueryMessageService.java +++ b/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/ResourceMessageService.java @@ -5,7 +5,7 @@ import org.springframework.stereotype.Service; @Service -public class ResourceQueryMessageService implements JmfMessageService { +public class ResourceMessageService implements JmfMessageService { @Override public String getMessageType() { diff --git a/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/ResubmitQueueEntryMessageService.java b/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/ResubmitQueueEntryMessageService.java new file mode 100644 index 0000000..11932f4 --- /dev/null +++ b/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/ResubmitQueueEntryMessageService.java @@ -0,0 +1,28 @@ +package org.cip4.tools.alces.service.jmfmessage.cip4; + +import org.cip4.tools.alces.service.jmfmessage.IntegrationUtils; +import org.cip4.tools.alces.service.jmfmessage.JmfMessageService; +import org.springframework.stereotype.Service; + +import javax.swing.filechooser.FileFilter; +import java.io.File; + +@Service +public class ResubmitQueueEntryMessageService implements JmfMessageService { + + @Override + public String getMessageType() { + return "ResubmitQueueEntry"; + } + + @Override + public String getButtonTextExtension() { + return null; + } + + @Override + public String createJmfMessage(IntegrationUtils integrationUtils) { + + return ""; + } +} diff --git a/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/StatusQueryMessageService.java b/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/StatusMessageService.java similarity index 91% rename from src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/StatusQueryMessageService.java rename to src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/StatusMessageService.java index c08a733..0343559 100644 --- a/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/StatusQueryMessageService.java +++ b/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/StatusMessageService.java @@ -6,7 +6,7 @@ import org.springframework.stereotype.Service; @Service -public class StatusQueryMessageService implements JmfMessageService { +public class StatusMessageService implements JmfMessageService { @Override public String getMessageType() { diff --git a/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/StopPersistentChannelMessageService.java b/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/StopPersistentChannelMessageService.java new file mode 100644 index 0000000..8eb22d0 --- /dev/null +++ b/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/StopPersistentChannelMessageService.java @@ -0,0 +1,26 @@ +package org.cip4.tools.alces.service.jmfmessage.cip4; + +import org.cip4.tools.alces.service.jmfmessage.IntegrationUtils; +import org.cip4.tools.alces.service.jmfmessage.JmfMessageService; +import org.springframework.stereotype.Service; + +@Service +public class StopPersistentChannelMessageService implements JmfMessageService { + + @Override + public String getMessageType() { + return "StopPersistentChannel"; + } + + @Override + public String getButtonTextExtension() { + return null; + } + + @Override + public String createJmfMessage(IntegrationUtils integrationUtils) { + return integrationUtils.getJmfBuilder() + .buildStopPersistentChannel(null, null, integrationUtils.getSubscriberUrl()) + .toXML(); + } +} diff --git a/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/SubmitQueueEntryMessageService.java b/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/SubmitQueueEntryMessageService.java new file mode 100644 index 0000000..3c37701 --- /dev/null +++ b/src/main/groovy/org/cip4/tools/alces/service/jmfmessage/cip4/SubmitQueueEntryMessageService.java @@ -0,0 +1,50 @@ +package org.cip4.tools.alces.service.jmfmessage.cip4; + +import org.cip4.jdflib.auto.JDFAutoDeviceFilter; +import org.cip4.tools.alces.service.jmfmessage.IntegrationUtils; +import org.cip4.tools.alces.service.jmfmessage.JmfMessageService; +import org.springframework.stereotype.Service; + +import javax.swing.*; +import javax.swing.filechooser.FileFilter; +import java.io.File; + +@Service +public class SubmitQueueEntryMessageService implements JmfMessageService { + + @Override + public String getMessageType() { + return "SubmitQueueEntry"; + } + + @Override + public String getButtonTextExtension() { + return null; + } + + @Override + public String createJmfMessage(IntegrationUtils integrationUtils) { + + // define file filter + FileFilter fileFilter = new FileFilter() { + @Override + public boolean accept(File file) { + return file.getName().toLowerCase().endsWith(".jdf") + || (file.isDirectory() && !file.getName().startsWith(".")); + } + + @Override + public String getDescription() { + return "JDF Job Tickets (*.jdf)"; + } + }; + + // select file to be submitted + File file = integrationUtils.selectFile("Select JDF File", fileFilter); + + // create message + return integrationUtils.getJmfBuilder() + .buildSubmitQueueEntry(integrationUtils.getReturnUrl(), integrationUtils.publishFile(file)) + .toXML(); + } +} diff --git a/src/main/groovy/org/cip4/tools/alces/ui/Alces.java b/src/main/groovy/org/cip4/tools/alces/ui/Alces.java index 72b5206..758a0e2 100644 --- a/src/main/groovy/org/cip4/tools/alces/ui/Alces.java +++ b/src/main/groovy/org/cip4/tools/alces/ui/Alces.java @@ -23,6 +23,7 @@ import org.cip4.tools.alces.service.about.AboutService; import org.cip4.tools.alces.service.discovery.DiscoveryService; import org.cip4.tools.alces.service.discovery.model.*; +import org.cip4.tools.alces.service.file.FileService; import org.cip4.tools.alces.service.jmfmessage.IntegrationUtils; import org.cip4.tools.alces.service.jmfmessage.JmfMessageService; import org.cip4.tools.alces.service.settings.SettingsService; @@ -76,6 +77,9 @@ public class Alces extends JFrame { @Autowired private SettingsService settingsService; + @Autowired + private FileService fileService; + @Autowired private TestRunnerService testRunnerService; @@ -499,7 +503,7 @@ private void updateJdfMessageServices(JdfController jdfController) { List messageServices = jdfController.getJdfMessageServices(); // create creation utils - final IntegrationUtils integrationUtils = new IntegrationUtils(settingsService); + final IntegrationUtils integrationUtils = new IntegrationUtils(settingsService, fileService, this); // create buttons messageServices.stream() @@ -510,8 +514,22 @@ private void updateJdfMessageServices(JdfController jdfController) { jmfMessageServices.stream() .filter(jmfMessageService -> Objects.equals(jmfMessageService.getMessageType(), messageService.getType())) .forEach(jmfMessageService -> { - JButton button = createButton(messageService.getType() + jmfMessageService.getButtonTextExtension()); - button.addActionListener(e -> startTestSession(jmfMessageService.createJmfMessage(integrationUtils))); + + // create button + String buttonText = messageService.getType(); + + if(StringUtils.isNotEmpty(jmfMessageService.getButtonTextExtension())) { + buttonText += jmfMessageService.getButtonTextExtension(); + } + + JButton button = createButton(buttonText); + button.addActionListener(e -> { + + // TBD: put queue entry id in state and provide it. + + // create message and start test session + startTestSession(jmfMessageService.createJmfMessage(integrationUtils)); + }); messagesPanel.add(button); }); diff --git a/src/main/groovy/org/cip4/tools/alces/ui/filefilter/JDFFileFilter.java b/src/main/groovy/org/cip4/tools/alces/ui/filefilter/JDFFileFilter.java deleted file mode 100644 index 9884f95..0000000 --- a/src/main/groovy/org/cip4/tools/alces/ui/filefilter/JDFFileFilter.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.cip4.tools.alces.ui.filefilter; - -import javax.swing.filechooser.FileFilter; -import java.io.File; - -/** - * A filter that only accepts JDF job ticket files and directories that whose - * filenames do not start with '.'. - */ -public class JDFFileFilter extends FileFilter { - - /** - * Returns true if the filename ends with 'jdf'. - */ - public boolean accept(File pathname) { - return pathname.getName().toLowerCase().endsWith(".jdf") - || (pathname.isDirectory() && !pathname.getName().startsWith(".")); - } - - public String getDescription() { - return "JDF Job Tickets (*.jdf)"; - } -}