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@40
|
6 |
import cz.frantovo.hrisniciSpameri.dto.Soucet;
|
franta-hg@4
|
7 |
import cz.frantovo.hrisniciSpameri.dto.Souhrn;
|
franta-hg@3
|
8 |
import java.io.Serializable;
|
franta-hg@4
|
9 |
import java.sql.Date;
|
franta-hg@4
|
10 |
import java.text.DateFormat;
|
franta-hg@4
|
11 |
import java.text.ParseException;
|
franta-hg@4
|
12 |
import java.text.SimpleDateFormat;
|
franta-hg@30
|
13 |
import java.util.Calendar;
|
franta-hg@4
|
14 |
import java.util.Collection;
|
franta-hg@40
|
15 |
import java.util.HashMap;
|
franta-hg@4
|
16 |
import java.util.logging.Level;
|
franta-hg@4
|
17 |
import java.util.logging.Logger;
|
franta-hg@3
|
18 |
|
franta-hg@3
|
19 |
/**
|
franta-hg@4
|
20 |
* Beana zprostředkovávající denní souhrn hříšníků.
|
franta-hg@3
|
21 |
* @author fiki
|
franta-hg@3
|
22 |
*/
|
franta-hg@3
|
23 |
public class DenniSouhrn implements Serializable {
|
franta-hg@3
|
24 |
|
franta-hg@3
|
25 |
private static final long serialVersionUID = 7932392366943861342L;
|
franta-hg@4
|
26 |
private static final Logger log = Logger.getLogger(DenniSouhrn.class.getName());
|
franta-hg@20
|
27 |
private static String formatDataVzor = "yyyy-MM-dd";
|
franta-hg@47
|
28 |
public DateFormat formatData = new SimpleDateFormat(formatDataVzor);
|
franta-hg@26
|
29 |
private Date zacatek;
|
franta-hg@26
|
30 |
private Date konec;
|
franta-hg@20
|
31 |
private int cil;
|
franta-hg@20
|
32 |
|
franta-hg@26
|
33 |
public String getZacatekString() {
|
franta-hg@47
|
34 |
return formatData.format(getZacatek());
|
franta-hg@20
|
35 |
}
|
franta-hg@4
|
36 |
|
franta-hg@26
|
37 |
public Date getZacatek() {
|
franta-hg@26
|
38 |
if (zacatek == null) {
|
franta-hg@26
|
39 |
nastavVychoziZacatek();
|
franta-hg@20
|
40 |
}
|
franta-hg@26
|
41 |
return zacatek;
|
franta-hg@4
|
42 |
}
|
franta-hg@4
|
43 |
|
franta-hg@26
|
44 |
public void setZacatek(Date zacatek) {
|
franta-hg@26
|
45 |
if (zacatek == null) {
|
franta-hg@26
|
46 |
nastavVychoziZacatek();
|
franta-hg@4
|
47 |
} else {
|
franta-hg@26
|
48 |
this.zacatek = zacatek;
|
franta-hg@4
|
49 |
}
|
franta-hg@47
|
50 |
log.log(Level.FINE, "Začátek nastaven na: " + formatData.format(zacatek));
|
franta-hg@4
|
51 |
}
|
franta-hg@4
|
52 |
|
franta-hg@26
|
53 |
public void setZacatekString(String zacatek) {
|
franta-hg@26
|
54 |
if (zacatek == null) {
|
franta-hg@26
|
55 |
nastavVychoziZacatek();
|
franta-hg@30
|
56 |
} else {
|
franta-hg@30
|
57 |
try {
|
franta-hg@47
|
58 |
this.zacatek = new Date(formatData.parse(zacatek).getTime());
|
franta-hg@30
|
59 |
} catch (ParseException e) {
|
franta-hg@30
|
60 |
log.log(Level.FINE, "Chybně zadané datum – začátek: " + zacatek, e);
|
franta-hg@30
|
61 |
nastavVychoziZacatek();
|
franta-hg@30
|
62 |
}
|
franta-hg@26
|
63 |
}
|
franta-hg@26
|
64 |
}
|
franta-hg@26
|
65 |
|
franta-hg@26
|
66 |
public Date getKonec() {
|
franta-hg@30
|
67 |
if (konec == null) {
|
franta-hg@30
|
68 |
nastavVychoziKonec();
|
franta-hg@30
|
69 |
}
|
franta-hg@26
|
70 |
return konec;
|
franta-hg@26
|
71 |
}
|
franta-hg@26
|
72 |
|
franta-hg@26
|
73 |
public void setKonec(Date konec) {
|
franta-hg@30
|
74 |
if (konec == null) {
|
franta-hg@30
|
75 |
nastavVychoziKonec();
|
franta-hg@30
|
76 |
} else {
|
franta-hg@30
|
77 |
this.konec = konec;
|
franta-hg@30
|
78 |
}
|
franta-hg@47
|
79 |
log.log(Level.FINE, "Konec nastaven na: " + formatData.format(zacatek));
|
franta-hg@26
|
80 |
}
|
franta-hg@26
|
81 |
|
franta-hg@26
|
82 |
public void setKonecString(String konec) {
|
franta-hg@30
|
83 |
if (konec == null) {
|
franta-hg@30
|
84 |
nastavVychoziKonec();
|
franta-hg@30
|
85 |
} else {
|
franta-hg@30
|
86 |
try {
|
franta-hg@47
|
87 |
this.konec = new Date(formatData.parse(konec).getTime());
|
franta-hg@30
|
88 |
} catch (Exception e) {
|
franta-hg@30
|
89 |
nastavVychoziKonec();
|
franta-hg@30
|
90 |
}
|
franta-hg@4
|
91 |
}
|
franta-hg@4
|
92 |
}
|
franta-hg@4
|
93 |
|
franta-hg@40
|
94 |
public String getKonecString() {
|
franta-hg@47
|
95 |
return formatData.format(getKonec());
|
franta-hg@40
|
96 |
}
|
franta-hg@40
|
97 |
|
franta-hg@20
|
98 |
public void setCilString(String cil) {
|
franta-hg@20
|
99 |
try {
|
franta-hg@20
|
100 |
this.cil = Integer.parseInt(cil);
|
franta-hg@20
|
101 |
} catch (Exception e) {
|
franta-hg@20
|
102 |
this.cil = 0;
|
franta-hg@20
|
103 |
}
|
franta-hg@20
|
104 |
}
|
franta-hg@20
|
105 |
|
franta-hg@20
|
106 |
public void setCil(int cil) {
|
franta-hg@20
|
107 |
this.cil = cil;
|
franta-hg@20
|
108 |
}
|
franta-hg@20
|
109 |
|
franta-hg@20
|
110 |
public String getCilString() {
|
franta-hg@20
|
111 |
return String.valueOf(cil);
|
franta-hg@20
|
112 |
}
|
franta-hg@20
|
113 |
|
franta-hg@20
|
114 |
public int getCil() {
|
franta-hg@20
|
115 |
return cil;
|
franta-hg@20
|
116 |
}
|
franta-hg@20
|
117 |
|
franta-hg@26
|
118 |
private void nastavVychoziZacatek() {
|
franta-hg@26
|
119 |
log.log(Level.FINE, "Nastavuji začátek na výchozí hodnotu.");
|
franta-hg@30
|
120 |
setZacatek(getVychoziZacatek());
|
franta-hg@30
|
121 |
}
|
franta-hg@30
|
122 |
|
franta-hg@30
|
123 |
private void nastavVychoziKonec() {
|
franta-hg@30
|
124 |
log.log(Level.FINE, "Nastavuji konec na výchozí hodnotu.");
|
franta-hg@30
|
125 |
setKonec(getVychoziKonec());
|
franta-hg@4
|
126 |
}
|
franta-hg@4
|
127 |
|
franta-hg@40
|
128 |
/**
|
franta-hg@40
|
129 |
* @return Denní souhrny útoků –
|
franta-hg@40
|
130 |
* obsahuje IP adresy a domény útočníků,
|
franta-hg@40
|
131 |
* datum je den poslendího útoku daného útočníka na daný cíl.
|
franta-hg@40
|
132 |
*/
|
franta-hg@4
|
133 |
public Collection<Souhrn> getSouhrn() {
|
franta-hg@26
|
134 |
Collection<Souhrn> souhrn = new SouhrnDAO().getSouhrn(zacatek, konec, cil);
|
franta-hg@4
|
135 |
|
franta-hg@21
|
136 |
/** ne všechno musíme posílat do JSP vrstvy */
|
franta-hg@21
|
137 |
for (Souhrn s : souhrn) {
|
franta-hg@21
|
138 |
s.getCil().setDatabaze(null);
|
franta-hg@21
|
139 |
s.getCil().setSelekt(null);
|
franta-hg@4
|
140 |
}
|
franta-hg@4
|
141 |
|
franta-hg@4
|
142 |
return souhrn;
|
franta-hg@4
|
143 |
}
|
franta-hg@6
|
144 |
|
franta-hg@6
|
145 |
/**
|
franta-hg@40
|
146 |
* @return Vyšší stupeň agregace než souhrn –
|
franta-hg@40
|
147 |
* obsahuje jen součty útoků pro daný den a daný cíl,
|
franta-hg@40
|
148 |
* neobsahuje podrobnosti o útočnících (ip adresa, doména).
|
franta-hg@40
|
149 |
*/
|
franta-hg@40
|
150 |
public HashMap<Cil, Collection<Soucet>> getSoucty() {
|
franta-hg@40
|
151 |
HashMap<Cil, Collection<Soucet>> soucty = new SouhrnDAO().getSoucty(zacatek, konec, cil);
|
franta-hg@40
|
152 |
|
franta-hg@46
|
153 |
/** ne všechno musíme posílat do prezentační vrstvy */
|
franta-hg@40
|
154 |
for (Collection<Soucet> ss : soucty.values()) {
|
franta-hg@40
|
155 |
for (Soucet s : ss) {
|
franta-hg@46
|
156 |
filtrujCil(s.getCil());
|
franta-hg@40
|
157 |
}
|
franta-hg@40
|
158 |
}
|
franta-hg@40
|
159 |
|
franta-hg@40
|
160 |
return soucty;
|
franta-hg@40
|
161 |
}
|
franta-hg@40
|
162 |
|
franta-hg@40
|
163 |
/**
|
franta-hg@6
|
164 |
* @return Seznam všech cílů. Ale bez těchto hodnot: databáze a selekt.
|
franta-hg@6
|
165 |
*/
|
franta-hg@6
|
166 |
public Collection<Cil> getSeznamCilu() {
|
franta-hg@6
|
167 |
Collection<Cil> cile = new CilDAO().getCile();
|
franta-hg@46
|
168 |
/** ne všechno musíme posílat do prezentační vrstvy */
|
franta-hg@46
|
169 |
filtrujCile(cile);
|
franta-hg@46
|
170 |
return cile;
|
franta-hg@46
|
171 |
}
|
franta-hg@6
|
172 |
|
franta-hg@46
|
173 |
/**
|
franta-hg@46
|
174 |
* Vymaže u cílů hodnoty „databáze“ a „selekt“ – ktreré v prezentační vrstvě většinou nepotřebujeme
|
franta-hg@46
|
175 |
* @param cile kolekce, který bude upravena
|
franta-hg@46
|
176 |
*/
|
franta-hg@46
|
177 |
private static void filtrujCile(Collection<Cil> cile) {
|
franta-hg@6
|
178 |
for (Cil c : cile) {
|
franta-hg@46
|
179 |
filtrujCil(c);
|
franta-hg@6
|
180 |
}
|
franta-hg@46
|
181 |
}
|
franta-hg@6
|
182 |
|
franta-hg@46
|
183 |
/**
|
franta-hg@46
|
184 |
* Vymaže u cíle hodnoty „databáze“ a „selekt“ – ktreré v prezentační vrstvě většinou nepotřebujeme
|
franta-hg@46
|
185 |
* @param c cíl, který bude upraven
|
franta-hg@46
|
186 |
*/
|
franta-hg@46
|
187 |
private static void filtrujCil(Cil c) {
|
franta-hg@46
|
188 |
c.setDatabaze(null);
|
franta-hg@46
|
189 |
c.setSelekt(null);
|
franta-hg@6
|
190 |
}
|
franta-hg@30
|
191 |
|
franta-hg@30
|
192 |
/**
|
franta-hg@30
|
193 |
* @return Výchozí začátek je před měsícem
|
franta-hg@30
|
194 |
*/
|
franta-hg@30
|
195 |
private static Date getVychoziZacatek() {
|
franta-hg@30
|
196 |
Calendar c = Calendar.getInstance();
|
franta-hg@30
|
197 |
c.add(Calendar.MONTH, -1);
|
franta-hg@30
|
198 |
return new Date(c.getTimeInMillis());
|
franta-hg@30
|
199 |
}
|
franta-hg@30
|
200 |
|
franta-hg@30
|
201 |
/**
|
franta-hg@30
|
202 |
* @return Výchozí konec je současnost
|
franta-hg@30
|
203 |
*/
|
franta-hg@30
|
204 |
private static Date getVychoziKonec() {
|
franta-hg@30
|
205 |
return new Date(System.currentTimeMillis());
|
franta-hg@30
|
206 |
}
|
franta-hg@3
|
207 |
}
|