127 lines
4.8 KiB
Plaintext
Executable File
127 lines
4.8 KiB
Plaintext
Executable File
package com.fp.armas.rules.save.webservices;
|
|
|
|
import java.util.Calendar;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
import javax.persistence.Query;
|
|
|
|
import com.fp.common.logger.APPLogger;
|
|
import com.fp.dto.rules.TransactionRule;
|
|
import com.fp.dto.save.SaveRequest;
|
|
import com.fp.persistence.commondb.PersistenceHelper;
|
|
import com.fp.persistence.parmas.soli.TarmDocumentoHabilitante;
|
|
import com.fp.persistence.parmas.soli.TarmSolicitud;
|
|
import com.fp.persistence.pgeneral.gene.TgeneCatalogDetail;
|
|
|
|
/**
|
|
* Actualiza los datos del documento habilitante enviado
|
|
* @author ndominguez
|
|
*
|
|
*/
|
|
public class DocumentoHabilitanteDatos extends TransactionRule {
|
|
|
|
private static final long serialVersionUID = -951465699701916612L;
|
|
public static final String QUERY_SOLICITUD_NUM = "SELECT o FROM TarmSolicitud o WHERE o.numerosolicitud=:numerosolicitud";
|
|
@SuppressWarnings("unchecked")
|
|
@Override
|
|
public SaveRequest normalProcess(SaveRequest pRequest) throws Exception {
|
|
System.out.println(".........ACTUALIZA LOS DATOS DEL TARMDOCUMENTOHABILITANTE...................");
|
|
String respuesta = "0";
|
|
try {
|
|
String numerosolicitud = (String) pRequest.get("NUMEROSOLICITUD");
|
|
Query query = PersistenceHelper.getEntityManager().createQuery(QUERY_SOLICITUD_NUM);
|
|
query.setParameter("numerosolicitud", numerosolicitud);
|
|
List<TarmSolicitud> ltarmSolicitud = query.getResultList();
|
|
if ( ltarmSolicitud != null && !ltarmSolicitud.isEmpty() ) {
|
|
TarmSolicitud tarmSolicitud = ltarmSolicitud.iterator().next();
|
|
Query queryDoc = PersistenceHelper.createQuery("SELECT o FROM TarmDocumentoHabilitante o WHERE o.csolicitud=:csolicitud ");
|
|
queryDoc.setParameter("csolicitud", tarmSolicitud.getPk());
|
|
List<TarmDocumentoHabilitante> documentoHabilitantes = queryDoc.getResultList();
|
|
if(documentoHabilitantes != null && !documentoHabilitantes.isEmpty()){
|
|
TarmDocumentoHabilitante documentoHabilitante = documentoHabilitantes.iterator().next();
|
|
String fileName = null;
|
|
try {
|
|
//Se valida que no tenga caracteres especiales
|
|
fileName = caractersEspeciales(documentoHabilitante.getNumerodocumento());
|
|
} catch (Exception e) {
|
|
respuesta = "2";
|
|
APPLogger.getLogger().error(e.getMessage(), e);
|
|
}
|
|
if (fileName != null) {
|
|
String xpathdocumento = getRutaDocumentoSolBase(documentoHabilitante.getFechaemision(), numerosolicitud, fileName);
|
|
documentoHabilitante.setXpath(xpathdocumento);
|
|
PersistenceHelper.getEntityManager().merge(documentoHabilitante);
|
|
PersistenceHelper.getEntityManager().flush();
|
|
pRequest.getResponse().put("XPATHDOCUMENTOSOLICITUD", documentoHabilitante.getXpath());
|
|
} else {
|
|
respuesta = "1";
|
|
}
|
|
} else {
|
|
respuesta = "1";
|
|
}
|
|
} else {
|
|
respuesta = "1";
|
|
}
|
|
} catch (Throwable e) {
|
|
respuesta = "2";
|
|
APPLogger.getLogger().error(e.getMessage(), e);
|
|
}
|
|
pRequest.getResponse().put("RESPONSESTATUS", respuesta);
|
|
return pRequest;
|
|
}
|
|
|
|
@Override
|
|
public SaveRequest reverseProcess(SaveRequest pRequest) throws Exception {
|
|
return pRequest;
|
|
}
|
|
|
|
/**
|
|
* Método que revisa si una cadena tiene caracteres especiales
|
|
* @param nombre
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
public static String caractersEspeciales(String nombre) throws Exception{
|
|
List<TgeneCatalogDetail> caracteresEsp=TgeneCatalogDetail.find(PersistenceHelper.getEntityManager(),"CARACTERESPECIAL");
|
|
for(TgeneCatalogDetail caract:caracteresEsp){
|
|
if(nombre.contains(caract.getPk().getCatalog())){
|
|
return null;
|
|
}
|
|
}
|
|
String numero="1234567890";
|
|
if(numero.contains(nombre.substring(0, 1))){
|
|
return null;
|
|
}
|
|
if(nombre!=null && nombre.trim().contains(" ")){
|
|
return null;
|
|
}
|
|
if(nombre.length()<9){
|
|
nombre="DOCUMENTO-"+nombre;
|
|
}
|
|
return nombre;
|
|
}
|
|
|
|
/**
|
|
* Retorna la ruta base donde se almacenara dicho archivo
|
|
*
|
|
* @return
|
|
*/
|
|
private String getRutaDocumentoSolBase(Date fechaEmision, String numerosolicitud, String numerodocumento) {
|
|
StringBuilder ruta = null;
|
|
if (fechaEmision != null && numerosolicitud != null
|
|
&& numerodocumento != null) {
|
|
Calendar calendar = Calendar.getInstance();
|
|
calendar.setTime(fechaEmision);
|
|
ruta = new StringBuilder("cm:Solicitud");
|
|
ruta = ruta.append("/cm:A-").append(calendar.get(Calendar.YEAR));
|
|
ruta = ruta.append("/cm:M-").append((calendar.get(Calendar.MONTH)+1) <= 9 ? "0" + (calendar.get(Calendar.MONTH) + 1) : (calendar.get(Calendar.MONTH)+1));
|
|
ruta = ruta.append("/cm:").append(numerosolicitud);
|
|
ruta = ruta.append("/cm:").append(numerodocumento+".pdf");
|
|
}
|
|
return ruta != null ? ruta.toString() : null;
|
|
}
|
|
|
|
|
|
}
|