Easy Button

download Easy Button

If you can't read please download the document

Transcript of Easy Button

/** * 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","FiberInquireAccountDetailsServiceResponse","FiberInquireCrossProductPackagesServiceRequest","FiberInquireCrossProductPackagesServiceResponse","FiberInquireProductDetailsServiceRequest","FiberInquireProductDetailsServiceResponse","FiberValidateProductDetailsServiceRequest","FiberValidateProductDetailsServiceResponse","FiberInquireQuotationServiceRequestRequest","FiberInquireQuotationServiceRequestResponse","FInqAsgndProdDetailsServiceRequest", "FInqAsgndProdDetailsServiceResponse"};private String totalResults, accountNumber="", orderID, fileName;private ArrayList csixmlData;private ArrayList 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 readFile 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 processtry {Thread.sleep(1000);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}if(plinkHostBatch.exists()){plinkHostBatch.delete();}

if(plinkRegKeys.exists()){plinkRegKeys.delete();}}}

public void actionPerformed(ActionEvent arg0) {

//Comment out for testing usesif(arg0.getActionCommand().equals("TEST")){}if(arg0.getActionCommand().equals("Close")){ShowPopUpWindow.closeWindow();}if(arg0.getActionCommand().equals("!EASY!")){ //Lets make sure no frames are openpopUpFrame.dispose();boolean debugFlag = false;//Delete all files created once finishedcheckForExistingFiles(debugFlag);//Clear all variablesaccountNumber="";totalResults="";orderID="";

ftpFileList = new ArrayList();csixmlData = new ArrayList();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 lengthorderID = EasyGUI.getOrderIDTextField();if(checkOrderIDFormat(orderID)){//checkForExistingFiles();// Get order id from user and pass it in hereString 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 debugautoTechResults=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="",fiberInquireAccountDetailsServiceRequest=""; String fiberInquireCrossProductPackagesServiceResponse="", fiberInquireCrossProductPackagesServiceRequest=""; String fiberInquireProductDetailsServiceResponse="",fiberInquireProductDetailsServiceRequest=""; String fiberValidateProductDetailsServiceResponse="",fiberValidateProductDetailsServiceRequest=""; String fiberInquireQuotationServiceResponse="",fiberInquireQuotationServiceRequest=""; String fInqAsgndProdDetailsServiceResponse="",fInqAsgndProdDetailsServiceRequest=""; 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(fiberAddAccountServiceResponse, 1)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberAddAccountServiceRequest, 0)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireAccountDetailsServiceResponse, 3)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireAccountDetailsServiceRequest, 2)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireCrossProductPackagesServiceResponse, 5)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireCrossProductPackagesServiceRequest, 4)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireProductDetailsServiceResponse,7)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireProductDetailsServiceRequest, 6)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberValidateProductDetailsServiceResponse,9)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberValidateProductDetailsServiceRequest,8)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireQuotationServiceResponse,11)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireQuotationServiceRequest,10)); } else { csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireAccountDetailsServiceResponse, 3)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireAccountDetailsServiceRequest, 2)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fInqAsgndProdDetailsServiceResponse,13)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fInqAsgndProdDetailsServiceRequest,12)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberValidateProductDetailsServiceResponse,9)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberValidateProductDetailsServiceRequest,8)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireQuotationServiceResponse,11)); csixmlData.add(checkLogForEmptyCSIXMLFileNames(fiberInquireQuotationServiceRequest,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="CSIXMLS\r\nN/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 +"\r\nBan is: "+accountNumber +"\r\nOrder is: "+orderID +"\r\n"+totalResults +"\r\n\r\n\r\nAUTOMATION RESULTS:\r\n\r\n"+autoTechResults);out.close(); if(confirmResults==0){

for(int i=0; iconvIDStr.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())+"\r\n"; }

} 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+"\r\n"; } } 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 ftpFileList, String hostName, String envir, String flow) {// TODO Auto-generated method stubtry {

//Create the batch that will copy over the filesFileWriter fstream = new FileWriter("EasyFtpFileCopy.bat");BufferedWriter out = new BufferedWriter(fstream);out.write("@echo off\n" + "setlocal EnableDelayedExpansion\n"+ "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.txt\n"+ "echo Finished ftp batch >>\"results3.txt\"\n"+ "exit\n" );out.close();}catch (Exception e){ System.err.println("Error: " + e.getMessage());}}}