Skip to content

Commit

Permalink
migrationo of Messages to new structure
Browse files Browse the repository at this point in the history
  • Loading branch information
meiXXI committed May 10, 2022
1 parent 8c681d5 commit 45db346
Show file tree
Hide file tree
Showing 13 changed files with 315 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.springframework.stereotype.Service;

@Service
public class ResourceQueryMessageService implements JmfMessageService {
public class ResourceMessageService implements JmfMessageService {

@Override
public String getMessageType() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.springframework.stereotype.Service;

@Service
public class StatusQueryMessageService implements JmfMessageService {
public class StatusMessageService implements JmfMessageService {

@Override
public String getMessageType() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
24 changes: 21 additions & 3 deletions src/main/groovy/org/cip4/tools/alces/ui/Alces.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,6 +77,9 @@ public class Alces extends JFrame {
@Autowired
private SettingsService settingsService;

@Autowired
private FileService fileService;

@Autowired
private TestRunnerService testRunnerService;

Expand Down Expand Up @@ -499,7 +503,7 @@ private void updateJdfMessageServices(JdfController jdfController) {
List<MessageService> messageServices = jdfController.getJdfMessageServices();

// create creation utils
final IntegrationUtils integrationUtils = new IntegrationUtils(settingsService);
final IntegrationUtils integrationUtils = new IntegrationUtils(settingsService, fileService, this);

// create buttons
messageServices.stream()
Expand All @@ -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);
});

Expand Down
Loading

0 comments on commit 45db346

Please sign in to comment.