franta-hg@28: package cz.frantovo.nekurak.ejb; franta-hg@28: franta-hg@39: import cz.frantovo.nekurak.dao.PodnikDAO; franta-hg@28: import cz.frantovo.nekurak.dto.Podnik; franta-hg@107: import cz.frantovo.nekurak.dto.VysledekHlasovani; franta-hg@119: import cz.frantovo.nekurak.ext.Geo; franta-hg@119: import cz.frantovo.nekurak.ext.Geo.Souradnice; franta-hg@28: import java.util.Collection; franta-hg@107: import java.util.logging.Logger; franta-hg@63: import javax.annotation.Resource; franta-hg@40: import javax.annotation.security.RolesAllowed; franta-hg@39: import javax.ejb.EJB; franta-hg@63: import javax.ejb.SessionContext; franta-hg@28: import javax.ejb.Stateless; franta-hg@28: franta-hg@28: /** franta-hg@28: * franta-hg@28: * @author fiki franta-hg@28: */ franta-hg@28: @Stateless franta-hg@39: public class PodnikEJB implements PodnikRemote { franta-hg@28: franta-hg@107: private static final Logger log = Logger.getLogger(PodnikEJB.class.getSimpleName()); franta-hg@39: @EJB franta-hg@50: private PodnikDAO podnikDAO; franta-hg@63: @Resource franta-hg@63: private SessionContext ctx; franta-hg@28: franta-hg@28: public Collection getPodniky() { franta-hg@39: Collection vysledek = podnikDAO.getPodniky(); franta-hg@39: return vysledek; franta-hg@28: } franta-hg@40: franta-hg@100: public Podnik getPodnik(int id) { franta-hg@100: return podnikDAO.getPodnik(id); franta-hg@100: } franta-hg@100: franta-hg@40: @RolesAllowed("opravneny") franta-hg@40: public void zalozPodnik(Podnik p) { franta-hg@63: p.setSpravce(ctx.getCallerPrincipal().getName()); franta-hg@56: podnikDAO.zaloz(p); franta-hg@40: } franta-hg@40: franta-hg@40: @RolesAllowed("opravneny") franta-hg@40: public void upravPodnik(Podnik p) { franta-hg@40: podnikDAO.uloz(p); franta-hg@40: } franta-hg@100: franta-hg@100: public int dopocitejSouradnice() { franta-hg@100: /** franta-hg@100: * TODO: refaktorovat, změnit datové typy, souřadnice… franta-hg@100: */ franta-hg@100: Geo g = new Geo(); franta-hg@100: int pocetAktualizovanych = 0; franta-hg@100: franta-hg@102: for (Podnik p : podnikDAO.getPodnikyBezSouradnic()) { franta-hg@100: Souradnice s = g.getSouradnice(p.getUlice() + " " + p.getCisloPopisne() + ", " + p.getMesto()); franta-hg@100: if (s != null) { franta-hg@100: pocetAktualizovanych++; franta-hg@100: p.setSirka(s.getSirka()); franta-hg@100: p.setDelka(s.getDelka()); franta-hg@100: podnikDAO.uloz(p); franta-hg@100: } franta-hg@100: } franta-hg@100: franta-hg@100: return pocetAktualizovanych; franta-hg@100: } franta-hg@107: franta-hg@107: public void hlasuj(int podnik, boolean hlas, String ipAdresa) { franta-hg@110: franta-hg@107: podnikDAO.hlasuj(podnik, hlas, ipAdresa); franta-hg@107: } franta-hg@107: franta-hg@107: public VysledekHlasovani getVysledekHlasovani(int podnik) { franta-hg@107: return podnikDAO.getVysledekHlasovani(podnik); franta-hg@107: } franta-hg@28: }