package com.fp.frontend.controller.armas.funcionalidad; import java.util.ArrayList; 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 javax.faces.context.FacesContext; import org.primefaces.context.RequestContext; 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.frontend.controller.AbstractController; import com.fp.frontend.controller.alfresco.AlfrescoController; import com.fp.frontend.controller.armas.parametros.CentroControlArmasController; import com.fp.frontend.controller.armas.parametros.TarmCentroControlJurController; import com.fp.frontend.controller.armas.parametros.TarmVentaArmaTemporalController; import com.fp.frontend.controller.pcustomer.PersonAddressController; import com.fp.frontend.controller.pgeneral.gene.CatalogDetailController; import com.fp.frontend.helper.MessageHelper; import com.fp.persistence.parmas.fun.TarmVentaArmaTem; import com.fp.persistence.parmas.param.TarmCentroControl; import com.fp.persistence.parmas.param.TarmCentroControlJur; import com.fp.persistence.parmas.soli.TarmArmas; import com.fp.persistence.pcustomer.gene.TcustPersonAddress; import com.fp.persistence.pgeneral.gene.TgeneCatalogDetail; import com.fp.persistence.pgeneral.safe.TsafeUserDetail; /** * @author CP * Clase Controladora flujo venta de armas */ @ManagedBean @ViewScoped public class VentaTraspasoDominioController extends AbstractController { public VentaTraspasoDominioController() throws Exception { super(TarmArmas.class); } private static final long serialVersionUID = 1L; /** * Constante usada para referirse a la opcion general aprobar */ private final String APROBAR = "APR"; /** * Opciones de aceptar o rechazar */ private List accionList; /** * numero de solicitud */ private String numerosolicitud; /** * Numero del arma a vender */ private String csolicitud; /** * Accion tomada por el usuario, aprobar o rechazar */ private String accionTomada; /** * Propiedad usada para el manejo del Alfresco */ @ManagedProperty(value = "#{alfrescoController}") private AlfrescoController alfrescoController; @PostConstruct private void postconstruct() { startQuery(); this.getMfilters().clear(); accionList=CatalogDetailController.find("ACCION"); } public void startQuery() { try { this.pasteBpmScreenParameters(); //codigo del arma carma pk csolicitud=super.getMfilters().get("csolicitud"); //codigo persona compra numerosolicitud=super.getMfilters().get("numerosolicitud"); this.getMfilters().clear(); querydatabase(); for (TarmArmas item : this.lrecord) { TarmVentaArmaTem ventaArma=TarmVentaArmaTemporalController.findPendienteCarma(item.getPk()); if(ventaArma!=null){ item.getModifiedData().put("pathdocumento", ventaArma.getPathdocumento()); } } } catch (Exception e) { MessageHelper.setMessageError(e); } } @SuppressWarnings("unchecked") @Override public void querydatabase() { try { DtoQuery dto = super.getDtoQuery(true); SubQuery subqueryMarca= new SubQuery("TgeneCatalogDetail","description","marca","i.pk.catalog=t.marca and i.pk.catalogcode=t.marcacodigo"); dto.addSubQuery(subqueryMarca); SubQuery subqueryColor= new SubQuery("TgeneCatalogDetail","description","color","i.pk.catalog=t.color and i.pk.catalogcode=t.colorcodigo"); dto.addSubQuery(subqueryColor); SubQuery subqueryEstado= new SubQuery("TgeneCatalogDetail","description","estado","i.pk.catalog=t.estado and i.pk.catalogcode=t.estadocodigo"); dto.addSubQuery(subqueryEstado); SubQuery subqueryLonguitud= new SubQuery("TgeneCatalogDetail","description","longitud","i.pk.catalog=(select o.longitud from TarmTipoArmaExplosivo o where o.pk=t.ctipoarmaexplosivo) and " + " i.pk.catalogcode=(select o.longitudcodigo from TarmTipoArmaExplosivo o where o.pk=t.ctipoarmaexplosivo)"); dto.addSubQuery(subqueryLonguitud); SubQuery subqueryClase= new SubQuery("TgeneCatalogDetail","description","clase","i.pk.catalog=(select o.clase from TarmTipoArmaExplosivo o where o.pk=t.ctipoarmaexplosivo) and " + " i.pk.catalogcode=(select o.clasecodigo from TarmTipoArmaExplosivo o where o.pk=t.ctipoarmaexplosivo)"); dto.addSubQuery(subqueryClase); SubQuery subqueryTipoArma= new SubQuery("TgeneCatalogDetail","description","tipoarmaexplosivo","i.pk.catalog=(select o.tipoarmaexplosivo from TarmTipoArmaExplosivo o where o.pk=t.ctipoarmaexplosivo) and " + " i.pk.catalogcode=(select o.tipoarmaexplosivocodigo from TarmTipoArmaExplosivo o where o.pk=t.ctipoarmaexplosivo)"); dto.addSubQuery(subqueryTipoArma); SubQuery subqueryCalibre= new SubQuery("TgeneCatalogDetail","description","calibre","i.pk.catalog=(select o.calibre from TarmTipoArmaExplosivo o where o.pk=t.ctipoarmaexplosivo) and " + " i.pk.catalogcode=(select o.calibrecodigo from TarmTipoArmaExplosivo o where o.pk=t.ctipoarmaexplosivo)"); dto.addSubQuery(subqueryCalibre); SubQuery subqueryUnidad= new SubQuery("TgeneCatalogDetail","description","unidadmedidapeso","i.pk.catalog=(select o.unidadmedidapeso from TarmTipoArmaExplosivo o where o.pk=t.ctipoarmaexplosivo) and " + " i.pk.catalogcode=(select o.unidadmedidapesocodigo from TarmTipoArmaExplosivo o where o.pk=t.ctipoarmaexplosivo)"); dto.addSubQuery(subqueryUnidad); dto.setOrderby("lote, ctipoarmaexplosivo,cregistro"); Filter filtro=new Filter(); String filtroCarma= "t.pk='"+csolicitud+"' and t.estadoventa='PENVEN'"; filtro.setSql(filtroCarma); dto.addFiltro(filtro); HashMap mtables = new HashMap(); mtables.put(this.beanalias, dto); // permite adicionar mas de una tabla. Request request = this.callerhelper.getRequest(); request.setQueryTables(mtables); // request.put("queryalias", "ARMASCOMPLETE"); Response resp = this.callerhelper.executeQuery(request); if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) != 0) { this.lrecord = new ArrayList(); MessageHelper.setMessageError(resp); } else { this.lrecord = (List) resp.get(this.beanalias); super.postQuery(this.lrecord); } } catch (Throwable e) { MessageHelper.setMessageError(e); } } /* (non-Javadoc) * @see com.fp.frontend.controller.AbstractController#postCommit(com.fp.dto.Response) */ @Override public void postCommit(Response response) throws Exception { super.postCommit(response); } /** * Método 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("BPMObs", bpmDataComment == null ? "OK" : bpmDataComment); //mail Map datosmail = new HashMap(); datosmail.put("sol", numerosolicitud); TarmCentroControl centroControl= obtenerCentroControl(); datosmail.put("centrocontrol",(centroControl==null || centroControl.getNombreinstitucion()==null || centroControl.getNombreinstitucioncodigo()==null)?"":CatalogDetailController.findxCodigoCodcatalogo( centroControl.getNombreinstitucion(), centroControl.getNombreinstitucioncodigo()).getDescription()); // Completar tarea en el flujo if(accionTomada.equalsIgnoreCase(APROBAR)){ request.modifiedData().put("BPMStatus", "A"); datosmail.put("observaciones", "Aprobada"); }else{ request.modifiedData().put("BPMStatus", "D"); datosmail.put("observaciones", "Rechazada"); } request.modifiedData().put("datosmail", datosmail); request.modifiedData().put("csolicitud", csolicitud);//nuemro del arma carma pk request.modifiedData().put("numerosolicitud", numerosolicitud); Response resp = this.callerhelper.executeSave(request); if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) == 0) { this.postCommit(resp); MessageHelper.setMessageInfo(resp); RequestContext.getCurrentInstance().execute("Maia.refreshusertasks()"); this.clearAll(); } else { MessageHelper.setMessageError(resp); } } catch (Exception e) { e.printStackTrace(); } catch (Throwable e) { e.printStackTrace(); } } /** * Método para obtener el centro de control * @throws Exception */ private TarmCentroControl obtenerCentroControl() throws Exception { try { TsafeUserDetail tsafeUserDetail = (TsafeUserDetail) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("TSAFEUSERDETAIL"); PersonAddressController personAddressController = new PersonAddressController(); TcustPersonAddress tcustPersonAddres=personAddressController.findPrincipal(tsafeUserDetail.getPk().getPersoncode().toString()); TarmCentroControlJur centroControlJur= TarmCentroControlJurController.findxProvincia(tcustPersonAddres.getProvincecode()); TarmCentroControl centroControl= CentroControlArmasController.findPorCodigo(centroControlJur.getCcentrocontrol()); return centroControl; } catch (Exception e) { e.getMessage(); } return null; } public List getAccionList() { return accionList; } public void setAccionList(List accionList) { this.accionList = accionList; } public String getAccionTomada() { return accionTomada; } public void setAccionTomada(String accionTomada) { this.accionTomada = accionTomada; } public AlfrescoController getAlfrescoController() { return alfrescoController; } public void setAlfrescoController(AlfrescoController alfrescoController) { this.alfrescoController = alfrescoController; } }