java/nekurak.net-ejb/src/java/cz/frantovo/nekurak/ejb/PodnikEJB.java
author František Kučera <franta-hg@frantovo.cz>
Wed Apr 14 00:12:32 2010 +0200 (2010-04-14)
changeset 100 01be78803f73
parent 69 4964cf581166
child 102 7a7c06ea01db
permissions -rw-r--r--
Webové služby, zjišťování souřadnic podniků.
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@28
     4
import cz.frantovo.nekurak.dto.Podnik;
franta-hg@100
     5
import cz.frantovo.nekurak.ejb.Geo.Souradnice;
franta-hg@28
     6
import java.util.Collection;
franta-hg@63
     7
import javax.annotation.Resource;
franta-hg@40
     8
import javax.annotation.security.RolesAllowed;
franta-hg@39
     9
import javax.ejb.EJB;
franta-hg@63
    10
import javax.ejb.SessionContext;
franta-hg@28
    11
import javax.ejb.Stateless;
franta-hg@28
    12
franta-hg@28
    13
/**
franta-hg@28
    14
 *
franta-hg@28
    15
 * @author fiki
franta-hg@28
    16
 */
franta-hg@28
    17
@Stateless
franta-hg@39
    18
public class PodnikEJB implements PodnikRemote {
franta-hg@28
    19
franta-hg@39
    20
    @EJB
franta-hg@50
    21
    private PodnikDAO podnikDAO;
franta-hg@63
    22
    @Resource
franta-hg@63
    23
    private SessionContext ctx;
franta-hg@28
    24
franta-hg@28
    25
    public Collection<Podnik> getPodniky() {
franta-hg@39
    26
	Collection<Podnik> vysledek = podnikDAO.getPodniky();
franta-hg@39
    27
	return vysledek;
franta-hg@28
    28
    }
franta-hg@40
    29
franta-hg@100
    30
    public Podnik getPodnik(int id) {
franta-hg@100
    31
	return podnikDAO.getPodnik(id);
franta-hg@100
    32
    }
franta-hg@100
    33
franta-hg@40
    34
    @RolesAllowed("opravneny")
franta-hg@40
    35
    public void zalozPodnik(Podnik p) {
franta-hg@63
    36
	p.setSpravce(ctx.getCallerPrincipal().getName());
franta-hg@56
    37
	podnikDAO.zaloz(p);
franta-hg@40
    38
    }
franta-hg@40
    39
franta-hg@40
    40
    @RolesAllowed("opravneny")
franta-hg@40
    41
    public void upravPodnik(Podnik p) {
franta-hg@40
    42
	podnikDAO.uloz(p);
franta-hg@40
    43
    }
franta-hg@100
    44
franta-hg@100
    45
    public int dopocitejSouradnice() {
franta-hg@100
    46
	/**
franta-hg@100
    47
	 * TODO:    refaktorovat, změnit datové typy, souřadnice…
franta-hg@100
    48
	 *	    dopočítávat jen ty, které ještě nemají souřadnice
franta-hg@100
    49
	 */
franta-hg@100
    50
	Geo g = new Geo();
franta-hg@100
    51
	int pocetAktualizovanych = 0;
franta-hg@100
    52
franta-hg@100
    53
	for (Podnik p : podnikDAO.getPodniky()) {
franta-hg@100
    54
	    Souradnice s = g.getSouradnice(p.getUlice() + " " + p.getCisloPopisne() + ", " + p.getMesto());
franta-hg@100
    55
	    if (s != null) {
franta-hg@100
    56
		pocetAktualizovanych++;
franta-hg@100
    57
		p.setSirka(s.getSirka());
franta-hg@100
    58
		p.setDelka(s.getDelka());
franta-hg@100
    59
		podnikDAO.uloz(p);
franta-hg@100
    60
	    }
franta-hg@100
    61
	}
franta-hg@100
    62
franta-hg@100
    63
	return pocetAktualizovanych;
franta-hg@100
    64
    }
franta-hg@28
    65
}