Skip to content

Commit 7972a06

Browse files
committed
Se realizan ajustes de nombres, para metodos, tambien se actualizan las UT, se genera javadoc.
1 parent 03eeb8f commit 7972a06

File tree

4 files changed

+144
-54
lines changed

4 files changed

+144
-54
lines changed

src/main/java/mx/com/sw/services/ResponseHandler.java

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.http.client.methods.HttpDelete;
2222
import org.apache.http.client.methods.HttpGet;
2323
import org.apache.http.client.methods.HttpPost;
24+
import org.apache.http.client.methods.HttpPut;
2425
import org.apache.http.entity.BufferedHttpEntity;
2526
import org.apache.http.entity.ContentType;
2627
import org.apache.http.entity.StringEntity;
@@ -33,6 +34,7 @@
3334
/**
3435
* ResponseHandler Clase mediante la cual se hacen las peticiones y
3536
* des-serializaciones de respuestas.
37+
*
3638
* @param <T> IResponse subclasses
3739
* @author Juan Gamez
3840
* @version 0.0.0.1
@@ -46,11 +48,12 @@ public abstract class ResponseHandler<T> {
4648

4749
/**
4850
* Este método realiza un HTTP POST con la configuracion enviada.
49-
* @param url String url o host.
50-
* @param path String path
51-
* @param headers Map String String con headers.
52-
* @param jsonBody String body
53-
* @param configHTTP RequestConfig objeto de configuración.
51+
*
52+
* @param url String url o host.
53+
* @param path String path
54+
* @param headers Map String String con headers.
55+
* @param jsonBody String body
56+
* @param configHTTP RequestConfig objeto de configuración.
5457
* @param contentClass Clase de respuesta esperada.
5558
* @return T
5659
*/
@@ -117,12 +120,14 @@ public T postHTTPJson(String url, String path, Map<String, String> headers, Stri
117120
}
118121

119122
/**
120-
* Este método realiza un HTTP POST (modo Multipart form data) con la configuracion enviada.
121-
* @param url String url o host.
122-
* @param path String path.
123-
* @param headers Map String String con headers.
124-
* @param body String formato Multipart con body a enviar.
125-
* @param configHTTP RequestConfig objeto de configuración.
123+
* Este método realiza un HTTP POST (modo Multipart form data) con la
124+
* configuracion enviada.
125+
*
126+
* @param url String url o host.
127+
* @param path String path.
128+
* @param headers Map String String con headers.
129+
* @param body String formato Multipart con body a enviar.
130+
* @param configHTTP RequestConfig objeto de configuración.
126131
* @param contentClass Clase esperada de respuesta.
127132
* @return T
128133
*/
@@ -150,7 +155,7 @@ public T postHTTPMultipart(String url, String path, Map<String, String> headers,
150155
Future<HttpResponse> future = client.execute(request, null);
151156
HttpResponse response = future.get(MAX_EXECUTION_TIME, TimeUnit.MINUTES);
152157
if (response.getStatusLine() != null
153-
&& response.getStatusLine().getStatusCode() < HttpStatus.SC_INTERNAL_SERVER_ERROR) {
158+
&& response.getStatusLine().getStatusCode() < HttpStatus.SC_INTERNAL_SERVER_ERROR) {
154159
HttpEntity responseEntity = response.getEntity();
155160
String responseBody = new String();
156161
if (responseEntity != null) {
@@ -159,13 +164,15 @@ public T postHTTPMultipart(String url, String path, Map<String, String> headers,
159164
} else {
160165
throw new GeneralException(
161166
response.getStatusLine() != null
162-
? response.getStatusLine().getStatusCode() : HttpStatus.SC_UNPROCESSABLE_ENTITY,
167+
? response.getStatusLine().getStatusCode()
168+
: HttpStatus.SC_UNPROCESSABLE_ENTITY,
163169
"Can´t get body from the request made.");
164170
}
165171
} else {
166172
throw new GeneralException(
167173
response.getStatusLine() != null
168-
? response.getStatusLine().getStatusCode() : HttpStatus.SC_INTERNAL_SERVER_ERROR,
174+
? response.getStatusLine().getStatusCode()
175+
: HttpStatus.SC_INTERNAL_SERVER_ERROR,
169176
"Error > 500 calling the service.");
170177
}
171178
} catch (IllegalArgumentException e) {
@@ -195,10 +202,11 @@ public T postHTTPMultipart(String url, String path, Map<String, String> headers,
195202

196203
/**
197204
* Este método realiza un HTTP GET con la configuracion enviada.
198-
* @param url String url o host.
199-
* @param path String path.
200-
* @param headers Map String String con headers.
201-
* @param configHTTP RequestConfig objeto de configuración.
205+
*
206+
* @param url String url o host.
207+
* @param path String path.
208+
* @param headers Map String String con headers.
209+
* @param configHTTP RequestConfig objeto de configuración.
202210
* @param contentClass Clase esperada de respuesta.
203211
* @return T
204212
*/
@@ -219,7 +227,7 @@ public T getHTTP(String url, String path, Map<String, String> headers, RequestCo
219227
Future<HttpResponse> future = client.execute(request, null);
220228
HttpResponse response = future.get(MAX_EXECUTION_TIME, TimeUnit.MINUTES);
221229
if (response.getStatusLine() != null
222-
&& response.getStatusLine().getStatusCode() < HttpStatus.SC_INTERNAL_SERVER_ERROR) {
230+
&& response.getStatusLine().getStatusCode() < HttpStatus.SC_INTERNAL_SERVER_ERROR) {
223231
HttpEntity responseEntity = response.getEntity();
224232
String responseBody = new String();
225233
if (responseEntity != null) {
@@ -228,13 +236,15 @@ public T getHTTP(String url, String path, Map<String, String> headers, RequestCo
228236
} else {
229237
throw new GeneralException(
230238
response.getStatusLine() != null
231-
? response.getStatusLine().getStatusCode() : HttpStatus.SC_UNPROCESSABLE_ENTITY,
239+
? response.getStatusLine().getStatusCode()
240+
: HttpStatus.SC_UNPROCESSABLE_ENTITY,
232241
"Can´t get body from the request made.");
233242
}
234243
} else {
235244
throw new GeneralException(
236245
response.getStatusLine() != null
237-
? response.getStatusLine().getStatusCode() : HttpStatus.SC_INTERNAL_SERVER_ERROR,
246+
? response.getStatusLine().getStatusCode()
247+
: HttpStatus.SC_INTERNAL_SERVER_ERROR,
238248
"Error > 500 calling the service.");
239249
}
240250
} catch (IllegalArgumentException e) {
@@ -264,10 +274,11 @@ public T getHTTP(String url, String path, Map<String, String> headers, RequestCo
264274

265275
/**
266276
* Este método realiza un HTTP DELTE con la configuracion enviada.
267-
* @param url String url o host.
268-
* @param path String path.
269-
* @param headers Map String String con headers.
270-
* @param configHTTP RequestConfig objeto de configuración.
277+
*
278+
* @param url String url o host.
279+
* @param path String path.
280+
* @param headers Map String String con headers.
281+
* @param configHTTP RequestConfig objeto de configuración.
271282
* @param contentClass Clase esperada de respuesta.
272283
* @return T
273284
*/
@@ -288,7 +299,7 @@ public T deleteHTTP(String url, String path, Map<String, String> headers, Reques
288299
Future<HttpResponse> future = client.execute(request, null);
289300
HttpResponse response = future.get(MAX_EXECUTION_TIME, TimeUnit.MINUTES);
290301
if (response.getStatusLine() != null
291-
&& response.getStatusLine().getStatusCode() < HttpStatus.SC_INTERNAL_SERVER_ERROR) {
302+
&& response.getStatusLine().getStatusCode() < HttpStatus.SC_INTERNAL_SERVER_ERROR) {
292303
HttpEntity responseEntity = response.getEntity();
293304
String responseBody = new String();
294305
if (responseEntity != null) {
@@ -297,13 +308,15 @@ public T deleteHTTP(String url, String path, Map<String, String> headers, Reques
297308
} else {
298309
throw new GeneralException(
299310
response.getStatusLine() != null
300-
? response.getStatusLine().getStatusCode() : HttpStatus.SC_UNPROCESSABLE_ENTITY,
311+
? response.getStatusLine().getStatusCode()
312+
: HttpStatus.SC_UNPROCESSABLE_ENTITY,
301313
"Can´t get body from the request made.");
302314
}
303315
} else {
304316
throw new GeneralException(
305317
response.getStatusLine() != null
306-
? response.getStatusLine().getStatusCode() : HttpStatus.SC_INTERNAL_SERVER_ERROR,
318+
? response.getStatusLine().getStatusCode()
319+
: HttpStatus.SC_INTERNAL_SERVER_ERROR,
307320
"Error > 500 calling the service.");
308321
}
309322
} catch (IllegalArgumentException e) {
@@ -333,11 +346,12 @@ public T deleteHTTP(String url, String path, Map<String, String> headers, Reques
333346

334347
/**
335348
* Este método realiza una deserializacion de un JSON al tipo de clase T.
349+
*
336350
* @param json String json.
337351
* @param contentClass Clase esperada de respuesta.
338352
* @return T
339353
* @throws JsonSyntaxException en caso de error.
340-
* @throws ServicesException en caso de json vacío (Errores 404 o similar).
354+
* @throws ServicesException en caso de json vacío (Errores 404 o similar).
341355
*/
342356
public T deserialize(String json, Class<T> contentClass) throws JsonSyntaxException, ServicesException {
343357
if (json == null || json.isEmpty()) {

src/main/java/mx/com/sw/services/account/info/AccountInfo.java

Lines changed: 74 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class AccountInfo extends AccountInfoService {
5555
/**
5656
* Constructor de la clase.
5757
*
58-
* @param urlApi url base de la API
58+
* @param urlApi url base de la API
5959
* @param user correo o usuario de SW
6060
* @param password password de SW.
6161
* @param proxy ip o dominio de proxy (null si no se utiliza)
@@ -79,7 +79,7 @@ public AccountInfo(String url, String urlApi, String user, String password, Stri
7979
* @param proxyPort número de puerto de proxy (cualquier valor si proxy es null)
8080
* @throws ServicesException exception en caso de error.
8181
*/
82-
82+
8383
public AccountInfo(String urlApi, String token, String proxy, int proxyPort) throws ServicesException {
8484
super(urlApi, token, proxy, proxyPort);
8585
handler = new AccountInfoResponseHandler();
@@ -92,29 +92,66 @@ public AccountInfo(String urlApi, String token, String proxy, int proxyPort) thr
9292
*/
9393
@Override
9494

95-
//Metodos de respuesta con array de todos los datos de usuarios
95+
/**
96+
* Obtiene la lista de todos los usuarios.
97+
*
98+
* @param page Número de página.
99+
* @param pageSize Tamaño de la página.
100+
* @return Objeto AccountListDataResponse con la respuesta de la API.
101+
* @throws ServicesException Excepción en caso de error.
102+
*/
96103
public AccountListDataResponse getAllUsers(int page, int pageSize) throws ServicesException {
97104
Map<String, String> headers = getHeaders();
98105
RequestConfig config = GeneralHelpers.setProxyAndTimeOut(getProxy(), getProxyPort());
99106
String path = "management/api/users?page=" + page + "&pageSize=" + pageSize;
100-
return handlerList.getHTTP(getUrlapi() == null ? getUrl() : getUrlapi(), path, headers, config, AccountListDataResponse.class);
107+
return handlerList.getHTTP(getUrlapi() == null ? getUrl() : getUrlapi(), path, headers, config,
108+
AccountListDataResponse.class);
101109
}
102-
//Metodos de respuestas de que devuelven los datos del user
110+
111+
/**
112+
* Obtiene la información de un usuario por su Token.
113+
*
114+
* @return Objeto AccountInfoResponse con la respuesta de la API.
115+
* @throws ServicesException Excepción en caso de error.
116+
*/
103117
public AccountInfoResponse getInfo() throws ServicesException {
104118
Map<String, String> headers = getHeaders();
105119
RequestConfig config = GeneralHelpers.setProxyAndTimeOut(getProxy(), getProxyPort());
106-
return handler.getHTTP(getUrlapi() == null ? getUrl() : getUrlapi(), "management/api/users/info", headers, config, AccountInfoResponse.class);
120+
return handler.getHTTP(getUrlapi() == null ? getUrl() : getUrlapi(), "management/api/users/info", headers,
121+
config, AccountInfoResponse.class);
107122
}
108123

124+
/**
125+
* Obtiene la información de un usuario por su ID.
126+
*
127+
* @param IdUser ID del usuario.
128+
* @return Objeto AccountInfoResponse con la respuesta de la API.
129+
* @throws ServicesException Excepción en caso de error.
130+
*/
109131
public AccountInfoResponse getInfoById(String IdUser) throws ServicesException {
110132
Map<String, String> headers = getHeaders();
111133
RequestConfig config = GeneralHelpers.setProxyAndTimeOut(getProxy(), getProxyPort());
112134
String path = "management/api/users/" + IdUser;
113-
return handler.getHTTP(getUrlapi() == null ? getUrl() : getUrlapi(), path, headers, config, AccountInfoResponse.class);
135+
return handler.getHTTP(getUrlapi() == null ? getUrl() : getUrlapi(), path, headers, config,
136+
AccountInfoResponse.class);
114137
}
115-
//Metodos de respuestas simples
116138

117-
public AccountInfoActionResponse createUser(String email, String password, String name, String rfc, int profile,
139+
/**
140+
* Crea un nuevo usuario con la información proporcionada.
141+
*
142+
* @param email Correo electrónico del usuario.
143+
* @param password Contraseña del usuario.
144+
* @param name Nombre del usuario.
145+
* @param rfc RFC del usuario.
146+
* @param profile Perfil del usuario.
147+
* @param stamps Cantidad de timbres del usuario.
148+
* @param unlimited Indica si el usuario tiene timbres ilimitados.
149+
* @param active Indica si el usuario está activo.
150+
* @return Objeto AccountInfoActionResponse con la respuesta de la API.
151+
* @throws ServicesException Excepción en caso de error.
152+
*/
153+
154+
private AccountInfoActionResponse createMapUser(String email, String password, String name, String rfc, int profile,
118155
int stamps, boolean unlimited, boolean active) throws ServicesException {
119156
Map<String, String> headers = getHeaders();
120157
RequestConfig config = GeneralHelpers.setProxyAndTimeOut(getProxy(), getProxyPort());
@@ -133,15 +170,39 @@ public AccountInfoActionResponse createUser(String email, String password, Strin
133170
config, AccountInfoActionResponse.class);
134171
}
135172

136-
public AccountInfoActionResponse getDeleteIdUser(String idUser) throws ServicesException {
173+
/**
174+
* Elimina un usuario por su ID.
175+
*
176+
* @param idUser ID del usuario a eliminar.
177+
* @return Objeto AccountInfoActionResponse con la respuesta de la API.
178+
* @throws ServicesException Excepción en caso de error.
179+
*/
180+
public AccountInfoActionResponse deleteIdUser(String idUser) throws ServicesException {
137181
Map<String, String> headers = getHeaders();
138182
RequestConfig config = GeneralHelpers.setProxyAndTimeOut(getProxy(), getProxyPort());
139183
String path = "management/api/users/" + idUser;
140-
return handlerActions.deleteHTTP(getUrlapi() == null ? getUrl() : getUrlapi(), path, headers, config, AccountInfoActionResponse.class);
184+
return handlerActions.deleteHTTP(getUrlapi() == null ? getUrl() : getUrlapi(), path, headers, config,
185+
AccountInfoActionResponse.class);
141186
}
142187

143-
public AccountInfoActionResponse getCreateUser(String email, String password, String name, String rfc, int profile,
188+
/**
189+
* Crea un nuevo usuario con la información proporcionada.
190+
*
191+
* @param email Correo electrónico del usuario.
192+
* @param password Contraseña del usuario.
193+
* @param name Nombre del usuario.
194+
* @param rfc RFC del usuario.
195+
* @param profile Perfil del usuario.
196+
* @param stamps Cantidad de timbres del usuario.
197+
* @param unlimited Indica si el usuario tiene timbres ilimitados.
198+
* @param active Indica si el usuario está activo.
199+
* @return Objeto AccountInfoActionResponse con la respuesta de la API.
200+
* @throws ServicesException Excepción en caso de error.
201+
*/
202+
203+
public AccountInfoActionResponse createUser(String email, String password, String name, String rfc, int profile,
144204
int stamps, boolean unlimited, boolean active) throws ServicesException {
145-
return createUser(email, password, name, rfc, profile, stamps, unlimited, active);
205+
return createMapUser(email, password, name, rfc, profile, stamps, unlimited, active);
146206
}
207+
147208
}

src/main/java/mx/com/sw/services/account/info/AccountInfoService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ protected AccountInfoService(String urlApi, String token, String proxy, int prox
7878
* @return Respuesta de la solicitud de información de los usuarios.
7979
* @throws ServicesException exception en caso de error.
8080
*/
81-
public abstract AccountInfoActionResponse getCreateUser(String email, String password, String name, String rfc, int profile, int stamps, boolean unlimited, boolean active) throws ServicesException;
81+
public abstract AccountInfoActionResponse createUser(String email, String password, String name, String rfc, int profile, int stamps, boolean unlimited, boolean active) throws ServicesException;
8282

8383
/**
8484
* Elimina la cuenta para un usuario específico por su Id.
8585
* @param IdUser Identificador del usuario.
8686
* @return Respuesta de la solicitud de información de la cuenta.
8787
* @throws ServicesException exception en caso de error.
8888
*/
89-
public abstract AccountInfoActionResponse getDeleteIdUser(String idUser) throws ServicesException;
89+
public abstract AccountInfoActionResponse deleteIdUser(String idUser) throws ServicesException;
9090

9191
/**
9292
* Obtiene los headers necesarios para el consumo del servicio.

0 commit comments

Comments
 (0)