use of com.fo0.robot.model.ActionItem in project Robot by fo0.
the class TypeDownloadChainTest method downloadTestParsing.
@Test
public void downloadTestParsing() {
ActionItem item = ActionItem.builder().type(EActionType.Download).value("$SRC(http://fo0.me/ip.php) $DST(ip.php)").description("description example").build();
List<KeyValue> list = item.parsedValue();
KeyValue url = list.stream().filter(e -> e.getKey().equals(CONSTANTS_PATTERN.SOURCE)).findFirst().orElse(null);
Assert.assertEquals(CONSTANTS_PATTERN.SOURCE, url.getKey());
Assert.assertEquals("http://fo0.me/ip.php", url.getValue());
KeyValue path = list.stream().filter(e -> e.getKey().equals(CONSTANTS_PATTERN.DESTINATION)).findFirst().orElse(null);
Assert.assertEquals(CONSTANTS_PATTERN.DESTINATION, path.getKey());
Assert.assertEquals("ip.php", path.getValue());
}
use of com.fo0.robot.model.ActionItem in project Robot by fo0.
the class MainGUI method initialize.
/**
* Initialize the contents of the frame.
*/
private static void initialize() {
// create main frame
frame = new JFrame();
frame.setTitle("Robot v" + CONSTANTS.VERSION);
frame.getContentPane().setLayout(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// center frame on screen
frame.setSize(655, 528);
frame.setLocationRelativeTo(null);
frame.getContentPane().setBackground(Color.LIGHT_GRAY);
frame.setBackground(Color.LIGHT_GRAY);
frame.setResizable(false);
toggleConsole(currentMode);
JPanel panelTop = new JPanel();
panelTop.setBounds(0, 0, 653, 25);
frame.getContentPane().add(panelTop);
panelTop.setLayout(null);
JButton btnAdd = new JButton("ADD");
btnAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new AddChainItemWindow();
}
});
btnAdd.setBounds(97, 0, 73, 24);
panelTop.add(btnAdd);
JButton btnDel = new JButton("DEL");
btnDel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int col = actionTable.getSelectedRow();
deleteItem(tableModel.getRow(col));
}
});
btnDel.setBounds(169, 0, 73, 24);
panelTop.add(btnDel);
JButton btnStart = new JButton("START");
btnStart.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent a) {
new Thread(() -> {
SwingUtilities.invokeLater(() -> {
areaConsole.setText("");
areaChain.setText("");
});
SwingUtilities.invokeLater(() -> {
toggleConsole(EMode.ConsoleMaximized);
});
Utils.sleep(TimeUnit.MILLISECONDS, 200);
// adding listener to receive events from backend
ControllerChain.getChain().addCmdListener((ctx, e) -> {
appendToChain(String.valueOf(e.getKey().getId()), e.getKey().getName(), e.getKey().getDescription(), e.getValue().getData().getState().getCmd().name());
});
// add listener for: Console output log
ControllerChain.getChain().getContext().addOutputListener(cli -> {
appendToConsole(cli);
});
Utils.sleep(TimeUnit.SECONDS, 1);
ControllerChain.start();
}).start();
}
});
btnStart.setBounds(0, 0, 98, 24);
panelTop.add(btnStart);
JButton buttonToggleConsole = new JButton(">_");
buttonToggleConsole.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (currentMode == EMode.ConsoleMaximized) {
toggleConsole(EMode.Normal);
} else {
toggleConsole(EMode.ConsoleMaximized);
}
}
});
buttonToggleConsole.setBounds(580, 0, 73, 24);
panelTop.add(buttonToggleConsole);
ErrorMode errMode = ErrorMode.FailOnErr;
if (Controller.getConfig().ignoreErrors)
errMode = ErrorMode.NotFailOnErr;
JButton btnTgleErrors = new JButton(errMode.name());
btnTgleErrors.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (btnTgleErrors.getText().equals(ErrorMode.FailOnErr.name())) {
Controller.getConfig().ignoreErrors = true;
btnTgleErrors.setText(ErrorMode.NotFailOnErr.name());
} else {
Controller.getConfig().ignoreErrors = false;
btnTgleErrors.setText(ErrorMode.FailOnErr.name());
}
}
});
btnTgleErrors.setBounds(468, 0, 105, 24);
panelTop.add(btnTgleErrors);
createStopButton(panelTop);
createProcessLabel(panelTop);
JPanel panelTable = new JPanel();
panelTable.setBounds(0, 26, 653, 265);
frame.getContentPane().add(panelTable);
panelTable.setLayout(new CardLayout(0, 0));
actionTable = new JTable();
actionTable.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
if (e.getClickCount() == 2) {
JTable table = (JTable) e.getSource();
Point point = e.getPoint();
int row = table.rowAtPoint(point);
ActionItem item = tableModel.getRow(row);
new AddChainItemWindow(item);
}
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
}
});
tableModel = new BeanTableModelAction();
actionTable.setModel(tableModel);
JScrollPane scrollPaneTable = new JScrollPane(actionTable);
panelTable.add(scrollPaneTable, "name_7985051461163");
JPanel panelChain = new JPanel();
panelChain.setBounds(0, 292, 248, 188);
frame.getContentPane().add(panelChain);
panelChain.setLayout(new CardLayout(0, 0));
areaChain = new JTextArea();
areaChain.setEditable(false);
JScrollPane scrollPaneChain = new JScrollPane(areaChain);
// scrollPaneChain.getVerticalScrollBar().addAdjustmentListener(e -> {
// e.getAdjustable().setValue(e.getAdjustable().getMaximum());
// });
panelChain.add(scrollPaneChain, "name_1466312782685");
JPanel panelConsole = new JPanel();
panelConsole.setBounds(248, 292, 405, 188);
frame.getContentPane().add(panelConsole);
panelConsole.setLayout(new CardLayout(0, 0));
JScrollPane scrollPaneConsole = new JScrollPane((Component) null);
// scrollPaneConsole.getVerticalScrollBar().addAdjustmentListener(e -> {
// e.getAdjustable().setValue(e.getAdjustable().getMaximum());
// });
panelConsole.add(scrollPaneConsole, "name_2349855873542");
areaConsole = new JTextArea();
areaConsole.setEditable(false);
scrollPaneConsole.setViewportView(areaConsole);
JMenuBar menuBar = new JMenuBar();
frame.setJMenuBar(menuBar);
JMenu mnConfig = new JMenu("Config");
menuBar.add(mnConfig);
JMenuItem mntmConfigLoad = new JMenuItem("Load");
mntmConfigLoad.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File("."));
FileNameExtensionFilter filter = new FileNameExtensionFilter("Robot", "robot");
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
// load config from disk -> file
ControllerChain.getChain().getContext().loadFromFile(file.getAbsolutePath());
MainGUI.getTableModel().loadActionContextFromController();
}
}
});
mnConfig.add(mntmConfigLoad);
JMenuItem mntmConfigSave = new JMenuItem("Save");
mntmConfigSave.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
String lastPathDetection = ".";
if (!Controller.getConfig().configFile.isEmpty()) {
lastPathDetection = Controller.getConfig().configFile;
}
chooser.setCurrentDirectory(new File(lastPathDetection));
FileNameExtensionFilter filter = new FileNameExtensionFilter("Robot", "robot");
chooser.setFileFilter(filter);
int returnVal = chooser.showSaveDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
if (!file.getName().endsWith(".robot")) {
Logger.info("detected missing file extension, appending .robot to file");
File tmpFile = new File(file.getAbsolutePath() + ".robot");
file.renameTo(tmpFile);
file = tmpFile;
}
// save config to disk -> file
ControllerChain.getChain().getContext().save(file.getAbsolutePath());
}
}
});
mnConfig.add(mntmConfigSave);
JMenu mnHelp = new JMenu("Help");
menuBar.add(mnHelp);
JMenuItem mntmHelpAbout = new JMenuItem("About");
mntmHelpAbout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
mnHelp.add(mntmHelpAbout);
JMenuItem mntmHelpUpdate = new JMenuItem("Update");
mntmHelpUpdate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new UpdateWindow();
}
});
mnHelp.add(mntmHelpUpdate);
refreshTable();
addChainObservers();
}
use of com.fo0.robot.model.ActionItem in project Robot by fo0.
the class ChainActionItem method command.
@Override
public EChainResponse command(ActionContext ctx) throws Exception {
// get latest action
this.ctx = ctx;
Entry<Integer, ActionItem> item = ctx.pop();
// info
Logger.info("Action[" + item.getKey() + "] " + item.getValue());
type = item.getValue().getType();
EChainResponse response = EChainResponse.Break;
switch(type) {
case Simple_Commandline:
response = simple_commandline(item.getValue().parsedValue());
break;
case Commandline:
response = commandline(item.getValue().parsedValue());
break;
case Sleep:
response = sleep(item.getValue().parsedValue());
break;
case COPY:
response = copy(item.getValue().parsedValue());
break;
case MOVE:
response = move(item.getValue().parsedValue());
break;
case Download:
response = download(item.getValue().parsedValue());
break;
case Zip:
response = zip(item.getValue().parsedValue());
break;
case Unzip:
response = unzip(item.getValue().parsedValue());
break;
case TAR:
response = tar(item.getValue().parsedValue());
break;
case UNTAR:
response = untar(item.getValue().parsedValue());
break;
case TARGZ:
response = targz(item.getValue().parsedValue());
break;
case UNTARGZ:
response = untargz(item.getValue().parsedValue());
break;
case SEVEN_ZIP:
response = sevenZip(item.getValue().parsedValue());
break;
case UNSEVEN_ZIP:
response = unSevenZip(item.getValue().parsedValue());
break;
case SSH:
response = ssh(item.getValue().parsedValue());
break;
case SCP_Download:
case SCP_Upload:
response = scp(item.getValue().parsedValue());
break;
case FTP_Download:
response = ftp(item.getValue().parsedValue());
break;
default:
ctx.addToLog(type, "Currently not implemented, you may check for updates");
break;
}
return response;
}
use of com.fo0.robot.model.ActionItem in project Robot by fo0.
the class ChainPreAction method preCommand.
@Override
public EChainResponse preCommand(ActionContext ctx) throws Exception {
ActionItem item = ctx.peek().getValue();
if (!item.isActive()) {
ctx.addToLog(item.getType(), "is inactive");
// to remove the item
ctx.pop();
return EChainResponse.Skip;
}
return EChainResponse.Continue;
}
use of com.fo0.robot.model.ActionItem in project Robot by fo0.
the class TypeZipChainTest method zip.
@Test
public void zip() {
ActionItem item = ActionItem.builder().type(EActionType.Zip).value("$SRC(/home/max/Schreibtisch/Robot/test/agent.zip) $DST(/home/max/Schreibtisch/Robot/test/x)").description("description example").build();
List<KeyValue> list = item.parsedValue();
KeyValue zipFile = list.stream().filter(e -> e.getKey().equals(CONSTANTS_PATTERN.SOURCE)).findFirst().orElse(null);
Assert.assertEquals(CONSTANTS_PATTERN.SOURCE, zipFile.getKey());
Assert.assertEquals("/home/max/Schreibtisch/Robot/test/agent.zip", zipFile.getValue());
KeyValue zipDstFolder = list.stream().filter(e -> e.getKey().equals(CONSTANTS_PATTERN.DESTINATION)).findFirst().orElse(null);
Assert.assertEquals(CONSTANTS_PATTERN.DESTINATION, zipDstFolder.getKey());
Assert.assertEquals("/home/max/Schreibtisch/Robot/test/x", zipDstFolder.getValue());
}
Aggregations