ISBets21MAUBRY
3cf4057e97448d401b49261033b8ab566105944e
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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 |
package businessLogic; //hola import java.util.Date; import java.util.ResourceBundle; import java.util.Vector; import javax.jws.WebMethod; import javax.jws.WebService; import configuration.ConfigXML; import configuration.UtilDate; import dataAccess.DataAccess; import domain.AdminUser; import domain.Bet; import domain.Event; import domain.Forecast; import domain.Question; import domain.RegularUser; import domain.User; import exceptions.EventFinished; import exceptions.QuestionAlreadyExist; import exceptions.UserAlreadyExistException; /** * It implements the business logic as a web service. */ @WebService(endpointInterface = "businessLogic.BLFacade") public class BLFacadeImplementation implements BLFacade { DataAccess dbManager; public BLFacadeImplementation() { System.out.println("Creating BLFacadeImplementation instance"); ConfigXML c = ConfigXML.getInstance(); if (c.getDataBaseOpenMode().equals("initialize")) { dbManager = new DataAccess(c.getDataBaseOpenMode().equals("initialize")); dbManager.initializeDB(); dbManager.close(); } } public BLFacadeImplementation(DataAccess da) { System.out.println("Creating BLFacadeImplementation instance with DataAccess parameter"); ConfigXML c = ConfigXML.getInstance(); if (c.getDataBaseOpenMode().equals("initialize")) { da.open(true); da.initializeDB(); da.close(); } dbManager = da; } /** * This method creates a question for an event, with a question text and the * minimum bet * * @param event to which question is added * @param question text of the question * @param betMinimum minimum quantity of the bet * @return the created question, or null, or an exception * @throws EventFinished if current data is after data of the event * @throws QuestionAlreadyExist if the same question already exists for the * event */ @Override @WebMethod public Question createQuestion(Event event, String question, float betMinimum) throws EventFinished, QuestionAlreadyExist { // The minimum bed must be greater than 0 dbManager.open(false); Question qry = null; if (new Date().compareTo(event.getEventDate()) > 0) throw new EventFinished(ResourceBundle.getBundle("Etiquetas").getString("ErrorEventHasFinished")); qry = dbManager.createQuestion(event, question, betMinimum); dbManager.close(); return qry; }; @Override public Vector<Question> getAllQuestions() { dbManager.open(false); Vector<Question> questions = dbManager.getAllQuestions(); dbManager.close(); return questions; } @Override public boolean deleteEvent(Event evento) { dbManager.open(false); boolean res = dbManager.deleteEvent(evento); dbManager.close(); return res; } /** * This method invokes the data access to retrieve the events of a given date * * @param date in which events are retrieved * @return collection of events */ @Override @WebMethod public Vector<Event> getEvents(Date date) { dbManager.open(false); Vector<Event> events = dbManager.getEvents(date); dbManager.close(); return events; } /** * This method invokes the data access to retrieve the events of a given date * * @param date in which events are retrieved * @return collection of events */ @Override @WebMethod public Vector<Event> getAllEvents() { dbManager.open(false); Vector<Event> events = dbManager.getAllEvents(); dbManager.close(); return events; } /** * This method invokes the data access to retrieve the dates a month for which * there are events * * @param date of the month for which days with events want to be retrieved * @return collection of dates */ @Override @WebMethod public Vector<Date> getEventsMonth(Date date) { dbManager.open(false); Vector<Date> dates = dbManager.getEventsMonth(date); dbManager.close(); return dates; } public void close() { DataAccess dB4oManager = new DataAccess(false); dB4oManager.close(); } /** * This method invokes the data access to initialize the database with some * events and questions. It is invoked only when the option "initialize" is * declared in the tag dataBaseOpenMode of resources/config.xml file */ @Override @WebMethod public void initializeBD() { dbManager.open(false); dbManager.initializeDB(); dbManager.close(); } // @Override // public RegularUser login(String userName, String password) // throws UserDoesNotExistException, IncorrectPassException { // dbManager.open(false); // User login = dbManager.login(userName, password); // dbManager.close(); // return login; // } // public boolean validoUsuario(String puser) { // dbManager.open(false); // boolean usuarioBD = dbManager.validoUsuario(puser); // dbManager.close(); // return usuarioBD; // } @Override public RegularUser registrar(String user, String pass, String name, String lastName, String birthDate, String email, String account, Integer numb, String address, float balance) throws UserAlreadyExistException { dbManager.open(false); RegularUser u = dbManager.registrar(user, pass, name, lastName, birthDate, email, account, numb, address, balance); dbManager.close(); return u; } @Override public boolean insertEvent(Event pEvento) { dbManager.open(false); boolean inserted = dbManager.insertEvent(pEvento); dbManager.close(); return inserted; } @Override public int getNumberEvents() { dbManager.open(false); int n = dbManager.getNumberEvents(); dbManager.close(); return n; } @Override public boolean existEvent(Event event) { dbManager.open(false); boolean result = dbManager.existEvent(event); dbManager.close(); return result; } @Override public int getNumberForecasts() { dbManager.open(false); int n = dbManager.getNumberForecasts(); dbManager.close(); return n; } @Override public boolean existForecast(Forecast f) { dbManager.open(false); boolean result = dbManager.existForecast(f); dbManager.close(); return result; } @Override public boolean insertForecast(Question question, String forecast, float fee) { dbManager.open(false); Forecast inserted = dbManager.insertForecast(question, forecast, fee); if (inserted == null) { return false; } dbManager.close(); return true; } @Override public Vector<Forecast> getForecasts() { dbManager.open(false); Vector<Forecast> result = dbManager.getForecasts(); dbManager.close(); return result; } @Override public Vector<Forecast> getForecasts(Question pregunta) { dbManager.open(false); Vector<Forecast> result = dbManager.getForecasts(pregunta); dbManager.close(); return result; } @Override public boolean editarPerfilUsuario(String pContraseña, String pUsername, String pNombre, String pApellido, String pEmail, String pCuentaBancaria) { dbManager.open(false); boolean res = dbManager.editarPerfilUsuario(pContraseña, pUsername, pNombre, pApellido, pEmail, pCuentaBancaria); dbManager.close(); return res; } @Override public boolean editarPerfilUsuarioSinPass(String pUsername, String pNombre, String pApellido, String pEmail, String pCuentaBancaria) { dbManager.open(false); boolean res = dbManager.editarPerfilUsuarioSinPass(pUsername, pNombre, pApellido, pEmail, pCuentaBancaria); dbManager.close(); return res; } @Override public Vector<User> getAllUsers() { dbManager.open(false); Vector<User> users = dbManager.getAllUsers(); dbManager.close(); return users; } @Override public Integer getMaxIdInDB() { dbManager.open(false); Integer maxid = dbManager.getMaxIdInDB(); dbManager.close(); return maxid; } @Override public boolean doLogin(String username, String pass) { dbManager.open(false); boolean bo = dbManager.doLogin(username, pass); dbManager.close(); return bo; } @Override public boolean isAdmin(String pusername, String ppassword) { dbManager.open(false); boolean bo = dbManager.isAdmin(pusername, ppassword); dbManager.close(); return bo; } @Override public RegularUser getRegularUserByUsername(String pusername) { dbManager.open(false); RegularUser ru = dbManager.getRegularUserByUsername(pusername); dbManager.close(); return ru; } @Override public AdminUser getAdminUserByUsername(String pusername) { dbManager.open(false); AdminUser au = dbManager.getAdminUserByUsername(pusername); dbManager.close(); return au; } @Override public int createApuesta(Forecast pselectedAnswer, RegularUser pselectedClient, Float pselectedAmount) { dbManager.open(false); int inserted = dbManager.createApuesta(pselectedAnswer, pselectedClient, pselectedAmount); return inserted; } @Override public boolean closeEvent(Event e, Question q, Forecast f) { dbManager.open(false); boolean closed = dbManager.closeEvent(e, q, f); return closed; } @Override public boolean anularApuesta(Bet pApuesta) { dbManager.open(false); boolean result = dbManager.anularApuesta(pApuesta); return result; } @Override public Vector<Bet> getApuestasAbiertas(RegularUser pUser) { dbManager.open(false); Vector<Bet> result = dbManager.getApuestasAbiertas(pUser); return result; } @Override public Vector<Bet> getApuestasCerradas(RegularUser pUser) { dbManager.open(false); Vector<Bet> result = dbManager.getApuestasCerradas(pUser); return result; } @Override public Vector<Bet> getApuestasGanadas(RegularUser pUser) { dbManager.open(false); Vector<Bet> result = dbManager.getApuestasGanadas(pUser); return result; } @Override public Vector<Bet> getApuestasPerdidas(RegularUser pUser) { dbManager.open(false); Vector<Bet> result = dbManager.getApuestasPerdidas(pUser); return result; } @Override public Vector<Bet> getApuestasAnuladas(RegularUser pUser) { dbManager.open(false); Vector<Bet> result = dbManager.getApuestasAnuladas(pUser); return result; } @Override public Vector<Bet> getApuestasByUser(RegularUser user) { dbManager.open(false); Vector<Bet> result = dbManager.getApuestasByUser(user); return result; } @Override public boolean aplicarBonoBienvenida(String user) { dbManager.open(false); boolean result = dbManager.aplicarBonoBienvenida(user); return result; } @Override public boolean recargarSaldo(String user, Float importe) { dbManager.open(false); boolean result = dbManager.recargarSaldo(user, importe); return result; } @Override public boolean definirResultados(Event pselectedEvent, Question pselectedQuestion, Forecast pselectedForecast) { dbManager.open(false); boolean result = dbManager.definirResultados(pselectedEvent, pselectedQuestion, pselectedForecast); return result; } public static void main(String[] args) { BLFacadeImplementation controlador = new BLFacadeImplementation(); RegularUser usuario = new RegularUser("usuario", "Usuario1?", "Nombre", "Apellido", "01/01/2000", "usuario@gmail.com", "ES11 1111 1111 1111", 123456789, "", 0); Event ev1 = new Event(69, "Eibar-Eibar", UtilDate.newDate(2015, 4, 17)); Question pregunta = new Question("pregunta", 2, ev1); Forecast pronostico = new Forecast("Madrid", 17, pregunta); Bet apuesta = new Bet(pronostico, usuario, 13); System.out.println(controlador.anularApuesta(apuesta)); } @Override public Vector<Question> getOpenedQuestions(Event ev) { dbManager.open(false); Vector<Question> ArrayListQuestions = dbManager.getOpenedQuestions(ev); return ArrayListQuestions; } public boolean getEstadoEvento(Event ev) { dbManager.open(false); boolean result = dbManager.getEstadoEvento(ev); return result; } public Vector<Event> getEventosMedioCerrados(){ dbManager.open(false); Vector<Event> result = dbManager.getEventosMedioCerrados(); return result; } } |
Commits for ISBets21MAUBRYeclipse-workspace/ISBets21MAUBRY/src/main/java/businessLogic/BLFacadeImplementation.java
Revision | Author | Commited | Message |
---|---|---|---|
3cf405 ... | porkipig | Sun 16 May, 2021 19:27:29 +0000 | Iteración 3(Versión sin idiomas) |