SlideShare a Scribd company logo
/**
* EasyButton
*
* @author Adam Dale
*
*
*/
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class EasyGUI {
private JFrame frame = new JFrame();
//Create all panel componants
private JPanel mainPanel = new JPanel();
private JCheckBox orderHandoffCheck = new JCheckBox("Do you need
orderHandoff?");
private JLabel enterOrderIDLabel = new JLabel("Please enter
orderID: ");
private JLabel enterEnvLabel = new JLabel("Please select which
environment: ");
private JLabel enterFlowLabel = new JLabel("Please slect which
flow: ");
private JLabel enterOrderLabel = new JLabel("Please slect which
order type: ");
//private JButton submit = new JButton("TEST");
private JButton submit = new JButton("!EASY!");
private static JTextField orderIDTextField = new JTextField(10);
private static JCheckBox csixmlCheck = new JCheckBox("Do you need
CSIXML files?");
private static String [] flowType = {"A","B"};
private static String [] envirType = {"FST1","FST2", "FST3", "FST5",
"FST7", "DEV3"};
private static String [] orderType = {"Provide", "Modify"};
private static JComboBox flowTypeComboBox = new JComboBox(flowType);
private static JComboBox envirTypeComboBox = new
JComboBox(envirType);
private static JComboBox orderTypeComboBox = new
JComboBox(orderType);
private EasyButton actionListener = new EasyButton();
public EasyGUI() {
//Create frames and size for main program
frame.setTitle("EasyButton Version 1.0.5.2");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setSize(400, 400);
frame.setLocation(100,200);
frame.setResizable(false);
GridBagConstraints mainC = new GridBagConstraints();
mainPanel.setLayout(new GridBagLayout());
mainC.fill = GridBagConstraints.HORIZONTAL;
mainC.gridx = 0;
mainC.gridy = 0;
mainPanel.add(enterEnvLabel, mainC);
mainC.gridx = 2;
mainC.gridy = 0;
mainC.insets = new Insets(0,30,10,0);
mainPanel.add(envirTypeComboBox, mainC);
envirTypeComboBox.addActionListener(actionListener);
mainC.gridx = 0;
mainC.gridy = 1;
mainC.insets = new Insets(0,0,10,0);
mainPanel.add(enterFlowLabel, mainC);
mainC.gridx = 2;
mainC.gridy = 1;
mainC.insets = new Insets(0,30,10,0);
mainPanel.add(flowTypeComboBox, mainC);
flowTypeComboBox.addActionListener(actionListener);
mainC.gridx = 0;
mainC.gridy = 2;
mainC.insets = new Insets(0,0,10,0);
mainPanel.add(enterOrderLabel, mainC);
mainC.gridx = 2;
mainC.gridy = 2;
mainC.insets = new Insets(0,30,10,0);
mainPanel.add(orderTypeComboBox, mainC);
orderTypeComboBox.addActionListener(actionListener);
mainC.gridx = 0;
mainC.gridy = 3;
mainC.insets = new Insets(0,0,10,0);
mainPanel.add(enterOrderIDLabel, mainC);
mainC.gridx = 2;
mainC.gridy = 3;
mainC.insets = new Insets(0,30,10,0);
mainPanel.add(orderIDTextField, mainC);
orderIDTextField.addActionListener(actionListener);
mainC.gridx = 0;
mainC.gridy = 4;
mainC.insets = new Insets(0,0,10,0);
mainPanel.add(csixmlCheck, mainC);
//csixmlCheck.setSelected(true);
csixmlCheck.addActionListener(actionListener);
mainC.gridx = 2;
mainC.gridy = 4;
mainC.insets = new Insets(0,30,10,0);
mainPanel.add(orderHandoffCheck, mainC);
orderHandoffCheck.addActionListener(actionListener);
mainC.gridx = 1;
mainC.gridy = 5;
mainC.fill = GridBagConstraints.CENTER;
mainPanel.add(submit, mainC);
submit.addActionListener(actionListener);
//Finish frame layout
frame.add(mainPanel);
frame.pack();
frame.setVisible(true);
}
/**
* Gets the value of the environment type.
* @return
*/
public static String getEnvirTypeComboBox(){
return envirTypeComboBox.getSelectedItem().toString();
}
/**
* Gets the order ID value.
* @return
*/
public static String getOrderIDTextField(){
return orderIDTextField.getText();
}
/**
* Sets the order ID fields based on text input.
* @param text
*/
public static void setOrderIDTextField(String text){
orderIDTextField.setText(text);
}
/**
* Gets the order type value.
*
* @return
*/
public static String getOrderTypeComboBox(){
return orderTypeComboBox.getSelectedItem().toString();
}
/**
* Gets the value of the Flow type.
*
* @return
*/
public static String getFlowTypeComboBox(){
return flowTypeComboBox.getSelectedItem().toString();
}
/**
* Gets the value of the CSIXML flag and returns
* true or false.
* @return
*/
public static boolean isCSIXMLSelected(){
if(csixmlCheck.isSelected()){
return true;
}
else {
return false;
}
}
}
/**
* EasyButton
*
* @author Adam Dale
*
*/
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class EasyButton extends JFrame implements ActionListener{
/**
* serialVersionUID
*/
private static final long serialVersionUID = 1L;
JFrame popUpFrame = new JFrame();
private String [] csixmlLabels=
{"FiberAddAccountServiceRequest","FiberAddAccountServiceResponse",
"FiberInquireAccountDetailsServiceRequest","FiberInquireAccountDeta
ilsServiceResponse",
"FiberInquireCrossProductPackagesServiceRequest","FiberInquireCross
ProductPackagesServiceResponse",
"FiberInquireProductDetailsServiceRequest","FiberInquireProductDeta
ilsServiceResponse",
"FiberValidateProductDetailsServiceRequest","FiberValidateProductDe
tailsServiceResponse",
"FiberInquireQuotationServiceRequestRequest","FiberInquireQuotation
ServiceRequestResponse",
"FInqAsgndProdDetailsServiceRequest",
"FInqAsgndProdDetailsServiceResponse"};
private String totalResults, accountNumber="", orderID, fileName;
private ArrayList<String> csixmlData;
private ArrayList<String> ftpFileList;
private File orderFolder;
private int confirmResults =1;
/**
* Create main to show driver
* @param args
*/
public static void main(String[] args) {
new EasyGUI();
}
public EasyButton() {
//First check to make sure plink is setup and read
File plinkRegKeys= new File("Plink Host Keys.reg");
File plinkHostBatch = new File("PlinkHostKey.bat");
if(plinkRegKeys.exists()){
JOptionPane.showMessageDialog(null, "Setup will configure
now",
"First Time Setup",
JOptionPane.INFORMATION_MESSAGE);
BatchEngine.checkPlinkHostKey();
//Perform cleanup
//Give time to process
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(plinkHostBatch.exists()){
plinkHostBatch.delete();
}
if(plinkRegKeys.exists()){
plinkRegKeys.delete();
}
}
}
public void actionPerformed(ActionEvent arg0) {
//Comment out for testing uses
if(arg0.getActionCommand().equals("TEST")){
}
if(arg0.getActionCommand().equals("Close")){
ShowPopUpWindow.closeWindow();
}
if(arg0.getActionCommand().equals("!EASY!")){
//Lets make sure no frames are open
popUpFrame.dispose();
boolean debugFlag = false;
//Delete all files created once finished
checkForExistingFiles(debugFlag);
//Clear all variables
accountNumber="";
totalResults="";
orderID="";
ftpFileList = new ArrayList<String>();
csixmlData = new ArrayList<String>();
String flow =EasyGUI.getFlowTypeComboBox();
String orderType = EasyGUI.getOrderTypeComboBox();
String autoResults = "", autoTechResults="";
//First do a check on the order number
//Lets make sure its only digits at x length
orderID = EasyGUI.getOrderIDTextField();
if(checkOrderIDFormat(orderID)){
//checkForExistingFiles();
// Get order id from user and pass it in here
String envirVariable="", hostName="";
if(EasyGUI.getEnvirTypeComboBox().equals("FST1")){
envirVariable="1";
hostName="b2cfst";
}
if(EasyGUI.getEnvirTypeComboBox().equals("FST2")){
envirVariable="2";
hostName="b2cfst";
}
if(EasyGUI.getEnvirTypeComboBox().equals("FST3")){
envirVariable="3";
hostName="b2cfst";
}
if(EasyGUI.getEnvirTypeComboBox().equals("FST5")){
envirVariable="5";
hostName="b2cfst";
}
if(EasyGUI.getEnvirTypeComboBox().equals("FST7")){
envirVariable="7";
hostName="b2cfst";
}
if(EasyGUI.getEnvirTypeComboBox().equals("DEV3")){
envirVariable="03";
hostName="b2cimp";
}
BatchEngine.createConvIDLogBatch(orderID, hostName,
envirVariable, flow);
try {
//NOTE
//When placing commands for batch params are only
seprated by space and may not go past 9.
String convIDCommand = "cmd /C start /MIN
EasyConvID.bat "
+hostName
+" "+envirVariable
+" "+flow
+" "+orderID;
Runtime convIDRunTime = Runtime.getRuntime();
Process convIDProcess =
convIDRunTime.exec(convIDCommand);
//Call special timer here if this process is running
for more
//than 60 seconds kill it.
startTimeOutSession(60);
int convIDPause=0;
int banPause=0;
int ftpPause=0;
File convIDResults = new File("results.txt");
File banResults = new File("results2.txt");
File ftpResults = new File("results3.txt");
String convIDStr="";
while (convIDPause==0) {
if(convIDResults.exists()){
convIDProcess.destroy();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
convIDStr=BatchEngine.getConversationID();
autoResults=BatchEngine.getAutomationResults(convIDStr);
//special automation call for Jira tickets
and developers to debug
autoTechResults=BatchEngine.getAutomationResultsForText();
convIDPause=1;
}
}
//Check to make sure system did not run to fast
System.out.println("Conversation ID grab is
"+convIDStr);
if(convIDStr.equals("ECHO is off.")||
convIDStr.equals("")){
ShowPopUpWindow.showPopUp(orderID,"Not
Found","Not Found","nCSIXMLS Found:nN/A",autoResults, "", null);
EasyGUI.setOrderIDTextField("");
}
else {
accountNumber=BatchEngine.getAccountNumber();
//Run second batch job
if(EasyGUI.isCSIXMLSelected()){
BatchEngine.createBanBatch(convIDStr,
getMessageID());
String banCommand = "cmd /C start /MIN
EasyBan.bat "
+hostName
+" "+envirVariable
+" "+flow
+" "+orderID;
Runtime banRunTime = Runtime.getRuntime();
Process banProcess = banRunTime.exec(banCommand);
//Create a timer to wait for x amount of time
before killing process
//This will fix hang in system, if error found in
plink
csixmlData.clear();
while (banPause==0){
if(banResults.exists()){
banProcess.destroy();
banResults.delete();
//Start reading in output to get BAN and
CSIXML
BufferedReader line = new
BufferedReader(new FileReader("output2.txt"));
String bufBanStr;
String
fiberAddAccountServiceResponse="",fiberAddAccountServiceRequest="";
String
fiberInquireAccountDetailsServiceResponse="",fiberInquireAccountDetails
ServiceRequest="";
String
fiberInquireCrossProductPackagesServiceResponse="",
fiberInquireCrossProductPackagesServiceRequest="";
String
fiberInquireProductDetailsServiceResponse="",fiberInquireProductDetails
ServiceRequest="";
String
fiberValidateProductDetailsServiceResponse="",fiberValidateProductDetai
lsServiceRequest="";
String
fiberInquireQuotationServiceResponse="",fiberInquireQuotationServiceReq
uest="";
String
fInqAsgndProdDetailsServiceResponse="",fInqAsgndProdDetailsServiceReque
st="";
while ((bufBanStr = line.readLine()) !=
null) {
if(bufBanStr.contains("FiberAddAccountServiceResponse")){
fiberAddAccountServiceResponse=bufBanStr;
}
if(bufBanStr.contains("FiberAddAccountServiceRequest")){
fiberAddAccountServiceRequest=bufBanStr;
}
if(bufBanStr.contains("FiberInquireAccountDetailsServiceResponse")){
fiberInquireAccountDetailsServiceResponse=bufBanStr;
}
if(bufBanStr.contains("FiberInquireAccountDetailsServiceRequest")){
fiberInquireAccountDetailsServiceRequest=bufBanStr;
}
if(bufBanStr.contains("FiberInquireCrossProductPackagesServiceResponse"
)){
fiberInquireCrossProductPackagesServiceResponse=bufBanStr;
}
if(bufBanStr.contains("FiberInquireCrossProductPackagesServiceRequest")
){
fiberInquireCrossProductPackagesServiceRequest=bufBanStr;
}
if(bufBanStr.contains("FiberInquireProductDetailsServiceResponse")){
fiberInquireProductDetailsServiceResponse=bufBanStr;
}
if(bufBanStr.contains("FiberInquireProductDetailsServiceRequest")){
fiberInquireProductDetailsServiceRequest=bufBanStr;
}
if(bufBanStr.contains("FiberValidateProductDetailsServiceResponse")){
fiberValidateProductDetailsServiceResponse=bufBanStr;
}
if(bufBanStr.contains("FiberValidateProductDetailsServiceRequest")){
fiberValidateProductDetailsServiceRequest=bufBanStr;
}
if(bufBanStr.contains("FiberInquireQuotationServiceResponse")){
fiberInquireQuotationServiceResponse=bufBanStr;
}
if(bufBanStr.contains("FiberInquireQuotationServiceRequest")){
fiberInquireQuotationServiceRequest=bufBanStr;
}
if(bufBanStr.contains("FInqAsgndProdDetailsServiceResponse")){
fInqAsgndProdDetailsServiceResponse=bufBanStr;
}
if(bufBanStr.contains("FInqAsgndProdDetailsServiceRequest")){
fInqAsgndProdDetailsServiceRequest=bufBanStr;
}
}
if(orderType.equals("Provide")){
csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberAddAccountServiceRe
sponse, 1));
csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberAddAccountServiceRe
quest, 0));
csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireAccountDetai
lsServiceResponse, 3));
csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireAccountDetai
lsServiceRequest, 2));
csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireCrossProduct
PackagesServiceResponse, 5));
csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireCrossProduct
PackagesServiceRequest, 4));
csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireProductDetai
lsServiceResponse,7));
csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireProductDetai
lsServiceRequest, 6));
csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberValidateProductDeta
ilsServiceResponse,9));
csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberValidateProductDeta
ilsServiceRequest,8));
csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireQuotationSer
viceResponse,11));
csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireQuotationSer
viceRequest,10));
}
else {
csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireAccountDetai
lsServiceResponse, 3));
csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireAccountDetai
lsServiceRequest, 2));
csixmlData.add(checkLogForEmptyCSIXMLFileNames(fInqAsgndProdDetailsServ
iceResponse,13));
csixmlData.add(checkLogForEmptyCSIXMLFileNames(fInqAsgndProdDetailsServ
iceRequest,12));
csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberValidateProductDeta
ilsServiceResponse,9));
csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberValidateProductDeta
ilsServiceRequest,8));
csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireQuotationSer
viceResponse,11));
csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireQuotationSer
viceRequest,10));
}
totalResults=gatherResults(csixmlData);
banPause=1;
line.close();
}
}
confirmResults =
JOptionPane.showConfirmDialog(null,"Would you like the xml files copied
to your system?n","Copy Results",JOptionPane.YES_NO_OPTION);
}
if(totalResults==null){
totalResults="CSIXMLSrnN/A";
}
//Create directory for results found an put text
file in that folder
orderFolder = new File(orderID);
if(orderFolder.exists()){
orderFolder.delete();
}
else{
orderFolder.mkdir();
}
fileName="Order ID "+orderID+".txt";
FileWriter fstream = new
FileWriter(orderFolder+"/"+fileName);
BufferedWriter out = new
BufferedWriter(fstream);
out.write("Conversation ID is:"+"
"+convIDStr
+"rnBan is:
"+accountNumber
+"rnOrder is:
"+orderID
+"rn"+totalResults
+"rnrnrnAUTOMATION
RESULTS:rnrn"+autoTechResults
);
out.close();
if(confirmResults==0){
for(int i=0; i<csixmlData.size();i++){
if(!csixmlData.get(i).contains("File
Not Found")){
ftpFileList.add(csixmlData.get(i));
}
}
//Before we run batch job check for old
files and delete to make room for new files
for(int i=0; i<ftpFileList.size();i++)
{
deleteFiles(ftpFileList.get(i),
orderFolder);
}
//Create the batch job for files found
BatchEngine.getFtpFiles(ftpFileList,
hostName, envirVariable, flow);
//Run batch job
String ftpCommand = "cmd /C start /MIN
EasyFtpFileCopy.bat ";
Runtime ftpRunTime = Runtime.getRuntime();
Process ftpProcess =
ftpRunTime.exec(ftpCommand);
//Move files to correct directory
while (ftpPause==0) {
if(ftpResults.exists()){
ftpProcess.destroy();
for(int i=0;
i<ftpFileList.size();i++)
{
moveFiles(ftpFileList.get(i),
orderFolder);
}
JOptionPane.showMessageDialog(null, "Your files have been copied",
"Finished",
JOptionPane.INFORMATION_MESSAGE);
ftpPause+=1;
}
}
}
ShowPopUpWindow.showPopUp(orderID, convIDStr,
accountNumber,totalResults, autoResults, fileName.toString(),
orderFolder);
//Delete all files created once finished
checkForExistingFiles(debugFlag);
EasyGUI.setOrderIDTextField("");
}
} catch (IOException e) {
// Catch error and print stack
e.printStackTrace();
}
//End if statement for digit check
}
//End if statement for listener
}
}
/**
* Method takes the command and executes the process by
* creating a generic runtime and process to execute.
* @param command
*/
private void runBatchJob(String command){
Runtime genericRuntime = Runtime.getRuntime();
try {
Process genericProcess = genericRuntime.exec(command);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Check for existing xml files and delete
* @param fileName
* @param orderFolder
*/
private void deleteFiles(String filename, File folder) {
// Check for file in folder
File checkFile = new File(folder+"/"+filename);
if(checkFile.exists()){
checkFile.delete();
}
}
/**
* Take all the xml files and move them to the correct folders
* @param fileName
* @param orderFolder
*/
private void moveFiles(String fileName, File folder) {
// File (or directory) to be moved
File file = new File(fileName);
// Move file to new directory
file.renameTo(new File(folder, file.getName()));
}
/**
* Check to make sure Order is in the correct format
* @param orderID2
* @return
*/
private boolean checkOrderIDFormat(String orderID2) {
Pattern digitPattern = Pattern.compile("d+");
Matcher digitMatcher = digitPattern.matcher(orderID2);
if(orderID2.length()!=10){
JOptionPane.showMessageDialog(null, "Please enter correct
order number lenght.nEx. 5777870132", "Format Error",
JOptionPane.ERROR_MESSAGE);
return false;
}
if(!digitMatcher.matches()){
JOptionPane.showMessageDialog(null, "Please enter digits
only.nEx. 5777870132", "Format Error", JOptionPane.ERROR_MESSAGE);
return false;
}
//Everything looks ok return true.
return true;
}
/**
* Get all results
* @param csixmlData2
*/
private String gatherResults(ArrayList<String> csixmlData2) {
//Get all results and format.
String results="rnrnCSIXML RESULTS:rnrn";
for(int i=0; i<csixmlData2.size();i++){
results+=csixmlData2.get(i)+" rn";
}
return results;
}
/**
* Check for existing files and then delete them if they exist.
*/
public void checkForExistingFiles(Boolean debug) {
File result1Text = new File("results.txt");
File result2Text = new File("results2.txt");
File result3Text = new File("results3.txt");
File command1Text = new File("commands.txt");
File command2Text = new File("commands2.txt");
File command3Text = new File("ftpCommands.txt");
File output1Text = new File("output.txt");
File output2Text = new File("output2.txt");
File bat1File = new File("EasyConvID.bat");
File bat2File = new File("EasyBan.bat");
File bat3File = new File("EasyFtpFileCopy.bat");
if(!debug){
if(result1Text.exists()){
result1Text.delete();
}
if(result2Text.exists()){
result2Text.delete();
}
if(result3Text.exists()){
result3Text.delete();
}
if(bat1File.exists()){
bat1File.delete();
}
if(bat2File.exists()){
bat2File.delete();
}
if(bat3File.exists()){
bat3File.delete();
}
if(command1Text.exists()){
command1Text.delete();
}
if(command2Text.exists()){
command2Text.delete();
}
if(command3Text.exists()){
command3Text.delete();
}
if(output1Text.exists()){
output1Text.delete();
}
if(output2Text.exists()){
output2Text.delete();
}
}
}
/**
* Read in the message ID for other batch files
* @return
*/
public static String getMessageID(){
String messageIDFound="";
try {
FileReader input = new FileReader("output.txt");
BufferedReader line = new BufferedReader(input);
String messageIDStr;
while ((messageIDStr = line.readLine()) != null) {
//Strip out the message id
if(messageIDStr.contains("<cng:messageId>")){
messageIDFound =
messageIDStr.split("</cng:messageId>")[0].split("<cng:messageId>")[1];
//messageIDFound= messageIDFound.substring(0,
messageIDFound.length()-6);
}
}
input.close();
line.close();
}catch (IOException e) {
}
return messageIDFound;
}
/**
* Check to see if file found if not display error
*/
public String checkLogForEmptyCSIXMLFileNames(String xml, int
nameTagID){
if(xml.equals("")){
xml="File Not Found.............................
"+csixmlLabels[nameTagID];
}
return xml;
}
/**
* Will start a timer to kill process after x amount of time
* @param convIDProcess
* @return
*/
public void startTimeOutSession(int sessionTimeout){
Timer timer = new Timer();
timer.schedule(new TimerTask(){
public void run(){
System.out.println("This process is killed.");
String killCommand = "cmd /C taskkill /F /IM plink.exe ";
Runtime convIDRunTime = Runtime.getRuntime();
try {
Process convIDProcess =
convIDRunTime.exec(killCommand);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
},sessionTimeout*1000);
}
}
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.io.File;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.UIManager;
/**
* EasyButton
*
* @author Adam Dale
*
*/
public class ShowPopUpWindow {
private static JFrame popUpFrame;
private static EasyButton actionListener = new EasyButton();
public ShowPopUpWindow(){
}
/**
* Creates the results window based on what was returned from search
* @param string
*/
public static void showPopUp(String orderID, String convID, String
ban, String csixml, String auto, String fileName, File orderFolder) {
// TODO Auto-generated method stub
popUpFrame = new JFrame();
JTextArea resultsArea = new JTextArea(17, 50);
JScrollPane scrollPane = new JScrollPane(resultsArea);
JTextArea autoResultsArea = new JTextArea(10, 25);
JScrollPane autoScrollPane = new JScrollPane(autoResultsArea);
JPanel popUpPanel = new JPanel();
JButton close = new JButton("Close");
//Only if something was found will we print this label
JLabel savedFileLabel, savedPathLabel, savedPathNameLabel;
popUpFrame.setTitle("Results Found");
popUpFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
popUpFrame.setVisible(true);
popUpFrame.setSize(200, 200);
popUpFrame.setLocation(100,25);
popUpFrame.setResizable(false);
//Configure text here
resultsArea.setText("Order ID: "+orderID+"n"
+"Conversation ID: "+convID+"n"
+"Ban: "+ban+"n"
+csixml
);
resultsArea.setEditable(false);
resultsArea.setBorder(null);
resultsArea.setForeground(UIManager.getColor("Label.foreground"));
//resultsArea.setBackground(getBackground());
resultsArea.setFont(UIManager.getFont("Label.font"));
resultsArea.setCaretPosition(0);
//Configure auto text here
autoResultsArea.setText("AUTOMATION RESULTS: nn"+auto);
autoResultsArea.setEditable(false);
autoResultsArea.setBorder(null);
autoResultsArea.setForeground(UIManager.getColor("Label.foreground"));
//autoResultsArea.setBackground(getBackground());
autoResultsArea.setFont(UIManager.getFont("Label.font"));
autoResultsArea.setCaretPosition(0);
GridBagConstraints mainC = new GridBagConstraints();
popUpPanel.setLayout(new GridBagLayout());
mainC.fill = GridBagConstraints.HORIZONTAL;
mainC.gridx = 0;
mainC.gridy = 0;
popUpPanel.add(scrollPane, mainC);
mainC.gridy = 1;
mainC.insets = new Insets(20,0,0,0);
popUpPanel.add(autoScrollPane, mainC);
mainC.insets = new Insets(0,0,0,0);
if(convID.equals("Not Found")){
mainC.gridy = 2;
mainC.insets = new Insets(20,240,10,240);
popUpPanel.add(close, mainC);
}
else
{
mainC.gridy = 2;
mainC.insets = new Insets(10,0,0,0);
savedFileLabel = new JLabel("Your results have been saved
as ""+fileName+""");
popUpPanel.add(savedFileLabel, mainC);
mainC.insets = new Insets(0,0,0,0);
mainC.gridy = 3;
savedPathLabel= new JLabel("All files have been saved to:
");
popUpPanel.add(savedPathLabel, mainC);
mainC.gridy = 4;
savedPathNameLabel= new
JLabel(orderFolder.getAbsolutePath());
popUpPanel.add(savedPathNameLabel, mainC);
mainC.gridy = 5;
mainC.insets = new Insets(20,240,10,240);
popUpPanel.add(close, mainC);
}
close.addActionListener(actionListener);
popUpFrame.add(popUpPanel);
popUpFrame.pack();
}
public static void closeWindow(){
popUpFrame.dispose();
}
}
/**
* EasyButton
*
* @author Adam Dale
*
*/
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
public class BatchEngine {
/**
* Method will use plink once to make sure we have at
* host key stored on the users system.
*
*/
public static void checkPlinkHostKey(){
FileWriter fstreamBatch;
try {
fstreamBatch = new FileWriter("PlinkHostKey.bat");
BufferedWriter outBatch = new BufferedWriter(fstreamBatch);
outBatch.write(
"regedit.exe /c /s "Plink Host
Keys.reg"n"+
"exitn"
);
outBatch.close();
String hostCommand = "cmd /C start /MIN PlinkHostKey.bat
";
Runtime hostRunTime = Runtime.getRuntime();
Process hostProcess = hostRunTime.exec(hostCommand);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Method creates batch job that will find the convID.
* @param flow
* @param envirVariable
* @param hostName
*/
public static void createConvIDLogBatch(String orderID, String
hostName, String envirVariable, String flow) {
try{
//Create the commands file that will be used by the batch
FileWriter fstreamCommands = new FileWriter("commands.txt");
BufferedWriter outCommands = new
BufferedWriter(fstreamCommands);
outCommands.write(
"cd /rn"+
"cd
sites/servers/"+hostName+envirVariable+flow+"/logsrn"+
"conv=`grep "+orderID+" dynamo.log | grep SetupAccount
| grep CONVERSATIONID |cut -c142-212`rn"+
"clearrn"+
"conv=${conv%%]*}rn"+
"echo $convrn"+
"grep "+orderID+" dynamo.log | grep automationrn"+
"cd csixmlsrn"+
"if [[ -n $conv ]]; then grep messageId `find
*FiberAddAccountServiceResponse.xml -type f -exec grep -l "$conv"
{} ;`; firn"+
//finds the ban for given convID
"if [[ -n $conv ]]; then grep accountNumber `find
*FiberInquireAccountDetailsServiceResponse.xml -type f -exec grep
-l "$conv" {} ;`; firn"+
//Debugging turned on
//"if [[ -n $conv ]]; then grep "$conv" dynamo.log |
grep AccountNumber ; firn"+
"exitrn"
);
outCommands.close();
// Create batch job to write with all hard coded commands
FileWriter fstreamBatch = new FileWriter("EasyConvID.bat");
BufferedWriter outBatch = new BufferedWriter(fstreamBatch);
outBatch.write(
"@echo offn" +
"setlocal EnableDelayedExpansionn"+
"goto :environmentn"+
"REM Select Environmentn"+
":environmentn"+
"set hostName=%1n"+
"set env=%2n"+
//"echo Host selected is %1n"+
"REM Select Flown"+
":flown"+
"if %3==A set flow=An"+
"if %3==B set flow=Bn"+
//"echo Envir selected is %2n"+
"REM Search for Ordern"+
":ordern"+
"set order=%4n"+
//"echo Flow is %3n"+
//"echo Order is %4n"+
"REM Open plink and execute proper scriptn"+
"plink -ssh -pw atgview atgview@%hostName%%env
%.edc.cingular.net <"commands.txt" >>"output.txt"n"+
"REM Takes the output file and finds the conv IDn"+
"echo Finished>>"results.txt"n"+
"echo Debugging Turned onrn"+
//"pausern"+
"exitn");
//Close the output stream
outBatch.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
/**
* Method takes the convID then process the BAN and xml files from
another batch job.
* @param convID
* @param messageID
*/
public static void createBanBatch(String convID, String messageID) {
// Create batch job to write with all hard coded commands
try {
FileWriter fstream = new FileWriter("EasyBan.bat");
BufferedWriter out = new BufferedWriter(fstream);
out.write(
"@echo offn" +
"setlocal EnableDelayedExpansionn"+
"set hostName=%1n"+
"set env=%2n"+
"if %3==A set flow=An"+
"if %3==B set flow=Bn"+
"REM Creates the list of commands to find
Conversation ID in txt filen"+
"echo cd / >>"commands2.txt"n"+
"echo cd sites/servers/%hostName%%env%%flow
%/logs/csixmls >>"commands2.txt"n"+
//Finds the Ban
//"echo grep accountNumber `find
*FiberInquireAccountDetailsServiceResponse.xml -type f -exec grep
-l "$conv" {} ;>>"commands2.txt"n"+
//"REM finds all xml files that have the convID in
itn"+
"REM finds the csixmls filesn"+
"echo find *Fiber*.xml -type f -exec grep
-l ""+convID+"" {} ;>>"commands2.txt"n"+
"echo find *FiberAddAccountServiceRequest.xml -type
f -exec grep -l ""+messageID+"" {} ;>>"commands2.txt"n"+
"echo exit >>"commands2.txt"n"+
"REM Open plink and execute proper scriptn"+
"plink -ssh -pw atgview atgview@%hostName%%env
%.edc.cingular.net <"commands2.txt" >>"output2.txt"n"+
"echo Finished BAN batch >>"results2.txt"n" +
"exitn"
);
out.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
/**
* Get the conversation ID
* @throws IOException
*
*/
public static String getConversationID() throws IOException{
String convID="";
BufferedReader line = new BufferedReader(new
FileReader("output.txt"));
while ((convID = line.readLine()) != null) {
if(convID.contains("buyonline")){
line.close();
return convID;
}
}
line.close();
return "";
}
/**
* Get the account Number
* @throws IOException
*
*/
public static String getAccountNumber() throws IOException{
String accountNumber="";
BufferedReader line = new BufferedReader(new
FileReader("output.txt"));
while ((accountNumber = line.readLine()) != null) {
if(accountNumber.contains("<accountNumber>")){
line.close();
return accountNumber.substring(15, 24);
}
}
line.close();
return "";
}
/**
* Get the automation results to display to user
* @param convIDStr
* @throws IOException
*
*/
public static String getAutomationResults(String convIDStr) throws
IOException{
String autoLine="", autoResults="";
BufferedReader autoLineBuf = new BufferedReader(new
FileReader("output.txt"));
while ((autoLine = autoLineBuf.readLine()) != null) {
//Add extra space where needed
if(autoLine.contains("Executing")){
autoLine=autoLine.substring(0,autoLine.indexOf("Executing"))+"
"+autoLine.substring(autoLine.indexOf("Executing"));
}
//Remove out the conversation ID we have this and it
causes clutter
if(autoLine.contains(convIDStr)&&
autoLine.length()>convIDStr.length() && !convIDStr.equals("")){
autoLine=autoLine.substring(0,
autoLine.indexOf("[Order:")
+17)+autoLine.substring(autoLine.indexOf(convIDStr)+convIDStr.length());
}
if(autoLine.contains("/automation/")){
autoResults+=autoLine.substring(autoLine.indexOf("PST")-
20,autoLine.indexOf("PST"))
+autoLine.substring(autoLine.indexOf("[Order"),autoLine.length())
+"rn";
}
}
autoLineBuf.close();
return autoResults;
}
/**
* Get the automation results to display in text, this will include
all data found
* @param convIDStr
* @throws IOException
*
*/
public static String getAutomationResultsForText() throws
IOException{
String autoLine="", autoResults="";
BufferedReader autoLineBuf = new BufferedReader(new
FileReader("output.txt"));
while ((autoLine = autoLineBuf.readLine()) != null) {
if(autoLine.contains("/automation/")){
autoResults+=autoLine+"rn";
}
}
autoLineBuf.close();
return autoResults;
}
/**
* Go ahead and copy the files found over to the users host computer
*
* @param ftpFileList
* @param flow
* @param flow2
* @param envirVarable
*/
public static void getFtpFiles(ArrayList<String> ftpFileList,
String hostName, String envir, String flow) {
// TODO Auto-generated method stub
try {
//Create the batch that will copy over the files
FileWriter fstream = new FileWriter("EasyFtpFileCopy.bat");
BufferedWriter out = new BufferedWriter(fstream);
out.write("@echo offn" +
"setlocal EnableDelayedExpansionn"+
"echo cd />>"ftpCommands.txt"n"+
"echo cd
sites/servers/"+hostName+envir+flow+"/logs/csixmls>>"ftpCommands.txt"
n");
for(int i=0; i< ftpFileList.size(); i++){
out.write("echo get "+ftpFileList.get(i)
+">>"ftpCommands.txt"n");
}
out.write("echo bye>>"ftpCommands.txt"n"+
"PSFTP -l atgview -pw atgview
"+hostName+envir+".edc.cingular.net -b ftpCommands.txtn"+
"echo Finished ftp batch >>"results3.txt"n"
+
"exitn"
);
out.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
}

More Related Content

TXT
Test
DOCX
Student management system
PDF
Tests unitaires mock_kesako_20130516
PDF
COScheduler In Depth
PPTX
The uniform interface is 42
PDF
Server1
DOCX
201913046 wahyu septiansyah network programing
PDF
Construire une application JavaFX 8 avec gradle
Test
Student management system
Tests unitaires mock_kesako_20130516
COScheduler In Depth
The uniform interface is 42
Server1
201913046 wahyu septiansyah network programing
Construire une application JavaFX 8 avec gradle

What's hot (20)

PDF
#JavaFX.forReal() - ElsassJUG
PDF
Clean Test Code
PDF
Android TDD
PDF
Redux for ReactJS Programmers
PPT
2012 JDays Bad Tests Good Tests
KEY
Unit testing en iOS @ MobileCon Galicia
PDF
Android Design Patterns
PDF
Unit Testing: Special Cases
TXT
Notepad
PDF
Software Testing - Invited Lecture at UNSW Sydney
PDF
知っておきたいSpring Batch Tips
PDF
Hidden rocks in Oracle ADF
PPTX
NetBeans Plugin Development: JRebel Experience Report
PDF
JS and patterns
PDF
33rd Degree 2013, Bad Tests, Good Tests
PDF
Introduction to web programming for java and c# programmers by @drpicox
DOCX
VISUALIZAR REGISTROS EN UN JTABLE
PDF
Migrating from Flux to Redux. Why and how.
PDF
GMock framework
#JavaFX.forReal() - ElsassJUG
Clean Test Code
Android TDD
Redux for ReactJS Programmers
2012 JDays Bad Tests Good Tests
Unit testing en iOS @ MobileCon Galicia
Android Design Patterns
Unit Testing: Special Cases
Notepad
Software Testing - Invited Lecture at UNSW Sydney
知っておきたいSpring Batch Tips
Hidden rocks in Oracle ADF
NetBeans Plugin Development: JRebel Experience Report
JS and patterns
33rd Degree 2013, Bad Tests, Good Tests
Introduction to web programming for java and c# programmers by @drpicox
VISUALIZAR REGISTROS EN UN JTABLE
Migrating from Flux to Redux. Why and how.
GMock framework
Ad

Viewers also liked (7)

PPT
Portfolio_Mukesh Kumar
DOC
ETM Server Program v1.0
DOC
Mus feature wider release - 06.07.15
PPTX
I-10 Calcasieu River Bridge Project
DOCX
RWC Trophy Tour Comms Plan
DOC
Rel - George Lamb feature 04.03.16
PPT
theScore, Inc. Q4 F2016 Conference Call Presentation
Portfolio_Mukesh Kumar
ETM Server Program v1.0
Mus feature wider release - 06.07.15
I-10 Calcasieu River Bridge Project
RWC Trophy Tour Comms Plan
Rel - George Lamb feature 04.03.16
theScore, Inc. Q4 F2016 Conference Call Presentation
Ad

Similar to Easy Button (20)

PDF
You are to simulate a dispatcher using a priority queue system in C+.pdf
PDF
JJUG CCC 2011 Spring
PDF
Write a GUI application to simulate writing out a check. The value o.pdf
PDF
In Java Write a GUI application to simulate writing out a check. The.pdf
PDF
Google guava
DOCX
ETM Server
PPT
Unit testing with mock libs
PDF
package net.codejava.swing.mail;import java.awt.Font;import java.pdf
PDF
AJUG April 2011 Cascading example
PDF
How do I make my JTable non editableimport java.awt.; import j.pdf
PDF
Main class --------------------------import java.awt.FlowLayout.pdf
PPTX
What’s new in C# 6
PDF
Simple Calculator using JavaFx a part of Advance Java
PDF
Below is the question I need help with. It need to be done in Java. .pdf
PDF
Griffon @ Svwjug
PDF
JEEConf 2017 - Having fun with Javassist
PDF
Chat application in java using swing and socket programming.
DOCX
culadora cientifica en java
PDF
Vielseitiges In-Memory Computing mit Apache Ignite und Kubernetes
DOC
code for quiz in my sql
You are to simulate a dispatcher using a priority queue system in C+.pdf
JJUG CCC 2011 Spring
Write a GUI application to simulate writing out a check. The value o.pdf
In Java Write a GUI application to simulate writing out a check. The.pdf
Google guava
ETM Server
Unit testing with mock libs
package net.codejava.swing.mail;import java.awt.Font;import java.pdf
AJUG April 2011 Cascading example
How do I make my JTable non editableimport java.awt.; import j.pdf
Main class --------------------------import java.awt.FlowLayout.pdf
What’s new in C# 6
Simple Calculator using JavaFx a part of Advance Java
Below is the question I need help with. It need to be done in Java. .pdf
Griffon @ Svwjug
JEEConf 2017 - Having fun with Javassist
Chat application in java using swing and socket programming.
culadora cientifica en java
Vielseitiges In-Memory Computing mit Apache Ignite und Kubernetes
code for quiz in my sql

Easy Button

  • 1. /** * EasyButton * * @author Adam Dale * * */ import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class EasyGUI { private JFrame frame = new JFrame(); //Create all panel componants private JPanel mainPanel = new JPanel(); private JCheckBox orderHandoffCheck = new JCheckBox("Do you need orderHandoff?"); private JLabel enterOrderIDLabel = new JLabel("Please enter orderID: "); private JLabel enterEnvLabel = new JLabel("Please select which environment: "); private JLabel enterFlowLabel = new JLabel("Please slect which flow: "); private JLabel enterOrderLabel = new JLabel("Please slect which order type: "); //private JButton submit = new JButton("TEST"); private JButton submit = new JButton("!EASY!"); private static JTextField orderIDTextField = new JTextField(10); private static JCheckBox csixmlCheck = new JCheckBox("Do you need CSIXML files?"); private static String [] flowType = {"A","B"}; private static String [] envirType = {"FST1","FST2", "FST3", "FST5", "FST7", "DEV3"}; private static String [] orderType = {"Provide", "Modify"}; private static JComboBox flowTypeComboBox = new JComboBox(flowType); private static JComboBox envirTypeComboBox = new JComboBox(envirType); private static JComboBox orderTypeComboBox = new JComboBox(orderType); private EasyButton actionListener = new EasyButton(); public EasyGUI() { //Create frames and size for main program frame.setTitle("EasyButton Version 1.0.5.2"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  • 2. frame.setVisible(true); frame.setSize(400, 400); frame.setLocation(100,200); frame.setResizable(false); GridBagConstraints mainC = new GridBagConstraints(); mainPanel.setLayout(new GridBagLayout()); mainC.fill = GridBagConstraints.HORIZONTAL; mainC.gridx = 0; mainC.gridy = 0; mainPanel.add(enterEnvLabel, mainC); mainC.gridx = 2; mainC.gridy = 0; mainC.insets = new Insets(0,30,10,0); mainPanel.add(envirTypeComboBox, mainC); envirTypeComboBox.addActionListener(actionListener); mainC.gridx = 0; mainC.gridy = 1; mainC.insets = new Insets(0,0,10,0); mainPanel.add(enterFlowLabel, mainC); mainC.gridx = 2; mainC.gridy = 1; mainC.insets = new Insets(0,30,10,0); mainPanel.add(flowTypeComboBox, mainC); flowTypeComboBox.addActionListener(actionListener); mainC.gridx = 0; mainC.gridy = 2; mainC.insets = new Insets(0,0,10,0); mainPanel.add(enterOrderLabel, mainC); mainC.gridx = 2; mainC.gridy = 2; mainC.insets = new Insets(0,30,10,0); mainPanel.add(orderTypeComboBox, mainC); orderTypeComboBox.addActionListener(actionListener); mainC.gridx = 0; mainC.gridy = 3; mainC.insets = new Insets(0,0,10,0); mainPanel.add(enterOrderIDLabel, mainC); mainC.gridx = 2; mainC.gridy = 3; mainC.insets = new Insets(0,30,10,0); mainPanel.add(orderIDTextField, mainC); orderIDTextField.addActionListener(actionListener); mainC.gridx = 0; mainC.gridy = 4; mainC.insets = new Insets(0,0,10,0); mainPanel.add(csixmlCheck, mainC); //csixmlCheck.setSelected(true); csixmlCheck.addActionListener(actionListener); mainC.gridx = 2; mainC.gridy = 4; mainC.insets = new Insets(0,30,10,0); mainPanel.add(orderHandoffCheck, mainC);
  • 3. orderHandoffCheck.addActionListener(actionListener); mainC.gridx = 1; mainC.gridy = 5; mainC.fill = GridBagConstraints.CENTER; mainPanel.add(submit, mainC); submit.addActionListener(actionListener); //Finish frame layout frame.add(mainPanel); frame.pack(); frame.setVisible(true); } /** * Gets the value of the environment type. * @return */ public static String getEnvirTypeComboBox(){ return envirTypeComboBox.getSelectedItem().toString(); } /** * Gets the order ID value. * @return */ public static String getOrderIDTextField(){ return orderIDTextField.getText(); } /** * Sets the order ID fields based on text input. * @param text */ public static void setOrderIDTextField(String text){ orderIDTextField.setText(text); } /** * Gets the order type value. * * @return */ public static String getOrderTypeComboBox(){ return orderTypeComboBox.getSelectedItem().toString(); } /** * Gets the value of the Flow type. * * @return */ public static String getFlowTypeComboBox(){ return flowTypeComboBox.getSelectedItem().toString(); } /** * Gets the value of the CSIXML flag and returns * true or false. * @return */ public static boolean isCSIXMLSelected(){ if(csixmlCheck.isSelected()){ return true;
  • 4. } else { return false; } } } /** * EasyButton * * @author Adam Dale * */ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Timer; import java.util.TimerTask; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.JFrame; import javax.swing.JOptionPane; public class EasyButton extends JFrame implements ActionListener{ /** * serialVersionUID */ private static final long serialVersionUID = 1L; JFrame popUpFrame = new JFrame(); private String [] csixmlLabels= {"FiberAddAccountServiceRequest","FiberAddAccountServiceResponse", "FiberInquireAccountDetailsServiceRequest","FiberInquireAccountDeta ilsServiceResponse", "FiberInquireCrossProductPackagesServiceRequest","FiberInquireCross ProductPackagesServiceResponse", "FiberInquireProductDetailsServiceRequest","FiberInquireProductDeta ilsServiceResponse", "FiberValidateProductDetailsServiceRequest","FiberValidateProductDe tailsServiceResponse", "FiberInquireQuotationServiceRequestRequest","FiberInquireQuotation ServiceRequestResponse", "FInqAsgndProdDetailsServiceRequest", "FInqAsgndProdDetailsServiceResponse"}; private String totalResults, accountNumber="", orderID, fileName; private ArrayList<String> csixmlData; private ArrayList<String> ftpFileList;
  • 5. private File orderFolder; private int confirmResults =1; /** * Create main to show driver * @param args */ public static void main(String[] args) { new EasyGUI(); } public EasyButton() { //First check to make sure plink is setup and read File plinkRegKeys= new File("Plink Host Keys.reg"); File plinkHostBatch = new File("PlinkHostKey.bat"); if(plinkRegKeys.exists()){ JOptionPane.showMessageDialog(null, "Setup will configure now", "First Time Setup", JOptionPane.INFORMATION_MESSAGE); BatchEngine.checkPlinkHostKey(); //Perform cleanup //Give time to process try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } if(plinkHostBatch.exists()){ plinkHostBatch.delete(); } if(plinkRegKeys.exists()){ plinkRegKeys.delete(); } } } public void actionPerformed(ActionEvent arg0) { //Comment out for testing uses if(arg0.getActionCommand().equals("TEST")){ } if(arg0.getActionCommand().equals("Close")){ ShowPopUpWindow.closeWindow(); } if(arg0.getActionCommand().equals("!EASY!")){ //Lets make sure no frames are open popUpFrame.dispose(); boolean debugFlag = false; //Delete all files created once finished checkForExistingFiles(debugFlag); //Clear all variables
  • 6. accountNumber=""; totalResults=""; orderID=""; ftpFileList = new ArrayList<String>(); csixmlData = new ArrayList<String>(); String flow =EasyGUI.getFlowTypeComboBox(); String orderType = EasyGUI.getOrderTypeComboBox(); String autoResults = "", autoTechResults=""; //First do a check on the order number //Lets make sure its only digits at x length orderID = EasyGUI.getOrderIDTextField(); if(checkOrderIDFormat(orderID)){ //checkForExistingFiles(); // Get order id from user and pass it in here String envirVariable="", hostName=""; if(EasyGUI.getEnvirTypeComboBox().equals("FST1")){ envirVariable="1"; hostName="b2cfst"; } if(EasyGUI.getEnvirTypeComboBox().equals("FST2")){ envirVariable="2"; hostName="b2cfst"; } if(EasyGUI.getEnvirTypeComboBox().equals("FST3")){ envirVariable="3"; hostName="b2cfst"; } if(EasyGUI.getEnvirTypeComboBox().equals("FST5")){ envirVariable="5"; hostName="b2cfst"; } if(EasyGUI.getEnvirTypeComboBox().equals("FST7")){ envirVariable="7"; hostName="b2cfst"; } if(EasyGUI.getEnvirTypeComboBox().equals("DEV3")){ envirVariable="03"; hostName="b2cimp"; } BatchEngine.createConvIDLogBatch(orderID, hostName, envirVariable, flow); try { //NOTE //When placing commands for batch params are only seprated by space and may not go past 9. String convIDCommand = "cmd /C start /MIN EasyConvID.bat " +hostName +" "+envirVariable +" "+flow +" "+orderID; Runtime convIDRunTime = Runtime.getRuntime(); Process convIDProcess =
  • 7. convIDRunTime.exec(convIDCommand); //Call special timer here if this process is running for more //than 60 seconds kill it. startTimeOutSession(60); int convIDPause=0; int banPause=0; int ftpPause=0; File convIDResults = new File("results.txt"); File banResults = new File("results2.txt"); File ftpResults = new File("results3.txt"); String convIDStr=""; while (convIDPause==0) { if(convIDResults.exists()){ convIDProcess.destroy(); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } convIDStr=BatchEngine.getConversationID(); autoResults=BatchEngine.getAutomationResults(convIDStr); //special automation call for Jira tickets and developers to debug autoTechResults=BatchEngine.getAutomationResultsForText(); convIDPause=1; } } //Check to make sure system did not run to fast System.out.println("Conversation ID grab is "+convIDStr); if(convIDStr.equals("ECHO is off.")|| convIDStr.equals("")){ ShowPopUpWindow.showPopUp(orderID,"Not Found","Not Found","nCSIXMLS Found:nN/A",autoResults, "", null); EasyGUI.setOrderIDTextField(""); } else { accountNumber=BatchEngine.getAccountNumber(); //Run second batch job if(EasyGUI.isCSIXMLSelected()){ BatchEngine.createBanBatch(convIDStr, getMessageID()); String banCommand = "cmd /C start /MIN
  • 8. EasyBan.bat " +hostName +" "+envirVariable +" "+flow +" "+orderID; Runtime banRunTime = Runtime.getRuntime(); Process banProcess = banRunTime.exec(banCommand); //Create a timer to wait for x amount of time before killing process //This will fix hang in system, if error found in plink csixmlData.clear(); while (banPause==0){ if(banResults.exists()){ banProcess.destroy(); banResults.delete(); //Start reading in output to get BAN and CSIXML BufferedReader line = new BufferedReader(new FileReader("output2.txt")); String bufBanStr; String fiberAddAccountServiceResponse="",fiberAddAccountServiceRequest=""; String fiberInquireAccountDetailsServiceResponse="",fiberInquireAccountDetails ServiceRequest=""; String fiberInquireCrossProductPackagesServiceResponse="", fiberInquireCrossProductPackagesServiceRequest=""; String fiberInquireProductDetailsServiceResponse="",fiberInquireProductDetails ServiceRequest=""; String fiberValidateProductDetailsServiceResponse="",fiberValidateProductDetai lsServiceRequest=""; String fiberInquireQuotationServiceResponse="",fiberInquireQuotationServiceReq uest=""; String fInqAsgndProdDetailsServiceResponse="",fInqAsgndProdDetailsServiceReque st=""; while ((bufBanStr = line.readLine()) != null) { if(bufBanStr.contains("FiberAddAccountServiceResponse")){ fiberAddAccountServiceResponse=bufBanStr; } if(bufBanStr.contains("FiberAddAccountServiceRequest")){ fiberAddAccountServiceRequest=bufBanStr; }
  • 9. if(bufBanStr.contains("FiberInquireAccountDetailsServiceResponse")){ fiberInquireAccountDetailsServiceResponse=bufBanStr; } if(bufBanStr.contains("FiberInquireAccountDetailsServiceRequest")){ fiberInquireAccountDetailsServiceRequest=bufBanStr; } if(bufBanStr.contains("FiberInquireCrossProductPackagesServiceResponse" )){ fiberInquireCrossProductPackagesServiceResponse=bufBanStr; } if(bufBanStr.contains("FiberInquireCrossProductPackagesServiceRequest") ){ fiberInquireCrossProductPackagesServiceRequest=bufBanStr; } if(bufBanStr.contains("FiberInquireProductDetailsServiceResponse")){ fiberInquireProductDetailsServiceResponse=bufBanStr; } if(bufBanStr.contains("FiberInquireProductDetailsServiceRequest")){ fiberInquireProductDetailsServiceRequest=bufBanStr; } if(bufBanStr.contains("FiberValidateProductDetailsServiceResponse")){ fiberValidateProductDetailsServiceResponse=bufBanStr; } if(bufBanStr.contains("FiberValidateProductDetailsServiceRequest")){ fiberValidateProductDetailsServiceRequest=bufBanStr; } if(bufBanStr.contains("FiberInquireQuotationServiceResponse")){ fiberInquireQuotationServiceResponse=bufBanStr; } if(bufBanStr.contains("FiberInquireQuotationServiceRequest")){ fiberInquireQuotationServiceRequest=bufBanStr; } if(bufBanStr.contains("FInqAsgndProdDetailsServiceResponse")){
  • 10. fInqAsgndProdDetailsServiceResponse=bufBanStr; } if(bufBanStr.contains("FInqAsgndProdDetailsServiceRequest")){ fInqAsgndProdDetailsServiceRequest=bufBanStr; } } if(orderType.equals("Provide")){ csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberAddAccountServiceRe sponse, 1)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberAddAccountServiceRe quest, 0)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireAccountDetai lsServiceResponse, 3)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireAccountDetai lsServiceRequest, 2)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireCrossProduct PackagesServiceResponse, 5)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireCrossProduct PackagesServiceRequest, 4)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireProductDetai lsServiceResponse,7)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireProductDetai lsServiceRequest, 6)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberValidateProductDeta ilsServiceResponse,9)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberValidateProductDeta ilsServiceRequest,8)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireQuotationSer viceResponse,11)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireQuotationSer viceRequest,10)); } else { csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireAccountDetai lsServiceResponse, 3)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireAccountDetai lsServiceRequest, 2));
  • 11. csixmlData.add(checkLogForEmptyCSIXMLFileNames(fInqAsgndProdDetailsServ iceResponse,13)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fInqAsgndProdDetailsServ iceRequest,12)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberValidateProductDeta ilsServiceResponse,9)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberValidateProductDeta ilsServiceRequest,8)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireQuotationSer viceResponse,11)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireQuotationSer viceRequest,10)); } totalResults=gatherResults(csixmlData); banPause=1; line.close(); } } confirmResults = JOptionPane.showConfirmDialog(null,"Would you like the xml files copied to your system?n","Copy Results",JOptionPane.YES_NO_OPTION); } if(totalResults==null){ totalResults="CSIXMLSrnN/A"; } //Create directory for results found an put text file in that folder orderFolder = new File(orderID); if(orderFolder.exists()){ orderFolder.delete(); } else{ orderFolder.mkdir(); } fileName="Order ID "+orderID+".txt"; FileWriter fstream = new FileWriter(orderFolder+"/"+fileName); BufferedWriter out = new BufferedWriter(fstream); out.write("Conversation ID is:"+" "+convIDStr +"rnBan is: "+accountNumber +"rnOrder is: "+orderID +"rn"+totalResults +"rnrnrnAUTOMATION RESULTS:rnrn"+autoTechResults );
  • 12. out.close(); if(confirmResults==0){ for(int i=0; i<csixmlData.size();i++){ if(!csixmlData.get(i).contains("File Not Found")){ ftpFileList.add(csixmlData.get(i)); } } //Before we run batch job check for old files and delete to make room for new files for(int i=0; i<ftpFileList.size();i++) { deleteFiles(ftpFileList.get(i), orderFolder); } //Create the batch job for files found BatchEngine.getFtpFiles(ftpFileList, hostName, envirVariable, flow); //Run batch job String ftpCommand = "cmd /C start /MIN EasyFtpFileCopy.bat "; Runtime ftpRunTime = Runtime.getRuntime(); Process ftpProcess = ftpRunTime.exec(ftpCommand); //Move files to correct directory while (ftpPause==0) { if(ftpResults.exists()){ ftpProcess.destroy(); for(int i=0; i<ftpFileList.size();i++) { moveFiles(ftpFileList.get(i), orderFolder); } JOptionPane.showMessageDialog(null, "Your files have been copied", "Finished", JOptionPane.INFORMATION_MESSAGE); ftpPause+=1; } } } ShowPopUpWindow.showPopUp(orderID, convIDStr, accountNumber,totalResults, autoResults, fileName.toString(), orderFolder); //Delete all files created once finished checkForExistingFiles(debugFlag); EasyGUI.setOrderIDTextField(""); } } catch (IOException e) { // Catch error and print stack e.printStackTrace(); }
  • 13. //End if statement for digit check } //End if statement for listener } } /** * Method takes the command and executes the process by * creating a generic runtime and process to execute. * @param command */ private void runBatchJob(String command){ Runtime genericRuntime = Runtime.getRuntime(); try { Process genericProcess = genericRuntime.exec(command); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * Check for existing xml files and delete * @param fileName * @param orderFolder */ private void deleteFiles(String filename, File folder) { // Check for file in folder File checkFile = new File(folder+"/"+filename); if(checkFile.exists()){ checkFile.delete(); } } /** * Take all the xml files and move them to the correct folders * @param fileName * @param orderFolder */ private void moveFiles(String fileName, File folder) { // File (or directory) to be moved File file = new File(fileName); // Move file to new directory file.renameTo(new File(folder, file.getName())); } /** * Check to make sure Order is in the correct format * @param orderID2 * @return */ private boolean checkOrderIDFormat(String orderID2) { Pattern digitPattern = Pattern.compile("d+"); Matcher digitMatcher = digitPattern.matcher(orderID2); if(orderID2.length()!=10){ JOptionPane.showMessageDialog(null, "Please enter correct
  • 14. order number lenght.nEx. 5777870132", "Format Error", JOptionPane.ERROR_MESSAGE); return false; } if(!digitMatcher.matches()){ JOptionPane.showMessageDialog(null, "Please enter digits only.nEx. 5777870132", "Format Error", JOptionPane.ERROR_MESSAGE); return false; } //Everything looks ok return true. return true; } /** * Get all results * @param csixmlData2 */ private String gatherResults(ArrayList<String> csixmlData2) { //Get all results and format. String results="rnrnCSIXML RESULTS:rnrn"; for(int i=0; i<csixmlData2.size();i++){ results+=csixmlData2.get(i)+" rn"; } return results; } /** * Check for existing files and then delete them if they exist. */ public void checkForExistingFiles(Boolean debug) { File result1Text = new File("results.txt"); File result2Text = new File("results2.txt"); File result3Text = new File("results3.txt"); File command1Text = new File("commands.txt"); File command2Text = new File("commands2.txt"); File command3Text = new File("ftpCommands.txt"); File output1Text = new File("output.txt"); File output2Text = new File("output2.txt"); File bat1File = new File("EasyConvID.bat"); File bat2File = new File("EasyBan.bat"); File bat3File = new File("EasyFtpFileCopy.bat"); if(!debug){ if(result1Text.exists()){ result1Text.delete(); } if(result2Text.exists()){ result2Text.delete(); } if(result3Text.exists()){ result3Text.delete(); } if(bat1File.exists()){ bat1File.delete(); } if(bat2File.exists()){
  • 15. bat2File.delete(); } if(bat3File.exists()){ bat3File.delete(); } if(command1Text.exists()){ command1Text.delete(); } if(command2Text.exists()){ command2Text.delete(); } if(command3Text.exists()){ command3Text.delete(); } if(output1Text.exists()){ output1Text.delete(); } if(output2Text.exists()){ output2Text.delete(); } } } /** * Read in the message ID for other batch files * @return */ public static String getMessageID(){ String messageIDFound=""; try { FileReader input = new FileReader("output.txt"); BufferedReader line = new BufferedReader(input); String messageIDStr; while ((messageIDStr = line.readLine()) != null) { //Strip out the message id if(messageIDStr.contains("<cng:messageId>")){ messageIDFound = messageIDStr.split("</cng:messageId>")[0].split("<cng:messageId>")[1]; //messageIDFound= messageIDFound.substring(0, messageIDFound.length()-6); } } input.close(); line.close(); }catch (IOException e) { } return messageIDFound; } /** * Check to see if file found if not display error */ public String checkLogForEmptyCSIXMLFileNames(String xml, int
  • 16. nameTagID){ if(xml.equals("")){ xml="File Not Found............................. "+csixmlLabels[nameTagID]; } return xml; } /** * Will start a timer to kill process after x amount of time * @param convIDProcess * @return */ public void startTimeOutSession(int sessionTimeout){ Timer timer = new Timer(); timer.schedule(new TimerTask(){ public void run(){ System.out.println("This process is killed."); String killCommand = "cmd /C taskkill /F /IM plink.exe "; Runtime convIDRunTime = Runtime.getRuntime(); try { Process convIDProcess = convIDRunTime.exec(killCommand); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } },sessionTimeout*1000); } } import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.io.File; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.UIManager; /** * EasyButton * * @author Adam Dale * */ public class ShowPopUpWindow {
  • 17. private static JFrame popUpFrame; private static EasyButton actionListener = new EasyButton(); public ShowPopUpWindow(){ } /** * Creates the results window based on what was returned from search * @param string */ public static void showPopUp(String orderID, String convID, String ban, String csixml, String auto, String fileName, File orderFolder) { // TODO Auto-generated method stub popUpFrame = new JFrame(); JTextArea resultsArea = new JTextArea(17, 50); JScrollPane scrollPane = new JScrollPane(resultsArea); JTextArea autoResultsArea = new JTextArea(10, 25); JScrollPane autoScrollPane = new JScrollPane(autoResultsArea); JPanel popUpPanel = new JPanel(); JButton close = new JButton("Close"); //Only if something was found will we print this label JLabel savedFileLabel, savedPathLabel, savedPathNameLabel; popUpFrame.setTitle("Results Found"); popUpFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); popUpFrame.setVisible(true); popUpFrame.setSize(200, 200); popUpFrame.setLocation(100,25); popUpFrame.setResizable(false); //Configure text here resultsArea.setText("Order ID: "+orderID+"n" +"Conversation ID: "+convID+"n" +"Ban: "+ban+"n" +csixml ); resultsArea.setEditable(false); resultsArea.setBorder(null); resultsArea.setForeground(UIManager.getColor("Label.foreground")); //resultsArea.setBackground(getBackground()); resultsArea.setFont(UIManager.getFont("Label.font")); resultsArea.setCaretPosition(0); //Configure auto text here autoResultsArea.setText("AUTOMATION RESULTS: nn"+auto); autoResultsArea.setEditable(false); autoResultsArea.setBorder(null); autoResultsArea.setForeground(UIManager.getColor("Label.foreground")); //autoResultsArea.setBackground(getBackground());
  • 18. autoResultsArea.setFont(UIManager.getFont("Label.font")); autoResultsArea.setCaretPosition(0); GridBagConstraints mainC = new GridBagConstraints(); popUpPanel.setLayout(new GridBagLayout()); mainC.fill = GridBagConstraints.HORIZONTAL; mainC.gridx = 0; mainC.gridy = 0; popUpPanel.add(scrollPane, mainC); mainC.gridy = 1; mainC.insets = new Insets(20,0,0,0); popUpPanel.add(autoScrollPane, mainC); mainC.insets = new Insets(0,0,0,0); if(convID.equals("Not Found")){ mainC.gridy = 2; mainC.insets = new Insets(20,240,10,240); popUpPanel.add(close, mainC); } else { mainC.gridy = 2; mainC.insets = new Insets(10,0,0,0); savedFileLabel = new JLabel("Your results have been saved as ""+fileName+"""); popUpPanel.add(savedFileLabel, mainC); mainC.insets = new Insets(0,0,0,0); mainC.gridy = 3; savedPathLabel= new JLabel("All files have been saved to: "); popUpPanel.add(savedPathLabel, mainC); mainC.gridy = 4; savedPathNameLabel= new JLabel(orderFolder.getAbsolutePath()); popUpPanel.add(savedPathNameLabel, mainC); mainC.gridy = 5; mainC.insets = new Insets(20,240,10,240); popUpPanel.add(close, mainC); } close.addActionListener(actionListener); popUpFrame.add(popUpPanel); popUpFrame.pack(); } public static void closeWindow(){ popUpFrame.dispose(); } } /** * EasyButton *
  • 19. * @author Adam Dale * */ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; public class BatchEngine { /** * Method will use plink once to make sure we have at * host key stored on the users system. * */ public static void checkPlinkHostKey(){ FileWriter fstreamBatch; try { fstreamBatch = new FileWriter("PlinkHostKey.bat"); BufferedWriter outBatch = new BufferedWriter(fstreamBatch); outBatch.write( "regedit.exe /c /s "Plink Host Keys.reg"n"+ "exitn" ); outBatch.close(); String hostCommand = "cmd /C start /MIN PlinkHostKey.bat "; Runtime hostRunTime = Runtime.getRuntime(); Process hostProcess = hostRunTime.exec(hostCommand); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * Method creates batch job that will find the convID. * @param flow * @param envirVariable * @param hostName */ public static void createConvIDLogBatch(String orderID, String hostName, String envirVariable, String flow) { try{ //Create the commands file that will be used by the batch FileWriter fstreamCommands = new FileWriter("commands.txt"); BufferedWriter outCommands = new BufferedWriter(fstreamCommands);
  • 20. outCommands.write( "cd /rn"+ "cd sites/servers/"+hostName+envirVariable+flow+"/logsrn"+ "conv=`grep "+orderID+" dynamo.log | grep SetupAccount | grep CONVERSATIONID |cut -c142-212`rn"+ "clearrn"+ "conv=${conv%%]*}rn"+ "echo $convrn"+ "grep "+orderID+" dynamo.log | grep automationrn"+ "cd csixmlsrn"+ "if [[ -n $conv ]]; then grep messageId `find *FiberAddAccountServiceResponse.xml -type f -exec grep -l "$conv" {} ;`; firn"+ //finds the ban for given convID "if [[ -n $conv ]]; then grep accountNumber `find *FiberInquireAccountDetailsServiceResponse.xml -type f -exec grep -l "$conv" {} ;`; firn"+ //Debugging turned on //"if [[ -n $conv ]]; then grep "$conv" dynamo.log | grep AccountNumber ; firn"+ "exitrn" ); outCommands.close(); // Create batch job to write with all hard coded commands FileWriter fstreamBatch = new FileWriter("EasyConvID.bat"); BufferedWriter outBatch = new BufferedWriter(fstreamBatch); outBatch.write( "@echo offn" + "setlocal EnableDelayedExpansionn"+ "goto :environmentn"+ "REM Select Environmentn"+ ":environmentn"+ "set hostName=%1n"+ "set env=%2n"+ //"echo Host selected is %1n"+ "REM Select Flown"+ ":flown"+ "if %3==A set flow=An"+ "if %3==B set flow=Bn"+ //"echo Envir selected is %2n"+ "REM Search for Ordern"+ ":ordern"+ "set order=%4n"+ //"echo Flow is %3n"+ //"echo Order is %4n"+ "REM Open plink and execute proper scriptn"+ "plink -ssh -pw atgview atgview@%hostName%%env %.edc.cingular.net <"commands.txt" >>"output.txt"n"+ "REM Takes the output file and finds the conv IDn"+ "echo Finished>>"results.txt"n"+ "echo Debugging Turned onrn"+ //"pausern"+ "exitn"); //Close the output stream outBatch.close();
  • 21. }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } /** * Method takes the convID then process the BAN and xml files from another batch job. * @param convID * @param messageID */ public static void createBanBatch(String convID, String messageID) { // Create batch job to write with all hard coded commands try { FileWriter fstream = new FileWriter("EasyBan.bat"); BufferedWriter out = new BufferedWriter(fstream); out.write( "@echo offn" + "setlocal EnableDelayedExpansionn"+ "set hostName=%1n"+ "set env=%2n"+ "if %3==A set flow=An"+ "if %3==B set flow=Bn"+ "REM Creates the list of commands to find Conversation ID in txt filen"+ "echo cd / >>"commands2.txt"n"+ "echo cd sites/servers/%hostName%%env%%flow %/logs/csixmls >>"commands2.txt"n"+ //Finds the Ban //"echo grep accountNumber `find *FiberInquireAccountDetailsServiceResponse.xml -type f -exec grep -l "$conv" {} ;>>"commands2.txt"n"+ //"REM finds all xml files that have the convID in itn"+ "REM finds the csixmls filesn"+ "echo find *Fiber*.xml -type f -exec grep -l ""+convID+"" {} ;>>"commands2.txt"n"+ "echo find *FiberAddAccountServiceRequest.xml -type f -exec grep -l ""+messageID+"" {} ;>>"commands2.txt"n"+ "echo exit >>"commands2.txt"n"+ "REM Open plink and execute proper scriptn"+ "plink -ssh -pw atgview atgview@%hostName%%env %.edc.cingular.net <"commands2.txt" >>"output2.txt"n"+ "echo Finished BAN batch >>"results2.txt"n" + "exitn" ); out.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } /** * Get the conversation ID * @throws IOException
  • 22. * */ public static String getConversationID() throws IOException{ String convID=""; BufferedReader line = new BufferedReader(new FileReader("output.txt")); while ((convID = line.readLine()) != null) { if(convID.contains("buyonline")){ line.close(); return convID; } } line.close(); return ""; } /** * Get the account Number * @throws IOException * */ public static String getAccountNumber() throws IOException{ String accountNumber=""; BufferedReader line = new BufferedReader(new FileReader("output.txt")); while ((accountNumber = line.readLine()) != null) { if(accountNumber.contains("<accountNumber>")){ line.close(); return accountNumber.substring(15, 24); } } line.close(); return ""; } /** * Get the automation results to display to user * @param convIDStr * @throws IOException * */ public static String getAutomationResults(String convIDStr) throws IOException{ String autoLine="", autoResults=""; BufferedReader autoLineBuf = new BufferedReader(new FileReader("output.txt")); while ((autoLine = autoLineBuf.readLine()) != null) { //Add extra space where needed if(autoLine.contains("Executing")){ autoLine=autoLine.substring(0,autoLine.indexOf("Executing"))+" "+autoLine.substring(autoLine.indexOf("Executing")); } //Remove out the conversation ID we have this and it
  • 23. causes clutter if(autoLine.contains(convIDStr)&& autoLine.length()>convIDStr.length() && !convIDStr.equals("")){ autoLine=autoLine.substring(0, autoLine.indexOf("[Order:") +17)+autoLine.substring(autoLine.indexOf(convIDStr)+convIDStr.length()); } if(autoLine.contains("/automation/")){ autoResults+=autoLine.substring(autoLine.indexOf("PST")- 20,autoLine.indexOf("PST")) +autoLine.substring(autoLine.indexOf("[Order"),autoLine.length()) +"rn"; } } autoLineBuf.close(); return autoResults; } /** * Get the automation results to display in text, this will include all data found * @param convIDStr * @throws IOException * */ public static String getAutomationResultsForText() throws IOException{ String autoLine="", autoResults=""; BufferedReader autoLineBuf = new BufferedReader(new FileReader("output.txt")); while ((autoLine = autoLineBuf.readLine()) != null) { if(autoLine.contains("/automation/")){ autoResults+=autoLine+"rn"; } } autoLineBuf.close(); return autoResults; } /** * Go ahead and copy the files found over to the users host computer * * @param ftpFileList * @param flow * @param flow2 * @param envirVarable */ public static void getFtpFiles(ArrayList<String> ftpFileList, String hostName, String envir, String flow) {
  • 24. // TODO Auto-generated method stub try { //Create the batch that will copy over the files FileWriter fstream = new FileWriter("EasyFtpFileCopy.bat"); BufferedWriter out = new BufferedWriter(fstream); out.write("@echo offn" + "setlocal EnableDelayedExpansionn"+ "echo cd />>"ftpCommands.txt"n"+ "echo cd sites/servers/"+hostName+envir+flow+"/logs/csixmls>>"ftpCommands.txt" n"); for(int i=0; i< ftpFileList.size(); i++){ out.write("echo get "+ftpFileList.get(i) +">>"ftpCommands.txt"n"); } out.write("echo bye>>"ftpCommands.txt"n"+ "PSFTP -l atgview -pw atgview "+hostName+envir+".edc.cingular.net -b ftpCommands.txtn"+ "echo Finished ftp batch >>"results3.txt"n" + "exitn" ); out.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } }