139 lines
5.7 KiB
Plaintext
Executable File
139 lines
5.7 KiB
Plaintext
Executable File
package com.fp.armas.rules.save.pcustomer;
|
|
|
|
import java.sql.Date;
|
|
import java.sql.Timestamp;
|
|
import java.util.Calendar;
|
|
|
|
import org.apache.velocity.texen.util.FileUtil;
|
|
|
|
import com.fp.dto.rules.TransactionRule;
|
|
import com.fp.dto.save.SaveRequest;
|
|
import com.fp.persistence.commondb.PersistenceHelper;
|
|
import com.fp.persistence.pcustomer.gene.TcustPersonDetail;
|
|
import com.fp.persistence.pgeneral.image.TgeneFiles;
|
|
import com.fp.persistence.pgeneral.image.TgeneFilesDetail;
|
|
import com.fp.persistence.pgeneral.image.TgeneFilesDetailKey;
|
|
import com.fp.persistence.pgeneral.safe.TsafeUserDetail;
|
|
import com.fp.sessionbeans.helper.Sequence;
|
|
|
|
public class PeopleFastSave extends TransactionRule {
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
@Override
|
|
public SaveRequest normalProcess(SaveRequest pSaveRequest) throws Exception {
|
|
try {
|
|
/*
|
|
TcustPersonDetail d=(TcustPersonDetail)pSaveRequest.get("DETALLESPERSONA");
|
|
TcustPersonDetail personaBD=PersistenceHelper.getEntityManager().find(TcustPersonDetail.class, d.getPk());
|
|
byte[] photo=(byte[])pSaveRequest.get("PHOTO");
|
|
String extension=pSaveRequest.get("EXTENSION").toString();
|
|
TsafeUserDetail usuario=(TsafeUserDetail)pSaveRequest.get("USUARIO");
|
|
|
|
//Seteando los campos
|
|
personaBD.setActivitycode(d.getActivitycode());
|
|
personaBD.setBranchcode(d.getBranchcode());
|
|
personaBD.setClienttypecatalog(d.getClienttypecatalog());
|
|
personaBD.setClienttypecatalogcode(d.getClienttypecatalogcode());
|
|
personaBD.setCompanycode(d.getCompanycode());
|
|
personaBD.setDateexpidentification(d.getDateexpidentification());
|
|
personaBD.setDatefrom(d.getDatefrom());
|
|
personaBD.setEconomicsectorcatalog(d.getEconomicsectorcatalog());
|
|
personaBD.setEconomicsectorcatalogcode(d.getEconomicsectorcatalogcode());
|
|
personaBD.setIdentification(d.getIdentification());
|
|
personaBD.setIdentificationcatalog(d.getIdentificationcatalog());
|
|
personaBD.setIdentificationcatalogcode(d.getIdentificationcatalogcode());
|
|
personaBD.setIngressuser(d.getIngressuser());
|
|
personaBD.setInnerscore(d.getInnerscore());
|
|
personaBD.setIsmigrated(d.getIsmigrated());
|
|
personaBD.setLanguagecode(d.getLanguagecode());
|
|
personaBD.setLegalrepresent(d.getLegalrepresent());
|
|
personaBD.setLegalrepresentidentification(d.getLegalrepresentidentification());
|
|
personaBD.setMilitarygrade(d.getMilitarygrade());
|
|
personaBD.setMilitarygradecode(d.getMilitarygradecode());
|
|
personaBD.setModifyuser(d.getModifyuser());
|
|
personaBD.setName(d.getName());
|
|
personaBD.setNickname(d.getNickname());
|
|
personaBD.setOfficecode(d.getOfficecode());
|
|
personaBD.setParthnernumber(d.getParthnernumber());
|
|
personaBD.setPersontypecatalog(d.getPersontypecatalog());
|
|
personaBD.setPersontypecatalogcode(d.getPersontypecatalogcode());
|
|
|
|
personaBD.setRecordversion(d.getRecordversion());
|
|
personaBD.setRegisterdate(d.getRegisterdate());
|
|
personaBD.setSbsemployee(d.getSbsemployee());
|
|
personaBD.setSbsusercode(d.getSbsusercode());
|
|
personaBD.setSign(d.getSign());
|
|
personaBD.setTaxexempt(d.getTaxexempt());
|
|
//personaBD.setPicture(d.getPicture());
|
|
|
|
//Asginando la foto
|
|
if(photo!=null){
|
|
|
|
//Creando un nuevo archivo
|
|
TgeneFilesDetail archivoActual=new TgeneFilesDetail();
|
|
|
|
//Caso de que exista un arhivo anterior
|
|
if(personaBD.getPhoto()!=null){
|
|
|
|
TgeneFilesDetail archivoAnterior=PersistenceHelper.getEntityManager().find(TgeneFilesDetail.class, personaBD.getPhoto());
|
|
archivoAnterior.getPk().setDateto(new java.sql.Timestamp(Calendar.getInstance().getTimeInMillis()));
|
|
PersistenceHelper.getEntityManager().persist(archivoAnterior);
|
|
|
|
archivoActual.setPk(archivoAnterior.getPk());
|
|
archivoActual.setDatefrom(archivoAnterior.getDatefrom());
|
|
archivoActual.setIngressuser(archivoAnterior.getIngressuser());
|
|
}
|
|
|
|
//Creando un nuevo TEGENEFILES
|
|
Sequence sequence = new Sequence();
|
|
Integer code=sequence.getNextValue("CODE");
|
|
TgeneFiles file=new TgeneFiles();
|
|
file.setPk(code);
|
|
//PersistenceHelper.getEntityManager().persist(file);
|
|
|
|
//Creando el pk del TGENEFILEDETAIL
|
|
TgeneFilesDetailKey pk=new TgeneFilesDetailKey();
|
|
|
|
pk.setCode(code);
|
|
|
|
Calendar calendario=Calendar.getInstance();
|
|
calendario.set(Calendar.MONTH, Calendar.DECEMBER);
|
|
calendario.set(Calendar.DAY_OF_MONTH, 31);
|
|
calendario.set(Calendar.YEAR, 2999);
|
|
|
|
pk.setDateto(new Timestamp(calendario.getTimeInMillis()));
|
|
archivoActual.setPk(pk);
|
|
|
|
archivoActual.setImage(photo);
|
|
archivoActual.setExtension(extension);
|
|
archivoActual.setImagesize(photo.length);
|
|
archivoActual.setCapturedate(new Date(Calendar.getInstance().getTimeInMillis()));
|
|
archivoActual.setModifyuser(usuario.getPk().getUsercode());
|
|
archivoActual.setDescription("Foto de la persona");
|
|
archivoActual.setContenttype("image/"+extension.substring(1,extension.length()));
|
|
|
|
//PersistenceHelper.getEntityManager().persist(archivoActual);
|
|
}
|
|
|
|
if(personaBD.getPk()!=null && personaBD.getPk().getPersoncode()!=null){
|
|
personaBD=PersistenceHelper.getEntityManager().merge(personaBD);
|
|
PersistenceHelper.getEntityManager().persist(personaBD);
|
|
}
|
|
|
|
PersistenceHelper.getEntityManager().flush();
|
|
*/
|
|
|
|
} catch (Exception e) {
|
|
return pSaveRequest;
|
|
}
|
|
return pSaveRequest;
|
|
}
|
|
|
|
@Override
|
|
public SaveRequest reverseProcess(SaveRequest arg0) throws Exception {
|
|
|
|
return arg0;
|
|
}
|
|
|
|
}
|