293 lines
11 KiB
Plaintext
Executable File
293 lines
11 KiB
Plaintext
Executable File
package com.fp.frontend.controller.armas.solicitud;
|
|
|
|
import java.sql.Date;
|
|
import java.util.ArrayList;
|
|
import java.util.Calendar;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import javax.annotation.PostConstruct;
|
|
import javax.faces.bean.ManagedBean;
|
|
import javax.faces.bean.ManagedProperty;
|
|
import javax.faces.bean.ViewScoped;
|
|
|
|
import org.primefaces.context.RequestContext;
|
|
import org.primefaces.event.FileUploadEvent;
|
|
import org.primefaces.event.SelectEvent;
|
|
import org.primefaces.model.UploadedFile;
|
|
|
|
import com.fp.dto.Request;
|
|
import com.fp.dto.Response;
|
|
import com.fp.dto.query.DtoQuery;
|
|
import com.fp.dto.query.Filter;
|
|
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.enums.EnumLovOption;
|
|
import com.fp.frontend.helper.MessageHelper;
|
|
import com.fp.persistence.parmas.soli.TarmDocumentoHabilitante;
|
|
import com.fp.persistence.pcustomer.gene.TcustPersonDetail;
|
|
|
|
/**
|
|
* Controlador para listar los documentos habilitantes del sistema
|
|
*
|
|
*/
|
|
|
|
@ManagedBean
|
|
@ViewScoped
|
|
public class PermisosAutorizacionesAnularController extends AbstractController<TarmDocumentoHabilitante> {
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
@ManagedProperty(value = "#{alfrescoController}")
|
|
private AlfrescoController alfrescoController;
|
|
|
|
private TcustPersonDetail tcustPersonDetail;
|
|
|
|
|
|
/**
|
|
* Variable que nos permite cargar el documento al Alfresco
|
|
*/
|
|
private UploadedFile uploadedFile;
|
|
|
|
public PermisosAutorizacionesAnularController() throws Exception{
|
|
super(TarmDocumentoHabilitante.class);
|
|
}
|
|
|
|
@PostConstruct
|
|
public void postConstruct() {
|
|
this.init();
|
|
super.startQuery();
|
|
}
|
|
|
|
private void init(){
|
|
this.beanalias = "PERMISOSAUTORIZACIONES";
|
|
this.recperpage = 15;
|
|
this.lrecord = new ArrayList<>();
|
|
}
|
|
|
|
@SuppressWarnings({ "unchecked", "deprecation" })
|
|
@Override
|
|
protected void querydatabase() {
|
|
try {
|
|
if(!this.getMfilters().containsKey("personcode") || this.getMfilters().get("personcode")==null){
|
|
MessageHelper.setMessageError("SELECCIONE UNA IDENTIFICACI\u00d3N");
|
|
return;
|
|
}
|
|
DtoQuery dto = super.getDtoQuery(Boolean.TRUE);
|
|
HashMap<String, DtoQuery> mtables = new HashMap<String, DtoQuery>();
|
|
//nombre
|
|
SubQuery snombre= new SubQuery
|
|
("TcustPersonDetail", "name", "nombre", "i.pk.personcode = t.personcode and i.pk.dateto=(select max(dt.pk.dateto) from TcustPersonDetail dt where dt.pk.personcode=t.personcode)");
|
|
dto.addSubQuery(snombre);
|
|
SubQuery snumerodocumento= new SubQuery
|
|
("TcustPersonDetail", "identification", "identification", "i.pk.personcode = t.personcode and i.pk.dateto=(select max(dt.pk.dateto) from TcustPersonDetail dt where dt.pk.personcode=t.personcode)");
|
|
dto.addSubQuery(snumerodocumento);
|
|
SubQuery subqueryCategoriaCodigo= new SubQuery("TgeneCatalogDetail", "description", "description", "i.pk.catalog = (select a.tipotramite from TarmTramite a where a.pk=t.ctramite)"
|
|
+ "and i.pk.catalogcode=(select a.tipotramitecodigo from TarmTramite a where a.pk=t.ctramite)");
|
|
dto.addSubQuery(subqueryCategoriaCodigo);
|
|
|
|
SubQuery subqueryipoAutorizacion= new SubQuery("TgeneCatalogDetail", "description", "descriptionTipoAut", "i.pk.catalog = (select a.tipoautorizacion from TarmTramite a where a.pk=t.ctramite)"
|
|
+ "and i.pk.catalogcode=(select a.tipoautorizacioncodigo from TarmTramite a where a.pk=t.ctramite)");
|
|
dto.addSubQuery(subqueryipoAutorizacion);
|
|
|
|
SubQuery subqueryTipocodigo=new SubQuery("TgeneCatalogDetail", "description", "descriptiontram", "i.pk.catalog = (select a.categoria from TarmTramite a where a.pk=t.ctramite)"
|
|
+ "and i.pk.catalogcode=(select a.categoriacodigo from TarmTramite a where a.pk=t.ctramite)");
|
|
dto.addSubQuery(subqueryTipocodigo);
|
|
SubQuery subqueryUsocodigo=new SubQuery("TgeneCatalogDetail", "description", "descriptionact", "i.pk.catalog = (select a.usoactividad from TarmTramite a where a.pk=t.ctramite)"
|
|
+ "and i.pk.catalogcode=(select a.usoactividadcodigo from TarmTramite a where a.pk=t.ctramite)");
|
|
dto.addSubQuery(subqueryUsocodigo);
|
|
SubQuery subqueryEstadoDoc=new SubQuery("TgeneCatalogDetail", "description", "estadodocumento", "i.pk.catalog = t.estado"
|
|
+ " and i.pk.catalogcode= t.estadocode");
|
|
dto.addSubQuery(subqueryEstadoDoc);
|
|
|
|
dto.setOrderby("t.fechaemision desc");
|
|
//filtro
|
|
Filter filtroFinal = new Filter();
|
|
String sqlFinal= " t.fechaemision is not null ";
|
|
filtroFinal.setSql(sqlFinal);
|
|
dto.addFiltro(filtroFinal);
|
|
|
|
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<>();
|
|
MessageHelper.setMessageError(resp);
|
|
} else {
|
|
lrecord = (List<TarmDocumentoHabilitante>) resp.get(beanalias);
|
|
java.util.Date fecha2=new java.util.Date();
|
|
fecha2.setHours(0);
|
|
fecha2.setMinutes(0);
|
|
fecha2.setSeconds(0);
|
|
for (TarmDocumentoHabilitante item : lrecord) {
|
|
item.getModifiedData().put("btnanular", Boolean.TRUE);
|
|
java.util.Date fecha1=new java.util.Date(item.getFechaexpiracion().getTime()) ;
|
|
fecha1.setHours(0);
|
|
fecha1.setMinutes(0);
|
|
fecha1.setSeconds(0);
|
|
if(fecha1.getTime()<fecha2.getTime()){
|
|
item.getModifiedData().put("btnanular", Boolean.FALSE);
|
|
}
|
|
}
|
|
super.postQuery(lrecord);
|
|
}
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
public void update() throws Exception{
|
|
record.setEstado("SUS");
|
|
record.setFechacambioexpiracion(record.getFechaexpiracion());
|
|
record.setFechaexpiracion(new Date(new java.util.Date().getTime()));
|
|
//Valida si el archivo esta adjunto
|
|
String xPathLocation= getRutaDocumentoSolBase() + "/cm:I-" +record.getModifiedData().get("identification")+ "/cm:C-" + record.getCodigoarma() ;
|
|
if(uploadedFile!=null && uploadedFile.getFileName()!=null){
|
|
String extencionArchivo=getExtension(uploadedFile.getFileName());
|
|
String nombreArchivo = "SUS-"+this.record.getCodigoarma()+"."+extencionArchivo;
|
|
if(alfrescoController.uploadFile(uploadedFile.getInputstream(),nombreArchivo, xPathLocation)){
|
|
record.setPathSuspencion(xPathLocation + "/cm:" + nombreArchivo);
|
|
}else{
|
|
MessageHelper.setMessageError("Adjunte el documento");
|
|
return;
|
|
}
|
|
}else{
|
|
MessageHelper.setMessageError("Adjunte el documento");
|
|
return;
|
|
}
|
|
super.update();
|
|
}
|
|
@Override
|
|
public void save() {
|
|
try {
|
|
Request request = this.callerhelper.getRequest();
|
|
DtoSave dtosave = super.getDtoSave();
|
|
if(!dtosave.pendingProcess()){
|
|
return;
|
|
}
|
|
HashMap<String, DtoSave> msave = new HashMap<String, DtoSave>();
|
|
msave.put(this.beanalias, dtosave); // adicionar metadata de mantenimiento para cada tabla.
|
|
request.setSaveTables(msave);
|
|
Response resp = this.callerhelper.executeSave(request);
|
|
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) == 0) {
|
|
this.postCommit(resp);
|
|
querydatabase();
|
|
MessageHelper.setMessageInfo(resp);
|
|
} else {
|
|
MessageHelper.setMessageError(resp);
|
|
}
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
public static void openLov() {
|
|
Map<String, Object> options = new HashMap<String, Object>();
|
|
// hint: ver EnumLovOption para las opciones del modal
|
|
options.put(EnumLovOption.MODAL.getLabel(), true);
|
|
options.put(EnumLovOption.HEIGHT.getLabel(), 450);
|
|
options.put(EnumLovOption.WIDTH.getLabel(), 700);
|
|
options.put(EnumLovOption.RESIZABLE.getLabel(), true);
|
|
// lovpersona es el nombre de la pagina
|
|
RequestContext.getCurrentInstance().openDialog("/pages/customer/lov/personLov.xhtml", options, null);
|
|
}
|
|
|
|
|
|
/**
|
|
* Maneja la respuesta del Lov de Personas
|
|
* @param event
|
|
* @throws Exception
|
|
*/
|
|
public void onReturnPersonLov(SelectEvent event) throws Exception {
|
|
tcustPersonDetail = (TcustPersonDetail) event.getObject();
|
|
this.getMfilters().put("personcode",tcustPersonDetail.getPk().getPersoncode().toString());
|
|
this.query();
|
|
}
|
|
|
|
/**
|
|
* Retorna la ruta base donde se almacenara dicho archivo
|
|
*
|
|
* @return
|
|
*/
|
|
public String getRutaDocumentoSolBase() {
|
|
Calendar calendar = Calendar.getInstance();
|
|
calendar.setTime(new java.util.Date());
|
|
StringBuilder ruta = new StringBuilder("cm:Suspencion");
|
|
ruta = ruta.append("/cm:Suspencion-");
|
|
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();
|
|
}
|
|
|
|
/**
|
|
* Metodo que retorna la extencion del documento que se desea subir al alfresco
|
|
*/
|
|
public String getExtension(String filename) {
|
|
int index = filename.lastIndexOf('.');
|
|
if (index == -1) {
|
|
return "";
|
|
} else {
|
|
return filename.substring(index + 1);
|
|
}
|
|
}
|
|
/**
|
|
* Recorta el nombre del archivo a cargarse
|
|
* @param nombre
|
|
* @return nombre recortado
|
|
*/
|
|
public String recorteNombre(String nombre){
|
|
String fielname=nombre;
|
|
if(fielname.length()>30){
|
|
fielname=fielname.substring(0,30)+extencionArchivo(nombre);
|
|
}
|
|
return fielname;
|
|
}
|
|
/**
|
|
* Obtiene la extencion del archivo a cargar
|
|
* @param nombre
|
|
* @return
|
|
*/
|
|
private String extencionArchivo(String nombre){
|
|
int pos=nombre.lastIndexOf('.');
|
|
nombre=nombre.substring(pos);
|
|
return nombre;
|
|
}
|
|
/**
|
|
* Carga el archivo a grabar en la memoria para su posterior persistencia en el Alfresco
|
|
*/
|
|
public void handleUpload(FileUploadEvent event){
|
|
uploadedFile = event.getFile();
|
|
}
|
|
|
|
public TcustPersonDetail getTcustPersonDetail() {
|
|
return tcustPersonDetail;
|
|
}
|
|
|
|
public void setTcustPersonDetail(TcustPersonDetail tcustPersonDetail) {
|
|
this.tcustPersonDetail = tcustPersonDetail;
|
|
}
|
|
|
|
public AlfrescoController getAlfrescoController() {
|
|
return alfrescoController;
|
|
}
|
|
|
|
public void setAlfrescoController(AlfrescoController alfrescoController) {
|
|
this.alfrescoController = alfrescoController;
|
|
}
|
|
|
|
public UploadedFile getUploadedFile() {
|
|
return uploadedFile;
|
|
}
|
|
|
|
public void setUploadedFile(UploadedFile uploadedFile) {
|
|
this.uploadedFile = uploadedFile;
|
|
}
|
|
|
|
}
|