Commit a5e47903 authored by Cristian Aguirre's avatar Cristian Aguirre

Update ETL Delete Sensible Data

parent b0d4957a
......@@ -21,6 +21,7 @@ import com.bytesw.bytebot.repository.AgentRepository;
import com.bytesw.xdf.multitenant.core.ThreadLocalStorage;
import com.google.gson.Gson;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.dbcp.BasicDataSource;
import org.springframework.batch.core.*;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
......@@ -38,6 +39,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Service;
import javax.sql.DataSource;
import java.time.Duration;
import java.time.OffsetDateTime;
import java.time.ZoneId;
......@@ -248,8 +250,7 @@ public class ScheduleService implements SchedulingConfigurer {
if (differenceTime < data.getDeletePeriod()) {
log.info("Agente " + data.getValue() + " aun no cumple con el periodo de espera.");
// throw new RuntimeException("Time is not yet fulfilled");
return null;
id = null;
} else {
id = control.getEventId();
}
......@@ -258,7 +259,6 @@ public class ScheduleService implements SchedulingConfigurer {
Map<String, Object> params = new HashMap<>();
params.putAll(tenantFound.get().getDatasource());
params.put("query", String.format((String) params.get("query"), id));
log.debug("PARAMS: " + params);
return dataBaseItemReaderFactory.createReader(rowMapperFactory.createMapper(new HashMap<>()), params);
}
......
......@@ -13,6 +13,7 @@ import com.bytesw.bytebot.etl.model.Intent;
import com.bytesw.bytebot.etl.utils.JsonUtils;
import com.bytesw.xdf.multitenant.core.ThreadLocalStorage;
import com.bytesw.bytebot.etl.services.DeleteSensMessageService;
import com.jayway.jsonpath.PathNotFoundException;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.log4j.Log4j2;
......@@ -64,11 +65,15 @@ public class DataSensibleJPAWriter implements ItemWriter<DynaBean>, StepExecutio
Long id = Long.parseLong(dynaBean.get("id").toString());
String json = (String) dynaBean.get("data");
String event = (String) JsonUtils.getFieldFromJson(json, "$.event");
String sender_id;
// Transform present Date
String presentDate = OffsetDateTime.now().toString().replace('T', ' ');
String timeZone = presentDate.substring(presentDate.length() - 6);
presentDate = presentDate.replace(timeZone, "");
if (EventTypeEnum.USER.getName().equals(event)) {
String toAgent = (String) JsonUtils.getFieldFromJson(json, "$.metadata.To");
if (agent.getChannelValue().equals(toAgent)) {
String intent = (String) JsonUtils.getFieldFromJson(json, "$.parse_data.intent.name");
if (intentByAgent.contains(intent)) {
String SmSMessageSid = (String) JsonUtils.getFieldFromJson(json, "$.metadata.SmsMessageSid");
......@@ -76,19 +81,16 @@ public class DataSensibleJPAWriter implements ItemWriter<DynaBean>, StepExecutio
if (!intenId.isPresent()) {
throw new Exception("Intent no esta presente");
}
// Transform present Date
String presentDate = OffsetDateTime.now().toString().replace('T', ' ');
String timeZone = presentDate.substring(presentDate.length() - 6);
presentDate = presentDate.replace(timeZone, "");
String senderId = (String) JsonUtils.getFieldFromJson(json, "$.metadata.sender_id");
if (senderId.isEmpty()) {
senderId = (String) JsonUtils.getFieldFromJson(json, "$.sender_id");
try{
sender_id = (String) JsonUtils.getFieldFromJson(json, "$.sender_id");
log.info(sender_id);
}catch(Exception e){
log.info(e.getMessage());
sender_id = (String) JsonUtils.getFieldFromJson(json, "$.metadata.sender_id");
}
List<DeleteDataSensRegistryBean> deleteSensibleBean = service.deleteMessage(agent.getAgenId()
, SmSMessageSid, intenId.get().getId(), senderId);
, SmSMessageSid, intenId.get().getId(), sender_id);
for (DeleteDataSensRegistryBean registry : deleteSensibleBean) {
DeleteDataSensibleLog reg = new DeleteDataSensibleLog();
......@@ -99,30 +101,26 @@ public class DataSensibleJPAWriter implements ItemWriter<DynaBean>, StepExecutio
reg.setDate(Timestamp.valueOf(presentDate));
deleteDataSensibleLogRepository.save(reg);
}
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);
}
}
}
}
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);
}
}
//service.saveDataSensControl(eventBean.getId(), eventBean.getSenderId());
}
@Override
......
......@@ -63,14 +63,12 @@ public class TwilioService extends ProviderService{
exist_agent = true;
}
}
log.debug("EXISTE AGENT: "+exist_agent);
if(!exist_agent){
log.info("No existe un agente con el ID especificado");
throw new Exception("No se encontró un agente con canales deployados con dicho ID");
}
String[] images_droped = new String[MAX_LIMIT];
Twilio.init(sid, token);
TwilioRestClient twilio_client = Twilio.getRestClient();
ResourceSet<Media> media = Media.reader(SmsId).limit(MAX_LIMIT).read();
int cont = 0;
for (Media record : media) {
......@@ -80,9 +78,8 @@ public class TwilioService extends ProviderService{
}
if (cont == 0) {
log.info("No hay imágenes para el mensaje indicado");
throw new NotFoundException("No se encontraron imágenes para dicho mensaje");
throw new NotFoundException("No se encontraron imágenes para el mensaje "+SmsId);
} else {
// data.put("images_droped", Arrays.copyOfRange(images_droped, 0, cont));
for(String image : Arrays.copyOfRange(images_droped, 0, cont)){
data.add(image);
}
......@@ -101,10 +98,12 @@ public class TwilioService extends ProviderService{
throw new InternalError("Fallo en la conexión con Twilio API");
}else{
log.info("El mensaje no existe para : " + SmsId + "\n" + e.getMessage());
throw new NotFoundException("No se encontro el mensaje en el Proveedor");
throw new NotFoundException("No se encontraron imágenes para el mensaje "+SmsId);
}
}catch (NotFoundException e){
throw new NotFoundException(e.getMessage());
}catch (Exception e){
throw new Exception(e);
throw new Exception(e.getMessage());
}
}
}
......@@ -26,8 +26,8 @@ management:
application:
byte-bot:
batch:
chunk: 1
cron: 0/500 * * * * *
chunk: 10
cron: 0/50 * * * * *
show-side-bar: false
test: ENC(OEchnTXpIZnCVdPNthgCZBfQjMt1AUS1)
name: xdf-example
......@@ -55,7 +55,7 @@ application:
multi-tenant-conf:
exclude-service: /
authorization-service.url: http://localhost:17580
security: oauth2sso # none, basic, oauth2sso
security: none # none, basic, oauth2sso
security.method: true
security-exclude: /service/oauth/userinfo, /actuator/**, /mylogout, /login, /logout, /goodbye, /error, /anon, /cache.manifest, /favicon.ico, /service/file, /goodbye /byteboot
messaging:
......
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