481 lines
17 KiB
Plaintext
Executable File
481 lines
17 KiB
Plaintext
Executable File
package com.fp.frontend.controller.armas.parametros;
|
|
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.math.BigDecimal;
|
|
import java.sql.Timestamp;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
import javax.annotation.PostConstruct;
|
|
import javax.faces.bean.ManagedBean;
|
|
import javax.faces.bean.ManagedProperty;
|
|
import javax.faces.bean.ViewScoped;
|
|
import javax.faces.context.FacesContext;
|
|
|
|
import org.primefaces.context.RequestContext;
|
|
import org.primefaces.event.FileUploadEvent;
|
|
import org.primefaces.model.UploadedFile;
|
|
|
|
import com.fp.dto.AbstractDataTransport;
|
|
import com.fp.dto.Request;
|
|
import com.fp.dto.Response;
|
|
import com.fp.frontend.controller.AbstractController;
|
|
import com.fp.frontend.controller.alfresco.AlfrescoController;
|
|
import com.fp.frontend.controller.armas.solicitud.DecomisoArmaTransaccionController;
|
|
import com.fp.frontend.controller.armas.solicitud.DocumentoHabilitanteController;
|
|
import com.fp.frontend.controller.armas.solicitud.PlanificacionInspeccionController;
|
|
import com.fp.frontend.controller.armas.solicitud.SolicitudArmasController;
|
|
import com.fp.frontend.controller.armas.solicitud.SolicitudCertificadoController;
|
|
import com.fp.frontend.controller.pcustomer.PersonAddressController;
|
|
import com.fp.frontend.controller.pcustomer.PersonDetailController;
|
|
import com.fp.frontend.controller.pgeneral.gene.CityController;
|
|
import com.fp.frontend.controller.pgeneral.gene.ParametersController;
|
|
import com.fp.frontend.controller.pgeneral.gene.ProvinceController;
|
|
import com.fp.frontend.controller.pgeneral.message.MessageTemplatesController;
|
|
import com.fp.frontend.controller.pgeneral.message.MessageTemplatesDescController;
|
|
import com.fp.frontend.helper.MessageHelper;
|
|
import com.fp.frontend.utility.MsgControlArmas;
|
|
import com.fp.frontend.validators.DocFirmaValidator;
|
|
import com.fp.mail.Mail;
|
|
import com.fp.persistence.parmas.ins.TarmPlanificacionInspeccion;
|
|
import com.fp.persistence.parmas.param.TarmCentroControl;
|
|
import com.fp.persistence.parmas.soli.TarmCertificadoFiscalia;
|
|
import com.fp.persistence.parmas.soli.TarmDecomisoArmaTransaccion;
|
|
import com.fp.persistence.parmas.soli.TarmDocumentoHabilitante;
|
|
import com.fp.persistence.parmas.soli.TarmSolicitud;
|
|
import com.fp.persistence.pcustomer.gene.TcustPersonAddress;
|
|
import com.fp.persistence.pgeneral.gene.TgeneCity;
|
|
import com.fp.persistence.pgeneral.gene.TgeneProvince;
|
|
import com.fp.persistence.pgeneral.message.TgeneMessageTemplates;
|
|
import com.fp.persistence.pgeneral.message.TgeneMessageTemplatesDesc;
|
|
import com.fp.persistence.pgeneral.safe.TsafeUserDetail;
|
|
/**
|
|
* Clase controladora para firmar documentos.
|
|
*
|
|
* @author Carlos Guzman.
|
|
* @version 2.1
|
|
*/
|
|
@SuppressWarnings("serial")
|
|
@ManagedBean
|
|
@ViewScoped
|
|
public class FirmarDocumentoFiscaliaController extends AbstractController<AbstractDataTransport> {
|
|
|
|
private String xpathflujo;
|
|
private String xpathSolicitud;
|
|
private String xpath;
|
|
private String numerosolicitud;
|
|
private String appletCoordenadallx="";
|
|
private String appletCoordenadally="";
|
|
private String appletCoordenadaurx="";
|
|
private String appletCoordenadaury="";
|
|
private String appletLugar="";
|
|
private String appletFirma="";
|
|
private UploadedFile uploadedFile;
|
|
private TsafeUserDetail userDetail;
|
|
private boolean mensajeGuardar=false;
|
|
private boolean mensajeNoFirma=false;
|
|
private String btnFlujo;
|
|
// private TarmSolicitud solicitud;
|
|
private TarmCertificadoFiscalia certificadoFiscalia;
|
|
@ManagedProperty(value = "#{alfrescoController}")
|
|
private AlfrescoController alfrescoController;
|
|
@ManagedProperty(value="#{personAddressController}")
|
|
private PersonAddressController personAddress;
|
|
|
|
/**
|
|
* Constructor
|
|
* @throws Exception
|
|
*/
|
|
public FirmarDocumentoFiscaliaController() throws Exception {
|
|
super(AbstractDataTransport.class);
|
|
}
|
|
|
|
@PostConstruct
|
|
private void postconstruct() {
|
|
startQuery();
|
|
this.init();
|
|
}
|
|
|
|
public void startQuery() {
|
|
try {
|
|
this.pasteBpmScreenParameters();
|
|
numerosolicitud=super.getMfilters().get("csolicitud");
|
|
userDetail=(TsafeUserDetail)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("TSAFEUSERDETAIL");
|
|
|
|
if(userDetail.getPk().getPersoncode()!=null){
|
|
appletFirma = PersonDetailController.find(userDetail.getPk().getPersoncode().toString()).getName() + " " + (new Timestamp(new Date().getTime())).toString().split("\\.")[0];
|
|
// if(creporte!=null && !creporte.equals("null")){
|
|
// PersonAddressController personAddressController = new PersonAddressController();
|
|
// TcustPersonAddress tcustPersonAddres=personAddressController.findPrincipal(userDetail.getPk().getPersoncode().toString());
|
|
// List<TgeneProvince> provinceList = ProvinceController.findPorCodigo("EC", tcustPersonAddres.getProvincecode());
|
|
// appletLugar = provinceList.get(0).getDescription();
|
|
// }
|
|
}
|
|
else{
|
|
appletFirma = "";
|
|
}
|
|
if(numerosolicitud!=null &&!numerosolicitud.equals("null") && numerosolicitud.trim().length()>0){
|
|
certificadoFiscalia = SolicitudCertificadoController.findPorSolicitud(numerosolicitud.trim());
|
|
if(certificadoFiscalia!=null && certificadoFiscalia.getXpathSolicitudArma()!=null){
|
|
xpathflujo = certificadoFiscalia.getXpathSolicitudArma();
|
|
xpathSolicitud = certificadoFiscalia.getXpath();
|
|
}
|
|
Request request = this.callerhelper.getRequest();
|
|
if(request!=null && request.getCentrocontrol()!=null) {
|
|
TarmCentroControl centroControl=CentroControlArmasController.findPorCodigo(request.getCentrocontrol());
|
|
List<TgeneCity> lciudades = CityController.find("EC", centroControl.getProvincecode(), centroControl.getCantoncode());
|
|
appletLugar = lciudades.get(0).getDescription();
|
|
}
|
|
}
|
|
// else if(numerotransaccion!=null && !numerotransaccion.equals("null")){
|
|
// TarmDecomisoArmaTransaccion decomisoArmaTransaccion= DecomisoArmaTransaccionController.find(numerotransaccion);
|
|
// TarmCentroControl centroControl=CentroControlArmasController.findPorCodigo(decomisoArmaTransaccion.getCcentrocontrol());
|
|
// List<TgeneCity> lciudades = CityController.find("EC", centroControl.getProvincecode(), centroControl.getCantoncode());
|
|
// appletLugar = lciudades.get(0).getDescription();
|
|
// }else if(cplanificacion!=null && !cplanificacion.equals("null")){
|
|
// planificacionInspeccion= PlanificacionInspeccionController.findPorCodigo(Long.parseLong(cplanificacion));
|
|
// TarmCentroControl centroControl=CentroControlArmasController.findPorCodigo(planificacionInspeccion.getCcentrocontrol());
|
|
// List<TgeneCity> lciudades = CityController.find("EC", centroControl.getProvincecode(), centroControl.getCantoncode());
|
|
// appletLugar = lciudades.get(0).getDescription();
|
|
// }
|
|
|
|
|
|
super.getMfilters().clear();
|
|
} catch (Exception e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
/**
|
|
* Metodo para extrer solo elnoimbre del archivo
|
|
* @param xpath xpath del archivo en alfresco
|
|
* @return solo la parte correspondiente al nombre del archivo
|
|
*/
|
|
public String soloNombreArchivo(String xpath){
|
|
return xpath.substring(xpath.lastIndexOf(":") + 1,xpath.length());
|
|
}
|
|
/**
|
|
* Incializa el controlador, cuando se esta utilizando una pagina que utliza el controlador.
|
|
*/
|
|
private void init() {
|
|
try {
|
|
this.lrecord = new ArrayList<>();
|
|
this.beanalias = "FIRMARDOCUMENTOCERTIFICADO";
|
|
btnFlujo=null;
|
|
} catch (Exception e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
/* (non-Javadoc)
|
|
* @see com.fp.frontend.controller.AbstractController#querydatabase()
|
|
*/
|
|
@SuppressWarnings("unchecked")
|
|
@Override
|
|
protected void querydatabase() {
|
|
|
|
}
|
|
|
|
/**
|
|
* Metodo que analiza si el archivo tiene la extension permitida
|
|
* @param nombreArchivo
|
|
* @return
|
|
*/
|
|
public Boolean esExtensionDeArchivoPermitida(String nombreArchivo){
|
|
String[]archivosPermitidosLst = {".pdf"};
|
|
for(String extensionValida:archivosPermitidosLst){
|
|
if(nombreArchivo.contains(extensionValida)){
|
|
return Boolean.TRUE;
|
|
}
|
|
}
|
|
return Boolean.FALSE;
|
|
}
|
|
|
|
/**
|
|
* Metodo para grabar el documento en alfresco
|
|
*/
|
|
public void saveWithDocumentAlfresco() {
|
|
try {
|
|
if(uploadedFile!=null && esExtensionDeArchivoPermitida(uploadedFile.getFileName())){
|
|
|
|
if(!uploadedFile.getFileName().equals(xpathflujo.substring( xpathflujo.lastIndexOf(":") + 1,xpathflujo.length()))){
|
|
MessageHelper.setMessageError(MsgControlArmas.getProperty("msg_error_nombrearchivo_xpath"));
|
|
return;
|
|
}
|
|
alfrescoController.uploadFile(uploadedFile.getInputstream(),xpathflujo.substring( xpathflujo.lastIndexOf(":") + 1,xpathflujo.length()), xpathflujo.substring(0,xpathflujo.lastIndexOf(":")-2));
|
|
//completa la tarea
|
|
//completarTarea();
|
|
btnFlujo="ok";
|
|
}
|
|
else if(uploadedFile==null){
|
|
MessageHelper.setMessageError(MsgControlArmas.getProperty("msg_error_sinarchivo"));
|
|
return;
|
|
}
|
|
else{
|
|
MessageHelper.setMessageError(MsgControlArmas.getProperty("msg_error_archivo_firma"));
|
|
return;
|
|
}
|
|
} catch (Exception e) {
|
|
// TODO Auto-generated catch block
|
|
MessageHelper.setMessageError(MsgControlArmas.getProperty("msg_error_archivo_firma"));
|
|
e.printStackTrace();
|
|
return;
|
|
} catch (Throwable e) {
|
|
// TODO Auto-generated catch block
|
|
MessageHelper.setMessageError(MsgControlArmas.getProperty("msg_error_archivo"));
|
|
e.printStackTrace();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void guardarRegistro() {
|
|
|
|
}
|
|
|
|
/**
|
|
* Metodo para finalizar la tarea del flujo
|
|
*/
|
|
public void completarTarea() {
|
|
|
|
try {
|
|
Request request = callerhelper.getRequest();
|
|
// limpiar request para finalizar la tarea.
|
|
super.cleanRequest(request);
|
|
request.modifiedData().put("TID", tid);
|
|
request.modifiedData().put("BPMStatus", "A" ); // A,D,R
|
|
request.modifiedData().put("BPMObs","OK" );
|
|
|
|
Response resp = callerhelper.executeSave(request);
|
|
|
|
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) == 0) {
|
|
MessageHelper.setMessageInfo(resp);
|
|
this.envioCorreoDocumentoAdjunto();
|
|
RequestContext.getCurrentInstance().execute("Maia.refreshusertasks()");
|
|
btnFlujo=null;
|
|
} else {
|
|
MessageHelper.setMessageError(resp);
|
|
}
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Envía el correo de cambio de email
|
|
* @throws Exception
|
|
*/
|
|
private void envioCorreoDocumentoAdjunto() throws Exception{
|
|
Mail m = new Mail();
|
|
m.config(ParametersController.find("MAIL.FROM", "1").getTextvalue(),
|
|
ParametersController.find("MAIL.SMTP.SERVER", "1").getTextvalue(),
|
|
ParametersController.find("MAIL.SMTP.PORT", "1").getNumbervalue().intValue(),
|
|
ParametersController.find("MAIL.SMTP.USER", "1").getTextvalue(),
|
|
ParametersController.find("MAIL.SMTP.PASSWORD", "1").getTextvalue(),
|
|
Boolean.valueOf(ParametersController.find("MAIL.SMTP.AUTH", "1").getTextvalue()),
|
|
Boolean.valueOf(ParametersController.find("MAIL.SMTPS", "1").getTextvalue()));
|
|
TcustPersonAddress mail = personAddress.findPersonaPorDireccionTipoCatalogo(certificadoFiscalia.getPersoncode().toString(), "3");
|
|
m.setTo(personAddress.getRecord().getAddress());
|
|
MessageTemplatesController message = new MessageTemplatesController();
|
|
message.addFilter("pk", "67");
|
|
message.query();
|
|
if(message.getLrecord() != null && !message.getLrecord().isEmpty()){
|
|
TgeneMessageTemplates asunto = message.getLrecord().get(0);
|
|
MessageTemplatesDescController content = new MessageTemplatesDescController();
|
|
content.addFilter("pk.code", "67");
|
|
content.addFilter("pk.languagecode", "ES");
|
|
content.query();
|
|
if(content.getLrecord() != null && !content.getLrecord().isEmpty()){
|
|
TgeneMessageTemplatesDesc descripcionContenido = content.getLrecord().get(0);
|
|
//Velocity.init();
|
|
//VelocityContext context = new VelocityContext();
|
|
//context.put("nombreusuario", this.getLoginController().getRequest().getUser());
|
|
//context.put("clave", this.record.get("newpassword"));
|
|
m.setSubject(asunto.getDescription());
|
|
//StringWriter sw = new StringWriter();
|
|
// String sw=descripcionContenido.getTemplate().replace("$clave", this.record.get("newpassword").toString());
|
|
// sw=sw.replace("$nombreusuario", this.record.get("name")+"");
|
|
//Velocity.evaluate(context, sw, "", descripcionContenido.getTemplate());
|
|
String sw = "Mail de prueba documento habilitante con adjunto";
|
|
m.setCont(sw.toString());
|
|
m.setContentMessageType("text/html");
|
|
// Descargar el documento habilitante a adjuntar
|
|
byte[] bytes = alfrescoController.downloadReturnDocument(this.xpathflujo);
|
|
m.addAttachment("documento.pdf", bytes, "application/pdf");
|
|
// m.addAttachment("Documento Habilitante","C:\\Users\\JALVARADO\\Downloads\\DOC-000362250.pdf");
|
|
m.send();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/* (non-Javadoc)
|
|
* @see com.fp.frontend.controller.AbstractController#save()
|
|
*/
|
|
@Override
|
|
public void save(){}
|
|
|
|
/**
|
|
* Carga el archivo a grabar en la memoria para su posterior persistencia en el Alfresco
|
|
*/
|
|
public void handleUpload(FileUploadEvent event){
|
|
uploadedFile = event.getFile();
|
|
}
|
|
|
|
public AlfrescoController getAlfrescoController() {
|
|
return alfrescoController;
|
|
}
|
|
|
|
public void setAlfrescoController(AlfrescoController alfrescoController) {
|
|
this.alfrescoController = alfrescoController;
|
|
}
|
|
|
|
public String getXpathflujo() {
|
|
return xpathflujo;
|
|
}
|
|
|
|
public void setXpathflujo(String xpathflujo) {
|
|
this.xpathflujo = xpathflujo;
|
|
}
|
|
|
|
|
|
public String getXpath() {
|
|
return xpathSolicitud;
|
|
}
|
|
|
|
public void setXpath(String xpathSolicitud) {
|
|
this.xpathSolicitud = xpathSolicitud;
|
|
}
|
|
|
|
public UploadedFile getUploadedFile() {
|
|
return uploadedFile;
|
|
}
|
|
|
|
public void setUploadedFile(UploadedFile uploadedFile) {
|
|
this.uploadedFile = uploadedFile;
|
|
}
|
|
|
|
public void upload(FileUploadEvent event) {
|
|
uploadedFile = event.getFile();
|
|
try {
|
|
boolean isValid = DocFirmaValidator.validDocSign(uploadedFile.getInputstream());
|
|
if(isValid){
|
|
mensajeNoFirma = false;
|
|
mensajeGuardar = true;
|
|
|
|
}else{
|
|
uploadedFile = null;
|
|
btnFlujo=null;
|
|
mensajeNoFirma = true;
|
|
mensajeGuardar = false;
|
|
MessageHelper.setMessageError(MsgControlArmas.getProperty("msg_error_sinfirmararchivo"));
|
|
}
|
|
} catch (IOException e) {
|
|
MessageHelper.setMessageError(MsgControlArmas.getProperty("msg_error_sinfirmararchivo"));
|
|
}
|
|
|
|
}
|
|
|
|
public String getAppletCoordenadallx() {
|
|
return appletCoordenadallx;
|
|
}
|
|
|
|
public void setAppletCoordenadallx(String appletCoordenadallx) {
|
|
this.appletCoordenadallx = appletCoordenadallx;
|
|
}
|
|
|
|
public String getAppletCoordenadally() {
|
|
return appletCoordenadally;
|
|
}
|
|
|
|
public void setAppletCoordenadally(String appletCoordenadally) {
|
|
this.appletCoordenadally = appletCoordenadally;
|
|
}
|
|
|
|
public String getAppletCoordenadaurx() {
|
|
return appletCoordenadaurx;
|
|
}
|
|
|
|
public void setAppletCoordenadaurx(String appletCoordenadaurx) {
|
|
this.appletCoordenadaurx = appletCoordenadaurx;
|
|
}
|
|
|
|
public String getAppletCoordenadaury() {
|
|
return appletCoordenadaury;
|
|
}
|
|
|
|
public boolean isMensajeGuardar() {
|
|
return mensajeGuardar;
|
|
}
|
|
|
|
public void setMensajeGuardar(boolean mensajeGuardar) {
|
|
this.mensajeGuardar = mensajeGuardar;
|
|
}
|
|
|
|
public void setAppletCoordenadaury(String appletCoordenadaury) {
|
|
this.appletCoordenadaury = appletCoordenadaury;
|
|
}
|
|
|
|
public String getAppletLugar() {
|
|
return appletLugar;
|
|
}
|
|
|
|
public void setAppletLugar(String appletLugar) {
|
|
this.appletLugar = appletLugar;
|
|
}
|
|
|
|
public String getAppletFirma() {
|
|
return appletFirma;
|
|
}
|
|
|
|
public void setAppletFirma(String appletFirma) {
|
|
this.appletFirma = appletFirma;
|
|
}
|
|
|
|
public String getBtnFlujo() {
|
|
return btnFlujo;
|
|
}
|
|
|
|
public void setBtnFlujo(String btnFlujo) {
|
|
this.btnFlujo = btnFlujo;
|
|
}
|
|
|
|
public PersonAddressController getPersonAddress() {
|
|
return personAddress;
|
|
}
|
|
|
|
public void setPersonAddress(PersonAddressController personAddress) {
|
|
this.personAddress = personAddress;
|
|
}
|
|
|
|
public String getXpathSolicitud() {
|
|
return xpathSolicitud;
|
|
}
|
|
|
|
public void setXpathSolicitud(String xpathSolicitud) {
|
|
this.xpathSolicitud = xpathSolicitud;
|
|
}
|
|
|
|
public String getNumerosolicitud() {
|
|
return numerosolicitud;
|
|
}
|
|
|
|
public void setNumerosolicitud(String numerosolicitud) {
|
|
this.numerosolicitud = numerosolicitud;
|
|
}
|
|
|
|
public boolean isMensajeNoFirma() {
|
|
return mensajeNoFirma;
|
|
}
|
|
|
|
public void setMensajeNoFirma(boolean mensajeNoFirma) {
|
|
this.mensajeNoFirma = mensajeNoFirma;
|
|
}
|
|
|
|
|
|
|
|
} |