Skip to content

Commit 21d5008

Browse files
committed
Fix validation and README
1 parent 03972d2 commit 21d5008

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,7 +2274,8 @@ public class App {
22742274
//Automaticamente despues de obtenerlo se procedera a timbrar
22752275
StampV4 stamp = new StampV4("http://services.test.sw.com.mx", "user", "password", null, 0);
22762276
String xml = new String(Files.readAllBytes(Paths.get("file.xml")), "UTF-8");
2277-
StampResponseV1 response = stamp.timbrarV1(xml, "test@test.com.mx, test@test2.com.mx", null, false, false);
2277+
List<String> email = Arrays.asList("test@test.com.mx");
2278+
StampResponseV1 response = stamp.timbrarV1(xml, email, null, false, false);
22782279

22792280
//Para obtener el estatus
22802281
System.out.println(response.getStatus());
@@ -2312,7 +2313,8 @@ public class App {
23122313
StampV4 stamp = new StampV4("http://services.test.sw.com.mx", "user", "password", null, 0);
23132314
byte[] xml = Files.readAllBytes(Paths.get("file.xml"));
23142315
String xml64 = Base64.getEncoder().encodeToString(xml);
2315-
StampResponseV1 response = stamp.timbrarV1(xml, "test@test.com.mx, test@test2.com.mx", null, false, false);
2316+
List<String> email = Arrays.asList("test@test.com.mx");
2317+
StampResponseV1 response = stamp.timbrarV1(xml, email, null, false, false);
23162318

23172319
//Para obtener el estatus
23182320
System.out.println(response.getStatus());
@@ -2354,7 +2356,8 @@ public class App {
23542356
//Automaticamente despues de obtenerlo se procedera a timbrar
23552357
IssueV4 stamp = new IssueV4("http://services.test.sw.com.mx", "user", "password", null, 0);
23562358
String xml = new String(Files.readAllBytes(Paths.get("file.xml")), "UTF-8");
2357-
StampResponseV1 response = stamp.timbrarV1(xml, "test@test.com.mx, test@test2.com.mx", null, false, false);
2359+
List<String> email = Arrays.asList("test@test.com.mx");
2360+
StampResponseV1 response = stamp.timbrarV1(xml, email, null, false, false);
23582361

23592362
//Para obtener el estatus
23602363
System.out.println(response.getStatus());
@@ -2392,7 +2395,8 @@ public class App {
23922395
IssueV4 stamp = new IssueV4("http://services.test.sw.com.mx", "user", "password", null, 0);
23932396
byte[] xml = Files.readAllBytes(Paths.get("file.xml"));
23942397
String xml64 = Base64.getEncoder().encodeToString(xml);
2395-
StampResponseV1 response = stamp.timbrarV1(xml, "test@test.com.mx, test@test2.com.mx", null, false, false);
2398+
List<String> email = Arrays.asList("test@test.com.mx");
2399+
StampResponseV1 response = stamp.timbrarV1(xml, email, null, false, false);
23962400

23972401
//Para obtener el estatus
23982402
System.out.println(response.getStatus());
@@ -2434,8 +2438,9 @@ public class App {
24342438
//A esta le pasamos la Url, usuario y password o token
24352439
//Automaticamente despues de obtenerlo se procedera a timbrar
24362440
IssueJsonV4 stamp = new IssueJsonV4("http://services.test.sw.com.mx", "user", "password", null, 0);
2441+
List<String> email = Arrays.asList("test@test.com.mx");
24372442
String json = new String(Files.readAllBytes(Paths.get("pruebas.json")), "UTF-8");
2438-
StampResponseV1 response = stamp.timbrarV1(json, "test@test.com.mx, test@test2.com.mx", null, false);
2443+
StampResponseV1 response = stamp.timbrarV1(json, email, null, false);
24392444

24402445
//Para obtener el estatus
24412446
System.out.println(response.getStatus());

src/main/java/mx/com/sw/helpers/GeneralValidations.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,17 @@ protected void validateCustomId(String customId) throws ServicesException{
8989
* @param emails
9090
* @throws ServicesException
9191
*/
92-
protected boolean validateEmails(String emails) throws ServicesException {
93-
List<String> emailList = Arrays.asList(emails.split("\\s*,\\s*"));
94-
if (emailList.size() > 0 && emailList.size() <= 5) {
95-
for (int i = 0; i <= emailList.size() - 1; i++) {
96-
Pattern pattern = Pattern
97-
.compile("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$");
98-
Matcher matcher = pattern.matcher(emailList.get(i));
99-
if (!matcher.matches()) {
100-
throw new ServicesException(
101-
"El listado de correos no contiene un formato válido o alguno de los correos es inválido."
102-
);
103-
}
104-
}
105-
} else {
92+
protected boolean validateEmails(List<String> emails) throws ServicesException {
93+
if (emails.isEmpty() || emails.size() > 5) {
10694
throw new ServicesException("El listado de correos está vacío o contiene más de 5 correos.");
10795
}
96+
Pattern emailPattern = Pattern.compile("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$");
97+
for (String email : emails) {
98+
Matcher matcher = emailPattern.matcher(email);
99+
if (!matcher.matches()) {
100+
throw new ServicesException("El listado de correos no contiene un formato válido o alguno de los correos es inválido.");
101+
}
102+
}
108103
return true;
109104
}
110105
}

0 commit comments

Comments
 (0)