Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Upcoming SlideShare
Geological observations on volcanic islands pdf
Next
Download to read offline and view in fullscreen.

0

Share

ETM Server

Download to read offline

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all
  • Be the first to like this

ETM Server

  1. 1. /** * 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
  2. 2. * 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(); GridBagConstraints subC = new GridBagConstraints();
  3. 3. 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. File ruleEngine = new File("H:Rules Engine Updates"); if(FileHelper.isSharedDriveOnline()){ folders =FileHelper.listOfSubfolders(ruleEngine);
  4. 4. for(int i=0; i<folders.length; i++){ selectCurrentRuleEngine.addItem(folders[i]); } selectCurrentRuleEngine.setSelectedItem(folders[0]); } else { //Set to Not online and disable selectCurrentRuleEngine.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); selectDefaultUserPassCheck.addActionListener(actionListener); subC.gridx = 1; subC.gridy = 5;
  5. 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 one mainC.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(){ if(selectSetupCheck.isSelected()){ return true; } else { return false;
  6. 6. } } /** * 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 */ public static boolean isSysUserTomcat(){ if(selectSysUserTomcatCheck.isSelected()){ return true; } else {
  7. 7. 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); changeRuleEngineCheck.setEnabled(b); selectCurrentRuleEngine.setEnabled(b); //selectCurrentRuleEngine.setSelectedItem(folders[0]); }
  8. 8. /** * 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 stub userName.setText(""); password.setText(""); selectSysUserTomcatCheck.setSelected(false); selectDefaultUserPassCheck.setSelected(false); } /** * Get username text. */ public static String getUserName() { // TODO Auto-generated method stub return userName.getText(); } /** * Get password text. */ public static String getPassword() { // TODO Auto-generated method stub return password.getText(); }
  9. 9. /** * Get selected rule engine version. */ public static String getRuleEngineValue() { // TODO Auto-generated method stub return selectCurrentRuleEngine.getSelectedItem().toString(); } /** * Get the latest rule engine version * @return */ public static String getLatestRuleEngineValue() { // TODO Auto-generated method stub return Array.get(folders, folders.length-1).toString(); } /** * Clear fields here and reset defaults. */ public static void clearFields() { // TODO Auto-generated method stub selectUpdateJavaCheck.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; import javax.swing.JOptionPane;
  10. 10. 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 block e1.printStackTrace(); } cleanUpTempFiles(); } //****************************************************************************************************** //Setup all checks for validation on checkbox here if(ETMServerGUIPanel.isFirstTimeSetup()){ ETMServerGUIPanel.showFirstTimeHideFields(false); //Prevent unwanted side effects and clear other checkboxes back to default ETMServerGUIPanel.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 default ETMServerGUIPanel.clearAdvancedFields(); } if(ETMServerGUIPanel.isDefaultUserPassCheck()){ ETMServerGUIPanel.showUserPassFields(true); } else { ETMServerGUIPanel.showUserPassFields(false);
  11. 11. } if(ETMServerGUIPanel.isChangeRuleEngineCheck()){ ETMServerGUIPanel.showRuleEngineFields(true); } else { ETMServerGUIPanel.showRuleEngineFields(false); } if(ETMServerGUIPanel.isUpdateJava()|| ETMServerGUIPanel.isStartServer()){ ETMServerGUIPanel.showFirstTimeFields(false); } else { ETMServerGUIPanel.showFirstTimeFields(true); } //Close results window if(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 bar Thread processHandlerThread = new Thread(){ public void run(){ while(ProgressWindow.isRunningProcesses()){ try { Thread.sleep(100); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } //Clear log issues ETMServerLogHandler.clearLogEntrys(); ProgressWindow.updateProgress(10); if(ETMServerGUIPanel.isFirstTimeSetup()) {
  12. 12. int onlineFlag=0; if(!FileHelper.isSharedDriveOnline()){ onlineFlag = JOptionPane.showConfirmDialog(null, "Shared drive not online limited setup will run.nn" + "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 no if(onlineFlag==0){ //Check for previous initiation setup runs File initTempFile = new File("C:TempinitTempFile.log"); if(initTempFile.exists()){ initSetupFlag = JOptionPane.showConfirmDialog(null, "Initial Setup has ran before.nn" + "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 username userId=ETMServer.getCurrentUser(); ProgressWindow.updateProgress(20); if(FileHelper.isSharedDriveOnline()){ //Copy over meridan jars skip this process if not online ETMServer.copyMREJars(); //Setup Hibernate properties and files //Find a faster process here maybe open a new thread ETMServer.setupHibernate(); //Copy tnsnames 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.");
  13. 13. ETMServerLogHandler.warningHandler("Shared Drive Offline setupHibernate skipped."); } //Copy shortcuts ETMServer.copyEclipseShortcut(userId); ETMServer.copyStartServerShortcut(userId); ProgressWindow.updateProgress(35); //Create repository callBatchProcess(ETMServer.createSVNRepository()); ProgressWindow.updateProgress(55); //Update Java and JavaScript //callBatchProcess(ETMServer.performSVNUpdate()); //Update Tomcat Users File ncdorTomcatUsers = new File("C:etmETM_DEV_SDKproducttomcatBaseconfncdor-tomcat-users.xml"); File tomcatUsers = new File("C:etmETM_DEV_SDKproducttomcatBaseconftomcat- users.xml"); //PLACE CODE HERE TO ENTER USER AND PASSWORD if(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 user ETMServerLogHandler.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"); } ProgressWindow.updateProgress(68); ETMServer.setHibernateProperties(); ProgressWindow.updateProgress(75); //Setup Environ.ini file to match DB pass ETMServer.setupEnvironDBPass();
  14. 14. ProgressWindow.updateProgress(85); //Setup the server.xml file ETMServer.setupServerXMLFile(); ProgressWindow.updateProgress(90); //Edit the spl.cmd command ETMServer.updateSplCommand(); ProgressWindow.updateProgress(91); //Edit the spl.properties ETMServer.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 checked if(ETMServerGUIPanel.isUpdateJava()){ //Update Java and JavaScript callBatchProcess(ETMServer.performSVNUpdate()); } //If start server is checked if(ETMServerGUIPanel.isStartServer()){ ETMServer.startServer(); try { Thread.sleep(100); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } cleanUpTempFiles(); ProgressWindow.updateProgress(100); //Set to false here to stop processing ProgressWindow.setRunningProcesses(false); ETMServerLogHandler.addFinishEntry("Setup Has finished"); ProgressWindow.setCloseButtonEnable(true); } }
  15. 15. }; //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:Temptemp.txt"); File getUserId = new File("C:TempgetUserID.bat"); File performSVNUpdate = new File("C:TempperformSVNUpdate.bat"); File createSVNRepository = new File("C:TempcreateSVNRepository.bat"); File createHibernatePath = new File("C:TempcreateHibernatePath.bat"); File startServer = new File("C:TemprunTomcatServer.bat"); File copyHibernateZip = new File("C:TempcopyHibernate.bat"); File copyMeridianJars = new File("C:TempcopyMeridianJars.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"); } 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.
  16. 16. 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+" "; 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); }
  17. 17. input.close(); //Set to false here to stop processing ProgressWindow.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)); } } catch (InterruptedException e) { ETMServerLogHandler.exceptionHandler("Debug Wrong"); } } } }; checkDownloadProcess.start(); }
  18. 18. } /** * 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:TempgetUserID.bat"); BufferedWriter out = new BufferedWriter(fstream); //Commands to get current user out.write("ECHO %USERNAME% > C:Temptemp.txt"+"nrexit"); out.close(); ETMServerActionEngine.callBatchProcess("C:TempgetUserID.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 block e1.printStackTrace(); } //Now Read in file and set global varable for later use.
  19. 19. FileReader input = new FileReader("C:Temptemp.txt"); BufferedReader bufRead = new BufferedReader(input); //String read in line String 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:etmETM_DEV_SDKsplappstandalonelibmeridian.jar"); //File rootJarDest = new File("C:etmETM_DEV_SDKsplappapplicationsrootWEB-INFlibmeridian.jar"); //File XAIAppJarDest = new File("C:etmETM_DEV_SDKsplappapplicationsXAIAppWEB- INFlibmeridian.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. 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+"appServersplappstandalonelibmeridian.jar";
  20. 20. String rootSrcPath="H:Rules Engine Updates"+userInput+"appServersplappapplicationsrootWEB- INFlibmeridian.jar"; String XAIAppSrcPath="H:Rules Engine Updates"+userInput+"appServersplappapplicationsXAIAppWEB- INFlibmeridian.jar"; // get all the src paths File 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 from try { FileWriter fstream = new FileWriter("C:TempcopyMeridianJars.bat"); BufferedWriter out = new BufferedWriter(fstream); out.write("copy "H:Rules Engine Updates"+userInput+"appServersplappstandalonelibmeridian.jar" "C:etmETM_DEV_SDKsplappstandalonelibmeridian.jar" n"+ "copy "H:Rules Engine Updates"+userInput+"appServersplappapplicationsrootWEB- INFlibmeridian.jar" "C:etmETM_DEV_SDKsplappapplicationsrootWEB-INFlibmeridian.jar" n"+ "copy "H:Rules Engine Updates"+userInput+"appServersplappapplicationsXAIAppWEB- INFlibmeridian.jar" "C:etmETM_DEV_SDKsplappapplicationsXAIAppWEB-INFlibmeridian.jar"n"+ "exitn"); out.close(); ETMServerActionEngine.callBatchProcess("C:TempcopyMeridianJars.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.");
  21. 21. //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 stub FileWriter fstream = new FileWriter("C:TempperformSVNUpdate.bat"); BufferedWriter out = new BufferedWriter(fstream); //Commands to update java and javaScript //Note change 0 and 1 to display update dialog String updateJavaCommand = "TortoiseProc.exe /command:update /path:"C:etmETM_DEV_SDKjavasourcecmcomsplwgcm"/closeonend:1n"; String updateJavaScriptCommand = "TortoiseProc.exe /command:update /path:"C:etmETM_DEV_SDKsplappapplicationsrootcm"/closeonend:1"; out.write(updateJavaCommand+updateJavaScriptCommand+"nrexit"); out.close(); //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:TempperformSVNUpdate.bat"; } catch (Exception e){ //JOptionPane.showMessageDialog(null,e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); ETMServerLogHandler.exceptionHandler("performSVNUpdate "+e.getMessage()); return ""; } }
  22. 22. /** * 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 stub try { //Add log entry to give detailed results. ETMServerLogHandler.addNewLogEntry("Starting createSVNRepository ..."); String createJavaRepositoryCommand = "TortoiseProc.exe /command:checkout /path:"C:etmETM_DEV_SDKjavasourcecmcomsplwgcm" /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:etmETM_DEV_SDKsplappapplicationsrootcm" /url:"https://unixsvn1/repos/tims/trunk/ETM_DEV_SDK/splapp/applications/root/cm" /closeonend:1"; FileWriter fstream = new FileWriter("C:TempcreateSVNRepository.bat"); BufferedWriter out = new BufferedWriter(fstream); out.write(createJavaRepositoryCommand+"nr"+createJavaScriptRepositoryCommand+"nrexit"); 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:TempcreateSVNRepository.bat"; } catch (Exception e) { //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 stub try { //Add log entry to give detailed results. ETMServerLogHandler.addNewLogEntry("Starting genericUpdateFile ..."); ArrayList<String> tempXMLFile = new ArrayList<String>(); FileReader input = new FileReader(fileToUpdate);
  23. 23. BufferedReader bufRead = new BufferedReader(input); //Flag to update file boolean addLineFlag=false; //String read in line String 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 user if(!addLineFlag){ FileWriter fstream = new FileWriter(fileToUpdate); BufferedWriter out = new BufferedWriter(fstream); Iterator<String> iterator = tempXMLFile.iterator(); while(iterator.hasNext()){ //Add new line of code here String currentLine = iterator.next(); 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."); }
  24. 24. 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 stub try { //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 user String systemXMLLine="<user username="SYSUSER" password="ENC(mJZ+qKfZ2gOIvFrWwVAJXPpYM8pghmUhP38lJAgwz8E=)" roles="cisusers,admin,manager"/>"; //String to add user to list 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); } } }
  25. 25. 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 here String 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"); } } } 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
  26. 26. * Returns the batch name created. * @return */ public static String createHibernatePath() { // TODO Auto-generated method stub try { //Add log entry to give detailed results. ETMServerLogHandler.addNewLogEntry("Starting createHibernatePath ..."); FileWriter fstream = new FileWriter("C:TempcreateHibernatePath.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:TempcreateHibernatePath.bat"; } catch (Exception e) { //JOptionPane.showMessageDialog(null,e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); ETMServerLogHandler.exceptionHandler("createHibernatePath "+e.getMessage()); return ""; } } /** * 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 from try { FileWriter fstream = new FileWriter("C:TempcopyHibernate.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"+ "exitn"); out.close();
  27. 27. ETMServerActionEngine.callBatchProcess("C:TempcopyHibernate.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:etmETM_DEV_SDKetcENVIRON.INI"); try { //Add log entry to give detailed results. ETMServerLogHandler.addNewLogEntry("Starting setupEnvironDBPass ..."); ArrayList<String> tempIniFile = new ArrayList<String>(); FileReader input = new FileReader(environIni); BufferedReader bufRead = new BufferedReader(input); //Flag to update ini file users boolean addLineFlag=false; //String to add user to list String 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 user
  28. 28. if(!addLineFlag){ FileWriter fstream = new FileWriter(environIni); BufferedWriter out = new BufferedWriter(fstream); Iterator<String> iterator = tempIniFile.iterator(); while(iterator.hasNext()){ //Add new line of code here String 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()); } //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:etmETM_DEV_SDK");
  29. 29. 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:etmETM_DEV_SDK"); ArrayList<File> fileList = new ArrayList<File>(); fileList = FileHelper.searchForFile(searchDir, "spl.properties", fileList); 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 stub File serverXML = new File("C:etmETM_DEV_SDKproducttomcatBaseconfserver.xml"); String updateString = "<!-- <Context path="/XAIApp" docBase="C:/etm/ETM_DEV_SDK/splapp/applications/XAIApp"
  30. 30. 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 stub File splCommand = new File("C:etmETM_DEV_SDKbinspl.cmd"); String matchString ="set JAVA_OPTS="; String updateString = "set JAVA_OPTS=-Xms1024m -Xmx1024m -XX:MaxPermSize=256m -Dfile.encoding=ISO8859_1 -Xdebug -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 file boolean addLineFlag=false; //String read in line String 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); }
  31. 31. input.close(); bufRead.close(); //If no string is found we need line if(addLineFlag){ FileWriter fstream = new FileWriter(splCommand); BufferedWriter out = new BufferedWriter(fstream); Iterator<String> iterator = tempXMLFile.iterator(); while(iterator.hasNext()){ //Add new line of code here String 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."); } 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.
  32. 32. ETMServerLogHandler.addNewLogEntry("Starting copyTnsNames ..."); File tnsNamesSrc = new File("H:OtherTNSNAMES.ORA"); File tnsNamesDest = new File("C:OracleOracle11gnetworkadminTNSNAMES.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 ..."); File eclipseSrc = new File("C:ETM22_SDKSDKshortcutsstartEclipse.bat"); File eclipseDest = new File("C:Documents and Settings"+userId+"DesktopstartEclipse.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"); } } }
  33. 33. /** * 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:OtherstartTomcatExpress.exe.lnk"); File startServerDest = new File("C:Documents and Settings"+userId+"DesktopstartTomcatExpress.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"); } } /** * Method will start the tomcat server. */ public static void startServer() { // TODO Auto-generated method stub try { //Add log entry to give detailed results. ETMServerLogHandler.addNewLogEntry("Starting startServer ..."); FileWriter fstream = new FileWriter("C:TemprunTomcatServer.bat"); BufferedWriter out = new BufferedWriter(fstream); out.write("cd c:etmetm_dev_sdkbin n"+ "%windir%system32cmd.exe /K "splenviron -e etm_dev_sdk && spl Start"n"+ "exitn"); out.close(); //ETMServerActionEngine.callBatchProcess("C:TemprunTomcatServer.bat"); String cmdString = "cmd /C start /MIN C:TemprunTomcatServer.bat "; Runtime cmdRunTime= Runtime.getRuntime(); cmdRunTime.exec(cmdString); //Add log entry to give detailed results. ETMServerLogHandler.addNewLogEntry("startServer Ran successful."); ETMServerLogHandler.addNewLogEntry("startServer successful.");
  34. 34. } 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 stub try { //Add log entry to give detailed results. ETMServerLogHandler.addNewLogEntry("Starting createTempLogFile ..."); FileWriter fstream = new FileWriter("C:TempinitTempFile.log"); BufferedWriter out = new BufferedWriter(fstream); out.write("Success"); out.close(); //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;
  35. 35. 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); } 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();
  36. 36. 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 */ 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()){
  37. 37. //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; } } 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); } }
  38. 38. 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); return files; } return null; } /** * Method will check to make sure H: and return boolean value * */ public static boolean isSharedDriveOnline() { File sharedDrive = new File("H:SharedSecretary's OfficeAdamD"); 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. * * * */
  39. 39. 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("ERRORt"+exception); ProgressWindow.addLogEntryToWindow("ERRORt"+exception); } public static void warningHandler(String exception){ logMessage.add("WARNINGt"+exception); ProgressWindow.addLogEntryToWindow("WARNINGt"+exception); } public static void addNewLogEntry(String logEntry){ logMessage.add("INFOt"+logEntry); ProgressWindow.addLogEntryToWindow("INFOt"+logEntry); } public static void addFinishEntry(String logEntry){ logMessage.add("nnnFINISHEDt"+logEntry+"nnn"); ProgressWindow.addLogEntryToWindow("FINISHEDt"+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. * * *
  40. 40. */ 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; 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();
  41. 41. //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(); 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);
  42. 42. } /** * Create method here to have flag set to tell if process are running. * @return */ public static boolean isRunningProcesses() { // TODO Auto-generated method stub if(runningProcess){ return true; } else { return false; } } /** * 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 */
  43. 43. 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 stub if(runningBatch){ return true; } else { return false; } } /** * 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 stub try { if(message.contains("ERROR")){ //Set the error style Style errorStyle = textPane.addStyle("Error", null); StyleConstants.setForeground(errorStyle, Color.red); StyleConstants.setBackground(errorStyle, Color.lightGray); doc.insertString(doc.getLength(), message+"n", errorStyle); }
  44. 44. else if(message.contains("WARNING")){ //Set the error style Style 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 style Style warningStyle = textPane.addStyle("Warning", null); StyleConstants.setForeground(warningStyle, Color.blue); StyleConstants.setBackground(warningStyle, Color.lightGray); doc.insertString(doc.getLength(), message+"n", warningStyle); } else { //Set the default style Style 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 end textPane.setCaretPosition(doc.getLength()); } catch (BadLocationException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void closeWindow() { // TODO Auto-generated method stub window.dispose(); } }

Views

Total views

293

On Slideshare

0

From embeds

0

Number of embeds

10

Actions

Downloads

3

Shares

0

Comments

0

Likes

0

×