author | František Kučera <franta-hg@frantovo.cz> |
Sun Feb 15 22:24:37 2009 +0100 (2009-02-15) | |
changeset 30 | 0ffc8c1b2b9c |
parent 26 | feb4c3774c42 |
child 40 | fd29fd5a8e29 |
permissions | -rw-r--r-- |
franta-hg@3 | 1 |
package cz.frantovo.hrisniciSpameri; |
franta-hg@3 | 2 |
|
franta-hg@6 | 3 |
import cz.frantovo.hrisniciSpameri.dao.CilDAO; |
franta-hg@21 | 4 |
import cz.frantovo.hrisniciSpameri.dao.SouhrnDAO; |
franta-hg@4 | 5 |
import cz.frantovo.hrisniciSpameri.dto.Cil; |
franta-hg@4 | 6 |
import cz.frantovo.hrisniciSpameri.dto.Souhrn; |
franta-hg@3 | 7 |
import java.io.Serializable; |
franta-hg@4 | 8 |
import java.sql.Date; |
franta-hg@4 | 9 |
import java.text.DateFormat; |
franta-hg@4 | 10 |
import java.text.ParseException; |
franta-hg@4 | 11 |
import java.text.SimpleDateFormat; |
franta-hg@30 | 12 |
import java.util.Calendar; |
franta-hg@4 | 13 |
import java.util.Collection; |
franta-hg@4 | 14 |
import java.util.logging.Level; |
franta-hg@4 | 15 |
import java.util.logging.Logger; |
franta-hg@3 | 16 |
|
franta-hg@3 | 17 |
/** |
franta-hg@4 | 18 |
* Beana zprostředkovávající denní souhrn hříšníků. |
franta-hg@3 | 19 |
* @author fiki |
franta-hg@3 | 20 |
*/ |
franta-hg@3 | 21 |
public class DenniSouhrn implements Serializable { |
franta-hg@3 | 22 |
|
franta-hg@3 | 23 |
private static final long serialVersionUID = 7932392366943861342L; |
franta-hg@4 | 24 |
private static final Logger log = Logger.getLogger(DenniSouhrn.class.getName()); |
franta-hg@20 | 25 |
private static String formatDataVzor = "yyyy-MM-dd"; |
franta-hg@4 | 26 |
public static DateFormat formatData = new SimpleDateFormat(formatDataVzor); |
franta-hg@26 | 27 |
private Date zacatek; |
franta-hg@26 | 28 |
private Date konec; |
franta-hg@20 | 29 |
private int cil; |
franta-hg@20 | 30 |
|
franta-hg@26 | 31 |
public String getZacatekString() { |
franta-hg@26 | 32 |
return formatData.format(getZacatek()); |
franta-hg@20 | 33 |
} |
franta-hg@4 | 34 |
|
franta-hg@26 | 35 |
public Date getZacatek() { |
franta-hg@26 | 36 |
if (zacatek == null) { |
franta-hg@26 | 37 |
nastavVychoziZacatek(); |
franta-hg@20 | 38 |
} |
franta-hg@26 | 39 |
return zacatek; |
franta-hg@4 | 40 |
} |
franta-hg@4 | 41 |
|
franta-hg@26 | 42 |
public void setZacatek(Date zacatek) { |
franta-hg@26 | 43 |
if (zacatek == null) { |
franta-hg@26 | 44 |
nastavVychoziZacatek(); |
franta-hg@4 | 45 |
} else { |
franta-hg@26 | 46 |
this.zacatek = zacatek; |
franta-hg@4 | 47 |
} |
franta-hg@26 | 48 |
log.log(Level.FINE, "Začátek nastaven na: " + formatData.format(zacatek)); |
franta-hg@4 | 49 |
} |
franta-hg@4 | 50 |
|
franta-hg@26 | 51 |
public void setZacatekString(String zacatek) { |
franta-hg@26 | 52 |
if (zacatek == null) { |
franta-hg@26 | 53 |
nastavVychoziZacatek(); |
franta-hg@30 | 54 |
} else { |
franta-hg@30 | 55 |
try { |
franta-hg@30 | 56 |
this.zacatek = new Date(formatData.parse(zacatek).getTime()); |
franta-hg@30 | 57 |
} catch (ParseException e) { |
franta-hg@30 | 58 |
log.log(Level.FINE, "Chybně zadané datum – začátek: " + zacatek, e); |
franta-hg@30 | 59 |
nastavVychoziZacatek(); |
franta-hg@30 | 60 |
} |
franta-hg@26 | 61 |
} |
franta-hg@26 | 62 |
} |
franta-hg@26 | 63 |
|
franta-hg@26 | 64 |
public Date getKonec() { |
franta-hg@30 | 65 |
if (konec == null) { |
franta-hg@30 | 66 |
nastavVychoziKonec(); |
franta-hg@30 | 67 |
} |
franta-hg@26 | 68 |
return konec; |
franta-hg@26 | 69 |
} |
franta-hg@26 | 70 |
|
franta-hg@26 | 71 |
public void setKonec(Date konec) { |
franta-hg@30 | 72 |
if (konec == null) { |
franta-hg@30 | 73 |
nastavVychoziKonec(); |
franta-hg@30 | 74 |
} else { |
franta-hg@30 | 75 |
this.konec = konec; |
franta-hg@30 | 76 |
} |
franta-hg@30 | 77 |
log.log(Level.FINE, "Konec nastaven na: " + formatData.format(zacatek)); |
franta-hg@26 | 78 |
} |
franta-hg@26 | 79 |
|
franta-hg@26 | 80 |
public void setKonecString(String konec) { |
franta-hg@30 | 81 |
if (konec == null) { |
franta-hg@30 | 82 |
nastavVychoziKonec(); |
franta-hg@30 | 83 |
} else { |
franta-hg@30 | 84 |
try { |
franta-hg@30 | 85 |
this.konec = new Date(formatData.parse(konec).getTime()); |
franta-hg@30 | 86 |
} catch (Exception e) { |
franta-hg@30 | 87 |
nastavVychoziKonec(); |
franta-hg@30 | 88 |
} |
franta-hg@4 | 89 |
} |
franta-hg@4 | 90 |
} |
franta-hg@4 | 91 |
|
franta-hg@20 | 92 |
public void setCilString(String cil) { |
franta-hg@20 | 93 |
try { |
franta-hg@20 | 94 |
this.cil = Integer.parseInt(cil); |
franta-hg@20 | 95 |
} catch (Exception e) { |
franta-hg@20 | 96 |
this.cil = 0; |
franta-hg@20 | 97 |
} |
franta-hg@20 | 98 |
} |
franta-hg@20 | 99 |
|
franta-hg@20 | 100 |
public void setCil(int cil) { |
franta-hg@20 | 101 |
this.cil = cil; |
franta-hg@20 | 102 |
} |
franta-hg@20 | 103 |
|
franta-hg@20 | 104 |
public String getCilString() { |
franta-hg@20 | 105 |
return String.valueOf(cil); |
franta-hg@20 | 106 |
} |
franta-hg@20 | 107 |
|
franta-hg@20 | 108 |
public int getCil() { |
franta-hg@20 | 109 |
return cil; |
franta-hg@20 | 110 |
} |
franta-hg@20 | 111 |
|
franta-hg@26 | 112 |
private void nastavVychoziZacatek() { |
franta-hg@26 | 113 |
log.log(Level.FINE, "Nastavuji začátek na výchozí hodnotu."); |
franta-hg@30 | 114 |
setZacatek(getVychoziZacatek()); |
franta-hg@30 | 115 |
} |
franta-hg@30 | 116 |
|
franta-hg@30 | 117 |
private void nastavVychoziKonec() { |
franta-hg@30 | 118 |
log.log(Level.FINE, "Nastavuji konec na výchozí hodnotu."); |
franta-hg@30 | 119 |
setKonec(getVychoziKonec()); |
franta-hg@4 | 120 |
} |
franta-hg@4 | 121 |
|
franta-hg@4 | 122 |
public Collection<Souhrn> getSouhrn() { |
franta-hg@26 | 123 |
Collection<Souhrn> souhrn = new SouhrnDAO().getSouhrn(zacatek, konec, cil); |
franta-hg@4 | 124 |
|
franta-hg@21 | 125 |
/** ne všechno musíme posílat do JSP vrstvy */ |
franta-hg@21 | 126 |
for (Souhrn s : souhrn) { |
franta-hg@21 | 127 |
s.getCil().setDatabaze(null); |
franta-hg@21 | 128 |
s.getCil().setSelekt(null); |
franta-hg@4 | 129 |
} |
franta-hg@4 | 130 |
|
franta-hg@4 | 131 |
return souhrn; |
franta-hg@4 | 132 |
} |
franta-hg@6 | 133 |
|
franta-hg@6 | 134 |
/** |
franta-hg@6 | 135 |
* @return Seznam všech cílů. Ale bez těchto hodnot: databáze a selekt. |
franta-hg@6 | 136 |
*/ |
franta-hg@6 | 137 |
public Collection<Cil> getSeznamCilu() { |
franta-hg@6 | 138 |
Collection<Cil> cile = new CilDAO().getCile(); |
franta-hg@6 | 139 |
|
franta-hg@6 | 140 |
/** ne všechno musíme posílat do JSP vrstvy */ |
franta-hg@6 | 141 |
for (Cil c : cile) { |
franta-hg@6 | 142 |
c.setDatabaze(null); |
franta-hg@6 | 143 |
c.setSelekt(null); |
franta-hg@6 | 144 |
} |
franta-hg@6 | 145 |
|
franta-hg@6 | 146 |
return cile; |
franta-hg@6 | 147 |
} |
franta-hg@30 | 148 |
|
franta-hg@30 | 149 |
/** |
franta-hg@30 | 150 |
* @return Výchozí začátek je před měsícem |
franta-hg@30 | 151 |
*/ |
franta-hg@30 | 152 |
private static Date getVychoziZacatek() { |
franta-hg@30 | 153 |
Calendar c = Calendar.getInstance(); |
franta-hg@30 | 154 |
c.add(Calendar.MONTH, -1); |
franta-hg@30 | 155 |
return new Date(c.getTimeInMillis()); |
franta-hg@30 | 156 |
} |
franta-hg@30 | 157 |
|
franta-hg@30 | 158 |
/** |
franta-hg@30 | 159 |
* @return Výchozí konec je současnost |
franta-hg@30 | 160 |
*/ |
franta-hg@30 | 161 |
private static Date getVychoziKonec() { |
franta-hg@30 | 162 |
return new Date(System.currentTimeMillis()); |
franta-hg@30 | 163 |
} |
franta-hg@3 | 164 |
} |