* @param historico
* @throws Exception
*/
public void alterar(PontoCriticoPtc pontoCritico, HttpServletRequest request, UsuarioUsu usuario, HistoricoPtc historico) throws Exception {
Transaction tx = null;
HistoricoPontoCriticoPtc pojoHistorico = new HistoricoPontoCriticoPtc();
PontoCriticoPtc ptcNegocio = (PontoCriticoPtc) buscar(PontoCriticoPtc.class, pontoCritico.getCodPtc());
try {
tx = session.beginTransaction();
ArrayList objetos = new ArrayList();
super.inicializarLogBean();
PontoCriticoPtc pontoCriticoOld = (PontoCriticoPtc) buscar(PontoCriticoPtc.class, Long.valueOf(pontoCritico.getCodPtc()));
/*** Historico ***/
historico.gerarHistorico(pontoCriticoOld);
/*** Historico ***/
/* apaga os filhos para serem gravados novamente */
if (pontoCritico.getPontoCriticoCorPtccores() != null) {
Iterator itAtb = pontoCritico.getPontoCriticoCorPtccores().iterator();
while (itAtb.hasNext()) {
PontocriticoCorPtccor ptcCor = (PontocriticoCorPtccor) itAtb.next();
session.delete(ptcCor);
objetos.add(ptcCor);
}
}
else
pontoCritico.setPontoCriticoCorPtccores(new HashSet<PontocriticoCorPtccor>());
pontoCritico.setPontoCriticoCorPtccores(null);
/* apaga os filhos para serem gravados novamente */
if (pontoCritico.getPontoCriticoSisAtributoPtcSatbs() != null && !pontoCritico.getPontoCriticoSisAtributoPtcSatbs().isEmpty()) {
Iterator itAtb = pontoCritico.getPontoCriticoSisAtributoPtcSatbs().iterator();
while (itAtb.hasNext()) {
PontoCriticoSisAtributoPtcSatb pontoCriticoSisAtributoPtcSatb = (PontoCriticoSisAtributoPtcSatb) itAtb.next();
if(pontoCriticoSisAtributoPtcSatb.getSisAtributoSatb().getSisGrupoAtributoSga().getSisTipoExibicGrupoSteg().getCodSteg() == Input.IMAGEM){
String nomeCampo = request.getParameter("a" + pontoCriticoSisAtributoPtcSatb.getSisAtributoSatb().getSisGrupoAtributoSga().getCodSga().toString());
if (nomeCampo != null && nomeCampo.equals("")){
String fullFile = pontoCriticoSisAtributoPtcSatb.getInformacao();
if (fullFile.lastIndexOf("=") != -1)
fullFile = fullFile.substring(fullFile.lastIndexOf("=") + 1);
File f = new File(fullFile);
if( f.exists() )
FileUpload.apagarArquivo(fullFile);
}
}
session.delete(pontoCriticoSisAtributoPtcSatb);
objetos.add(pontoCriticoSisAtributoPtcSatb);
}
}
else
pontoCritico.setPontoCriticoSisAtributoPtcSatbs(new HashSet<PontoCriticoSisAtributoPtcSatb>());
pontoCritico.setPontoCriticoSisAtributoPtcSatbs(null);
this.setPontoCritico(request, pontoCritico);
pontoCritico.setUsuarioUsuByCodUsuUltManutPtc(usuario);
pontoCritico.setDataUltManutencaoPtc(Data.getDataAtual());
List filhos = new ArrayList();
if (pontoCritico.getPontoCriticoCorPtccores() != null) {
filhos.addAll(pontoCritico.getPontoCriticoCorPtccores());
}
if (pontoCritico.getPontoCriticoSisAtributoPtcSatbs() != null) {
for (Object object : pontoCritico.getPontoCriticoSisAtributoPtcSatbs()) {
PontoCriticoSisAtributoPtcSatb ptcSatb = (PontoCriticoSisAtributoPtcSatb) object;
ptcSatb.gerarTiposValores();
}
filhos.addAll(pontoCritico.getPontoCriticoSisAtributoPtcSatbs());
}
session.update(pontoCritico);
objetos.add(pontoCritico);
Iterator it = filhos.iterator();
while (it.hasNext()) {
PaiFilho object = (PaiFilho) it.next();
object.atribuirPKPai();
// salva os filhos
session.save(object);
objetos.add(object);
}
tx.commit();
session.merge(pontoCritico);
pojoHistorico.carregar(pontoCritico);
tx = session.beginTransaction();
gerarHistorico(pojoHistorico, Historico.ALTERAR, ((ecar.login.SegurancaECAR) request.getSession().getAttribute("seguranca")).getUsuario());
tx.commit();
if (super.logBean != null) {
super.logBean.setCodigoTransacao(Data.getHoraAtual(false));