author | František Kučera <franta-hg@frantovo.cz> |
Tue Jun 08 09:09:17 2010 +0200 (2010-06-08) | |
changeset 130 | 1bbff3f5181f |
parent 123 | 9135d52e8b0a |
child 131 | 0d1cba59734b |
permissions | -rw-r--r-- |
franta-hg@28 | 1 |
package cz.frantovo.nekurak.ejb; |
franta-hg@28 | 2 |
|
franta-hg@39 | 3 |
import cz.frantovo.nekurak.dao.PodnikDAO; |
franta-hg@130 | 4 |
import cz.frantovo.nekurak.dto.Komentar; |
franta-hg@28 | 5 |
import cz.frantovo.nekurak.dto.Podnik; |
franta-hg@107 | 6 |
import cz.frantovo.nekurak.dto.VysledekHlasovani; |
franta-hg@119 | 7 |
import cz.frantovo.nekurak.ext.Geo; |
franta-hg@119 | 8 |
import cz.frantovo.nekurak.ext.Geo.Souradnice; |
franta-hg@130 | 9 |
import cz.frantovo.nekurak.ext.Texy; |
franta-hg@130 | 10 |
import cz.frantovo.nekurak.util.Komentare; |
franta-hg@28 | 11 |
import java.util.Collection; |
franta-hg@130 | 12 |
import java.util.Date; |
franta-hg@107 | 13 |
import java.util.logging.Logger; |
franta-hg@63 | 14 |
import javax.annotation.Resource; |
franta-hg@40 | 15 |
import javax.annotation.security.RolesAllowed; |
franta-hg@39 | 16 |
import javax.ejb.EJB; |
franta-hg@63 | 17 |
import javax.ejb.SessionContext; |
franta-hg@28 | 18 |
import javax.ejb.Stateless; |
franta-hg@28 | 19 |
|
franta-hg@28 | 20 |
/** |
franta-hg@28 | 21 |
* |
franta-hg@28 | 22 |
* @author fiki |
franta-hg@28 | 23 |
*/ |
franta-hg@28 | 24 |
@Stateless |
franta-hg@39 | 25 |
public class PodnikEJB implements PodnikRemote { |
franta-hg@28 | 26 |
|
franta-hg@107 | 27 |
private static final Logger log = Logger.getLogger(PodnikEJB.class.getSimpleName()); |
franta-hg@39 | 28 |
@EJB |
franta-hg@50 | 29 |
private PodnikDAO podnikDAO; |
franta-hg@63 | 30 |
@Resource |
franta-hg@63 | 31 |
private SessionContext ctx; |
franta-hg@28 | 32 |
|
franta-hg@28 | 33 |
public Collection<Podnik> getPodniky() { |
franta-hg@39 | 34 |
Collection<Podnik> vysledek = podnikDAO.getPodniky(); |
franta-hg@39 | 35 |
return vysledek; |
franta-hg@28 | 36 |
} |
franta-hg@40 | 37 |
|
franta-hg@100 | 38 |
public Podnik getPodnik(int id) { |
franta-hg@100 | 39 |
return podnikDAO.getPodnik(id); |
franta-hg@100 | 40 |
} |
franta-hg@100 | 41 |
|
franta-hg@40 | 42 |
@RolesAllowed("opravneny") |
franta-hg@40 | 43 |
public void zalozPodnik(Podnik p) { |
franta-hg@63 | 44 |
p.setSpravce(ctx.getCallerPrincipal().getName()); |
franta-hg@56 | 45 |
podnikDAO.zaloz(p); |
franta-hg@40 | 46 |
} |
franta-hg@40 | 47 |
|
franta-hg@40 | 48 |
@RolesAllowed("opravneny") |
franta-hg@40 | 49 |
public void upravPodnik(Podnik p) { |
franta-hg@40 | 50 |
podnikDAO.uloz(p); |
franta-hg@40 | 51 |
} |
franta-hg@100 | 52 |
|
franta-hg@100 | 53 |
public int dopocitejSouradnice() { |
franta-hg@100 | 54 |
/** |
franta-hg@123 | 55 |
* TODO: refaktorovat, změnit datové typy, souřadnice… |
franta-hg@100 | 56 |
*/ |
franta-hg@100 | 57 |
Geo g = new Geo(); |
franta-hg@100 | 58 |
int pocetAktualizovanych = 0; |
franta-hg@100 | 59 |
|
franta-hg@102 | 60 |
for (Podnik p : podnikDAO.getPodnikyBezSouradnic()) { |
franta-hg@100 | 61 |
Souradnice s = g.getSouradnice(p.getUlice() + " " + p.getCisloPopisne() + ", " + p.getMesto()); |
franta-hg@100 | 62 |
if (s != null) { |
franta-hg@100 | 63 |
pocetAktualizovanych++; |
franta-hg@100 | 64 |
p.setSirka(s.getSirka()); |
franta-hg@100 | 65 |
p.setDelka(s.getDelka()); |
franta-hg@100 | 66 |
podnikDAO.uloz(p); |
franta-hg@100 | 67 |
} |
franta-hg@100 | 68 |
} |
franta-hg@100 | 69 |
|
franta-hg@100 | 70 |
return pocetAktualizovanych; |
franta-hg@100 | 71 |
} |
franta-hg@107 | 72 |
|
franta-hg@107 | 73 |
public void hlasuj(int podnik, boolean hlas, String ipAdresa) { |
franta-hg@110 | 74 |
|
franta-hg@107 | 75 |
podnikDAO.hlasuj(podnik, hlas, ipAdresa); |
franta-hg@107 | 76 |
} |
franta-hg@107 | 77 |
|
franta-hg@107 | 78 |
public VysledekHlasovani getVysledekHlasovani(int podnik) { |
franta-hg@107 | 79 |
return podnikDAO.getVysledekHlasovani(podnik); |
franta-hg@107 | 80 |
} |
franta-hg@130 | 81 |
|
franta-hg@130 | 82 |
@RolesAllowed("opravneny") |
franta-hg@130 | 83 |
public void komentuj(Komentar k) { |
franta-hg@130 | 84 |
k.setUzivatel(ctx.getCallerPrincipal().getName()); |
franta-hg@130 | 85 |
k.setDatum(new Date()); |
franta-hg@130 | 86 |
|
franta-hg@130 | 87 |
/** Převedeme na XML */ |
franta-hg@130 | 88 |
switch (k.getTyp()) { |
franta-hg@130 | 89 |
case PROSTY_TEXT: |
franta-hg@130 | 90 |
k.setKomentar(Komentare.upravProstyText(k.getKomentar())); |
franta-hg@130 | 91 |
k.setKomentar(Komentare.obal(k.getKomentar())); |
franta-hg@130 | 92 |
break; |
franta-hg@130 | 93 |
case TEXY: |
franta-hg@130 | 94 |
Texy t = new Texy(); |
franta-hg@130 | 95 |
k.setKomentar(t.preved(k.getKomentar())); |
franta-hg@130 | 96 |
k.setKomentar(Komentare.obal(k.getKomentar())); |
franta-hg@130 | 97 |
break; |
franta-hg@130 | 98 |
} |
franta-hg@130 | 99 |
|
franta-hg@130 | 100 |
|
franta-hg@130 | 101 |
/** Zkontrolujeme XML */ |
franta-hg@130 | 102 |
log.severe("Komentář: " + k.getNadpis() + " | " + k.getKomentar() + " | " + k.getTyp()); |
franta-hg@130 | 103 |
} |
franta-hg@28 | 104 |
} |