314 lines
11 KiB
Plaintext
Executable File
314 lines
11 KiB
Plaintext
Executable File
package com.fp.frontend.controller.armas.solicitud;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Calendar;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
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.event.ActionEvent;
|
|
|
|
import org.apache.commons.io.FilenameUtils;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.primefaces.event.FileUploadEvent;
|
|
|
|
import com.fp.common.helper.Constant;
|
|
import com.fp.dto.Request;
|
|
import com.fp.dto.Response;
|
|
import com.fp.dto.query.DtoQuery;
|
|
import com.fp.dto.query.SubQuery;
|
|
import com.fp.dto.save.DtoSave;
|
|
import com.fp.frontend.controller.AbstractController;
|
|
import com.fp.frontend.controller.alfresco.AlfrescoController;
|
|
import com.fp.frontend.controller.armas.RequisitoPorTipoTramiteController;
|
|
import com.fp.frontend.helper.MessageHelper;
|
|
import com.fp.persistence.parmas.param.TarmRequisitoPorTipoTramite;
|
|
import com.fp.persistence.parmas.soli.TarmSolicitudRequisitos;
|
|
import com.fp.persistence.parmas.soli.TarmSolicitudRequisitosKey;
|
|
|
|
/**
|
|
* Clase controladora del bean TarmSolicitud.
|
|
*
|
|
* @author Jorge Vaca.
|
|
* @version 2.1
|
|
*/
|
|
@SuppressWarnings("serial")
|
|
@ManagedBean
|
|
@ViewScoped
|
|
public class SolicitudRequisitosController extends AbstractController<TarmSolicitudRequisitos> {
|
|
|
|
@ManagedProperty(value = "#{alfrescoController}")
|
|
private AlfrescoController alfrescoController;
|
|
|
|
private Boolean auxBotonVerificacion;
|
|
|
|
public SolicitudRequisitosController() throws Exception {
|
|
super(TarmSolicitudRequisitos.class);
|
|
}
|
|
|
|
@PostConstruct
|
|
private void postconstruct() {
|
|
this.init();
|
|
// Inicializa autoconsulta
|
|
super.startQuery();
|
|
|
|
}
|
|
|
|
/**
|
|
* Incializa el controlador, cuando se esta utilizando una pagina que utliza el controlador.
|
|
*/
|
|
private void init() {
|
|
try {
|
|
recperpage = 100; // Cambiar al # reg a mirar.
|
|
lrecord = new ArrayList<>();
|
|
beanalias = "REQUISITOPORTIPOTRAMITE";
|
|
auxBotonVerificacion=Boolean.FALSE;
|
|
this.create();
|
|
} catch (Exception e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Crea una instancia de TgeneTransactionProcess y marca el registro como nuevo.
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
@Override
|
|
public void create() throws Exception {
|
|
super.create();
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@Override
|
|
protected void querydatabase() {
|
|
try {
|
|
DtoQuery dto = super.getDtoQuery(true);
|
|
// dto.setOrderby("t.nombre");
|
|
|
|
SubQuery subNombre= new SubQuery
|
|
("TarmRequisito","nombre", "nombre", "i.pk = t.pk.crequisito");
|
|
|
|
dto.addSubQuery(subNombre);
|
|
SubQuery subDesCorta= new SubQuery
|
|
("TarmRequisito","descripcioncorta", "descripcion", "i.pk = t.pk.crequisito");
|
|
|
|
dto.addSubQuery(subDesCorta);
|
|
|
|
HashMap<String, DtoQuery> mtables = new HashMap<String, DtoQuery>();
|
|
mtables.put(beanalias, dto); // permite adicionar mas de una tabla.
|
|
|
|
Request request = callerhelper.getRequest();
|
|
request.setQueryTables(mtables);
|
|
|
|
Response resp = callerhelper.executeQuery(request);
|
|
|
|
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) != 0) {
|
|
lrecord = new ArrayList<TarmSolicitudRequisitos>();
|
|
MessageHelper.setMessageError(resp);
|
|
} else {
|
|
lrecord = (List<TarmSolicitudRequisitos>) resp.get(beanalias);
|
|
super.postQuery(lrecord);
|
|
}
|
|
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void save() {
|
|
try {
|
|
DtoSave dtosave = super.getDtoSave();
|
|
dtosave.setReturnpk(true); // Para que el core devuelva el pk de los registros nuevos.
|
|
HashMap<String, DtoSave> msave = new HashMap<String, DtoSave>();
|
|
|
|
Request request = callerhelper.getRequest();
|
|
msave.put(beanalias, dtosave); // adicionar metadata de mantenimiento para cada tabla.
|
|
|
|
request.setSaveTables(msave);
|
|
Response resp = callerhelper.executeSave(request);
|
|
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) == 0) {
|
|
this.postCommit(resp);
|
|
MessageHelper.setMessageInfo(resp);
|
|
} else {
|
|
MessageHelper.setMessageError(resp);
|
|
}
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void postCommit(Response response) throws Exception {
|
|
super.postCommitGeneric(response, beanalias);
|
|
}
|
|
|
|
public void fijaSolicitud(String csolicitud) throws Exception {
|
|
if (csolicitud == null) {
|
|
return;
|
|
}
|
|
record.getPk().setCsolicitud(csolicitud);
|
|
}
|
|
|
|
public void consultaPorTipoTramite(String ctipotramite) throws Exception {
|
|
if (record == null) {
|
|
super.create();
|
|
}
|
|
List<TarmRequisitoPorTipoTramite> lrequisitos = RequisitoPorTipoTramiteController.find(ctipotramite);
|
|
for (TarmRequisitoPorTipoTramite obj : lrequisitos) {
|
|
TarmSolicitudRequisitosKey key = new TarmSolicitudRequisitosKey();
|
|
key.setCrequisito(obj.getPk().getCrequisito());
|
|
// key.setCtipotramite(obj.getPk().getCtipotramite());
|
|
TarmSolicitudRequisitos sol = new TarmSolicitudRequisitos();
|
|
sol.setPk(key);
|
|
sol.modifiedData.put("nrequisito", obj.modifiedData.get("nrequisito"));
|
|
sol.setCargado("N");
|
|
lrecord.add(sol);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Retorna la ruta de documento base en donde se almacenará dicho archivo
|
|
*
|
|
* @return
|
|
*/
|
|
public String getRutaDocumentoSolBase() {
|
|
Calendar calendar = Calendar.getInstance();
|
|
calendar.setTime(new Date());
|
|
StringBuilder ruta=new StringBuilder("cm:Solicitudes");
|
|
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));
|
|
return ruta.toString();
|
|
}
|
|
|
|
|
|
/**
|
|
* guarda actualiza el numero de documentos subidos a alfresco
|
|
*/
|
|
public void guardarRegistro(ActionEvent event) {
|
|
System.out.println("Actualizo la fila requisito");
|
|
System.out.println(event.getComponent().getAttributes().get("xPathLocation"));
|
|
record.setCargado(Constant.STR_Y);
|
|
}
|
|
|
|
public static List<TarmSolicitudRequisitos> find(String codigoSolicitud) {
|
|
try {
|
|
SolicitudRequisitosController cc = new SolicitudRequisitosController();
|
|
cc.init();
|
|
cc.recperpage = 300;
|
|
cc.addFilter("pk.csolicitud", codigoSolicitud);
|
|
cc.querydatabase();
|
|
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
|
|
return cc.lrecord;
|
|
}
|
|
return null;
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Método para manejar el evento change en el CheckBox
|
|
* @throws Exception
|
|
*/
|
|
public void onActualizar(TarmSolicitudRequisitos bean) throws Exception {
|
|
record=bean;
|
|
update();
|
|
}
|
|
|
|
/**
|
|
* Método para manejar el evento change en el CheckBox
|
|
* @throws Exception
|
|
*/
|
|
public void onChangeAprobado(TarmSolicitudRequisitos principal) throws Exception {
|
|
if (principal.getEstadovalidacion()==null || principal.getEstadovalidacion().equals("N")) {
|
|
principal.setEstadovalidacion("Y");
|
|
} else {
|
|
principal.setEstadovalidacion("N");
|
|
}
|
|
record=principal;
|
|
update();
|
|
validaiones();
|
|
}
|
|
|
|
public void validaiones() {
|
|
auxBotonVerificacion= Boolean.TRUE;
|
|
for(TarmSolicitudRequisitos item:lrecord){
|
|
if(item.getEstadovalidacion()==null || item.getEstadovalidacion().equals("N")){
|
|
auxBotonVerificacion =Boolean.FALSE;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Método de carga de archivos en Alfresco
|
|
* @param event
|
|
*/
|
|
public void uploadRequisitos(FileUploadEvent event) {
|
|
TarmSolicitudRequisitos solicitudRequisitos = null;
|
|
try {
|
|
String xPathLocation = (String) event.getComponent().getAttributes().get("xPathLocation");
|
|
solicitudRequisitos = (TarmSolicitudRequisitos) event.getComponent().getAttributes().get("record");
|
|
String nombreArchivo = "Documento_"+obtieneNombreLimpio(solicitudRequisitos.getModifiedData().get("crequisito") != null ? solicitudRequisitos.getModifiedData().get("crequisito").toString():"")+"."+FilenameUtils.getExtension(event.getFile().getFileName());
|
|
if(solicitudRequisitos != null
|
|
&& alfrescoController.uploadFile(event.getFile().getInputstream(),
|
|
nombreArchivo,
|
|
xPathLocation)){
|
|
solicitudRequisitos.setCargado(Constant.STR_Y);
|
|
solicitudRequisitos.setXpathrequisito(xPathLocation+"/cm:"+nombreArchivo);
|
|
this.record = solicitudRequisitos;
|
|
this.record.setIsnew(Boolean.FALSE);
|
|
this.update();
|
|
}
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Reemplazo un string los caracteres en blanco y reemplazo caracteres especiales
|
|
* @param toConvert
|
|
* @return la cadena convertida
|
|
*/
|
|
private String obtieneNombreLimpio(String toConvert){
|
|
return StringUtils.replaceEach(StringUtils.deleteWhitespace(toConvert),
|
|
new String[]{"\u00e1","\u00e9","\u00ed","\u00f3","\u00fa","\u00c1","\u00c9","\u00cd","\u00d3","\u00da","\u00F1","\u00d1"},
|
|
new String[]{"a","e","i","o","u","A","E","I","O","U","n","N"});
|
|
}
|
|
|
|
/**
|
|
* Entrega el valor de: alfrescoController
|
|
*
|
|
* @return AlfrescoController
|
|
*/
|
|
public AlfrescoController getAlfrescoController() {
|
|
return alfrescoController;
|
|
}
|
|
|
|
/**
|
|
* Fija el valor de: alfrescoController
|
|
*
|
|
* @param alfrescoController Valor a fijar en el atributo.
|
|
*/
|
|
public void setAlfrescoController(AlfrescoController alfrescoController) {
|
|
this.alfrescoController = alfrescoController;
|
|
}
|
|
|
|
public Boolean getAuxBotonVerificacion() {
|
|
return auxBotonVerificacion;
|
|
}
|
|
|
|
public void setAuxBotonVerificacion(Boolean auxBotonVerificacion) {
|
|
this.auxBotonVerificacion = auxBotonVerificacion;
|
|
}
|
|
|
|
}
|