3 import java.util.ArrayList;
6 import java.util.ResourceBundle;
7 import java.util.Vector;
9 import javax.jws.WebMethod;
10 import javax.jws.WebService;
12 import configuration.ConfigXML;
13 import dataAccess.DataAccess;
14 import domain.Question;
17 import domain.Forecast;
18 import exceptions.EventFinished;
19 import exceptions.IncorrectPassException;
20 import exceptions.QuestionAlreadyExist;
21 import exceptions.UserAlreadyExistException;
22 import exceptions.UserDoesNotExistException;
25 * It implements the business logic as a web service.
27 @WebService(endpointInterface = "businessLogic.BLFacade")
28 public class BLFacadeImplementation implements BLFacade {
31 public BLFacadeImplementation() {
32 System.out.println("Creating BLFacadeImplementation instance");
33 ConfigXML c = ConfigXML.getInstance();
35 if (c.getDataBaseOpenMode().equals("initialize")) {
36 dbManager = new DataAccess(c.getDataBaseOpenMode().equals("initialize"));
37 dbManager.initializeDB();
43 public BLFacadeImplementation(DataAccess da) {
45 System.out.println("Creating BLFacadeImplementation instance with DataAccess parameter");
46 ConfigXML c = ConfigXML.getInstance();
48 if (c.getDataBaseOpenMode().equals("initialize")) {
58 * This method creates a question for an event, with a question text and the
61 * @param event to which question is added
62 * @param question text of the question
63 * @param betMinimum minimum quantity of the bet
64 * @return the created question, or null, or an exception
65 * @throws EventFinished if current data is after data of the event
66 * @throws QuestionAlreadyExist if the same question already exists for the
70 public Question createQuestion(Event event, String question, float betMinimum)
71 throws EventFinished, QuestionAlreadyExist {
73 // The minimum bed must be greater than 0
74 dbManager.open(false);
77 if (new Date().compareTo(event.getEventDate()) > 0)
78 throw new EventFinished(ResourceBundle.getBundle("Etiquetas").getString("ErrorEventHasFinished"));
80 qry = dbManager.createQuestion(event, question, betMinimum);
88 * This method invokes the data access to retrieve the events of a given date
90 * @param date in which events are retrieved
91 * @return collection of events
94 public Vector<Event> getEvents(Date date) {
95 dbManager.open(false);
96 Vector<Event> events = dbManager.getEvents(date);
102 * This method invokes the data access to retrieve the dates a month for which
105 * @param date of the month for which days with events want to be retrieved
106 * @return collection of dates
109 public Vector<Date> getEventsMonth(Date date) {
110 dbManager.open(false);
111 Vector<Date> dates = dbManager.getEventsMonth(date);
116 public void close() {
117 DataAccess dB4oManager = new DataAccess(false);
124 * This method invokes the data access to initialize the database with some
125 * events and questions. It is invoked only when the option "initialize" is
126 * declared in the tag dataBaseOpenMode of resources/config.xml file
129 public void initializeBD() {
130 dbManager.open(false);
131 dbManager.initializeDB();
135 public User login(String userName, String password) throws UserDoesNotExistException, IncorrectPassException {
136 dbManager.open(false);
137 User login = dbManager.login(userName, password);
142 // public boolean validoUsuario(String puser) {
143 // dbManager.open(false);
144 // boolean usuarioBD = dbManager.validoUsuario(puser);
145 // dbManager.close();
149 public User registrar(String user,String pass,String name,String lastName,String birthDate,String email,String account,Integer numb,String address) throws UserAlreadyExistException {
150 dbManager.open(false);
151 User u = dbManager.registrar(user, pass, name, lastName, birthDate, email, account, numb, address);
156 public boolean insertEvent(Event pEvento) {
157 dbManager.open(false);
158 boolean inserted = dbManager.insertEvent(pEvento);
163 public int getNumberEvents() {
164 dbManager.open(false);
165 int n = dbManager.getNumberEvents();
170 public boolean existEvent(Event event) {
171 dbManager.open(false);
172 boolean result = dbManager.existEvent(event);
177 public int getNumberForecasts() {
178 dbManager.open(false);
179 int n = dbManager.getNumberForecasts();
184 public boolean existForecast(Forecast f) {
185 dbManager.open(false);
186 boolean result = dbManager.existForecast(f);
191 public boolean insertForecast(Forecast f) {
192 dbManager.open(false);
193 boolean inserted = dbManager.insertForecast(f);