Package net.sf.nfp.mini.dao

Examples of net.sf.nfp.mini.dao.PeriodDAO


   * 0 - period number 1 - period day 2 - date & time 3 - temperature 4 -
   * mucus category 5 - mucus description 6 - is bleeding 7 - is disturbed
   */
  public void exportToCSV(OutputStream stream, NFPControler controler) throws IOException, RecordStoreException {
    PrintStream writer = new PrintStream(stream);
    PeriodDAO periodDAO = controler.getPeriodDAO();
    ObservationDAO observationDAO = controler.getObservationDAO();
    try {
      String[] header = {
        "${csv.period}",
        "${csv.observation}",
        "${csv.date}",
        "${csv.temperature}",
        "${csv.mucus.id}",
        "${csv.mucus.category}",
        "${csv.mucus.description}",
        "${csv.bleeding}",
        "${csv.disturbed}"
      };
      for(int i=0;i<header.length;++i) {
        writer.print('"');
        writer.print(header[i]);
        writer.print('"');
        if(i < header.length - 1)
          writer.print(',');
      }
      writer.println();
      Vector periods = periodDAO.findAll();
      controler.progressListner.setMaxValue(periods.size() * 100);
      for (int i = 0; i < periods.size(); ++i) {
        Period period = (Period) periods.elementAt(i);
        Vector ids = periodDAO.getObservationIds(period);
        for (int j = 0; j < ids.size(); ++j) {
          controler.progressListner.setValue(i * 100 + (j * 100 / ids.size()));
          Integer id = (Integer) ids.elementAt(j);
          Observation ob = observationDAO.find(id.intValue());
          if (ob == null)
View Full Code Here


   */ 
  public void importFromCSV(InputStream stream, long size, NFPControler controler) throws Exception {   
    Log.log("Exporter.importFromCSV() "+stream.available());
    InputStreamReader reader = new InputStreamReader(stream);
    Log.log("Exporter.importFromCSV() "+stream.available());
    PeriodDAO periodDAO = controler.getPeriodDAO();
    ObservationDAO observationDAO = controler.getObservationDAO();
    Period period = null;
    controler.progressListner.setMaxValue((int) size);
    long left = size;
    try {
      left -= readLine(reader).length(); // read CSV header
      periodDAO.deleteAll();
      observationDAO.deleteAll();
      String currentPeriod = null;
      String[] fields = new String[10];
      for (int lineNo = 1;; ++lineNo) {
        StringBuffer line = readLine(reader);
        if (line == null)
          break;
        left -= line.length();
        for (int i = 0; i < fields.length; ++i)
          fields[i] = grabField(line);
        if (!fields[0].equals(currentPeriod)) {
          if (period != null)
            periodDAO.persist(period);
          period = new Period();
          currentPeriod = fields[0];
        }
        Observation observation = new Observation(
            parseCSVDate(fields[2]),
            parseCSVTemperature(fields[3]),
            MucusRegistry.instance().find(Integer.parseInt(fields[4])),
            parseCSVBoolean(fields[7]),
            parseCSVBoolean(fields[8]),
            fields[9]);
       
        LogicDAO.addObservationToPeriod(observation, new Period[]{period}, controler);
        controler.progressListner.setValue((int) (size - left));
      }
    } finally {
      reader.close();
      stream.close();
    }
    if(period != null)
      periodDAO.setCurrent(period);
  }
View Full Code Here

    Object[] params = (Object[]) parameter;
    period = (Period) params[0];
    if (period == null)
      return;
   
    final PeriodDAO periodDAO = controler.getPeriodDAO();
    final ObservationDAO observationDAO = controler.getObservationDAO();
   
    int days = Utils.getDaysBetween(period.getStart(), period.getEnd());
    Vector ids = periodDAO.getObservationIds(period);
    Vector observations = new Vector(days);
    observations.setSize(days + 1);
    controler.progressListner.setMaxValue(ids.size());
    for (int i1 = 0; i1 < ids.size(); ++i1) {
      int id = ((Integer) ids.elementAt(i1)).intValue();
View Full Code Here

  }

  private Observation getObservationAt(Date date) throws RecordStoreException, IOException {
    System.out.println("InputModel.getObservationAt("+date+")");
   
    final PeriodDAO periodDAO = controler.getPeriodDAO();
    final ObservationDAO observationDAO = controler.getObservationDAO();

    if(period == null)
      return null;
    if (date.getTime() < period.getStart().getTime())
      return null;
    if (date.getTime() > period.getEnd().getTime())
      return null;
    Vector ids = periodDAO.getObservationIds(period);
    controler.progressListner.setMaxValue(ids.size());
    for (int i = 0; i < ids.size(); ++i) {
      int id = ((Integer) ids.elementAt(i)).intValue();
      Observation o = observationDAO.find(id);
      if (Utils.equals(date, o.getDate()))
View Full Code Here

  }
 

  private boolean isBleeingContinuation(Period period, Observation observation) throws RecordStoreException, IOException {
    Log.log("SaveObservationModel.isBleeingContinuation("+period+","+observation+")");
    final PeriodDAO periodDAO = controler.getPeriodDAO();
    final ObservationDAO observationDAO = controler.getObservationDAO();
    Vector ids = periodDAO.getObservationIds(period);
    for(int i=0;i<ids.size();++i) {
      Integer id = (Integer) ids.elementAt(i);
      Observation o = observationDAO.find(id.intValue());
      if(o.isBleeding() == false)
        if(o.getDate().getTime() < observation.getDate().getTime())
View Full Code Here

      }
    });
  }

  public PeriodDAO getPeriodDAO() {
    return periodDAO == null ? (periodDAO = new PeriodDAO()) : periodDAO;
  }
View Full Code Here

TOP

Related Classes of net.sf.nfp.mini.dao.PeriodDAO

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.