/** * Directs a chart request to a ChartMediator.<br> * Referring to a given configuration (id), it directs a request for a chart to a ChartMediator * and returns the result. * * @param json String path to a .json file where request information are stored * @return a json-object which contains all information about the requested chart * @see ChartMediator */ public JSONObject computeChart(JSONObject json) { if (json == null) { throw new IllegalArgumentException(); } // checks whether a request is allowed if (!isInitialized()) { Printer.pproblem("Configurations & mediators not initalized!"); Printer.print("-> Chart creation not possible!"); return null; } if (!(tablesAreCreated())) { Printer.pproblem("Tables not created. Request not possible"); return null; } // direct request and hopefully receive a JSON object JSONObject chart = chartMedi.computeChart(json); if (chart == null) { Printer.pfail("Computing chart."); return null; } else { Printer.psuccess("Computing chart."); } return chart; }
/** Precomputes the Strings in the dimensions for the web page selection boxes. */ private void computeDimensionData() { assert (isInitialized()); if (!(dataMedi.organizeData())) { Printer.pfail("Precomputing data for dimensions."); } else { web.ChartHelper.reset(); Printer.psuccess("Precomputing data for dimensions."); } }
/** * Initializes this facade with a ConfigWrap, what is necessary to post requests to it. * * @param path of the configuration file (.json) * @return whether initialization was successful */ public boolean init(final String path) { if (path == null) { throw new IllegalArgumentException(); } // tries to build a new ConfigWrap ConfigWrap config = ConfigWrap.buildConfig(path); if (config == null) { Printer.pfail("Building ConfigWrap with the given path failed"); return false; } else { Printer.psuccess("Building ConfigWrap for: " + config.getNameOfDB()); } // set all the attributes currentConfig = config; dataMedi = new DataMediator(config); chartMedi = new ChartMediator(config, dataMedi); parsMedi = new ParserMediator(config, dataMedi); // testing // Printer.ptest(config.toString()); // create tables for the configuration if necessary if (!(tablesAreCreated())) { Printer.print("Tables not created for this configuration. Will happen now."); if (!(createDBTables())) { Printer.pfail("Creating tables for this configuration"); return false; } else { Printer.psuccess("Creating tables for this configuration"); } } // pre-compute strings for the web page selection boxes computeDimensionData(); Printer.psuccess("Initialize facade."); return true; }
/** * Directs a parsing request to a ParserMediator.<br> * Referring to the given configuration (id), it directs the request of parsing a given log-file * (path) to a ParserMediator. * * @param path path of the log file, which has to be parsed * @return whether parsing this log file was successful, to a certain point; therefore {@linkplain * ParserMediator} * @see ParserMediator */ public boolean parseLogFile(String path) { if (path == null) { throw new IllegalArgumentException(); } // Printer.ptest("creating tables: " + createDBTables()); // testing // Printer.ptest("Start parsing task."); // long start = System.currentTimeMillis(); // checks whether a request is allowed if (!isInitialized()) { Printer.pproblem("Configurations & mediators not initalized!"); Printer.print("-> Parsing not possible!"); return false; } if (!(tablesAreCreated())) { Printer.pproblem("Tables not created. Request not possible"); return false; } // directs the request if (!parsMedi.parseLogFile(path)) { Printer.pfail("Parsing."); return false; } else { Printer.psuccess("Parsing."); } // testing // Printer.ptest("Completed parsing task. Time needed: " + (System.currentTimeMillis() - // start)); // precompute strings for the web page selection boxes after parsinng computeDimensionData(); return true; }