List of usage examples for java.util ArrayList size
int size
To view the source code for java.util ArrayList size.
Click Source Link
From source file:edu.oregonstate.eecs.mcplan.abstraction.EvaluateSimilarityFunction.java
/** * @param args/* w w w . j av a 2s . c om*/ * @throws IOException * @throws FileNotFoundException */ public static void main(final String[] args) throws FileNotFoundException, IOException { final String experiment_file = args[0]; final File root_directory; if (args.length > 1) { root_directory = new File(args[1]); } else { root_directory = new File("."); } final CsvConfigurationParser csv_config = new CsvConfigurationParser(new FileReader(experiment_file)); final String experiment_name = FilenameUtils.getBaseName(experiment_file); final File expr_directory = new File(root_directory, experiment_name); expr_directory.mkdirs(); final Csv.Writer csv = new Csv.Writer( new PrintStream(new FileOutputStream(new File(expr_directory, "results.csv")))); final String[] parameter_headers = new String[] { "kpca.kernel", "kpca.rbf.sigma", "kpca.random_forest.Ntrees", "kpca.random_forest.max_depth", "kpca.Nbases", "multiclass.classifier", "multiclass.random_forest.Ntrees", "multiclass.random_forest.max_depth", "pairwise_classifier.max_branching", "training.label_noise" }; csv.cell("domain").cell("abstraction"); for (final String p : parameter_headers) { csv.cell(p); } csv.cell("Ntrain").cell("Ntest").cell("ami.mean").cell("ami.variance").cell("ami.confidence").newline(); for (int expr = 0; expr < csv_config.size(); ++expr) { try { final KeyValueStore expr_config = csv_config.get(expr); final Configuration config = new Configuration(root_directory.getPath(), expr_directory.getName(), expr_config); System.out.println("[Loading '" + config.training_data_single + "']"); final Instances single = WekaUtil .readLabeledDataset(new File(root_directory, config.training_data_single + ".arff")); final Instances train = new Instances(single, 0); final int[] idx = Fn.range(0, single.size()); int instance_counter = 0; Fn.shuffle(config.rng, idx); final int Ntrain = config.getInt("Ntrain_games"); // TODO: Rename? final double label_noise = config.getDouble("training.label_noise"); final int Nlabels = train.classAttribute().numValues(); assert (Nlabels > 0); for (int i = 0; i < Ntrain; ++i) { final Instance inst = single.get(idx[instance_counter++]); if (label_noise > 0 && config.rng.nextDouble() < label_noise) { int noisy_label = 0; do { noisy_label = config.rng.nextInt(Nlabels); } while (noisy_label == (int) inst.classValue()); System.out.println("Noisy label (" + inst.classValue() + " -> " + noisy_label + ")"); inst.setClassValue(noisy_label); } train.add(inst); inst.setDataset(train); } final Fn.Function2<Boolean, Instance, Instance> plausible_p = createPlausiblePredicate(config); final int Ntest = config.Ntest_games; int Ntest_added = 0; final ArrayList<Instances> tests = new ArrayList<Instances>(); while (instance_counter < single.size() && Ntest_added < Ntest) { final Instance inst = single.get(idx[instance_counter++]); boolean found = false; for (final Instances test : tests) { // Note that 'plausible_p' should be transitive if (plausible_p.apply(inst, test.get(0))) { WekaUtil.addInstance(test, inst); if (test.size() == 30) { Ntest_added += test.size(); } else if (test.size() > 30) { Ntest_added += 1; } found = true; break; } } if (!found) { final Instances test = new Instances(single, 0); WekaUtil.addInstance(test, inst); tests.add(test); } } final Iterator<Instances> test_itr = tests.iterator(); while (test_itr.hasNext()) { if (test_itr.next().size() < 30) { test_itr.remove(); } } System.out.println("=== tests.size() = " + tests.size()); System.out.println("=== Ntest_added = " + Ntest_added); System.out.println("[Training]"); final Evaluator evaluator = createEvaluator(config, train); // final Instances transformed_test = evaluator.prepareInstances( test ); System.out.println("[Evaluating]"); final int Nxval = evaluator.isSensitiveToOrdering() ? 10 : 1; final MeanVarianceAccumulator ami = new MeanVarianceAccumulator(); final MeanVarianceAccumulator errors = new MeanVarianceAccumulator(); final MeanVarianceAccumulator relative_error = new MeanVarianceAccumulator(); int c = 0; for (int xval = 0; xval < Nxval; ++xval) { for (final Instances test : tests) { // TODO: Debugging WekaUtil.writeDataset(new File(config.root_directory), "test_" + (c++), test); // transformed_test.randomize( new RandomAdaptor( config.rng ) ); // final ClusterContingencyTable ct = evaluator.evaluate( transformed_test ); test.randomize(new RandomAdaptor(config.rng)); final ClusterContingencyTable ct = evaluator.evaluate(test); System.out.println(ct); int Nerrors = 0; final MeanVarianceAccumulator mv = new MeanVarianceAccumulator(); for (int i = 0; i < ct.R; ++i) { final int max = Fn.max(ct.n[i]); Nerrors += (ct.a[i] - max); mv.add(((double) ct.a[i]) / ct.N * Nerrors / ct.a[i]); } errors.add(Nerrors); relative_error.add(mv.mean()); System.out.println("exemplar: " + test.get(0)); System.out.println("Nerrors = " + Nerrors); final PrintStream ct_out = new PrintStream( new FileOutputStream(new File(expr_directory, "ct_" + expr + "_" + xval + ".csv"))); ct.writeCsv(ct_out); ct_out.close(); final double ct_ami = ct.adjustedMutualInformation_max(); if (Double.isNaN(ct_ami)) { System.out.println("! ct_ami = NaN"); } else { ami.add(ct_ami); } System.out.println(); } } System.out.println("errors = " + errors.mean() + " (" + errors.confidence() + ")"); System.out.println( "relative_error = " + relative_error.mean() + " (" + relative_error.confidence() + ")"); System.out.println("AMI_max = " + ami.mean() + " (" + ami.confidence() + ")"); csv.cell(config.domain).cell(config.get("abstraction.discovery")); for (final String p : parameter_headers) { csv.cell(config.get(p)); } csv.cell(Ntrain).cell(Ntest).cell(ami.mean()).cell(ami.variance()).cell(ami.confidence()).newline(); } catch (final Exception ex) { ex.printStackTrace(); } } }
From source file:TestBufferStreamGenomicsDBImporter.java
/** * Sample driver code for testing Java VariantContext write API for GenomicsDB * The code shows two ways of using the API * (a) Iterator<VariantContext>//w ww . j ava 2 s. co m * (b) Directly adding VariantContext objects * If "-iterators" is passed as the second argument, method (a) is used. */ public static void main(final String[] args) throws IOException, GenomicsDBException, ParseException { if (args.length < 2) { System.err.println("For loading: [-iterators] <loader.json> " + "<stream_name_to_file.json> [bufferCapacity rank lbRowIdx ubRowIdx useMultiChromosomeIterator]"); System.exit(-1); } int argsLoaderFileIdx = 0; if (args[0].equals("-iterators")) argsLoaderFileIdx = 1; //Buffer capacity long bufferCapacity = (args.length >= argsLoaderFileIdx + 3) ? Integer.parseInt(args[argsLoaderFileIdx + 2]) : 1024; //Specify rank (or partition idx) of this process int rank = (args.length >= argsLoaderFileIdx + 4) ? Integer.parseInt(args[argsLoaderFileIdx + 3]) : 0; //Specify smallest row idx from which to start loading. // This is useful for incremental loading into existing array long lbRowIdx = (args.length >= argsLoaderFileIdx + 5) ? Long.parseLong(args[argsLoaderFileIdx + 4]) : 0; //Specify largest row idx up to which loading should be performed - for completeness long ubRowIdx = (args.length >= argsLoaderFileIdx + 6) ? Long.parseLong(args[argsLoaderFileIdx + 5]) : Long.MAX_VALUE - 1; //Boolean to use MultipleChromosomeIterator boolean useMultiChromosomeIterator = (args.length >= argsLoaderFileIdx + 7) ? Boolean.parseBoolean(args[argsLoaderFileIdx + 6]) : false; //<loader.json> first arg String loaderJSONFile = args[argsLoaderFileIdx]; GenomicsDBImporter loader = new GenomicsDBImporter(loaderJSONFile, rank, lbRowIdx, ubRowIdx); //<stream_name_to_file.json> - useful for the driver only //JSON file that contains "stream_name": "vcf_file_path" entries FileReader mappingReader = new FileReader(args[argsLoaderFileIdx + 1]); JSONParser parser = new JSONParser(); LinkedHashMap streamNameToFileName = (LinkedHashMap) parser.parse(mappingReader, new LinkedHashFactory()); ArrayList<VCFFileStreamInfo> streamInfoVec = new ArrayList<VCFFileStreamInfo>(); long rowIdx = 0; for (Object currObj : streamNameToFileName.entrySet()) { Map.Entry<String, String> entry = (Map.Entry<String, String>) currObj; VCFFileStreamInfo currInfo = new VCFFileStreamInfo(entry.getValue(), loaderJSONFile, rank, useMultiChromosomeIterator); /** The following 2 lines are not mandatory - use initializeSampleInfoMapFromHeader() * iff you know for sure that sample names in the VCF header are globally unique * across all streams/files. If not, you have 2 options: * (a) specify your own mapping from sample index in the header to SampleInfo object * (unique_name, rowIdx) OR * (b) specify the mapping in the callset_mapping_file (JSON) and pass null to * addSortedVariantContextIterator() */ LinkedHashMap<Integer, GenomicsDBImporter.SampleInfo> sampleIndexToInfo = new LinkedHashMap<Integer, GenomicsDBImporter.SampleInfo>(); rowIdx = GenomicsDBImporter.initializeSampleInfoMapFromHeader(sampleIndexToInfo, currInfo.mVCFHeader, rowIdx); int streamIdx = -1; if (args[0].equals("-iterators")) streamIdx = loader.addSortedVariantContextIterator(entry.getKey(), currInfo.mVCFHeader, currInfo.mIterator, bufferCapacity, VariantContextWriterBuilder.OutputType.BCF_STREAM, sampleIndexToInfo); //pass sorted VC iterators else //use buffers - VCs will be provided by caller streamIdx = loader.addBufferStream(entry.getKey(), currInfo.mVCFHeader, bufferCapacity, VariantContextWriterBuilder.OutputType.BCF_STREAM, sampleIndexToInfo); currInfo.mStreamIdx = streamIdx; streamInfoVec.add(currInfo); } if (args[0].equals("-iterators")) { //Much simpler interface if using Iterator<VariantContext> loader.importBatch(); assert loader.isDone(); } else { //Must be called after all iterators/streams added - no more iterators/streams // can be added once this function is called loader.setupGenomicsDBImporter(); //Counts and tracks buffer streams for which new data must be supplied //Initialized to all the buffer streams int numExhaustedBufferStreams = streamInfoVec.size(); int[] exhaustedBufferStreamIdxs = new int[numExhaustedBufferStreams]; for (int i = 0; i < numExhaustedBufferStreams; ++i) exhaustedBufferStreamIdxs[i] = i; while (!loader.isDone()) { //Add data for streams that were exhausted in the previous round for (int i = 0; i < numExhaustedBufferStreams; ++i) { VCFFileStreamInfo currInfo = streamInfoVec.get(exhaustedBufferStreamIdxs[i]); boolean added = true; while (added && (currInfo.mIterator.hasNext() || currInfo.mNextVC != null)) { if (currInfo.mNextVC != null) added = loader.add(currInfo.mNextVC, currInfo.mStreamIdx); if (added) if (currInfo.mIterator.hasNext()) currInfo.mNextVC = currInfo.mIterator.next(); else currInfo.mNextVC = null; } } loader.importBatch(); numExhaustedBufferStreams = (int) loader.getNumExhaustedBufferStreams(); for (int i = 0; i < numExhaustedBufferStreams; ++i) exhaustedBufferStreamIdxs[i] = loader.getExhaustedBufferStreamIndex(i); } } }
From source file:edu.nyu.vida.data_polygamy.feature_identification.IndexCreation.java
/** * @param args// w ww . j ava 2s.co m */ @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:com.adobe.aem.demo.communities.Loader.java
public static void main(String[] args) { String hostname = null;/*w w w. j a va 2 s. co m*/ String port = null; String altport = null; String csvfile = null; String location = null; String language = "en"; String analytics = null; String adminPassword = "admin"; String[] url = new String[10]; // Handling 10 levels maximum for nested comments boolean reset = false; boolean configure = false; int urlLevel = 0; int row = 0; HashMap<String, ArrayList<String>> learningpaths = new HashMap<String, ArrayList<String>>(); // Command line options for this tool Options options = new Options(); options.addOption("h", true, "Hostname"); options.addOption("p", true, "Port"); options.addOption("a", true, "Alternate Port"); options.addOption("f", true, "CSV file"); options.addOption("r", false, "Reset"); options.addOption("u", true, "Admin Password"); options.addOption("c", false, "Configure"); options.addOption("s", true, "Analytics Endpoint"); options.addOption("t", false, "Analytics Tracking"); CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { hostname = cmd.getOptionValue("h"); } if (cmd.hasOption("p")) { port = cmd.getOptionValue("p"); } if (cmd.hasOption("a")) { altport = cmd.getOptionValue("a"); } if (cmd.hasOption("f")) { csvfile = cmd.getOptionValue("f"); } if (cmd.hasOption("u")) { adminPassword = cmd.getOptionValue("u"); } if (cmd.hasOption("t")) { if (cmd.hasOption("s")) { analytics = cmd.getOptionValue("s"); } } if (cmd.hasOption("r")) { reset = true; } if (cmd.hasOption("c")) { configure = true; } if (csvfile == null || port == null || hostname == null) { System.out.println( "Request parameters: -h hostname -p port -a alternateport -u adminPassword -f path_to_CSV_file -r (true|false, delete content before import) -c (true|false, post additional properties)"); System.exit(-1); } } catch (ParseException ex) { logger.error(ex.getMessage()); } String componentType = null; try { logger.debug("AEM Demo Loader: Processing file " + csvfile); // Reading the CSV file, line by line Reader in = new FileReader(csvfile); Iterable<CSVRecord> records = CSVFormat.EXCEL.parse(in); for (CSVRecord record : records) { row = row + 1; logger.info("Row: " + row + ", new record: " + record.get(0)); // Let's see if we deal with a comment if (record.get(0).startsWith("#")) { // We can ignore the comment line and move on continue; } // Let's see if we need to terminate this process if (record.get(0).equals(KILL)) { System.exit(1); } // Let's see if we need to create a new Community site if (record.get(0).equals(SITE)) { // Building the form entity to be posted MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setCharset(MIME.UTF8_CHARSET); builder.addTextBody(":operation", "social:createSite", ContentType.create("text/plain", MIME.UTF8_CHARSET)); builder.addTextBody("_charset_", "UTF-8", ContentType.create("text/plain", MIME.UTF8_CHARSET)); String urlName = null; for (int i = 2; i < record.size() - 1; i = i + 2) { if (record.get(i) != null && record.get(i + 1) != null && record.get(i).length() > 0) { String name = record.get(i).trim(); String value = record.get(i + 1).trim(); if (value.equals("TRUE")) { value = "true"; } if (value.equals("FALSE")) { value = "false"; } if (name.equals("urlName")) { urlName = value; } if (name.equals(LANGUAGE)) { language = value; } if (name.equals(BANNER)) { File attachment = new File( csvfile.substring(0, csvfile.indexOf(".csv")) + File.separator + value); builder.addBinaryBody(BANNER, attachment, ContentType.MULTIPART_FORM_DATA, attachment.getName()); } else if (name.equals(THUMBNAIL)) { File attachment = new File( csvfile.substring(0, csvfile.indexOf(".csv")) + File.separator + value); builder.addBinaryBody(THUMBNAIL, attachment, ContentType.MULTIPART_FORM_DATA, attachment.getName()); } else { builder.addTextBody(name, value, ContentType.create("text/plain", MIME.UTF8_CHARSET)); } } } // Site creation String siteId = doPost(hostname, port, "/content.social.json", "admin", adminPassword, builder.build(), "response/siteId"); // Site publishing, if there's a publish instance to publish to if (!port.equals(altport)) { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("id", "nobot")); nameValuePairs.add(new BasicNameValuePair(":operation", "social:publishSite")); nameValuePairs .add(new BasicNameValuePair("path", "/content/sites/" + urlName + "/" + language)); doPost(hostname, port, "/communities/sites.html", "admin", adminPassword, new UrlEncodedFormEntity(nameValuePairs), null); // Wait for site to be available on Publish doWait(hostname, altport, "admin", adminPassword, (siteId != null ? siteId : urlName) + "-groupadministrators"); } continue; } // Let's see if we need to create a new Tag if (record.get(0).equals(TAG)) { // Building the form entity to be posted MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setCharset(MIME.UTF8_CHARSET); builder.addTextBody("_charset_", "UTF-8", ContentType.create("text/plain", MIME.UTF8_CHARSET)); for (int i = 1; i < record.size() - 1; i = i + 2) { if (record.get(i) != null && record.get(i + 1) != null && record.get(i).length() > 0 && record.get(i + 1).length() > 0) { String name = record.get(i).trim(); String value = record.get(i + 1).trim(); builder.addTextBody(name, value, ContentType.create("text/plain", MIME.UTF8_CHARSET)); } } // Tag creation doPost(hostname, port, "/bin/tagcommand", "admin", adminPassword, builder.build(), null); continue; } // Let's see if we need to create a new Community site template, and if we can do it (script run against author instance) if (record.get(0).equals(SITETEMPLATE)) { // Building the form entity to be posted MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setCharset(MIME.UTF8_CHARSET); builder.addTextBody(":operation", "social:createSiteTemplate", ContentType.create("text/plain", MIME.UTF8_CHARSET)); builder.addTextBody("_charset_", "UTF-8", ContentType.create("text/plain", MIME.UTF8_CHARSET)); for (int i = 2; i < record.size() - 1; i = i + 2) { if (record.get(i) != null && record.get(i + 1) != null && record.get(i).length() > 0) { String name = record.get(i).trim(); String value = record.get(i + 1).trim(); builder.addTextBody(name, value, ContentType.create("text/plain", MIME.UTF8_CHARSET)); } } // Site template creation doPost(hostname, port, "/content.social.json", "admin", adminPassword, builder.build(), null); continue; } // Let's see if we need to create a new Community group if (record.get(0).equals(GROUP)) { // Building the form entity to be posted MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setCharset(MIME.UTF8_CHARSET); builder.addTextBody(":operation", "social:createCommunityGroup", ContentType.create("text/plain", MIME.UTF8_CHARSET)); builder.addTextBody("_charset_", "UTF-8", ContentType.create("text/plain", MIME.UTF8_CHARSET)); for (int i = 3; i < record.size() - 1; i = i + 2) { if (record.get(i) != null && record.get(i + 1) != null && record.get(i).length() > 0) { String name = record.get(i).trim(); String value = record.get(i + 1).trim(); if (value.equals("TRUE")) { value = "true"; } if (value.equals("FALSE")) { value = "false"; } if (name.equals(IMAGE)) { File attachment = new File( csvfile.substring(0, csvfile.indexOf(".csv")) + File.separator + value); builder.addBinaryBody(IMAGE, attachment, ContentType.MULTIPART_FORM_DATA, attachment.getName()); } else { builder.addTextBody(name, value, ContentType.create("text/plain", MIME.UTF8_CHARSET)); } } } // Group creation String memberGroupId = doPost(hostname, port, record.get(1), getUserName(record.get(2)), getPassword(record.get(2), adminPassword), builder.build(), "response/memberGroupId"); // Wait for group to be available on Publish, if available logger.debug("Waiting for completion of Community Group creation"); doWait(hostname, port, "admin", adminPassword, memberGroupId); continue; } // Let's see if it's simple Sling Delete request if (record.get(0).equals(SLINGDELETE)) { doDelete(hostname, port, record.get(1), "admin", adminPassword); continue; } // Let's see if we need to add users to an AEM Group if ((record.get(0).equals(GROUPMEMBERS) || record.get(0).equals(SITEMEMBERS)) && record.get(GROUP_INDEX_NAME) != null) { // Checking if we have a member group for this site String groupName = record.get(GROUP_INDEX_NAME); if (record.get(0).equals(SITEMEMBERS)) { // Let's fetch the siteId for this Community Site Url String siteConfig = doGet(hostname, port, groupName, "admin", adminPassword, null); try { String siteId = new JSONObject(siteConfig).getString("siteId"); if (siteId != null) groupName = "community-" + siteId + "-members"; logger.debug("Member group name is " + groupName); } catch (Exception e) { logger.error(e.getMessage()); } } // Pause until the group can found doWait(hostname, port, "admin", adminPassword, groupName); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("filter", "[{\"operation\":\"like\",\"rep:principalName\":\"" + groupName + "\"}]")); nameValuePairs.add(new BasicNameValuePair("type", "groups")); String groupList = doGet(hostname, port, "/libs/social/console/content/content/userlist.social.0.10.json", "admin", adminPassword, nameValuePairs); logger.debug("List of groups" + groupList); if (groupList.indexOf(groupName) > 0) { logger.debug("Group was found on " + port); try { JSONArray jsonArray = new JSONObject(groupList).getJSONArray("items"); if (jsonArray.length() == 1) { JSONObject jsonObject = jsonArray.getJSONObject(0); String groupPath = jsonObject.getString("path"); logger.debug("Group path is " + groupPath); // Constructing a multi-part POST for group membership MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setCharset(MIME.UTF8_CHARSET); builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); List<NameValuePair> groupNameValuePairs = buildNVP(record, 2); for (NameValuePair nameValuePair : groupNameValuePairs) { builder.addTextBody(nameValuePair.getName(), nameValuePair.getValue(), ContentType.create("text/plain", MIME.UTF8_CHARSET)); } // Adding the list of group members doPost(hostname, port, groupPath + ".rw.userprops.html", "admin", adminPassword, builder.build(), null); } else { logger.info("We have more than one match for a group with this name!"); } } catch (Exception e) { logger.error(e.getMessage()); } } continue; } // Let's see if it's user related if (record.get(0).equals(USERS)) { //First we need to get the path to the user node String json = doGet(hostname, port, "/libs/granite/security/currentuser.json", getUserName(record.get(1)), getPassword(record.get(1), adminPassword), null); if (json != null) { try { // Fetching the home property String home = new JSONObject(json).getString("home"); if (record.get(2).equals(PREFERENCES)) { home = home + "/preferences"; } else { home = home + "/profile"; } logger.debug(home); // Now we can post all the preferences or the profile List<NameValuePair> nameValuePairs = buildNVP(record, 3); doPost(hostname, port, home, "admin", adminPassword, new UrlEncodedFormEntity(nameValuePairs), null); } catch (Exception e) { logger.error(e.getMessage()); } } continue; } // Let's see if we deal with a new block of content or just a new entry if (record.get(0).equals(CALENDAR) || record.get(0).equals(SLINGPOST) || record.get(0).equals(RATINGS) || record.get(0).equals(BLOG) || record.get(0).equals(JOURNAL) || record.get(0).equals(COMMENTS) || record.get(0).equals(REVIEWS) || record.get(0).equals(FILES) || record.get(0).equals(SUMMARY) || record.get(0).equals(ACTIVITIES) || record.get(0).equals(JOIN) || record.get(0).equals(FOLLOW) || record.get(0).equals(MESSAGE) || record.get(0).equals(ASSET) || record.get(0).equals(AVATAR) || record.get(0).equals(RESOURCE) || record.get(0).equals(LEARNING) || record.get(0).equals(QNA) || record.get(0).equals(FORUM)) { // New block of content, we need to reset the processing to first Level componentType = record.get(0); url[0] = record.get(1); urlLevel = 0; if (!componentType.equals(SLINGPOST) && reset) { int pos = record.get(1).indexOf("/jcr:content"); if (pos > 0) doDelete(hostname, port, "/content/usergenerated" + record.get(1).substring(0, pos), "admin", adminPassword); } // If the Configure command line flag is set, we try to configure the component with all options enabled if (componentType.equals(SLINGPOST) || configure) { String configurePath = getConfigurePath(record.get(1)); List<NameValuePair> nameValuePairs = buildNVP(record, 2); if (nameValuePairs.size() > 2) // Only do this when really have configuration settings doPost(hostname, port, configurePath, "admin", adminPassword, new UrlEncodedFormEntity(nameValuePairs), null); } // We're done with this line, moving on to the next line in the CSV file continue; } // Let's see if we need to indent the list, if it's a reply or a reply to a reply if (record.get(1).length() != 1) continue; // We need a valid level indicator if (Integer.parseInt(record.get(1)) > urlLevel) { url[++urlLevel] = location; logger.debug("Incremented urlLevel to: " + urlLevel + ", with a new location:" + location); } else if (Integer.parseInt(record.get(1)) < urlLevel) { urlLevel = Integer.parseInt(record.get(1)); logger.debug("Decremented urlLevel to: " + urlLevel); } // Get the credentials or fall back to password String password = getPassword(record.get(0), adminPassword); String userName = getUserName(record.get(0)); // Adding the generic properties for all POST requests List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); if (!componentType.equals(RESOURCE)) nameValuePairs.add(new BasicNameValuePair("id", "nobot")); nameValuePairs.add(new BasicNameValuePair("_charset_", "UTF-8")); // Setting some specific fields depending on the content type if (componentType.equals(COMMENTS)) { nameValuePairs.add(new BasicNameValuePair(":operation", "social:createComment")); nameValuePairs.add(new BasicNameValuePair("message", record.get(2))); } // Creates a forum post (or reply) if (componentType.equals(FORUM)) { nameValuePairs.add(new BasicNameValuePair(":operation", "social:createForumPost")); nameValuePairs.add(new BasicNameValuePair("subject", record.get(2))); nameValuePairs.add(new BasicNameValuePair("message", record.get(3))); } // Follows a user (followedId) for the user posting the request if (componentType.equals(FOLLOW)) { nameValuePairs.add(new BasicNameValuePair(":operation", "social:follow")); nameValuePairs.add(new BasicNameValuePair("userId", "/social/authors/" + userName)); nameValuePairs.add(new BasicNameValuePair("followedId", "/social/authors/" + record.get(2))); } // Uploading Avatar picture if (componentType.equals(AVATAR)) { nameValuePairs.add(new BasicNameValuePair(":operation", "social:changeAvatar")); } // Joins a user (posting the request) to a Community Group (path) if (componentType.equals(JOIN)) { nameValuePairs.add(new BasicNameValuePair(":operation", "social:joinCommunityGroup")); int pos = url[0].indexOf("/configuration.social.json"); if (pos > 0) nameValuePairs.add(new BasicNameValuePair("path", url[0].substring(0, pos) + ".html")); else continue; // Invalid record } // Creates a new private message if (componentType.equals(MESSAGE)) { nameValuePairs.add(new BasicNameValuePair(":operation", "social:createMessage")); nameValuePairs.add(new BasicNameValuePair("sendMail", "Sending...")); nameValuePairs.add(new BasicNameValuePair("content", record.get(4))); nameValuePairs.add(new BasicNameValuePair("subject", record.get(3))); nameValuePairs.add(new BasicNameValuePair("serviceSelector", "/bin/community")); nameValuePairs.add(new BasicNameValuePair("to", "/social/authors/" + record.get(2))); nameValuePairs.add(new BasicNameValuePair("userId", "/social/authors/" + record.get(2))); nameValuePairs.add(new BasicNameValuePair(":redirect", "//messaging.html")); nameValuePairs.add(new BasicNameValuePair(":formid", "generic_form")); nameValuePairs.add(new BasicNameValuePair(":formstart", "/content/sites/communities/messaging/compose/jcr:content/content/primary/start")); } // Creates a file or a folder if (componentType.equals(FILES)) { // Top level is always assumed to be a folder, second level files, and third and subsequent levels comments on files if (urlLevel == 0) { nameValuePairs.add(new BasicNameValuePair(":operation", "social:createFileLibraryFolder")); nameValuePairs.add(new BasicNameValuePair("name", record.get(2))); nameValuePairs.add(new BasicNameValuePair("message", record.get(3))); } else if (urlLevel == 1) { nameValuePairs.add(new BasicNameValuePair(":operation", "social:createComment")); } } // Creates a question, a reply or mark a reply as the best answer if (componentType.equals(QNA)) { if (urlLevel == 0) { nameValuePairs.add(new BasicNameValuePair(":operation", "social:createQnaPost")); nameValuePairs.add(new BasicNameValuePair("subject", record.get(2))); nameValuePairs.add(new BasicNameValuePair("message", record.get(3))); } else if (urlLevel == 1) { nameValuePairs.add(new BasicNameValuePair(":operation", "social:createQnaPost")); nameValuePairs.add(new BasicNameValuePair("message", record.get(3))); } else if (urlLevel == 2) { nameValuePairs.add(new BasicNameValuePair(":operation", "social:selectAnswer")); } } // Creates an article or a comment if (componentType.equals(JOURNAL) || componentType.equals(BLOG)) { nameValuePairs.add(new BasicNameValuePair(":operation", "social:createJournalComment")); nameValuePairs.add(new BasicNameValuePair("subject", record.get(2))); StringBuffer message = new StringBuffer("<p>" + record.get(3) + "</p>"); //We might have more paragraphs to add to the blog or journal article for (int i = 6; i < record.size(); i++) { if (record.get(i).length() > 0) { message.append("<p>" + record.get(i) + "</p>"); } } //We might have some tags to add to the blog or journal article if (record.get(5).length() > 0) { nameValuePairs.add(new BasicNameValuePair("tags", record.get(5))); } nameValuePairs.add(new BasicNameValuePair("message", message.toString())); } // Creates a review or a comment if (componentType.equals(REVIEWS)) { nameValuePairs.add(new BasicNameValuePair("message", record.get(2))); // This might be a top level review, or a comment on a review or another comment if (urlLevel == 0) { nameValuePairs.add(new BasicNameValuePair(":operation", "social:createReview")); nameValuePairs.add(new BasicNameValuePair("ratings", record.get(3))); if (record.size() > 4 && record.get(4).length() > 0) { // If we are dealing with a non-existent resource, then the design drives the behavior nameValuePairs.add(new BasicNameValuePair("scf:resourceType", "social/reviews/components/hbs/reviews")); nameValuePairs.add(new BasicNameValuePair("scf:included", record.get(4))); } } else { nameValuePairs.add(new BasicNameValuePair(":operation", "social:createComment")); } } // Creates a rating if (componentType.equals(RATINGS)) { nameValuePairs.add(new BasicNameValuePair(":operation", "social:postTallyResponse")); nameValuePairs.add(new BasicNameValuePair("tallyType", "Rating")); nameValuePairs.add(new BasicNameValuePair("response", record.get(2))); } // Creates a DAM asset if (componentType.equals(ASSET) && record.get(ASSET_INDEX_NAME).length() > 0) { nameValuePairs.add(new BasicNameValuePair("fileName", record.get(ASSET_INDEX_NAME))); } // Creates an enablement resource if (componentType.equals(RESOURCE)) { nameValuePairs.add(new BasicNameValuePair(":operation", "se:createResource")); List<NameValuePair> otherNameValuePairs = buildNVP(record, RESOURCE_INDEX_PROPERTIES); nameValuePairs.addAll(otherNameValuePairs); // Adding the site nameValuePairs.add(new BasicNameValuePair("site", "/content/sites/" + record.get(RESOURCE_INDEX_SITE) + "/resources/en")); // Building the cover image fragment if (record.get(RESOURCE_INDEX_THUMBNAIL).length() > 0) { nameValuePairs.add(new BasicNameValuePair("cover-image", doThumbnail(hostname, port, adminPassword, csvfile, record.get(RESOURCE_INDEX_THUMBNAIL)))); } else { nameValuePairs.add(new BasicNameValuePair("cover-image", "")); } // Building the asset fragment String coverPath = "/content/dam/" + record.get(RESOURCE_INDEX_SITE) + "/resource-assets/" + record.get(2) + "/jcr:content/renditions/cq5dam.thumbnail.319.319.png"; String coverSource = "dam"; String assets = "[{\"cover-img-path\":\"" + coverPath + "\",\"thumbnail-source\":\"" + coverSource + "\",\"asset-category\":\"enablementAsset:dam\",\"resource-asset-name\":null,\"state\":\"A\",\"asset-path\":\"/content/dam/" + record.get(RESOURCE_INDEX_SITE) + "/resource-assets/" + record.get(2) + "\"}]"; nameValuePairs.add(new BasicNameValuePair("assets", assets)); logger.debug("assets:" + assets); } // Creates a learning path if (componentType.equals(LEARNING)) { nameValuePairs.add(new BasicNameValuePair(":operation", "se:editLearningPath")); List<NameValuePair> otherNameValuePairs = buildNVP(record, RESOURCE_INDEX_PROPERTIES); nameValuePairs.addAll(otherNameValuePairs); // Adding the site nameValuePairs.add(new BasicNameValuePair("site", "/content/sites/" + record.get(RESOURCE_INDEX_SITE) + "/resources/en")); // Building the cover image fragment if (record.get(RESOURCE_INDEX_THUMBNAIL).length() > 0) { nameValuePairs.add(new BasicNameValuePair("card-image", doThumbnail(hostname, port, adminPassword, csvfile, record.get(RESOURCE_INDEX_THUMBNAIL)))); } // Building the learning path fragment StringBuffer assets = new StringBuffer("[\""); if (learningpaths.get(record.get(2)) != null) { ArrayList<String> paths = learningpaths.get(record.get(2)); int i = 0; for (String path : paths) { assets.append("{\\\"type\\\":\\\"linked-resource\\\",\\\"path\\\":\\\""); assets.append(path); assets.append("\\\"}"); if (i++ < paths.size() - 1) { assets.append("\",\""); } } } else { logger.debug("No asset for this learning path"); } assets.append("\"]"); nameValuePairs.add(new BasicNameValuePair("learningpath-items", assets.toString())); logger.debug("Learning path:" + assets.toString()); } // Creates a calendar event if (componentType.equals(CALENDAR)) { nameValuePairs.add(new BasicNameValuePair(":operation", "social:createEvent")); try { JSONObject event = new JSONObject(); // Building the JSON fragment for a new calendar event event.accumulate("subject", record.get(2)); event.accumulate("message", record.get(3)); event.accumulate("location", record.get(4)); event.accumulate("tags", ""); event.accumulate("undefined", "update"); String startDate = record.get(5); startDate = startDate.replaceAll("YYYY", Integer.toString(Calendar.getInstance().get(Calendar.YEAR))); startDate = startDate.replaceAll("MM", Integer.toString(1 + Calendar.getInstance().get(Calendar.MONTH))); event.accumulate("start", startDate); String endDate = record.get(6); endDate = endDate.replaceAll("YYYY", Integer.toString(Calendar.getInstance().get(Calendar.YEAR))); endDate = endDate.replaceAll("MM", Integer.toString(1 + Calendar.getInstance().get(Calendar.MONTH))); event.accumulate("end", endDate); nameValuePairs.add(new BasicNameValuePair("event", event.toString())); } catch (Exception ex) { logger.error(ex.getMessage()); } } // Constructing a multi-part POST request MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setCharset(MIME.UTF8_CHARSET); builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); for (NameValuePair nameValuePair : nameValuePairs) { builder.addTextBody(nameValuePair.getName(), nameValuePair.getValue(), ContentType.create("text/plain", MIME.UTF8_CHARSET)); } // See if we have attachments for this new post - or some other actions require a form nonetheless if ((componentType.equals(ASSET) || componentType.equals(AVATAR) || componentType.equals(FORUM) || (componentType.equals(JOURNAL)) || componentType.equals(BLOG)) && record.size() > 4 && record.get(ASSET_INDEX_NAME).length() > 0) { File attachment = new File(csvfile.substring(0, csvfile.indexOf(".csv")) + File.separator + record.get(ASSET_INDEX_NAME)); ContentType ct = ContentType.MULTIPART_FORM_DATA; if (record.get(ASSET_INDEX_NAME).indexOf(".mp4") > 0) { ct = ContentType.create("video/mp4", MIME.UTF8_CHARSET); } else if (record.get(ASSET_INDEX_NAME).indexOf(".jpg") > 0 || record.get(ASSET_INDEX_NAME).indexOf(".jpeg") > 0) { ct = ContentType.create("image/jpeg", MIME.UTF8_CHARSET); } else if (record.get(ASSET_INDEX_NAME).indexOf(".png") > 0) { ct = ContentType.create("image/png", MIME.UTF8_CHARSET); } else if (record.get(ASSET_INDEX_NAME).indexOf(".pdf") > 0) { ct = ContentType.create("application/pdf", MIME.UTF8_CHARSET); } else if (record.get(ASSET_INDEX_NAME).indexOf(".zip") > 0) { ct = ContentType.create("application/zip", MIME.UTF8_CHARSET); } builder.addBinaryBody("file", attachment, ct, attachment.getName()); logger.debug("Adding file to payload with name: " + attachment.getName() + " and type: " + ct.getMimeType()); } // If it's a resource or a learning path, we need the path to the resource for subsequent publishing String jsonElement = "location"; if (componentType.equals(RESOURCE)) { jsonElement = "changes/argument"; } if (componentType.equals(LEARNING)) { jsonElement = "path"; } if (componentType.equals(ASSET)) { jsonElement = null; } // This call generally returns the path to the content fragment that was just created location = Loader.doPost(hostname, port, url[urlLevel], userName, password, builder.build(), jsonElement); // If we are loading a DAM asset, we are waiting for all renditions to be generated before proceeding if (componentType.equals(ASSET)) { int pathIndex = url[urlLevel].lastIndexOf(".createasset.html"); if (pathIndex > 0) doWaitPath(hostname, port, adminPassword, url[urlLevel].substring(0, pathIndex) + "/" + record.get(ASSET_INDEX_NAME) + "/jcr:content/renditions", "nt:file"); } // Let's see if it needs to be added to a learning path if (componentType.equals(RESOURCE) && record.get(RESOURCE_INDEX_PATH).length() > 0 && location != null) { // Adding the location to a list of a resources for this particular Learning Path if (learningpaths.get(record.get(RESOURCE_INDEX_PATH)) == null) learningpaths.put(record.get(RESOURCE_INDEX_PATH), new ArrayList<String>()); logger.debug("Adding resource to Learning path: " + record.get(RESOURCE_INDEX_PATH)); ArrayList<String> locations = learningpaths.get(record.get(RESOURCE_INDEX_PATH)); locations.add(location); learningpaths.put(record.get(RESOURCE_INDEX_PATH), locations); } // If it's a Learning Path, we publish it when possible if (componentType.equals(LEARNING) && !port.equals(altport) && location != null) { // Publishing the learning path List<NameValuePair> publishNameValuePairs = new ArrayList<NameValuePair>(); publishNameValuePairs.add(new BasicNameValuePair(":operation", "se:publishEnablementContent")); publishNameValuePairs.add(new BasicNameValuePair("replication-action", "activate")); logger.debug("Publishing a learning path from: " + location); Loader.doPost(hostname, port, location, userName, password, new UrlEncodedFormEntity(publishNameValuePairs), null); // Waiting for the learning path to be published Loader.doWait(hostname, altport, "admin", adminPassword, location.substring(1 + location.lastIndexOf("/")) // Only search for groups with the learning path in it ); // Decorate the resources within the learning path with comments and ratings, randomly generated ArrayList<String> paths = learningpaths.get(record.get(2)); for (String path : paths) { doDecorate(hostname, altport, path, record, analytics); } } // If it's an Enablement Resource, a lot of things need to happen... // Step 1. If it's a SCORM resource, we wait for the SCORM metadata workflow to be complete before proceeding // Step 2. We publish the resource // Step 3. We set a new first published date on the resource (3 weeks earlier) so that reporting data is more meaningful // Step 4. We wait for the resource to be available on publish (checking that associated groups are available) // Step 5. We retrieve the json for the resource on publish to retrieve the Social endpoints // Step 6. We post ratings and comments for each of the enrollees on publish if (componentType.equals(RESOURCE) && !port.equals(altport) && location != null) { // Wait for the data to be fully copied doWaitPath(hostname, port, adminPassword, location + "/assets/asset", "nt:file"); // If we are dealing with a SCORM asset, we wait a little bit before publishing the resource to that the SCORM workflow is completed if (record.get(2).indexOf(".zip") > 0) { doSleep(10000, "SCORM Resource, waiting for workflow to complete"); } // Publishing the resource List<NameValuePair> publishNameValuePairs = new ArrayList<NameValuePair>(); publishNameValuePairs.add(new BasicNameValuePair(":operation", "se:publishEnablementContent")); publishNameValuePairs.add(new BasicNameValuePair("replication-action", "activate")); logger.debug("Publishing a resource from: " + location); Loader.doPost(hostname, port, location, userName, password, new UrlEncodedFormEntity(publishNameValuePairs), null); // Waiting for the resource to be published Loader.doWait(hostname, altport, "admin", adminPassword, location.substring(1 + location.lastIndexOf("/")) // Only search for groups with the resource path in it ); // Setting the first published timestamp so that reporting always comes with 3 weeks of data after building a new demo instance DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, REPORTINGDAYS); List<NameValuePair> publishDateNameValuePairs = new ArrayList<NameValuePair>(); publishDateNameValuePairs .add(new BasicNameValuePair("date-first-published", dateFormat.format(cal.getTime()))); logger.debug("Setting the publish date for a resource from: " + location); doPost(hostname, port, location, userName, password, new UrlEncodedFormEntity(publishDateNameValuePairs), null); // Adding comments and ratings for this resource doDecorate(hostname, altport, location, record, analytics); } } } catch (IOException e) { logger.error(e.getMessage()); } }
From source file:edu.oregonstate.eecs.mcplan.ml.ConstrainedKMeans.java
/** * @param args/*from w w w. j ava 2 s .co m*/ */ public static void main(final String[] args) { final RandomGenerator rng = new MersenneTwister(42); final int K = 2; final int d = 2; final ArrayList<RealVector> X = new ArrayList<RealVector>(); final double u = 2.0; final double ell = 8.0; final double gamma = 10.0; for (final int s : new int[] { 0, 5, 10 }) { for (int x = -1; x <= 1; ++x) { for (int y = -1; y <= 1; ++y) { X.add(new ArrayRealVector(new double[] { x + s, y })); } } } final TIntObjectMap<Pair<int[], double[]>> M = new TIntObjectHashMap<Pair<int[], double[]>>(); M.put(16, Pair.makePair(new int[] { 20 }, new double[] { 1.0 })); M.put(0, Pair.makePair(new int[] { 8 }, new double[] { 1.0 })); final TIntObjectMap<Pair<int[], double[]>> C = new TIntObjectHashMap<Pair<int[], double[]>>(); C.put(13, Pair.makePair(new int[] { 20 }, new double[] { 1.0 })); C.put(10, Pair.makePair(new int[] { 16 }, new double[] { 1.0 })); final ArrayList<double[]> S = new ArrayList<double[]>(); M.forEachKey(new TIntProcedure() { @Override public boolean execute(final int i) { final Pair<int[], double[]> p = M.get(i); if (p != null) { for (final int j : p.first) { S.add(new double[] { i, j }); } } return true; } }); final ArrayList<double[]> D = new ArrayList<double[]>(); C.forEachKey(new TIntProcedure() { @Override public boolean execute(final int i) { final Pair<int[], double[]> p = C.get(i); if (p != null) { for (final int j : p.first) { D.add(new double[] { i, j }); } } return true; } }); final ConstrainedKMeans kmeans = new ConstrainedKMeans(K, d, X, M, C, rng) { RealMatrix A_ = MatrixUtils.createRealIdentityMatrix(d); double Dmax_ = 1.0; @Override public double distance(final RealVector x1, final RealVector x2) { final RealVector diff = x1.subtract(x2); return Math.sqrt(HilbertSpace.inner_prod(diff, A_, diff)); } @Override public double distanceMax() { return Dmax_; } @Override protected void initializeDistanceFunction() { double max_distance = 0.0; for (int i = 0; i < X.size(); ++i) { for (int j = i + 1; j < X.size(); ++j) { final double d = distance(X.get(i), X.get(j)); if (d > max_distance) { max_distance = d; } } } Dmax_ = max_distance; } @Override protected boolean updateDistanceFunction() { final InformationTheoreticMetricLearner itml = new InformationTheoreticMetricLearner(S, D, u, ell, A_, gamma, rng_); itml.run(); final double delta = A_.subtract(itml.A()).getFrobeniusNorm(); A_ = itml.A(); initializeDistanceFunction(); return delta > convergence_tolerance_; } }; kmeans.run(); for (int i = 0; i < kmeans.mu().length; ++i) { System.out.println("Mu " + i + ": " + kmeans.mu()[i]); for (int j = 0; j < kmeans.assignments().length; ++j) { if (kmeans.assignments()[j] == i) { System.out.println("\tPoint " + X.get(j)); } } } }
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/* www . j av a2 s. c o m*/ ----------------------------*/ 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:com.hp.test.framework.Reporting.Utlis.java
public static void main(String ar[]) throws IOException { ArrayList<String> runs_list = new ArrayList<String>(); String basepath = replacelogs(); String path = basepath + "ATU Reports\\Results"; File directory = new File(path); File[] subdirs = directory.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY); String htmlReport = basepath + "HTML_Design_Files\\CSS\\HtmlReport.html"; for (File dir : subdirs) { runs_list.add(dir.getName());/*w w w . ja v a2 s . co m*/ } String Reports_path = basepath + "ATU Reports\\"; int LatestRun = Utlis.getLastRun(Reports_path); String Last_run_path = Reports_path + "Results\\Run_" + String.valueOf(LatestRun) + "\\"; HtmlParse.replaceMainTable(false, new File(Last_run_path + "/CurrentRun.html")); HtmlParse.replaceCountsinJSFile(new File("HTML_Design_Files/JS/3dChart.js"), Last_run_path); UpdateTestCaseDesciption.basepath = Last_run_path; UpdateTestCaseDesciption.getTestCaseHtmlPath(Last_run_path + "/CurrentRun.html"); UpdateTestCaseDesciption.replaceDetailsTable(Last_run_path + "/CurrentRun.html"); // GenerateFailReport.genarateFailureReport(new File(htmlReport), Reports_path + "Results\\Run_" + String.valueOf(LatestRun)); genarateFailureReport(new File(htmlReport), Reports_path + "Results\\"); Map<String, List<String>> runCounts = GetCountsrunsWise(runs_list, path); int success = replaceCounts(runCounts, path); if (success == 0) { File SourceFile = new File(path + "\\lineChart_temp.js"); File RenameFile = new File(path + "\\lineChart.js"); renameOriginalFile(SourceFile, RenameFile); File SourceFile1 = new File(path + "\\barChart_temp.js"); File RenameFile1 = new File(path + "\\barChart.js"); renameOriginalFile(SourceFile1, RenameFile1); Utlis.getpaths(Reports_path + "\\Results\\Run_" + String.valueOf(LatestRun)); try { Utlis.replaceMainTable(false, new File(Reports_path + "index.html")); Utlis.replaceMainTable(true, new File(Reports_path + "results\\" + "ConsolidatedPage.html")); Utlis.replaceMainTable(true, new File(Reports_path + "Results\\Run_" + String.valueOf(LatestRun) + "CurrentRun.html")); fileList.add( new File(Reports_path + "\\Results\\Run_" + String.valueOf(LatestRun) + "CurrentRun.html")); for (File f : fileList) { Utlis.replaceMainTable(true, f); } } catch (Exception ex) { log.info("Error in updating Report format" + ex.getMessage()); } Last_run_path = Reports_path + "Results\\Run_" + String.valueOf(LatestRun) + "\\"; // HtmlParse.replaceMainTable(false, new File(Last_run_path + "/CurrentRun.html")); // HtmlParse.replaceCountsinJSFile(new File("../HTML_Design_Files/JS/3dChart.js"), Last_run_path); ArrayList<String> to_list = new ArrayList<String>(); ReportingProperties reportingproperties = new ReportingProperties(); String temp_eml = reportingproperties.getProperty("TOLIST"); String JenkinsURL = reportingproperties.getProperty("JENKINSURL"); String ScreenShotsDir = reportingproperties.getProperty("ScreenShotsDirectory"); Boolean cleanScreenshotsDir = Boolean.valueOf(reportingproperties.getProperty("CleanPreScreenShots")); Boolean generatescreenshots = Boolean.valueOf(reportingproperties.getProperty("GenerateScreenShots")); String HtmlreportFilePrefix = reportingproperties.getProperty("HtmlreportFilePrefix"); if (cleanScreenshotsDir) { if (!CleanFilesinDir(ScreenShotsDir)) { log.error("Not able to Clean the Previous Run Details in the paht" + ScreenShotsDir); } else { log.info("Cleaning Previous Run Details in the paht" + ScreenShotsDir + "Sucess"); } } List<String> scr_fileList; List<String> html_fileList; if (generatescreenshots) { scr_fileList = GetFileListinDir(ScreenShotsDir, "png"); int len = scr_fileList.size(); len = len + 1; screenshot.generatescreenshot(Last_run_path + "CurrentRun.html", ScreenShotsDir + "screenshot_" + len + ".png"); File source = new File(Reports_path + "Results\\HtmlReport.html"); File dest = new File(ScreenShotsDir + HtmlreportFilePrefix + "_HtmlReport.html"); // Files.copy(f.toPath(), (new File((ScreenShotsDir+HtmlreportFilePrefix+"_HtmlReport.html").toPath(),StandardCopyOption.REPLACE_EXISTING); FileUtils.copyFile(source, dest); scr_fileList.clear(); } scr_fileList = GetFileListinDir(ScreenShotsDir, "png"); html_fileList = GetFileListinDir(ScreenShotsDir, "html"); if (temp_eml.length() > 1) { String[] to_list_temp = temp_eml.split(","); if (to_list_temp.length > 0) { for (String to_list_temp1 : to_list_temp) { to_list.add(to_list_temp1); } } if (to_list.size() > 0) { screenshot.generatescreenshot(Last_run_path + "CurrentRun.html", Last_run_path + "screenshot.png"); // cleanTempDir.cleanandCreate(Reports_path, LatestRun); // ZipUtils.ZipFolder(Reports_path + "temp", Reports_path + "ISTF_Reports.zip"); if (generatescreenshots) { SendingEmail.sendmail(to_list, JenkinsURL, scr_fileList, html_fileList); } else { SendingEmail.sendmail(to_list, JenkinsURL, Reports_path + "/Results/HtmlReport.html", Last_run_path + "screenshot.png"); } // FileUtils.deleteQuietly(new File(Reports_path + "ISTF_Reports.zip")); // FileUtils.deleteDirectory(new File(Reports_path + "temp")); } } } }
From source file:it.univpm.deit.semedia.musicuri.core.MusicURISearch.java
/** * Identifies the MusicURIReference that most closely matches the given audio file * @param args the audio file to identify */// w w w.ja va 2 s . c o m public static void main(String[] args) throws Exception { MusicURISearch engine = new MusicURISearch((Toolset.getCWD() + "db\\"), "MusicURIReferences.db"); // MusicURIDatabase db = new MusicURIDatabase ("C:/Eclipse/workspace/MusicURI/db/", "MusicURIReferences.db"); // MusicURISearch engine = new MusicURISearch (db); //MusicURISearch engine = new MusicURISearch ("D:/10References/", "MusicURIReferences.db"); //***************************************************************************** //************************* F I L E I N P U T *************************** //***************************************************************************** if ((args.length == 1) && (new File(args[0]).exists())) { // get the file's canonical path File givenHandle = new File(args[0]); boolean finalResortIsCombinedDistance = true; String queryAudioCanonicalPath = givenHandle.getCanonicalPath(); System.out.println("Input: " + queryAudioCanonicalPath); PerformanceStatistic tempStat; if (givenHandle.isDirectory()) { File[] list = givenHandle.listFiles(); if (list.length == 0) { System.out.println("Directory is empty"); return; } else { ArrayList allStats = new ArrayList(); File currentFile; int truePositives = 0; int falsePositives = 0; int trueNegatives = 0; int falseNegatives = 0; if (finalResortIsCombinedDistance) System.out.println(" Final resort is combined distance"); else System.out.println(" Final resort is audio signature distance"); for (int i = 0; i < list.length; i++) { currentFile = list[i]; try { if (Toolset.isSupportedAudioFile(currentFile)) { System.out.println("\nIdentifying : " + currentFile.getName()); tempStat = engine.getIdentificationPerformance(new MusicURIQuery(givenHandle), true, true, 0.09f, finalResortIsCombinedDistance); //identify (new MusicURIQuery(currentFile), true, true, 0.09f, finalResortIsCombinedDistance, 1); if (tempStat != null) allStats.add(tempStat); if (tempStat.isTruePositive()) truePositives++; if (tempStat.isFalsePositive()) falsePositives++; if (tempStat.isTrueNegative()) trueNegatives++; if (tempStat.isFalseNegative()) falseNegatives++; System.out.println( "\nTrue Positives : " + truePositives + "/" + allStats.size()); System.out .println("False Positives : " + falsePositives + "/" + allStats.size()); System.out .println("True Negatives : " + trueNegatives + "/" + allStats.size()); System.out .println("False Negatives : " + falseNegatives + "/" + allStats.size()); } } catch (Exception e) { e.printStackTrace(); } } System.out.println("\n\nStatistics for Test Case: " + queryAudioCanonicalPath); engine.mergeStatistics(allStats); } } //end if givenHandle is Directory if (givenHandle.isFile()) { if (Toolset.isSupportedAudioFile(givenHandle)) { //tempStat = engine.getIdentificationPerformance (new MusicURIQuery(givenHandle), true, true, 0.09f, finalResortIsCombinedDistance); tempStat = engine.getIdentificationPerformance(new MusicURIQuery(givenHandle), false, false, 0.09f, false); //identify (new MusicURIQuery(givenHandle), true, true, 0.09f, finalResortIsCombinedDistance, 1); if (tempStat != null) { System.out.println("\nIdentification completed"); //tempStat.printStatistics(); ArrayList allStats = new ArrayList(); allStats.add(tempStat); engine.mergeStatistics(allStats); } else System.out.println("Error in identification "); } } } //end if else { System.err.println("MusicURISearch"); System.err.println("Usage: java it.univpm.deit.semedia.musicuri.core.MusicURISearch {unknown.mp3}"); } }
From source file:gov.nasa.jpl.memex.pooledtimeseries.PoT.java
public static void main(String[] args) { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); Option fileOpt = OptionBuilder.withArgName("file").hasArg().withLongOpt("file") .withDescription("Path to a single file").create('f'); Option dirOpt = OptionBuilder.withArgName("directory").hasArg().withLongOpt("dir") .withDescription("A directory with image files in it").create('d'); Option helpOpt = OptionBuilder.withLongOpt("help").withDescription("Print this message.").create('h'); Option pathFileOpt = OptionBuilder.withArgName("path file").hasArg().withLongOpt("pathfile") .withDescription(//from w w w. j a va 2 s.c om "A file containing full absolute paths to videos. Previous default was memex-index_temp.txt") .create('p'); Option outputFileOpt = OptionBuilder.withArgName("output file").withLongOpt("outputfile").hasArg() .withDescription("File containing similarity results. Defaults to ./similarity.txt").create('o'); Option jsonOutputFlag = OptionBuilder.withArgName("json output").withLongOpt("json") .withDescription("Set similarity output format to JSON. Defaults to .txt").create('j'); Option similarityFromFeatureVectorsOpt = OptionBuilder .withArgName("similarity from FeatureVectors directory") .withLongOpt("similarityFromFeatureVectorsDirectory").hasArg() .withDescription("calculate similarity matrix from given directory of feature vectors").create('s'); Options options = new Options(); options.addOption(dirOpt); options.addOption(pathFileOpt); options.addOption(fileOpt); options.addOption(helpOpt); options.addOption(outputFileOpt); options.addOption(jsonOutputFlag); options.addOption(similarityFromFeatureVectorsOpt); // create the parser CommandLineParser parser = new GnuParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); String directoryPath = null; String pathFile = null; String singleFilePath = null; String similarityFromFeatureVectorsDirectory = null; ArrayList<Path> videoFiles = null; if (line.hasOption("dir")) { directoryPath = line.getOptionValue("dir"); } if (line.hasOption("pathfile")) { pathFile = line.getOptionValue("pathfile"); } if (line.hasOption("file")) { singleFilePath = line.getOptionValue("file"); } if (line.hasOption("outputfile")) { outputFile = line.getOptionValue("outputfile"); } if (line.hasOption("json")) { outputFormat = OUTPUT_FORMATS.JSON; } if (line.hasOption("similarityFromFeatureVectorsDirectory")) { similarityFromFeatureVectorsDirectory = line .getOptionValue("similarityFromFeatureVectorsDirectory"); } if (line.hasOption("help") || (line.getOptions() == null || (line.getOptions() != null && line.getOptions().length == 0)) || (directoryPath != null && pathFile != null && !directoryPath.equals("") && !pathFile.equals(""))) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("pooled_time_series", options); System.exit(1); } if (directoryPath != null) { File dir = new File(directoryPath); List<File> files = (List<File>) FileUtils.listFiles(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); videoFiles = new ArrayList<Path>(files.size()); for (File file : files) { String filePath = file.toString(); // When given a directory to load videos from we need to ensure that we // don't try to load the of.txt and hog.txt intermediate result files // that results from previous processing runs. if (!filePath.contains(".txt")) { videoFiles.add(file.toPath()); } } LOG.info("Added " + videoFiles.size() + " video files from " + directoryPath); } if (pathFile != null) { Path list_file = Paths.get(pathFile); videoFiles = loadFiles(list_file); LOG.info("Loaded " + videoFiles.size() + " video files from " + pathFile); } if (singleFilePath != null) { Path singleFile = Paths.get(singleFilePath); LOG.info("Loaded file: " + singleFile); videoFiles = new ArrayList<Path>(1); videoFiles.add(singleFile); } if (similarityFromFeatureVectorsDirectory != null) { File dir = new File(similarityFromFeatureVectorsDirectory); List<File> files = (List<File>) FileUtils.listFiles(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); videoFiles = new ArrayList<Path>(files.size()); for (File file : files) { String filePath = file.toString(); // We need to load only the *.of.txt and *.hog.txt values if (filePath.endsWith(".of.txt")) { videoFiles.add(file.toPath()); } if (filePath.endsWith(".hog.txt")) { videoFiles.add(file.toPath()); } } LOG.info("Added " + videoFiles.size() + " feature vectors from " + similarityFromFeatureVectorsDirectory); evaluateSimilarity(videoFiles, 1); } else { evaluateSimilarity(videoFiles, 1); } LOG.info("done."); } catch (ParseException exp) { // oops, something went wrong System.err.println("Parsing failed. Reason: " + exp.getMessage()); } }
From source file:de.prozesskraft.ptest.Launch.java
public static void main(String[] args) throws org.apache.commons.cli.ParseException, IOException { // try//from w w w .j a v a 2s.c o m // { // if (args.length != 3) // { // System.out.println("Please specify processdefinition file (xml) and an outputfilename"); // } // // } // catch (ArrayIndexOutOfBoundsException e) // { // System.out.println("***ArrayIndexOutOfBoundsException: Please specify processdefinition.xml, openoffice_template.od*, newfile_for_processdefinitions.odt\n" + e.toString()); // } /*---------------------------- get options from ini-file ----------------------------*/ File inifile = new java.io.File( WhereAmI.getInstallDirectoryAbsolutePath(Launch.class) + "/" + "../etc/ptest-launch.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 ospl = OptionBuilder.withArgName("DIR").hasArg() .withDescription("[mandatory] directory with sample input data") // .isRequired() .create("spl"); Option oinstancedir = OptionBuilder.withArgName("DIR").hasArg() .withDescription("[mandatory, default: .] directory where the test will be performed") // .isRequired() .create("instancedir"); Option ocall = OptionBuilder.withArgName("FILE").hasArg() .withDescription("[mandatory, default: random call in spl-directory] file with call-string") // .isRequired() .create("call"); Option oaltapp = OptionBuilder.withArgName("STRING").hasArg() .withDescription( "[optional] alternative app. this String replaces the first line of the .call-file.") // .isRequired() .create("altapp"); Option oaddopt = OptionBuilder.withArgName("STRING").hasArg() .withDescription("[optional] add an option to the call.") // .isRequired() .create("addopt"); Option onolaunch = new Option("nolaunch", "only create instance directory, copy all spl files, but do NOT launch the process"); /*---------------------------- create options object ----------------------------*/ Options options = new Options(); options.addOption(ohelp); options.addOption(ov); options.addOption(ospl); options.addOption(oinstancedir); options.addOption(ocall); options.addOption(oaltapp); options.addOption(oaddopt); options.addOption(onolaunch); /*---------------------------- create the parser ----------------------------*/ CommandLineParser parser = new GnuParser(); try { // parse the command line arguments commandline = parser.parse(options, args); } catch (Exception exp) { // oops, something went wrong System.err.println("Parsing failed. Reason: " + exp.getMessage()); exiter(); } /*---------------------------- usage/help ----------------------------*/ if (commandline.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("launch", options); System.exit(0); } else if (commandline.hasOption("v")) { System.out.println("web: " + web); System.out.println("author: " + author); System.out.println("version:" + version); System.out.println("date: " + date); System.exit(0); } /*---------------------------- ueberpruefen ob eine schlechte kombination von parametern angegeben wurde ----------------------------*/ boolean error = false; String spl = null; String instancedir = null; String call = null; String altapp = null; ArrayList<String> addopt = new ArrayList<String>(); // spl initialisieren if (commandline.hasOption("spl")) { spl = commandline.getOptionValue("spl"); } else { System.err.println("option -spl is mandatory"); error = true; } // instancedir initialisieren if (commandline.hasOption("instancedir")) { instancedir = commandline.getOptionValue("instancedir"); } else { instancedir = System.getProperty("user.dir"); } // call initialisieren if (commandline.hasOption("call")) { call = commandline.getOptionValue("call"); } // altapp initialisieren if (commandline.hasOption("altapp")) { altapp = commandline.getOptionValue("altapp"); } // addopt initialisieren if (commandline.hasOption("addopt")) { for (String actString : commandline.getOptionValues("addopt")) { addopt.add(actString); } } // wenn fehler, dann exit if (error) { exiter(); } /*---------------------------- 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 ----------------------------*/ // das erste spl-objekt geben lassen Spl actSpl = new Splset(spl).getSpl().get(0); // den call, result und altapp ueberschreiben actSpl.setName("default"); if (call != null) { actSpl.setCall(new java.io.File(call)); } if (actSpl.getCall() == null) { System.err.println("error: no call information found"); System.exit(1); } if (altapp != null) { actSpl.setAltapp(altapp); } if (addopt.size() > 0) { actSpl.setAddopt(addopt); } actSpl.setResult(null); // das instancedir erstellen java.io.File actSplInstanceDir = new java.io.File(instancedir); System.err.println("info: creating directory " + actSplInstanceDir.getCanonicalPath()); actSplInstanceDir.mkdirs(); // Inputdaten in das InstanceDir exportieren actSpl.exportInput(actSplInstanceDir); // exit, wenn --nolaunch if (commandline.hasOption("nolaunch")) { System.err.println("info: exiting, because of -nolaunch"); System.exit(0); } // das logfile des Syscalls (zum debuggen des programms "process syscall" gedacht) String AbsLogSyscallWrapper = actSplInstanceDir.getCanonicalPath() + "/.log"; String AbsStdout = actSplInstanceDir.getCanonicalPath() + "/.stdout.txt"; String AbsStderr = actSplInstanceDir.getCanonicalPath() + "/.stderr.txt"; String AbsPid = actSplInstanceDir.getCanonicalPath() + "/.pid"; // beim starten von syscall werden parameter mit whitespaces an diesen auseinandergeschnitten und der nachfolgende aufruf schlaeft fehl // deshalb sollen whitespaces durch eine 'zeichensequenz' ersetzt werden // syscall ersetzt die zeichensequenz wieder zurueck in ein " " ArrayList<String> callFuerSyscall = actSpl.getCallAsArrayList(); ArrayList<String> callFuerSyscallMitTrennzeichen = new ArrayList<String>(); for (String actString : callFuerSyscall) { callFuerSyscallMitTrennzeichen.add(actString.replaceAll("\\s+", "%WHITESPACE%")); } try { // den Aufrufstring fuer die externe App (process syscall --version 0.6.0)) splitten // beim aufruf muss das erste argument im path zu finden sein, sonst gibt die fehlermeldung 'no such file or directory' ArrayList<String> processSyscallWithArgs = new ArrayList<String>( Arrays.asList(ini.get("apps", "pkraft-syscall").split(" "))); // die sonstigen argumente hinzufuegen processSyscallWithArgs.add("-call"); processSyscallWithArgs.add(String.join(" ", callFuerSyscallMitTrennzeichen)); // processSyscallWithArgs.add("\""+call+"\""); processSyscallWithArgs.add("-stdout"); processSyscallWithArgs.add(AbsStdout); processSyscallWithArgs.add("-stderr"); processSyscallWithArgs.add(AbsStderr); processSyscallWithArgs.add("-pid"); processSyscallWithArgs.add(AbsPid); processSyscallWithArgs.add("-mylog"); processSyscallWithArgs.add(AbsLogSyscallWrapper); processSyscallWithArgs.add("-maxrun"); processSyscallWithArgs.add("" + 3000); // erstellen prozessbuilder ProcessBuilder pb = new ProcessBuilder(processSyscallWithArgs); // erweitern des PATHs um den prozesseigenen path // Map<String,String> env = pb.environment(); // String path = env.get("PATH"); // log("debug", "$PATH="+path); // path = this.parent.getAbsPath()+":"+path; // env.put("PATH", path); // log("info", "path: "+path); // setzen der aktuellen directory (in der syscall ausgefuehrt werden soll) java.io.File directory = new java.io.File(instancedir); System.err.println("info: setting execution directory to: " + directory.getCanonicalPath()); pb.directory(directory); // zum debuggen ein paar ausgaben // java.lang.Process p1 = Runtime.getRuntime().exec("date >> ~/tmp.debug.work.txt"); // p1.waitFor(); // java.lang.Process p2 = Runtime.getRuntime().exec("ls -la "+this.getParent().getAbsdir()+" >> ~/tmp.debug.work.txt"); // p2.waitFor(); // java.lang.Process pro = Runtime.getRuntime().exec("nautilus"); // java.lang.Process superpro = Runtime.getRuntime().exec(processSyscallWithArgs.toArray(new String[processSyscallWithArgs.size()])); // p3.waitFor(); System.err.println("info: calling: " + pb.command()); // starten des prozesses java.lang.Process sysproc = pb.start(); // einfangen der stdout- und stderr des subprozesses InputStream is_stdout = sysproc.getInputStream(); InputStream is_stderr = sysproc.getErrorStream(); // Send your InputStream to an InputStreamReader: InputStreamReader isr_stdout = new InputStreamReader(is_stdout); InputStreamReader isr_stderr = new InputStreamReader(is_stderr); // That needs to go to a BufferedReader: BufferedReader br_stdout = new BufferedReader(isr_stdout); BufferedReader br_stderr = new BufferedReader(isr_stderr); // // oeffnen der OutputStreams zu den Ausgabedateien // FileWriter fw_stdout = new FileWriter(sStdout); // FileWriter fw_stderr = new FileWriter(sStderr); // zeilenweise in die files schreiben String line_out = new String(); String line_err = new String(); while (br_stdout.readLine() != null) { } // while (((line_out = br_stdout.readLine()) != null) || ((line_err = br_stderr.readLine()) != null)) // { // if (!(line_out == null)) // { // System.out.println(line_out); // System.out.flush(); // } // if (!(line_err == null)) // { // System.err.println(line_err); // System.err.flush(); // } // } int exitValue = sysproc.waitFor(); // fw_stdout.close(); // fw_stderr.close(); System.err.println("exitvalue: " + exitValue); sysproc.destroy(); System.exit(exitValue); // alternativer aufruf // java.lang.Process sysproc = Runtime.getRuntime().exec(StringUtils.join(args_for_syscall, " ")); // log("info", "call executed. pid="+sysproc.hashCode()); // wait 2 seconds for becoming the pid-file visible // Thread.sleep(2000); // int exitValue = sysproc.waitFor(); // // der prozess soll bis laengstens // if(exitValue != 0) // { // System.err.println("error: call returned a value indicating an error: "+exitValue); // } // else // { // System.err.println("info: call returned value: "+exitValue); // } // System.err.println("info: "+new Date().toString()); // System.err.println("info: bye"); // // sysproc.destroy(); // // System.exit(sysproc.exitValue()); } catch (Exception e2) { System.err.println("error: " + e2.getMessage()); System.exit(1); } }