maia/.svn/pristine/96/96bcdcf55853f74afe0bf9b99ce...

243 lines
13 KiB
Plaintext
Executable File

package com.fp.person.rules.save;
import com.fp.common.helper.Constant;
import com.fp.dto.Response;
import com.fp.dto.data.SaveData;
import com.fp.dto.rules.TransactionRule;
import com.fp.dto.save.SaveRequest;
import com.fp.general.exception.GeneralException;
import com.fp.persistence.commondb.NestedSave;
import com.fp.persistence.commondb.PersistenceHelper;
import com.fp.persistence.pcustomer.gene.TcustPersonDetail;
import com.fp.persistence.pcustomer.gene.TcustPersonDetailKey;
import com.fp.persistence.pcustomer.people.TcustPeople;
import com.fp.persistence.pgeneral.date.TgeneAccountingDateBranch;
import com.fp.persistence.pgeneral.gene.OptmListaNegra;
import com.fp.persistence.pgeneral.gene.TgeneConsepLog;
import com.fp.sessionbeans.helper.Sequence;
import java.sql.Timestamp;
import java.util.List;
/**
*
* @author hinga
*/
public abstract class VerifyInConsep extends TransactionRule {
/**
* Metodo q busca personas que se encuentre en la lista de CONSEP y guarda auditoria de la misma
*
* @param pSaveRequest Objeto que almacena referencia a las tablas de que intervienen en el proceso con sus datos.
* @param ldata lista de objetos OptmListaNegra
* @param personId Identificación de la persona.
* @throws Exception
*/
protected void fillConsep(SaveRequest pSaveRequest, List<OptmListaNegra> ldata, String personId, String firsname, String middlename, String lastname, String surename, String transaction, boolean continueSave) throws Exception {
Response resp = pSaveRequest.getResponse();
TgeneAccountingDateBranch db = com.fp.persistence.commondb.db.DataHelper.getInstance().getTgeneAccountingDateBranch(
pSaveRequest.getCompany(), 0);
Timestamp datenow = new Timestamp(db.getWorkingdate().getTime());
Integer cod = this.getLogId();
resp.setResponseCode("TIME-0016");
boolean verifysindicado = false;
String saveorupdate = "N";
if (ldata != null && !ldata.isEmpty()) {
String message = "";
for (OptmListaNegra obj : ldata) {
if (message.compareTo("") != 0) {
message += "<br/>";
}
message += "(" + obj.getNombre() + " " + obj.getApellido() + ") " + "SE ENCUENTRA REGISTRADA EN LA TABLA DE CONSEP - ";
if (obj.getId_tiplisneg() == 1) {
verifysindicado = true;
saveorupdate = "N";
message += "SINDICADO";
} else if (obj.getId_tiplisneg() == 2 && "YES".equals((String) pSaveRequest.get("lisnegcontinue"))) {
saveorupdate = "S";
message += "HOMÓNIMO";
} else {
message += "HOMÓNIMO";
}
pSaveRequest.putSaveBean("TGENECONSEP", obj);
}
for (OptmListaNegra obj : ldata) {
this.saveConsepLog(pSaveRequest, obj, personId, firsname, middlename, lastname, surename, cod, transaction, datenow, saveorupdate);
cod = cod + 1;
}
if (verifysindicado && transaction.equals("N")) {
if (!continueSave) {
throw new GeneralException("CUST-0002", "<br/>" + message + "<br/>NO SE PUEDE REGISTRAR EL CLIENTE");
}
} else if (verifysindicado && transaction.equals("U")) {
resp.setResponseUserMessage(message);
} else {
if ("YES".equals((String) pSaveRequest.get("lisnegcontinue"))) {
resp.setResponseUserMessage(message);
} else {
if (!continueSave) {
throw new GeneralException("CUST-0003", "<br/>" + message + "<br/>NO SE REGISTRO EL CLIENTE");
}
}
}
} else {
pSaveRequest.putSaveBean("TGENECONSEP", null);
TgeneConsepLog tgeneConsepLog = new TgeneConsepLog();
tgeneConsepLog.setPk(cod);
tgeneConsepLog.setIdentificacion(personId);
tgeneConsepLog.setNombre_prim(firsname);
tgeneConsepLog.setNombre_seg(middlename);
tgeneConsepLog.setApellido_prim(lastname);
tgeneConsepLog.setApellido_seg(surename);
tgeneConsepLog.setId_listanegra("0");
tgeneConsepLog.setId_tiplisneg(0L);
tgeneConsepLog.setFec_ing_lisneg(null);
tgeneConsepLog.setUsuario_cod(pSaveRequest.getUser());
tgeneConsepLog.setFec_transaccion(datenow);//FormatDates.getInstance().getDataBaseTimestamp()
tgeneConsepLog.setTerminal(pSaveRequest.getTerminalCode());
tgeneConsepLog.setTransaccion(transaction);
if ("N".equals(transaction)) {
tgeneConsepLog.setCreacion_cli("S");
tgeneConsepLog.setActualizacion_cli("N");
} else {
tgeneConsepLog.setCreacion_cli("N");
tgeneConsepLog.setActualizacion_cli("S");
}
tgeneConsepLog.setConstancia_consep("N");
//Envia el bean a la base de datos en una session independiente
NestedSave nestedSave = new NestedSave(pSaveRequest.getCompany(), tgeneConsepLog);
nestedSave.start();
//sb.join(); NO HABILITAR Espera a la ejecuciond el hijo.
resp.setResponseUserMessage("LA PERSONA NO SE ENCUENTRA REGISTRADA EN LA TABLA DEL CONSEP");
}
}
/**
* Metodo que guarda auditoria de los registros de CONSEP
*
* @param pSaveRequest
* @param optmListaNegra
* @param identificationConsep
* @param firsname
* @param middlename
* @param lastname
* @param surename
* @param cod
* @param transac
* @param datenow
* @param saveorupdate
* @throws Exception
*/
private void saveConsepLog(SaveRequest pSaveRequest, OptmListaNegra optmListaNegra, String identificationConsep, String firsname,
String middlename, String lastname, String surename, Integer cod, String transac, Timestamp datenow, String saveorupdate) throws Exception {
TgeneConsepLog tgeneConsepLog = new TgeneConsepLog();
tgeneConsepLog.setPk(cod);
tgeneConsepLog.setIdentificacion(identificationConsep);
tgeneConsepLog.setNombre_prim(firsname);
tgeneConsepLog.setNombre_seg(middlename);
tgeneConsepLog.setApellido_prim(lastname);
tgeneConsepLog.setApellido_seg(surename);
tgeneConsepLog.setId_listanegra(optmListaNegra.getPk());
tgeneConsepLog.setId_tiplisneg(optmListaNegra.getId_tiplisneg());
tgeneConsepLog.setFec_ing_lisneg(optmListaNegra.getFec_ing_lisneg());
tgeneConsepLog.setUsuario_cod((String) pSaveRequest.get("user"));
tgeneConsepLog.setFec_transaccion(datenow);//FormatDates.getInstance().getDataBaseTimestamp()
tgeneConsepLog.setTerminal((String) pSaveRequest.get("terminalCode"));
tgeneConsepLog.setTransaccion(transac);
if ("N".equals(transac)) {
tgeneConsepLog.setCreacion_cli(saveorupdate);
tgeneConsepLog.setActualizacion_cli("N");
} else {
tgeneConsepLog.setCreacion_cli("N");
tgeneConsepLog.setActualizacion_cli("S");
}
tgeneConsepLog.setConstancia_consep("S");
NestedSave nestedSave = new NestedSave(pSaveRequest.getCompany(), tgeneConsepLog);
nestedSave.start();
}
/**
* Metodo que verifica que si cambian la identificaci&oacute;n no se encuentre SINDICADA
*
* @param tcustPeople
* @param pSaveRequest
* @param identificationConsep
* @throws Exception
*/
protected void verifyChangeIdentificationPeople(TcustPeople tcustPeople, SaveRequest pSaveRequest, String identificationConsep) throws Exception {
if (tcustPeople != null) {
TcustPersonDetail tcustPersonDetailUpdate = (TcustPersonDetail) pSaveRequest.getSaveBeanModifiedObject("TCUSTPERSONDETAIL");
if (tcustPersonDetailUpdate != null && tcustPersonDetailUpdate.getIdentification() != null) {
TcustPersonDetailKey tcustPersonDetailKey = new TcustPersonDetailKey((Integer) pSaveRequest.get("personcode"), Constant.getDefaultExpiryTimestamp());
TcustPersonDetail tcustPersonDetail = TcustPersonDetail.find(PersistenceHelper.getEntityManager(), tcustPersonDetailKey);
if (tcustPersonDetail != null && tcustPersonDetail.getIdentification() != null
&& tcustPersonDetailUpdate.getIdentification().compareTo(tcustPersonDetail.getIdentification()) != 0) {
List<OptmListaNegra> ldata = OptmListaNegra.find(PersistenceHelper.getEntityManager(), identificationConsep);
if (ldata != null && !ldata.isEmpty()) {
Integer cod = this.getLogId();
TgeneAccountingDateBranch db = com.fp.persistence.commondb.db.DataHelper.getInstance().getTgeneAccountingDateBranch(
pSaveRequest.getCompany(), 0);
Timestamp datenow = new Timestamp(db.getWorkingdate().getTime());
for (int i = 0; i < ldata.size(); i++) {
OptmListaNegra optmListaNegra = ldata.get(i);
if (optmListaNegra != null) {
if (optmListaNegra.getId_tiplisneg() != null && String.valueOf(optmListaNegra.getId_tiplisneg()).compareTo("1") == 0) {
this.saveConsepLog(pSaveRequest, optmListaNegra, identificationConsep, tcustPeople.getFirstname(), tcustPeople.getMiddlename(),
tcustPeople.getLastname(), tcustPeople.getSurename(), cod, "U", datenow, null);
throw new GeneralException("CUST-0008", "NO SE PUEDE CAMBIAR LA IDENTIFICACIÓN YA QUE ESTA SE ENCUENTRA COMO SINDICADA");
}
}
}
}
}
}
}
}
/**
* Metodo para grabar auditoria de personas juridicas en cambio de identificacion si esta como SINDICADA
*
* @param pSaveRequest
* @param identificationConsep
* @throws Exception
*/
protected void verifyChangeIdentificationPeople(SaveRequest pSaveRequest, String identificationConsep) throws Exception {
TcustPersonDetail tcustPersonDetailUpdate = (TcustPersonDetail) pSaveRequest.getSaveBeanModifiedObject("TCUSTPERSONDETAIL");
if (tcustPersonDetailUpdate != null && tcustPersonDetailUpdate.getIdentification() != null) {
TcustPersonDetailKey tcustPersonDetailKey = new TcustPersonDetailKey((Integer) pSaveRequest.get("personcode"), Constant.getDefaultExpiryTimestamp());
TcustPersonDetail tcustPersonDetail = TcustPersonDetail.find(PersistenceHelper.getEntityManager(), tcustPersonDetailKey);
if (tcustPersonDetail != null && tcustPersonDetail.getIdentification() != null
&& tcustPersonDetailUpdate.getIdentification().compareTo(tcustPersonDetail.getIdentification()) != 0) {
List<OptmListaNegra> ldata = OptmListaNegra.find(PersistenceHelper.getEntityManager(), identificationConsep);
if (ldata != null && !ldata.isEmpty()) {
Integer cod = this.getLogId();
TgeneAccountingDateBranch db = com.fp.persistence.commondb.db.DataHelper.getInstance().getTgeneAccountingDateBranch(
pSaveRequest.getCompany(), 0);
Timestamp datenow = new Timestamp(db.getWorkingdate().getTime());
for (int i = 0; i < ldata.size(); i++) {
OptmListaNegra optmListaNegra = ldata.get(i);
if (optmListaNegra != null) {
if (optmListaNegra.getId_tiplisneg() != null && String.valueOf(optmListaNegra.getId_tiplisneg()).compareTo("1") == 0) {
this.saveConsepLog(pSaveRequest, optmListaNegra, identificationConsep, tcustPersonDetail.getName(), null,
null, null, cod, "U", datenow, null);
throw new GeneralException("CUST-0008", "NO SE PUEDE CAMBIAR LA IDENTIFICACIÓN YA QUE ESTA SE ENCUENTRA COMO SINDICADA");
}
}
}
}
}
}
}
/**
* Metodoq ue obtiene la secuencia para guardar los logs
*
* @return
* @throws Exception
*/
protected Integer getLogId() throws Exception {
Sequence sequence = new Sequence();
Integer personcode = Integer.valueOf(sequence.getNextValue("LOGCONSEP").toString());
return personcode;
}
}