288 lines
9.2 KiB
Plaintext
Executable File
288 lines
9.2 KiB
Plaintext
Executable File
package com.fp.frontend.controller.armas.solicitud;
|
||
|
||
import java.util.ArrayList;
|
||
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 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.pgeneral.gene.CatalogDetailController;
|
||
import com.fp.frontend.controller.pgeneral.menu.MenuController;
|
||
import com.fp.frontend.controller.security.ProfileController;
|
||
import com.fp.frontend.helper.MessageHelper;
|
||
import com.fp.persistence.parmas.soli.TarmDocumentoAlfresco;
|
||
import com.fp.persistence.pgeneral.gene.TgeneCatalogDetail;
|
||
import com.fp.persistence.pgeneral.safe.TsafeProfile;
|
||
|
||
/**
|
||
* Controlador principal del mantenimiento de documentos alfresco
|
||
* @author Manuel Cepeda
|
||
*
|
||
*/
|
||
@SuppressWarnings("serial")
|
||
@ManagedBean
|
||
@ViewScoped
|
||
public class MantenimientoDocumentosAlfrescoController extends AbstractController<TarmDocumentoAlfresco> {
|
||
|
||
@ManagedProperty(value = "#{menuController}")
|
||
private MenuController menuController;
|
||
|
||
/**
|
||
* Lista de perfiles asociados al usuario que hace login a la aplicacion.
|
||
*/
|
||
private List<TsafeProfile> lprofile;
|
||
|
||
/**
|
||
* Listado de estados del arma
|
||
*/
|
||
private List<TgeneCatalogDetail> ltipodocumento;
|
||
|
||
/**
|
||
* Listado de estados del arma
|
||
*/
|
||
private List<TgeneCatalogDetail> ldocumento;
|
||
|
||
private String[] selectedDocumentos;
|
||
|
||
|
||
|
||
public MantenimientoDocumentosAlfrescoController() throws Exception {
|
||
super(TarmDocumentoAlfresco.class);
|
||
}
|
||
|
||
/**
|
||
* Método que se ejecuta después del constructor
|
||
*/
|
||
@PostConstruct
|
||
private void postconstruct() {
|
||
this.init();
|
||
super.startQuery();
|
||
setLprofile(ProfileController.find());
|
||
querydatabase();
|
||
}
|
||
|
||
|
||
/**
|
||
* Inicializa valores del controlador
|
||
*/
|
||
private void init() {
|
||
try {
|
||
recperpage = 15; // Cambiar al # reg a mirar.
|
||
lrecord = new ArrayList<>();
|
||
record = new TarmDocumentoAlfresco();
|
||
beanalias = "DOCUMENTOALFRESCO";
|
||
ltipodocumento = CatalogDetailController.find("TIPODOCUMENTO");
|
||
ldocumento = CatalogDetailController.find("DOCUMENTO");
|
||
|
||
} catch (Exception e) {
|
||
MessageHelper.setMessageError(e);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
@SuppressWarnings("unchecked")
|
||
@Override
|
||
protected void querydatabase() {
|
||
try {
|
||
DtoQuery dto = super.getDtoQuery(true);
|
||
dto.setOrderby("pk");
|
||
|
||
// subqueries 1
|
||
SubQuery subqueryPerfil = new SubQuery("TsafeProfile", "description", "perfilDescription", "i.pk = t.perfil");
|
||
dto.addSubQuery(subqueryPerfil);
|
||
|
||
SubQuery subqueryTipoDocumento = new SubQuery("TgeneCatalogDetail","description","tipoDocumento","i.pk.catalog=t.catalogo and i.pk.catalogcode=t.catalogoCode");
|
||
dto.addSubQuery(subqueryTipoDocumento);
|
||
|
||
HashMap<String, DtoQuery> mtables = new HashMap<String, DtoQuery>();
|
||
mtables.put(this.beanalias, dto); // permite adicionar mas de una tabla.
|
||
|
||
Request request = this.callerhelper.getRequest();
|
||
request.setQueryTables(mtables);
|
||
request.put("queryalias", "DOCUMENTOALFRESCOCOMPLETE");
|
||
Response resp = this.callerhelper.executeQuery(request);
|
||
|
||
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) != 0) {
|
||
this.lrecord = new ArrayList<TarmDocumentoAlfresco>();
|
||
MessageHelper.setMessageError(resp);
|
||
} else {
|
||
this.lrecord = (List<TarmDocumentoAlfresco>) resp.get(this.beanalias);
|
||
if(!lrecord.isEmpty()){
|
||
record=lrecord.get(0);
|
||
}
|
||
super.postQuery(this.lrecord);
|
||
}
|
||
} catch (Throwable e) {
|
||
MessageHelper.setMessageError(e);
|
||
}
|
||
}
|
||
|
||
/*/
|
||
* Permite obtener elementos de la entidad TarmDocumentoAlfresco dado el perfil
|
||
*/
|
||
public static List<TarmDocumentoAlfresco> findByProfile(String perfil) {
|
||
try {
|
||
MantenimientoDocumentosAlfrescoController cc = new MantenimientoDocumentosAlfrescoController();
|
||
cc.init();
|
||
cc.recperpage = 5000;
|
||
cc.addFilter("perfil", perfil);
|
||
cc.querydatabase();
|
||
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
|
||
return cc.lrecord;
|
||
}
|
||
return null;
|
||
} catch (Throwable e) {
|
||
MessageHelper.setMessageError(e);
|
||
return null;
|
||
}
|
||
}
|
||
|
||
|
||
@Override
|
||
public void next() throws Exception {
|
||
// TODO Auto-generated method stub
|
||
super.next();
|
||
}
|
||
|
||
@Override
|
||
public void save() {
|
||
try {
|
||
List<TarmDocumentoAlfresco> listaNueva = new ArrayList<>();
|
||
for(TarmDocumentoAlfresco tarmDocumentoAlfresco : lrecord){
|
||
for(TarmDocumentoAlfresco documentoAlfresco : listaNueva){
|
||
if(tarmDocumentoAlfresco.getModifiedData().get("perfilDescription").equals(documentoAlfresco.getModifiedData().get("perfilDescription"))
|
||
&& tarmDocumentoAlfresco.getModifiedData().get("tipoDocumento").equals(documentoAlfresco.getModifiedData().get("tipoDocumento"))){
|
||
MessageHelper.setMessageError(" Ya se encuentra creada una combinaci<63>n: " + tarmDocumentoAlfresco.getModifiedData().get("perfilDescription") + " - " + tarmDocumentoAlfresco.getModifiedData().get("tipoDocumento"));
|
||
return;
|
||
}
|
||
}
|
||
listaNueva.add(tarmDocumentoAlfresco);
|
||
}
|
||
|
||
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(this.beanalias, dtosave);
|
||
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 update() throws Exception {
|
||
record.setCatalogoCode("TIPODOCUMENTO");
|
||
record.setDocumento("");
|
||
if(menuController.findPerfil(record.getPerfil()) != null){
|
||
record.getModifiedData().put("perfilDescription", menuController.findPerfil(record.getPerfil()).getDescription());
|
||
}
|
||
if(CatalogDetailController.findxCodigoCodcatalogo(record.getCatalogo(), record.getCatalogoCode()) != null){
|
||
record.getModifiedData().put("tipoDocumento", CatalogDetailController.findxCodigoCodcatalogo(record.getCatalogo(), record.getCatalogoCode()).getDescription());
|
||
}
|
||
for(String documento : selectedDocumentos){
|
||
if(record.getDocumento() == null || "".equals(record.getDocumento())){
|
||
record.setDocumento(documento);
|
||
}else{
|
||
record.setDocumento(record.getDocumento() + ", " + documento);
|
||
}
|
||
|
||
}
|
||
super.update();
|
||
}
|
||
|
||
public void updateAutorizacion()throws Exception {
|
||
super.update();
|
||
}
|
||
|
||
/**
|
||
* Método que se ejecuta al carga edición
|
||
* @throws Exception
|
||
*/
|
||
public void loadEdit() throws Exception {
|
||
setSelectedDocumentos(record.getDocumento().split(", "));
|
||
}
|
||
|
||
|
||
@Override
|
||
public void create() throws Exception {
|
||
setSelectedDocumentos(null);
|
||
super.create();
|
||
}
|
||
|
||
public void update(TarmDocumentoAlfresco bean) throws Exception {
|
||
record=bean;
|
||
updateAutorizacion();
|
||
}
|
||
|
||
public void actualizar(TarmDocumentoAlfresco arma) throws Exception{
|
||
record=arma;
|
||
super.update();
|
||
}
|
||
|
||
public List<TsafeProfile> getLprofile() {
|
||
return lprofile;
|
||
}
|
||
|
||
public void setLprofile(List<TsafeProfile> lprofile) {
|
||
this.lprofile = lprofile;
|
||
}
|
||
|
||
public MenuController getMenuController() {
|
||
return menuController;
|
||
}
|
||
|
||
public void setMenuController(MenuController menuController) {
|
||
this.menuController = menuController;
|
||
}
|
||
|
||
public List<TgeneCatalogDetail> getLtipodocumento() {
|
||
return ltipodocumento;
|
||
}
|
||
|
||
public void setLtipodocumento(List<TgeneCatalogDetail> ltipodocumento) {
|
||
this.ltipodocumento = ltipodocumento;
|
||
}
|
||
|
||
public List<TgeneCatalogDetail> getLdocumento() {
|
||
return ldocumento;
|
||
}
|
||
|
||
public void setLdocumento(List<TgeneCatalogDetail> ldocumento) {
|
||
this.ldocumento = ldocumento;
|
||
}
|
||
|
||
/**
|
||
* @return the selectedDocumentos
|
||
*/
|
||
public String[] getSelectedDocumentos() {
|
||
return selectedDocumentos;
|
||
}
|
||
|
||
/**
|
||
* @param selectedDocumentos the selectedDocumentos to set
|
||
*/
|
||
public void setSelectedDocumentos(String[] selectedDocumentos) {
|
||
this.selectedDocumentos = selectedDocumentos;
|
||
}
|
||
|
||
}
|