diff --git a/.classpath b/.classpath
index 090ce48..538a9de 100644
--- a/.classpath
+++ b/.classpath
@@ -19,7 +19,7 @@
-
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
index 3e4748e..0fb1240 100644
--- a/.settings/org.eclipse.jdt.core.prefs
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -42,9 +42,9 @@ org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.lambda.genericSignature=do not generate
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.shareCommonFinallyBlocks=disabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
@@ -169,7 +169,7 @@ org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled
-org.eclipse.jdt.core.compiler.source=1.6
+org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.compiler.storeAnnotations=disabled
org.eclipse.jdt.core.compiler.taskCaseSensitive=enabled
org.eclipse.jdt.core.compiler.taskPriorities=NORMAL,HIGH,NORMAL
diff --git a/README.md b/README.md
index 995fb6e..c923efb 100644
--- a/README.md
+++ b/README.md
@@ -918,6 +918,20 @@ System.out.println(response.message);
System.out.println(response.messageDetail);
```
+## Recuperar XML por UUID ##
+Método para recuperar la información de un XML enviando el UUID de la factura, así como el token de la cuenta en la cual fue timbrada.
+
+```java
+SWStorageService storage = new SWStorageService(Utils.tokenSW, Utils.urlApiSW, null, 0);
+StorageResponse response = (StorageResponse) storage.getXml(UUID.fromString("c75f87db-e059-4a7c-a922-e4b9c871e8c1"));
+System.out.println(response.Status);
+System.out.println(response.HttpStatusCode);
+System.out.println(response.getData);
+//En caso de obtener un error, este puede obtenerse de los campos
+System.out.println(response.message);
+System.out.println(response.messageDetail);
+```
+
# Servicio PDF #
Servicio para generar PDF de un XML previamente timbrado.
Se permite especificar una de las plantillas genericas o una plantilla personalizada en caso de contar con una.
diff --git a/pom.xml b/pom.xml
index e07d1d6..d0c4715 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
ISO-8859-1
SW-JAVA
- 1.0.8.2
+ 1.0.9.1
jar
https://github.com/lunasoft/sw-sdk-java
@@ -107,8 +107,8 @@
+ true
- true
--batch
--pinentry-mode
loopback
@@ -151,6 +151,11 @@
+
+ false
+ false
+ false
+
diff --git a/src/main/java/Services/SWService.java b/src/main/java/Services/SWService.java
index ab17be0..d8f4267 100644
--- a/src/main/java/Services/SWService.java
+++ b/src/main/java/Services/SWService.java
@@ -114,7 +114,7 @@ protected SWService(String token, String URI) {
protected SWService(String token, String URI, String ProxyHost, int ProxyPort) {
Token = token;
- this.URI = URI;
+ this.URIAPI = URI;
this.ProxyHost = ProxyHost;
this.ProxyPort = ProxyPort;
this.time = new Date((long)999999999*100000);
diff --git a/src/main/java/Services/Storage/SWStorageService.java b/src/main/java/Services/Storage/SWStorageService.java
new file mode 100644
index 0000000..bea2f61
--- /dev/null
+++ b/src/main/java/Services/Storage/SWStorageService.java
@@ -0,0 +1,51 @@
+package Services.Storage;
+
+import java.io.IOException;
+import java.util.UUID;
+import Exceptions.AuthException;
+import Exceptions.GeneralException;
+import Services.SWService;
+import Utils.Requests.Storage.StorageOptionsRequest;
+import Utils.Requests.Storage.StorageRequest;
+import Utils.Responses.IResponse;
+
+public class SWStorageService extends SWService {
+ /**
+ * Constructor de la clase.
+ *
+ * @param user correo o usuario de SW
+ * @param password password de SW.
+ * @param URI url base
+ * @param URIAPI base de la API
+ * @param proxyHost ip o dominio de proxy (null si no se utiliza)
+ * @param proxyPort número de puerto de proxy (cualquier valor si proxy es
+ * ull)
+ * @throws AuthException exception en caso de error.
+ */
+ public SWStorageService(String user, String password, String URI, String URIAPI, String proxyHost, int proxyPort)
+ throws AuthException {
+ super(user, password, URI, URIAPI, proxyHost, proxyPort);
+ }
+
+ /**
+ * Constructor de la clase.
+ *
+ * @param token token infinito de SW.
+ * @param URIAPI url base de la API
+ * @param proxyHost ip o dominio de proxy (null si no se utiliza)
+ * @param proxyPort número de puerto de proxy (cualquier valor si proxy es
+ * ull)
+ */
+ public SWStorageService(String token, String URIAPI, String proxyHost, int proxyPort) {
+ super(token, URIAPI, proxyHost, proxyPort);
+ }
+
+ // Metodo para recuperar información de un XML timbrado con SW
+ public IResponse getXml(UUID uuid) throws AuthException, GeneralException, IOException {
+ StorageOptionsRequest settings = new StorageOptionsRequest(getToken(), uuid, getURIAPI(), getProxyHost(),
+ getProxyPort());
+ StorageRequest req = new StorageRequest();
+ req.sendRequest(settings);
+ return req.sendRequest(settings);
+ }
+}
diff --git a/src/main/java/Utils/Constants.java b/src/main/java/Utils/Constants.java
index 18096ee..fa17e32 100644
--- a/src/main/java/Utils/Constants.java
+++ b/src/main/java/Utils/Constants.java
@@ -26,6 +26,7 @@ public class Constants {
public static String PENDIENTES_CANCELAR_PATH = "/pendings/";
public static String TAXPAYERS_PATH = "/taxpayers/";
public static String SAVE_CSD = "/certificates/save";
+ public static String STORAGE_PATH = "/datawarehouse/v1/live/";
public static String DISABLE_SEARCH_CSD = "/certificates/";
public static String LIST_CSD = "/certificates";
public static String REGENERATE_PDF = "/pdf/v1/api/regeneratepdf/";
diff --git a/src/main/java/Utils/Requests/Pdf/PdfRequest.java b/src/main/java/Utils/Requests/Pdf/PdfRequest.java
index a303694..2b51327 100644
--- a/src/main/java/Utils/Requests/Pdf/PdfRequest.java
+++ b/src/main/java/Utils/Requests/Pdf/PdfRequest.java
@@ -2,8 +2,6 @@
import java.io.IOException;
import java.nio.charset.Charset;
-import java.util.UUID;
-
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
@@ -17,7 +15,6 @@
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;
-
import Exceptions.AuthException;
import Exceptions.GeneralException;
import Utils.Helpers.RequestHelper;
diff --git a/src/main/java/Utils/Requests/Storage/StorageOptionsRequest.java b/src/main/java/Utils/Requests/Storage/StorageOptionsRequest.java
new file mode 100644
index 0000000..4c3b282
--- /dev/null
+++ b/src/main/java/Utils/Requests/Storage/StorageOptionsRequest.java
@@ -0,0 +1,18 @@
+package Utils.Requests.Storage;
+
+import java.util.UUID;
+import Utils.Constants;
+import Utils.Requests.IRequest;
+
+public class StorageOptionsRequest extends IRequest {
+ private UUID uuid;
+
+ public StorageOptionsRequest(String token, UUID uuid, String URIAPI, String proxyHost, int proxyPort) {
+ super(token, URIAPI + Constants.STORAGE_PATH, proxyHost, proxyPort);
+ this.uuid = uuid;
+ }
+
+ public UUID getUuid() {
+ return uuid;
+ }
+}
diff --git a/src/main/java/Utils/Requests/Storage/StorageRequest.java b/src/main/java/Utils/Requests/Storage/StorageRequest.java
new file mode 100644
index 0000000..88a9cec
--- /dev/null
+++ b/src/main/java/Utils/Requests/Storage/StorageRequest.java
@@ -0,0 +1,78 @@
+package Utils.Requests.Storage;
+
+import java.io.IOException;
+import org.apache.http.HttpEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+import org.json.JSONException;
+import org.json.JSONObject;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonSyntaxException;
+import Exceptions.AuthException;
+import Exceptions.GeneralException;
+import Utils.Helpers.RequestHelper;
+import Utils.Requests.IRequest;
+import Utils.Requests.IRequestor;
+import Utils.Responses.IResponse;
+import Utils.Responses.Storage.StorageData;
+import Utils.Responses.Storage.StorageResponse;
+
+public class StorageRequest implements IRequestor {
+ StorageData dataXml;
+
+ public IResponse sendRequest(IRequest request)
+ throws GeneralException, AuthException, GeneralException, IOException {
+ try {
+ CloseableHttpClient client = HttpClients.createDefault();
+ HttpGet httpget = new HttpGet(request.URI + ((StorageOptionsRequest) request).getUuid());
+ httpget.setHeader("Authorization", "bearer " + request.Token);
+ RequestHelper.setTimeOut(request.options, 3500);
+ RequestHelper.setProxy(request.options, request.proxyHost, request.proxyPort);
+ httpget.setConfig(request.options.build());
+ CloseableHttpResponse responseB = client.execute(httpget);
+ HttpEntity entity = responseB.getEntity();
+ String responseString = EntityUtils.toString(entity, "UTF-8");
+ int status = responseB.getStatusLine().getStatusCode();
+ client.close();
+ responseB.close();
+
+ if (!responseString.isEmpty() && status < 500) {
+ JSONObject body = new JSONObject(responseString);
+ if (status == 200) {
+ dataXml = deserialize(responseString, StorageData.class);
+ StorageResponse response = new StorageResponse(status, body.getString("status"), "OK", "OK",
+ dataXml);
+ if (response.getData() == null || response.getData().getData().getRecords().size() <= 0) {
+ response.setHttpStatusCode(400);
+ response.setStatus("error");
+ response.setMessage("Bad request.");
+ response.setMessageDetail("El UUID no ha sido encontrado");
+ }
+ return response;
+ } else {
+ StorageResponse response = new StorageResponse(status, body.getString("status"), "OK", "OK",
+ dataXml);
+ return new StorageResponse(status, "error", response.getMessage(), response.getMessageDetail());
+ }
+ } else {
+ return new StorageResponse(status, "error", responseB.getStatusLine().getReasonPhrase(),
+ responseString);
+ }
+ } catch (JSONException e) {
+ throw new GeneralException(500, e.getMessage());
+ }
+
+ }
+
+ public T deserialize(String json, Class contentClass) throws JsonSyntaxException, IOException {
+ if (json == null || json.isEmpty()) {
+ throw new IOException("No se obtuvo respuesta para el request hecho.");
+ }
+ Gson gson = new GsonBuilder().create();
+ return gson.fromJson(json, contentClass);
+ }
+}
diff --git a/src/main/java/Utils/Responses/IResponse.java b/src/main/java/Utils/Responses/IResponse.java
index 679eb21..b352444 100644
--- a/src/main/java/Utils/Responses/IResponse.java
+++ b/src/main/java/Utils/Responses/IResponse.java
@@ -1,21 +1,79 @@
package Utils.Responses;
public abstract class IResponse {
- public int HttpStatusCode ;
+ public int HttpStatusCode;
public String Status;
public String message = null;
public String messageDetail = null;
- //Status error
+ // Status error
public IResponse(int httpStatusCode, String status, String message, String messageDetail) {
HttpStatusCode = httpStatusCode;
Status = status;
this.message = message;
this.messageDetail = messageDetail;
}
- //Status success general
+
+ // Status success general
public IResponse(int httpStatusCode, String status) {
HttpStatusCode = httpStatusCode;
Status = status;
}
+
+ /**
+ * Obtiene el status de la solicitud.
+ * Solo puede ser "success" o "error".
+ * En caso de "success" puede consultar el campo "data".
+ * En caso de "error", consultar "getMessage" y "getMessageDetail".
+ *
+ * @return String
+ */
+ public String getStatus() {
+ return this.Status;
+ }
+
+ public void setStatus(String value) {
+ this.Status = value;
+ }
+
+ /**
+ * En caso de requerirlo se puede modificar el Codigo de respuesta Http..
+ *
+ * @return int
+ */
+ public void setHttpStatusCode(int value) {
+ this.HttpStatusCode = value;
+ }
+
+ /**
+ * Obtiene el mensaje de error obtenido.
+ * Nota: Este valor generalmente solo existe cunado la solicitud
+ * termino con status "error".
+ *
+ * @return String
+ */
+ public String getMessage() {
+ return this.message;
+ }
+
+ public void setMessage(String value) {
+ this.message = value;
+ }
+
+ /**
+ * Obtiene los detalles acerca del mensaje de error.
+ * Útil cuando el mensaje de error no es muy claro.
+ * Nota: Este valor generalmente solo existe cunado la solicitud
+ * termino con status "error".
+ * Nota: Puede ser null.
+ *
+ * @return String
+ */
+ public String getMessageDetail() {
+ return this.messageDetail;
+ }
+
+ public void setMessageDetail(String value) {
+ this.messageDetail = value;
+ }
}
diff --git a/src/main/java/Utils/Responses/Storage/StorageData.java b/src/main/java/Utils/Responses/Storage/StorageData.java
new file mode 100644
index 0000000..6f99dcb
--- /dev/null
+++ b/src/main/java/Utils/Responses/Storage/StorageData.java
@@ -0,0 +1,533 @@
+package Utils.Responses.Storage;
+
+import java.util.List;
+/*Estructura de los datos que se enviaran en el Storage response */
+
+public class StorageData {
+ public Data data;
+
+ public Data getData() {
+ return this.data;
+ }
+
+ public class Data {
+
+ public MetaData metaData;
+ public List records;
+ public String status;
+
+ public MetaData getMetaData() {
+ return this.metaData;
+ }
+
+ public List getRecords() {
+ return this.records;
+ }
+
+ public String getStatus() {
+ return this.status;
+ }
+ }
+
+ public class Records {
+ private String codigoCancelacion;
+ private String statusSAT;
+ private String urlPDF;
+ private String urlAckCfdi;
+ private String urlAckCancellation;
+ private boolean hasAddenda;
+ private String addenda;
+ private String urlAddenda;
+ private String fechaGeneracionPdf;
+ private String idDealer;
+ private String idUser;
+ private String version;
+ private String serie;
+ private String folio;
+ private String fecha;
+ private String numeroCertificado;
+ private Double subTotal;
+ private Double descuento;
+ private Double total;
+ private String moneda;
+ private Double tipoCambio;
+ private String tipoDeComprobante;
+ private String metodoPago;
+ private String formaPago;
+ private String condicionesPago;
+ private String luegarExpedicion;
+ private String emisorRfc;
+ private String emisorNombre;
+ private String regimenFiscal;
+ private String receptorRfc;
+ private String receptorNombre;
+ private String residenciaFiscal;
+ private String numRegIdTrib;
+ private String usoCFDI;
+ private Double totalImpuestosTraslados;
+ private Double totalImpuestosRetencion;
+ private Double trasladosIVA;
+ private Double trasladosIEPS;
+ private Double retencionesISR;
+ private Double retencionesIVA;
+ private Double retencionesIEPS;
+ private Double totalImpuestosLocalesTraslados;
+ private Double totalImpuestosLocalesRetencion;
+ private String complementos;
+ private String uuid;
+ private String fechaTimbrado;
+ private String rfcProvCertif;
+ private String selloCFD;
+ private String urlXml;
+ private String yearMonth;
+ private boolean status;
+
+ public String getCodigoCancelacion() {
+ return codigoCancelacion;
+ }
+
+ public void setCodigoCancelacion(String codigoCancelacion) {
+ this.codigoCancelacion = codigoCancelacion;
+ }
+
+ public String getStatusSAT() {
+ return statusSAT;
+ }
+
+ public void setStatusSAT(String statusSAT) {
+ this.statusSAT = statusSAT;
+ }
+
+ public String getUrlPDF() {
+ return urlPDF;
+ }
+
+ public void setUrlPDF(String urlPDF) {
+ this.urlPDF = urlPDF;
+ }
+
+ public String getUrlAckCfdi() {
+ return urlAckCfdi;
+ }
+
+ public void setUrlAckCfdi(String urlAckCfdi) {
+ this.urlAckCfdi = urlAckCfdi;
+ }
+
+ public String getUrlAckCancellation() {
+ return urlAckCancellation;
+ }
+
+ public void setUrlAckCancellation(String urlAckCancellation) {
+ this.urlAckCancellation = urlAckCancellation;
+ }
+
+ public boolean isHasAddenda() {
+ return hasAddenda;
+ }
+
+ public void setHasAddenda(boolean hasAddenda) {
+ this.hasAddenda = hasAddenda;
+ }
+
+ public String getAddenda() {
+ return addenda;
+ }
+
+ public void setAddenda(String addenda) {
+ this.addenda = addenda;
+ }
+
+ public String getUrlAddenda() {
+ return urlAddenda;
+ }
+
+ public void setUrlAddenda(String urlAddenda) {
+ this.urlAddenda = urlAddenda;
+ }
+
+ public String getFechaGeneracionPdf() {
+ return fechaGeneracionPdf;
+ }
+
+ public void setFechaGeneracionPdf(String fechaGeneracionPdf) {
+ this.fechaGeneracionPdf = fechaGeneracionPdf;
+ }
+
+ public String getIdDealer() {
+ return idDealer;
+ }
+
+ public void setIdDealer(String idDealer) {
+ this.idDealer = idDealer;
+ }
+
+ public String getIdUser() {
+ return idUser;
+ }
+
+ public void setIdUser(String idUser) {
+ this.idUser = idUser;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public String getSerie() {
+ return serie;
+ }
+
+ public void setSerie(String serie) {
+ this.serie = serie;
+ }
+
+ public String getFolio() {
+ return folio;
+ }
+
+ public void setFolio(String folio) {
+ this.folio = folio;
+ }
+
+ public String getFecha() {
+ return fecha;
+ }
+
+ public void setFecha(String fecha) {
+ this.fecha = fecha;
+ }
+
+ public String getNumeroCertificado() {
+ return numeroCertificado;
+ }
+
+ public void setNumeroCertificado(String numeroCertificado) {
+ this.numeroCertificado = numeroCertificado;
+ }
+
+ public Double getSubTotal() {
+ return subTotal;
+ }
+
+ public void setSubTotal(Double subTotal) {
+ this.subTotal = subTotal;
+ }
+
+ public Double getDescuento() {
+ return descuento;
+ }
+
+ public void setDescuento(Double descuento) {
+ this.descuento = descuento;
+ }
+
+ public Double getTotal() {
+ return total;
+ }
+
+ public void setTotal(Double total) {
+ this.total = total;
+ }
+
+ public String getMoneda() {
+ return moneda;
+ }
+
+ public void setMoneda(String moneda) {
+ this.moneda = moneda;
+ }
+
+ public Double getTipoCambio() {
+ return tipoCambio;
+ }
+
+ public void setTipoCambio(Double tipoCambio) {
+ this.tipoCambio = tipoCambio;
+ }
+
+ public String getTipoDeComprobante() {
+ return tipoDeComprobante;
+ }
+
+ public void setTipoDeComprobante(String tipoDeComprobante) {
+ this.tipoDeComprobante = tipoDeComprobante;
+ }
+
+ public String getMetodoPago() {
+ return metodoPago;
+ }
+
+ public void setMetodoPago(String metodoPago) {
+ this.metodoPago = metodoPago;
+ }
+
+ public String getFormaPago() {
+ return formaPago;
+ }
+
+ public void setFormaPago(String formaPago) {
+ this.formaPago = formaPago;
+ }
+
+ public String getCondicionesPago() {
+ return condicionesPago;
+ }
+
+ public void setCondicionesPago(String condicionesPago) {
+ this.condicionesPago = condicionesPago;
+ }
+
+ public String getLuegarExpedicion() {
+ return luegarExpedicion;
+ }
+
+ public void setLuegarExpedicion(String luegarExpedicion) {
+ this.luegarExpedicion = luegarExpedicion;
+ }
+
+ public String getEmisorRfc() {
+ return emisorRfc;
+ }
+
+ public void setEmisorRfc(String emisorRfc) {
+ this.emisorRfc = emisorRfc;
+ }
+
+ public String getEmisorNombre() {
+ return emisorNombre;
+ }
+
+ public void setEmisorNombre(String emisorNombre) {
+ this.emisorNombre = emisorNombre;
+ }
+
+ public String getRegimenFiscal() {
+ return regimenFiscal;
+ }
+
+ public void setRegimenFiscal(String regimenFiscal) {
+ this.regimenFiscal = regimenFiscal;
+ }
+
+ public String getReceptorRfc() {
+ return receptorRfc;
+ }
+
+ public void setReceptorRfc(String receptorRfc) {
+ this.receptorRfc = receptorRfc;
+ }
+
+ public String getReceptorNombre() {
+ return receptorNombre;
+ }
+
+ public void setReceptorNombre(String receptorNombre) {
+ this.receptorNombre = receptorNombre;
+ }
+
+ public String getResidenciaFiscal() {
+ return residenciaFiscal;
+ }
+
+ public void setResidenciaFiscal(String residenciaFiscal) {
+ this.residenciaFiscal = residenciaFiscal;
+ }
+
+ public String getNumRegIdTrib() {
+ return numRegIdTrib;
+ }
+
+ public void setNumRegIdTrib(String numRegIdTrib) {
+ this.numRegIdTrib = numRegIdTrib;
+ }
+
+ public String getUsoCFDI() {
+ return usoCFDI;
+ }
+
+ public void setUsoCFDI(String usoCFDI) {
+ this.usoCFDI = usoCFDI;
+ }
+
+ public Double getTotalImpuestosTraslados() {
+ return totalImpuestosTraslados;
+ }
+
+ public void setTotalImpuestosTraslados(Double totalImpuestosTraslados) {
+ this.totalImpuestosTraslados = totalImpuestosTraslados;
+ }
+
+ public Double getTotalImpuestosRetencion() {
+ return totalImpuestosRetencion;
+ }
+
+ public void setTotalImpuestosRetencion(Double totalImpuestosRetencion) {
+ this.totalImpuestosRetencion = totalImpuestosRetencion;
+ }
+
+ public Double getTrasladosIVA() {
+ return trasladosIVA;
+ }
+
+ public void setTrasladosIVA(Double trasladosIVA) {
+ this.trasladosIVA = trasladosIVA;
+ }
+
+ public Double getTrasladosIEPS() {
+ return trasladosIEPS;
+ }
+
+ public void setTrasladosIEPS(Double trasladosIEPS) {
+ this.trasladosIEPS = trasladosIEPS;
+ }
+
+ public Double getRetencionesISR() {
+ return retencionesISR;
+ }
+
+ public void setRetencionesISR(Double retencionesISR) {
+ this.retencionesISR = retencionesISR;
+ }
+
+ public Double getRetencionesIVA() {
+ return retencionesIVA;
+ }
+
+ public void setRetencionesIVA(Double retencionesIVA) {
+ this.retencionesIVA = retencionesIVA;
+ }
+
+ public Double getRetencionesIEPS() {
+ return retencionesIEPS;
+ }
+
+ public void setRetencionesIEPS(Double retencionesIEPS) {
+ this.retencionesIEPS = retencionesIEPS;
+ }
+
+ public Double getTotalImpuestosLocalesTraslados() {
+ return totalImpuestosLocalesTraslados;
+ }
+
+ public void setTotalImpuestosLocalesTraslados(Double totalImpuestosLocalesTraslados) {
+ this.totalImpuestosLocalesTraslados = totalImpuestosLocalesTraslados;
+ }
+
+ public Double getTotalImpuestosLocalesRetencion() {
+ return totalImpuestosLocalesRetencion;
+ }
+
+ public void setTotalImpuestosLocalesRetencion(Double totalImpuestosLocalesRetencion) {
+ this.totalImpuestosLocalesRetencion = totalImpuestosLocalesRetencion;
+ }
+
+ public String getComplementos() {
+ return complementos;
+ }
+
+ public void setComplementos(String complementos) {
+ this.complementos = complementos;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+
+ public String getFechaTimbrado() {
+ return fechaTimbrado;
+ }
+
+ public void setFechaTimbrado(String fechaTimbrado) {
+ this.fechaTimbrado = fechaTimbrado;
+ }
+
+ public String getRfcProvCertif() {
+ return rfcProvCertif;
+ }
+
+ public void setRfcProvCertif(String rfcProvCertif) {
+ this.rfcProvCertif = rfcProvCertif;
+ }
+
+ public String getSelloCFD() {
+ return selloCFD;
+ }
+
+ public void setSelloCFD(String selloCFD) {
+ this.selloCFD = selloCFD;
+ }
+
+ public String getUrlXml() {
+ return urlXml;
+ }
+
+ public void setUrlXml(String urlXml) {
+ this.urlXml = urlXml;
+ }
+
+ public String getYearMonth() {
+ return yearMonth;
+ }
+
+ public void setYearMonth(String yearMonth) {
+ this.yearMonth = yearMonth;
+ }
+
+ public boolean isStatus() {
+ return status;
+ }
+
+ public void setStatus(boolean status) {
+ this.status = status;
+ }
+
+ }
+
+ public class MetaData {
+
+ public String page;
+ public String perPage;
+ public String pageCount;
+ public String totalCount;
+ public Links links;
+
+ public String getPage() {
+ return this.page;
+ }
+
+ public String getPerPage() {
+ return this.perPage;
+ }
+
+ public String getPageCount() {
+ return this.pageCount;
+ }
+
+ public String getTotalCount() {
+ return this.totalCount;
+ }
+
+ public Links getLinks() {
+ return this.links;
+ }
+ }
+
+ public class Links {
+
+ public String current;
+
+ public String getCurrent() {
+ return this.current;
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/Utils/Responses/Storage/StorageResponse.java b/src/main/java/Utils/Responses/Storage/StorageResponse.java
new file mode 100644
index 0000000..89c8bbc
--- /dev/null
+++ b/src/main/java/Utils/Responses/Storage/StorageResponse.java
@@ -0,0 +1,33 @@
+package Utils.Responses.Storage;
+
+import Utils.Responses.IResponse;
+
+public class StorageResponse extends IResponse {
+
+ private StorageData dataXml;
+
+ /**
+ * Constructor de la clase.
+ *
+ * @param httpStatusCode codigo de respuesta.
+ * @param status status de llamada a API.
+ * @param msg mensaje devuelto por API.
+ * @param msgDetail detalles mensaje de la API.
+ * @param dataXml datos del xml
+ */
+ public StorageResponse(int httpStatusCode, String status, String msg, String msgDetail,
+ StorageData dataXml) {
+ super(httpStatusCode, status, msg, msgDetail);
+ this.dataXml = dataXml;
+
+ }
+
+ public StorageResponse(int httpStatusCode, String status, String msg, String msgDetail) {
+ super(httpStatusCode, status, msg, msgDetail);
+ }
+
+ // Metodo para acceder a los datos de la respuesta
+ public StorageData getData() {
+ return this.dataXml;
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/Tests/Cancelation/SWCancelationServiceTest.java b/src/test/java/Tests/Cancelation/SWCancelationServiceTest.java
index 7f90951..2ea4d75 100644
--- a/src/test/java/Tests/Cancelation/SWCancelationServiceTest.java
+++ b/src/test/java/Tests/Cancelation/SWCancelationServiceTest.java
@@ -220,7 +220,6 @@ public void testCancelationServicePfx_emptyCancelationParams() throws Exception
Assert.assertTrue(response.message.contains("CACFDI33"));
Assert.assertTrue(expected_HttpStatusCode == response.HttpStatusCode);
}
-
// Uuid
@Test
public void testCancelationServiceUuid_authUser() throws Exception {
diff --git a/src/test/java/Tests/Storage/SWStorageServiceTest.java b/src/test/java/Tests/Storage/SWStorageServiceTest.java
new file mode 100644
index 0000000..22a99ed
--- /dev/null
+++ b/src/test/java/Tests/Storage/SWStorageServiceTest.java
@@ -0,0 +1,99 @@
+package Tests.Storage;
+
+import java.io.IOException;
+import java.util.UUID;
+
+import org.junit.Test;
+
+import Services.Storage.SWStorageService;
+import Tests.Utils;
+import Utils.Responses.Storage.StorageResponse;
+
+import org.apache.commons.ssl.Util;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.rules.TestName;
+
+import Exceptions.AuthException;
+import Exceptions.GeneralException;
+
+public class SWStorageServiceTest {
+ @Rule
+ public TestName testName = new TestName();
+
+ /**
+ * Método de UT con token.
+ */
+ @Test
+ public void testGetXmlToken_Success() throws AuthException, GeneralException, IOException {
+ SWStorageService storage = new SWStorageService(Utils.tokenSW, Utils.urlApiSW, null, 0);
+ StorageResponse res = (StorageResponse) storage
+ .getXml(UUID.fromString("c75f84db-e058-4a7c-a902-e4b9c871e8c1"));
+ Assert.assertNotNull(res);
+ Assert.assertEquals(res.Status, "success");
+ Assert.assertNotNull(res.getData());
+ }
+
+ /**
+ * Método de UT con Authentication.
+ */
+ @Test
+ public void testGetXmlAuth_Success() throws AuthException, GeneralException, IOException {
+ SWStorageService storage = new SWStorageService(Utils.userSW, Utils.passwordSW, Utils.urlSW,
+ Utils.urlApiSW, null, 0);
+ StorageResponse res = (StorageResponse) storage
+ .getXml(UUID.fromString("c75f84db-e058-4a7c-a902-e4b9c871e8c1"));
+ Assert.assertNotNull(res);
+ Assert.assertEquals(res.Status, "success");
+ // Assert.assertNotNull(res.getData());
+ // Assert.assertTrue(res.getData().getRecords().size() > 0);
+ }
+
+ /**
+ * Método de UT con token incorrecto.
+ */
+ @Test
+ public void testGetXmlToken_Error() throws AuthException, GeneralException, IOException {
+ SWStorageService storage = new SWStorageService("empty.token.sw", Utils.urlApiSW, null, 0);
+ StorageResponse res = (StorageResponse) storage
+ .getXml(UUID.fromString("c75f84db-e058-4a7c-a902-e4c9c871e8c1"));
+ Assert.assertNotNull(res);
+ Assert.assertTrue(res.Status.equals("error"));
+ Assert.assertTrue(!res.message.isEmpty());
+ }
+
+ /**
+ * Método de UT con Authentication incorrecta pero Uuid correcto.
+ */
+ @Test
+ public void testGetXmlAuthIncorrect_Error() {
+ try {
+ SWStorageService storage = new SWStorageService("user", "pass", Utils.urlSW, Utils.urlApiSW,
+ null, 0);
+ StorageResponse res = (StorageResponse) storage
+ .getXml(UUID.fromString("c75f84db-e058-4a7c-a902-e4b9c871e8c1"));
+ Assert.assertNotNull(res);
+ Assert.assertTrue(res.Status.equals("error"));
+ } catch (AuthException ex) {
+ Utils.showTestLog(testName, ex.getMessage());
+ } catch (GeneralException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Método de UT con uuid incorrecto.
+ */
+ @Test
+ public void testGetXmlUuid_Error() throws AuthException, GeneralException, IOException {
+ SWStorageService storage = new SWStorageService(Utils.tokenSW, Utils.urlApiSW, null, 0);
+ StorageResponse res = (StorageResponse) storage
+ .getXml(UUID.fromString("c75f84db-e058-4b7c-a902-e4b9c871e8c1"));
+ Assert.assertNotNull(res);
+ Assert.assertTrue(res.Status.equals("error"));
+ }
+}
diff --git a/src/test/java/Tests/Utils.java b/src/test/java/Tests/Utils.java
index 575bb24..65ee5c9 100644
--- a/src/test/java/Tests/Utils.java
+++ b/src/test/java/Tests/Utils.java
@@ -23,39 +23,41 @@
import javax.xml.parsers.ParserConfigurationException;
/**
-* Utils
-* Clase auxiliar de UT con datos comunes.
-* @author Eduardo Mares
-* @version 0.0.0.2
-* @since 2022-04-30
-*/
+ * Utils
+ * Clase auxiliar de UT con datos comunes.
+ *
+ * @author Eduardo Mares
+ * @version 0.0.0.2
+ * @since 2022-04-30
+ */
public class Utils {
public static String urlSW = "http://services.test.sw.com.mx";
public static String urlApiSW = "http://api.test.sw.com.mx";
public static String userSW = System.getenv("SDKTEST_USER");
public static String passwordSW = System.getenv("SDKTEST_PASSWORD");
public static String tokenSW = System.getenv("SDKTEST_TOKEN");
-
+
/**
- * Genera un CFDI especifico y lo sella en caso de indicarse.
- * @param fileName
- * @param signed
- * @param version
- * @param isBase64
- * @return String
- */
- public String getCFDI(String fileName, boolean signed, String version, boolean isBase64){
-
+ * Genera un CFDI especifico y lo sella en caso de indicarse.
+ *
+ * @param fileName
+ * @param signed
+ * @param version
+ * @param isBase64
+ * @return String
+ */
+ public String getCFDI(String fileName, boolean signed, String version, boolean isBase64) {
+
String xml = "";
try {
xml = new String(Files.readAllBytes(Paths.get(fileName)), "UTF-8");
- } catch (IOException e) {
+ } catch (IOException e) {
e.printStackTrace();
}
-
+
String cfdi = changeDateAndSign(xml, signed, version);
- if(isBase64){
+ if (isBase64) {
try {
return encodeBase64(cfdi);
} catch (UnsupportedEncodingException e) {
@@ -65,22 +67,23 @@ public String getCFDI(String fileName, boolean signed, String version, boolean i
return cfdi;
}
-
+
/**
- * Genera un CFDI especifico.
- * @param fileName
- * @param isBase64
- * @return String
- */
- public String getJsonCFDI(String fileName, boolean isBase64) {
+ * Genera un CFDI especifico.
+ *
+ * @param fileName
+ * @param isBase64
+ * @return String
+ */
+ public String getJsonCFDI(String fileName, boolean isBase64) {
Gson gson = new Gson();
String xml = "";
try {
xml = new String(Files.readAllBytes(Paths.get(fileName)), "UTF-8");
- } catch (IOException e) {
+ } catch (IOException e) {
e.printStackTrace();
}
-
+
Map data = gson.fromJson(xml, Map.class);
if (data != null) {
UUID uuid = UUID.randomUUID();
@@ -88,8 +91,8 @@ public String getJsonCFDI(String fileName, boolean isBase64) {
data.put("Folio", randomUUIDString + "sdkjava");
data.put("Fecha", getDateCFDI());
}
-
- if(isBase64){
+
+ if (isBase64) {
try {
return encodeBase64(gson.toJson(data));
} catch (UnsupportedEncodingException e) {
@@ -101,11 +104,12 @@ public String getJsonCFDI(String fileName, boolean isBase64) {
}
/**
- * Genera un CFDI único y lo sella en caso de indicarse.
- * @param xml
- * @param signed
- * @return String
- */
+ * Genera un CFDI único y lo sella en caso de indicarse.
+ *
+ * @param xml
+ * @param signed
+ * @return String
+ */
private String changeDateAndSign(String xml, boolean signed, String version) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
@@ -149,17 +153,19 @@ private String changeDateAndSign(String xml, boolean signed, String version) {
}
/**
- * Obtiene la fecha actual en formato necesario para CFDI.
- * @return String
- */
+ * Obtiene la fecha actual en formato necesario para CFDI.
+ *
+ * @return String
+ */
private String getDateCFDI() {
SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
date.setTimeZone(TimeZone.getTimeZone("America/Mexico_City"));
return date.format(new Date());
}
- private String GenerateCadena(Document xml, String version) throws TransformerConfigurationException, TransformerException, URISyntaxException {
-
+ private String GenerateCadena(Document xml, String version)
+ throws TransformerConfigurationException, TransformerException, URISyntaxException {
+
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = null;
transformer = transformerFactory.newTransformer();
@@ -172,51 +178,51 @@ private String GenerateCadena(Document xml, String version) throws TransformerCo
}
private String encodeBase64(String text) throws UnsupportedEncodingException {
- byte[] bytesEncoded = Base64.encodeBase64(text.getBytes("UTF-8"));
+ byte[] bytesEncoded = Base64.encodeBase64(text.getBytes("UTF-8"));
return new String(bytesEncoded);
}
- public String genComercioExterior(boolean isBase64){
+ public String genComercioExterior(boolean isBase64) {
return getCFDI("src/test/resources/CFDI33/ComercioExterior11.xml", true, "3.3", isBase64);
}
- public String genComercioExteriorTimbrePrevio(boolean isBase64){
+ public String genComercioExteriorTimbrePrevio(boolean isBase64) {
return getCFDI("src/test/resources/CFDI33/ComercioExterior11TimbrePrevio.xml", true, "3.3", isBase64);
}
- public String genPagos10(boolean isBase64){
+ public String genPagos10(boolean isBase64) {
return getCFDI("src/test/resources/CFDI33/Pago10.xml", true, "3.3", isBase64);
}
- public String genPagos10TimbrePrevio(boolean isBase64){
+ public String genPagos10TimbrePrevio(boolean isBase64) {
return getCFDI("src/test/resources/CFDI33/Pago10TimbrePrevio.xml", true, "3.3", isBase64);
}
-
- public String genNomina12(boolean isBase64){
+
+ public String genNomina12(boolean isBase64) {
return getCFDI("src/test/resources/CFDI33/Nomina12.xml", true, "3.3", isBase64);
}
- public String genNomina12TimbrePrevio(boolean isBase64){
+ public String genNomina12TimbrePrevio(boolean isBase64) {
return getCFDI("src/test/resources/CFDI33/Nomina12TimbrePrevio.xml", true, "3.3", isBase64);
}
- public String StringgenBasico(boolean isBase64){
+ public String StringgenBasico(boolean isBase64) {
return getCFDI("src/test/resources/CFDI33/CFDI33.xml", true, "3.3", isBase64);
}
-
- public String StringgenBasicoTimbrePrevio(boolean isBase64){
+
+ public String StringgenBasicoTimbrePrevio(boolean isBase64) {
return getCFDI("src/test/resources/CFDI33/CFDI33TimbrePrevio.xml", true, "3.3", isBase64);
}
-
+
public String JsonGenBasico(boolean isBase64) {
return getJsonCFDI("src/test/resources/CFDI33/CFDI33.json", isBase64);
}
- public static boolean isValidB64(String value){
+ public static boolean isValidB64(String value) {
return Base64.isBase64(value.getBytes());
}
- public static String getCertificadoB64(){
+ public static String getCertificadoB64() {
byte[] fileContent;
try {
fileContent = Files.readAllBytes(Paths.get("src/test/resources/CertificadosDePrueba/CSD_EKU9003173C9.key"));
@@ -226,9 +232,9 @@ public static String getCertificadoB64(){
}
return "";
- }
+ }
- public static String getLlaveB64(){
+ public static String getLlaveB64() {
byte[] fileContent;
try {
fileContent = Files.readAllBytes(Paths.get("src/test/resources/CertificadosDePrueba/CSD_EKU9003173C9.key"));
@@ -237,10 +243,10 @@ public static String getLlaveB64(){
e.printStackTrace();
}
- return "";
+ return "";
}
- public String getResource(String fileName){
+ public String getResource(String fileName) {
byte[] fileContent;
try {
fileContent = Files.readAllBytes(Paths.get("src/test/resources/Extras/" + fileName));
@@ -249,9 +255,10 @@ public String getResource(String fileName){
e.printStackTrace();
}
- return "";
+ return "";
}
- public static void showTestLog(TestName testName, String status){
+
+ public static void showTestLog(TestName testName, String status) {
System.out.println(testName.getMethodName());
System.out.println(status + "\n");
}
diff --git a/src/test/resources/CFDI40/CFDI40/CFDI40_Ingreso_Global.json b/src/test/resources/CFDI40/CFDI40/CFDI40_Ingreso_Global.json
index f1d50bb..fc9b17c 100644
--- a/src/test/resources/CFDI40/CFDI40/CFDI40_Ingreso_Global.json
+++ b/src/test/resources/CFDI40/CFDI40/CFDI40_Ingreso_Global.json
@@ -22,7 +22,7 @@
"InformacionGlobal": {
"Periodicidad": "01",
"Meses": "01",
- "Año": "2021"
+ "Año": "2022"
},
"Emisor": {
"Rfc": "EKU9003173C9",
diff --git a/src/test/resources/CFDI40/CFDI40/CFDI40_Ingreso_Global.xml b/src/test/resources/CFDI40/CFDI40/CFDI40_Ingreso_Global.xml
index 8920684..b50e62c 100644
--- a/src/test/resources/CFDI40/CFDI40/CFDI40_Ingreso_Global.xml
+++ b/src/test/resources/CFDI40/CFDI40/CFDI40_Ingreso_Global.xml
@@ -2,7 +2,7 @@
-
+