Commit dfca8e2e authored by Cristian Aguirre's avatar Cristian Aguirre

ETL Delete Sensible Data Tested

parent 45afe2fc
...@@ -7,14 +7,12 @@ import com.bytesw.bytebot.http.FileValidationResponse; ...@@ -7,14 +7,12 @@ import com.bytesw.bytebot.http.FileValidationResponse;
import com.bytesw.bytebot.service.AgentService; import com.bytesw.bytebot.service.AgentService;
import com.bytesw.bytebot.service.FileManagementService; import com.bytesw.bytebot.service.FileManagementService;
import com.bytesw.xdf.annotation.ProgramSecurity; import com.bytesw.xdf.annotation.ProgramSecurity;
import com.bytesw.xdf.multitenant.core.ThreadLocalStorage;
import com.bytesw.xdf.sql.beans.Pagination; import com.bytesw.xdf.sql.beans.Pagination;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import java.security.Principal; import java.security.Principal;
import java.time.LocalDate;
import java.util.UUID; import java.util.UUID;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
......
package com.bytesw.bytebot.controller; package com.bytesw.bytebot.controller;
import com.bytesw.bytebot.service.provider.TwilioService; import com.bytesw.bytebot.service.provider.TwilioService;
import com.bytesw.xdf.exception.BusinessExceptionHandler;
import com.bytesw.xdf.exception.NotFoundException; import com.bytesw.xdf.exception.NotFoundException;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses; import io.swagger.annotations.ApiResponses;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang.NullArgumentException;
import com.twilio.exception.AuthenticationException; import com.twilio.exception.AuthenticationException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import com.google.gson.Gson; import com.google.gson.Gson;
import org.springframework.web.context.request.WebRequest;
import javax.management.ObjectName;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
......
...@@ -53,7 +53,6 @@ public class DataBaseItemReaderFactory implements ItemReaderFactory<DynaBean, Ro ...@@ -53,7 +53,6 @@ public class DataBaseItemReaderFactory implements ItemReaderFactory<DynaBean, Ro
databaseReader.setRowMapper(mapper); databaseReader.setRowMapper(mapper);
databaseReader.setSql(query); databaseReader.setSql(query);
log.debug("DATASOURCE: "+databaseReader.getDataSource());
return databaseReader; return databaseReader;
} }
......
package com.bytesw.bytebot.etl.batch.service; package com.bytesw.bytebot.etl.batch.service;
import com.bytesw.bytebot.etl.batch.beans.*; import com.bytesw.bytebot.etl.batch.beans.DeleteDataSensBean;
import com.bytesw.bytebot.etl.batch.beans.DeleteDataSensControlBean;
import com.bytesw.bytebot.etl.batch.beans.DynaBean;
import com.bytesw.bytebot.etl.batch.beans.TenantBatchBean;
import com.bytesw.bytebot.etl.batch.factory.mapper.RowMapperFactory; import com.bytesw.bytebot.etl.batch.factory.mapper.RowMapperFactory;
import com.bytesw.bytebot.etl.batch.factory.reader.DataBaseItemReaderFactory; import com.bytesw.bytebot.etl.batch.factory.reader.DataBaseItemReaderFactory;
import com.bytesw.bytebot.etl.batch.processor.ConvertToBeanProcessor; import com.bytesw.bytebot.etl.batch.processor.ConvertToBeanProcessor;
...@@ -21,7 +24,6 @@ import com.bytesw.bytebot.repository.AgentRepository; ...@@ -21,7 +24,6 @@ import com.bytesw.bytebot.repository.AgentRepository;
import com.bytesw.xdf.multitenant.core.ThreadLocalStorage; import com.bytesw.xdf.multitenant.core.ThreadLocalStorage;
import com.google.gson.Gson; import com.google.gson.Gson;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.apache.commons.dbcp.BasicDataSource;
import org.springframework.batch.core.*; import org.springframework.batch.core.*;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
...@@ -39,7 +41,6 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar; ...@@ -39,7 +41,6 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronTrigger; import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.sql.DataSource;
import java.time.Duration; import java.time.Duration;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;
import java.time.ZoneId; import java.time.ZoneId;
...@@ -192,11 +193,9 @@ public class ScheduleService implements SchedulingConfigurer { ...@@ -192,11 +193,9 @@ public class ScheduleService implements SchedulingConfigurer {
} }
Long id = eventHistoryRepository.maxEventId(); Long id = eventHistoryRepository.maxEventId();
log.debug("ID: " + id);
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
params.putAll(tenantFound.get().getDatasource()); params.putAll(tenantFound.get().getDatasource());
params.put("query", String.format((String) params.get("query"), id != null ? id : 0)); params.put("query", String.format((String) params.get("query"), id != null ? id : 0));
log.debug("PARAMS: " + params);
return dataBaseItemReaderFactory.createReader(rowMapperFactory.createMapper(new HashMap<>()), params); return dataBaseItemReaderFactory.createReader(rowMapperFactory.createMapper(new HashMap<>()), params);
} }
......
...@@ -19,7 +19,8 @@ import java.util.List; ...@@ -19,7 +19,8 @@ import java.util.List;
@Log4j2 @Log4j2
public class ByteBotJPAWriter implements ItemWriter<DynaBean>, StepExecutionListener { public class ByteBotJPAWriter implements ItemWriter<DynaBean>, StepExecutionListener {
@Getter @Setter @Getter
@Setter
private ProcessMessageService service; private ProcessMessageService service;
@Override @Override
......
package com.bytesw.bytebot.etl.batch.writer; package com.bytesw.bytebot.etl.batch.writer;
import com.bytesw.bytebot.etl.batch.beans.DeleteDataSensBean; import com.bytesw.bytebot.etl.batch.beans.DeleteDataSensBean;
import com.bytesw.bytebot.etl.batch.beans.DeleteDataSensControlBean; import com.bytesw.bytebot.etl.batch.beans.DeleteDataSensRegistryBean;
import com.bytesw.bytebot.etl.batch.beans.DynaBean; import com.bytesw.bytebot.etl.batch.beans.DynaBean;
import com.bytesw.bytebot.etl.dao.DeleteDataSensibleControlRepository; import com.bytesw.bytebot.etl.dao.DeleteDataSensibleControlRepository;
import com.bytesw.bytebot.etl.dao.DeleteDataSensibleLogRepository; import com.bytesw.bytebot.etl.dao.DeleteDataSensibleLogRepository;
...@@ -10,11 +10,10 @@ import com.bytesw.bytebot.etl.enums.EventTypeEnum; ...@@ -10,11 +10,10 @@ import com.bytesw.bytebot.etl.enums.EventTypeEnum;
import com.bytesw.bytebot.etl.model.DeleteDataSensibleControl; import com.bytesw.bytebot.etl.model.DeleteDataSensibleControl;
import com.bytesw.bytebot.etl.model.DeleteDataSensibleLog; import com.bytesw.bytebot.etl.model.DeleteDataSensibleLog;
import com.bytesw.bytebot.etl.model.Intent; import com.bytesw.bytebot.etl.model.Intent;
import com.bytesw.bytebot.etl.services.DeleteSensMessageService;
import com.bytesw.bytebot.etl.utils.JsonUtils; import com.bytesw.bytebot.etl.utils.JsonUtils;
import com.bytesw.xdf.exception.NotFoundException; import com.bytesw.xdf.exception.NotFoundException;
import com.bytesw.xdf.multitenant.core.ThreadLocalStorage; import com.bytesw.xdf.multitenant.core.ThreadLocalStorage;
import com.bytesw.bytebot.etl.services.DeleteSensMessageService;
import com.jayway.jsonpath.PathNotFoundException;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
...@@ -22,8 +21,6 @@ import org.springframework.batch.core.ExitStatus; ...@@ -22,8 +21,6 @@ import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.item.ItemWriter; import org.springframework.batch.item.ItemWriter;
import com.bytesw.bytebot.etl.batch.beans.DeleteDataSensRegistryBean;
import org.springframework.beans.BeanUtils;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import java.sql.Timestamp; import java.sql.Timestamp;
...@@ -84,23 +81,23 @@ public class DataSensibleJPAWriter implements ItemWriter<DynaBean>, StepExecutio ...@@ -84,23 +81,23 @@ public class DataSensibleJPAWriter implements ItemWriter<DynaBean>, StepExecutio
if (!intenId.isPresent()) { if (!intenId.isPresent()) {
throw new Exception("Intent no esta presente"); throw new Exception("Intent no esta presente");
} }
try{ try {
sender_id = (String) JsonUtils.getFieldFromJson(json, "$.sender_id"); sender_id = (String) JsonUtils.getFieldFromJson(json, "$.sender_id");
log.info(sender_id); log.info(sender_id);
}catch(Exception e){ } catch (Exception e) {
log.info(e.getMessage()); log.info(e.getMessage());
sender_id = (String) JsonUtils.getFieldFromJson(json, "$.metadata.sender_id"); sender_id = (String) JsonUtils.getFieldFromJson(json, "$.metadata.sender_id");
} }
List<DeleteDataSensRegistryBean> deleteSensibleBean = new ArrayList<>(); List<DeleteDataSensRegistryBean> deleteSensibleBean = new ArrayList<>();
try{ try {
deleteSensibleBean = service.deleteMessage(agent.getAgenId() deleteSensibleBean = service.deleteMessage(agent.getAgenId()
, SmSMessageSid, intenId.get().getId(), sender_id); , SmSMessageSid, intenId.get().getId(), sender_id);
update_control = true;
} catch (NotFoundException e){
update_control = true; update_control = true;
} catch (Exception e){ } catch (NotFoundException e) {
update_control = true;
} catch (Exception e) {
update_control = false; update_control = false;
} }
for (DeleteDataSensRegistryBean registry : deleteSensibleBean) { for (DeleteDataSensRegistryBean registry : deleteSensibleBean) {
...@@ -117,7 +114,7 @@ public class DataSensibleJPAWriter implements ItemWriter<DynaBean>, StepExecutio ...@@ -117,7 +114,7 @@ public class DataSensibleJPAWriter implements ItemWriter<DynaBean>, StepExecutio
} }
DeleteDataSensibleControl control = new DeleteDataSensibleControl(); DeleteDataSensibleControl control = new DeleteDataSensibleControl();
Optional<DeleteDataSensibleControl> controlBd = deleteDataSensibleControlRepository.findEventIdByAgentId(agent.getAgenId()); Optional<DeleteDataSensibleControl> controlBd = deleteDataSensibleControlRepository.findEventIdByAgentId(agent.getAgenId());
if (update_control){ if (update_control) {
if (controlBd.isPresent()) { if (controlBd.isPresent()) {
// Update // Update
control.setId(controlBd.get().getId()); control.setId(controlBd.get().getId());
......
...@@ -2,13 +2,11 @@ package com.bytesw.bytebot.etl.services; ...@@ -2,13 +2,11 @@ package com.bytesw.bytebot.etl.services;
import com.bytesw.bytebot.etl.batch.beans.DeleteDataSensRegistryBean; import com.bytesw.bytebot.etl.batch.beans.DeleteDataSensRegistryBean;
import com.bytesw.bytebot.etl.dao.DeleteDataSensibleControlRepository; import com.bytesw.bytebot.etl.dao.DeleteDataSensibleControlRepository;
import com.bytesw.bytebot.etl.model.DeleteDataSensibleLog;
import com.bytesw.bytebot.service.provider.TwilioService; import com.bytesw.bytebot.service.provider.TwilioService;
import com.bytesw.xdf.exception.NotFoundException; import com.bytesw.xdf.exception.NotFoundException;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -26,26 +24,26 @@ public class DeleteSensMessageService { ...@@ -26,26 +24,26 @@ public class DeleteSensMessageService {
@Autowired @Autowired
DeleteDataSensibleControlRepository deleteDataSensibleControlRepository; DeleteDataSensibleControlRepository deleteDataSensibleControlRepository;
public List<DeleteDataSensRegistryBean> deleteMessage(Long agentId, String SmsMessage, Long inten_id, String sender_id) throws Exception{ public List<DeleteDataSensRegistryBean> deleteMessage(Long agentId, String SmsMessage, Long inten_id, String sender_id) throws Exception {
List<DeleteDataSensRegistryBean> deleteMessages = new ArrayList<DeleteDataSensRegistryBean>(); List<DeleteDataSensRegistryBean> deleteMessages = new ArrayList<DeleteDataSensRegistryBean>();
Map<String,Object> data = new HashMap<>(); Map<String, Object> data = new HashMap<>();
Map<String,Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
params.put("agent_id",agentId.intValue()); params.put("agent_id", agentId.intValue());
try{ try {
Map<String,Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
data = twilioService.generateInfo(SmsMessage,params); data = twilioService.generateInfo(SmsMessage, params);
if(data.isEmpty()){ if (data.isEmpty()) {
throw new Exception("Parámetros vacíos"); throw new Exception("Parámetros vacíos");
} }
DeleteDataSensRegistryBean registry = new DeleteDataSensRegistryBean(); DeleteDataSensRegistryBean registry = new DeleteDataSensRegistryBean();
if(data.get("status") != null){ if (data.get("status") != null) {
List<String> images = new ArrayList<String>(); List<String> images = new ArrayList<String>();
images = (List<String>) data.get("data"); images = (List<String>) data.get("data");
for(String image : images){ for (String image : images) {
if (image.trim().isEmpty()){ if (image.trim().isEmpty()) {
continue; continue;
} }
// Info del Bean // Info del Bean
...@@ -58,11 +56,11 @@ public class DeleteSensMessageService { ...@@ -58,11 +56,11 @@ public class DeleteSensMessageService {
deleteMessages.add(registry); deleteMessages.add(registry);
} }
} }
return deleteMessages; return deleteMessages;
}catch (NotFoundException e){ } catch (NotFoundException e) {
log.debug(e); log.debug(e);
throw new NotFoundException(e.getMessage()); throw new NotFoundException(e.getMessage());
}catch (Exception e ){ } catch (Exception e) {
log.debug(e); log.debug(e);
throw new Exception(e.getMessage()); throw new Exception(e.getMessage());
} }
......
...@@ -6,7 +6,9 @@ import lombok.extern.log4j.Log4j2; ...@@ -6,7 +6,9 @@ import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.*; import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
...@@ -35,7 +37,6 @@ public abstract class MessageProcessedSupport { ...@@ -35,7 +37,6 @@ public abstract class MessageProcessedSupport {
protected OffsetDateTime getOffsetDateTimeFromTimestampPython(Object objectTimestamp) { protected OffsetDateTime getOffsetDateTimeFromTimestampPython(Object objectTimestamp) {
BigDecimal dateDecimal; BigDecimal dateDecimal;
log.debug("TIME MILI: "+objectTimestamp);
if (objectTimestamp instanceof Double) { if (objectTimestamp instanceof Double) {
dateDecimal = new BigDecimal((Double) objectTimestamp); dateDecimal = new BigDecimal((Double) objectTimestamp);
} else { } else {
...@@ -44,7 +45,7 @@ public abstract class MessageProcessedSupport { ...@@ -44,7 +45,7 @@ public abstract class MessageProcessedSupport {
} }
dateDecimal = new BigDecimal(String.valueOf(objectTimestamp)); dateDecimal = new BigDecimal(String.valueOf(objectTimestamp));
} }
Long timestamp = (long)(dateDecimal.doubleValue()*1000); Long timestamp = (long) (dateDecimal.doubleValue() * 1000);
if (String.valueOf(timestamp).length() < 13) { if (String.valueOf(timestamp).length() < 13) {
int numberOfZero = 13 - String.valueOf(timestamp).length(); int numberOfZero = 13 - String.valueOf(timestamp).length();
for (int i = 0; i < numberOfZero; i++) { for (int i = 0; i < numberOfZero; i++) {
...@@ -52,7 +53,6 @@ public abstract class MessageProcessedSupport { ...@@ -52,7 +53,6 @@ public abstract class MessageProcessedSupport {
} }
} }
OffsetDateTime date = OffsetDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault()); OffsetDateTime date = OffsetDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault());
log.debug("TIME: "+date);
return date; return date;
} }
......
package com.bytesw.bytebot.etl.services; package com.bytesw.bytebot.etl.services;
import com.bytesw.bytebot.etl.beans.ProcessMessageResult; import com.bytesw.bytebot.etl.beans.ProcessMessageResult;
import com.bytesw.bytebot.etl.dao.EventHistoryRepository;
import com.bytesw.bytebot.etl.dao.DeleteDataSensibleControlRepository; import com.bytesw.bytebot.etl.dao.DeleteDataSensibleControlRepository;
import com.bytesw.bytebot.etl.dao.EventHistoryRepository;
import com.bytesw.bytebot.etl.enums.EventTypeEnum; import com.bytesw.bytebot.etl.enums.EventTypeEnum;
import com.bytesw.bytebot.etl.model.EventHistory; import com.bytesw.bytebot.etl.model.EventHistory;
import com.bytesw.bytebot.etl.utils.JsonUtils; import com.bytesw.bytebot.etl.utils.JsonUtils;
...@@ -31,18 +31,9 @@ public class ProcessMessageService { ...@@ -31,18 +31,9 @@ public class ProcessMessageService {
eventHistoryRepository.save(eventHistory); eventHistoryRepository.save(eventHistory);
} }
/*public void saveDataSensControl(Long agentId, Timestamp date, Long eventId){
DeleteDataSensibleControl deleteDataSensibleControl = new DeleteDataSensibleControl();
deleteDataSensibleControl.setAgentId(agentId);
deleteDataSensibleControl.setDate(date);
deleteDataSensibleControl.setEventId(eventId);
deleteDataSensibleControlRepository.save(deleteDataSensibleControl);
}*/
public ProcessMessageResult processMessage(String json, String senderId) throws Exception { public ProcessMessageResult processMessage(String json, String senderId) throws Exception {
ProcessMessageResult result = new ProcessMessageResult(); ProcessMessageResult result = new ProcessMessageResult();
log.debug(json);
MessageProcessed messageProcessed = detectType(json); MessageProcessed messageProcessed = detectType(json);
if (messageProcessed == null) { if (messageProcessed == null) {
result.setProcessed(false); result.setProcessed(false);
...@@ -64,11 +55,9 @@ public class ProcessMessageService { ...@@ -64,11 +55,9 @@ public class ProcessMessageService {
if (type != null) { if (type != null) {
// Verify if message is valid // Verify if message is valid
if(EventTypeEnum.USER.equals(type)){ if (EventTypeEnum.USER.equals(type)) {
String message_id = (String) JsonUtils.getFieldFromJson(json, "$.message_id"); String message_id = (String) JsonUtils.getFieldFromJson(json, "$.message_id");
log.debug("MESSAGE: "+message_id); if (message_id == null) {
log.debug(("TIPO: "+message_id.getClass().getName()));
if (message_id == null){
return null; return null;
} }
} }
......
package com.bytesw.bytebot.etl.services; package com.bytesw.bytebot.etl.services;
import com.bytesw.bytebot.etl.beans.SessionBean; import com.bytesw.bytebot.etl.beans.SessionBean;
import com.bytesw.bytebot.model.Channel;
import com.bytesw.bytebot.repository.ChannelRepository;
import com.bytesw.bytebot.etl.dao.IntentRepository; import com.bytesw.bytebot.etl.dao.IntentRepository;
import com.bytesw.bytebot.etl.dao.MessageRepository; import com.bytesw.bytebot.etl.dao.MessageRepository;
import com.bytesw.bytebot.etl.dao.UserRepository; import com.bytesw.bytebot.etl.dao.UserRepository;
import com.bytesw.bytebot.etl.enums.MessageTypeEnum; import com.bytesw.bytebot.etl.enums.MessageTypeEnum;
import com.bytesw.bytebot.etl.jdbc.ETLMessageJDBCRepository; import com.bytesw.bytebot.etl.jdbc.ETLMessageJDBCRepository;
import com.bytesw.bytebot.etl.jdbc.ETLSessionBotJDBCRepository; import com.bytesw.bytebot.etl.jdbc.ETLSessionBotJDBCRepository;
import com.bytesw.bytebot.etl.model.*; import com.bytesw.bytebot.etl.model.Intent;
import com.bytesw.bytebot.etl.model.Message;
import com.bytesw.bytebot.etl.model.Session;
import com.bytesw.bytebot.etl.model.User;
import com.bytesw.bytebot.etl.utils.JsonUtils; import com.bytesw.bytebot.etl.utils.JsonUtils;
import com.bytesw.bytebot.model.Channel;
import com.bytesw.bytebot.repository.ChannelRepository;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -73,7 +76,6 @@ public class UserMessageProcessed extends MessageProcessedSupport implements Mes ...@@ -73,7 +76,6 @@ public class UserMessageProcessed extends MessageProcessedSupport implements Mes
if (message != null) { if (message != null) {
int correlative = messageJDBCRepository.getLastCorrelativeBySession(message.getSessionId()); int correlative = messageJDBCRepository.getLastCorrelativeBySession(message.getSessionId());
correlative++; correlative++;
log.debug("CORRE: "+correlative);
message.setCorrelative(correlative); message.setCorrelative(correlative);
messageRepository.save(message); messageRepository.save(message);
...@@ -134,10 +136,8 @@ public class UserMessageProcessed extends MessageProcessedSupport implements Mes ...@@ -134,10 +136,8 @@ public class UserMessageProcessed extends MessageProcessedSupport implements Mes
if (MessageTypeEnum.ACCEPTED.equals(message.getType())) { if (MessageTypeEnum.ACCEPTED.equals(message.getType())) {
String intentName = (String) JsonUtils.getFieldFromJson(json, this.fields.get(INTENT_NAME)); String intentName = (String) JsonUtils.getFieldFromJson(json, this.fields.get(INTENT_NAME));
log.debug("INTENTNAME: "+intentName);
Optional<Intent> optionalIntent = intentRepository.findByIdentifier(intentName); Optional<Intent> optionalIntent = intentRepository.findByIdentifier(intentName);
if (optionalIntent.isPresent()) { if (optionalIntent.isPresent()) {
log.debug("Intencion presente en mensaje");
message.setIntentId(optionalIntent.get().getId()); message.setIntentId(optionalIntent.get().getId());
} }
} }
......
package com.bytesw.bytebot.jdbc; package com.bytesw.bytebot.jdbc;
import com.bytesw.bytebot.bean.DeploymentChannelParamValueBean; import com.bytesw.bytebot.bean.DeploymentChannelParamValueBean;
import com.bytesw.bytebot.model.enums.AgentStatusEnum; import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -21,14 +19,14 @@ public class AgentJDBCRepository { ...@@ -21,14 +19,14 @@ public class AgentJDBCRepository {
@Qualifier("sqlSessionFactory") @Qualifier("sqlSessionFactory")
private SqlSessionFactory sqlsession; private SqlSessionFactory sqlsession;
@Cacheable(value="deploy_agents") @Cacheable(value = "deploy_agents")
public List<DeploymentChannelParamValueBean> getCredentialsFromAgentStatus(String status){ public List<DeploymentChannelParamValueBean> getCredentialsFromAgentStatus(String status) {
SqlSession session = sqlsession.openSession(); SqlSession session = sqlsession.openSession();
try{ try {
Map<String,Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
params.put("status",status); params.put("status", status);
return session.selectList("com.bytesw.bytebot.dao.jdbc.AgentMapper.getCredentialsFromAgentandChannel",params); return session.selectList("com.bytesw.bytebot.dao.jdbc.AgentMapper.getCredentialsFromAgentandChannel", params);
} finally { } finally {
session.close(); session.close();
......
package com.bytesw.bytebot.jdbc; package com.bytesw.bytebot.jdbc;
import com.bytesw.bytebot.etl.model.Session;
import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
......
...@@ -11,7 +11,6 @@ import lombok.extern.log4j.Log4j2; ...@@ -11,7 +11,6 @@ import lombok.extern.log4j.Log4j2;
import org.apache.camel.ProducerTemplate; import org.apache.camel.ProducerTemplate;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
...@@ -66,7 +65,6 @@ public class AgentService extends CustomPaginationService<Agent> { ...@@ -66,7 +65,6 @@ public class AgentService extends CustomPaginationService<Agent> {
if (values == null){ if (values == null){
values = new ArrayList<>(); values = new ArrayList<>();
} }
log.debug("LLegue al getkeysfromagents");
//log.debug(values); //log.debug(values);
return values; return values;
} }
...@@ -333,8 +331,6 @@ public class AgentService extends CustomPaginationService<Agent> { ...@@ -333,8 +331,6 @@ public class AgentService extends CustomPaginationService<Agent> {
} else { } else {
deploymentChannelParamValue.setParameter(null); deploymentChannelParamValue.setParameter(null);
} }
log.debug("SE GUARDO DEPLOYMEN: "+deploymentChannelBD);
deploymentChannelParamValueRepository.save(deploymentChannelParamValue); deploymentChannelParamValueRepository.save(deploymentChannelParamValue);
} }
......
...@@ -4,7 +4,6 @@ import com.bytesw.bytebot.bean.*; ...@@ -4,7 +4,6 @@ import com.bytesw.bytebot.bean.*;
import com.bytesw.bytebot.jdbc.ActionJDBCRepository; import com.bytesw.bytebot.jdbc.ActionJDBCRepository;
import com.bytesw.bytebot.jdbc.MessageJDBCRepository; import com.bytesw.bytebot.jdbc.MessageJDBCRepository;
import com.bytesw.xdf.sql.beans.Pagination; import com.bytesw.xdf.sql.beans.Pagination;
import lombok.extern.java.Log;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -33,7 +32,6 @@ public class CustomerInteractionDashboardService extends DashboardService { ...@@ -33,7 +32,6 @@ public class CustomerInteractionDashboardService extends DashboardService {
@Override @Override
protected void completeData(OffsetDateTime startDate, OffsetDateTime endDate, Integer rangeMinutes,Map<String, Object> info) { protected void completeData(OffsetDateTime startDate, OffsetDateTime endDate, Integer rangeMinutes,Map<String, Object> info) {
List<RangeBean> rangeList = calculateRangeList(startDate, endDate); List<RangeBean> rangeList = calculateRangeList(startDate, endDate);
log.debug("PERIOD: "+rangeList);
info.put("sessionFlow", generateInteractionByCustomerData(startDate, endDate)); info.put("sessionFlow", generateInteractionByCustomerData(startDate, endDate));
info.put("summaryGoals", generateSummaryByGoals(startDate, endDate)); info.put("summaryGoals", generateSummaryByGoals(startDate, endDate));
info.put("intentAvgByCustomer", generateAverageIntentsByCustomer(rangeList)); info.put("intentAvgByCustomer", generateAverageIntentsByCustomer(rangeList));
...@@ -57,8 +55,6 @@ public class CustomerInteractionDashboardService extends DashboardService { ...@@ -57,8 +55,6 @@ public class CustomerInteractionDashboardService extends DashboardService {
Map<String, List<Object>> data = new HashMap<>(); Map<String, List<Object>> data = new HashMap<>();
rangeList.stream().forEach(x -> { rangeList.stream().forEach(x -> {
List<String> identifiers = new ArrayList<>(); List<String> identifiers = new ArrayList<>();
log.debug("START: "+x.getStartDate());
log.debug(("END: "+x.getEndDate()));
List<MessageByIntentBean> list = messageJDBCRepository.countMessageByIntent(x.getStartDate(), x.getEndDate()); List<MessageByIntentBean> list = messageJDBCRepository.countMessageByIntent(x.getStartDate(), x.getEndDate());
list.stream().forEach(intentSummary -> { list.stream().forEach(intentSummary -> {
identifiers.add((intentSummary.getIdentifier())); identifiers.add((intentSummary.getIdentifier()));
...@@ -76,7 +72,6 @@ public class CustomerInteractionDashboardService extends DashboardService { ...@@ -76,7 +72,6 @@ public class CustomerInteractionDashboardService extends DashboardService {
} }
}); });
}); });
log.debug("DATA: "+data);
return data; return data;
} }
......
package com.bytesw.bytebot.service.provider; package com.bytesw.bytebot.service.provider;
import com.bytesw.xdf.exception.NotFoundException; import com.bytesw.xdf.exception.NotFoundException;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang.NullArgumentException;
import com.twilio.exception.AuthenticationException; import com.twilio.exception.AuthenticationException;
import lombok.extern.log4j.Log4j2;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -11,28 +10,27 @@ import java.util.Map; ...@@ -11,28 +10,27 @@ import java.util.Map;
@Log4j2 @Log4j2
public abstract class ProviderService { public abstract class ProviderService {
abstract void completeData(Map<String, Object> info, String SmsId, int Agent_id) throws AuthenticationException, Exception; abstract void completeData(Map<String, Object> info, String SmsId, int Agent_id) throws Exception;
public Map<String,Object> generateInfo(String sid, Map<String, Object> params) throws AuthenticationException { public Map<String, Object> generateInfo(String sid, Map<String, Object> params) throws AuthenticationException {
Map<String, Object> info = new HashMap<>(); Map<String, Object> info = new HashMap<>();
if(params == null){ if (params == null) {
return info; return info;
} }
try { try {
int agen_id = (Integer) params.get("agent_id"); int agen_id = (Integer) params.get("agent_id");
log.debug("AGEN_ID: " + agen_id);
this.completeData(info, sid, agen_id); this.completeData(info, sid, agen_id);
}catch (NotFoundException e){ } catch (NotFoundException e) {
throw new NotFoundException(e.getMessage()); throw new NotFoundException(e.getMessage());
}catch (java.lang.ClassCastException e){ } catch (java.lang.ClassCastException e) {
log.info("Body Input inválido"); log.info("Body Input inválido");
throw new ClassCastException("Input inválido"); throw new ClassCastException("Input inválido");
}catch (AuthenticationException e){ } catch (AuthenticationException e) {
throw new AuthenticationException(e.getMessage()); throw new AuthenticationException(e.getMessage());
}catch (InternalError e){ } catch (InternalError e) {
throw new InternalError(e.getMessage()); throw new InternalError(e.getMessage());
}catch (Exception e){ } catch (Exception e) {
throw new InternalError(e.getMessage()); throw new InternalError(e.getMessage());
} }
......
...@@ -7,44 +7,45 @@ import com.bytesw.bytebot.model.enums.ChannelEnum; ...@@ -7,44 +7,45 @@ import com.bytesw.bytebot.model.enums.ChannelEnum;
import com.bytesw.bytebot.model.enums.ProviderErrorEnum; import com.bytesw.bytebot.model.enums.ProviderErrorEnum;
import com.bytesw.bytebot.service.AgentService; import com.bytesw.bytebot.service.AgentService;
import com.bytesw.xdf.exception.NotFoundException; import com.bytesw.xdf.exception.NotFoundException;
import com.twilio.http.TwilioRestClient;
import lombok.extern.log4j.Log4j2;
import com.twilio.exception.AuthenticationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.twilio.Twilio; import com.twilio.Twilio;
import com.twilio.base.ResourceSet; import com.twilio.base.ResourceSet;
import com.twilio.exception.AuthenticationException;
import com.twilio.rest.api.v2010.account.message.Media; import com.twilio.rest.api.v2010.account.message.Media;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@Log4j2 @Log4j2
@Service @Service
public class TwilioService extends ProviderService{ public class TwilioService extends ProviderService {
@Autowired @Autowired
private AgentService agentService; private AgentService agentService;
public List<DeploymentChannelParamValueBean> getAllParamsWithRefresh(){ public List<DeploymentChannelParamValueBean> getAllParamsWithRefresh() {
return getAllParams(); return getAllParams();
} }
public List<DeploymentChannelParamValueBean> getAllParams(){ public List<DeploymentChannelParamValueBean> getAllParams() {
List<DeploymentChannelParamValueBean> agents = new ArrayList<>(); List<DeploymentChannelParamValueBean> agents = new ArrayList<>();
agents = agentService.GetKeysFromAgents(AgentStatusEnum.DEPLOYED); agents = agentService.GetKeysFromAgents(AgentStatusEnum.DEPLOYED);
log.debug("AGENTS FROM DB: "+agents);
return agents; return agents;
} }
@Override @Override
protected void completeData(Map<String, Object> info, String SmsId,int agent_id) throws AuthenticationException, Exception{ protected void completeData(Map<String, Object> info, String SmsId, int agent_id) throws Exception {
long start_time = System.nanoTime(); long start_time = System.nanoTime();
List<DeploymentChannelParamValueBean> agents = getAllParamsWithRefresh(); List<DeploymentChannelParamValueBean> agents = getAllParamsWithRefresh();
long end_time = System.nanoTime(); long end_time = System.nanoTime();
long duration = (end_time - start_time) / 1000000; long duration = (end_time - start_time) / 1000000;
log.debug("DURACION: "+duration); log.debug("DURACION: " + duration);
String sid = new String(); String sid = "";
String token = new String(); String token = "";
int MAX_LIMIT = 999; int MAX_LIMIT = 999;
List<String> data = new ArrayList<String>(); List<String> data = new ArrayList<String>();
...@@ -63,7 +64,7 @@ public class TwilioService extends ProviderService{ ...@@ -63,7 +64,7 @@ public class TwilioService extends ProviderService{
exist_agent = true; exist_agent = true;
} }
} }
if(!exist_agent){ if (!exist_agent) {
log.info("No existe un agente con el ID especificado"); log.info("No existe un agente con el ID especificado");
throw new Exception("No se encontró un agente con canales deployados con dicho ID"); throw new Exception("No se encontró un agente con canales deployados con dicho ID");
} }
...@@ -78,9 +79,9 @@ public class TwilioService extends ProviderService{ ...@@ -78,9 +79,9 @@ public class TwilioService extends ProviderService{
} }
if (cont == 0) { if (cont == 0) {
log.info("No hay imágenes para el mensaje indicado"); log.info("No hay imágenes para el mensaje indicado");
throw new NotFoundException("No se encontraron imágenes para el mensaje "+SmsId); throw new NotFoundException("No se encontraron imágenes para el mensaje " + SmsId);
} else { } else {
for(String image : Arrays.copyOfRange(images_droped, 0, cont)){ for (String image : Arrays.copyOfRange(images_droped, 0, cont)) {
data.add(image); data.add(image);
} }
} }
...@@ -89,20 +90,20 @@ public class TwilioService extends ProviderService{ ...@@ -89,20 +90,20 @@ public class TwilioService extends ProviderService{
info.put("data", data); info.put("data", data);
}catch (com.twilio.exception.ApiException e){ } catch (com.twilio.exception.ApiException e) {
if (e.getMessage().toString().equals(ProviderErrorEnum.AUTHENTICATE.getName())){ if (e.getMessage().equals(ProviderErrorEnum.AUTHENTICATE.getName())) {
log.error("Credenciales inválidas para borrar imagen"); log.error("Credenciales inválidas para borrar imagen");
throw new AuthenticationException("Credenciales inválidas"); throw new AuthenticationException("Credenciales inválidas");
}else if(e.getMessage().toString().contains(ProviderErrorEnum.CONEXION.getName())){ } else if (e.getMessage().contains(ProviderErrorEnum.CONEXION.getName())) {
log.error("Fallo temporal en la conexión con el Proveedor"); log.error("Fallo temporal en la conexión con el Proveedor");
throw new InternalError("Fallo en la conexión con Twilio API"); throw new InternalError("Fallo en la conexión con Twilio API");
}else{ } else {
log.info("El mensaje no existe para : " + SmsId + "\n" + e.getMessage()); log.info("El mensaje no existe para : " + SmsId + "\n" + e.getMessage());
throw new NotFoundException("No se encontraron imágenes para el mensaje "+SmsId); throw new NotFoundException("No se encontraron imágenes para el mensaje " + SmsId);
} }
}catch (NotFoundException e){ } catch (NotFoundException e) {
throw new NotFoundException(e.getMessage()); throw new NotFoundException(e.getMessage());
}catch (Exception e){ } catch (Exception e) {
throw new Exception(e.getMessage()); 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