Skip to content

Commit

Permalink
Merge pull request #73 from lunasoft/release/1.0.7.1
Browse files Browse the repository at this point in the history
Release/1.0.7.1
  • Loading branch information
SwAeyrton authored Oct 6, 2022
2 parents 6a66e73 + e2bef17 commit 3c90775
Show file tree
Hide file tree
Showing 51 changed files with 1,748 additions and 785 deletions.
4 changes: 2 additions & 2 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
</natures>
<filteredResources>
<filter>
<id>1652984931087</id>
<id>1664829736278</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
Expand Down
562 changes: 562 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -916,4 +916,45 @@ System.out.println(response.acuse);
//En caso de obtener error, este puede obtenerse de los siguientes 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.

### Crear instancia de la clase.
* Usuario y contraseña.
```java
SWPdfService app = new SWPdfService(Utils.userSW, Utils.passwordSW, "http://api.test.sw.com.mx", "http://services.test.sw.com.mx");
```
* Token
```java
SWPdfService app = new SWPdfService(Utils.tokenSW, "http://api.test.sw.com.mx");
```
## Generar PDF Default
Generar PDF con plantilla por defecto CFDI 4.0.
```java
PdfResponse response = null;
response = (PdfResponse) app.GeneratePdf(stamp.cfdi, this.logoB64);
```
## Generar PDF Default Extras
Generar PDF con plantilla por defecto CFDI 4.0 con datos adicionales.
```java
HashMap<String, String> extras = new HashMap<String,String>();
PdfResponse response = null;
response = (PdfResponse) app.GeneratePdf(stamp.cfdi, this.logoB64, extras);
```
## Generar PDF Plantilla Generica.
Generar PDF con plantilla generica.
```java
HashMap<String, String> extras = new HashMap<String,String>();
PdfResponse response = null;
response = (PdfResponse) app.GeneratePdf(stamp.cfdi, PdfTemplates.payment20, this.logoB64, extras);
```
## Generar PDF Plantilla Personalizada
Generar PDF especificando una plantilla como string.
```java
HashMap<String, String> extras = new HashMap<String,String>();
PdfResponse response = null;
response = (PdfResponse) app.GeneratePdf(stamp.cfdi, "cfdi40", this.logoB64, extras);
```
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
</properties>
<artifactId>SW-JAVA</artifactId>
<version>1.0.6.7</version>
<version>1.0.7.1</version>
<packaging>jar</packaging>
<scm>
<url>https://github.com/lunasoft/sw-sdk-java</url>
Expand Down
115 changes: 93 additions & 22 deletions src/main/java/Services/Pdf/SWPdfService.java
Original file line number Diff line number Diff line change
@@ -1,47 +1,118 @@
package Services.Pdf;

import java.io.IOException;

import java.util.Map;
import Exceptions.AuthException;
import Exceptions.GeneralException;
import Services.SWService;
import Utils.Helpers.PdfTemplates;
import Utils.Helpers.RequestHelper;
import Utils.Requests.Pdf.PdfOptionsRequest;
import Utils.Requests.Pdf.PdfRequest;
import Utils.Responses.IResponse;


public class SWPdfService extends SWService {

public SWPdfService(String user, String password, String URI) throws AuthException {
super(user, password, URI);
/**
* Crear una instancia de la clase SWPdfService.
* @param user Email del usuario.
* @param password Contrasena del usuario.
* @param urlApi Url API.
* @param url Url Services.
* @throws AuthException
*/
public SWPdfService(String user, String password, String urlApi, String url) throws AuthException {
super(user, password, url, urlApi);
}

public SWPdfService(String token, String URI) {
super(token, URI);
/**
* Crear una instancia de la clase SWPdfService.
* @param token Token de autenticacion.
* @param urlApi Url API.
*/
public SWPdfService(String token, String urlApi) {
super(token, urlApi);
}

public SWPdfService(String user, String password, String URI, String proxyHost, int proxyPort) throws AuthException {
super(user, password, URI, proxyHost, proxyPort);
/**
* Crear una instancia de la clase SWPdfService.
* @param user Email del usuario.
* @param password Contrasena del usuario.
* @param urlApi Url API.
* @param url Url Services.
* @param proxyHost Proxy.
* @param proxyPort Puerto Proxy.
* @throws AuthException
*/
public SWPdfService(String user, String password, String urlApi, String url, String proxyHost, int proxyPort) throws AuthException {
super(user, password, url, urlApi, proxyHost, proxyPort);
}

public SWPdfService(String token, String URI, String proxyHost, int proxyPort) {
super(token, URI, proxyHost, proxyPort);
/**
* Crear una instancia de la clase SWPdfService.
* @param token Token de autenticacion.
* @param urlApi Url API.
* @param proxyHost Proxy.
* @param proxyPort Puerto Proxy.
*/
public SWPdfService(String token, String urlApi, String proxyHost, int proxyPort) {
super(token, urlApi, proxyHost, proxyPort);
}
/**
* Servicio para generar PDF con plantilla por defecto CFDI 4.0
* @param xml String CFDI formato XML.
* @param b64Logo Logo en B64.
* @return {@link Utils.Responses.Pdf.PdfResponse}
* @throws AuthException
* @throws GeneralException
* @throws IOException
*/
public IResponse GeneratePdf(String xml, String b64Logo) throws AuthException, GeneralException, IOException {
PdfOptionsRequest settings = new PdfOptionsRequest(getToken(), RequestHelper.stringEmptyOrNull(getURIAPI()) ? getURI() : getURIAPI(), xml, b64Logo, getProxyHost(), getProxyPort());
PdfRequest req = new PdfRequest();
return req.sendRequest(settings);
}

public IResponse GeneratePdf(String xml) throws AuthException, GeneralException, IOException {
PdfOptionsRequest settings = new PdfOptionsRequest(getToken(),getURI(), xml, getProxyHost(), getProxyPort());
/**
* Servicio para generar PDF con plantilla por defecto CFDI 4.0.
* @param xml String CFDI formato XML.
* @param b64Logo Logo en B64.
* @param extras Especifica datos adicionales.
* @return {@link Utils.Responses.Pdf.PdfResponse}
* @throws AuthException
* @throws GeneralException
* @throws IOException
*/
public IResponse GeneratePdf(String xml, String b64Logo, Map<String, String> extras) throws AuthException, GeneralException, IOException {
PdfOptionsRequest settings = new PdfOptionsRequest(getToken(), RequestHelper.stringEmptyOrNull(getURIAPI()) ? getURI() : getURIAPI(), xml, b64Logo, extras, getProxyHost(), getProxyPort());
PdfRequest req = new PdfRequest();
return req.sendRequest(settings);
}

public IResponse GeneratePdf(String xml, String extras) throws AuthException, GeneralException, IOException {
PdfOptionsRequest settings = new PdfOptionsRequest(getToken(),getURI(), xml, extras, getProxyHost(), getProxyPort());
/**
* Servicio para generar PDF con plantilla personalizada.
* @param xml String CFDI formato XML.
* @param templateId Identificador de la plantilla.
* @param b64Logo Logo en B64.
* @param extras Especifica parametros extras.
* @return {@link Utils.Responses.Pdf.PdfResponse}
* @throws AuthException
* @throws GeneralException
* @throws IOException
*/
public IResponse GeneratePdf(String xml, String templateId, String b64Logo, Map<String, String> extras) throws AuthException, GeneralException, IOException {
PdfOptionsRequest settings = new PdfOptionsRequest(getToken(), RequestHelper.stringEmptyOrNull(getURIAPI()) ? getURI() : getURIAPI(), xml, templateId, b64Logo, extras, getProxyHost(), getProxyPort());
PdfRequest req = new PdfRequest();
return req.sendRequest(settings);
}

public IResponse GeneratePdf(String xml, String extras, String templateId) throws AuthException, GeneralException, IOException {
PdfOptionsRequest settings = new PdfOptionsRequest(getToken(),getURI(), xml, extras, templateId, getProxyHost(), getProxyPort());
/**
* Servicio para generar PDF con plantilla generica.
* @param xml String CFDI formato XML.
* @param templateId Identificador de la plantilla.
* @param b64Logo Logo en B64.
* @param extras Especifica parametros extras.
* @return {@link Utils.Responses.Pdf.PdfResponse}
* @throws AuthException
* @throws GeneralException
* @throws IOException
*/
public IResponse GeneratePdf(String xml, PdfTemplates templateId, String b64Logo, Map<String,String> extras) throws AuthException, GeneralException, IOException {
PdfOptionsRequest settings = new PdfOptionsRequest(getToken(), RequestHelper.stringEmptyOrNull(getURIAPI()) ? getURI() : getURIAPI(), xml, templateId.toString(), b64Logo, extras, getProxyHost(), getProxyPort());
PdfRequest req = new PdfRequest();
return req.sendRequest(settings);
}
Expand Down
47 changes: 38 additions & 9 deletions src/main/java/Services/SWService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

public abstract class SWService {
private String URI;
private String URIAPI;
private String Token = null;
private String User = null;
private String Password = null;
Expand All @@ -24,23 +25,21 @@ public String getToken() throws AuthException, GeneralException, IOException {
}
return Token;
}

public String getUser() {
return User;
}

public String getPassword() {
return Password;
}

public String getURI() {
return URI;
}

public String getURIAPI(){
return URIAPI;
}
public String getProxyHost() {
return ProxyHost;
}

public int getProxyPort() {
return ProxyPort;
}
Expand All @@ -58,8 +57,22 @@ protected SWService(String user, String password, String URI) throws AuthExcepti
} catch (IOException e) {
throw new AuthException(409, e.getMessage());
}
}

}
protected SWService(String user, String password, String URI, String URIAPI) throws AuthException {
User = user;
Password = password;
this.URI = URI;
this.URIAPI = URIAPI;
try {
generateToken();
} catch (AuthException e) {
throw new AuthException(e.getHttpStatusCode(), e.getErrorMSG());
} catch (GeneralException e) {
throw new AuthException(e.getHttpStatusCode(), e.getErrorMSG());
} catch (IOException e) {
throw new AuthException(409, e.getMessage());
}
}
protected SWService(String user, String password, String URI, String ProxyHost, int ProxyPort) throws AuthException {
User = user;
Password = password;
Expand All @@ -76,7 +89,23 @@ protected SWService(String user, String password, String URI, String ProxyHost,
throw new AuthException(409, e.getMessage());
}
}

protected SWService(String user, String password, String URI, String URIAPI, String ProxyHost, int ProxyPort) throws AuthException {
User = user;
Password = password;
this.ProxyHost = ProxyHost;
this.ProxyPort = ProxyPort;
this.URI = URI;
this.URIAPI = URIAPI;
try {
generateToken();
} catch (AuthException e) {
throw new AuthException(e.getHttpStatusCode(), e.getErrorMSG());
} catch (GeneralException e) {
throw new AuthException(e.getHttpStatusCode(), e.getErrorMSG());
} catch (IOException e) {
throw new AuthException(409, e.getMessage());
}
}
protected SWService(String token, String URI) {
Token = token;
this.URI = URI;
Expand Down Expand Up @@ -109,7 +138,7 @@ public void setPassword(String password) {

public void generateToken() throws AuthException, GeneralException, IOException {
if (User == null || Password == null) {
throw new AuthException(400, "no existen elementos de autenticación");
throw new AuthException(400, "no existen elementos de autenticación");
}
AuthOptionsRequest settings = new AuthOptionsRequest(URI, getUser(), getPassword(), getProxyHost(), getProxyPort());
AuthRequest req = new AuthRequest();
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/Utils/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ public class Constants {
public static String CANCELATION_UUID_PATH = "/cfdi33/cancel/";
public static String BALANCE_ACCOUNT_PATH = "/account/balance/";
public static String VALIDATE_XML_PATH = "/validate/cfdi33";
public static String VALIDATE_LRFC_PATH = "/lrfc/";
public static String VALIDATE_LCO_PATH = "/lco/";
public static String GENERATE_PDF_PATH = "/pdf/v1/generate";
public static String GENERATE_PDF_PATH = "/pdf/v1/api/GeneratePdf";
public static String ACEPTAR_RECHAZAR_CANCELACION_CSD_PATH = "/acceptreject/csd";
public static String ACEPTAR_RECHAZAR_CANCELACION_XML_PATH = "/acceptreject/xml";
public static String ACEPTAR_RECHAZAR_CANCELACION_PFX_PATH = "/acceptreject/pfx";
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/Utils/Helpers/PdfTemplates.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package Utils.Helpers;
/**
* Plantilas Genericas
*/
public enum PdfTemplates {
/**
* CFDI 3.3
*/
cfdi33,
/**
* CFDI 4.0
*/
cfdi40,
/**
* Pagos 1.0
*/
payment,
/**
* Pagos 2.0
*/
payment20,
/**
* Nomina Rev. B
*/
payroll,
/**
* Nomina Rev. C
*/
payroll40,
/**
* Carta Porte 2.0 CFDI 3.3
*/
billoflading20,
/**
* Carta Porte 2.0 CFDI 4.0
*/
billoflading40
}
Loading

0 comments on commit 3c90775

Please sign in to comment.