Commit f7f7fad2 authored by jgomez's avatar jgomez

Actualizacion proceso Writter

parent 8868b12a
......@@ -10,7 +10,7 @@ public class DeleteDataSensRegistryBean {
private Long id;
private Long inten_id;
private Long sender_id;
private String sender_id;
private String message_sid;
private String multimedia_sid;
private OffsetDateTime update_time;
......
......@@ -2,6 +2,8 @@ package com.bytesw.bytebot.etl.batch.writer;
import com.bytesw.bytebot.etl.batch.beans.DeleteDataSensBean;
import com.bytesw.bytebot.etl.batch.beans.DynaBean;
import com.bytesw.bytebot.etl.beans.IntentBean;
import com.bytesw.bytebot.etl.dao.IntentRepository;
import com.bytesw.bytebot.etl.enums.EventTypeEnum;
import com.bytesw.bytebot.etl.services.ProcessMessageService;
import com.bytesw.bytebot.etl.utils.JsonUtils;
......@@ -17,14 +19,19 @@ import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.item.ItemWriter;
import com.bytesw.bytebot.etl.batch.beans.DeleteDataSensRegistryBean;
import org.springframework.beans.factory.annotation.Autowired;
import javax.transaction.Transactional;
import java.util.List;
import java.util.Optional;
@Log4j2
public class DataSensibleJPAWriter implements ItemWriter<DynaBean>, StepExecutionListener {
@Autowired
IntentRepository intentRepository;
@Getter @Setter
private DeleteSensMessageService service;
......@@ -49,7 +56,19 @@ public class DataSensibleJPAWriter implements ItemWriter<DynaBean>, StepExecutio
if (intentByAgent.indexOf(intent) >= 0) {
log.debug("Llegue aca");
String SmSMessageSid = (String) JsonUtils.getFieldFromJson(json, "$.metadata.SmsMessageSid");
List<DeleteDataSensRegistryBean> deleteSensibleBean = service.deleteMessage(agent.getAgenId(),SmSMessageSid);
//Nuevos parametros para el llamado del metodo
//@TODO evaluar si transformar a MAP
Optional<IntentBean> intenId = this.intentRepository.findIntenNameById(intent, agent.getAgenId());
if (!intenId.isPresent()){
//Exception
}
String senderId = (String) JsonUtils.getFieldFromJson(json, "$.metadata.sender_id");;
List<DeleteDataSensRegistryBean> deleteSensibleBean = service.deleteMessage(agent.getAgenId()
,SmSMessageSid, intenId.get().getId(), senderId);
}
}
}
......
package com.bytesw.bytebot.etl.beans;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class IntentBean {
private Long id;
private String identifier;
private String sensible;
private Long agenId;
}
package com.bytesw.bytebot.etl.dao;
import com.bytesw.bytebot.etl.model.DeleteDataSensibleLog;
import org.springframework.data.repository.CrudRepository;
public interface DeleteDataSensibleLogRepository extends CrudRepository<DeleteDataSensibleLog, Long> {
}
package com.bytesw.bytebot.etl.dao;
import com.bytesw.bytebot.etl.beans.IntentBean;
import com.bytesw.bytebot.etl.model.Intent;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import java.util.Optional;
public interface IntentRepository extends CrudRepository<Intent, Long> {
Optional<Intent> findByIdentifier(String identifier);
@Query("SELECT s from avb_intent s WHERE s.identifier = :intenIdent and s.agenId = :agenId")
Optional<IntentBean> findIntenNameById(@Param("intenIdent") String intenIdent, @Param("agenId") Long agenId);
}
package com.bytesw.bytebot.etl.model;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import javax.persistence.*;
import java.sql.Timestamp;
@Cacheable(false)
@Entity
@Getter
@Setter
@ToString
@Table(name="avb_delete_sens_msg_log")
public class DeleteDataSensibleLog {
@Id
@Column(name = "dele_id")
@TableGenerator(name = "AVB_DELETE_MSG_SENS_LOG_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME",
valueColumnName = "SEQ_COUNT", pkColumnValue = "AVB_DELETE_MSG_SENS_LOG_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.TABLE,generator = "AVB_DELETE_MSG_SENS_LOG_GENERATOR")
private Long id;
@Column(name = "inten_id")
private Long intenId;
@Column(name = "send_id")
private String sendId;
@Column(name = "dele_smsg")
private String messageId;
@Column(name = "dele_msmsg")
private String multimediaId;
@Column(name = "dele_fecej")
private Timestamp date;
}
......@@ -8,6 +8,7 @@ import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -23,7 +24,7 @@ public class DeleteSensMessageService {
@Autowired
DeleteDataSensibleControlRepository deleteDataSensibleControlRepository;
public List<DeleteDataSensRegistryBean> deleteMessage(Long agentId, String SmsMessage) throws Exception{
public List<DeleteDataSensRegistryBean> deleteMessage(Long agentId, String SmsMessage, Long inten_id, String sender_id) throws Exception{
List<DeleteDataSensRegistryBean> deleteMessages = new ArrayList<DeleteDataSensRegistryBean>();
Map<String,Object> data = new HashMap<>();
Map<String,Object> params = new HashMap<>();
......@@ -31,16 +32,37 @@ public class DeleteSensMessageService {
try{
Map<String,Object> result = new HashMap<>();
data = twilioService.generateInfo(SmsMessage,params);
if(data.isEmpty()){
//Excepcion
}
log.debug("RESPUESTA: "+data);
DeleteDataSensRegistryBean registry = new DeleteDataSensRegistryBean();
if(data.get("status") != null){
if(data.get("status") != null){
List<String> images = new ArrayList<String>();
images = (List<String>) data.get("data");
for(String image : images){
// Info del Bean
registry.setMultimedia_sid(image);
registry.setMessage_sid(SmsMessage);
registry.setUpdate_time(OffsetDateTime.now());
registry.setInten_id(inten_id);
registry.setSender_id(sender_id);
// Agregado a la lista
deleteMessages.add(registry);
}
}
}catch (NotFoundException e){
log.debug(e);
log.debug("Imagen no encontrada");
}catch (Exception e ){
log.debug(e);
log.debug("Error consumiento servicio de Proveedor");
}
return deleteMessages;
......
......@@ -33,6 +33,7 @@ public abstract class ProviderService {
}catch (InternalError e){
throw new InternalError(e.getMessage());
}
return info;
}
}
......@@ -47,7 +47,8 @@ public class TwilioService extends ProviderService{
String token = new String();
int MAX_LIMIT = 999;
Map<String,Object> data = new HashMap<>();
List<String> data = new ArrayList<String>();
log.debug(agents);
try {
boolean exist_agent = false;
......@@ -81,11 +82,16 @@ public class TwilioService extends ProviderService{
log.info("No hay imágenes para el mensaje indicado");
throw new NotFoundException("No se encontraron imágenes para dicho mensaje");
} else {
data.put("images_droped", Arrays.copyOfRange(images_droped, 0, cont));
// data.put("images_droped", Arrays.copyOfRange(images_droped, 0, cont));
for(String image : Arrays.copyOfRange(images_droped, 0, cont)){
data.add(image);
}
}
info.put("status", "success");
info.put("data", data);
}catch (com.twilio.exception.ApiException e){
if (e.getMessage().toString().equals(ProviderErrorEnum.AUTHENTICATE.getName())){
log.error("Credenciales inválidas para borrar imagen");
......
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