List of usage examples for java.lang Runtime exec
public Process exec(String cmdarray[]) throws IOException
From source file:gda.device.detector.pco.PCODetector.java
private void transferFiles() throws DeviceException { try {/*from w w w. ja va 2s . c o m*/ // copy the files off Runtime rt = Runtime.getRuntime(); String script = LocalProperties.get(GDA_FILE_TRANSFER_SCRIPT, null); if (script == null) { logger.warn("property '{}' is not defined.", GDA_FILE_TRANSFER_SCRIPT); return; } Process p = rt.exec(String.format("%s %s", script, scanSaveFolder.getAbsolutePath())); InterfaceProvider.getTerminalPrinter().print("Start to copy data to Central Storage"); // TODO this should be in a monitoring loop p.waitFor(); } catch (Exception e) { throw new DeviceException("Failed to run pco.transferFiles.", e); } }
From source file:com.ah.ui.actions.hiveap.HiveApFileAction.java
private boolean checkImageInfo(String imageFile) { try {/*from www . ja va2 s .co m*/ Runtime rt = Runtime.getRuntime(); Process new_process = rt.exec("chmod u+x " + imageFile); if (new_process.waitFor() != 0) { return false; } new_process = rt.exec(imageFile); if (new_process.waitFor() != 0) { return false; } HmBeOsUtil.deletefile(imageFile.substring(0, imageFile.length() - 3) + ".xml"); return true; } catch (Exception ex) { log.error("checkImageInfo : ", ex.getMessage()); return false; } }
From source file:ingestor.SingleFileProcessor.java
private boolean UnzipArchive(File inSourceFile) throws IOException, InterruptedException { logger.begin("UnzipArchive(" + inSourceFile + ")"); String line = ""; String cmd = ""; Runtime run = Runtime.getRuntime(); Process pr = null;/*from w w w.ja v a 2 s .c o m*/ String srcPath = "", tgtPath = ""; line = GetFileHeader(inSourceFile); srcPath = inSourceFile.getAbsolutePath(); tgtPath = inSourceFile.getParentFile().getAbsolutePath(); logger.force("\tsrcPath=" + srcPath); logger.force("\ttgtPath=" + tgtPath); logger.force("\tline=" + line); if (line.contains("gzip compressed data")) { cmd = "/bin/tar -C " + tgtPath + " -xvzf " + srcPath; } else if (line.contains("xz compressed data")) { cmd = "/bin/tar -C " + tgtPath + " -xvJf " + srcPath; } else if (line.contains("Zip archive data")) { cmd = "/usr/bin/unzip " + srcPath + " -d " + tgtPath; } else { logger.force("\t\tUnable to determine compression type, exiting"); return false; } logger.force("\t\tcmd=" + cmd); //logger.fine("\nexecuting: "+cmd+"\n"); pr = run.exec(cmd); BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream())); BufferedReader buferr = new BufferedReader(new InputStreamReader(pr.getErrorStream())); // read everything and output to outputStream as you go String s = null; ScreenLog.out("===== stdout ====="); while ((s = buf.readLine()) != null) { ScreenLog.out("line=" + s); } ScreenLog.out("===== stderr ====="); while ((s = buferr.readLine()) != null) { ScreenLog.out("line=" + s); } pr.waitFor(); logger.end("UnzipArchive(" + inSourceFile + ")==exit(" + pr.exitValue() + ")"); return pr.exitValue() == 0; }
From source file:userstudy.UserStudyResultsEvaluation2.java
public String generateTTest() { try {/* w w w . j ava 2s .c o m*/ //first get the column names of the files BufferedReader br;// = new BufferedReader(new FileReader(firstAccuracyFile)); String line = ""; int numOfColumns = numOfTasks; String[][] accColumnNames = new String[numOfConditions][numOfTasks]; String[][] timeColumnNames = new String[numOfConditions][numOfTasks]; for (int i = 0; i < numOfConditions; i++) { File AccuracyFile = new File( getServletContext().getRealPath(DATA_DIR + File.separator + accuracyFilenames.get(i))); br = new BufferedReader(new FileReader(AccuracyFile)); while ((line = br.readLine()) != null) { String split[] = line.split(","); for (int j = 0; j < split.length; j++) { accColumnNames[i][j] = split[j]; } break; } br.close(); } for (int i = 0; i < numOfConditions; i++) { File timeFile = new File( getServletContext().getRealPath(DATA_DIR + File.separator + timeFilenames.get(i))); br = new BufferedReader(new FileReader(timeFile)); while ((line = br.readLine()) != null) { String split[] = line.split(","); for (int j = 0; j < split.length; j++) { timeColumnNames[i][j] = split[j]; } break; } br.close(); } //Write the R-Script String scriptFilename = "rscript-ttest.R"; String scriptOutputFilename = "rscript-ttest.Rout"; String filePath = getServletContext().getRealPath(DATA_DIR + File.separator + scriptFilename); String dataPath = getServletContext().getRealPath(DATA_DIR); File scriptFile = new File(filePath); FileWriter fileWriter = new FileWriter(scriptFile); BufferedWriter bw = new BufferedWriter(fileWriter); PrintWriter pw = new PrintWriter(bw); if (dataPath.indexOf("\\") >= 0) { dataPath = dataPath.replaceAll("\\\\", "\\\\\\\\"); } //first set the working directory pw.println("setwd(\"" + dataPath + "\")"); //read the accuracy files for (int i = 0; i < numOfConditions; i++) { pw.println("accuracy" + (i + 1) + " = read.csv(\"" + accuracyFilenames.get(i) + "\")"); } //write the accuracy analysis for (int i = 0; i < numOfConditions - 1; i++) { String dataName1 = "accuracy" + (i + 1); String dataName2 = "accuracy" + (i + 2); for (int j = 0; j < accColumnNames[i].length; j++) { pw.println("" + accColumnNames[i][j] + "= c(" + dataName1 + "[," + (j + 1) + "])"); pw.println("" + accColumnNames[i + 1][j] + "= c(" + dataName1 + "[," + (j + 1) + "])"); pw.println("results<-capture.output(t.test(" + accColumnNames[i][j] + "," + accColumnNames[i + 1][j] + "))"); pw.println("results"); } } //close the printwriter pw.close(); /** * Run the script * */ Runtime r = Runtime.getRuntime(); Process p = null; String load; String workdir = getServletContext().getRealPath(DATA_DIR); String cmd[] = new String[3]; cmd[0] = "cmd.exe"; cmd[1] = "/C"; cmd[2] = "Rterm.exe --slave --no-restore --no-save <" + workdir + File.separator + scriptFilename + " > " + workdir + File.separator + scriptOutputFilename + " 2>&1"; //the working directory has to be the servlet and the datat direc //System.out.println("The Rterm is ::::: " + cmd[2]); //System.out.println("***The working directory is::: " + getServletContext().getRealPath(DATA_DIR)); try { // Use instance of Runtime class to run the command as a java Process p = r.exec(cmd); // Need to be careful with Process input and output to prevent it seizing up // May not be needed (up to **) in most cases but included just in case InputStream pin = p.getInputStream(); InputStreamReader cin = new InputStreamReader(pin); BufferedReader in = new BufferedReader(cin); try { while ((load = in.readLine()) != null) { } } catch (IOException e) { } InputStream epin = p.getErrorStream(); InputStreamReader ecin = new InputStreamReader(epin); BufferedReader ein = new BufferedReader(ecin); try { while ((load = ein.readLine()) != null) { } } catch (IOException e) { } ein.close(); in.close(); // ** } catch (IOException e) { System.out.println("Problems running: " + e.toString()); } } catch (Exception ex) { ex.printStackTrace(); } return ""; }
From source file:userstudy.UserStudyResultsEvaluation2.java
public void generateShapiroWilk() { try {/* w w w . j a v a2 s . c o m*/ //first get the column names of the files BufferedReader br;// = new BufferedReader(new FileReader(firstAccuracyFile)); String line = ""; int numOfColumns = numOfTasks; String[][] accColumnNames = new String[numOfConditions][numOfTasks]; String[][] timeColumnNames = new String[numOfConditions][numOfTasks]; for (int i = 0; i < numOfConditions; i++) { File AccuracyFile = new File( getServletContext().getRealPath(DATA_DIR + File.separator + accuracyFilenames.get(i))); br = new BufferedReader(new FileReader(AccuracyFile)); while ((line = br.readLine()) != null) { String split[] = line.split(","); for (int j = 0; j < split.length; j++) { accColumnNames[i][j] = split[j]; } break; } br.close(); } for (int i = 0; i < numOfConditions; i++) { File timeFile = new File( getServletContext().getRealPath(DATA_DIR + File.separator + timeFilenames.get(i))); br = new BufferedReader(new FileReader(timeFile)); while ((line = br.readLine()) != null) { String split[] = line.split(","); for (int j = 0; j < split.length; j++) { timeColumnNames[i][j] = split[j]; } break; } br.close(); } //Write the R-Script String scriptFilename = "rscript-shapiro.R"; String scriptOutputFilename = "rscript-shapiro.Rout"; String filePath = getServletContext().getRealPath(DATA_DIR + File.separator + scriptFilename); String dataPath = getServletContext().getRealPath(DATA_DIR); File scriptFile = new File(filePath); FileWriter fileWriter = new FileWriter(scriptFile); BufferedWriter bw = new BufferedWriter(fileWriter); PrintWriter pw = new PrintWriter(bw); if (dataPath.indexOf("\\") >= 0) { dataPath = dataPath.replaceAll("\\\\", "\\\\\\\\"); } //first set the working directory pw.println("setwd(\"" + dataPath + "\")"); //read the accuracy files for (int i = 0; i < numOfConditions; i++) { pw.println("accuracy" + (i + 1) + " = read.csv(\"" + accuracyFilenames.get(i) + "\")"); } //write the accuracy analysis for (int i = 0; i < numOfConditions; i++) { String dataName = "accuracy" + (i + 1); for (int j = 0; j < accColumnNames[i].length; j++) { pw.println("" + accColumnNames[i][j] + "= c(" + dataName + "[," + (j + 1) + "])"); pw.println("results<-capture.output(shapiro.test(" + accColumnNames[i][j] + "))"); pw.println("results"); } } //read the time files for (int i = 0; i < numOfConditions; i++) { pw.println("time" + (i + 1) + " = read.csv(\"" + timeFilenames.get(i) + "\")"); } //write the time analysis for (int i = 0; i < numOfConditions; i++) { String dataName = "time" + (i + 1); for (int j = 0; j < timeColumnNames[i].length; j++) { pw.println("" + timeColumnNames[i][j] + "= c(" + dataName + "[," + (j + 1) + "])"); pw.println("results<-capture.output(shapiro.test(" + timeColumnNames[i][j] + "))"); pw.println("results"); } } //close the printwriter pw.close(); /** * Run the script * */ Runtime r = Runtime.getRuntime(); Process p = null; String load; String workdir = getServletContext().getRealPath(DATA_DIR); String cmd[] = new String[3]; cmd[0] = "cmd.exe"; cmd[1] = "/C"; cmd[2] = "Rterm.exe --slave --no-restore --no-save <" + workdir + File.separator + scriptFilename + " > " + workdir + File.separator + scriptOutputFilename + " 2>&1"; //the working directory has to be the servlet and the datat direc //System.out.println("The Rterm is ::::: " + cmd[2]); //System.out.println("***The working directory is::: " + getServletContext().getRealPath(DATA_DIR)); try { // Use instance of Runtime class to run the command as a java Process p = r.exec(cmd); // Need to be careful with Process input and output to prevent it seizing up // May not be needed (up to **) in most cases but included just in case InputStream pin = p.getInputStream(); InputStreamReader cin = new InputStreamReader(pin); BufferedReader in = new BufferedReader(cin); try { while ((load = in.readLine()) != null) { } } catch (IOException e) { } InputStream epin = p.getErrorStream(); InputStreamReader ecin = new InputStreamReader(epin); BufferedReader ein = new BufferedReader(ecin); try { while ((load = ein.readLine()) != null) { } } catch (IOException e) { } ein.close(); in.close(); // ** } catch (IOException e) { System.out.println("Problems running: " + e.toString()); } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:es.bsc.servicess.ide.PackagingUtils.java
private static void instrumentOrchestrations(String runtime, String[] cls, IFolder classes, List<Dependency> depLibraries, IProgressMonitor myProgressMonitor) throws CoreException { Runtime rt = Runtime.getRuntime(); if (runtime != null && cls != null) { String classpath = new String(); for (Dependency d : depLibraries) { if (d.getType().equalsIgnoreCase(ProjectMetadata.JAR_DEP_TYPE) || d.getType().equalsIgnoreCase(ProjectMetadata.CLASS_FOLDER_DEP_TYPE)) classpath = classpath.concat(":" + d.getLocation()); }//from w w w.j a va 2 s . co m for (String cl : cls) { String command = new String( runtime + "/../scripts/instrument.sh " + cl + " " + classes.getLocation().toOSString() + classpath + " " + runtime + "/.." + " " + classes.getLocation().toOSString()); log.debug("Command to exec: " + command); Process ps; try { ps = rt.exec(command); BufferedReader stdInput = new BufferedReader(new InputStreamReader(ps.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(ps.getErrorStream())); String s = null; // read the output from the command log.debug("Here is the standard output of the command:\n"); while ((s = stdInput.readLine()) != null) { log.debug(s); } // read any errors from the attempted command log.debug("Here is the standard error of the command (if any):\n"); while ((s = stdError.readLine()) != null) { log.debug(s); } // if (ps.exitValue() != 0){ if (ps.waitFor() != 0) { throw (new CoreException( new Status(IStatus.ERROR, Activator.PLUGIN_ID, "metadata info not found"))); } } catch (IOException e) { CoreException ce = new CoreException( new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e)); ce.setStackTrace(e.getStackTrace()); throw (ce); } catch (InterruptedException e) { CoreException ce = new CoreException( new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e)); ce.setStackTrace(e.getStackTrace()); throw (ce); } } } else { throw (new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "metadata info not found"))); } }
From source file:rems.RunActualRqtsfunc.java
@Override public void run() { System.out.println("Running " + threadName); String dateStr = Global.getDB_Date_time(); //String dateStr = Global.getDB_Date_time(); String log_tbl = "rpt.rpt_run_msgs"; try {/*w ww .j av a 2 s .c om*/ long prgmID = Global.getGnrlRecID("rpt.rpt_prcss_rnnrs", "rnnr_name", "prcss_rnnr_id", Program.runnerName); Global.errorLog = "Successfully Started Thread Five\r\nProgram ID:" + prgmID + ": Program Name: " + Program.runnerName + "\r\n"; String[] macDet = Global.getMachDetails(); Global.errorLog += "PID: " + Global.pid + " Running on: " + macDet[0] + " / " + macDet[1] + " / " + macDet[2]; Global.writeToLog(); String rptTitle = ""; String jsprFileName = ""; String[] colsToGrp = { "" }; String[] colsToCnt = { "" }; String[] colsToSum = { "" }; String[] colsToAvrg = { "" }; String[] colsToFrmt = { "" }; String toMails = ""; String ccMails = ""; String bccMails = ""; String sbjct = ""; String msgBdy = ""; String attchMns = ""; long nwMsgSntID = -1; long toPrsnID = -1; long toCstmrSpplrID = -1; String[] errMsg = new String[1]; if (Global.runID > 0) { ResultSet runDtSt = Global.get_RptRun_Det(Global.runID); int alertID = -1; long locRptID = -1; long msgSentID = -1; String paramIDs = ""; String paramVals = ""; String outputUsd = ""; String orntnUsd = ""; String imgCols = ""; String rptLyout = ""; String rptOutpt = ""; String rptdlmtr = ""; //String rptType = Global.getGnrlRecNm("rpt.rpt_reports", "report_id", "rpt_or_sys_prcs", rpt_id); String rptType = ""; while (runDtSt.next()) { locRptID = runDtSt.getLong(6); alertID = runDtSt.getInt(14); msgSentID = runDtSt.getInt(15); Global.rnUser_ID = runDtSt.getLong(1); paramIDs = runDtSt.getString(7); paramVals = runDtSt.getString(8); outputUsd = runDtSt.getString(9); orntnUsd = runDtSt.getString(10); } ResultSet rptDtSt = Global.get_RptDet(locRptID); ResultSet alrtDtSt = Global.get_AlertDet(alertID); while (rptDtSt.next()) { imgCols = rptDtSt.getString(16); jsprFileName = rptDtSt.getString(20); rptLyout = rptDtSt.getString(15); rptOutpt = ""; rptdlmtr = rptDtSt.getString(17); //String rptType = Global.getGnrlRecNm("rpt.rpt_reports", "report_id", "rpt_or_sys_prcs", rpt_id); rptType = rptDtSt.getString(6); } String alertType = ""; if (alertID > 0) { while (alrtDtSt.next()) { alertType = alrtDtSt.getString(6); } alrtDtSt.beforeFirst(); } ResultSet prgmUntsDtSt = Global.get_AllPrgmUnts(locRptID); prgmUntsDtSt.last(); long prgUntsCnt = prgmUntsDtSt.getRow(); prgmUntsDtSt.beforeFirst(); Global.errorLog += "\r\nRun ID: " + Global.runID + " Report ID:" + locRptID + "\r\n"; Global.writeToLog(); long msg_id = Global.getGnrlRecID("rpt.rpt_run_msgs", "process_typ", "process_id", "msg_id", "Process Run", Global.runID); Global.updateLogMsg(msg_id, "\r\n\r\n\r\nLog Messages ==>\r\n\r\n" + Global.errorLog, log_tbl, dateStr, Global.rnUser_ID); Global.updateRptRn(Global.runID, "Preparing to Start...", 20); Global.logMsgID = msg_id; Global.logTbl = log_tbl; Global.gnrlDateStr = dateStr; long rpt_run_id = Global.runID; long rpt_id = locRptID; String w = "\\|"; String seps = "\\,"; String seps1 = "\\;"; String[] arry1 = paramIDs.split(w); String[] arry2 = paramVals.split(w); System.out.println(paramIDs); Global.ovrllDataCnt = 0; Global.strSB = new StringBuilder(""); //Program.updatePrgrm(prgmID); for (int q = 0; q < prgUntsCnt + 1; q++) { boolean isfirst = true; boolean islast = true; boolean shdAppnd = false; String rqrdParamVal = ""; String exclFileName = ""; if (q == prgUntsCnt) { islast = true; } else { islast = false; } if (prgUntsCnt > 0) { shdAppnd = true; } else { shdAppnd = false; } if (q == 0) { isfirst = true; //rpt_id = rpt_id; } else { isfirst = false; prgmUntsDtSt.next(); rpt_id = prgmUntsDtSt.getLong(1); rptDtSt = Global.get_RptDet(rpt_id); while (rptDtSt.next()) { outputUsd = rptDtSt.getString(13); orntnUsd = rptDtSt.getString(14); jsprFileName = rptDtSt.getString(20); //rptdlmtr = Global.getGnrlRecNm("rpt.rpt_reports", "report_id", "csv_delimiter", rpt_id); rptLyout = rptDtSt.getString(15); rptType = rptDtSt.getString(6); colsToGrp = rptDtSt.getString(8).split(seps); colsToCnt = rptDtSt.getString(9).split(seps); colsToSum = rptDtSt.getString(10).split(seps); colsToAvrg = rptDtSt.getString(11).split(seps); colsToFrmt = rptDtSt.getString(12).split(seps); } rptDtSt.beforeFirst(); } /*if (Global.callngAppType.equals("DESKTOP")) { if (!jsprFileName.equals("")) { Global.dwnldImgsFTP(15, Global.getRptDrctry() + "/jrxmls", jsprFileName); } }*/ String rpt_SQL = ""; if (alertID > 0 && msgSentID <= 0) { rpt_SQL = Global.get_Alert_SQL(alertID); } else { rpt_SQL = Global.get_Rpt_SQL(rpt_id); } for (int i = 0; i < arry1.length; i++) { long pID = Long.parseLong(arry1[i]); int h1 = Global.findArryIdx(Global.sysParaIDs, arry1[i]); if (h1 >= 0) { if (arry1[i].equals("-130") && i < arry2.length) { rptTitle = arry2[i]; } else if (arry1[i].equals("-140") && i < arry2.length) { if (q == 0) { colsToGrp = arry2[i].split(seps); } } else if (arry1[i].equals("-150") && i < arry2.length) { if (q == 0) { colsToCnt = arry2[i].split(seps); } } else if (arry1[i].equals("-160") && i < arry2.length) { if (q == 0) { colsToSum = arry2[i].split(seps); } } else if (arry1[i].equals("-170") && i < arry2.length) { if (q == 0) { colsToAvrg = arry2[i].split(seps); } } else if (arry1[i].equals("-180") && i < arry2.length) { if (q == 0) { colsToFrmt = arry2[i].split(seps); } } else if (arry1[i].equals("-190") && i < arry2.length) { //colsToGrp = arry2[i].Split(seps); } else if (arry1[i].equals("-200") && i < arry2.length) { //colsToGrp = arry2[i].Split(seps); } } else if (pID > 0 && i < arry2.length - 1) { String paramSqlRep = Global.getGnrlRecNm("rpt.rpt_report_parameters", "parameter_id", "paramtr_rprstn_nm_in_query", pID); rpt_SQL = rpt_SQL.replace(paramSqlRep, arry2[i]); if (paramSqlRep.equals("{:alert_type}") && rptType.contains("Alert")) { //alertType = arry2[i]; } if (paramSqlRep.equals("{:msg_body}") && rptType.equals("Alert(SQL Mail List)")) { rqrdParamVal = arry2[i]; } else if (paramSqlRep.equals("{:to_mail_list}") && rptType.equals("Alert(SQL Message)")) { rqrdParamVal = arry2[i]; } else if (paramSqlRep.equals("{:intrfc_tbl_name}") && rptType.equals("Journal Import")) { rqrdParamVal = arry2[i]; } else if (paramSqlRep.equals("{:orgID}")) { if (Global.tryParseInt(arry2[i])) { if (Integer.parseInt(arry2[i]) > 0) { Global.UsrsOrg_ID = Integer.parseInt(arry2[i]); } } } else if (paramSqlRep.equals("{:alert_type}")) { //alertType = arry2[i]; } else if (paramSqlRep.equals("{:excl_file_name}")) { exclFileName = arry2[i]; } else if (paramSqlRep.equals("{:documentTitle}")) { rptTitle = arry2[i]; } } } rpt_SQL = rpt_SQL.replace("{:usrID}", String.valueOf(Global.rnUser_ID)); rpt_SQL = rpt_SQL.replace("{:msgID}", String.valueOf(msg_id)); rpt_SQL = rpt_SQL.replace("{:orgID}", String.valueOf(Global.UsrsOrg_ID)); if (rptType.equals("Command Line Script")) { rpt_SQL = rpt_SQL.replace("{:host_name}", Global.Hostnme); rpt_SQL = rpt_SQL.replace("{:portnum}", Global.Portnum); } //NB. Be updating all report run statuses and percentages in the table Global.updateLogMsg(msg_id, "\r\n\r\n\r\nReport/Process SQL being executed is ==>\r\n\r\n" + rpt_SQL, log_tbl, dateStr, Global.rnUser_ID); //1. Execute SQL to get a dataset Global.updateRptRn(rpt_run_id, "Running SQL...", 40); //Program.updatePrgrm(prgmID); //worker.ReportProgress(40); ResultSet dtst = null; if (rptType.equals("Database Function")) { Global.executeGnrlSQL(rpt_SQL.replace("\r\n", " ").replace("\n", " ").replace("\r", " ")); } else if (rptType.equals("Command Line Script")) { rpt_SQL = rpt_SQL.replace("{:db_password}", Global.Pswd); String batchFilnm = Global.appStatPath + "/" + "REM_DBBackup" + String.valueOf(rpt_run_id) + ".bat"; PrintWriter fileWriter; fileWriter = new PrintWriter(batchFilnm, "UTF-8"); StringBuilder strSB = new StringBuilder(System.getProperty("line.separator")) .append(System.getProperty("line.separator")); strSB.append(rpt_SQL); fileWriter.println(strSB); fileWriter.close(); Runtime runTime = Runtime.getRuntime(); Process process = runTime.exec(batchFilnm); process.destroy(); Global.updateLogMsg(msg_id, "\r\n\r\nCommand Line Script Successfully Run!\r\n\r\n", log_tbl, dateStr, Global.rnUser_ID); boolean success = (new java.io.File(batchFilnm)).delete(); } else if (rptType.equals("Import/Overwrite Data from Excel") && !exclFileName.equals("")) { //Check if {:alert_type} EMAIL/SMS parameter was set //NB sql first column is address and 2nd col is message body //Global.imprtTrnsTmp(exclFileName, rpt_SQL.replace("\r\n", " ").replace("\n", " ").replace("\r", " ")); rpt_SQL = rpt_SQL.replace("{:orgnValColA}", ""); } else { dtst = Global.selectDataNoParams( rpt_SQL.replace("\r\n", " ").replace("\n", " ").replace("\r", " ")); } //Report Title is Message Title if Alert String uptFileUrl = ""; if (alertID > 0 && msgSentID <= 0) { alrtDtSt.next(); ResultSet dtstPrm = Global.get_RptParams(rpt_id); ResultSetMetaData dtstmd = dtst.getMetaData(); dtst.last(); int ttlRws = dtst.getRow(); dtst.beforeFirst(); int ttlCols = dtstmd.getColumnCount(); for (int z = 0; z < ttlRws; z++) { dtst.next(); toPrsnID = -1; toCstmrSpplrID = -1; toMails = alrtDtSt.getString(3); ccMails = alrtDtSt.getString(4); bccMails = alrtDtSt.getString(10); sbjct = alrtDtSt.getString(9); msgBdy = alrtDtSt.getString(5); attchMns = alrtDtSt.getString(18); for (int y = 0; y < ttlCols; y++) { toMails = toMails.replace("{:" + dtstmd.getColumnName(y + 1) + "}", dtst.getString(y + 1)); ccMails = ccMails.replace("{:" + dtstmd.getColumnName(y + 1) + "}", dtst.getString(y + 1)); bccMails = bccMails.replace("{:" + dtstmd.getColumnName(y + 1) + "}", dtst.getString(y + 1)); sbjct = sbjct.replace("{:" + dtstmd.getColumnName(y + 1) + "}", dtst.getString(y + 1)); msgBdy = msgBdy.replace("{:" + dtstmd.getColumnName(y + 1) + "}", dtst.getString(y + 1)); attchMns = attchMns.replace("{:" + dtstmd.getColumnName(y + 1) + "}", dtst.getString(y + 1)); if (dtstmd.getColumnName(y + 1).equals("toPrsnID")) { toPrsnID = Long.parseLong(dtst.getString(y + 1)); } if (dtstmd.getColumnName(y + 1).equals("toCstmrSpplrID")) { toCstmrSpplrID = Long.parseLong(dtst.getString(y + 1)); } } Thread.sleep(1000); nwMsgSntID = Global.getNewMsgSentID(); Global.createAlertMsgSent(nwMsgSntID, toMails, ccMails, msgBdy, dateStr, sbjct, rpt_id, bccMails, toPrsnID, toCstmrSpplrID, alertID, attchMns, alertType); if (alrtDtSt.getString(13).equals("1")) { String prmIDs = ""; String prmVals = ""; String prmValsFnd = ""; dtstPrm.last(); int ttldtstPrm = dtstPrm.getRow(); dtstPrm.beforeFirst(); for (int x = 0; x < ttldtstPrm; x++) { dtstPrm.next(); prmIDs += dtstPrm.getString(1) + "|"; prmValsFnd = dtstPrm.getString(4); for (int r = 0; r < ttlCols; r++) { if (dtstPrm.getString(3).equals("{:" + dtstmd.getColumnName(r + 1) + "}")) { prmValsFnd = dtst.getString(r + 1); break; } } prmVals += prmValsFnd + "|"; } String colsToGrp1 = ""; String colsToCnt1 = ""; String colsToSum1 = ""; String colsToAvrg1 = ""; String colsToFrmt1 = ""; String rpTitle = ""; while (rptDtSt.next()) { colsToGrp1 = rptDtSt.getString(8); colsToCnt1 = rptDtSt.getString(9); colsToSum1 = rptDtSt.getString(10); colsToAvrg1 = rptDtSt.getString(11); colsToFrmt1 = rptDtSt.getString(12); rpTitle = rptDtSt.getString(1); } //Report Title prmVals += rpTitle + "|"; prmIDs += Global.sysParaIDs[0] + "|"; //Cols To Group prmVals += colsToGrp1 + "|"; prmIDs += Global.sysParaIDs[1] + "|"; //Cols To Count prmVals += colsToCnt1 + "|"; prmIDs += Global.sysParaIDs[2] + "|"; //Cols To Sum prmVals += colsToSum1 + "|"; prmIDs += Global.sysParaIDs[3] + "|"; //colsToAvrg prmVals += colsToAvrg1 + "|"; prmIDs += Global.sysParaIDs[4] + "|"; //colsToFrmt prmVals += colsToFrmt1 + "|"; prmIDs += Global.sysParaIDs[5] + "|"; //outputUsd prmVals += outputUsd + "|"; prmIDs += Global.sysParaIDs[6] + "|"; //orntnUsd prmVals += orntnUsd + "|"; prmIDs += Global.sysParaIDs[7] + "|"; Program.gnrtAlertMailerfunc(rpt_id, Global.rnUser_ID, alertID, nwMsgSntID, prmIDs, prmVals, outputUsd, orntnUsd); } else if (alertType.equals("Email")) { errMsg = new String[1]; if (Global.sendEmail(StringUtils.strip(toMails.replace(",", ";"), seps1), StringUtils.strip(ccMails.replace(",", ";"), seps1), StringUtils.strip(bccMails.replace(",", ";"), seps1), StringUtils.strip(attchMns.replace(",", ";"), seps1), sbjct, msgBdy, errMsg) == false) { Global.updateAlertMsgSent(nwMsgSntID, dateStr, "0", Arrays.toString(errMsg)); } else { Global.updateAlertMsgSent(nwMsgSntID, dateStr, "1", ""); } } else if (alertType.equals("SMS")) { errMsg = new String[1]; if (Global.sendSMS(msgBdy, StringUtils.strip( (toMails + ";" + ccMails + ";" + bccMails).replace(";", ","), seps), errMsg) == false) { Global.updateAlertMsgSent(nwMsgSntID, dateStr, "0", Arrays.toString(errMsg)); } else { Global.updateAlertMsgSent(nwMsgSntID, dateStr, "1", ""); } } else { } if ((z % 100) == 0) { Thread.sleep(60000); } } } else if (rptType.equals("System Process")) { } else if (rptType.equals("Alert(SQL Mail List)")) { //check if {:msg_body} and {:alert_type} parameter was set //NB sql first column must be valid email address } else if (rptType.equals("Alert(SQL Mail List & Message)")) { //Check if {:alert_type} EMAIL/SMS parameter was set //NB sql first column is address and 2nd col is message body } else if (rptType.equals("Posting of GL Trns. Batches")) { //NB sql col0=batch_id, col1=batch_name, col2=batch_source, col3=batch_status, col4=batch_status_meaning //i.e SQL Must Contain accb.accb_trnsctn_batches and all the colnames above // ResultSet wrngDtst = Global.get_WrongBalncs(Global.UsrsOrg_ID); wrngDtst.last(); int rwCnt = wrngDtst.getRow(); wrngDtst.beforeFirst(); if (rwCnt > 0) { wrngDtst.next(); Global.updateLogMsg(msg_id, "\r\n\r\nCannot Post this Batch Since Some Accounts have wrong Balances!" + "\r\nPlease correct the Imbalance First!!\r\nUser Org ID=" + Global.UsrsOrg_ID + "\r\nNumber of Records Involved=" + rwCnt + "\r\n\r\n", log_tbl, dateStr, Global.rnUser_ID); Program.correctImblns(); Global.updateRptRnStopCmd(Global.runID, "1"); Program.checkNClosePrgrm(); return; } else { //Check if no other accounting process is running boolean isAnyRnng = true; int witcntr = 0; do { witcntr++; isAnyRnng = Global.isThereANActvActnPrcss("1,2,3,4,5,6", "10 second"); if (witcntr > 8) { Global.updateRptRnStopCmd(Global.runID, "1"); } Program.checkNClosePrgrm(); Thread.sleep(5000); } while (isAnyRnng == true); dtst.beforeFirst(); dtst.last(); int rwsTtl = dtst.getRow(); dtst.beforeFirst(); for (int rh = 0; rh < rwsTtl; rh++) { dtst.next(); Global.updtActnPrcss(5); Program.validateBatchNPost(Long.parseLong(dtst.getString(1)), dtst.getString(4), dtst.getString(3), msg_id, log_tbl, dateStr); Thread.sleep(200); } } } else if (rptType.equals("Journal Import")) { //check if {:intrfc_tbl_name} parameter was set /*NB sql col0=accnt_id, col1=trnsctn_date(DD-Mon-YYYY HH24:MI:SS), * col2=dbt_amount, col3=crdt_amount, col4=net_amount, col5=func_cur_id*/ // String[] errmsg = new String[1]; int prcID = 8;//Internal Payments Import Process if (rqrdParamVal.equals("scm.scm_gl_interface")) { prcID = 7; } boolean isAnyRnng = true; int witcntr = 0; do { witcntr++; isAnyRnng = Global.isThereANActvActnPrcss(String.valueOf(prcID), "10 second"); if (witcntr > 8) { Global.updateRptRnStopCmd(Global.runID, "1"); Program.killThreads(); } Program.updatePrgrm(prgmID); Thread.sleep(5000); } while (isAnyRnng == true); Global.updtActnPrcss(prcID); if (Program.sendJournalsToGL(dtst, rqrdParamVal, prcID, errmsg)) { Global.updateLogMsg(msg_id, "\r\n\r\nJournals Successfully Sent to GL!\r\n" + errmsg, log_tbl, dateStr, Global.rnUser_ID); } else { Global.updateLogMsg(msg_id, "\r\n\r\nFailed to send Journals to GL!\r\n" + errmsg, log_tbl, dateStr, Global.rnUser_ID); } } else if (rpt_id == Global.getRptID("Send Outstanding Bulk Messages")) { String lastTimeChckd = Global.getDB_Date_time(); int lstChckCnt = 0; int row_cntr = 0; errMsg = new String[1]; boolean tmeUp = false; do { dateStr = lastTimeChckd; if (lstChckCnt > 0) { dtst = Global.selectDataNoParams( rpt_SQL.replace("\r\n", " ").replace("\n", " ").replace("\r", " ")); } dtst.last(); row_cntr = dtst.getRow(); dtst.beforeFirst(); for (int v = 0; v < row_cntr; v++) { dtst.next(); String msgTyp = dtst.getString(14); toMails = dtst.getString(3); ccMails = dtst.getString(4); bccMails = dtst.getString(8); attchMns = dtst.getString(13); sbjct = dtst.getString(7); msgBdy = dtst.getString(5); nwMsgSntID = Long.parseLong(dtst.getString(1)); errMsg = new String[1]; if (msgTyp.equals("Email")) { if (Global.sendEmail(StringUtils.strip(toMails.replace(",", ";"), seps1), StringUtils.strip(ccMails.replace(",", ";"), seps1), StringUtils.strip(bccMails.replace(",", ";"), seps1), StringUtils.strip(attchMns.replace(",", ";"), seps1), sbjct, msgBdy, errMsg) == false) { Global.updateBulkMsgSent(nwMsgSntID, dateStr, "0", Arrays.toString(errMsg)); Global.updateLogMsg(msg_id, "\r\n\r\nMessage to " + (toMails + ";" + ccMails + ";" + bccMails) .replace(";", ",") + " Failed!\r\n" + Arrays.toString(errMsg), log_tbl, dateStr, Global.rnUser_ID); } else { Global.updateBulkMsgSent(nwMsgSntID, dateStr, "1", ""); Global.updateLogMsg(msg_id, "\r\n\r\nMessage to " + (toMails + ";" + ccMails + ";" + bccMails) .replace(";", ",") + " Successfully Sent!\r\n", log_tbl, dateStr, Global.rnUser_ID); } } else if (msgTyp.equals("SMS")) { if (Global.sendSMS(msgBdy, StringUtils.strip( (toMails + ";" + ccMails + ";" + bccMails).replace(";", ","), seps), errMsg) == false) { Global.updateBulkMsgSent(nwMsgSntID, dateStr, "0", Arrays.toString(errMsg)); Global.updateLogMsg(msg_id, "\r\n\r\nMessage to " + (toMails + ";" + ccMails + ";" + bccMails) .replace(";", ",") + " Failed!\r\n" + Arrays.toString(errMsg), log_tbl, dateStr, Global.rnUser_ID); } else { Global.updateBulkMsgSent(nwMsgSntID, dateStr, "1", ""); Global.updateLogMsg(msg_id, "\r\n\r\nMessage to " + (toMails + ";" + ccMails + ";" + bccMails) .replace(";", ",") + " Successfully Sent!\r\n", log_tbl, dateStr, Global.rnUser_ID); } } else { } if (v == (row_cntr - 1)) { lastTimeChckd = Global.getDB_Date_time(); } Thread.sleep(500); Global.errorLog = "\r\nMessages to " + (toMails + ";" + ccMails + ";" + bccMails) + " worked on"; Global.writeToLog(); } dtst.close(); lstChckCnt++; Thread.sleep(5000); tmeUp = Global.doesDteTmExcdIntvl("30 second", lastTimeChckd); } while (tmeUp == false); Global.updateLogMsg(msg_id, "\r\n\r\nFinished Sending all Messages!\r\n", log_tbl, dateStr, Global.rnUser_ID); } if (rpt_id == Global.getRptID("Send Outstanding Bulk Messages")) { dtst = Global.selectDataNoParams( rpt_SQL.replace("\r\n", " ").replace("\n", " ").replace("\r", " ")); } int totl = 0; ResultSetMetaData dtstmd = null; if (dtst != null) { dtst.beforeFirst(); dtst.last(); totl = dtst.getRow(); dtst.beforeFirst(); dtstmd = dtst.getMetaData(); } if (totl > 0) { Global.updateLogMsg(msg_id, "\r\n\r\nSQL Statement successfully run! Total Records = " + totl, log_tbl, dateStr, Global.rnUser_ID); //2. Check and Format Output in the dataset if Required //Based on the 4 Output types decide what to do //None|MICROSOFT EXCEL|HTML|STANDARD Global.updateRptRn(rpt_run_id, "Formatting Output...", 60); //Program.updatePrgrm(prgmID); //worker.ReportProgress(60); //String outputFileName = ""; rpt_SQL = rpt_SQL.replace("\r\n", " ").replace("\n", " ").replace("\r", " "); if (!jsprFileName.equals("")) { jsprFileName = Global.getRptDrctry() + "/jrxmls/" + jsprFileName; String outFlNmOnly = ""; if (outputUsd.equals("MICROSOFT EXCEL")) { uptFileUrl = Global.getRptDrctry() + "/" + String.valueOf(rpt_run_id) + ".xls"; outFlNmOnly = "/" + String.valueOf(rpt_run_id) + ".xls"; Global.runReport(outputUsd, uptFileUrl, jsprFileName, rptTitle, rpt_SQL); } else if (outputUsd.equals("PDF")) { uptFileUrl = Global.getRptDrctry() + "/" + String.valueOf(rpt_run_id) + ".pdf"; outFlNmOnly = "/" + String.valueOf(rpt_run_id) + ".pdf"; Global.updateLogMsg(Global.logMsgID, "\r\nBefore Jasper..." + uptFileUrl, Global.logTbl, Global.gnrlDateStr, Global.rnUser_ID); Global.runReport(outputUsd, uptFileUrl, jsprFileName, rptTitle, rpt_SQL); } else if (outputUsd.equals("HTML")) { uptFileUrl = Global.getRptDrctry() + "/amcharts_2100/samples/" + String.valueOf(rpt_run_id) + ".html"; outFlNmOnly = "/amcharts_2100/samples/" + String.valueOf(rpt_run_id) + ".html"; Global.runReport(outputUsd, uptFileUrl, jsprFileName, rptTitle, rpt_SQL); } else if (outputUsd.equals("STANDARD")) { uptFileUrl = Global.getRptDrctry() + "/" + String.valueOf(rpt_run_id) + ".pdf"; outFlNmOnly = "/" + String.valueOf(rpt_run_id) + ".pdf"; Global.runReport(outputUsd, uptFileUrl, jsprFileName, rptTitle, rpt_SQL); } else if (outputUsd.equals("MICROSOFT WORD")) { uptFileUrl = Global.getRptDrctry() + "/" + String.valueOf(rpt_run_id) + ".rtf"; outFlNmOnly = "/" + String.valueOf(rpt_run_id) + ".rtf"; Global.runReport(outputUsd, uptFileUrl, jsprFileName, rptTitle, rpt_SQL); } else if (outputUsd.equals("CHARACTER SEPARATED FILE (CSV)")) { uptFileUrl = Global.getRptDrctry() + "/" + String.valueOf(rpt_run_id) + ".csv"; outFlNmOnly = "/" + String.valueOf(rpt_run_id) + ".csv"; Global.runReport(outputUsd, uptFileUrl, jsprFileName, rptTitle, rpt_SQL); } else { outputUsd = "PDF"; uptFileUrl = Global.getRptDrctry() + "/" + String.valueOf(rpt_run_id) + ".pdf"; outFlNmOnly = "/" + String.valueOf(rpt_run_id) + ".pdf"; Global.runReport(outputUsd, uptFileUrl, jsprFileName, rptTitle, rpt_SQL); } System.out.println("Finished and Opening report..."); if (Global.callngAppType.equals("DESKTOP")) { Global.upldImgsFTP(9, Global.getRptDrctry(), outFlNmOnly); } } else if (outputUsd.equals("CHARACTER SEPARATED FILE (CSV)")) { Global.exprtDtStToCSV(dtst, Global.getRptDrctry() + "/" + String.valueOf(rpt_run_id) + ".csv", isfirst, islast, shdAppnd, rptdlmtr); uptFileUrl = Global.getRptDrctry() + "/" + String.valueOf(rpt_run_id) + ".csv"; } else if (outputUsd.equals("COLUMN CHART")) { Global.exprtToHTMLSCC( dtst, Global.getRptDrctry() + "/amcharts_2100/samples/" + String.valueOf(rpt_run_id) + ".html", rptTitle, colsToGrp, colsToCnt, isfirst, islast, shdAppnd); uptFileUrl = Global.getRptDrctry() + "/amcharts_2100/samples/" + String.valueOf(rpt_run_id) + ".html"; } else if (outputUsd.equals("PIE CHART"))// { Global.exprtToHTMLPC( dtst, Global.getRptDrctry() + "/amcharts_2100/samples/" + String.valueOf(rpt_run_id) + ".html", rptTitle, colsToGrp, colsToCnt, isfirst, islast, shdAppnd); uptFileUrl = Global.getRptDrctry() + "/amcharts_2100/samples/" + String.valueOf(rpt_run_id) + ".html"; } else if (outputUsd.equals("LINE CHART"))// { Global.exprtToHTMLLC( dtst, Global.getRptDrctry() + "/amcharts_2100/samples/" + String.valueOf(rpt_run_id) + ".html", rptTitle, colsToGrp, colsToCnt, isfirst, islast, shdAppnd); uptFileUrl = Global.getRptDrctry() + "/amcharts_2100/samples/" + String.valueOf(rpt_run_id) + ".html"; } else if (outputUsd.equals("STANDARD")) { if (rptLyout.equals("None") || rptLyout.equals("TABULAR")) { if (totl == 1 && dtstmd.getColumnCount() == 1) { rptOutpt += dtst.getString(1); } else { rptOutpt += Program.formatDtSt(dtst, rptTitle, colsToGrp, colsToCnt, colsToSum, colsToAvrg, colsToFrmt); } } else if (rptLyout.equals("DETAIL")) { //Show detail STANDARD Report } if (islast) { Program.writeAFile( Global.getRptDrctry() + "/" + String.valueOf(rpt_run_id) + ".txt", rptOutpt); if (Global.callngAppType.equals("DESKTOP")) { Global.upldImgsFTP(9, Global.getRptDrctry(), String.valueOf(Global.runID) + ".txt"); } uptFileUrl = Global.getRptDrctry() + "/" + String.valueOf(rpt_run_id) + ".txt"; } } else { Global.updateRptRnOutptUsd(rpt_run_id, "HTML"); if (rptLyout.equals("None") || rptLyout.equals("TABULAR")) { Global.exprtToHTMLTblr(dtst, Global.getRptDrctry() + "/amcharts_2100/samples/" + String.valueOf(rpt_run_id) + ".html", rptTitle, colsToGrp, colsToCnt, colsToSum, colsToAvrg, colsToFrmt, isfirst, islast, shdAppnd); } else if (rptLyout.equals("DETAIL")) { //Show detail HTML Report ResultSet grpngsDtSt = Global.get_AllGrpngs(rpt_id); Global.exprtToHTMLDet(dtst, grpngsDtSt, Global.getRptDrctry() + "/amcharts_2100/samples/" + String.valueOf(rpt_run_id) + ".html", rptTitle, isfirst, islast, shdAppnd, orntnUsd, imgCols); } uptFileUrl = Global.getRptDrctry() + "/amcharts_2100/samples/" + String.valueOf(rpt_run_id) + ".html"; } Global.updateRptRn(rpt_run_id, "Storing Output...", 80); //worker.ReportProgress(80); Global.updateLogMsg(msg_id, "\r\n\r\nSaving Report Output...", log_tbl, dateStr, Global.rnUser_ID); Global.updateRptRnOutpt(rpt_run_id, rptOutpt); Global.updateLogMsg(msg_id, "\r\n\r\nSuccessfully Saved Report Output...", log_tbl, dateStr, Global.rnUser_ID); if (msgSentID > 0) { Global.updateRptRn(rpt_run_id, "Sending Output...", 81); Global.updateLogMsg(msg_id, "\r\n\r\nSending Report Via Mail/SMS...", log_tbl, dateStr, Global.rnUser_ID); ResultSet msgDtSt = Global.get_MsgSentDet(msgSentID); msgDtSt.next(); toMails = msgDtSt.getString(1); ccMails = msgDtSt.getString(2); bccMails = msgDtSt.getString(7); sbjct = msgDtSt.getString(5); msgBdy = msgDtSt.getString(3); attchMns = msgDtSt.getString(15) + ";" + uptFileUrl; toPrsnID = Long.parseLong(msgDtSt.getString(8)); toCstmrSpplrID = Long.parseLong(msgDtSt.getString(9)); alertType = msgDtSt.getString(16); errMsg = new String[1]; if (alertType.equals("Email")) { if (Global.sendEmail(StringUtils.strip(toMails.replace(",", ";"), seps1), StringUtils.strip(ccMails.replace(",", ";"), seps1), StringUtils.strip(bccMails.replace(",", ";"), seps1), StringUtils.strip(attchMns.replace(",", ";"), seps1), sbjct, msgBdy, errMsg) == false) { Global.updateAlertMsgSent(nwMsgSntID, dateStr, "0", Arrays.toString(errMsg)); } else { Global.updateAlertMsgSent(nwMsgSntID, dateStr, "1", ""); } } else if (alertType.equals("SMS")) { if (Global.sendSMS(msgBdy, StringUtils.strip( (toMails + ";" + ccMails + ";" + bccMails).replace(";", ","), seps), errMsg) == false) { Global.updateAlertMsgSent(nwMsgSntID, dateStr, "0", Arrays.toString(errMsg)); } else { Global.updateAlertMsgSent(nwMsgSntID, dateStr, "1", ""); } } else { } Thread.sleep(1500); } Global.updateLogMsg(msg_id, "\r\n\r\nSuccessfully Completed Process/Report Run...", log_tbl, dateStr, Global.rnUser_ID); Global.updateRptRn(rpt_run_id, "Completed!", 100); if (rptType.equals("Alert(SQL Message)")) { //check if {:to_mail_list} and {:alert_type} parameter was set //NB entire sql output is message body //Report Output file must be added as attachment } } else { Global.updateLogMsg(msg_id, "\r\n\r\nSQL Statement yielded no Results!", log_tbl, dateStr, Global.rnUser_ID); Global.updateLogMsg(msg_id, "\r\n\r\nSuccessfully Completed Process/Report Run...", log_tbl, dateStr, Global.rnUser_ID); Global.updateRptRn(rpt_run_id, "Completed!", 100); } } Program.killThreads(); } Program.killThreads(); } catch (SQLException ex) { Global.errorLog = ex.getMessage() + "\r\n\r\n" + Arrays.toString(ex.getStackTrace()) + "\r\n\r\n"; Global.writeToLog(); Global.updateRptRn(Global.runID, "Error!", 100); long msg_id = Global.getGnrlRecID("rpt.rpt_run_msgs", "process_typ", "process_id", "msg_id", "Process Run", Global.runID); Global.updateLogMsg(msg_id, "\r\n\r\n\r\nThe Program has Errored Out ==>\r\n\r\n" + Global.errorLog, log_tbl, dateStr, Global.rnUser_ID); Program.killThreads(); } catch (NumberFormatException ex) { Global.errorLog = ex.getMessage() + "\r\n\r\n" + Arrays.toString(ex.getStackTrace()) + "\r\n\r\n"; Global.writeToLog(); Global.updateRptRn(Global.runID, "Error!", 100); long msg_id = Global.getGnrlRecID("rpt.rpt_run_msgs", "process_typ", "process_id", "msg_id", "Process Run", Global.runID); Global.updateLogMsg(msg_id, "\r\n\r\n\r\nThe Program has Errored Out ==>\r\n\r\n" + Global.errorLog, log_tbl, dateStr, Global.rnUser_ID); Program.killThreads(); } catch (IOException ex) { Global.errorLog = ex.getMessage() + "\r\n\r\n" + Arrays.toString(ex.getStackTrace()) + "\r\n\r\n"; Global.writeToLog(); Global.updateRptRn(Global.runID, "Error!", 100); long msg_id = Global.getGnrlRecID("rpt.rpt_run_msgs", "process_typ", "process_id", "msg_id", "Process Run", Global.runID); Global.updateLogMsg(msg_id, "\r\n\r\n\r\nThe Program has Errored Out ==>\r\n\r\n" + Global.errorLog, log_tbl, dateStr, Global.rnUser_ID); Program.killThreads(); } catch (InterruptedException ex) { Global.errorLog = ex.getMessage() + "\r\n\r\n" + Arrays.toString(ex.getStackTrace()) + "\r\n\r\n"; Global.writeToLog(); Global.updateRptRn(Global.runID, "Error!", 100); long msg_id = Global.getGnrlRecID("rpt.rpt_run_msgs", "process_typ", "process_id", "msg_id", "Process Run", Global.runID); Global.updateLogMsg(msg_id, "\r\n\r\n\r\nThe Program has Errored Out ==>\r\n\r\n" + Global.errorLog, log_tbl, dateStr, Global.rnUser_ID); Program.killThreads(); } finally { } }
From source file:com.ikanow.infinit.e.core.mapreduce.HadoopJobRunner.java
@SuppressWarnings("unused") private String runHadoopJob_commandLine(CustomMapReduceJobPojo job, String jar) { String jobid = null;/*from ww w . j a v a2 s .c o m*/ try { job.tempConfigXMLLocation = createConfigXML_commandLine(job.jobtitle, job.inputCollection, job._id.toString(), job.tempConfigXMLLocation, job.mapper, job.reducer, job.combiner, getQueryOrProcessing(job.query, QuerySpec.QUERY), job.communityIds, job.isCustomTable, job.getOutputDatabase(), job.outputKey, job.outputValue, job.outputCollectionTemp, job.arguments); Runtime rt = Runtime.getRuntime(); String[] commands = new String[] { "hadoop", "--config", prop_custom.getHadoopConfigPath() + "/hadoop", "jar", jar, "-conf", job.tempConfigXMLLocation }; String command = ""; for (String s : commands) command += s + " "; Process pr = rt.exec(commands); //Once we start running the command attach to stderr to //receive the output to parse out the jobid InputStream in = pr.getErrorStream(); InputStreamReader is = new InputStreamReader(in); BufferedReader br = new BufferedReader(is); StringBuilder output = new StringBuilder(); String line = null; long startTime = new Date().getTime(); boolean bGotJobId = false; //while we haven't found the id, there are still lines to read, and it hasn't been more than 60 seconds while (!bGotJobId && (line = br.readLine()) != null && (new Date().getTime() - startTime) < SECONDS_60) { output.append(line); int getJobIdIndex = -1; String searchstring = "INFO mapred.JobClient: Running job: "; if ((getJobIdIndex = line.indexOf(searchstring)) >= 0) { // Get JobId and trim() it (obviously trivial) jobid = line.substring(getJobIdIndex + searchstring.length()).trim(); bGotJobId = true; } } //60 seconds passed and we never found the id if (!bGotJobId) { _logger.info("job_start_timeout_error_title=" + job.jobtitle + " job_start_timeout_error_id=" + job._id.toString() + " job_start_timeout_error_message=" + output.toString()); //if we never found the id mark it as errored out return "Error:\n" + output.toString(); } } catch (Exception ex) { //had an error running command //probably log error to the job so we stop trying to run it _logger.info("job_start_timeout_error_title=" + job.jobtitle + " job_start_timeout_error_id=" + job._id.toString() + " job_start_timeout_error_message=" + HarvestExceptionUtils.createExceptionMessage(ex)); jobid = "Error:\n" + ex.getMessage(); // (means this gets displayed) } return jobid; }
From source file:com.panet.imeta.trans.steps.luciddbbulkloader.LucidDBBulkLoader.java
public boolean execute(LucidDBBulkLoaderMeta meta, boolean wait) throws KettleException { Runtime rt = Runtime.getRuntime(); try {// w ww . j a va 2s . c o m String tableName = environmentSubstitute(meta.getTableName()); // 1) Set up the FIFO folder, create the directory and path to it... // String fifoVfsDirectory = environmentSubstitute(meta.getFifoDirectory()); FileObject directory = KettleVFS.getFileObject(fifoVfsDirectory); directory.createFolder(); String fifoDirectory = KettleVFS.getFilename(directory); // 2) Create the FIFO file using the "mkfifo" command... // Make sure to log all the possible output, also from STDERR // data.fifoFilename = KettleVFS.getFilename(directory) + Const.FILE_SEPARATOR + tableName + ".csv"; data.bcpFilename = KettleVFS.getFilename(directory) + Const.FILE_SEPARATOR + tableName + ".bcp"; File fifoFile = new File(data.fifoFilename); if (!fifoFile.exists()) { String mkFifoCmd = "mkfifo " + data.fifoFilename + ""; logBasic("Creating FIFO file using this command : " + mkFifoCmd); Process mkFifoProcess = rt.exec(mkFifoCmd); StreamLogger errorLogger = new StreamLogger(mkFifoProcess.getErrorStream(), "mkFifoError"); StreamLogger outputLogger = new StreamLogger(mkFifoProcess.getInputStream(), "mkFifoOuptut"); new Thread(errorLogger).start(); new Thread(outputLogger).start(); int result = mkFifoProcess.waitFor(); if (result != 0) { throw new Exception("Return code " + result + " received from statement : " + mkFifoCmd); } } // 3) Make a connection to LucidDB for sending SQL commands // (Also, we need a clear cache for getting up-to-date target metadata) DBCache.getInstance().clear(meta.getDatabaseMeta().getName()); data.db = new Database(meta.getDatabaseMeta()); data.db.shareVariablesWith(this); // Connect to the database if (getTransMeta().isUsingUniqueConnections()) { synchronized (getTrans()) { data.db.connect(getTrans().getThreadName(), getPartitionID()); } } else { data.db.connect(getPartitionID()); } logBasic("Connected to LucidDB"); // 4) Now we are ready to create the LucidDB FIFO server that will handle the actual bulk loading. // String fifoServerStatement = ""; fifoServerStatement += "create or replace server " + meta.getFifoServerName() + Const.CR; fifoServerStatement += "foreign data wrapper sys_file_wrapper" + Const.CR; fifoServerStatement += "options (" + Const.CR; fifoServerStatement += "directory '" + fifoDirectory + "'," + Const.CR; fifoServerStatement += "file_extension 'csv'," + Const.CR; fifoServerStatement += "with_header 'no'," + Const.CR; fifoServerStatement += "num_rows_scan '0'," + Const.CR; fifoServerStatement += "lenient 'no');" + Const.CR; logBasic("Creating LucidDB fifo_server with the following command: " + fifoServerStatement); data.db.execStatements(fifoServerStatement); // 5) Set the error limit in the LucidDB session // REVIEW jvs 13-Dec-2008: is this guaranteed to retain the same // connection? String errorMaxStatement = ""; errorMaxStatement += "alter session set \"errorMax\" = " + meta.getMaxErrors() + ";" + Const.CR; logBasic("Setting error limit in LucidDB session with the following command: " + errorMaxStatement); data.db.execStatements(errorMaxStatement); // 6) Now we also need to create a bulk loader file .bcp // createBulkLoadConfigFile(data.bcpFilename); // 7) execute the actual load command! // This will actually block until the load is done in the // separate execution thread; see notes in executeLoadCommand // on why it's important for this to occur BEFORE // opening our end of the FIFO. // executeLoadCommand(tableName); // 8) We have to write rows to the FIFO file later on. data.fifoStream = new BufferedOutputStream(new FileOutputStream(fifoFile)); } catch (Exception ex) { throw new KettleException(ex); } return true; }
From source file:Classes.MainForm.java
private void initMainForm() throws IOException {//create sally form switch (getPrayerTimesHandler().getActualPrayerTime()) {//set background case 0:// w ww . j av a2 s. co m this.backgroundImage = new ImageIcon(getClass().getResource(duhrBackground)).getImage(); break; case 1: this.backgroundImage = new ImageIcon(getClass().getResource(shorou9Background)).getImage(); break; case 2: this.backgroundImage = new ImageIcon(getClass().getResource(fajrBackground)).getImage(); break; case 3: this.backgroundImage = new ImageIcon(getClass().getResource(ishaaBackground)).getImage(); break; case 4: this.backgroundImage = new ImageIcon(getClass().getResource(maghribBackground)).getImage(); break; case 5: this.backgroundImage = new ImageIcon(getClass().getResource(asrBackground)).getImage(); break; default: this.backgroundImage = new ImageIcon(getClass().getResource(shorou9Background)).getImage(); break; } this.mainFrame = new JFrame(); this.mainPanel = new MainImagePanel(getBackgroundImage(), prayerTimesHandler.getActualPrayerTime()); this.mainPanel.setLayout(null); this.font = new Font("TimesRoman", Font.ITALIC, 15); this.locationFont = new Font("TimesRoman", Font.ITALIC, 22); this.digitalClockfont = new Font("TimesRoman", Font.ROMAN_BASELINE, 20); this.fontMiladiHijriTimes = new Font("TimesRoman", Font.ROMAN_BASELINE, 13); this.fontNextPrayer = new Font("TimesRoman", Font.ROMAN_BASELINE, 20); this.exitLabel = new JLabel(); this.hijriTime = new JLabel("", SwingConstants.RIGHT); this.miladiTime = new JLabel(); this.location = new JLabel(locationValue); this.location.setHorizontalAlignment(SwingConstants.CENTER); this.locationFromInternet = new JLabel(); //get all translated salat names this.fajrName = new JLabel(PropertiesHandler.getSingleton().getValue(1020)); this.fajrName.setHorizontalAlignment(SwingConstants.CENTER); this.fajrTime = new JLabel(); this.fajrTime.setHorizontalAlignment(SwingConstants.CENTER); this.shorou9Name = new JLabel(PropertiesHandler.getSingleton().getValue(1021)); this.shorou9Name.setHorizontalAlignment(SwingConstants.CENTER); this.shorou9Time = new JLabel(); this.shorou9Time.setHorizontalAlignment(SwingConstants.CENTER); this.duhrName = new JLabel(PropertiesHandler.getSingleton().getValue(1022)); this.duhrName.setHorizontalAlignment(SwingConstants.CENTER); this.duhrTime = new JLabel(); this.duhrTime.setHorizontalAlignment(SwingConstants.CENTER); this.asrName = new JLabel(PropertiesHandler.getSingleton().getValue(1023)); this.asrName.setHorizontalAlignment(SwingConstants.CENTER); this.asrTime = new JLabel(); this.asrTime.setHorizontalAlignment(SwingConstants.CENTER); this.maghribName = new JLabel(PropertiesHandler.getSingleton().getValue(1024)); this.maghribName.setHorizontalAlignment(SwingConstants.CENTER); this.maghribTime = new JLabel(); this.maghribTime.setHorizontalAlignment(SwingConstants.CENTER); this.ishaaName = new JLabel(PropertiesHandler.getSingleton().getValue(1025)); this.ishaaName.setHorizontalAlignment(SwingConstants.CENTER); this.ishaaTime = new JLabel(); this.ishaaTime.setHorizontalAlignment(SwingConstants.CENTER); this.digitalClock = new JLabel(); this.nextPrayer = new JLabel(); this.settings = new JLabel(); this.exitLabel.setIcon(exitIcon); this.settings.setIcon(settingsIcon); this.locationFromInternet.setIcon(locationfromInternetIconMain); this.nextDayPrayerTimes = new JLabel(new ImageIcon(getClass().getResource(nextDayPrayerTimesIcon))); this.previousDayPrayerTimes = new JLabel(new ImageIcon(getClass().getResource(previousDayPrayerTimesIcon))); this.actualDayPrayerTimes = new JLabel(new ImageIcon(getClass().getResource(actualDayPrayerTimesIcon))); this.previousDayPrayerTimes.setBounds(480, 275, 15, 15); this.actualDayPrayerTimes.setBounds(500, 275, 15, 15); this.nextDayPrayerTimes.setBounds(520, 275, 15, 15); this.nextDayPrayerTimes.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { nextPreviousDay++; Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, nextPreviousDay); try { PrayersTimes prayerTimes = new PrayersTimes(cal); MiladiTime miladiTime = new MiladiTime(cal); HijriTime hijriTime = new HijriTime(cal); setAllLabelsTimesHijriMiladiValues2(prayerTimes, hijriTime, miladiTime); } catch (IOException e1) { } } }); this.previousDayPrayerTimes.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { nextPreviousDay--; Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, nextPreviousDay); try { PrayersTimes prayerTimes = new PrayersTimes(cal); MiladiTime miladiTime = new MiladiTime(cal); HijriTime hijriTime = new HijriTime(cal); setAllLabelsTimesHijriMiladiValues2(prayerTimes, hijriTime, miladiTime); } catch (IOException e1) { } } }); this.actualDayPrayerTimes.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { try { nextPreviousDay = 0; setAllLabelsTimesHijriMiladiValues(prayersTimes, hijriTimeObj, miladiTimeObj); } catch (IOException e1) { } //set all values to all labels } }); //set foreground color to all salat names and times this.duhrName.setForeground(Color.WHITE); this.shorou9Name.setForeground(Color.WHITE); this.fajrName.setForeground(Color.WHITE); this.ishaaName.setForeground(Color.WHITE); this.maghribName.setForeground(Color.WHITE); this.asrName.setForeground(Color.WHITE); this.duhrTime.setForeground(Color.WHITE); this.shorou9Time.setForeground(Color.WHITE); this.fajrTime.setForeground(Color.WHITE); this.ishaaTime.setForeground(Color.WHITE); this.maghribTime.setForeground(Color.WHITE); this.asrTime.setForeground(Color.WHITE); this.miladiTime.setForeground(Color.WHITE); this.hijriTime.setForeground(Color.WHITE); this.location.setForeground(Color.WHITE); this.digitalClock.setForeground(Color.WHITE); this.nextPrayer.setForeground(Color.WHITE); //set font to all salat names and times this.duhrName.setFont(font); this.shorou9Name.setFont(font); this.fajrName.setFont(font); this.ishaaName.setFont(font); this.maghribName.setFont(font); this.asrName.setFont(font); this.duhrTime.setFont(font); this.shorou9Time.setFont(font); this.fajrTime.setFont(font); this.ishaaTime.setFont(font); this.maghribTime.setFont(font); this.asrTime.setFont(font); this.digitalClock.setFont(digitalClockfont); this.nextPrayer.setFont(fontNextPrayer); this.miladiTime.setFont(fontMiladiHijriTimes); this.hijriTime.setFont(fontMiladiHijriTimes); this.location.setFont(locationFont); //set position color to all salat names and times this.exitLabel.setBounds(510, 0, 40, 40); if (UserConfig.getSingleton().getLanguage().equalsIgnoreCase(ar)) { this.hijriTime.setBounds(100, 3, 250, 20); this.miladiTime.setBounds(20, 3, 250, 20); } else { this.hijriTime.setBounds(150, 3, 250, 20); this.miladiTime.setBounds(5, 3, 250, 20); } this.location.setBounds(0, 40, 550, 30); this.donateLabel = new JLabel(PropertiesHandler.getSingleton().getValue(1106)); this.donateLabel.setFont(fontMiladiHijriTimes); this.donateLabel.setBounds(420, 3, 50, 20); this.donateLabel.setForeground(Color.WHITE); this.donateLabel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { String url = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FJDAFTPKN2S2W"; String os = System.getProperty("os.name").toLowerCase(); Runtime rt = Runtime.getRuntime(); try { if (os.indexOf("win") >= 0) { // this doesn't support showing urls in the form of "page.html#nameLink" rt.exec("rundll32 url.dll,FileProtocolHandler " + url); } else if (os.indexOf("mac") >= 0) { rt.exec("open " + url); } else if (os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0) { // Do a best guess on unix until we get a platform independent way // Build a list of browsers to try, in this order. String[] browsers = { "epiphany", "firefox", "mozilla", "konqueror", "netscape", "opera", "links", "lynx" }; // Build a command string which looks like "browser1 "url" || browser2 "url" ||..." StringBuffer cmd = new StringBuffer(); for (int i = 0; i < browsers.length; i++) cmd.append((i == 0 ? "" : " || ") + browsers[i] + " \"" + url + "\" "); rt.exec(new String[] { "sh", "-c", cmd.toString() }); } else { } } catch (Exception ex) { } } }); this.locationFromInternet.setBounds(260, 70, 20, 20); this.locationFromInternet.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(final MouseEvent e) { new Thread(new Runnable() { @Override public void run() { if (locationFromInternet.isEnabled()) { locationFromInternet.setEnabled(false); locationFromInternet.setIcon(loaderMain); locationFromInternetLabelMouseClicked(e); } } }).start(); } }); this.fajrAthan = new JLabel(); this.fajrAthan.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { try { allAthanClickHandler(0); } catch (Exception e1) { } } }); this.shorou9Athan = new JLabel(); this.shorou9Athan.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { try { allAthanClickHandler(1); } catch (Exception e1) { } } }); this.duhrAthan = new JLabel(); this.duhrAthan.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { try { allAthanClickHandler(2); } catch (Exception e1) { } } }); this.asrAthan = new JLabel(); this.asrAthan.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { try { allAthanClickHandler(3); } catch (Exception e1) { } } }); this.maghribAthan = new JLabel(); this.maghribAthan.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { try { allAthanClickHandler(4); } catch (Exception e1) { } } }); this.ishaaAthan = new JLabel(); this.ishaaAthan.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { try { allAthanClickHandler(5); } catch (Exception e1) { } } }); this.duhrAthan.setBounds(152, 132, 28, 28); this.shorou9Athan.setBounds(322, 132, 28, 28); this.fajrAthan.setBounds(492, 132, 28, 28); this.ishaaAthan.setBounds(152, 212, 28, 28); this.maghribAthan.setBounds(322, 212, 28, 28); this.asrAthan.setBounds(492, 212, 28, 28); setAllAthanIcons(); this.duhrName.setBounds(30, 100, 150, 30); this.duhrTime.setBounds(30, 130, 150, 30); this.shorou9Name.setBounds(200, 100, 150, 30); this.shorou9Time.setBounds(200, 130, 150, 30); this.fajrName.setBounds(370, 100, 150, 30); this.fajrTime.setBounds(370, 130, 150, 30); this.ishaaName.setBounds(30, 180, 150, 30); this.ishaaTime.setBounds(30, 210, 150, 30); this.maghribName.setBounds(200, 180, 150, 30); this.maghribTime.setBounds(200, 210, 150, 30); this.asrName.setBounds(370, 180, 150, 30); this.asrTime.setBounds(370, 210, 150, 30); this.digitalClock.setBounds(10, 250, 200, 50); this.nextPrayer.setBounds(150, 262, 350, 30); this.settings.setBounds(470, 0, 40, 40); this.settings.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { settingsLabelMouseClicked(e); } }); this.exitLabel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { exitLabelMouseClicked(e); } }); this.mainFrame.addMouseMotionListener(new MouseAdapter() { @Override public void mouseDragged(MouseEvent e) { mainFrameMouseDragged(e); } }); this.mainFrame.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { mainFrameMousePressed(e); } }); this.mainFrame.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { mainFrameMouseReleased(e); } }); this.mainFrame.setSize(550, 300); this.mainFrame.setLocationRelativeTo(null); this.mainFrame.setUndecorated(true); this.mainFrame.setResizable(false); //adding all labels objects to main panel this.mainPanel.add(exitLabel); this.mainPanel.add(hijriTime); this.mainPanel.add(miladiTime); this.mainPanel.add(location); this.mainPanel.add(locationFromInternet); this.mainPanel.add(duhrName); this.mainPanel.add(duhrTime); this.mainPanel.add(shorou9Name); this.mainPanel.add(shorou9Time); this.mainPanel.add(fajrName); this.mainPanel.add(fajrTime); this.mainPanel.add(ishaaName); this.mainPanel.add(ishaaTime); this.mainPanel.add(maghribName); this.mainPanel.add(maghribTime); this.mainPanel.add(asrName); this.mainPanel.add(asrTime); this.mainPanel.add(digitalClock); this.mainPanel.add(nextPrayer); this.mainPanel.add(settings); this.mainPanel.add(donateLabel); this.mainPanel.add(fajrAthan); this.mainPanel.add(shorou9Athan); this.mainPanel.add(duhrAthan); this.mainPanel.add(asrAthan); this.mainPanel.add(maghribAthan); this.mainPanel.add(ishaaAthan); this.mainPanel.add(nextDayPrayerTimes); this.mainPanel.add(previousDayPrayerTimes); this.mainPanel.add(actualDayPrayerTimes); this.mainFrame.add(mainPanel); this.pack(); trayConfig();//create try icon this.setAllLabelsTimesHijriMiladiValues(prayersTimes, hijriTimeObj, miladiTimeObj);//set all values to all labels this.prayerTimesHandler.start();//start prayer times handler thread }