List of usage examples for org.apache.commons.dbutils.handlers ArrayListHandler ArrayListHandler
public ArrayListHandler()
BasicRowProcessor
for conversions. From source file:ch.admin.suis.msghandler.log.DbLogService.java
/** * Creates the CSV-file in the directory in which the database files are located. If the service was not initialized, * this method silently returns./*from ww w.j a va 2s. c o m*/ */ @SuppressWarnings("unchecked") public void dump() { if (null == connection) { // this service was not initialized LOG.error("cannot create the DB dump file: the log service was not initialized"); return; } File dumpFile = new File(base, "dump.csv"); // TODO make this configurable try (BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(dumpFile), "ISO-8859-1"))) { // read all the available records from the DB ArrayList<Object[]> rowSet = (ArrayList<Object[]>) runner.query(connection, "select * from status", new ArrayListHandler()); for (Object[] row : rowSet) { for (int i = 0; i < row.length; i++) { // replace the null values with empty strings row[i] = null == row[i] ? "" : row[i]; } writer.write(MessageFormat.format(DUMP_LINE, row)); } } catch (UnsupportedEncodingException e) { LOG.fatal(e); } catch (FileNotFoundException e) { LOG.fatal("cannot create the DB dump file " + dumpFile.getAbsolutePath() + ". Error : " + e); } catch (SQLException e) { LOG.fatal("cannot read from the status table: " + e); } catch (IOException e) { LOG.fatal("cannot write to the dump file: " + e); } }
From source file:io.seqware.pipeline.plugins.WorkflowSchedulerTest.java
@Test public void testMetadataOff() { launchPlugin("--workflow-accession", "2860", "--host", FileTools.getLocalhost(null).hostname, "--no-metadata"); String s = getOut();//from w ww . ja v a 2 s . c o m String firstWorkflowRun = getAndCheckSwid(s); BasicTestDatabaseCreator dbCreator = new BasicTestDatabaseCreator(); List<Object[]> runQuery = dbCreator.runQuery(new ArrayListHandler(), "select r.status, r.workflow_id, r.workflow_engine from workflow_run r\n" + "WHERE \n" + "r.sw_accession = ?\n" + "; ", Integer.valueOf(firstWorkflowRun)); Assert.assertTrue( "schedule workflow is incorrect " + runQuery.get(0)[0].toString() + " " + runQuery.get(0)[1].toString(), runQuery.get(0)[0].equals(WorkflowRunStatus.submitted.toString()) && runQuery.get(0)[1].equals(15)); WorkflowRun workflowRun = metadata.getWorkflowRun(Integer.valueOf(firstWorkflowRun)); // check that default keys are present Map<String, String> baseMap = MapTools.iniString2Map(workflowRun.getIniFile()); Assert.assertTrue("base map is metadata", baseMap.containsKey("metadata")); Assert.assertTrue("base map has incorrect values", baseMap.get("metadata").equals("no-metadata")); }
From source file:ch.admin.suis.msghandler.log.DbLogService.java
@Override public List<String> getFiles(String messageId) throws LogServiceException { try {//from ww w . j av a 2 s . co m ArrayList<Object[]> rowSet = (ArrayList<Object[]>) runner.query(connection, SELECT_FILENAME_STATEMENT, new Object[] { messageId }, new ArrayListHandler()); List<String> result = new ArrayList<>(rowSet.size()); for (Object[] row : rowSet) { // we have only one element in the array - the filename and it is a // string result.add((String) row[0]); } return result; } catch (SQLException e) { throw new LogServiceException(e); } }
From source file:ch.admin.suis.msghandler.log.DbLogService.java
/** * {@inheritDoc }/*from www .j a va 2s. c o m*/ */ @Override public List<DBLogEntry> getAllEntries() throws LogServiceException { try { ArrayList<Object[]> rowSet = (ArrayList<Object[]>) runner.query(connection, SELECT_ALL_STATEMENT, new Object[] {}, new ArrayListHandler()); List<DBLogEntry> results = new ArrayList<>(rowSet.size()); for (Object[] row : rowSet) { DBLogEntry logEntry = parseDBLogEntry(row); results.add(logEntry); } return results; } catch (SQLException e) { throw new LogServiceException(e); } }
From source file:ch.admin.suis.msghandler.log.DbLogService.java
@Override public List<String> getMessages(LogStatus status) throws LogServiceException { try {//from www . ja v a 2 s . c o m ArrayList<Object[]> rowSet = (ArrayList<Object[]>) runner.query(connection, SELECT_MESSAGE_ID_ALL_STATEMENT, new Object[] { status.getCode() }, new ArrayListHandler()); List<String> result = new ArrayList<>(rowSet.size()); for (Object[] row : rowSet) { // we have only one element in the array - the message ID and it is a // string result.add((String) row[0]); } return result; } catch (SQLException e) { throw new LogServiceException(e); } }
From source file:ch.admin.suis.msghandler.log.DbLogService.java
@Override public boolean isTransparent(String messageId) throws LogServiceException { try {// w w w .ja v a 2 s. c o m ArrayList<Object[]> rowSet = (ArrayList<Object[]>) runner.query(connection, SELECT_SOURCE_STATEMENT, new Object[] { messageId }, new ArrayListHandler()); List<Integer> result = new ArrayList<>(rowSet.size()); for (Object[] row : rowSet) { // we have only one element in the array - the message ID and it is a // string result.add((Integer) row[0]); } // nothing found, otherwise return the first encountered value return result.isEmpty() || Mode.TRANSP.getCode() == result.get(0); } catch (SQLException e) { throw new LogServiceException(e); } }
From source file:net.sourceforge.seqware.pipeline.plugins.AttributeAnnotatorET.java
/** * Annotate skip with an implicit key of "skip" * * @param type/*from w w w.j a va 2 s. c o m*/ * @param accession * @throws IOException */ public void annotateSkipImplicitly(AttributeType type, int accession) throws IOException { String query = "SELECT t2." + type.table_name + "_attribute_id, t2.tag, t2.value FROM " + type.table_name + "_attribute t2, " + type.table_name + " t1 WHERE " + "t1." + type.table_name + "_id=t2." + type.attribute_id_prefix + "_id AND t1.sw_accession=? ORDER BY " + type.table_name + "_attribute_id"; Log.info(query); String value = "\"Improperly entered into the LIMS\""; String listCommand = "-p net.sourceforge.seqware.pipeline.plugins.AttributeAnnotator " + "-- --" + type.parameter_prefix + "-accession " + accession + " --skip true --value " + value; int expectedReturnValue = type.skippable ? ReturnValue.SUCCESS : ReturnValue.INVALIDPARAMETERS; ITUtility.runSeqWareJar(listCommand, expectedReturnValue, null); if (type.skippable) { Object[] runQuery = dbCreator.runQuery(new ArrayHandler(), "SELECT skip FROM " + type.table_name + " WHERE sw_accession=?", accession); Assert.assertTrue("skip value incorrect", runQuery.length == 1 && runQuery[0].equals(true)); List<Object[]> runQuery1 = dbCreator.runQuery(new ArrayListHandler(), query, accession); Assert.assertTrue("first annotation incorrect", runQuery1.size() == 1); Assert.assertTrue("first tag incorrect", runQuery1.get(0)[1].equals("skip")); Assert.assertTrue("first value incorrect", runQuery1.get(0)[2].equals(value)); } }
From source file:net.sourceforge.seqware.pipeline.plugins.AttributeAnnotatorET.java
/** * Annotate an attribute with both a key and value. Re-annotate and ensure * that no duplicates are formed.// ww w.j av a2 s .com * * @param type * @param accession * @throws IOException */ public void annotateAndReannotate(AttributeType type, int accession) throws IOException { final String funky_key = "funky_key"; final String funky_second_value = "funky_second_value"; final String funky_initial_value = "funky_initial_value"; final String groovy_key = "groovy_key"; final String groovy_value = "groovy_value"; String listCommand = "-p net.sourceforge.seqware.pipeline.plugins.AttributeAnnotator " + "-- --" + type.parameter_prefix + "-accession " + accession + " --key " + funky_key + " --value " + funky_initial_value; ITUtility.runSeqWareJar(listCommand, ReturnValue.SUCCESS, null); String query = "SELECT t2." + type.table_name + "_attribute_id, t2.tag, t2.value FROM " + type.table_name + "_attribute t2, " + type.table_name + " t1 WHERE " + "t1." + type.table_name + "_id=t2." + type.attribute_id_prefix + "_id AND t1.sw_accession=? ORDER BY " + type.table_name + "_attribute_id"; Log.info(query); List<Object[]> runQuery = dbCreator.runQuery(new ArrayListHandler(), query, accession); Assert.assertTrue("first annotation incorrect", runQuery.size() == 1); Assert.assertTrue("first tag incorrect", runQuery.get(0)[1].equals(funky_key)); Assert.assertTrue("first value incorrect", runQuery.get(0)[2].equals(funky_initial_value)); // count records in the database to check for cascading deletes List<Object[]> count1 = dbCreator.runQuery(new ArrayListHandler(), COUNT_DB_SIZE); // reannotate with same key, different value listCommand = "-p net.sourceforge.seqware.pipeline.plugins.AttributeAnnotator " + "-- --" + type.parameter_prefix + "-accession " + accession + " --key " + funky_key + " --value " + funky_second_value; ITUtility.runSeqWareJar(listCommand, ReturnValue.SUCCESS, null); // ensure that duplicates are not formed in the database runQuery = dbCreator.runQuery(new ArrayListHandler(), query, accession); Assert.assertTrue("incorrect resulting number of duplicate annotations, found " + runQuery.size(), runQuery.size() == 1); Assert.assertTrue("second tag incorrect", runQuery.get(0)[1].equals(funky_key)); Assert.assertTrue("second value incorrect", runQuery.get(0)[2].equals(funky_second_value)); // check against cascading deletes List<Object[]> count2 = dbCreator.runQuery(new ArrayListHandler(), COUNT_DB_SIZE); compareTwoCounts(count1.get(0), count2.get(0)); // try unrelated annotation listCommand = "-p net.sourceforge.seqware.pipeline.plugins.AttributeAnnotator " + "-- --" + type.parameter_prefix + "-accession " + accession + " --key " + groovy_key + " --value " + groovy_value; ITUtility.runSeqWareJar(listCommand, ReturnValue.SUCCESS, null); // check results of unrelated annotation runQuery = dbCreator.runQuery(new ArrayListHandler(), query, accession); Assert.assertTrue("incorrect resulting number of unrelated annotations, found: " + runQuery.size(), runQuery.size() == 2); Assert.assertTrue("second tag incorrect", runQuery.get(0)[1].equals(funky_key)); Assert.assertTrue("second value incorrect", runQuery.get(0)[2].equals(funky_second_value)); Assert.assertTrue("third tag incorrect", runQuery.get(1)[1].equals(groovy_key)); Assert.assertTrue("third value incorrect", runQuery.get(1)[2].equals(groovy_value)); List<Object[]> count3 = dbCreator.runQuery(new ArrayListHandler(), COUNT_DB_SIZE); compareTwoCounts(count2.get(0), count3.get(0)); }
From source file:net.sourceforge.seqware.pipeline.plugins.checkdb.plugins.WorkflowRunConventionsPlugin.java
@Override public void check(SelectQueryRunner qRunner, SortedMap<Level, Set<String>> result) throws SQLException { try {//from w ww. j a va 2 s .c om /** * May not be true for downsteam workflow runs * List<Integer> executeQuery = qRunner.executeQuery("select sw_accession from workflow_run WHERE workflow_run_id NOT IN (select workflow_run_id FROM ius_workflow_runs);", new ColumnListHandler<Integer>()); * CheckDB.processOutput(result, Level.TRIVIAL, "Workflow runs not connected to an IUS via ius_workflow_runs: " , executeQuery); **/ // workflow runs not connected to a study String query = IOUtils.toString( AttributePlugin.class.getResourceAsStream("workflow_runs_not_connected_to_study.sql")); List<Object[]> workflow_run_study_pairs = qRunner.executeQuery(query, new ArrayListHandler()); List<Integer> unreachableByStudy = new ArrayList<>(); // number studies -> workflow runs SortedMap<Integer, SortedSet<Integer>> reachableByMultipleStudies = new TreeMap<>(); for (Object[] pair : workflow_run_study_pairs) { int studyCount = Integer.valueOf(pair[1].toString()); if (pair[0] == null) { continue; } int sw_accession = Integer.valueOf(pair[0].toString()); if (studyCount == 0) { unreachableByStudy.add(sw_accession); } else if (studyCount > 1) { if (!reachableByMultipleStudies.containsKey(studyCount)) { reachableByMultipleStudies.put(studyCount, new TreeSet<Integer>()); } reachableByMultipleStudies.get(studyCount).add(sw_accession); } } CheckDB.processOutput(result, Level.SEVERE, "'Completed' Workflow runs not reachable by studies: ", unreachableByStudy); // workflow runs connected to more than one study if (reachableByMultipleStudies.size() > 0) { for (Entry<Integer, SortedSet<Integer>> e : reachableByMultipleStudies.entrySet()) { CheckDB.processOutput(result, Level.WARNING, "'Completed' Workflow runs reachable by " + e.getKey() + " studies: ", new ArrayList<>(e.getValue())); } } query = IOUtils.toString( AttributePlugin.class.getResourceAsStream("workflow_runs_not_connected_in_hierarchy.sql")); List<Integer> executeQuery = qRunner.executeQuery(query, new ColumnListHandler<Integer>()); CheckDB.processOutput(result, Level.SEVERE, "'Completed' Workflow runs reachable by ius_workflow_runs but not via the processing_hierarchy: ", executeQuery); query = IOUtils.toString(AttributePlugin.class.getResourceAsStream("new_input_files_versus_old.sql")); executeQuery = qRunner.executeQuery(query, new ColumnListHandler<Integer>()); CheckDB.processOutput(result, Level.TRIVIAL, "Workflow runs with input files via workflow_run_input_files but not via the processing hierarchy: ", executeQuery); query = IOUtils.toString(AttributePlugin.class.getResourceAsStream("old_input_files_versus_new.sql")); executeQuery = qRunner.executeQuery(query, new ColumnListHandler<Integer>()); CheckDB.processOutput(result, Level.TRIVIAL, "Workflow runs with input files via the processing hierarchy but not via workflow_run_input_files: ", executeQuery); } catch (IOException ex) { throw new RuntimeException(ex); } }
From source file:net.sourceforge.seqware.pipeline.plugins.FileLinkerTest.java
@Test public void testFileLinkerNormal() { String path = FileLinkerTest.class.getResource("file_linker_test.txt").getPath(); launchPlugin("--workflow-accession", "4", "--file-list-file", path); String s = getOut();//from ww w . j av a2 s .c o m String firstWorkflowRun = getAndCheckSwid(s); BasicTestDatabaseCreator dbCreator = new BasicTestDatabaseCreator(); List<Object[]> runQuery = dbCreator.runQuery(new ArrayListHandler(), "select f.file_path, f.meta_type, i.sw_accession from workflow_run r, processing p, processing_files pf, file f, processing_ius pi, ius i\n" + "WHERE \n" + "r.sw_accession = ?\n" + "AND p.workflow_run_id = r.workflow_run_id\n" + "AND p.processing_id = pf.processing_id\n" + "AND pf.file_id = f.file_id\n" + "AND p.processing_id = pi.processing_id \n" + "AND pi.ius_id = i.ius_id\n" + "ORDER BY f.sw_accession\n" + "; ", Integer.valueOf(firstWorkflowRun)); Assert.assertTrue("first file values were incorrect", runQuery.get(0)[0].equals("funky_file1.gz") && runQuery.get(0)[1].equals("txt")); Assert.assertTrue("second file values were incorrect", runQuery.get(1)[0].equals("funky_file2.gz") && runQuery.get(1)[1].equals("txt")); Assert.assertTrue("ius links were correct", runQuery.get(0)[2].equals(4765) && runQuery.get(1)[2].equals(4765)); // check that we can get them back via metadata methods as well WorkflowRun workflowRun = metadata.getWorkflowRunWithWorkflow(firstWorkflowRun); Assert.assertTrue("could not retrieve optional fields via metadata", workflowRun.getSwAccession().equals(Integer.valueOf(firstWorkflowRun))); Assert.assertTrue("parent workflow incorrect", workflowRun.getWorkflow().getSwAccession() == 4); String workflowRunReport = metadata.getWorkflowRunReport(Integer.valueOf(firstWorkflowRun)); // look for files using the gross metadata way Assert.assertTrue("files could not be found using the metadata workflow run report", workflowRunReport.contains("funky_file1.gz") && workflowRunReport.contains("funky_file2.gz")); s = s.split("\n")[1]; int secondWorkflowRun = Integer.valueOf(getAndCheckSwid(s)); workflowRunReport = metadata.getWorkflowRunReport(secondWorkflowRun); Assert.assertTrue("second set of files could not be found using the metadata workflow run report", workflowRunReport.contains("abc1.gz") && workflowRunReport.contains("abc2.gz")); }