/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package beans.lager; import beans.*; import beans.artikelManager.ArtikelManagerRemote; import entities.Artikel; import exceptions.IllegalerWertException; import exceptions.UnbekanntesEntityException; import javax.ejb.EJB; import javax.ejb.Stateless; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService; import javax.jws.WebResult; /** * Diese Klasse stellt Funktionen des Lagers bereit * @author jmueller */ @WebService @Stateless(mappedName="LagerBean") public class LagerBean implements LagerRemote { @EJB private ArtikelManagerRemote artikelManagerBean; /** * bucht eine bestimmte Anzahl von Artikeln aus dem Lager aus * * @param id die Id des Artikels * @param anzahl die Anzahl der auszubuchenden Artikel */ @WebMethod public void bucheArtikelAus( @WebParam(name="artikelId")long id, @WebParam(name="anzahl") long anzahl)throws UnbekanntesEntityException, IllegalerWertException{ System.out.println("Lager: bucheArtikelAus("+id+","+anzahl+")"); if(anzahl < 0){ throw new IllegalerWertException("anzahl", ""+id); } Artikel artikel = artikelManagerBean.readArtikel(id); artikel.setAnzahl(artikel.getAnzahl() - anzahl); artikelManagerBean.updateArtikel(artikel); } /** * bucht eine bestimmte Anzahl von Artikeln ins Lager ein * * @param id * @param anzahl * @throws exceptions.UnbekanntesEntityException * @throws exceptions.IllegalerWertException */ @WebMethod public void bucheArtikelEin( @WebParam(name="artikelId")long id, @WebParam(name="anzahl") long anzahl) throws UnbekanntesEntityException, IllegalerWertException{ System.out.println("Lager: bucheArtikelEin("+id+","+ anzahl+")"); if(anzahl < 0){ throw new IllegalerWertException("anzahl", ""+id); } Artikel artikel = artikelManagerBean.readArtikel(id); artikel.setAnzahl(artikel.getAnzahl() + anzahl); artikelManagerBean.updateArtikel(artikel); } /** * Testet ob der Artikel in ausreichender Anzahl vorhanden ist, * falls der Artikel nicht existiert wird false zurückgegeben * @param id * @param anzahl * @return */ @WebMethod public @WebResult(name="verfuegbar") boolean pruefeVerfuegbarkeit( @WebParam(name="artikelId") long id, @WebParam(name="anzahl") long anzahl) throws Exception{ Artikel artikel = artikelManagerBean.readArtikel(id); if( artikel.getAnzahl() >= anzahl ){ return true; } return false; } // Add business logic below. (Right-click in editor and choose // "EJB Methods > Add Business Method" or "Web Service > Add Operation") }