etm server

54
/** * TIMS ETM Server * * @author Adam Dale * * This program will take a set of configuration options and set up a VM or Local to * run a instance of the ETM program. * * * */ import javax . swing . JFrame ; public class ETMServerDriver { /** * Create main to show driver * @param args */ public static void main ( String [] args ) { new ETMServerDriver (); } /** * Constructor to setup the main page */ public ETMServerDriver (){ JFrame frame = new JFrame (); frame . setTitle ( "ETM Server by CGI" ); frame . setDefaultCloseOperation ( JFrame . EXIT_ON_CLOSE ); frame . setVisible ( true ); frame . setSize ( 800 , 800 ); frame . setLocation ( 0 , 200 ); frame . setResizable ( false ); frame . add ( new ETMServerGUIPanel ()); frame . pack (); frame . setVisible ( true ); }

Upload: adam-dale

Post on 12-Feb-2017

205 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ETM Server

/** * TIMS ETM Server * * @author Adam Dale * * This program will take a set of configuration options and set up a VM or Local to * run a instance of the ETM program. * * * */import javax.swing.JFrame;

public class ETMServerDriver {/** * Create main to show driver * @param args */public static void main(String[] args) {

new ETMServerDriver();}

/** * Constructor to setup the main page */public ETMServerDriver(){

JFrame frame = new JFrame();

frame.setTitle("ETM Server by CGI");frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);frame.setSize(800, 800);frame.setLocation(0,200);frame.setResizable(false);

frame.add(new ETMServerGUIPanel());frame.pack();frame.setVisible(true);

}

}/** * TIMS ETM Server * * @author Adam Dale * * This program will take a set of configuration options and set up a VM or Local to

Page 2: ETM Server

* run a instance of the ETM program. * * * */import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;import java.io.File;import java.lang.reflect.Array;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JComboBox;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.border.EtchedBorder;

public class ETMServerGUIPanel extends JPanel {

private static final long serialVersionUID = 1L;

private JButton startButton = new JButton("Start");//private JButton startButton = new JButton("TEST");private static JCheckBox selectSetupCheck = new JCheckBox("First Time Setup");private static JCheckBox selectUpdateJavaCheck = new JCheckBox("Update java and javascript");private static JCheckBox selectStartServer = new JCheckBox("Start tomcat server");private static JLabel selectInstallStepLabel = new JLabel("Please select setup type");private static JLabel userLabel = new JLabel("UserName:");private static JLabel passwordLabel = new JLabel("Password:");private static JCheckBox changeRuleEngineCheck = new JCheckBox("Select Rule Engine Version:");private static JCheckBox selectAdvancedSettingCheck = new JCheckBox(": Advanced Settings");private static JCheckBox selectSysUserTomcatCheck = new JCheckBox("Add SYS User on tomcat.");

private static JCheckBox selectDefaultUserPassCheck = new JCheckBox("Override Default User/Pass");private static JComboBox selectCurrentRuleEngine = new JComboBox();private static JTextField userName = new JTextField();private static JTextField password = new JTextField();private static String[] folders;

private ETMServerActionEngine actionListener = new ETMServerActionEngine();

public ETMServerGUIPanel() {JPanel basePanel= new JPanel();

Page 3: ETM Server

GridBagConstraints subC = new GridBagConstraints(); basePanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));basePanel.setLayout(new GridBagLayout());

//setBackground(new Color(142,142,56));

//Setup base panel subC.fill = GridBagConstraints.HORIZONTAL; //Row one subC.gridx = 1; subC.gridy = 0; basePanel.add(selectInstallStepLabel, subC); subC.gridx = 1; subC.gridy = 1; subC.insets = new Insets(0,25,0,0); basePanel.add(selectSetupCheck, subC); selectSetupCheck.setSelected(true); selectSetupCheck.addActionListener(actionListener); subC.gridx = 1; subC.gridy = 2; basePanel.add(selectUpdateJavaCheck, subC); selectUpdateJavaCheck.addActionListener(actionListener); subC.gridx = 1; subC.gridy = 3; basePanel.add(selectStartServer, subC); selectStartServer.addActionListener(actionListener); subC.gridx = 2; subC.insets = new Insets(0,90,0,0); basePanel.add(startButton,subC); startButton.addActionListener(actionListener); //Add code for advanced menu JPanel advancedPanel= new JPanel();

advancedPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));advancedPanel.setLayout(new GridBagLayout());

//Get folders for rule engine drop down.

Page 4: ETM Server

File ruleEngine = new File("H:\\Rules Engine Updates");if(FileHelper.isSharedDriveOnline()){

folders =FileHelper.listOfSubfolders(ruleEngine);for(int i=0; i<folders.length; i++){

selectCurrentRuleEngine.addItem(folders[i]);}

selectCurrentRuleEngine.setSelectedItem(folders[0]);}else {

//Set to Not online and disableselectCurrentRuleEngine.setSelectedItem("Not Online");selectCurrentRuleEngine.addItem("Not Online");

}

subC.insets = new Insets(0,0,0,0);subC.gridx = 1;

subC.gridy = 0; advancedPanel.add(selectAdvancedSettingCheck, subC); selectAdvancedSettingCheck.addActionListener(actionListener);

subC.insets = new Insets(0,40,0,0);subC.gridx = 1;subC.gridy = 2; advancedPanel.add(changeRuleEngineCheck, subC);changeRuleEngineCheck.setEnabled(false);changeRuleEngineCheck.addActionListener(actionListener);

subC.gridx = 2;subC.gridy = 2;subC.insets = new Insets(0,00,0,0);advancedPanel.add(selectCurrentRuleEngine, subC);selectCurrentRuleEngine.setEnabled(false);selectCurrentRuleEngine.addActionListener(actionListener);

subC.gridx = 1; subC.gridy = 3; subC.insets = new Insets(0,40,5,0); advancedPanel.add(selectSysUserTomcatCheck, subC); selectSysUserTomcatCheck.setEnabled(false); selectSysUserTomcatCheck.addActionListener(actionListener); subC.gridx = 1; subC.gridy = 4; advancedPanel.add(selectDefaultUserPassCheck, subC); selectDefaultUserPassCheck.setEnabled(false);

Page 5: ETM Server

selectDefaultUserPassCheck.addActionListener(actionListener); subC.gridx = 1; subC.gridy = 5; subC.insets = new Insets(0,10,0,0); advancedPanel.add(userLabel, subC); subC.gridx = 2; subC.gridy = 5; subC.insets = new Insets(0,-130,5,0); userName.setEditable(false); advancedPanel.add(userName, subC); userName.addActionListener(actionListener); subC.gridx = 1; subC.gridy = 6; subC.insets = new Insets(0,10,0,0); advancedPanel.add(passwordLabel, subC); subC.gridx = 2; subC.gridy = 6; subC.insets = new Insets(0,-130,0,0); password.setEditable(false); advancedPanel.add(password, subC); password.addActionListener(actionListener); //Add main panels GridBagConstraints mainC = new GridBagConstraints();

setBorder(BorderFactory.createEtchedBorder());setLayout(new GridBagLayout());

//Row onemainC.gridx = 1;mainC.gridy = 0;

add(basePanel, mainC); //Row two mainC.insets = new Insets(0,20,0,0);

mainC.gridx = 2;mainC.gridy = 0;

add(advancedPanel, mainC);}

/** * Checks to see if the first time setup flag is check * @return */

public static boolean isFirstTimeSetup(){

Page 6: ETM Server

if(selectSetupCheck.isSelected()){ return true;

} else {

return false; }

}/** * Checks to see if the update java is checked * @return */

public static boolean isUpdateJava(){ if(selectUpdateJavaCheck.isSelected()){

return true; } else {

return false; }

}/** * Checks to see if the start server is checked * @return */

public static boolean isStartServer(){ if(selectStartServer.isSelected()){

return true; } else {

return false; }

}/** * Checks to see if the advanced setting is checked * @return */

public static boolean isAdvancedSetting(){ if(selectAdvancedSettingCheck.isSelected()){

return true; } else {

return false; }

}/** * Checks to see if the SysUserTomcatCheck is checked * @return */

Page 7: ETM Server

public static boolean isSysUserTomcat(){ if(selectSysUserTomcatCheck.isSelected()){

return true; } else {

return false; }

}/** * Checks to see if the select default user is checked * @return */

public static boolean isDefaultUserPassCheck(){ if(selectDefaultUserPassCheck.isSelected()){

return true; } else {

return false; }

}/** * Checks to see if the select default user is checked * @return */

public static boolean isChangeRuleEngineCheck(){ if(changeRuleEngineCheck.isSelected()){

return true; } else {

return false; }

} /** * Show hide fields based on results from other check box * @param b */ public static void showFirstTimeHideFields(boolean b){

selectUpdateJavaCheck.setEnabled(b); selectStartServer.setEnabled(b);

} /** * Show hide fields based on results from other check box * @param b */public static void showAdvancedFields(boolean b) {

selectSysUserTomcatCheck.setEnabled(b);selectDefaultUserPassCheck.setEnabled(b);

Page 8: ETM Server

changeRuleEngineCheck.setEnabled(b);selectCurrentRuleEngine.setEnabled(b);//selectCurrentRuleEngine.setSelectedItem(folders[0]);

}

/** * Show hide fields based on results from other check box * @param b */public static void showUserPassFields(boolean b) {

userName.setEditable(b);password.setEditable(b);

} /** * Show hide fields based on results from other check box * @param b */public static void showRuleEngineFields(boolean b) {

selectCurrentRuleEngine.setEnabled(b);} /** * Show hide fields based on results from other check box * @param b */public static void showFirstTimeFields(boolean b) {

selectSetupCheck.setEnabled(b);}/** * Clear fields here and reset defaults. */public static void clearAdvancedFields() {

// TODO Auto-generated method stubuserName.setText("");password.setText("");selectSysUserTomcatCheck.setSelected(false);selectDefaultUserPassCheck.setSelected(false);

}/** * Get username text. */public static String getUserName() {

// TODO Auto-generated method stubreturn userName.getText();

}/** * Get password text.

Page 9: ETM Server

*/public static String getPassword() {

// TODO Auto-generated method stubreturn password.getText();

}/** * Get selected rule engine version. */public static String getRuleEngineValue() {

// TODO Auto-generated method stubreturn selectCurrentRuleEngine.getSelectedItem().toString();

}/** * Get the latest rule engine version * @return */public static String getLatestRuleEngineValue() {

// TODO Auto-generated method stubreturn Array.get(folders, folders.length-1).toString();

}/** * Clear fields here and reset defaults. */public static void clearFields() {

// TODO Auto-generated method stubselectUpdateJavaCheck.setSelected(false);selectStartServer.setSelected(false);

}}/** * TIMS ETM Server * * @author Adam Dale * * This program will take a set of configuration options and set up a VM or Local to * run a instance of the ETM program. * * * */import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.BufferedReader;import java.io.File;import java.io.IOException;import java.io.InputStreamReader;

Page 10: ETM Server

import javax.swing.JOptionPane;

public class ETMServerActionEngine implements ActionListener {

private String userId="";

public void actionPerformed(ActionEvent e) {//******************************************************************************************************//DEBUG CODE HERE

if(e.getActionCommand().equals("TEST")){ //___________________________________________________________________________________________________//Test code below new ProgressWindow();ETMServer.startServer();try {

Thread.sleep(1000);} catch (InterruptedException e1) {

// TODO Auto-generated catch blocke1.printStackTrace();

}cleanUpTempFiles();}

//******************************************************************************************************

//Setup all checks for validation on checkbox hereif(ETMServerGUIPanel.isFirstTimeSetup()){

ETMServerGUIPanel.showFirstTimeHideFields(false);//Prevent unwanted side effects and clear other checkboxes back to defaultETMServerGUIPanel.clearFields();

}else {

ETMServerGUIPanel.showFirstTimeHideFields(true);}if(ETMServerGUIPanel.isAdvancedSetting()){

ETMServerGUIPanel.showAdvancedFields(true);}else {

ETMServerGUIPanel.showAdvancedFields(false);//Prevent unwanted side effects and clear other checkboxes back to defaultETMServerGUIPanel.clearAdvancedFields();

Page 11: ETM Server

}if(ETMServerGUIPanel.isDefaultUserPassCheck()){

ETMServerGUIPanel.showUserPassFields(true);}else {

ETMServerGUIPanel.showUserPassFields(false);}if(ETMServerGUIPanel.isChangeRuleEngineCheck()){

ETMServerGUIPanel.showRuleEngineFields(true);}else {

ETMServerGUIPanel.showRuleEngineFields(false);}if(ETMServerGUIPanel.isUpdateJava()|| ETMServerGUIPanel.isStartServer()){

ETMServerGUIPanel.showFirstTimeFields(false);}else {

ETMServerGUIPanel.showFirstTimeFields(true);}

//Close results windowif(e.getActionCommand().equals("Close")){

ProgressWindow.setCloseButtonEnable(false);ProgressWindow.closeWindow();

}

//Run Setup based on which config options where picked above.if(e.getActionCommand().equals("Start")){

ProgressWindow.setCloseButtonEnable(false);new ProgressWindow();//VERY IMPORANT HERE TO CREATE NEW THREAD//Create a new thread here that will be separate from the GUI thread or the main thread.//This allows the GUI process free to update status barThread processHandlerThread = new Thread(){

public void run(){

while(ProgressWindow.isRunningProcesses()){ try {

Thread.sleep(100);} catch (InterruptedException e) {

// TODO Auto-generated catch block

Page 12: ETM Server

e.printStackTrace();} //Clear log issuesETMServerLogHandler.clearLogEntrys();ProgressWindow.updateProgress(10);if(ETMServerGUIPanel.isFirstTimeSetup()){

int onlineFlag=0;if(!FileHelper.isSharedDriveOnline()){

onlineFlag = JOptionPane.showConfirmDialog(null, "Shared drive not online limited setup will run.\n\n" +

"Do you wish to run limited setup the following will be skipped?" +"\n 1 - Copy of miridian jar files."+"\n 2 - Copy of hibernate folders." +"\n 3 - Copy of tnsNames.ora file.", "Limited Setup Required",

JOptionPane.YES_NO_OPTION);}

int initSetupFlag=0;//Do not ask this if above is noif(onlineFlag==0){

//Check for previous initiation setup runsFile initTempFile = new File("C:\\Temp\\initTempFile.log");if(initTempFile.exists()){initSetupFlag = JOptionPane.showConfirmDialog(null, "Initial Setup has ran before.\n\n"

+"Do you wish to run setup again?" +"\nWARNING-This will override any previous changes.", "Initial Setup Override",

JOptionPane.YES_NO_OPTION);}

}//Check to make sure they want to proceed and that the shared drive is online.if(initSetupFlag==0 && onlineFlag==0){

//Get the current usernameuserId=ETMServer.getCurrentUser();ProgressWindow.updateProgress(20);

if(FileHelper.isSharedDriveOnline()){//Copy over meridan jars skip this process if not onlineETMServer.copyMREJars();

//Setup Hibernate properties and files//Find a faster process here maybe open a new threadETMServer.setupHibernate();

//Copy tnsnames

Page 13: ETM Server

ETMServer.copyTnsNames();ProgressWindow.updateProgress(30);

}else {

//Add log enteries detailing what was done.ETMServerLogHandler.warningHandler("Shared Drive Offline copyMREJars skipped.");ETMServerLogHandler.warningHandler("Shared Drive Offline copyTnsNames skipped.");ETMServerLogHandler.warningHandler("Shared Drive Offline setupHibernate skipped.");

}//Copy shortcutsETMServer.copyEclipseShortcut(userId);ETMServer.copyStartServerShortcut(userId);ProgressWindow.updateProgress(35);//Create repositorycallBatchProcess(ETMServer.createSVNRepository());ProgressWindow.updateProgress(55);//Update Java and JavaScript//callBatchProcess(ETMServer.performSVNUpdate());

//Update Tomcat UsersFile ncdorTomcatUsers = new File("C:\\etm\\ETM_DEV_SDK\\product\\tomcatBase\\conf\\

ncdor-tomcat-users.xml");File tomcatUsers = new File("C:\\etm\\ETM_DEV_SDK\\product\\tomcatBase\\conf\\tomcat-

users.xml");

//PLACE CODE HERE TO ENTER USER AND PASSWORDif(ETMServerGUIPanel.isDefaultUserPassCheck()){

if(!ETMServerGUIPanel.getUserName().equals("") && !ETMServerGUIPanel.getPassword().equals("")){

ETMServer.updateTomcatXML(ncdorTomcatUsers, ETMServerGUIPanel.getUserName(),ETMServerGUIPanel.getPassword());

ETMServer.updateTomcatXML(tomcatUsers, ETMServerGUIPanel.getUserName(),ETMServerGUIPanel.getPassword());

}else {

//Write log warning and default to userETMServerLogHandler.warningHandler(" Username and/or password blank reverting to

Username: "+userId+ " Password: password");ETMServer.updateTomcatXML(ncdorTomcatUsers, userId,"password");ETMServer.updateTomcatXML(tomcatUsers, userId,"password");

}}else {

ETMServer.updateTomcatXML(ncdorTomcatUsers, userId,"password");ETMServer.updateTomcatXML(tomcatUsers, userId,"password");

Page 14: ETM Server

}ProgressWindow.updateProgress(68);

ETMServer.setHibernateProperties();ProgressWindow.updateProgress(75);//Setup Environ.ini file to match DB passETMServer.setupEnvironDBPass();ProgressWindow.updateProgress(85);//Setup the server.xml fileETMServer.setupServerXMLFile();ProgressWindow.updateProgress(90);//Edit the spl.cmd commandETMServer.updateSplCommand();ProgressWindow.updateProgress(91);//Edit the spl.propertiesETMServer.setSplProperties();ProgressWindow.updateProgress(92);

//Final step write output log to temp directory.ETMServer.createTempLogFile();

}else {

ETMServerLogHandler.warningHandler("Override declined, program terminated.");}

}

//If update java and javascript is checkedif(ETMServerGUIPanel.isUpdateJava()){

//Update Java and JavaScriptcallBatchProcess(ETMServer.performSVNUpdate());

}

//If start server is checkedif(ETMServerGUIPanel.isStartServer()){

ETMServer.startServer();try {

Thread.sleep(100);} catch (InterruptedException e) {

// TODO Auto-generated catch blocke.printStackTrace();

}}

cleanUpTempFiles();

Page 15: ETM Server

ProgressWindow.updateProgress(100);//Set to false here to stop processingProgressWindow.setRunningProcesses(false);

ETMServerLogHandler.addFinishEntry("Setup Has finished");ProgressWindow.setCloseButtonEnable(true);

}

}

}; //checkDownloadProgress(); processHandlerThread.start();

//End of start if

}}/** * Method will delete any temp files created */private void cleanUpTempFiles() {

// TODO Auto-generated method stub//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("Starting cleanUpTempFiles ...");

File tempTxt = new File("C:\\Temp\\temp.txt");File getUserId = new File("C:\\Temp\\getUserID.bat");File performSVNUpdate = new File("C:\\Temp\\performSVNUpdate.bat");File createSVNRepository = new File("C:\\Temp\\createSVNRepository.bat");File createHibernatePath = new File("C:\\Temp\\createHibernatePath.bat");File startServer = new File("C:\\Temp\\runTomcatServer.bat");File copyHibernateZip = new File("C:\\Temp\\copyHibernate.bat");File copyMeridianJars = new File("C:\\Temp\\copyMeridianJars.bat");

if(tempTxt.exists()){tempTxt.delete();//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("cleanUpTempFiles The temp file "+tempTxt.getName()+" was deleted");

}if(getUserId.exists()){

getUserId.delete();//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("cleanUpTempFiles The temp file "+getUserId.getName()+" was deleted");

Page 16: ETM Server

}if(performSVNUpdate.exists()){

performSVNUpdate.delete();//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("cleanUpTempFiles The temp file "+performSVNUpdate.getName()+" was

deleted");}if(createSVNRepository.exists()){

createSVNRepository.delete();//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("cleanUpTempFiles The temp file "+createSVNRepository.getName()+" was

deleted");}if(createHibernatePath.exists()){

createHibernatePath.delete();//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("cleanUpTempFiles The temp file "+createHibernatePath.getName()+" was

deleted");}if(startServer.exists()){

startServer.delete();//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("cleanUpTempFiles The temp file "+startServer.getName()+" was deleted");

}if(copyHibernateZip.exists()){

copyHibernateZip.delete();//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("cleanUpTempFiles The temp file "+copyHibernateZip.getName()+" was

deleted");}if(copyMeridianJars.exists()){

copyMeridianJars.delete();//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("cleanUpTempFiles The temp file "+copyMeridianJars.getName()+" was

deleted");}

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("cleanUpTempFiles successful.");

}

public static void callBatchProcess(String batchName){try {

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("Starting callBatchProcess ...");

String cmdString = "cmd /C start /MIN "+batchName+" ";

Page 17: ETM Server

Runtime cmdRunTime= Runtime.getRuntime();Process p =cmdRunTime.exec(cmdString);

String line=null;

BufferedReader input =new BufferedReader(new InputStreamReader(p.getInputStream())); //Make system wait till process is done.

while ((line = input.readLine()) != null) { ETMServerLogHandler.addNewLogEntry("callBatchProcess executing commands "+line);

} input.close();

//Set to false here to stop processingProgressWindow.setRunningBatch(false);

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("callBatchProcess successful.");

} catch (IOException e) {// TODO Auto-generated catch block//JOptionPane.showMessageDialog(null,e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);ETMServerLogHandler.exceptionHandler("callBatchProccess "+e.getMessage());

}

}

public void checkDownloadProgress(){Thread checkDownloadProcess = new Thread(){

public void run(){ File hibernate32 = new File("C:\\hibernate-3.2"); while(ProgressWindow.isRunningBatch()){

try {

Thread.sleep(1000); if(hibernate32.exists()){ //Do math hard coded file size is 86391918 // long fileSize= FileHelper.getFolderSize(hibernate32); int fileSize= (int) FileHelper.getFolderSize(hibernate32); double percent = ((double)fileSize/86391918)*100; //System.out.println("The Percent Complete is "+Math.round(percent)+"%"); ProgressWindow.updateProgress((int) Math.round(percent)); }

Page 18: ETM Server

} catch (InterruptedException e) {

ETMServerLogHandler.exceptionHandler("Debug Wrong"); }

} }

}; checkDownloadProcess.start();

}

}/** * TIMS ETM Server * * @author Adam Dale * * This program will take a set of configuration options and set up a VM or Local to * run a instance of the ETM program. * * * */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.Iterator;

public class ETMServer {

public static String getCurrentUser(){String currentUser="";try {

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("Starting getCurrentUser ...");// TODO Auto-generated method stub

FileWriter fstream = new FileWriter("C:\\Temp\\getUserID.bat");BufferedWriter out = new BufferedWriter(fstream);//Commands to get current userout.write("ECHO %USERNAME% > C:\\Temp\\temp.txt"+"\n\rexit");out.close();

Page 19: ETM Server

ETMServerActionEngine.callBatchProcess("C:\\Temp\\getUserID.bat");

//Weird case here but can't process to fast put the thread to sleep//This will prevent unwanted errors.try {

Thread.sleep(100);

} catch (InterruptedException e1) {// TODO Auto-generated catch blocke1.printStackTrace();

}//Now Read in file and set global varable for later use.FileReader input = new FileReader("C:\\Temp\\temp.txt");BufferedReader bufRead = new BufferedReader(input);//String read in lineString line;

while((line=bufRead.readLine())!=null){currentUser=line.trim();

}

input.close();bufRead.close();

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("getCurrentUser successful.");

} catch (Exception e){//JOptionPane.showMessageDialog(null,e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);ETMServerLogHandler.exceptionHandler("getCurrentUser "+e.getMessage());

}return currentUser;

}

public static void copyMREJars() {

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("Starting copyMREJars ...");// get all the dest file paths//File standAloneJarDest = new File("C:\\etm\\ETM_DEV_SDK\\splapp\\standalone\\lib\\meridian.jar");//File rootJarDest = new File("C:\\etm\\ETM_DEV_SDK\\splapp\\applications\\root\\WEB-INF\\lib\\meridian.jar");//File XAIAppJarDest = new File("C:\\etm\\ETM_DEV_SDK\\splapp\\applications\\XAIApp\\WEB-INF\\lib\\

meridian.jar");

//Check for the current version you want from the user and put it in the path here so we know //which path to take.

Page 20: ETM Server

String userInput ="";//Set userInput from popup here. You can also hard code this so the user has to pick a valid //choice which is a drop down and do a search on the folders in that path break them out into //strings then set the drop down nodes to each of these strings.if(ETMServerGUIPanel.isChangeRuleEngineCheck()){

userInput=ETMServerGUIPanel.getRuleEngineValue();}else {

userInput=ETMServerGUIPanel.getLatestRuleEngineValue();}

String standAloneSrcPath="H:\\Rules Engine Updates\\"+userInput+"\\appServer\\splapp\\standalone\\lib\\meridian.jar";

String rootSrcPath="H:\\Rules Engine Updates\\"+userInput+"\\appServer\\splapp\\applications\\root\\WEB-INF\\lib\\meridian.jar";

String XAIAppSrcPath="H:\\Rules Engine Updates\\"+userInput+"\\appServer\\splapp\\applications\\XAIApp\\WEB-INF\\lib\\meridian.jar";

// get all the src pathsFile standAloneJarSrc = new File(standAloneSrcPath);File rootJarSrc = new File(rootSrcPath);File XAIAppJarSrc = new File(XAIAppSrcPath);

if(!standAloneJarSrc.exists() || !rootJarSrc.exists() || !XAIAppJarSrc.exists()){

//JOptionPane.showMessageDialog(null,"JARS not found in Source", "Error", JOptionPane.ERROR_MESSAGE);ETMServerLogHandler.exceptionHandler("JARS not found in Source");

}else {

// setup the to file paths to copy to and fromtry {

FileWriter fstream = new FileWriter("C:\\Temp\\copyMeridianJars.bat");BufferedWriter out = new BufferedWriter(fstream);

out.write("copy \"H:\\Rules Engine Updates\\"+userInput+"\\appServer\\splapp\\standalone\\lib\\meridian.jar\" \"C:\\etm\\ETM_DEV_SDK\\splapp\\standalone\\lib\\meridian.jar\" \n"+

"copy \"H:\\Rules Engine Updates\\"+userInput+"\\appServer\\splapp\\applications\\root\\WEB-INF\\lib\\meridian.jar\" \"C:\\etm\\ETM_DEV_SDK\\splapp\\applications\\root\\WEB-INF\\lib\\meridian.jar\" \n"+

"copy \"H:\\Rules Engine Updates\\"+userInput+"\\appServer\\splapp\\applications\\XAIApp\\WEB-INF\\lib\\meridian.jar\" \"C:\\etm\\ETM_DEV_SDK\\splapp\\applications\\XAIApp\\WEB-INF\\lib\\meridian.jar\"\n"+

"exit\n");out.close();

Page 21: ETM Server

ETMServerActionEngine.callBatchProcess("C:\\Temp\\copyMeridianJars.bat");

}catch (Exception e) {

//JOptionPane.showMessageDialog(null,e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);ETMServerLogHandler.exceptionHandler("copyMREJars "+e.getMessage());

}

//FileHelper.copy(standAloneJarSrc, standAloneJarDest);ETMServerLogHandler.addNewLogEntry("copyMREJars "+standAloneJarSrc.getAbsolutePath()+" copied.");

//FileHelper.copy(rootJarSrc, rootJarDest);ETMServerLogHandler.addNewLogEntry("copyMREJars "+rootJarSrc.getAbsolutePath()+" copied.");

//FileHelper.copy(XAIAppJarSrc, XAIAppJarDest);ETMServerLogHandler.addNewLogEntry("copyMREJars "+XAIAppJarSrc.getAbsolutePath()+" copied.");

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("copyMREJars successful.");

}

}

/** * * @return */public static String performSVNUpdate() {

try {//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("Starting performSVNUpdate ...");

// TODO Auto-generated method stubFileWriter fstream = new FileWriter("C:\\Temp\\performSVNUpdate.bat");BufferedWriter out = new BufferedWriter(fstream);//Commands to update java and javaScript//Note change 0 and 1 to display update dialogString updateJavaCommand = "TortoiseProc.exe /command:update /path:\"C:\\etm\\ETM_DEV_SDK\\java\\source\\

cm\\com\\splwg\\cm\\\"/closeonend:1\n";String updateJavaScriptCommand = "TortoiseProc.exe /command:update /path:\"C:\\etm\\ETM_DEV_SDK\\splapp\\

applications\\root\\cm\\\"/closeonend:1";out.write(updateJavaCommand+updateJavaScriptCommand+"\n\rexit");out.close();

Page 22: ETM Server

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("performSVNUpdate Ran 1 batch file performSVNUpdate.bat and 2 SVN

updated folders.");ETMServerLogHandler.addNewLogEntry("performSVNUpdate successful.");

return "C:\\Temp\\performSVNUpdate.bat";

} catch (Exception e){//JOptionPane.showMessageDialog(null,e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);ETMServerLogHandler.exceptionHandler("performSVNUpdate "+e.getMessage());return "";

}

}/** * Creates the command that will run the java and javascript repositories. * Returns the batch name created. * @return */public static String createSVNRepository() {

// TODO Auto-generated method stubtry {

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("Starting createSVNRepository ...");

String createJavaRepositoryCommand = "TortoiseProc.exe /command:checkout /path:\"C:\\etm\\ETM_DEV_SDK\\java\\source\\cm\\com\\splwg\\cm\\\" /url:\"https://unixsvn1/repos/tims/trunk/ETM_DEV_SDK/java/source/cm/com/splwg/cm\"/closeonend:1";

String createJavaScriptRepositoryCommand = "TortoiseProc.exe /command:checkout /path:\"C:\\etm\\ETM_DEV_SDK\\splapp\\applications\\root\\cm\\\" /url:\"https://unixsvn1/repos/tims/trunk/ETM_DEV_SDK/splapp/applications/root/cm\" /closeonend:1";

FileWriter fstream = new FileWriter("C:\\Temp\\createSVNRepository.bat");BufferedWriter out = new BufferedWriter(fstream);

out.write(createJavaRepositoryCommand+"\n\r"+createJavaScriptRepositoryCommand+"\n\rexit");out.close();

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("createSVNRepository Ran 1 batch file createSVNRepository.bat and 2 SVN

repositories created.");ETMServerLogHandler.addNewLogEntry("createSVNRepository successful.");return "C:\\Temp\\createSVNRepository.bat";

}catch (Exception e) {

Page 23: ETM Server

//JOptionPane.showMessageDialog(null,e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);ETMServerLogHandler.exceptionHandler("createSVNRepository "+e.getMessage());return "";

}}/** * Generic method that will take a file and update it based on the parameters given */public static void genericUpdateFile(File fileToUpdate, String updateString, String matchString){

// TODO Auto-generated method stubtry {

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("Starting genericUpdateFile ...");

ArrayList<String> tempXMLFile = new ArrayList<String>();FileReader input = new FileReader(fileToUpdate);BufferedReader bufRead = new BufferedReader(input);

//Flag to update fileboolean addLineFlag=false;

//String read in lineString line;

while((line=bufRead.readLine())!=null){

if(line.trim().equals(updateString)){addLineFlag=true;

}//Add the lines to a temp array to be read later.tempXMLFile.add(line);

}input.close();bufRead.close();

//If no string is found we need to add that userif(!addLineFlag){

FileWriter fstream = new FileWriter(fileToUpdate);BufferedWriter out = new BufferedWriter(fstream);

Iterator<String> iterator = tempXMLFile.iterator();

while(iterator.hasNext()){//Add new line of code hereString currentLine = iterator.next();

Page 24: ETM Server

if(currentLine.contains(matchString)){out.write(updateString+"\n");

}else {

out.write(currentLine+"\n");}

}out.close();//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("genericUpdateFile The file "+fileToUpdate.getAbsolutePath()+"was

updated.");}else {

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("genericUpdateFile No changes made.");

}

ETMServerLogHandler.addNewLogEntry("genericUpdateFile successful.");} catch (IOException e) {

// TODO Auto-generated catch block//JOptionPane.showMessageDialog(null,e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);ETMServerLogHandler.exceptionHandler("genericUpdateFile "+e.getMessage());

}}/** * Creates the command that will update the tomacat with the rv id provided * * @param userID */public static void updateTomcatXML(File tomcatXMLFile, String userID, String password) {

// TODO Auto-generated method stubtry {

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("Starting updateTomcatXML ...");

ArrayList<String> tempXMLFile = new ArrayList<String>();FileReader input = new FileReader(tomcatXMLFile);BufferedReader bufRead = new BufferedReader(input);

//Special case here to add System userString systemXMLLine="<user username=\"SYSUSER\"

password=\"ENC(mJZ+qKfZ2gOIvFrWwVAJXPpYM8pghmUhP38lJAgwz8E=)\" roles=\"cisusers,admin,manager\"/>"; //String to add user to list

Page 25: ETM Server

String userXMLLine= "<user username=\""+userID+"\" password=\""+password+"\" roles=\"cisusers,admin,manager\"/>";

String line;

while((line=bufRead.readLine())!=null){if(ETMServerGUIPanel.isSysUserTomcat()){

if(!line.trim().equals(userXMLLine) && !line.trim().contains("<user username=\"SYSUSER\"")){//Add the lines to a temp array to be read later.tempXMLFile.add(line);

}}else {

if(!line.trim().equals(userXMLLine)){//Add the lines to a temp array to be read later.tempXMLFile.add(line);

}}

}input.close();bufRead.close();

FileWriter fstream = new FileWriter(tomcatXMLFile);BufferedWriter out = new BufferedWriter(fstream);

Iterator<String> iterator = tempXMLFile.iterator();

while(iterator.hasNext()){//Add new line of code hereString currentLine = iterator.next();if(ETMServerGUIPanel.isSysUserTomcat()){

if(currentLine.trim().equals("</tomcat-users>")){out.write(" "+userXMLLine+"\n "+systemXMLLine+"\n"+"</tomcat-users>");

}else {

out.write(currentLine+"\n");}

}else {

if(currentLine.trim().equals("</tomcat-users>")){out.write(" "+userXMLLine+"\n"+"</tomcat-users>");

}else {

out.write(currentLine+"\n");}

}}

Page 26: ETM Server

out.close();

ETMServerLogHandler.addNewLogEntry("updateTomcatXML Update made on"+tomcatXMLFile.getAbsolutePath()+"successful.");

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("updateTomcatXML successful.");

} catch (IOException e) {// TODO Auto-generated catch block//JOptionPane.showMessageDialog(null,e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);ETMServerLogHandler.exceptionHandler("updateTomcatXML "+e.getMessage());

}}/** * Creates the command that will set the global environment variable * Returns the batch name created. * @return */public static String createHibernatePath() {

// TODO Auto-generated method stubtry {

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("Starting createHibernatePath ...");

FileWriter fstream = new FileWriter("C:\\Temp\\createHibernatePath.bat");BufferedWriter out = new BufferedWriter(fstream);

out.write("regedit.exe /c /s \"hibernate.reg\" \n"+"regedit.exe /c /s \"Path.reg\" \nexit");

out.close();

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("createHibernatePath Registry updated successful.");ETMServerLogHandler.addNewLogEntry("createHibernatePath successful.");

return "C:\\Temp\\createHibernatePath.bat";}catch (Exception e) {

//JOptionPane.showMessageDialog(null,e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);ETMServerLogHandler.exceptionHandler("createHibernatePath "+e.getMessage());return "";

}}

Page 27: ETM Server

/** * Method will copy over user files from server and then * set the local variables accordingly. */public static boolean setupHibernate() {

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("Starting setupHibernate ...");

// setup the to file paths to copy to and fromtry {

FileWriter fstream = new FileWriter("C:\\Temp\\copyHibernate.bat");BufferedWriter out = new BufferedWriter(fstream);

out.write("xcopy \"H:\\hibernate-3.2.7.ga\" \"C:\\hibernate-3.2.7.ga\" /E /Q /R /Y /D /I \n"+ "exit\n");out.close();

ETMServerActionEngine.callBatchProcess("C:\\Temp\\copyHibernate.bat");

}catch (Exception e) {

//JOptionPane.showMessageDialog(null,e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);ETMServerLogHandler.exceptionHandler("startServer "+e.getMessage());return false;

}ETMServerActionEngine.callBatchProcess(createHibernatePath());//System.out.println("Copy Finished."+getFolderSize(hibernateSrc));

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("setupHibernate successful.");return true;

}/** * Method will search ETM_DEV_SDK for environ.ini and set * values accordingly. * */public static void setupEnvironDBPass(){

File environIni = new File("C:\\etm\\ETM_DEV_SDK\\etc\\ENVIRON.INI");try {

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("Starting setupEnvironDBPass ...");

Page 28: ETM Server

ArrayList<String> tempIniFile = new ArrayList<String>();FileReader input = new FileReader(environIni);BufferedReader bufRead = new BufferedReader(input);//Flag to update ini file usersboolean addLineFlag=false;//String to add user to listString newIniLine= "DBPASS=TEST#1";String line;

while((line=bufRead.readLine())!=null){

if(line.trim().equals(newIniLine)){addLineFlag=true;

}//Add the lines to a temp array to be read later.tempIniFile.add(line);

}input.close();bufRead.close();//If no user is found we need to add that userif(!addLineFlag){

FileWriter fstream = new FileWriter(environIni);BufferedWriter out = new BufferedWriter(fstream);

Iterator<String> iterator = tempIniFile.iterator();

while(iterator.hasNext()){//Add new line of code hereString currentLine = iterator.next();if(currentLine.contains("DBPASS=")){

out.write(newIniLine+"\n");}else {

out.write(currentLine+"\n");}

}out.close();//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("setupEnvironDBPass Update made on"+environIni.getAbsolutePath()

+"successful.");}else {

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("setupEnvironDBPass No changes made to

"+environIni.getAbsolutePath());}

Page 29: ETM Server

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("setupEnvironDBPass successful.");

} catch (IOException e) {// TODO Auto-generated catch block//JOptionPane.showMessageDialog(null,e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);ETMServerLogHandler.exceptionHandler("setupEnvironDBPass "+e.getMessage());

}}/** * Method will search all folders for the hibernate.properties and then * use the generic update file to check for update string */public static void setHibernateProperties(){

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("Starting setHibernateProperties ...");

File searchDir = new File("C:\\etm\\ETM_DEV_SDK");ArrayList<File> fileList = new ArrayList<File>();fileList = FileHelper.searchForFile(searchDir, "hibernate.properties", fileList);String updateString = "hibernate.connection.password = TEST#1";String matchString = "hibernate.connection.password = ";for(int i=0; i<fileList.size(); i++){

genericUpdateFile(fileList.get(i), updateString, matchString);//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("setHibernateProperties Update on"+fileList.get(i).getAbsolutePath()+"

successful.");}

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("setHibernateProperties successful.");

}/** * Method will search all folders for the spl.properties and then * use the generic update file to check for update string */public static void setSplProperties(){

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("Starting setSplProperties ...");File searchDir = new File("C:\\etm\\ETM_DEV_SDK");ArrayList<File> fileList = new ArrayList<File>();fileList = FileHelper.searchForFile(searchDir, "spl.properties", fileList);

Page 30: ETM Server

String updateString = "spl.tools.loaded.applications=base,tax,cm,meridian";String matchString = "spl.tools.loaded.applications=";for(int i=0; i<fileList.size(); i++){

genericUpdateFile(fileList.get(i), updateString, matchString);//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("setSplProperties Update on"+fileList.get(i).getAbsolutePath()+"

successful.");}

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("setSplProperties successful.");

}/** * */public static void setupServerXMLFile() {

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("Starting setupServerXMLFile ...");// TODO Auto-generated method stubFile serverXML = new File("C:\\etm\\ETM_DEV_SDK\\product\\tomcatBase\\conf\\server.xml");String updateString = "<!-- <Context path=\"/XAIApp\" docBase=\"C:/etm/ETM_DEV_SDK/splapp/applications/XAIApp\"

debug=\"0\" privileged=\"true\"/>-->";String matchString = "<Context path=\"/XAIApp\" docBase=\"C:/etm/ETM_DEV_SDK/splapp/applications/XAIApp\"

debug=\"0\" privileged=\"true\"/>";genericUpdateFile(serverXML, updateString, matchString);//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("setupServerXMLFile Update made on "+serverXML.getAbsolutePath()+"

successful.");//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("setupServerXMLFile successful.");

}/** * Method that updates the spl.cmd command with the java opts for debug. * Special care is taken here as we could use the generic method but we need to do * Additional checks when dealing with the cmd options. So reuse code will be found here. */public static void updateSplCommand() {

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("Starting updateSplCommand ...");// TODO Auto-generated method stubFile splCommand = new File("C:\\etm\\ETM_DEV_SDK\\bin\\spl.cmd");String matchString ="set JAVA_OPTS=";String updateString = "set JAVA_OPTS=-Xms1024m -Xmx1024m -XX:MaxPermSize=256m -Dfile.encoding=ISO8859_1 -Xdebug

Page 31: ETM Server

-Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000";

try {

ArrayList<String> tempXMLFile = new ArrayList<String>();FileReader input = new FileReader(splCommand);BufferedReader bufRead = new BufferedReader(input);

//Flag to update fileboolean addLineFlag=false;

//String read in lineString line;

while((line=bufRead.readLine())!=null){

if(line.trim().contains(matchString)&&!line.trim().contains("REM")){addLineFlag=true;

}//Add the lines to a temp array to be read later.tempXMLFile.add(line);

}input.close();bufRead.close();//If no string is found we need lineif(addLineFlag){

FileWriter fstream = new FileWriter(splCommand);BufferedWriter out = new BufferedWriter(fstream);

Iterator<String> iterator = tempXMLFile.iterator();

while(iterator.hasNext()){//Add new line of code hereString currentLine = iterator.next();if(currentLine.contains(matchString)&&!currentLine.contains("REM")){

out.write("\t"+updateString+"\n");}else {

out.write(currentLine+"\n");}

}out.close();//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("updateSplCommand Update made on "+splCommand.getAbsolutePath()+"

successful.");

Page 32: ETM Server

}else {

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("updateSplCommand No changes made to "+splCommand.getAbsolutePath());

}

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("updateSplCommand successful.");

} catch (IOException e) {// TODO Auto-generated catch block//JOptionPane.showMessageDialog(null,e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);ETMServerLogHandler.exceptionHandler("updateSplCommand "+e.getMessage());

}}/** * Method that will copy the tns names for the DB info. */public static void copyTnsNames() {

// TODO Auto-generated method stub//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("Starting copyTnsNames ...");

File tnsNamesSrc = new File("H:\\Other\\TNSNAMES.ORA");File tnsNamesDest = new File("C:\\Oracle\\Oracle11g\\network\\admin\\TNSNAMES.ORA");if(!tnsNamesSrc.exists()){

ETMServerLogHandler.exceptionHandler("TNSNAMES not found in Source");}else {

FileHelper.copy(tnsNamesSrc, tnsNamesDest);

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("copyTnsNames successful.");ETMServerLogHandler.addNewLogEntry("copyTnsNames "+tnsNamesSrc.getAbsolutePath()+" copied");

}}

/** * Method will check for desktop shortcut, if not found it will be created. */public static void copyEclipseShortcut(String userId) {

// TODO Auto-generated method stub//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("Starting copyEclipseShortcut ...");

Page 33: ETM Server

File eclipseSrc = new File("C:\\ETM22_SDK\\SDK\\shortcuts\\startEclipse.bat");File eclipseDest = new File("C:\\Documents and Settings\\"+userId+"\\Desktop\\startEclipse.bat");if(!eclipseSrc.exists()){

//JOptionPane.showMessageDialog(null,"Eclipse shortcut not found in Source", "Source Error", JOptionPane.ERROR_MESSAGE);

ETMServerLogHandler.exceptionHandler("copyEclipseShortcut Eclipse shortcut not found in Source");}else {

if(!eclipseDest.exists()){FileHelper.copy(eclipseSrc, eclipseDest);//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("copyEclipseShortcut successful.");

}else{

//JOptionPane.showMessageDialog(null,"Eclipse shortcut already created", "Error", JOptionPane.ERROR_MESSAGE);

ETMServerLogHandler.exceptionHandler("copyEclipseShortcut Eclipse shortcut already created");}

}

}

/** * Method will check for desktop shortcut start server, if not found it will be created. */public static void copyStartServerShortcut(String userId) {

// TODO Auto-generated method stub//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("Starting copyStartServerShortcut ...");

File startServerSrc = new File("H:\\Other\\startTomcatExpress.exe.lnk");File startServerDest = new File("C:\\Documents and Settings\\"+userId+"\\Desktop\\startTomcatExpress.exe.lnk");

if(!startServerDest.exists()){FileHelper.copy(startServerSrc, startServerDest);//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("copyStartServerShortcut successful.");

}else{

ETMServerLogHandler.exceptionHandler("copyStartServerShortcut Start server shortcut already created");}

}

Page 34: ETM Server

/** * Method will start the tomcat server. */public static void startServer() {

// TODO Auto-generated method stubtry {

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("Starting startServer ...");

FileWriter fstream = new FileWriter("C:\\Temp\\runTomcatServer.bat");BufferedWriter out = new BufferedWriter(fstream);

out.write("cd c:\\etm\\etm_dev_sdk\\bin \n"+ "%windir%\\system32\\cmd.exe /K \"splenviron -e etm_dev_sdk && spl Start\"\n"+ "exit\n");

out.close();

//ETMServerActionEngine.callBatchProcess("C:\\Temp\\runTomcatServer.bat");String cmdString = "cmd /C start /MIN C:\\Temp\\runTomcatServer.bat ";Runtime cmdRunTime= Runtime.getRuntime();cmdRunTime.exec(cmdString);//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("startServer Ran successful.");ETMServerLogHandler.addNewLogEntry("startServer successful.");

}catch (Exception e) {

//JOptionPane.showMessageDialog(null,e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);ETMServerLogHandler.exceptionHandler("startServer "+e.getMessage());

}}/** * Method will create a temp log file that will be used later to determine if the configuration has been * run before. */public static void createTempLogFile() {

// TODO Auto-generated method stubtry {

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("Starting createTempLogFile ...");

FileWriter fstream = new FileWriter("C:\\Temp\\initTempFile.log");BufferedWriter out = new BufferedWriter(fstream);

out.write("Success");out.close();

Page 35: ETM Server

//Add log entry to give detailed results.ETMServerLogHandler.addNewLogEntry("createTempLogFile created 1 file successful.");ETMServerLogHandler.addNewLogEntry("createTempLogFile successful.");

}catch (Exception e) {

//JOptionPane.showMessageDialog(null,e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);ETMServerLogHandler.exceptionHandler("createTempLogFile "+e.getMessage());

}}

}/** * TIMS ETM Server * * @author Adam Dale * * This program will take a set of configuration options and set up a VM or Local to * run a instance of the ETM program. * * * */import java.io.File;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import java.util.ArrayList;import java.util.Arrays;

import javax.swing.JOptionPane;

public class FileHelper {/** * Takes in two files and performs copy * @param src * @param desc */public static void copy(File src, File dest){ try {

FileReader in = new FileReader(src); FileWriter out = new FileWriter(dest); int c;

while ((c = in.read()) != -1){ out.write(c);

Page 36: ETM Server

}

in.close(); out.close(); ETMServerLogHandler.addNewLogEntry("Copying file..."+src.getAbsolutePath());

} catch (IOException errorMessage){ JOptionPane.showMessageDialog(null,errorMessage.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); }}

/** * Takes in two folders and performs copy * @param src * @param desc */public static void copyFolder(File src, File dest){

if(src.isDirectory()){ //if directory does not exist then make it if(!dest.exists()){ dest.mkdir(); } //list all the directory contents String files[]= src.list(); for (String file: files){ //set the file names as structures File srcFile = new File(src, file); File destFile = new File(dest, file); //ETMServerLogHandler.addNewLogEntry("Copying folder..."+src.getName()); //recursive copy copyFolder(srcFile, destFile); } } else { //if file then copy it copy(src, dest); } }/** * Takes in two folders and performs copy * @param src * @param desc

Page 37: ETM Server

*/public static long getFolderSize(File src){

long folderSize=0; File[] filelist = src.listFiles(); for (int i = 0; i < filelist.length; i++) {

if (filelist[i].isDirectory()) { folderSize += getFolderSize(filelist[i]); } else {

folderSize += filelist[i].length(); }

} return folderSize; }/** * Method will recursively search for a file name based on the search pattern given, if match * is found returns the absolute path of the file. * @param fileName * @param searchPattern * @return */public static ArrayList<File> searchForFile(File fileName, String searchPattern, ArrayList<File> filesFound){

if(fileName.isDirectory()){ //list all the directory contents String files[]= fileName.list(); for (String file: files){ File srcFile = new File(fileName, file); //recursive search searchForFile(srcFile, searchPattern, filesFound); } } else { //Must be a file check it if(fileName.getName().equals(searchPattern)){ filesFound.add(fileName); return filesFound; } }

Page 38: ETM Server

return filesFound;}

/** * Method will recursively search for a folder name based on the search pattern given, if match * is found returns the absolute path of the folder. * @param fileName * @param searchPattern * @return */public static String searchForFolder(File folder, String searchPattern, String foundPath){

if(folder.isDirectory()){ //list all the directory contents String files[]= folder.list(); for (String file: files){ File srcFile = new File(folder, file); //recursive search if(folder.getName().equals(searchPattern)){ System.out.println("Found the folder"+folder.getAbsolutePath()); foundPath=folder.getAbsolutePath(); } searchForFolder(srcFile, searchPattern, foundPath); } } return foundPath;

}

/** * Method will recursively search for a folder name based on the search pattern given, if match * is found returns the all sub folders for that path * @param fileName * @param searchPattern * @return */public static String[] listOfSubfolders(File folder){

if(folder.isDirectory()){ //list all the directory contents String files[]= folder.list(); Arrays.sort(files);

Page 39: ETM Server

return files; } return null;

}/** * Method will check to make sure H: and return boolean value * */public static boolean isSharedDriveOnline() {

File sharedDrive = new File("H:\\Shared\\Secretary's Office\\AdamD");if(sharedDrive.exists()){

return true;}return false;

}}/** * TIMS ETM Server * * @author Adam Dale * * This program will take a set of configuration options and set up a VM or Local to * run a instance of the ETM program. * * * */import java.util.ArrayList;

public class ETMServerLogHandler {private static ArrayList<String> logMessage = new ArrayList<String>();

public ETMServerLogHandler(){

}

public static void exceptionHandler(String exception){logMessage.add("ERROR\t"+exception);ProgressWindow.addLogEntryToWindow("ERROR\t"+exception);

}

public static void warningHandler(String exception){logMessage.add("WARNING\t"+exception);

Page 40: ETM Server

ProgressWindow.addLogEntryToWindow("WARNING\t"+exception);}

public static void addNewLogEntry(String logEntry){logMessage.add("INFO\t"+logEntry);ProgressWindow.addLogEntryToWindow("INFO\t"+logEntry);

}public static void addFinishEntry(String logEntry){

logMessage.add("\n\n\nFINISHED\t"+logEntry+"\n\n\n");ProgressWindow.addLogEntryToWindow("FINISHED\t"+logEntry);

}public static ArrayList<String> getLogEntrys(){

return logMessage;}

public static void clearLogEntrys(){logMessage.clear();

}

}/** * TIMS ETM Server * * @author Adam Dale * * This program will take a set of configuration options and set up a VM or Local to * run a instance of the ETM program. * * * */

import java.awt.Color;import java.awt.Dimension;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.JProgressBar;import javax.swing.JScrollPane;import javax.swing.JTextPane;import javax.swing.text.BadLocationException;import javax.swing.text.Style;import javax.swing.text.StyleConstants;import javax.swing.text.StyledDocument;

Page 41: ETM Server

public class ProgressWindow {

private static JProgressBar progressBar;

private static boolean runningProcess, runningBatch;private static JScrollPane scrollPane;private static JTextPane textPane;private static StyledDocument doc;private static JFrame window;private static JButton closeButton = new JButton("Close");private static ETMServerActionEngine listener = new ETMServerActionEngine();

public ProgressWindow() { //Create and set up the window.

window = new JFrame();

GridBagConstraints mainC = new GridBagConstraints(); window.setLayout(new GridBagLayout());

mainC.fill = GridBagConstraints.HORIZONTAL;

window.setTitle("PROCESS RESULTS"); window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); window.setVisible(true);

window.setSize(400, 400);window.setLocation(200,200);window.setResizable(false);window.toFront();

//Set the process running flag here. runningProcess=true; //Set the batch running flag here. runningBatch=true; //Set the curser to waiting //Cursor hourglassCursor = new Cursor(Cursor.WAIT_CURSOR);

progressBar = new JProgressBar();

progressBar.setValue(0); progressBar.setStringPainted(true);

textPane = new JTextPane();

Page 42: ETM Server

doc = textPane.getStyledDocument();

textPane.setBackground(Color.LIGHT_GRAY);scrollPane = new JScrollPane(textPane); scrollPane.setPreferredSize( new Dimension( 800, 400 ) );

JPanel panel = new JPanel(); panel.add(progressBar); //Row one

mainC.gridx = 0;mainC.gridy = 0;

window.add(scrollPane, mainC); //Row two

mainC.gridx = 0;mainC.gridy = 1;

window.add(panel, mainC); //Row three

mainC.gridx = 0;mainC.gridy = 2;mainC.insets = new Insets(0,350,0,350);closeButton.setEnabled(false);closeButton.addActionListener(listener);

window.add(closeButton, mainC); //Display the window. window.pack(); window.setVisible(true);

}

public static void updateProgress(int value){progressBar.setValue(value);

}/** * Create method here to have flag set to tell if process are running. * @return */public static boolean isRunningProcesses() {

// TODO Auto-generated method stubif(runningProcess){

return true;}else {

return false;}

}

Page 43: ETM Server

/** * Create method here to get flag tell if process are running. * @return */public static boolean getRunningProcesses() {

return runningProcess;}/** * Create method here to get button enabled value * @return */public static boolean getCloseButton() {

if(closeButton.isEnabled()){return true;

}else {

return false;}

}/** * Create method here to get button enabled value * @return */public static void setCloseButtonEnable(boolean b) {

closeButton.setEnabled(b);}

/** * Create method here to get flag tell if process are running. * @return */public static boolean setRunningProcesses(boolean flag) {

return runningProcess=flag;}/** * Create method here to have flag set to tell if batch are running. * @return */public static boolean isRunningBatch() {

// TODO Auto-generated method stubif(runningBatch){

return true;}else {

return false;

Page 44: ETM Server

}}

/** * Create method here to get flag tell if batch are running. * @return */public static boolean getRunningBatch() {

return runningBatch;}

/** * Create method here to get flag tell if batch are running. * @return */public static boolean setRunningBatch(boolean flag) {

return runningBatch=flag;}/** * Adds new log entry to panel. * @param message */public static void addLogEntryToWindow(String message) {

// TODO Auto-generated method stubtry {

if(message.contains("ERROR")){//Set the error styleStyle errorStyle = textPane.addStyle("Error", null); StyleConstants.setForeground(errorStyle, Color.red); StyleConstants.setBackground(errorStyle, Color.lightGray); doc.insertString(doc.getLength(), message+"\n", errorStyle);

}else if(message.contains("WARNING")){

//Set the error styleStyle warningStyle = textPane.addStyle("Warning", null); StyleConstants.setForeground(warningStyle, Color.yellow); StyleConstants.setBackground(warningStyle, Color.lightGray); doc.insertString(doc.getLength(), message+"\n", warningStyle);

}else if(message.contains("FINISHED")){

//Set the error styleStyle warningStyle = textPane.addStyle("Warning", null); StyleConstants.setForeground(warningStyle, Color.blue); StyleConstants.setBackground(warningStyle, Color.lightGray); doc.insertString(doc.getLength(), message+"\n", warningStyle);

}else {

Page 45: ETM Server

//Set the default styleStyle defaultStyle = textPane.addStyle("Default", null); StyleConstants.setForeground(defaultStyle, Color.black); StyleConstants.setBackground(defaultStyle, Color.lightGray); doc.insertString(doc.getLength(), message+"\n", defaultStyle);

}//Set the curser to the endtextPane.setCaretPosition(doc.getLength());

} catch (BadLocationException e) {// TODO Auto-generated catch blocke.printStackTrace();

}}

public static void closeWindow() {// TODO Auto-generated method stubwindow.dispose();

}

}