Commit 45afe2fc authored by Cristian Aguirre's avatar Cristian Aguirre

Update ETL Delete Sensible Data

parent a5e47903
......@@ -11,6 +11,7 @@ import com.bytesw.bytebot.etl.model.DeleteDataSensibleControl;
import com.bytesw.bytebot.etl.model.DeleteDataSensibleLog;
import com.bytesw.bytebot.etl.model.Intent;
import com.bytesw.bytebot.etl.utils.JsonUtils;
import com.bytesw.xdf.exception.NotFoundException;
import com.bytesw.xdf.multitenant.core.ThreadLocalStorage;
import com.bytesw.bytebot.etl.services.DeleteSensMessageService;
import com.jayway.jsonpath.PathNotFoundException;
......@@ -27,6 +28,7 @@ import org.springframework.beans.BeanUtils;
import javax.transaction.Transactional;
import java.sql.Timestamp;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
......@@ -66,6 +68,7 @@ public class DataSensibleJPAWriter implements ItemWriter<DynaBean>, StepExecutio
String json = (String) dynaBean.get("data");
String event = (String) JsonUtils.getFieldFromJson(json, "$.event");
String sender_id;
boolean update_control = false;
// Transform present Date
String presentDate = OffsetDateTime.now().toString().replace('T', ' ');
String timeZone = presentDate.substring(presentDate.length() - 6);
......@@ -89,9 +92,17 @@ public class DataSensibleJPAWriter implements ItemWriter<DynaBean>, StepExecutio
sender_id = (String) JsonUtils.getFieldFromJson(json, "$.metadata.sender_id");
}
List<DeleteDataSensRegistryBean> deleteSensibleBean = service.deleteMessage(agent.getAgenId()
, SmSMessageSid, intenId.get().getId(), sender_id);
List<DeleteDataSensRegistryBean> deleteSensibleBean = new ArrayList<>();
try{
deleteSensibleBean = service.deleteMessage(agent.getAgenId()
, SmSMessageSid, intenId.get().getId(), sender_id);
update_control = true;
} catch (NotFoundException e){
update_control = true;
} catch (Exception e){
update_control = false;
}
for (DeleteDataSensRegistryBean registry : deleteSensibleBean) {
DeleteDataSensibleLog reg = new DeleteDataSensibleLog();
reg.setIntenId(registry.getInten_id());
......@@ -106,19 +117,21 @@ public class DataSensibleJPAWriter implements ItemWriter<DynaBean>, StepExecutio
}
DeleteDataSensibleControl control = new DeleteDataSensibleControl();
Optional<DeleteDataSensibleControl> controlBd = deleteDataSensibleControlRepository.findEventIdByAgentId(agent.getAgenId());
if (controlBd.isPresent()) {
// Update
control.setId(controlBd.get().getId());
control.setAgentId(agent.getAgenId());
control.setEventId(id);
control.setDate(Timestamp.valueOf(presentDate));
deleteDataSensibleControlRepository.save(control);
} else {
// Create
control.setAgentId(agent.getAgenId());
control.setEventId(id);
control.setDate(Timestamp.valueOf(presentDate));
deleteDataSensibleControlRepository.save(control);
if (update_control){
if (controlBd.isPresent()) {
// Update
control.setId(controlBd.get().getId());
control.setAgentId(agent.getAgenId());
control.setEventId(id);
control.setDate(Timestamp.valueOf(presentDate));
deleteDataSensibleControlRepository.save(control);
} else {
// Create
control.setAgentId(agent.getAgenId());
control.setEventId(id);
control.setDate(Timestamp.valueOf(presentDate));
deleteDataSensibleControlRepository.save(control);
}
}
}
}
......
......@@ -39,8 +39,6 @@ public class DeleteSensMessageService {
throw new Exception("Parámetros vacíos");
}
log.debug("RESPUESTA: "+data);
DeleteDataSensRegistryBean registry = new DeleteDataSensRegistryBean();
if(data.get("status") != null){
......@@ -60,16 +58,13 @@ public class DeleteSensMessageService {
deleteMessages.add(registry);
}
}
return deleteMessages;
}catch (NotFoundException e){
log.debug(e);
log.debug("Imagen no encontrada");
throw new NotFoundException(e.getMessage());
}catch (Exception e ){
log.debug(e);
log.debug("Error consumiento servicio de Proveedor");
}finally {
return deleteMessages;
throw new Exception(e.getMessage());
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment