List of usage examples for java.lang String length
public int length()
From source file:com.admc.jcreole.JCreole.java
/** * Run this method with no parameters to see syntax requirements and the * available parameters.//from w w w. j a v a2 s. c o m * * N.b. do not call this method from a persistent program, because it * may call System.exit! * <p> * Any long-running program should use the lower-level methods in this * class instead (or directly use CreoleParser and CreoleScanner * instances). * </p> <p> * This method executes with all JCreole privileges. * </p> <p> * This method sets up the following htmlExpander mappings (therefore you * can reference these in both Creole and boilerplate text).<p> * <ul> * <li>sys|*: mappings for Java system properties * <li>isoDateTime * <li>isoDate * <li>pageTitle: Value derived from the specified Creole file name. * </ul> * * @throws IOException for any I/O problem that makes it impossible to * satisfy the request. * @throws CreoleParseException * if can not generate output, or if the run generates 0 output. * If the problem is due to input formatting, in most cases you * will get a CreoleParseException, which is a RuntimException, and * CreoleParseException has getters for locations in the source * data (though they will be offset for \r's in the provided * Creole source, if any). */ public static void main(String[] sa) throws IOException { String bpResPath = null; String bpFsPath = null; String outPath = null; String inPath = null; boolean debugs = false; boolean troubleshoot = false; boolean noBp = false; int param = -1; try { while (++param < sa.length) { if (sa[param].equals("-d")) { debugs = true; continue; } if (sa[param].equals("-t")) { troubleshoot = true; continue; } if (sa[param].equals("-r") && param + 1 < sa.length) { if (bpFsPath != null || bpResPath != null || noBp) throw new IllegalArgumentException(); bpResPath = sa[++param]; continue; } if (sa[param].equals("-f") && param + 1 < sa.length) { if (bpResPath != null || bpFsPath != null || noBp) throw new IllegalArgumentException(); bpFsPath = sa[++param]; continue; } if (sa[param].equals("-")) { if (noBp || bpFsPath != null || bpResPath != null) throw new IllegalArgumentException(); noBp = true; continue; } if (sa[param].equals("-o") && param + 1 < sa.length) { if (outPath != null) throw new IllegalArgumentException(); outPath = sa[++param]; continue; } if (inPath != null) throw new IllegalArgumentException(); inPath = sa[param]; } if (inPath == null) throw new IllegalArgumentException(); } catch (IllegalArgumentException iae) { System.err.println(SYNTAX_MSG); System.exit(1); } if (!noBp && bpResPath == null && bpFsPath == null) bpResPath = DEFAULT_BP_RES_PATH; String rawBoilerPlate = null; if (bpResPath != null) { if (bpResPath.length() > 0 && bpResPath.charAt(0) == '/') // Classloader lookups are ALWAYS relative to CLASSPATH roots, // and will abort if you specify a beginning "/". bpResPath = bpResPath.substring(1); InputStream iStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(bpResPath); if (iStream == null) throw new IOException("Boilerplate inaccessible: " + bpResPath); rawBoilerPlate = IOUtil.toString(iStream); } else if (bpFsPath != null) { rawBoilerPlate = IOUtil.toString(new File(bpFsPath)); } String creoleResPath = (inPath.length() > 0 && inPath.charAt(0) == '/') ? inPath.substring(1) : inPath; // Classloader lookups are ALWAYS relative to CLASSPATH roots, // and will abort if you specify a beginning "/". InputStream creoleStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream(creoleResPath); File inFile = (creoleStream == null) ? new File(inPath) : null; JCreole jCreole = (rawBoilerPlate == null) ? (new JCreole()) : (new JCreole(rawBoilerPlate)); if (debugs) { jCreole.setInterWikiMapper(new InterWikiMapper() { // This InterWikiMapper is just for prototyping. // Use wiki name of "nil" to force lookup failure for path. // Use wiki page of "nil" to force lookup failure for label. public String toPath(String wikiName, String wikiPage) { if (wikiName != null && wikiName.equals("nil")) return null; return "{WIKI-LINK to: " + wikiName + '|' + wikiPage + '}'; } public String toLabel(String wikiName, String wikiPage) { if (wikiPage == null) throw new RuntimeException("Null page name sent to InterWikiMapper"); if (wikiPage.equals("nil")) return null; return "{LABEL for: " + wikiName + '|' + wikiPage + '}'; } }); Expander creoleExpander = new Expander(Expander.PairedDelims.RECTANGULAR); creoleExpander.put("testMacro", "\n\n<<prettyPrint>>\n{{{\n" + "!/bin/bash -p\n\ncp /etc/inittab /tmp\n}}}\n"); jCreole.setCreoleExpander(creoleExpander); } jCreole.setPrivileges(EnumSet.allOf(JCreolePrivilege.class)); Expander exp = jCreole.getHtmlExpander(); Date now = new Date(); exp.putAll("sys", System.getProperties(), false); exp.put("isoDateTime", isoDateTimeFormatter.format(now), false); exp.put("isoDate", isoDateFormatter.format(now), false); exp.put("pageTitle", (inFile == null) ? creoleResPath.replaceFirst("[.][^.]*$", "").replaceFirst(".*[/\\\\.]", "") : inFile.getName().replaceFirst("[.][^.]*$", "")); if (troubleshoot) { // We don't write any HMTL output here. // Goal is just to output diagnostics. StringBuilder builder = (creoleStream == null) ? IOUtil.toStringBuilder(inFile) : IOUtil.toStringBuilder(creoleStream); int newlineCount = 0; int lastOffset = -1; int offset = builder.indexOf("\n"); for (; offset >= 0; offset = builder.indexOf("\n", offset + 1)) { lastOffset = offset; newlineCount++; } // Accommodate input files with no terminating newline: if (builder.length() > lastOffset + 1) newlineCount++; System.out.println("Input lines: " + newlineCount); Exception lastException = null; while (true) { try { jCreole.parseCreole(builder); break; } catch (Exception e) { lastException = e; } if (builder.charAt(builder.length() - 1) == '\n') builder.setLength(builder.length() - 1); offset = builder.lastIndexOf("\n"); if (offset < 1) break; newlineCount--; builder.setLength(builder.lastIndexOf("\n")); } System.out.println((lastException == null) ? "Input validates" : String.format("Error around input line %d: %s", newlineCount, lastException.getMessage())); return; } String generatedHtml = (creoleStream == null) ? jCreole.parseCreole(inFile) : jCreole.parseCreole(IOUtil.toStringBuilder(creoleStream)); String html = jCreole.postProcess(generatedHtml, SystemUtils.LINE_SEPARATOR); if (outPath == null) { System.out.print(html); } else { FileUtils.writeStringToFile(new File(outPath), html, "UTF-8"); } }
From source file:com.icebreak.p2p.trade.impl.TradeServiceImpl.java
public static void main(String[] args) { String guaranteeLicenseNoNew = ""; String guaranteeLicenseNo = "??TRB?[2013]001?"; String strDate = "20131112"; int count = 1; if (guaranteeLicenseNo.indexOf("?") > 0) { String prefix = guaranteeLicenseNo.substring(0, guaranteeLicenseNo.indexOf("?")); guaranteeLicenseNoNew = prefix + "[" + strDate.substring(0, 4) + "]" + strDate.substring(4, strDate.length()) + StringUtils.leftPad(String.valueOf(++count), 3, "0") + "?"; } else {//from w ww . ja v a 2s . co m String prefix = guaranteeLicenseNo.substring(0, guaranteeLicenseNo.indexOf("TRB") + 3); guaranteeLicenseNoNew = prefix + "[" + strDate.substring(0, 4) + "]" + strDate.substring(4, strDate.length()) + StringUtils.leftPad(String.valueOf(++count), 3, "0") + "?"; } System.out.println(guaranteeLicenseNoNew); }
From source file:com.l2jfree.loginserver.tools.L2AccountManager.java
/** * Launches the interactive account manager. * // w w w.j a v a 2s . c om * @param args ignored */ public static void main(String[] args) { // LOW rework this crap Util.printSection("Account Management"); _log.info("Please choose:"); //_log.info("list - list registered accounts"); _log.info("reg - register a new account"); _log.info("rem - remove a registered account"); _log.info("prom - promote a registered account"); _log.info("dem - demote a registered account"); _log.info("ban - ban a registered account"); _log.info("unban - unban a registered account"); _log.info("quit - exit this application"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); L2AccountManager acm = new L2AccountManager(); String line; try { while ((line = br.readLine()) != null) { line = line.trim(); Connection con = null; switch (acm.getState()) { case USER_NAME: line = line.toLowerCase(); try { con = L2Database.getConnection(); PreparedStatement ps = con .prepareStatement("SELECT superuser FROM account WHERE username LIKE ?"); ps.setString(1, line); ResultSet rs = ps.executeQuery(); if (!rs.next()) { acm.setUser(line); _log.info("Desired password:"); acm.setState(ManagerState.PASSWORD); } else { _log.info("User name already in use."); acm.setState(ManagerState.INITIAL_CHOICE); } rs.close(); ps.close(); } catch (SQLException e) { _log.error("Could not access database!", e); acm.setState(ManagerState.INITIAL_CHOICE); } finally { L2Database.close(con); } break; case PASSWORD: try { MessageDigest sha = MessageDigest.getInstance("SHA"); byte[] pass = sha.digest(line.getBytes("US-ASCII")); acm.setPass(HexUtil.bytesToHexString(pass)); } catch (NoSuchAlgorithmException e) { _log.fatal("SHA1 is not available!", e); Shutdown.exit(TerminationStatus.ENVIRONMENT_MISSING_COMPONENT_OR_SERVICE); } catch (UnsupportedEncodingException e) { _log.fatal("ASCII is not available!", e); Shutdown.exit(TerminationStatus.ENVIRONMENT_MISSING_COMPONENT_OR_SERVICE); } _log.info("Super user: [y/n]"); acm.setState(ManagerState.SUPERUSER); break; case SUPERUSER: try { if (line.length() != 1) throw new IllegalArgumentException("One char required."); else if (line.charAt(0) == 'y') acm.setSuper(true); else if (line.charAt(0) == 'n') acm.setSuper(false); else throw new IllegalArgumentException("Invalid choice."); _log.info("Date of birth: [yyyy-mm-dd]"); acm.setState(ManagerState.DOB); } catch (IllegalArgumentException e) { _log.info("[y/n]?"); } break; case DOB: try { Date d = Date.valueOf(line); if (d.after(new Date(System.currentTimeMillis()))) throw new IllegalArgumentException("Future date specified."); acm.setDob(d); _log.info("Ban reason ID or nothing:"); acm.setState(ManagerState.SUSPENDED); } catch (IllegalArgumentException e) { _log.info("[yyyy-mm-dd] in the past:"); } break; case SUSPENDED: try { if (line.length() > 0) { int id = Integer.parseInt(line); acm.setBan(L2BanReason.getById(id)); } else acm.setBan(null); try { con = L2Database.getConnection(); PreparedStatement ps = con.prepareStatement( "INSERT INTO account (username, password, superuser, birthDate, banReason) VALUES (?, ?, ?, ?, ?)"); ps.setString(1, acm.getUser()); ps.setString(2, acm.getPass()); ps.setBoolean(3, acm.isSuper()); ps.setDate(4, acm.getDob()); L2BanReason lbr = acm.getBan(); if (lbr == null) ps.setNull(5, Types.INTEGER); else ps.setInt(5, lbr.getId()); ps.executeUpdate(); _log.info("Account " + acm.getUser() + " has been registered."); ps.close(); } catch (SQLException e) { _log.error("Could not register an account!", e); } finally { L2Database.close(con); } acm.setState(ManagerState.INITIAL_CHOICE); } catch (NumberFormatException e) { _log.info("Ban reason ID or nothing:"); } break; case REMOVE: acm.setUser(line.toLowerCase()); try { con = L2Database.getConnection(); PreparedStatement ps = con.prepareStatement("DELETE FROM account WHERE username LIKE ?"); ps.setString(1, acm.getUser()); int cnt = ps.executeUpdate(); if (cnt > 0) _log.info("Account " + acm.getUser() + " has been removed."); else _log.info("Account " + acm.getUser() + " does not exist!"); ps.close(); } catch (SQLException e) { _log.error("Could not remove an account!", e); } finally { L2Database.close(con); } acm.setState(ManagerState.INITIAL_CHOICE); break; case PROMOTE: acm.setUser(line.toLowerCase()); try { con = L2Database.getConnection(); PreparedStatement ps = con .prepareStatement("UPDATE account SET superuser = ? WHERE username LIKE ?"); ps.setBoolean(1, true); ps.setString(2, acm.getUser()); int cnt = ps.executeUpdate(); if (cnt > 0) _log.info("Account " + acm.getUser() + " has been promoted."); else _log.info("Account " + acm.getUser() + " does not exist!"); ps.close(); } catch (SQLException e) { _log.error("Could not promote an account!", e); } finally { L2Database.close(con); } acm.setState(ManagerState.INITIAL_CHOICE); break; case DEMOTE: acm.setUser(line.toLowerCase()); try { con = L2Database.getConnection(); PreparedStatement ps = con .prepareStatement("UPDATE account SET superuser = ? WHERE username LIKE ?"); ps.setBoolean(1, false); ps.setString(2, acm.getUser()); int cnt = ps.executeUpdate(); if (cnt > 0) _log.info("Account " + acm.getUser() + " has been demoted."); else _log.info("Account " + acm.getUser() + " does not exist!"); ps.close(); } catch (SQLException e) { _log.error("Could not demote an account!", e); } finally { L2Database.close(con); } acm.setState(ManagerState.INITIAL_CHOICE); break; case UNBAN: acm.setUser(line.toLowerCase()); try { con = L2Database.getConnection(); PreparedStatement ps = con .prepareStatement("UPDATE account SET banReason = ? WHERE username LIKE ?"); ps.setNull(1, Types.INTEGER); ps.setString(2, acm.getUser()); int cnt = ps.executeUpdate(); if (cnt > 0) _log.info("Account " + acm.getUser() + " has been unbanned."); else _log.info("Account " + acm.getUser() + " does not exist!"); ps.close(); } catch (SQLException e) { _log.error("Could not demote an account!", e); } finally { L2Database.close(con); } acm.setState(ManagerState.INITIAL_CHOICE); break; case BAN: line = line.toLowerCase(); try { con = L2Database.getConnection(); PreparedStatement ps = con .prepareStatement("SELECT superuser FROM account WHERE username LIKE ?"); ps.setString(1, line); ResultSet rs = ps.executeQuery(); if (rs.next()) { acm.setUser(line); _log.info("Ban reason ID:"); acm.setState(ManagerState.REASON); } else { _log.info("Account does not exist."); acm.setState(ManagerState.INITIAL_CHOICE); } rs.close(); ps.close(); } catch (SQLException e) { _log.error("Could not access database!", e); acm.setState(ManagerState.INITIAL_CHOICE); } finally { L2Database.close(con); } break; case REASON: try { int ban = Integer.parseInt(line); con = L2Database.getConnection(); PreparedStatement ps = con .prepareStatement("UPDATE account SET banReason = ? WHERE username LIKE ?"); ps.setInt(1, ban); ps.setString(2, acm.getUser()); ps.executeUpdate(); _log.info("Account " + acm.getUser() + " has been banned."); ps.close(); } catch (NumberFormatException e) { _log.info("Ban reason ID:"); } catch (SQLException e) { _log.error("Could not ban an account!", e); } finally { L2Database.close(con); } acm.setState(ManagerState.INITIAL_CHOICE); break; default: line = line.toLowerCase(); if (line.equals("reg")) { _log.info("Desired user name:"); acm.setState(ManagerState.USER_NAME); } else if (line.equals("rem")) { _log.info("User name:"); acm.setState(ManagerState.REMOVE); } else if (line.equals("prom")) { _log.info("User name:"); acm.setState(ManagerState.PROMOTE); } else if (line.equals("dem")) { _log.info("User name:"); acm.setState(ManagerState.DEMOTE); } else if (line.equals("unban")) { _log.info("User name:"); acm.setState(ManagerState.UNBAN); } else if (line.equals("ban")) { _log.info("User name:"); acm.setState(ManagerState.BAN); } else if (line.equals("quit")) Shutdown.exit(TerminationStatus.MANUAL_SHUTDOWN); else _log.info("Incorrect command."); break; } } } catch (IOException e) { _log.fatal("Could not process input!", e); } finally { IOUtils.closeQuietly(br); } }
From source file:de.prozesskraft.pkraft.Createdoc.java
public static void main(String[] args) throws org.apache.commons.cli.ParseException, IOException { Createdoc tmp = new Createdoc(); /*---------------------------- get options from ini-file//from ww w . ja va 2 s . c om ----------------------------*/ File installDir = new java.io.File(WhereAmI.getInstallDirectoryAbsolutePath(Createdoc.class) + "/.."); File inifile = new java.io.File(installDir.getAbsolutePath() + "/etc/pkraft-createdoc.ini"); if (inifile.exists()) { try { ini = new Ini(inifile); } catch (InvalidFileFormatException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else { System.err.println("ini file does not exist: " + inifile.getAbsolutePath()); System.exit(1); } /*---------------------------- create boolean options ----------------------------*/ Option ohelp = new Option("help", "print this message"); Option ov = new Option("v", "prints version and build-date"); /*---------------------------- create argument options ----------------------------*/ Option odefinition = OptionBuilder.withArgName("definition").hasArg() .withDescription("[mandatory] process definition file") // .isRequired() .create("definition"); Option oformat = OptionBuilder.withArgName("format").hasArg() .withDescription("[mandatory, default=pdf] output format (pdf|pptx) ").create("format"); Option ooutput = OptionBuilder.withArgName("output").hasArg().withDescription( "[mandatory, default=out.<format>] output file with full documentation of process definition") // .isRequired() .create("output"); //// Option property = OptionBuilder.withArgName( "property=value" ) //// .hasArgs(2) //// .withValueSeparator() //// .withDescription( "use value for given property" ) //// .create("D"); // // /*---------------------------- // create options object // ----------------------------*/ Options options = new Options(); options.addOption(ohelp); options.addOption(ov); options.addOption(odefinition); options.addOption(oformat); options.addOption(ooutput); /*---------------------------- create the parser ----------------------------*/ CommandLineParser parser = new GnuParser(); // parse the command line arguments line = parser.parse(options, args); /*---------------------------- usage/help ----------------------------*/ if (line.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("createdoc", options); System.exit(0); } if (line.hasOption("v")) { System.out.println("web: www.prozesskraft.de"); System.out.println("version: [% version %]"); System.out.println("date: [% date %]"); System.exit(0); } /*---------------------------- die variablen festlegen ----------------------------*/ int error = 0; String definition = null; String format = null; String output = null; // festlegen von definition if (line.hasOption("definition")) { definition = line.getOptionValue("definition"); if (!(new java.io.File(definition).exists())) { System.err.println("file does not exist " + definition); } } else { System.err.println("parameter -definition is mandatory"); error++; } // festlegen von format if (line.hasOption("format")) { if (line.getOptionValue("format").matches("pdf|pptx")) { format = line.getOptionValue("format"); } else { System.err.println("for -format use only pdf|pptx"); error++; } } else { format = "pdf"; } // festlegen von output if (line.hasOption("output")) { output = line.getOptionValue("output"); } else { output = "out." + format; } // feststellen ob output bereits existiert if (new java.io.File(output).exists()) { System.err.println("output already exists: " + output); error++; } // aussteigen, falls fehler aufgetaucht sind if (error > 0) { System.err.println("error(s) occured. try -help for help."); System.exit(1); } /*---------------------------- die lizenz ueberpruefen und ggf abbrechen ----------------------------*/ // check for valid license ArrayList<String> allPortAtHost = new ArrayList<String>(); allPortAtHost.add(ini.get("license-server", "license-server-1")); allPortAtHost.add(ini.get("license-server", "license-server-2")); allPortAtHost.add(ini.get("license-server", "license-server-3")); MyLicense lic = new MyLicense(allPortAtHost, "1", "user-edition", "0.1"); // lizenz-logging ausgeben for (String actLine : (ArrayList<String>) lic.getLog()) { System.err.println(actLine); } // abbruch, wenn lizenz nicht valide if (!lic.isValid()) { System.exit(1); } /*---------------------------- die eigentliche business logic ----------------------------*/ Process process = new Process(); Reporter report; process.setInfilexml(definition); System.out.println("info: reading process definition " + definition); try { process.readXml(); process.setStepRanks(); } catch (JAXBException e) { // TODO Auto-generated catch block e.printStackTrace(); } //festlegen des temporaeren verzeichnisses fuer die Daten und Pfade erzeugen long jetztMillis = System.currentTimeMillis(); String randomPathJasperFilled = "/tmp/" + jetztMillis + "_jasperFilled"; String randomPathPng = "/tmp/" + jetztMillis + "_png"; String randomPathPdf = "/tmp/" + jetztMillis + "_pdf"; String randomPathPptx = "/tmp/" + jetztMillis + "_pptx"; new File(randomPathJasperFilled).mkdirs(); new File(randomPathPng).mkdirs(); new File(randomPathPdf).mkdirs(); new File(randomPathPptx).mkdirs(); ////////////////////////////////////////// // erstellen der Bilder // konfigurieren der processing ansicht // PmodelViewPage page = new PmodelViewPage(process); PmodelViewPage page = new PmodelViewPage(); page.einstellungen.getProcess().setStepRanks(); page.einstellungen.setSize(100); page.einstellungen.setZoom(100); // page.einstellungen.setZoom(8 * 100/process.getMaxLevel()); page.einstellungen.setTextsize(0); page.einstellungen.setRanksize(7); page.einstellungen.setWidth(2500); page.einstellungen.setHeight(750); page.einstellungen.setGravx(10); page.einstellungen.setGravy(0); page.einstellungen.setRootpositionratiox((float) 0.05); page.einstellungen.setRootpositionratioy((float) 0.5); page.einstellungen.setProcess(process); createContents(page); // mit open kann die page angezeigt werden if (!(produktiv)) { open(); } // // warten // System.out.println("stabilisierung ansicht: 5 sekunden warten gravitation = "+page.einstellungen.getGravx()); // long jetzt5 = System.currentTimeMillis(); // while (System.currentTimeMillis() < jetzt5 + 5000) // { // // } // // page.einstellungen.setGravx(10); // // warten int wartezeitSeconds = 1; if (produktiv) { wartezeitSeconds = page.einstellungen.getProcess().getStep().size() * 2; } System.out.println("stabilisierung ansicht: " + wartezeitSeconds + " sekunden warten gravitation = " + page.einstellungen.getGravx()); long jetzt6 = System.currentTimeMillis(); while (System.currentTimeMillis() < jetzt6 + (wartezeitSeconds * 1000)) { } page.einstellungen.setFix(true); // VORBEREITUNG) bild speichern processTopologyImagePath = randomPathPng + "/processTopology.png"; page.savePic(processTopologyImagePath); // zuerst 1 sekunde warten, dann autocrop long jetzt = System.currentTimeMillis(); while (System.currentTimeMillis() < jetzt + 1000) { } new AutoCropBorder(processTopologyImagePath); // VORBEREITUNG) fuer jeden step ein bild speichern for (Step actualStep : process.getStep()) { // root ueberspringen // if (actualStep.isRoot()); String stepImagePath = randomPathPng + "/step_" + actualStep.getName() + "_Topology.png"; // Farbe des Steps auf finished (gruen) aendern page.einstellungen.getProcess().getRootStep().setStatusOverwrite("waiting"); actualStep.setStatusOverwrite("finished"); // etwas warten, bis die farbe bezeichnet wurde long jetzt4 = System.currentTimeMillis(); while (System.currentTimeMillis() < jetzt4 + 500) { } page.savePic(stepImagePath); // zuerst 1 sekunde warten, dann autocrop long jetzt3 = System.currentTimeMillis(); while (System.currentTimeMillis() < jetzt3 + 1000) { } new AutoCropBorder(stepImagePath); stepTopologyImagePath.put(actualStep.getName(), stepImagePath); // farbe wieder auf grau aendern actualStep.setStatusOverwrite(null); System.out.println("erstelle bild fuer step: " + actualStep.getName()); long jetzt2 = System.currentTimeMillis(); while (System.currentTimeMillis() < jetzt2 + 1000) { } } page.destroy(); ////////////////////////////////////////// report = new Reporter(); // P03) erstellen des p03 System.out.println("info: generating p03."); String pdfPathP03 = null; String pptxPathP03 = null; String jasperPathP03 = null; String jasperFilledPathP03 = null; // P03) feststellen, welches jasperreports-template fuer den angeforderten typ verwendet werden soll if (ini.get("pkraft-createdoc", "p03") != null) { pdfPathP03 = randomPathPdf + "/p03.pdf"; pptxPathP03 = randomPathPptx + "/p03.pptx"; jasperPathP03 = installDir.getAbsolutePath() + "/" + ini.get("pkraft-createdoc", "p03"); jasperFilledPathP03 = (randomPathJasperFilled + "/p03.jasperFilled"); pdfRankFiles.put("0.0.03", pdfPathP03); pptxRankFiles.put("0.0.03", pptxPathP03); } else { System.err.println("no entry 'p03' found in ini file"); System.exit(1); } DateFormat dateFormat = new SimpleDateFormat("dd. MM. yyyy"); Date date = new Date(); report.setParameter("processName", process.getName()); report.setParameter("processVersion", process.getVersion()); report.setParameter("processDatum", dateFormat.format(date)); report.setParameter("processArchitectLogoImagePath", installDir.getAbsolutePath() + "/" + ini.get("pkraft-createdoc", "logo")); report.setParameter("processArchitectCompany", process.getArchitectCompany()); report.setParameter("processArchitectName", process.getArchitectName()); report.setParameter("processArchitectMail", process.getArchitectMail()); report.setParameter("processCustomerCompany", process.getCustomerCompany()); report.setParameter("processCustomerName", process.getCustomerName()); report.setParameter("processCustomerMail", process.getCustomerMail()); try { report.fillReportFileToFile(jasperPathP03, jasperFilledPathP03); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } // export to pdf try { report.convertFileToPdf(jasperFilledPathP03, pdfPathP03); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } // export to pptx try { report.convertFileToPptx(jasperFilledPathP03, pptxPathP03); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } report = null; //System.exit(0); ////////////////////////////////////////// report = new Reporter(); // P05) erstellen des p05 System.out.println("info: generating p05."); String pdfPathP05 = null; String pptxPathP05 = null; String jasperPathP05 = null; String jasperFilledPathP05 = null; // P05) feststellen, welches jasperreports-template fuer den angeforderten typ verwendet werden soll if (ini.get("pkraft-createdoc", "p05") != null) { pdfPathP05 = randomPathPdf + "/p05.pdf"; pptxPathP05 = randomPathPptx + "/p05.pptx"; jasperPathP05 = installDir.getAbsolutePath() + "/" + ini.get("pkraft-createdoc", "p05"); jasperFilledPathP05 = (randomPathJasperFilled + "/p05.jasperFilled"); pdfRankFiles.put("0.0.05", pdfPathP05); pptxRankFiles.put("0.0.05", pptxPathP05); } else { System.err.println("no entry 'p05' found in ini file"); System.exit(1); } report.setParameter("processName", process.getName()); report.setParameter("processVersion", process.getVersion()); report.setParameter("processArchitectCompany", process.getArchitectCompany()); report.setParameter("processArchitectName", process.getArchitectName()); report.setParameter("processArchitectMail", process.getArchitectMail()); report.setParameter("processCustomerCompany", process.getCustomerCompany()); report.setParameter("processCustomerName", process.getCustomerName()); report.setParameter("processCustomerMail", process.getCustomerMail()); try { report.fillReportFileToFile(jasperPathP05, jasperFilledPathP05); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } // export to pdf try { report.convertFileToPdf(jasperFilledPathP05, pdfPathP05); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } // export to pptx try { report.convertFileToPptx(jasperFilledPathP05, pptxPathP05); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } report = null; //System.exit(0); ////////////////////////////////////////// report = new Reporter(); // P08) erstellen des p08 System.out.println("info: generating p08."); String pdfPathP08 = null; String pptxPathP08 = null; String jasperPathP08 = null; String jasperFilledPathP08 = null; // P08) feststellen, welches jasperreports-template fuer den angeforderten typ verwendet werden soll if (ini.get("pkraft-createdoc", "p08") != null) { pdfPathP08 = randomPathPdf + "/p08.pdf"; pptxPathP08 = randomPathPptx + "/p08.pptx"; jasperPathP08 = installDir.getAbsolutePath() + "/" + ini.get("pkraft-createdoc", "p08"); jasperFilledPathP08 = (randomPathJasperFilled + "/p08.jasperFilled"); pdfRankFiles.put("0.0.08", pdfPathP08); pptxRankFiles.put("0.0.08", pptxPathP08); } else { System.err.println("no entry 'p08' found in ini file"); System.exit(1); } report.setParameter("processName", process.getName()); report.setParameter("processVersion", process.getVersion()); report.setParameter("processArchitectCompany", process.getArchitectCompany()); report.setParameter("processArchitectName", process.getArchitectName()); report.setParameter("processArchitectMail", process.getArchitectMail()); report.setParameter("processCustomerCompany", process.getCustomerCompany()); report.setParameter("processCustomerName", process.getCustomerName()); report.setParameter("processCustomerMail", process.getCustomerMail()); report.setParameter("processDescription", process.getDescription()); try { report.fillReportFileToFile(jasperPathP08, jasperFilledPathP08); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } // export to pdf try { report.convertFileToPdf(jasperFilledPathP08, pdfPathP08); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } // export to pptx try { report.convertFileToPptx(jasperFilledPathP08, pptxPathP08); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } report = null; //System.exit(0); ////////////////////////////////////////// report = new Reporter(); // P10) erstellen des p10 System.out.println("info: generating p10."); String pdfPathP10 = null; String pptxPathP10 = null; String jasperPathP10 = null; String jasperFilledPathP10 = null; // P10) feststellen, welches jasperreports-template fuer den angeforderten typ verwendet werden soll if (ini.get("pkraft-createdoc", "p10") != null) { pdfPathP10 = randomPathPdf + "/p10.pdf"; pptxPathP10 = randomPathPptx + "/p10.pptx"; jasperPathP10 = installDir.getAbsolutePath() + "/" + ini.get("pkraft-createdoc", "p10"); jasperFilledPathP10 = (randomPathJasperFilled + "/p10.jasperFilled"); pdfRankFiles.put("0.0.10", pdfPathP10); pptxRankFiles.put("0.0.10", pptxPathP10); } else { System.err.println("no entry 'p10' found in ini file"); System.exit(1); } report.setParameter("processName", process.getName()); report.setParameter("processVersion", process.getVersion()); report.setParameter("processArchitectCompany", process.getArchitectCompany()); report.setParameter("processArchitectName", process.getArchitectName()); report.setParameter("processArchitectMail", process.getArchitectMail()); report.setParameter("processCustomerCompany", process.getCustomerCompany()); report.setParameter("processCustomerName", process.getCustomerName()); report.setParameter("processCustomerMail", process.getCustomerMail()); // rootstep holen Step rootStep = process.getStep(process.getRootstepname()); // ueber alle commit iterieren for (Commit actualCommit : rootStep.getCommit()) { // ueber alle files iterieren for (de.prozesskraft.pkraft.File actualFile : actualCommit.getFile()) { HashMap<String, Object> row = new HashMap<String, Object>(); // Spalte 'origin' row.put("origin", "user/cb2"); // Spalte 'objectType' row.put("objectType", "file"); // Spalte 'minOccur' row.put("minOccur", "" + actualFile.getMinoccur()); // Spalte 'maxOccur' row.put("maxOccur", "" + actualFile.getMaxoccur()); // Spalte 'objectKey' row.put("objectKey", actualFile.getKey()); // die steps herausfinden, die dieses file benoetigen ArrayList<Step> allStepsThatNeedThisFileFromRoot = process.getStepWhichNeedFromRoot("file", actualFile.getKey()); String stepnameListe = ""; for (Step actStep : allStepsThatNeedThisFileFromRoot) { stepnameListe += "\n=> " + actStep.getName(); } // Spalte 'objectDescription' row.put("objectDescription", actualFile.getDescription() + stepnameListe); // Datensatz dem report hinzufuegen report.addField(row); } // ueber alle variablen iterieren for (de.prozesskraft.pkraft.Variable actualVariable : actualCommit.getVariable()) { HashMap<String, Object> row = new HashMap<String, Object>(); // Spalte 'origin' row.put("origin", "user/cb2"); // Spalte 'objectType' row.put("objectType", "variable"); // Spalte 'minOccur' row.put("minOccur", "" + actualVariable.getMinoccur()); // Spalte 'maxOccur' row.put("maxOccur", "" + actualVariable.getMaxoccur()); // Spalte 'objectKey' row.put("objectKey", actualVariable.getKey()); // die steps herausfinden, die dieses file benoetigen ArrayList<Step> allStepsThatNeedThisObjectFromRoot = process.getStepWhichNeedFromRoot("variable", actualVariable.getKey()); String stepnameListe = ""; for (Step actStep : allStepsThatNeedThisObjectFromRoot) { stepnameListe += "\n=> " + actStep.getName(); } // Spalte 'objectDescription' row.put("objectDescription", actualVariable.getDescription() + stepnameListe); // Datensatz dem report hinzufuegen report.addField(row); } } try { report.fillReportFileToFile(jasperPathP10, jasperFilledPathP10); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } // export to pdf try { report.convertFileToPdf(jasperFilledPathP10, pdfPathP10); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } // export to pptx try { report.convertFileToPptx(jasperFilledPathP10, pptxPathP10); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } report = null; ////////////////////////////////////////// report = new Reporter(); // P20) erstellen des p20 System.out.println("info: generating p20."); String pdfPathP20 = null; String pptxPathP20 = null; String jasperPathP20 = null; String jasperFilledPathP20 = null; // P20) feststellen, welches jasperreports-template fuer den angeforderten typ verwendet werden soll if (ini.get("pkraft-createdoc", "p20") != null) { pdfPathP20 = randomPathPdf + "/p20.pdf"; pptxPathP20 = randomPathPptx + "/p20.pptx"; jasperPathP20 = installDir.getAbsolutePath() + "/" + ini.get("pkraft-createdoc", "p20"); jasperFilledPathP20 = (randomPathJasperFilled + "/p20.jasperFilled"); pdfRankFiles.put("0.0.20", pdfPathP20); pptxRankFiles.put("0.0.20", pptxPathP20); } else { System.err.println("no entry 'p20' found in ini file"); System.exit(1); } report.setParameter("processName", process.getName()); report.setParameter("processVersion", process.getVersion()); report.setParameter("processArchitectCompany", process.getArchitectCompany()); report.setParameter("processArchitectName", process.getArchitectName()); report.setParameter("processArchitectMail", process.getArchitectMail()); report.setParameter("processCustomerCompany", process.getCustomerCompany()); report.setParameter("processCustomerName", process.getCustomerName()); report.setParameter("processCustomerMail", process.getCustomerMail()); // ueber alle steps iterieren (ausser root) for (Step actualStep : (ArrayList<Step>) process.getStep()) { // ueberspringen wenn es sich um root handelt if (!(actualStep.getName().equals(process.getRootstepname()))) { // ueber alle commit iterieren for (Commit actualCommit : actualStep.getCommit()) { // nur die, die toroot=true ( und spaeter auch tosdm=true) if (actualCommit.isTorootPresent()) { // ueber alle files iterieren for (de.prozesskraft.pkraft.File actualFile : actualCommit.getFile()) { HashMap<String, Object> row = new HashMap<String, Object>(); // Spalte 'destination' row.put("destination", "user/cb2"); // Spalte 'objectType' row.put("objectType", "file"); // Spalte 'minOccur' row.put("minOccur", "" + actualFile.getMinoccur()); // Spalte 'maxOccur' row.put("maxOccur", "" + actualFile.getMaxoccur()); // Spalte 'objectKey' row.put("objectKey", actualFile.getKey()); // Spalte 'objectDescription' row.put("objectDescription", actualFile.getDescription() + "\n<= " + actualStep.getName()); // Datensatz dem report hinzufuegen report.addField(row); } // ueber alle variablen iterieren for (de.prozesskraft.pkraft.Variable actualVariable : actualCommit.getVariable()) { HashMap<String, Object> row = new HashMap<String, Object>(); // Spalte 'objectType' row.put("destination", "user/cb2"); // Spalte 'objectType' row.put("objectType", "variable"); // Spalte 'minOccur' row.put("minOccur", "" + actualVariable.getMinoccur()); // Spalte 'maxOccur' row.put("maxOccur", "" + actualVariable.getMaxoccur()); // Spalte 'objectKey' row.put("objectKey", actualVariable.getKey()); // Spalte 'objectDescription' row.put("objectDescription", actualVariable.getDescription() + "\n<= " + actualStep.getName()); // Datensatz dem report hinzufuegen report.addField(row); } } } } } try { report.fillReportFileToFile(jasperPathP20, jasperFilledPathP20); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } // export to pdf try { report.convertFileToPdf(jasperFilledPathP20, pdfPathP20); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } // export to pptx try { report.convertFileToPptx(jasperFilledPathP20, pptxPathP20); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } report = null; ////////////////////////////////////////// report = new Reporter(); // P30) erstellen des p30 System.out.println("info: generating p30."); String pdfPathP30 = null; String pptxPathP30 = null; String jasperPathP30 = null; String jasperFilledPathP30 = null; // P30) feststellen, welches jasperreports-template fuer den angeforderten typ verwendet werden soll if (ini.get("pkraft-createdoc", "p30") != null) { pdfPathP30 = randomPathPdf + "/p30.pdf"; pptxPathP30 = randomPathPptx + "/p30.pptx"; jasperPathP30 = installDir.getAbsolutePath() + "/" + ini.get("pkraft-createdoc", "p30"); jasperFilledPathP30 = (randomPathJasperFilled + "/p30.jasperFilled"); pdfRankFiles.put("0.0.30", pdfPathP30); pptxRankFiles.put("0.0.30", pptxPathP30); } else { System.err.println("no entry 'p30' found in ini file"); System.exit(1); } report.setParameter("processName", process.getName()); report.setParameter("processVersion", process.getVersion()); report.setParameter("processArchitectCompany", process.getArchitectCompany()); report.setParameter("processArchitectName", process.getArchitectName()); report.setParameter("processArchitectMail", process.getArchitectMail()); report.setParameter("processCustomerCompany", process.getCustomerCompany()); report.setParameter("processCustomerName", process.getCustomerName()); report.setParameter("processCustomerMail", process.getCustomerMail()); // P1) bild an report melden report.setParameter("processTopologyImagePath", processTopologyImagePath); try { report.fillReportFileToFile(jasperPathP30, jasperFilledPathP30); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } // export to pdf try { report.convertFileToPdf(jasperFilledPathP30, pdfPathP30); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } // export to pptx try { report.convertFileToPptx(jasperFilledPathP30, pptxPathP30); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } report = null; // System.exit(0); ////////////////////////////////////////// report = new Reporter(); // P40) erstellen des p40 System.out.println("info: generating p40."); String pdfPathP40 = null; String pptxPathP40 = null; String jasperPathP40 = null; String jasperFilledPathP40 = null; // P40) feststellen, welches jasperreports-template fuer den angeforderten typ verwendet werden soll if (ini.get("pkraft-createdoc", "p40") != null) { pdfPathP40 = randomPathPdf + "/p40.pdf"; pptxPathP40 = randomPathPptx + "/p40.pptx"; jasperPathP40 = installDir.getAbsolutePath() + "/" + ini.get("pkraft-createdoc", "p40"); jasperFilledPathP40 = (randomPathJasperFilled + "/p40.jasperFilled"); pdfRankFiles.put("0.0.40", pdfPathP40); pptxRankFiles.put("0.0.40", pptxPathP40); } else { System.err.println("no entry 'p40' found in ini file"); System.exit(1); } report.setParameter("processName", process.getName()); report.setParameter("processVersion", process.getVersion()); report.setParameter("processArchitectCompany", process.getArchitectCompany()); report.setParameter("processArchitectName", process.getArchitectName()); report.setParameter("processArchitectMail", process.getArchitectMail()); report.setParameter("processCustomerCompany", process.getCustomerCompany()); report.setParameter("processCustomerName", process.getCustomerName()); report.setParameter("processCustomerMail", process.getCustomerMail()); // P40) bild an report melden report.setParameter("processTopologyImagePath", processTopologyImagePath); // Tabelle erzeugen ArrayList<Step> steps = process.getStep(); for (int x = 0; x < steps.size(); x++) { HashMap<String, Object> row = new HashMap<String, Object>(); Step actualStep = steps.get(x); // erste Spalte ist 'rank' // um die korrekte sortierung zu erhalten soll der rank-string auf jeweils 2 Stellen erweitert werden String[] rankArray = actualStep.getRank().split("\\."); Integer[] rankArrayInt = new Integer[rankArray.length]; for (int y = 0; y < rankArray.length; y++) { rankArrayInt[y] = Integer.parseInt(rankArray[y]); } String rankFormated = String.format("%02d.%02d", rankArrayInt); row.put("stepRank", rankFormated); // zweite Spalte ist 'stepname' row.put("stepName", actualStep.getName()); // System.out.println("stepName: "+actualStep.getName()); // dritte Spalte ist 'Beschreibung' row.put("stepDescription", actualStep.getDescription()); // System.out.println("stepRank: "+actualStep.getDescription()); // wenn nicht der root-step, dann row eintragen if (!(actualStep.getName().equals(process.getRootstepname()))) { report.addField(row); } } try { report.fillReportFileToFile(jasperPathP40, jasperFilledPathP40); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } // export to pdf try { report.convertFileToPdf(jasperFilledPathP40, pdfPathP40); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } // export to pptx try { report.convertFileToPptx(jasperFilledPathP40, pptxPathP40); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } report = null; ////////////////////////////////////////// // fuer jeden Step einen eigenen Input Report erzeugen for (Step actualStep : process.getStep()) { // root-step ueberspringen if (actualStep.getName().equals(process.getRootstepname())) { System.out.println("skipping step root"); } // alle anderen auswerten else { report = new Reporter(); // P51x) erstellen des p51 System.out.println( "info: generating p51 for step " + actualStep.getRank() + " => " + actualStep.getName()); String stepRank = actualStep.getRank(); String pdfPathP51 = null; String pptxPathP51 = null; String jasperPathP51 = null; String jasperFilledPathP51 = null; // P51x) feststellen, welches jasperreports-template fuer den angeforderten typ verwendet werden soll if (ini.get("pkraft-createdoc", "p51") != null) { pdfPathP51 = randomPathPdf + "/p5." + stepRank + ".1.pdf"; pptxPathP51 = randomPathPptx + "/p5." + stepRank + ".1.pptx"; jasperPathP51 = installDir.getAbsolutePath() + "/" + ini.get("pkraft-createdoc", "p51"); jasperFilledPathP51 = randomPathJasperFilled + "/p5." + stepRank + ".1.jasperFilled"; String[] rankArray = stepRank.split("\\."); Integer[] rankArrayInt = new Integer[rankArray.length]; for (int x = 0; x < rankArray.length; x++) { rankArrayInt[x] = Integer.parseInt(rankArray[x]); } String rankFormated = String.format("%03d.%03d", rankArrayInt); pdfRankFiles.put(rankFormated + ".1", pdfPathP51); pptxRankFiles.put(rankFormated + ".1", pptxPathP51); } else { System.err.println("no entry 'p51' found in ini file"); System.exit(1); } report.setParameter("processName", process.getName()); report.setParameter("processVersion", process.getVersion()); report.setParameter("processArchitectCompany", process.getArchitectCompany()); report.setParameter("processArchitectName", process.getArchitectName()); report.setParameter("processArchitectMail", process.getArchitectMail()); report.setParameter("processCustomerCompany", process.getCustomerCompany()); report.setParameter("processCustomerName", process.getCustomerName()); report.setParameter("processCustomerMail", process.getCustomerMail()); report.setParameter("stepName", actualStep.getName()); report.setParameter("stepRank", stepRank); report.setParameter("stepDescription", actualStep.getDescription()); String aufruf = ""; if (actualStep.getWork() != null) { // zusammensetzen des scriptaufrufs String interpreter = ""; if (actualStep.getWork().getInterpreter() != null) { interpreter = actualStep.getWork().getInterpreter(); } aufruf = interpreter + " " + actualStep.getWork().getCommand(); for (Callitem actualCallitem : actualStep.getWork().getCallitem()) { aufruf += " " + actualCallitem.getPar(); if (!(actualCallitem.getDel() == null)) { aufruf += actualCallitem.getDel(); } if (!(actualCallitem.getVal() == null)) { aufruf += actualCallitem.getVal(); } } } else if (actualStep.getSubprocess() != null) { aufruf = ini.get("apps", "pkraft-startinstance"); aufruf += " --pdomain " + actualStep.getSubprocess().getDomain(); aufruf += " --pname " + actualStep.getSubprocess().getName(); aufruf += " --pversion " + actualStep.getSubprocess().getVersion(); for (Commit actCommit : actualStep.getSubprocess().getStep().getCommit()) { for (de.prozesskraft.pkraft.File actFile : actCommit.getFile()) { aufruf += " --commitfile " + actFile.getGlob(); } for (Variable actVariable : actCommit.getVariable()) { aufruf += " --commitvariable " + actVariable.getKey() + "=" + actVariable.getValue(); } } } report.setParameter("stepWorkCall", aufruf); // P51x) bild an report melden report.setParameter("stepTopologyImagePath", stepTopologyImagePath.get(actualStep.getName())); // ueber alle lists iterieren for (List actualList : actualStep.getList()) { HashMap<String, Object> row = new HashMap<String, Object>(); // Spalte 'Woher?' row.put("origin", "-"); // Spalte 'typ' row.put("objectType", "wert"); // Spalte 'minOccur' row.put("minOccur", "-"); // Spalte 'maxOccur' row.put("maxOccur", "-"); // Spalte 'Label' row.put("objectKey", actualList.getName()); // Spalte 'Label' String listString = actualList.getItem().toString(); row.put("objectDescription", listString.substring(1, listString.length() - 1)); report.addField(row); } // ueber alle inits iterieren for (Init actualInit : actualStep.getInit()) { HashMap<String, Object> row = new HashMap<String, Object>(); // Spalte 'Woher?' if (actualInit.getFromstep().equals(process.getRootstepname())) { row.put("origin", "user/cb2"); } else { row.put("origin", actualInit.getFromstep()); } // Spalte 'typ' row.put("objectType", actualInit.getFromobjecttype()); // Spalte 'minOccur' row.put("minOccur", "" + actualInit.getMinoccur()); // Spalte 'maxOccur' row.put("maxOccur", "" + actualInit.getMaxoccur()); // Spalte 'Label' row.put("objectKey", actualInit.getListname()); // Spalte 'Label' row.put("objectDescription", "-"); report.addField(row); } try { report.fillReportFileToFile(jasperPathP51, jasperFilledPathP51); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } // export to pdf try { report.convertFileToPdf(jasperFilledPathP51, pdfPathP51); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } // export to pptx try { report.convertFileToPptx(jasperFilledPathP51, pptxPathP51); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } report = null; } } ////////////////////////////////////////// // fuer jeden Step einen eigenen Output Report erzeugen for (Step actualStep : process.getStep()) { // root-step ueberspringen if (actualStep.getName().equals(process.getRootstepname())) { System.out.println("skipping step root"); } // alle anderen auswerten else { report = new Reporter(); // P52x) erstellen des p52 System.out.println( "info: generating p52 for step " + actualStep.getRank() + " => " + actualStep.getName()); String stepRank = actualStep.getRank(); String pdfPathP52 = null; String pptxPathP52 = null; String jasperPathP52 = null; String jasperFilledPathP52 = null; // P52x) feststellen, welches jasperreports-template fuer den angeforderten typ verwendet werden soll if (ini.get("pkraft-createdoc", "p52") != null) { pdfPathP52 = randomPathPdf + "/p5." + stepRank + ".2.pdf"; pptxPathP52 = randomPathPptx + "/p5." + stepRank + ".2.pptx"; jasperPathP52 = installDir.getAbsolutePath() + "/" + ini.get("pkraft-createdoc", "p52"); jasperFilledPathP52 = randomPathJasperFilled + "/p5." + stepRank + ".1.jasperFilled"; String[] rankArray = stepRank.split("\\."); Integer[] rankArrayInt = new Integer[rankArray.length]; for (int x = 0; x < rankArray.length; x++) { rankArrayInt[x] = Integer.parseInt(rankArray[x]); } String rankFormated = String.format("%03d.%03d", rankArrayInt); pdfRankFiles.put(rankFormated + ".2", pdfPathP52); pptxRankFiles.put(rankFormated + ".2", pptxPathP52); } else { System.err.println("no entry 'p52' found in ini file"); System.exit(1); } report.setParameter("processName", process.getName()); report.setParameter("processVersion", process.getVersion()); report.setParameter("processArchitectCompany", process.getArchitectCompany()); report.setParameter("processArchitectName", process.getArchitectName()); report.setParameter("processArchitectMail", process.getArchitectMail()); report.setParameter("processCustomerCompany", process.getCustomerCompany()); report.setParameter("processCustomerName", process.getCustomerName()); report.setParameter("processCustomerMail", process.getCustomerMail()); report.setParameter("stepName", actualStep.getName()); report.setParameter("stepRank", stepRank); // logfile ermitteln String logfile = "-"; if (actualStep.getWork() != null) { if (actualStep.getWork().getLogfile() == null || actualStep.getWork().getLogfile().equals("")) { report.setParameter("stepWorkLogfile", actualStep.getWork().getLogfile()); } } else if (actualStep.getSubprocess() != null) { logfile = ".log"; } report.setParameter("stepWorkLogfile", logfile); // zusammensetzen der return/exitcode informationen String exitInfo = "exit 0 = kein fehler aufgetreten"; exitInfo += "\nexit >0 = ein fehler ist aufgetreten."; if (actualStep.getWork() != null) { for (Exit actualExit : actualStep.getWork().getExit()) { exitInfo += "\nexit " + actualExit.getValue() + " = " + actualExit.getMsg(); } } report.setParameter("stepWorkExit", exitInfo); // P52x) bild an report melden report.setParameter("stepTopologyImagePath", stepTopologyImagePath.get(actualStep.getName())); // ueber alle inits iterieren for (Commit actualCommit : actualStep.getCommit()) { // ueber alle files iterieren for (de.prozesskraft.pkraft.File actualFile : actualCommit.getFile()) { HashMap<String, Object> row = new HashMap<String, Object>(); // Spalte 'destination' if (actualCommit.isTorootPresent()) { row.put("destination", "user/cb2"); } else { row.put("destination", "prozessintern"); } // Spalte 'objectType' row.put("objectType", "file"); // Spalte 'minOccur' row.put("minOccur", "" + actualFile.getMinoccur()); // Spalte 'maxOccur' row.put("maxOccur", "" + actualFile.getMaxoccur()); // Spalte 'objectKey' row.put("objectKey", actualFile.getKey()); // Spalte 'objectDescription' row.put("objectDescription", actualFile.getDescription()); // Datensatz dem report hinzufuegen report.addField(row); } // ueber alle variablen iterieren for (de.prozesskraft.pkraft.Variable actualVariable : actualCommit.getVariable()) { HashMap<String, Object> row = new HashMap<String, Object>(); // Spalte 'destination' if (actualCommit.isTorootPresent()) { row.put("destination", "user/cb2"); } else { row.put("destination", "prozessintern"); } // Spalte 'objectType' row.put("objectType", "variable"); // Spalte 'minOccur' row.put("minOccur", "" + actualVariable.getMinoccur()); // Spalte 'maxOccur' row.put("maxOccur", "" + actualVariable.getMaxoccur()); // Spalte 'objectKey' row.put("objectKey", actualVariable.getKey()); // Spalte 'objectDescription' row.put("objectDescription", actualVariable.getDescription()); // Datensatz dem report hinzufuegen report.addField(row); } } try { report.fillReportFileToFile(jasperPathP52, jasperFilledPathP52); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } // export to pdf try { report.convertFileToPdf(jasperFilledPathP52, pdfPathP52); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } // export to pptx try { report.convertFileToPptx(jasperFilledPathP52, pptxPathP52); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JRException e) { // TODO Auto-generated catch block e.printStackTrace(); } report = null; } } // warten bis alles auf platte geschrieben ist try { Thread.sleep(1000); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } // merge and output if (format.equals("pdf")) { mergePdf(pdfRankFiles, output); } else if (format.equals("pptx")) { mergePptx(pptxRankFiles, output); } System.out.println("info: generating process documentation ready."); System.exit(0); }
From source file:edu.nyu.vida.data_polygamy.scalar_function_computation.Aggregation.java
/** * @param args/*from ww w. ja v a 2 s . c om*/ */ @SuppressWarnings({ "deprecation" }) public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException { Options options = new Options(); Option forceOption = new Option("f", "force", false, "force the computation of the aggregate functions " + "even if files already exist"); forceOption.setRequired(false); options.addOption(forceOption); Option gOption = new Option("g", "group", true, "set group of datasets for which the aggregate functions" + " will be computed, followed by their temporal and spatial attribute indices"); gOption.setRequired(true); gOption.setArgName("GROUP"); gOption.setArgs(Option.UNLIMITED_VALUES); options.addOption(gOption); Option machineOption = new Option("m", "machine", true, "machine identifier"); machineOption.setRequired(true); machineOption.setArgName("MACHINE"); machineOption.setArgs(1); options.addOption(machineOption); Option nodesOption = new Option("n", "nodes", true, "number of nodes"); nodesOption.setRequired(true); nodesOption.setArgName("NODES"); nodesOption.setArgs(1); options.addOption(nodesOption); Option s3Option = new Option("s3", "s3", false, "data on Amazon S3"); s3Option.setRequired(false); options.addOption(s3Option); Option awsAccessKeyIdOption = new Option("aws_id", "aws-id", true, "aws access key id; " + "this is required if the execution is on aws"); awsAccessKeyIdOption.setRequired(false); awsAccessKeyIdOption.setArgName("AWS-ACCESS-KEY-ID"); awsAccessKeyIdOption.setArgs(1); options.addOption(awsAccessKeyIdOption); Option awsSecretAccessKeyOption = new Option("aws_key", "aws-id", true, "aws secrect access key; " + "this is required if the execution is on aws"); awsSecretAccessKeyOption.setRequired(false); awsSecretAccessKeyOption.setArgName("AWS-SECRET-ACCESS-KEY"); awsSecretAccessKeyOption.setArgs(1); options.addOption(awsSecretAccessKeyOption); Option bucketOption = new Option("b", "s3-bucket", true, "bucket on s3; " + "this is required if the execution is on aws"); bucketOption.setRequired(false); bucketOption.setArgName("S3-BUCKET"); bucketOption.setArgs(1); options.addOption(bucketOption); Option helpOption = new Option("h", "help", false, "display this message"); helpOption.setRequired(false); options.addOption(helpOption); HelpFormatter formatter = new HelpFormatter(); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { formatter.printHelp("hadoop jar data-polygamy.jar " + "edu.nyu.vida.data_polygamy.scalar_function_computation.Aggregation", options, true); System.exit(0); } if (cmd.hasOption("h")) { formatter.printHelp("hadoop jar data-polygamy.jar " + "edu.nyu.vida.data_polygamy.scalar_function_computation.Aggregation", options, true); System.exit(0); } boolean s3 = cmd.hasOption("s3"); String s3bucket = ""; String awsAccessKeyId = ""; String awsSecretAccessKey = ""; if (s3) { if ((!cmd.hasOption("aws_id")) || (!cmd.hasOption("aws_key")) || (!cmd.hasOption("b"))) { System.out.println( "Arguments 'aws_id', 'aws_key', and 'b'" + " are mandatory if execution is on AWS."); formatter.printHelp( "hadoop jar data-polygamy.jar " + "edu.nyu.vida.data_polygamy.scalar_function_computation.Aggregation", options, true); System.exit(0); } s3bucket = cmd.getOptionValue("b"); awsAccessKeyId = cmd.getOptionValue("aws_id"); awsSecretAccessKey = cmd.getOptionValue("aws_key"); } boolean snappyCompression = false; boolean bzip2Compression = false; String machine = cmd.getOptionValue("m"); int nbNodes = Integer.parseInt(cmd.getOptionValue("n")); Configuration s3conf = new Configuration(); if (s3) { s3conf.set("fs.s3.awsAccessKeyId", awsAccessKeyId); s3conf.set("fs.s3.awsSecretAccessKey", awsSecretAccessKey); s3conf.set("bucket", s3bucket); } String datasetNames = ""; String datasetIds = ""; String preProcessingDatasets = ""; ArrayList<String> shortDataset = new ArrayList<String>(); ArrayList<String> shortDatasetAggregation = new ArrayList<String>(); HashMap<String, String> datasetTempAtt = new HashMap<String, String>(); HashMap<String, String> datasetSpatialAtt = new HashMap<String, String>(); HashMap<String, String> preProcessingDataset = new HashMap<String, String>(); HashMap<String, String> datasetId = new HashMap<String, String>(); boolean removeExistingFiles = cmd.hasOption("f"); String[] datasetArgs = cmd.getOptionValues("g"); for (int i = 0; i < datasetArgs.length; i += 3) { String dataset = datasetArgs[i]; // getting pre-processing String tempPreProcessing = FrameworkUtils.searchPreProcessing(dataset, s3conf, s3); if (tempPreProcessing == null) { System.out.println("No pre-processing available for " + dataset); continue; } preProcessingDataset.put(dataset, tempPreProcessing); shortDataset.add(dataset); datasetTempAtt.put(dataset, ((datasetArgs[i + 1] == "null") ? null : datasetArgs[i + 1])); datasetSpatialAtt.put(dataset, ((datasetArgs[i + 2] == "null") ? null : datasetArgs[i + 2])); datasetId.put(dataset, null); } if (shortDataset.size() == 0) { System.out.println("No datasets to process."); System.exit(0); } // getting dataset id Path path = null; FileSystem fs = null; if (s3) { path = new Path(s3bucket + FrameworkUtils.datasetsIndexDir); fs = FileSystem.get(path.toUri(), s3conf); } else { fs = FileSystem.get(new Configuration()); path = new Path(fs.getHomeDirectory() + "/" + FrameworkUtils.datasetsIndexDir); } BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(path))); String line = br.readLine(); while (line != null) { String[] dt = line.split("\t"); if (datasetId.containsKey(dt[0])) { datasetId.put(dt[0], dt[1]); datasetNames += dt[0] + ","; datasetIds += dt[1] + ","; } line = br.readLine(); } br.close(); if (s3) fs.close(); datasetNames = datasetNames.substring(0, datasetNames.length() - 1); datasetIds = datasetIds.substring(0, datasetIds.length() - 1); Iterator<String> it = shortDataset.iterator(); while (it.hasNext()) { String dataset = it.next(); if (datasetId.get(dataset) == null) { System.out.println("No dataset id for " + dataset); System.exit(0); } } FrameworkUtils.createDir(s3bucket + FrameworkUtils.aggregatesDir, s3conf, s3); // getting smallest resolution HashMap<String, String> tempResMap = new HashMap<String, String>(); HashMap<String, String> spatialResMap = new HashMap<String, String>(); HashMap<String, String> datasetTemporalStrMap = new HashMap<String, String>(); HashMap<String, String> datasetSpatialStrMap = new HashMap<String, String>(); HashSet<String> input = new HashSet<String>(); for (String dataset : shortDataset) { String[] datasetArray = preProcessingDataset.get(dataset).split("-"); String datasetTemporalStr = datasetArray[datasetArray.length - 2]; int datasetTemporal = utils.temporalResolution(datasetTemporalStr); String datasetSpatialStr = datasetArray[datasetArray.length - 1]; int datasetSpatial = utils.spatialResolution(datasetSpatialStr); // finding all possible resolutions String[] temporalResolutions = FrameworkUtils.getAggTempResolutions(datasetTemporal); String[] spatialResolutions = FrameworkUtils.getAggSpatialResolutions(datasetSpatial); String temporalResolution = ""; String spatialResolution = ""; String tempRes = ""; String spatialRes = ""; boolean dataAdded = false; for (int i = 0; i < temporalResolutions.length; i++) { for (int j = 0; j < spatialResolutions.length; j++) { temporalResolution = temporalResolutions[i]; spatialResolution = spatialResolutions[j]; String aggregatesOutputFileName = s3bucket + FrameworkUtils.aggregatesDir + "/" + dataset + "/"; if (removeExistingFiles) { FrameworkUtils.removeFile(aggregatesOutputFileName, s3conf, s3); } if (!FrameworkUtils.fileExists(aggregatesOutputFileName, s3conf, s3)) { dataAdded = true; tempRes += temporalResolution + "-"; spatialRes += spatialResolution + "-"; } } } if (dataAdded) { input.add(s3bucket + FrameworkUtils.preProcessingDir + "/" + preProcessingDataset.get(dataset)); shortDatasetAggregation.add(dataset); tempResMap.put(dataset, tempRes.substring(0, tempRes.length() - 1)); spatialResMap.put(dataset, spatialRes.substring(0, spatialRes.length() - 1)); datasetTemporalStrMap.put(dataset, datasetTemporalStr); datasetSpatialStrMap.put(dataset, datasetSpatialStr); } } if (input.isEmpty()) { System.out.println("All the input datasets have aggregates."); System.out.println("Use -f in the beginning of the command line to force the computation."); System.exit(0); } it = input.iterator(); while (it.hasNext()) { preProcessingDatasets += it.next() + ","; } Job aggJob = null; String aggregatesOutputDir = s3bucket + FrameworkUtils.aggregatesDir + "/tmp/"; String jobName = "aggregates"; FrameworkUtils.removeFile(aggregatesOutputDir, s3conf, s3); Configuration aggConf = new Configuration(); Machine machineConf = new Machine(machine, nbNodes); aggConf.set("dataset-name", datasetNames); aggConf.set("dataset-id", datasetIds); for (int i = 0; i < shortDatasetAggregation.size(); i++) { String dataset = shortDatasetAggregation.get(i); String id = datasetId.get(dataset); aggConf.set("dataset-" + id + "-temporal-resolutions", tempResMap.get(dataset)); aggConf.set("dataset-" + id + "-spatial-resolutions", spatialResMap.get(dataset)); aggConf.set("dataset-" + id + "-temporal-att", datasetTempAtt.get(dataset)); aggConf.set("dataset-" + id + "-spatial-att", datasetSpatialAtt.get(dataset)); aggConf.set("dataset-" + id + "-temporal", datasetTemporalStrMap.get(dataset)); aggConf.set("dataset-" + id + "-spatial", datasetSpatialStrMap.get(dataset)); if (s3) aggConf.set("dataset-" + id, s3bucket + FrameworkUtils.preProcessingDir + "/" + preProcessingDataset.get(dataset)); else aggConf.set("dataset-" + id, FileSystem.get(new Configuration()).getHomeDirectory() + "/" + FrameworkUtils.preProcessingDir + "/" + preProcessingDataset.get(dataset)); } aggConf.set("mapreduce.tasktracker.map.tasks.maximum", String.valueOf(machineConf.getMaximumTasks())); aggConf.set("mapreduce.tasktracker.reduce.tasks.maximum", String.valueOf(machineConf.getMaximumTasks())); aggConf.set("mapreduce.jobtracker.maxtasks.perjob", "-1"); aggConf.set("mapreduce.reduce.shuffle.parallelcopies", "20"); aggConf.set("mapreduce.input.fileinputformat.split.minsize", "0"); aggConf.set("mapreduce.task.io.sort.mb", "200"); aggConf.set("mapreduce.task.io.sort.factor", "100"); machineConf.setMachineConfiguration(aggConf); if (s3) { machineConf.setMachineConfiguration(aggConf); aggConf.set("fs.s3.awsAccessKeyId", awsAccessKeyId); aggConf.set("fs.s3.awsSecretAccessKey", awsSecretAccessKey); } if (snappyCompression) { aggConf.set("mapreduce.map.output.compress", "true"); aggConf.set("mapreduce.map.output.compress.codec", "org.apache.hadoop.io.compress.SnappyCodec"); //aggConf.set("mapreduce.output.fileoutputformat.compress.codec", "org.apache.hadoop.io.compress.SnappyCodec"); } if (bzip2Compression) { aggConf.set("mapreduce.map.output.compress", "true"); aggConf.set("mapreduce.map.output.compress.codec", "org.apache.hadoop.io.compress.BZip2Codec"); //aggConf.set("mapreduce.output.fileoutputformat.compress.codec", "org.apache.hadoop.io.compress.BZip2Codec"); } aggJob = new Job(aggConf); aggJob.setJobName(jobName); aggJob.setMapOutputKeyClass(SpatioTemporalWritable.class); aggJob.setMapOutputValueClass(AggregationArrayWritable.class); aggJob.setOutputKeyClass(SpatioTemporalWritable.class); aggJob.setOutputValueClass(FloatArrayWritable.class); //aggJob.setOutputKeyClass(Text.class); //aggJob.setOutputValueClass(Text.class); aggJob.setMapperClass(AggregationMapper.class); aggJob.setCombinerClass(AggregationCombiner.class); aggJob.setReducerClass(AggregationReducer.class); aggJob.setNumReduceTasks(machineConf.getNumberReduces()); aggJob.setInputFormatClass(SequenceFileInputFormat.class); //aggJob.setOutputFormatClass(SequenceFileOutputFormat.class); LazyOutputFormat.setOutputFormatClass(aggJob, SequenceFileOutputFormat.class); //LazyOutputFormat.setOutputFormatClass(aggJob, TextOutputFormat.class); SequenceFileOutputFormat.setCompressOutput(aggJob, true); SequenceFileOutputFormat.setOutputCompressionType(aggJob, CompressionType.BLOCK); FileInputFormat.setInputDirRecursive(aggJob, true); FileInputFormat.setInputPaths(aggJob, preProcessingDatasets.substring(0, preProcessingDatasets.length() - 1)); FileOutputFormat.setOutputPath(aggJob, new Path(aggregatesOutputDir)); aggJob.setJarByClass(Aggregation.class); long start = System.currentTimeMillis(); aggJob.submit(); aggJob.waitForCompletion(true); System.out.println(jobName + "\t" + (System.currentTimeMillis() - start)); // moving files to right place for (String dataset : shortDatasetAggregation) { String from = s3bucket + FrameworkUtils.aggregatesDir + "/tmp/" + dataset + "/"; String to = s3bucket + FrameworkUtils.aggregatesDir + "/" + dataset + "/"; FrameworkUtils.renameFile(from, to, s3conf, s3); } }
From source file:DIA_Umpire_Quant.DIA_Umpire_ExtLibSearch.java
/** * @param args the command line arguments *//*from ww w.j a v a 2 s . c om*/ public static void main(String[] args) throws FileNotFoundException, IOException, Exception { System.out.println( "================================================================================================="); System.out.println("DIA-Umpire targeted re-extraction analysis using external library (version: " + UmpireInfo.GetInstance().Version + ")"); if (args.length != 1) { System.out.println( "command format error, the correct format should be: java -jar -Xmx10G DIA_Umpire_ExtLibSearch.jar diaumpire_module.params"); return; } try { ConsoleLogger.SetConsoleLogger(Level.INFO); ConsoleLogger.SetFileLogger(Level.DEBUG, FilenameUtils.getFullPath(args[0]) + "diaumpire_extlibsearch.log"); } catch (Exception e) { } Logger.getRootLogger().info("Version: " + UmpireInfo.GetInstance().Version); Logger.getRootLogger().info("Parameter file:" + args[0]); BufferedReader reader = new BufferedReader(new FileReader(args[0])); String line = ""; String WorkFolder = ""; int NoCPUs = 2; String ExternalLibPath = ""; String ExternalLibDecoyTag = "DECOY"; float ExtProbThreshold = 0.99f; float RTWindow_Ext = -1f; TandemParam tandemPara = new TandemParam(DBSearchParam.SearchInstrumentType.TOF5600); HashMap<String, File> AssignFiles = new HashMap<>(); //<editor-fold defaultstate="collapsed" desc="Reading parameter file"> while ((line = reader.readLine()) != null) { line = line.trim(); Logger.getRootLogger().info(line); if (!"".equals(line) && !line.startsWith("#")) { //System.out.println(line); if (line.equals("==File list begin")) { do { line = reader.readLine(); line = line.trim(); if (line.equals("==File list end")) { continue; } else if (!"".equals(line)) { File newfile = new File(line); if (newfile.exists()) { AssignFiles.put(newfile.getAbsolutePath(), newfile); } else { Logger.getRootLogger().info("File: " + newfile + " does not exist."); } } } while (!line.equals("==File list end")); } if (line.split("=").length < 2) { continue; } String type = line.split("=")[0].trim(); String value = line.split("=")[1].trim(); switch (type) { case "Path": { WorkFolder = value; break; } case "path": { WorkFolder = value; break; } case "Thread": { NoCPUs = Integer.parseInt(value); break; } case "Fasta": { tandemPara.FastaPath = value; break; } case "DecoyPrefix": { if (!"".equals(value)) { tandemPara.DecoyPrefix = value; } break; } case "ExternalLibPath": { ExternalLibPath = value; break; } case "ExtProbThreshold": { ExtProbThreshold = Float.parseFloat(value); break; } case "RTWindow_Ext": { RTWindow_Ext = Float.parseFloat(value); break; } case "ExternalLibDecoyTag": { ExternalLibDecoyTag = value; if (ExternalLibDecoyTag.endsWith("_")) { ExternalLibDecoyTag = ExternalLibDecoyTag.substring(0, ExternalLibDecoyTag.length() - 1); } break; } } } } //</editor-fold> //Initialize PTM manager using compomics library PTMManager.GetInstance(); //Check if the fasta file can be found if (!new File(tandemPara.FastaPath).exists()) { Logger.getRootLogger().info("Fasta file :" + tandemPara.FastaPath + " cannot be found, the process will be terminated, please check."); System.exit(1); } //Generate DIA file list ArrayList<DIAPack> FileList = new ArrayList<>(); File folder = new File(WorkFolder); if (!folder.exists()) { Logger.getRootLogger().info("The path : " + WorkFolder + " cannot be found."); System.exit(1); } for (final File fileEntry : folder.listFiles()) { if (fileEntry.isFile() && (fileEntry.getAbsolutePath().toLowerCase().endsWith(".mzxml") | fileEntry.getAbsolutePath().toLowerCase().endsWith(".mzml")) && !fileEntry.getAbsolutePath().toLowerCase().endsWith("q1.mzxml") && !fileEntry.getAbsolutePath().toLowerCase().endsWith("q2.mzxml") && !fileEntry.getAbsolutePath().toLowerCase().endsWith("q3.mzxml")) { AssignFiles.put(fileEntry.getAbsolutePath(), fileEntry); } if (fileEntry.isDirectory()) { for (final File fileEntry2 : fileEntry.listFiles()) { if (fileEntry2.isFile() && (fileEntry2.getAbsolutePath().toLowerCase().endsWith(".mzxml") | fileEntry2.getAbsolutePath().toLowerCase().endsWith(".mzml")) && !fileEntry2.getAbsolutePath().toLowerCase().endsWith("q1.mzxml") && !fileEntry2.getAbsolutePath().toLowerCase().endsWith("q2.mzxml") && !fileEntry2.getAbsolutePath().toLowerCase().endsWith("q3.mzxml")) { AssignFiles.put(fileEntry2.getAbsolutePath(), fileEntry2); } } } } Logger.getRootLogger().info("No. of files assigned :" + AssignFiles.size()); for (File fileEntry : AssignFiles.values()) { Logger.getRootLogger().info(fileEntry.getAbsolutePath()); } for (File fileEntry : AssignFiles.values()) { String mzXMLFile = fileEntry.getAbsolutePath(); if (mzXMLFile.toLowerCase().endsWith(".mzxml") | mzXMLFile.toLowerCase().endsWith(".mzml")) { DIAPack DiaFile = new DIAPack(mzXMLFile, NoCPUs); Logger.getRootLogger().info( "================================================================================================="); Logger.getRootLogger().info("Processing " + mzXMLFile); if (!DiaFile.LoadDIASetting()) { Logger.getRootLogger().info("Loading DIA setting failed, job is incomplete"); System.exit(1); } if (!DiaFile.LoadParams()) { Logger.getRootLogger().info("Loading parameters failed, job is incomplete"); System.exit(1); } Logger.getRootLogger().info("Loading identification results " + mzXMLFile + "...."); //If the serialization file for ID file existed if (DiaFile.ReadSerializedLCMSID()) { DiaFile.IDsummary.ReduceMemoryUsage(); DiaFile.IDsummary.FastaPath = tandemPara.FastaPath; FileList.add(DiaFile); } } } //<editor-fold defaultstate="collapsed" desc="Targeted re-extraction using external library"> //External library search Logger.getRootLogger().info("Targeted extraction using external library"); //Read exteranl library FragmentLibManager ExlibManager = FragmentLibManager.ReadFragmentLibSerialization(WorkFolder, FilenameUtils.getBaseName(ExternalLibPath)); if (ExlibManager == null) { ExlibManager = new FragmentLibManager(FilenameUtils.getBaseName(ExternalLibPath)); //Import traML file ExlibManager.ImportFragLibByTraML(ExternalLibPath, ExternalLibDecoyTag); //Check if there are decoy spectra ExlibManager.CheckDecoys(); //ExlibManager.ImportFragLibBySPTXT(ExternalLibPath); ExlibManager.WriteFragmentLibSerialization(WorkFolder); } Logger.getRootLogger() .info("No. of peptide ions in external lib:" + ExlibManager.PeptideFragmentLib.size()); for (DIAPack diafile : FileList) { if (diafile.IDsummary == null) { diafile.ReadSerializedLCMSID(); } //Generate RT mapping RTMappingExtLib RTmap = new RTMappingExtLib(diafile.IDsummary, ExlibManager, diafile.GetParameter()); RTmap.GenerateModel(); RTmap.GenerateMappedPepIon(); diafile.BuildStructure(); diafile.MS1FeatureMap.ReadPeakCluster(); diafile.GenerateMassCalibrationRTMap(); //Perform targeted re-extraction diafile.TargetedExtractionQuant(false, ExlibManager, ExtProbThreshold, RTWindow_Ext); diafile.MS1FeatureMap.ClearAllPeaks(); diafile.IDsummary.ReduceMemoryUsage(); //Remove target IDs below the defined probability threshold diafile.IDsummary.RemoveLowProbMappedIon(ExtProbThreshold); diafile.ExportID(); diafile.ClearStructure(); Logger.getRootLogger().info("Peptide ions: " + diafile.IDsummary.GetPepIonList().size() + " Mapped ions: " + diafile.IDsummary.GetMappedPepIonList().size()); } //</editor-fold> Logger.getRootLogger().info("Job done"); Logger.getRootLogger().info( "================================================================================================="); }
From source file:edu.nyu.vida.data_polygamy.feature_identification.IndexCreation.java
/** * @param args// ww w . j av a2s.c om */ @SuppressWarnings({ "deprecation" }) public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException { Options options = new Options(); Option forceOption = new Option("f", "force", false, "force the computation of the index and events " + "even if files already exist"); forceOption.setRequired(false); options.addOption(forceOption); Option thresholdOption = new Option("t", "use-custom-thresholds", false, "use custom thresholds for regular and rare events, defined in HDFS_HOME/" + FrameworkUtils.thresholdDir + " file"); thresholdOption.setRequired(false); options.addOption(thresholdOption); Option gOption = new Option("g", "group", true, "set group of datasets for which the indices and events" + " will be computed"); gOption.setRequired(true); gOption.setArgName("GROUP"); gOption.setArgs(Option.UNLIMITED_VALUES); options.addOption(gOption); Option machineOption = new Option("m", "machine", true, "machine identifier"); machineOption.setRequired(true); machineOption.setArgName("MACHINE"); machineOption.setArgs(1); options.addOption(machineOption); Option nodesOption = new Option("n", "nodes", true, "number of nodes"); nodesOption.setRequired(true); nodesOption.setArgName("NODES"); nodesOption.setArgs(1); options.addOption(nodesOption); Option s3Option = new Option("s3", "s3", false, "data on Amazon S3"); s3Option.setRequired(false); options.addOption(s3Option); Option awsAccessKeyIdOption = new Option("aws_id", "aws-id", true, "aws access key id; " + "this is required if the execution is on aws"); awsAccessKeyIdOption.setRequired(false); awsAccessKeyIdOption.setArgName("AWS-ACCESS-KEY-ID"); awsAccessKeyIdOption.setArgs(1); options.addOption(awsAccessKeyIdOption); Option awsSecretAccessKeyOption = new Option("aws_key", "aws-id", true, "aws secrect access key; " + "this is required if the execution is on aws"); awsSecretAccessKeyOption.setRequired(false); awsSecretAccessKeyOption.setArgName("AWS-SECRET-ACCESS-KEY"); awsSecretAccessKeyOption.setArgs(1); options.addOption(awsSecretAccessKeyOption); Option bucketOption = new Option("b", "s3-bucket", true, "bucket on s3; " + "this is required if the execution is on aws"); bucketOption.setRequired(false); bucketOption.setArgName("S3-BUCKET"); bucketOption.setArgs(1); options.addOption(bucketOption); Option helpOption = new Option("h", "help", false, "display this message"); helpOption.setRequired(false); options.addOption(helpOption); HelpFormatter formatter = new HelpFormatter(); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { formatter.printHelp("hadoop jar data-polygamy.jar " + "edu.nyu.vida.data_polygamy.feature_identification.IndexCreation", options, true); System.exit(0); } if (cmd.hasOption("h")) { formatter.printHelp("hadoop jar data-polygamy.jar " + "edu.nyu.vida.data_polygamy.feature_identification.IndexCreation", options, true); System.exit(0); } boolean s3 = cmd.hasOption("s3"); String s3bucket = ""; String awsAccessKeyId = ""; String awsSecretAccessKey = ""; if (s3) { if ((!cmd.hasOption("aws_id")) || (!cmd.hasOption("aws_key")) || (!cmd.hasOption("b"))) { System.out.println( "Arguments 'aws_id', 'aws_key', and 'b'" + " are mandatory if execution is on AWS."); formatter.printHelp("hadoop jar data-polygamy.jar " + "edu.nyu.vida.data_polygamy.feature_identification.IndexCreation", options, true); System.exit(0); } s3bucket = cmd.getOptionValue("b"); awsAccessKeyId = cmd.getOptionValue("aws_id"); awsSecretAccessKey = cmd.getOptionValue("aws_key"); } boolean snappyCompression = false; boolean bzip2Compression = false; String machine = cmd.getOptionValue("m"); int nbNodes = Integer.parseInt(cmd.getOptionValue("n")); Configuration s3conf = new Configuration(); if (s3) { s3conf.set("fs.s3.awsAccessKeyId", awsAccessKeyId); s3conf.set("fs.s3.awsSecretAccessKey", awsSecretAccessKey); s3conf.set("bucket", s3bucket); } String datasetNames = ""; String datasetIds = ""; ArrayList<String> shortDataset = new ArrayList<String>(); ArrayList<String> shortDatasetIndex = new ArrayList<String>(); HashMap<String, String> datasetAgg = new HashMap<String, String>(); HashMap<String, String> datasetId = new HashMap<String, String>(); HashMap<String, HashMap<Integer, Double>> datasetRegThreshold = new HashMap<String, HashMap<Integer, Double>>(); HashMap<String, HashMap<Integer, Double>> datasetRareThreshold = new HashMap<String, HashMap<Integer, Double>>(); Path path = null; FileSystem fs = FileSystem.get(new Configuration()); BufferedReader br; boolean removeExistingFiles = cmd.hasOption("f"); boolean isThresholdUserDefined = cmd.hasOption("t"); for (String dataset : cmd.getOptionValues("g")) { // getting aggregates String[] aggregate = FrameworkUtils.searchAggregates(dataset, s3conf, s3); if (aggregate.length == 0) { System.out.println("No aggregates found for " + dataset + "."); continue; } // getting aggregates header String aggregatesHeaderFileName = FrameworkUtils.searchAggregatesHeader(dataset, s3conf, s3); if (aggregatesHeaderFileName == null) { System.out.println("No aggregate header for " + dataset); continue; } String aggregatesHeader = s3bucket + FrameworkUtils.preProcessingDir + "/" + aggregatesHeaderFileName; shortDataset.add(dataset); datasetId.put(dataset, null); if (s3) { path = new Path(aggregatesHeader); fs = FileSystem.get(path.toUri(), s3conf); } else { path = new Path(fs.getHomeDirectory() + "/" + aggregatesHeader); } br = new BufferedReader(new InputStreamReader(fs.open(path))); datasetAgg.put(dataset, br.readLine().split("\t")[1]); br.close(); if (s3) fs.close(); } if (shortDataset.size() == 0) { System.out.println("No datasets to process."); System.exit(0); } // getting dataset id if (s3) { path = new Path(s3bucket + FrameworkUtils.datasetsIndexDir); fs = FileSystem.get(path.toUri(), s3conf); } else { path = new Path(fs.getHomeDirectory() + "/" + FrameworkUtils.datasetsIndexDir); } br = new BufferedReader(new InputStreamReader(fs.open(path))); String line = br.readLine(); while (line != null) { String[] dt = line.split("\t"); if (datasetId.containsKey(dt[0])) { datasetId.put(dt[0], dt[1]); datasetNames += dt[0] + ","; datasetIds += dt[1] + ","; } line = br.readLine(); } br.close(); datasetNames = datasetNames.substring(0, datasetNames.length() - 1); datasetIds = datasetIds.substring(0, datasetIds.length() - 1); Iterator<String> it = shortDataset.iterator(); while (it.hasNext()) { String dataset = it.next(); if (datasetId.get(dataset) == null) { System.out.println("No dataset id for " + dataset); System.exit(0); } } // getting user defined thresholds if (isThresholdUserDefined) { if (s3) { path = new Path(s3bucket + FrameworkUtils.thresholdDir); fs = FileSystem.get(path.toUri(), s3conf); } else { path = new Path(fs.getHomeDirectory() + "/" + FrameworkUtils.thresholdDir); } br = new BufferedReader(new InputStreamReader(fs.open(path))); line = br.readLine(); while (line != null) { // getting dataset name String dataset = line.trim(); HashMap<Integer, Double> regThresholds = new HashMap<Integer, Double>(); HashMap<Integer, Double> rareThresholds = new HashMap<Integer, Double>(); line = br.readLine(); while ((line != null) && (line.split("\t").length > 1)) { // getting attribute ids and thresholds String[] keyVals = line.trim().split("\t"); int att = Integer.parseInt(keyVals[0].trim()); regThresholds.put(att, Double.parseDouble(keyVals[1].trim())); rareThresholds.put(att, Double.parseDouble(keyVals[2].trim())); line = br.readLine(); } datasetRegThreshold.put(dataset, regThresholds); datasetRareThreshold.put(dataset, rareThresholds); } br.close(); } if (s3) fs.close(); // datasets that will use existing merge tree ArrayList<String> useMergeTree = new ArrayList<String>(); // creating index for each spatio-temporal resolution FrameworkUtils.createDir(s3bucket + FrameworkUtils.indexDir, s3conf, s3); HashSet<String> input = new HashSet<String>(); for (String dataset : shortDataset) { String indexCreationOutputFileName = s3bucket + FrameworkUtils.indexDir + "/" + dataset + "/"; String mergeTreeFileName = s3bucket + FrameworkUtils.mergeTreeDir + "/" + dataset + "/"; if (removeExistingFiles) { FrameworkUtils.removeFile(indexCreationOutputFileName, s3conf, s3); FrameworkUtils.removeFile(mergeTreeFileName, s3conf, s3); FrameworkUtils.createDir(mergeTreeFileName, s3conf, s3); } else if (datasetRegThreshold.containsKey(dataset)) { FrameworkUtils.removeFile(indexCreationOutputFileName, s3conf, s3); if (FrameworkUtils.fileExists(mergeTreeFileName, s3conf, s3)) { useMergeTree.add(dataset); } } if (!FrameworkUtils.fileExists(indexCreationOutputFileName, s3conf, s3)) { input.add(s3bucket + FrameworkUtils.aggregatesDir + "/" + dataset); shortDatasetIndex.add(dataset); } } if (input.isEmpty()) { System.out.println("All the input datasets have indices."); System.out.println("Use -f in the beginning of the command line to force the computation."); System.exit(0); } String aggregateDatasets = ""; it = input.iterator(); while (it.hasNext()) { aggregateDatasets += it.next() + ","; } Job icJob = null; Configuration icConf = new Configuration(); Machine machineConf = new Machine(machine, nbNodes); String jobName = "index"; String indexOutputDir = s3bucket + FrameworkUtils.indexDir + "/tmp/"; FrameworkUtils.removeFile(indexOutputDir, s3conf, s3); icConf.set("dataset-name", datasetNames); icConf.set("dataset-id", datasetIds); if (!useMergeTree.isEmpty()) { String useMergeTreeStr = ""; for (String dt : useMergeTree) { useMergeTreeStr += dt + ","; } icConf.set("use-merge-tree", useMergeTreeStr.substring(0, useMergeTreeStr.length() - 1)); } for (int i = 0; i < shortDataset.size(); i++) { String dataset = shortDataset.get(i); String id = datasetId.get(dataset); icConf.set("dataset-" + id + "-aggregates", datasetAgg.get(dataset)); if (datasetRegThreshold.containsKey(dataset)) { HashMap<Integer, Double> regThresholds = datasetRegThreshold.get(dataset); String thresholds = ""; for (int att : regThresholds.keySet()) { thresholds += String.valueOf(att) + "-" + String.valueOf(regThresholds.get(att)) + ","; } icConf.set("regular-" + id, thresholds.substring(0, thresholds.length() - 1)); } if (datasetRareThreshold.containsKey(dataset)) { HashMap<Integer, Double> rareThresholds = datasetRareThreshold.get(dataset); String thresholds = ""; for (int att : rareThresholds.keySet()) { thresholds += String.valueOf(att) + "-" + String.valueOf(rareThresholds.get(att)) + ","; } icConf.set("rare-" + id, thresholds.substring(0, thresholds.length() - 1)); } } icConf.set("mapreduce.tasktracker.map.tasks.maximum", String.valueOf(machineConf.getMaximumTasks())); icConf.set("mapreduce.tasktracker.reduce.tasks.maximum", String.valueOf(machineConf.getMaximumTasks())); icConf.set("mapreduce.jobtracker.maxtasks.perjob", "-1"); icConf.set("mapreduce.reduce.shuffle.parallelcopies", "20"); icConf.set("mapreduce.input.fileinputformat.split.minsize", "0"); icConf.set("mapreduce.task.io.sort.mb", "200"); icConf.set("mapreduce.task.io.sort.factor", "100"); //icConf.set("mapreduce.task.timeout", "1800000"); machineConf.setMachineConfiguration(icConf); if (s3) { machineConf.setMachineConfiguration(icConf); icConf.set("fs.s3.awsAccessKeyId", awsAccessKeyId); icConf.set("fs.s3.awsSecretAccessKey", awsSecretAccessKey); icConf.set("bucket", s3bucket); } if (snappyCompression) { icConf.set("mapreduce.map.output.compress", "true"); icConf.set("mapreduce.map.output.compress.codec", "org.apache.hadoop.io.compress.SnappyCodec"); //icConf.set("mapreduce.output.fileoutputformat.compress.codec", "org.apache.hadoop.io.compress.SnappyCodec"); } if (bzip2Compression) { icConf.set("mapreduce.map.output.compress", "true"); icConf.set("mapreduce.map.output.compress.codec", "org.apache.hadoop.io.compress.BZip2Codec"); //icConf.set("mapreduce.output.fileoutputformat.compress.codec", "org.apache.hadoop.io.compress.BZip2Codec"); } icJob = new Job(icConf); icJob.setJobName(jobName); icJob.setMapOutputKeyClass(AttributeResolutionWritable.class); icJob.setMapOutputValueClass(SpatioTemporalFloatWritable.class); icJob.setOutputKeyClass(AttributeResolutionWritable.class); icJob.setOutputValueClass(TopologyTimeSeriesWritable.class); //icJob.setOutputKeyClass(Text.class); //icJob.setOutputValueClass(Text.class); icJob.setMapperClass(IndexCreationMapper.class); icJob.setReducerClass(IndexCreationReducer.class); icJob.setNumReduceTasks(machineConf.getNumberReduces()); icJob.setInputFormatClass(SequenceFileInputFormat.class); //icJob.setOutputFormatClass(SequenceFileOutputFormat.class); LazyOutputFormat.setOutputFormatClass(icJob, SequenceFileOutputFormat.class); //LazyOutputFormat.setOutputFormatClass(icJob, TextOutputFormat.class); SequenceFileOutputFormat.setCompressOutput(icJob, true); SequenceFileOutputFormat.setOutputCompressionType(icJob, CompressionType.BLOCK); FileInputFormat.setInputDirRecursive(icJob, true); FileInputFormat.setInputPaths(icJob, aggregateDatasets.substring(0, aggregateDatasets.length() - 1)); FileOutputFormat.setOutputPath(icJob, new Path(indexOutputDir)); icJob.setJarByClass(IndexCreation.class); long start = System.currentTimeMillis(); icJob.submit(); icJob.waitForCompletion(true); System.out.println(jobName + "\t" + (System.currentTimeMillis() - start)); // moving files to right place for (String dataset : shortDatasetIndex) { String from = s3bucket + FrameworkUtils.indexDir + "/tmp/" + dataset + "/"; String to = s3bucket + FrameworkUtils.indexDir + "/" + dataset + "/"; FrameworkUtils.renameFile(from, to, s3conf, s3); } }
From source file:org.fcrepo.client.test.PerformanceTests.java
public static void main(String[] args) throws Exception { if (args.length < 8 || args.length > 9) { usage();//w w w .ja v a 2s . c o m } String host = args[0]; String port = args[1]; String username = args[2]; String password = args[3]; String itr = args[4]; String thrds = args[5]; String output = args[6]; String name = args[7]; String context = Constants.FEDORA_DEFAULT_APP_CONTEXT; if (args.length == 9 && !args[8].equals("")) { context = args[8]; } if (host == null || host.startsWith("$") || port == null || port.startsWith("$") || username == null || username.startsWith("$") || password == null || password.startsWith("$") || itr == null || itr.startsWith("$") || thrds == null || thrds.startsWith("$") || output == null || output.startsWith("$") || name == null || name.startsWith("$")) { usage(); } name = name.replaceAll(",", ";"); iterations = Integer.parseInt(itr); threads = Integer.parseInt(thrds); boolean newFile = true; File outputFile = new File(output); File tempFile = null; BufferedReader reader = null; String line = ""; if (outputFile.exists()) { newFile = false; // Create a copy of the file to read from tempFile = File.createTempFile("performance-test", "tmp"); BufferedReader input = new BufferedReader(new FileReader(outputFile)); PrintStream tempOut = new PrintStream(tempFile); while ((line = input.readLine()) != null) { tempOut.println(line); } input.close(); tempOut.close(); reader = new BufferedReader(new FileReader(tempFile)); } PrintStream out = new PrintStream(outputFile); if (newFile) { out.println( "--------------------------------------------------------------" + " Performance Test Results " + "--------------------------------------------------------------"); } PerformanceTests tests = new PerformanceTests(); tests.init(host, port, context, username, password); System.out.println("Running Ingest Round-Trip Test..."); long ingestResults = tests.runIngestTest(); System.out.println("Running AddDatastream Round-Trip Test..."); long addDsResults = tests.runAddDatastreamTest(); System.out.println("Running ModifyDatastreamByReference Round-Trip Test..."); long modifyRefResults = tests.runModifyDatastreamByRefTest(); System.out.println("Running ModifyDatastreamByValue Round-Trip Test..."); long modifyValResults = tests.runModifyDatastreamByValueTest(); System.out.println("Running PurgeDatastream Round-Trip Test..."); long purgeDsResults = tests.runPurgeDatastreamTest(); System.out.println("Running PurgeObject Round-Trip Test..."); long purgeObjectResults = tests.runPurgeObjectTest(); System.out.println("Running GetDatastream Round-Trip Test..."); long getDatastreamResults = tests.runGetDatastreamTest(); System.out.println("Running GetDatastreamREST Round-Trip Test..."); long getDatastreamRestResults = tests.runGetDatastreamRestTest(); System.out.println("Running Throughput Tests..."); long[] tpResults = tests.runThroughputTests(); System.out.println("Running Threaded Throughput Tests..."); long[] tptResults = tests.runThreadedThroughputTests(); if (newFile) { out.println( "1. Test performing each operation in isolation. Time (in ms) is the average required to perform each operation."); out.println( "test name, ingest, addDatastream, modifyDatastreamByReference, modifyDatastreamByValue, purgeDatastream, purgeObject, getDatastream, getDatastreamREST"); } else { line = reader.readLine(); while (line != null && line.length() > 2) { out.println(line); line = reader.readLine(); } } out.println(name + ", " + ingestResults + ", " + addDsResults + ", " + modifyRefResults + ", " + modifyValResults + ", " + purgeDsResults + ", " + purgeObjectResults + ", " + getDatastreamResults / iterations + ", " + getDatastreamRestResults / iterations); out.println(); if (newFile) { out.println("2. Operations-Per-Second based on results listed in item 1."); out.println( "test name, ingest, addDatastream, modifyDatastreamByReference, modifyDatastreamByValue, purgeDatastream, purgeObject, getDatastream, getDatastreamREST"); } else { line = reader.readLine(); while (line != null && line.length() > 2) { out.println(line); line = reader.readLine(); } } double ingestPerSecond = 1000 / (double) ingestResults; double addDsPerSecond = 1000 / (double) addDsResults; double modifyRefPerSecond = 1000 / (double) modifyRefResults; double modifyValPerSecond = 1000 / (double) modifyValResults; double purgeDsPerSecond = 1000 / (double) purgeDsResults; double purgeObjPerSecond = 1000 / (double) purgeObjectResults; double getDatastreamPerSecond = 1000 / ((double) getDatastreamResults / iterations); double getDatastreamRestPerSecond = 1000 / ((double) getDatastreamRestResults / iterations); out.println(name + ", " + round(ingestPerSecond) + ", " + round(addDsPerSecond) + ", " + round(modifyRefPerSecond) + ", " + round(modifyValPerSecond) + ", " + round(purgeDsPerSecond) + ", " + round(purgeObjPerSecond) + ", " + round(getDatastreamPerSecond) + ", " + round(getDatastreamRestPerSecond)); out.println(); if (newFile) { out.println( "3. Test performing operations back-to-back. Time (in ms) is that required to perform all iterations."); out.println( "test name, ingest, addDatastream, modifyDatastreamByReference, modifyDatastreamByValue, purgeDatastream, purgeObject, getDatastream, getDatastreamREST"); } else { line = reader.readLine(); while (line != null && line.length() > 2) { out.println(line); line = reader.readLine(); } } out.println(name + ", " + tpResults[0] + ", " + tpResults[1] + ", " + tpResults[2] + ", " + tpResults[3] + ", " + tpResults[4] + ", " + tpResults[5] + ", " + getDatastreamResults + ", " + getDatastreamRestResults); out.println(); if (newFile) { out.println("4. Operations-Per-Second based on results listed in item 3."); out.println( "test name, ingest, addDatastream, modifyDatastreamByReference, modifyDatastreamByValue, purgeDatastream, purgeObject, getDatastream, getDatastreamREST"); } else { line = reader.readLine(); while (line != null && line.length() > 2) { out.println(line); line = reader.readLine(); } } double ingestItPerSecond = (double) (iterations * 1000) / tpResults[0]; double addDsItPerSecond = (double) (iterations * 1000) / tpResults[1]; double modifyRefItPerSecond = (double) (iterations * 1000) / tpResults[2]; double modifyValItPerSecond = (double) (iterations * 1000) / tpResults[3]; double purgeDsItPerSecond = (double) (iterations * 1000) / tpResults[4]; double purgeObjItPerSecond = (double) (iterations * 1000) / tpResults[5]; double getDsItPerSecond = (double) (iterations * 1000) / getDatastreamResults; double getDsRestItPerSecond = (double) (iterations * 1000) / getDatastreamRestResults; out.println(name + ", " + round(ingestItPerSecond) + ", " + round(addDsItPerSecond) + ", " + round(modifyRefItPerSecond) + ", " + round(modifyValItPerSecond) + ", " + round(purgeDsItPerSecond) + ", " + round(purgeObjItPerSecond) + ", " + round(getDsItPerSecond) + ", " + round(getDsRestItPerSecond)); out.println(); if (newFile) { out.println( "5. Test performing operations using a thread pool. Time (in ms) is that required to perform all iterations."); out.println( "test name, ingest, addDatastream, modifyDatastreamByReference, modifyDatastreamByValue, purgeDatastream, purgeObject, getDatastream, getDatastreamREST"); } else { line = reader.readLine(); while (line != null && line.length() > 2) { out.println(line); line = reader.readLine(); } } out.println(name + ", " + tptResults[0] + ", " + tptResults[1] + ", " + tptResults[2] + ", " + tptResults[3] + ", " + tptResults[4] + ", " + tptResults[5] + ", " + tptResults[6] + ", " + tptResults[7]); out.println(); if (newFile) { out.println("6. Operations-Per-Second based on results listed in item 5."); out.println( "test name, ingest, addDatastream, modifyDatastreamByReference, modifyDatastreamByValue, purgeDatastream, purgeObject, getDatastream, getDatastreamREST"); } else { line = reader.readLine(); while (line != null && line.length() > 2) { out.println(line); line = reader.readLine(); } } double thrdIngestItPerSecond = (double) (iterations * 1000) / tptResults[0]; double thrdAddDsItPerSecond = (double) (iterations * 1000) / tptResults[1]; double thrdModifyRefItPerSecond = (double) (iterations * 1000) / tptResults[2]; double thrdModifyValItPerSecond = (double) (iterations * 1000) / tptResults[3]; double thrdPurgeDsItPerSecond = (double) (iterations * 1000) / tptResults[4]; double thrdPurgeObjItPerSecond = (double) (iterations * 1000) / tptResults[5]; double thrdGetDsItPerSecond = (double) (iterations * 1000) / tptResults[6]; double thrdGetDsRestItPerSecond = (double) (iterations * 1000) / tptResults[7]; out.println(name + ", " + round(thrdIngestItPerSecond) + ", " + round(thrdAddDsItPerSecond) + ", " + round(thrdModifyRefItPerSecond) + ", " + round(thrdModifyValItPerSecond) + ", " + round(thrdPurgeDsItPerSecond) + ", " + round(thrdPurgeObjItPerSecond) + ", " + round(thrdGetDsItPerSecond) + ", " + round(thrdGetDsRestItPerSecond)); if (!newFile) { reader.close(); tempFile.delete(); } out.close(); System.out.println("Performance Tests Complete."); }
From source file:com.zigabyte.stock.stratplot.StrategyPlotter.java
/** Starts a StrategyPlotter. * @param parameters/*from www . j a v a 2s .co m*/ * <pre> * Optional Parameters and default values: * -initialCash $10,000.00 * -perTradeFee $1.00 * -perShareTradeCommission $0.02 * -strategy com.zigabyte.stock.strategy.SundayPeaks(0.2,0.08) * -metastock (default path: current directory) * -serialized (default path: current directory) * -serializedgz (default path: current directory) * Values may need to be quoted '$1' or 'pkg.MyStrategy(0.1)'. * Use only one -metastock, -serialized, or -serializedgz to specify data. * </pre> **/ public static void main(String... parameters) { double initialCash = DEFAULT_INITIAL_CASH; double initialPerTradeFee = DEFAULT_PER_TRADE_FEE; double initialPerShareTradeCommission = DEFAULT_PER_SHARE_TRADE_COMMISSION; String initialStrategy = DEFAULT_STRATEGY; String initialDataFormat = DEFAULT_DATA_FORMAT; String initialDataPath = DEFAULT_DATA_PATH; // parse parameters int parameterIndex = 0; try { for (; parameterIndex < parameters.length; parameterIndex++) { String parameter = parameters[parameterIndex]; if ("-initialCash".equalsIgnoreCase(parameter) || "-perTradeFee".equalsIgnoreCase(parameter) || "-perShareTradeCommission".equalsIgnoreCase(parameter)) { double value = DOLLAR_FORMAT.parse(parameters[++parameterIndex]).doubleValue(); if ("-initialCash".equalsIgnoreCase(parameter)) { initialCash = value; } else if ("-perTradeFee".equalsIgnoreCase(parameter)) { initialPerTradeFee = value; } else if ("-perShareTradeCommission".equalsIgnoreCase(parameter)) { initialPerShareTradeCommission = value; } else assert false; } else if ("-strategy".equalsIgnoreCase(parameter) || "-metastock".equalsIgnoreCase(parameter) || "-serialized".equalsIgnoreCase(parameter) || "-serializedgz".equalsIgnoreCase(parameter)) { StringBuffer buf = new StringBuffer(); String part; while (++parameterIndex < parameters.length && !(part = parameters[parameterIndex]).startsWith("-")) { if (buf.length() > 0) buf.append(' '); buf.append(part); } --parameterIndex; String value = buf.toString(); if ("-strategy".equalsIgnoreCase(parameter)) { initialStrategy = value; } else if ("-metastock".equalsIgnoreCase(parameter)) { initialDataPath = value; initialDataFormat = "Metastock"; } else if ("-serialized".equalsIgnoreCase(parameter)) { initialDataPath = value; initialDataFormat = "Serialized"; } else if ("-serializedgz".equalsIgnoreCase(parameter)) { initialDataPath = value; initialDataFormat = "SerializedGZ"; } else assert false; } else if ("-help".equalsIgnoreCase(parameter)) { parameterExit(0); } else throw new IllegalArgumentException(parameter); } } catch (Exception e) { System.err.println(e); int indent = 0; for (int i = 0; i < parameters.length; i++) { String parameter = parameters[i]; if (i < parameterIndex) indent += parameter.length() + 1; System.err.print(parameter); System.err.print(' '); } System.err.println(); for (int i = 0; i < indent; i++) System.err.print('_'); System.err.println('^'); parameterExit(-1); } // set up plotter StrategyPlotter plotter = new StrategyPlotter(initialCash, initialPerTradeFee, initialPerShareTradeCommission, initialStrategy, initialDataFormat, initialDataPath); plotter.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); plotter.setSize(1024, 768); plotter.setLocationRelativeTo(null); // center on screen plotter.setVisible(true); }
From source file:com.moviejukebox.MovieJukebox.java
public static void main(String[] args) throws Throwable { JukeboxStatistics.setTimeStart(System.currentTimeMillis()); // Create the log file name here, so we can change it later (because it's locked System.setProperty("file.name", LOG_FILENAME); PropertyConfigurator.configure("properties/log4j.properties"); LOG.info("Yet Another Movie Jukebox {}", GitRepositoryState.getVersion()); LOG.info("~~~ ~~~~~~~ ~~~~~ ~~~~~~~ {}", StringUtils.repeat("~", GitRepositoryState.getVersion().length())); LOG.info("https://github.com/YAMJ/yamj-v2"); LOG.info("Copyright (c) 2004-2016 YAMJ Members"); LOG.info(""); LOG.info("This software is licensed under the GNU General Public License v3+"); LOG.info("See this page: https://github.com/YAMJ/yamj-v2/wiki/License"); LOG.info(""); LOG.info(" Revision SHA: {} {}", GIT.getCommitId(), GIT.getDirty() ? "(Custom Build)" : ""); LOG.info(" Commit Date: {}", GIT.getCommitTime()); LOG.info(" Build Date: {}", GIT.getBuildTime()); LOG.info(""); LOG.info(" Java Version: {}", GitRepositoryState.getJavaVersion()); LOG.info(""); if (!SystemTools.validateInstallation()) { LOG.info("ABORTING."); return;/*from w w w. j a va 2 s . co m*/ } String movieLibraryRoot = null; String jukeboxRoot = null; Map<String, String> cmdLineProps = new LinkedHashMap<>(); try { for (int i = 0; i < args.length; i++) { String arg = args[i]; if ("-v".equalsIgnoreCase(arg)) { // We've printed the version, so quit now return; } else if ("-t".equalsIgnoreCase(arg)) { String pin = args[++i]; // load the apikeys.properties file if (!setPropertiesStreamName("./properties/apikeys.properties", Boolean.TRUE)) { return; } // authorize to Trakt.TV TraktTV.getInstance().initialize().authorizeWithPin(pin); // We've authorized access to Trakt.TV, so quit now return; } else if ("-o".equalsIgnoreCase(arg)) { jukeboxRoot = args[++i]; PropertiesUtil.setProperty("mjb.jukeboxRoot", jukeboxRoot); } else if ("-c".equalsIgnoreCase(arg)) { jukeboxClean = Boolean.TRUE; PropertiesUtil.setProperty("mjb.jukeboxClean", TRUE); } else if ("-k".equalsIgnoreCase(arg)) { setJukeboxPreserve(Boolean.TRUE); } else if ("-p".equalsIgnoreCase(arg)) { userPropertiesName = args[++i]; } else if ("-i".equalsIgnoreCase(arg)) { skipIndexGeneration = Boolean.TRUE; PropertiesUtil.setProperty("mjb.skipIndexGeneration", TRUE); } else if ("-h".equalsIgnoreCase(arg)) { skipHtmlGeneration = Boolean.TRUE; PropertiesUtil.setProperty("mjb.skipHtmlGeneration", Boolean.TRUE); } else if ("-dump".equalsIgnoreCase(arg)) { dumpLibraryStructure = Boolean.TRUE; } else if ("-memory".equalsIgnoreCase(arg)) { showMemory = Boolean.TRUE; PropertiesUtil.setProperty("mjb.showMemory", Boolean.TRUE); } else if (arg.startsWith("-D")) { String propLine = arg.length() > 2 ? arg.substring(2) : args[++i]; int propDiv = propLine.indexOf('='); if (-1 != propDiv) { cmdLineProps.put(propLine.substring(0, propDiv), propLine.substring(propDiv + 1)); } } else if (arg.startsWith("-")) { help(); return; } else { movieLibraryRoot = args[i]; } } } catch (Exception error) { LOG.error("Wrong arguments specified"); help(); return; } // Save the name of the properties file for use later setProperty("userPropertiesName", userPropertiesName); LOG.info("Processing started at {}", new Date()); LOG.info(""); // Load the moviejukebox-default.properties file if (!setPropertiesStreamName("./properties/moviejukebox-default.properties", Boolean.TRUE)) { return; } // Load the user properties file "moviejukebox.properties" // No need to abort if we don't find this file // Must be read before the skin, because this may contain an override skin setPropertiesStreamName(userPropertiesName, Boolean.FALSE); // Grab the skin from the command-line properties if (cmdLineProps.containsKey(SKIN_DIR)) { setProperty(SKIN_DIR, cmdLineProps.get(SKIN_DIR)); } // Load the skin.properties file if (!setPropertiesStreamName(getProperty(SKIN_DIR, SKIN_DEFAULT) + "/skin.properties", Boolean.TRUE)) { return; } // Load the skin-user.properties file (ignore the error) setPropertiesStreamName(getProperty(SKIN_DIR, SKIN_DEFAULT) + "/skin-user.properties", Boolean.FALSE); // Load the overlay.properties file (ignore the error) String overlayRoot = getProperty("mjb.overlay.dir", Movie.UNKNOWN); overlayRoot = (PropertiesUtil.getBooleanProperty("mjb.overlay.skinroot", Boolean.TRUE) ? (getProperty(SKIN_DIR, SKIN_DEFAULT) + File.separator) : "") + (StringTools.isValidString(overlayRoot) ? (overlayRoot + File.separator) : ""); setPropertiesStreamName(overlayRoot + "overlay.properties", Boolean.FALSE); // Load the apikeys.properties file if (!setPropertiesStreamName("./properties/apikeys.properties", Boolean.TRUE)) { return; } // This is needed to update the static reference for the API Keys in the pattern formatter // because the formatter is initialised before the properties files are read FilteringLayout.addApiKeys(); // Load the rest of the command-line properties for (Map.Entry<String, String> propEntry : cmdLineProps.entrySet()) { setProperty(propEntry.getKey(), propEntry.getValue()); } // Read the information about the skin SkinProperties.readSkinVersion(); // Display the information about the skin SkinProperties.printSkinVersion(); StringBuilder properties = new StringBuilder("{"); for (Map.Entry<Object, Object> propEntry : PropertiesUtil.getEntrySet()) { properties.append(propEntry.getKey()); properties.append("="); properties.append(propEntry.getValue()); properties.append(","); } properties.replace(properties.length() - 1, properties.length(), "}"); // Print out the properties to the log file. LOG.debug("Properties: {}", properties.toString()); // Check for mjb.skipIndexGeneration and set as necessary // This duplicates the "-i" functionality, but allows you to have it in the property file skipIndexGeneration = PropertiesUtil.getBooleanProperty("mjb.skipIndexGeneration", Boolean.FALSE); if (PropertiesUtil.getBooleanProperty("mjb.people", Boolean.FALSE)) { peopleScan = Boolean.TRUE; peopleScrape = PropertiesUtil.getBooleanProperty("mjb.people.scrape", Boolean.TRUE); peopleMax = PropertiesUtil.getIntProperty("mjb.people.maxCount", 10); popularity = PropertiesUtil.getIntProperty("mjb.people.popularity", 5); // Issue 1947: Cast enhancement - option to save all related files to a specific folder peopleFolder = PropertiesUtil.getProperty("mjb.people.folder", ""); if (isNotValidString(peopleFolder)) { peopleFolder = ""; } else if (!peopleFolder.endsWith(File.separator)) { peopleFolder += File.separator; } StringTokenizer st = new StringTokenizer( PropertiesUtil.getProperty("photo.scanner.photoExtensions", "jpg,jpeg,gif,bmp,png"), ",;| "); while (st.hasMoreTokens()) { PHOTO_EXTENSIONS.add(st.nextToken()); } } // Check for mjb.skipHtmlGeneration and set as necessary // This duplicates the "-h" functionality, but allows you to have it in the property file skipHtmlGeneration = PropertiesUtil.getBooleanProperty("mjb.skipHtmlGeneration", Boolean.FALSE); // Look for the parameter in the properties file if it's not been set on the command line // This way we don't overwrite the setting if it's not found and defaults to FALSE showMemory = PropertiesUtil.getBooleanProperty("mjb.showMemory", Boolean.FALSE); // This duplicates the "-c" functionality, but allows you to have it in the property file jukeboxClean = PropertiesUtil.getBooleanProperty("mjb.jukeboxClean", Boolean.FALSE); MovieFilenameScanner.setSkipKeywords( tokenizeToArray(getProperty("filename.scanner.skip.keywords", ""), ",;| "), PropertiesUtil.getBooleanProperty("filename.scanner.skip.caseSensitive", Boolean.TRUE)); MovieFilenameScanner.setSkipRegexKeywords( tokenizeToArray(getProperty("filename.scanner.skip.keywords.regex", ""), ","), PropertiesUtil.getBooleanProperty("filename.scanner.skip.caseSensitive.regex", Boolean.TRUE)); MovieFilenameScanner.setExtrasKeywords( tokenizeToArray(getProperty("filename.extras.keywords", "trailer,extra,bonus"), ",;| ")); MovieFilenameScanner.setMovieVersionKeywords(tokenizeToArray( getProperty("filename.movie.versions.keywords", "remastered,directors cut,extended cut,final cut"), ",;|")); MovieFilenameScanner.setLanguageDetection( PropertiesUtil.getBooleanProperty("filename.scanner.language.detection", Boolean.TRUE)); final KeywordMap languages = PropertiesUtil.getKeywordMap("filename.scanner.language.keywords", null); if (!languages.isEmpty()) { MovieFilenameScanner.clearLanguages(); for (String lang : languages.getKeywords()) { String values = languages.get(lang); if (values != null) { MovieFilenameScanner.addLanguage(lang, values, values); } else { LOG.info("No values found for language code '{}'", lang); } } } final KeywordMap sourceKeywords = PropertiesUtil.getKeywordMap("filename.scanner.source.keywords", "HDTV,PDTV,DVDRip,DVDSCR,DSRip,CAM,R5,LINE,HD2DVD,DVD,DVD5,DVD9,HRHDTV,MVCD,VCD,TS,VHSRip,BluRay,HDDVD,D-THEATER,SDTV"); MovieFilenameScanner.setSourceKeywords(sourceKeywords.getKeywords(), sourceKeywords); String temp = getProperty("sorting.strip.prefixes"); if (temp != null) { StringTokenizer st = new StringTokenizer(temp, ","); while (st.hasMoreTokens()) { String token = st.nextToken().trim(); if (token.startsWith("\"") && token.endsWith("\"")) { token = token.substring(1, token.length() - 1); } Movie.addSortIgnorePrefixes(token.toLowerCase()); } } enableWatchScanner = PropertiesUtil.getBooleanProperty("watched.scanner.enable", Boolean.TRUE); enableWatchTraktTv = PropertiesUtil.getBooleanProperty("watched.trakttv.enable", Boolean.FALSE); enableCompleteMovies = PropertiesUtil.getBooleanProperty("complete.movies.enable", Boolean.TRUE); // Check to see if don't have a root, check the property file if (StringTools.isNotValidString(movieLibraryRoot)) { movieLibraryRoot = getProperty("mjb.libraryRoot"); if (StringTools.isValidString(movieLibraryRoot)) { LOG.info("Got libraryRoot from properties file: {}", movieLibraryRoot); } else { LOG.error("No library root found!"); help(); return; } } if (jukeboxRoot == null) { jukeboxRoot = getProperty("mjb.jukeboxRoot"); if (jukeboxRoot == null) { LOG.info("jukeboxRoot is null in properties file. Please fix this as it may cause errors."); } else { LOG.info("Got jukeboxRoot from properties file: {}", jukeboxRoot); } } File f = new File(movieLibraryRoot); if (f.exists() && f.isDirectory() && jukeboxRoot == null) { jukeboxRoot = movieLibraryRoot; } if (movieLibraryRoot == null) { help(); return; } if (jukeboxRoot == null) { LOG.info("Wrong arguments specified: you must define the jukeboxRoot property (-o) !"); help(); return; } if (!f.exists()) { LOG.error("Directory or library configuration file '{}', not found.", movieLibraryRoot); return; } FileTools.initUnsafeChars(); FileTools.initSubtitleExtensions(); // make canonical names jukeboxRoot = FileTools.getCanonicalPath(jukeboxRoot); movieLibraryRoot = FileTools.getCanonicalPath(movieLibraryRoot); MovieJukebox ml = new MovieJukebox(movieLibraryRoot, jukeboxRoot); if (dumpLibraryStructure) { LOG.warn( "WARNING !!! A dump of your library directory structure will be generated for debug purpose. !!! Library won't be built or updated"); ml.makeDumpStructure(); } else { ml.generateLibrary(); } // Now rename the log files renameLogFile(); if (ScanningLimit.isLimitReached()) { LOG.warn("Scanning limit of {} was reached, please re-run to complete processing.", ScanningLimit.getLimit()); System.exit(EXIT_SCAN_LIMIT); } else { System.exit(EXIT_NORMAL); } }