maia_modificado/.svn/pristine/4c/4ce9b3d0cfd96a4862c330b5fcb...

64 lines
2.1 KiB
Plaintext
Executable File

package com.fp.armas.rules.save.webservices;
import java.util.List;
import com.fp.common.logger.APPLogger;
import com.fp.dto.rules.TransactionRule;
import com.fp.dto.save.SaveRequest;
import com.fp.persistence.commondb.PersistenceHelper;
import com.fp.persistence.parmas.inte.TarmLecturaDetalle;
import com.fp.persistence.parmas.inte.TarmTagArma;
import com.fp.persistence.parmas.inte.TarmTagArmaKey;
/**
* Desvinculo el arma de un tag determinado, respondo con estado de la petición
* @author dcruz
*
*/
public class DesvinculaTagArma extends TransactionRule {
private static final long serialVersionUID = -2755388437487909747L;
/**
* Env&iaucte;o una respuesta 0 correcto, 1 no existe el arma a desvincular, 2 ocurrió un error
*/
@SuppressWarnings("unchecked")
@Override
public SaveRequest normalProcess(SaveRequest pRequest) throws Exception {
String respuesta = "0";
try {
String carma = (String) pRequest.get("CODIGOARMA");
String tagArma = (String) pRequest.get("CODIGOTAG");
TarmTagArma tarmTagArma = PersistenceHelper.getEntityManager().find(TarmTagArma.class, new TarmTagArmaKey(carma, tagArma));
if(tarmTagArma == null){
respuesta = "1";
} else{
List<TarmLecturaDetalle> lecturaDetalles=PersistenceHelper.getEntityManager().
createQuery("select o from TarmLecturaDetalle o where o.pk.codigotag='"+tarmTagArma.getPk().getCtag()+"'").getResultList();
PersistenceHelper.getEntityManager().remove(tarmTagArma);
PersistenceHelper.getEntityManager().flush();
if(lecturaDetalles!=null && lecturaDetalles.size()>0){
for(TarmLecturaDetalle detalleLectura:lecturaDetalles){
PersistenceHelper.getEntityManager().remove(detalleLectura);
PersistenceHelper.getEntityManager().flush();
}
}
respuesta = "0";
}
} catch (Throwable e) {
respuesta = "2";
APPLogger.getLogger().error(e.getMessage(), e);
}
pRequest.getResponse().put("RESPONSESTATUS", respuesta);
return pRequest;
}
@Override
public SaveRequest reverseProcess(SaveRequest pRequest) throws Exception {
return pRequest;
}
}