Git Repository Public Repository

ISBets21MAUBRY

URLs

Copy to Clipboard
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
package businessLogic;

import java.util.ArrayList;
//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 dataAccess.DataAccess;
import domain.Question;
import domain.User;
import domain.Event;
import domain.Forecast;
import exceptions.EventFinished;
import exceptions.IncorrectPassException;
import exceptions.QuestionAlreadyExist;
import exceptions.UserAlreadyExistException;
import exceptions.UserDoesNotExistException;

/**
 * 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
	 */
	@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;
	};

	/**
	 * 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
	 */
	@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 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
	 */
	@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
	 */
	@WebMethod
	public void initializeBD() {
		dbManager.open(false);
		dbManager.initializeDB();
		dbManager.close();
	}

	public User 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;
//	}
	
	public User registrar(String user,String pass,String name,String lastName,String birthDate,String email,String account,Integer numb,String address) throws UserAlreadyExistException {
		dbManager.open(false);
		User u = dbManager.registrar(user, pass, name, lastName, birthDate, email, account, numb, address);
		dbManager.close();
		return u;
	}
	
	public boolean insertEvent(Event pEvento) {
		dbManager.open(false);
		boolean inserted = dbManager.insertEvent(pEvento);
		dbManager.close();
		
		return inserted;
	}
	public int getNumberEvents() {
		dbManager.open(false);
		int n = dbManager.getNumberEvents();
		dbManager.close();
		return n;
	}
	
	public boolean existEvent(Event event) {
		dbManager.open(false);
		boolean result = dbManager.existEvent(event);
		dbManager.close();
		return result;
	}
	
	public int getNumberForecasts() {
		dbManager.open(false);
		int n = dbManager.getNumberForecasts();
		dbManager.close();
		return n;
	}
	
	public boolean existForecast(Forecast f) {
		dbManager.open(false);
		boolean result = dbManager.existForecast(f);
		dbManager.close();
		return result;
	}
	
	public boolean insertForecast(Forecast f) {
		dbManager.open(false);
		boolean inserted = dbManager.insertForecast(f);
		dbManager.close();
		return inserted;
	}
}

Commits for ISBets21MAUBRYeclipse-workspace/ISBets21BRYMAUJONUNA/src/main/java/businessLogic/BLFacadeImplementation.java

Diff revisions: vs.
Revision Author Commited Message
cbae14 ... porkipig Thu 04 Mar, 2021 10:33:41 +0000

VersiĆ³n del proyecto de Apuestas tras la iteraciĆ³n 1