java/HrisniciSpameri/src/java/cz/frantovo/hrisniciSpameri/DenniSouhrn.java
author František Kučera <franta-hg@frantovo.cz>
Sat Feb 14 19:31:33 2009 +0100 (2009-02-14)
changeset 23 b22c06c8a55c
parent 21 2bc6c427894d
child 26 feb4c3774c42
permissions -rw-r--r--
Generátor generuje souhrny i překládá IP adresy na domény
     1 package cz.frantovo.hrisniciSpameri;
     2 
     3 import cz.frantovo.hrisniciSpameri.dao.CilDAO;
     4 import cz.frantovo.hrisniciSpameri.dao.SouhrnDAO;
     5 import cz.frantovo.hrisniciSpameri.dto.Cil;
     6 import cz.frantovo.hrisniciSpameri.dto.Souhrn;
     7 import java.io.Serializable;
     8 import java.sql.Date;
     9 import java.text.DateFormat;
    10 import java.text.ParseException;
    11 import java.text.SimpleDateFormat;
    12 import java.util.Collection;
    13 import java.util.logging.Level;
    14 import java.util.logging.Logger;
    15 
    16 /**
    17  * Beana zprostředkovávající denní souhrn hříšníků.
    18  * @author fiki
    19  */
    20 public class DenniSouhrn implements Serializable {
    21 
    22     private static final long serialVersionUID = 7932392366943861342L;
    23     private static final Logger log = Logger.getLogger(DenniSouhrn.class.getName());
    24     private static String formatDataVzor = "yyyy-MM-dd";
    25     public static DateFormat formatData = new SimpleDateFormat(formatDataVzor);
    26     private Date den;
    27     private int cil;
    28 
    29     public String getDenString() {
    30         return formatData.format(getDen());
    31     }
    32 
    33     public Date getDen() {
    34         if (den == null) {
    35             nastavVychoziDen();
    36         }
    37         return den;
    38     }
    39 
    40     public void setDen(Date den) {
    41         if (den == null) {
    42             nastavVychoziDen();
    43         } else {
    44             this.den = den;
    45         }
    46         log.log(Level.FINE, "Den nastaven na: " + formatData.format(den));
    47     }
    48 
    49     public void setDenString(String den) {
    50         if (den == null) {
    51             nastavVychoziDen();
    52         }
    53 
    54         try {
    55             this.den = new Date(formatData.parse(den).getTime());
    56         } catch (ParseException e) {
    57             log.log(Level.FINE, "Chybně zadané datum: " + den, e);
    58             nastavVychoziDen();
    59         }
    60     }
    61 
    62     public void setCilString(String cil) {
    63         try {
    64             this.cil = Integer.parseInt(cil);
    65         } catch (Exception e) {
    66             this.cil = 0;
    67         }
    68     }
    69 
    70     public void setCil(int cil) {
    71         this.cil = cil;
    72     }
    73 
    74     public String getCilString() {
    75         return String.valueOf(cil);
    76     }
    77 
    78     public int getCil() {
    79         return cil;
    80     }
    81 
    82     private void nastavVychoziDen() {
    83         log.log(Level.FINE, "Nastavuji den na výchozí hodnotu.");
    84         setDen(SouhrnDAO.getVychoziDen());
    85     }
    86 
    87     public Collection<Souhrn> getSouhrn() {
    88         Collection<Souhrn> souhrn = new SouhrnDAO().getSouhrn(den, null, cil);
    89 
    90         /** ne všechno musíme posílat do JSP vrstvy */
    91         for (Souhrn s : souhrn) {
    92             s.getCil().setDatabaze(null);
    93             s.getCil().setSelekt(null);
    94         }
    95 
    96         return souhrn;
    97     }
    98 
    99     /**
   100      * @return Seznam všech cílů. Ale bez těchto hodnot: databáze a selekt.
   101      */
   102     public Collection<Cil> getSeznamCilu() {
   103         Collection<Cil> cile = new CilDAO().getCile();
   104 
   105         /** ne všechno musíme posílat do JSP vrstvy */
   106         for (Cil c : cile) {
   107             c.setDatabaze(null);
   108             c.setSelekt(null);
   109         }
   110 
   111         return cile;
   112     }
   113 }