blob: 2c6dcf706bcd73a197c562063ec5219a6e48ed71 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
/*
* 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")
}
|