Package org.molgenis.io.csv

Examples of org.molgenis.io.csv.CsvWriter


  }

  @Override
  public void export(OutputStream os) throws IOException, TableException
  {
    CsvWriter csvWriter = new CsvWriter(os);

    // save table state
    int colOffset = tupleTable.getColOffset();
    int colLimit = tupleTable.getColLimit();
    int rowOffset = tupleTable.getOffset();
    int rowLimit = tupleTable.getLimit();

    // update table state
    tupleTable.setColOffset(0);
    tupleTable.setColLimit(0);
    tupleTable.setOffset(0);
    tupleTable.setLimit(0);

    try
    {
      csvWriter.writeColNames(new FieldHeaderTuple(tupleTable.getColumns()).getColNames());
      for (Tuple row : tupleTable)
        csvWriter.write(row);
    }
    finally
    {
      IOUtils.closeQuietly(csvWriter);
View Full Code Here


    {
      int nRowsChanged = 0;
      if (action.equals("ADD"))
      {
        File temp = File.createTempFile("molgenis", "tab");
        CsvWriter csvWriter = new CsvWriter(temp);
        try
        {
          if (req.get(INPUT_SILENT) != null && req.getBoolean(INPUT_SILENT) == true)
          {
            csvWriter.close();
            csvWriter = null;
          }

          if (req.get(INPUT_DATA) != null)
          {
            logger.info("processing textarea upload...");
            nRowsChanged = db.add(entityClass, csvReader, csvWriter);
          }
          else if (req.get(INPUT_FILE) != null)
          {
            logger.info("processing file upload...");
            nRowsChanged = db.add(entityClass, csvReader, csvWriter);
          }
          else
          {
            logger.error("no input data or input file provided.");
            out.print("ERROR: no input data or input file provided.");
          }
          out.print("Uploaded " + formatter.format(nRowsChanged) + " rows of "
              + entityClass.getCanonicalName() + "\n");
        }
        finally
        {
          if (csvWriter != null) csvWriter.close();
        }
        BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(temp),
            Charset.forName("UTF-8")));
        try
        {
View Full Code Here

      throws Exception
  {
    FormModel<?> view = this.getFormScreen();
    List<String> fieldsToExport = ((FormController<?>) this.getController()).getVisibleColumnNames();

    CsvWriter csvWriter = new CsvWriter(csvDownload);

    try
    {
      csvWriter.writeColNames(fieldsToExport);

      for (Entity e : view.getRecords())
        csvWriter.write(new EntityTuple(e));
    }
    finally
    {
      csvWriter.close();
    }

    return ScreenModel.Show.SHOW_MAIN;
  }
View Full Code Here

            out.println(db.count(getClassForName(entityName)));
          }
        }
        else
        {
          TupleWriter csvWriter = new CsvWriter(out);
          try
          {
            if (rulesList != null) db.find(getClassForName(entityName), csvWriter,
                rulesList.toArray(new QueryRule[rulesList.size()]));
            else
            {
              db.find(getClassForName(entityName), csvWriter);
            }
          }
          finally
          {
            csvWriter.close();
          }
        }
      }
      catch (Exception e)
      {
View Full Code Here

    }

    List<String> fieldsToExport = ((FormController<?>) this.getController()).getVisibleColumnNames();

    // watch out, the "IN" operator expects an Object[]
    CsvWriter csvWriter = new CsvWriter(csvDownload);
    try
    {
      db.find(view.getController().getEntityClass(), csvWriter, fieldsToExport, new QueryRule("id", Operator.IN,
          records));
    }
    finally
    {
      csvWriter.close();
    }
    return ScreenModel.Show.SHOW_MAIN;
  }
View Full Code Here

    List<String> fieldsToExport = controller.getVisibleColumnNames();

    // TODO remove entity name, capitals to small , and remove _name fields
    QueryRule[] rules = model.getRulesExclLimitOffset();
    CsvWriter csvWriter = new CsvWriter(csvDownload);
    try
    {
      db.find(model.getController().getEntityClass(), csvWriter, fieldsToExport, rules);
    }
    finally
    {
      csvWriter.close();
    }

    return ScreenModel.Show.SHOW_MAIN;
  }
View Full Code Here

    // create query rules
    List<QueryRule> rulesList = createQueryRules(req, klazz);

    // execute query
    TupleWriter csvWriter = new CsvWriter(out);
    try
    {
      db.find(klazz, csvWriter, rulesList.toArray(new QueryRule[rulesList.size()]));
    }
    finally
    {
      csvWriter.close();
    }
  }
View Full Code Here

TOP

Related Classes of org.molgenis.io.csv.CsvWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.