Commit 4b0a2139 authored by Cristian Aguirre's avatar Cristian Aguirre

Twilio Delete Sensible Media Service

parent 956d17e3
......@@ -240,6 +240,12 @@
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.twilio.sdk/twilio -->
<dependency>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio</artifactId>
<version>8.22.0</version>
</dependency>
</dependencies>
<build>
......
......@@ -30,4 +30,7 @@ public class DeploymentChannelParamValueBean {
@Expose
private String value;
@Expose
private Long agen_id;
}
package com.bytesw.bytebot.controller;
import com.bytesw.bytebot.bean.AgentBean;
import com.bytesw.bytebot.bean.SummaryMessageBySentenceBean;
import com.bytesw.bytebot.service.dashboard.CustomerInteractionDashboardService;
import com.bytesw.bytebot.service.dashboard.OperativeDashboardService;
......
package com.bytesw.bytebot.controller;
import com.bytesw.bytebot.service.provider.TwilioService;
import com.bytesw.xdf.exception.NotFoundException;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang.NullArgumentException;
import com.twilio.exception.AuthenticationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.annotation.*;
import com.google.gson.Gson;
import java.util.HashMap;
import java.util.Map;
@Log4j2
@RestController
@RequestMapping("/providers")
public class ProviderController {
@Autowired
private TwilioService twilioService;
@Autowired
private Gson gson;
@RequestMapping(value="/twilio/messages/{sid_message}",method = {RequestMethod.DELETE})
public ResponseEntity<String> deleteSensibleInfo(@PathVariable("sid_message") String sid_message, @RequestBody Map<String,Object> body){
Map<String,Object> info = new HashMap<>();
try{
if(sid_message == null){
throw new InvalidInput();
}
info = twilioService.generateInfo(sid_message,body);
}
catch(NotFoundException e){
return new ResponseEntity<>(e.getMessage(),HttpStatus.NOT_FOUND);
}catch (AuthenticationException e){
return new ResponseEntity<>(e.getMessage(),HttpStatus.UNAUTHORIZED);
}catch (InternalError e){
return new ResponseEntity<>(e.getMessage(),HttpStatus.INTERNAL_SERVER_ERROR);
}
return new ResponseEntity<>(gson.toJson(info), HttpStatus.OK);
}
@ResponseStatus(value=HttpStatus.INTERNAL_SERVER_ERROR, reason = "Input vacío")
public class InvalidInput extends RuntimeException{
}
}
......@@ -15,17 +15,17 @@ import javax.persistence.*;
public class Action {
@Id
@Column(name = "ACTION_ID")
@Column(name = "action_id")
@TableGenerator(name = "AVB_ACTION_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME",
valueColumnName = "SEQ_COUNT", pkColumnValue = "AVB_ACTION_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.TABLE,generator = "AVB_ACTION_GENERATOR")
private Long id;
@Column(name = "ACTION_IDENT")
@Column(name = "action_ident")
private String identifier;
@ManyToOne(optional = false)
@JoinColumn(name = "GOAL_ID", referencedColumnName = "GOAL_ID")
@JoinColumn(name = "goal_id", referencedColumnName = "GOAL_ID")
private Goal goal;
}
......@@ -10,23 +10,23 @@ import java.time.OffsetDateTime;
@Cacheable(false)
@Entity
@Getter @Setter @ToString
@Table(name="AVB_EVENT_HISTORY")
@Table(name="avb_event_history")
@NamedQuery(name = "EventHistory.findByPK", query = "Select p from EventHistory p where p.id = ?1")
public class EventHistory {
@Id
@Column(name = "EVENH_ID")
@Column(name = "evenh_id")
@TableGenerator(name = "AVB_EVENT_HISTORY_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME",
valueColumnName = "SEQ_COUNT", pkColumnValue = "AVB_EVENT_HISTORY_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.TABLE,generator = "AVB_EVENT_HISTORY_GENERATOR")
private Long id;
@Column(name = "EVENH_SENDID")
@Column(name = "evenh_sendid")
private String senderId;
@Column(name = "EVENH_EVID")
@Column(name = "evenh_evid")
private Long eventId;
@Column(name = "EVENH_DATE")
@Column(name = "evenh_date")
private OffsetDateTime date;
}
......@@ -9,17 +9,20 @@ import javax.persistence.*;
@Cacheable(false)
@Entity
@Getter @Setter @ToString
@Table(name="AVB_GOAL")
@Table(name="avb_goal")
@NamedQuery(name = "Goal.findByPK", query = "Select p from Goal p where p.id = ?1")
public class Goal {
@Id
@Column(name = "GOAL_ID")
@Column(name = "goal_id")
@TableGenerator(name = "AVB_GOAL_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME",
valueColumnName = "SEQ_COUNT", pkColumnValue = "AVB_GOAL_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.TABLE,generator = "AVB_GOAL_GENERATOR")
private Long id;
@Column(name = "GOAL_IDENT")
@Column(name = "goal_ident")
private String identifier;
@Column(name = "agen_id")
private Long agenId;
}
......@@ -10,17 +10,23 @@ import javax.persistence.*;
@Cacheable(false)
@Entity
@Getter @Setter @ToString
@Table(name="AVB_INTENT")
@Table(name="avb_intent")
@NamedQuery(name = "Intent.findByPK", query = "Select p from Intent p where p.id = ?1")
public class Intent {
@Id
@Column(name = "INTEN_ID")
@Column(name = "inten_id")
@TableGenerator(name = "AVB_INTENT_DASHBOARD_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME",
valueColumnName = "SEQ_COUNT", pkColumnValue = "AVB_INTENT_DASHBOARD_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.TABLE,generator = "AVB_INTENT_DASHBOARD_GENERATOR")
private Long id;
@Column(name = "INTEN_IDENT")
@Column(name = "inten_ident")
private String identifier;
@Column(name = "intent_is_sensible")
private String sensible;
@Column(name = "agen_id")
private Long agenId;
}
......@@ -14,36 +14,36 @@ import java.time.OffsetDateTime;
@Cacheable(false)
@Entity
@Getter @Setter @ToString @Builder
@Table(name="AVB_MESSAGE")
@Table(name="avb_message")
@NamedQuery(name = "Message.findByPK", query = "Select p from Message p where p.id = ?1")
public class Message {
@Id
@Column(name = "MESSA_ID")
@Column(name = "messa_id")
@TableGenerator(name = "AVB_MESSAGE_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME",
valueColumnName = "SEQ_COUNT", pkColumnValue = "AVB_MESSAGE_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.TABLE,generator = "AVB_MESSAGE_GENERATOR")
private Long id;
@Column(name = "SESSION_ID")
@Column(name = "session_id")
private Long sessionId;
@Column(name = "MESSA_DATE")
@Column(name = "messa_date")
private OffsetDateTime date;
@Column(name = "MESSA_CONT")
@Column(name = "messa_cont")
private String content;
@Column(name = "MESSA_CORRE")
@Column(name = "messa_corre")
private int correlative;
@Column(name = "MESSA_PROB")
@Column(name = "messa_prob")
private BigDecimal probability;
@Convert(converter = MessageTypeConverter.class)
@Column(name = "MESSA_TYPE")
@Column(name = "messa_type")
private MessageTypeEnum type;
@Column(name = "INTEN_ID")
@Column(name = "inten_id")
private Long intentId;
}
......@@ -10,26 +10,26 @@ import java.time.OffsetDateTime;
@Cacheable(false)
@Entity
@Getter @Setter @ToString
@Table(name="AVB_RESPONSE")
@Table(name="avb_response")
@NamedQuery(name = "Response.findByPK", query = "Select p from Response p where p.id = ?1")
public class Response {
@Id
@Column(name = "RESPO_ID")
@Column(name = "respo_id")
@TableGenerator(name = "AVB_RESPONSE_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME",
valueColumnName = "SEQ_COUNT", pkColumnValue = "AVB_RESPONSE_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.TABLE,generator = "AVB_RESPONSE_GENERATOR")
private Long id;
@Column(name = "RESPO_DATE")
@Column(name = "respo_date")
private OffsetDateTime date;
@Column(name = "RESPO_CONT")
@Column(name = "respo_cont")
private String content;
@Column(name = "RESPO_CORR")
@Column(name = "respo_corr")
private int correlative;
@Column(name = "SESSION_ID")
@Column(name = "session_id")
private Long sessionId;
}
......@@ -11,24 +11,24 @@ import java.time.OffsetDateTime;
@Cacheable(false)
@Entity
@Getter @Setter @ToString
@Table(name="AVB_SESSION")
@Table(name="avb_session")
@NamedQuery(name = "Session.findByPK", query = "Select p from Session p where p.id = ?1")
public class Session {
@Id
@Column(name = "SESSION_ID")
@Column(name = "session_id")
@TableGenerator(name = "AVB_SESSION_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME",
valueColumnName = "SEQ_COUNT", pkColumnValue = "AVB_SESSION_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.TABLE,generator = "AVB_SESSION_GENERATOR")
private Long id;
@Column(name = "SESSION_DATE", nullable = false)
@Column(name = "session_date", nullable = false)
private OffsetDateTime sessionDate;
@Column(name = "SESSION_LEDAT", nullable = false)
@Column(name = "session_ledat", nullable = false)
private OffsetDateTime lastEventDate;
@Column(name = "SESSION_FRDAT", nullable = false)
@Column(name = "session_frdat", nullable = false)
private OffsetDateTime responseDate;
@ManyToOne
......@@ -36,6 +36,6 @@ public class Session {
private Channel channel;
@ManyToOne(optional = false)
@JoinColumn(name = "USER_ID", referencedColumnName = "USER_ID")
@JoinColumn(name = "user_id", referencedColumnName = "user_id")
private User user;
}
......@@ -10,24 +10,24 @@ import java.time.OffsetDateTime;
@Cacheable(false)
@Entity
@Getter @Setter @ToString
@Table(name="AVB_ACTION_SESSION")
@Table(name="avb_action_session")
@NamedQuery(name = "SessionAction.findByPK", query = "Select p from SessionAction p where p.id = ?1")
public class SessionAction {
@Id
@Column(name = "ASESS_ID")
@Column(name = "asess_id")
@TableGenerator(name = "AVB_ACTION_SESSION_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME",
valueColumnName = "SEQ_COUNT", pkColumnValue = "AVB_ACTION_SESSION_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.TABLE,generator = "AVB_ACTION_SESSION_GENERATOR")
private Long id;
@ManyToOne(optional = false)
@JoinColumn(name = "ACTION_ID", referencedColumnName = "ACTION_ID")
@JoinColumn(name = "action_id", referencedColumnName = "action_id")
private Action action;
@Column(name = "ASESS_DATE")
@Column(name = "asess_date")
private OffsetDateTime date;
@Column(name = "SESSION_ID")
@Column(name = "session_id")
private Long sessionId;
}
......@@ -8,17 +8,17 @@ import javax.persistence.*;
@Cacheable(false)
@Entity @Getter @Setter @ToString
@Table(name="AVB_USER")
@Table(name="avb_user")
@NamedQuery(name = "User.findByPK", query = "Select p from User p where p.id = ?1")
public class User {
@Id
@Column(name = "USER_ID")
@Column(name = "user_id")
@TableGenerator(name = "AVB_USER_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME",
valueColumnName = "SEQ_COUNT", pkColumnValue = "AVB_USER_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.TABLE,generator = "AVB_USER_GENERATOR")
private Long id;
@Column(name = "USER_IDENT")
@Column(name = "user_ident")
private String identifier;
}
......@@ -50,6 +50,16 @@ public class ProcessMessageService {
String name = (String) JsonUtils.getFieldFromJson(json, "$.name");
type = EventTypeEnum.fromString(event);
if (type != null) {
// Verify if message is valid
if(EventTypeEnum.USER.equals(type)){
String message_id = (String) JsonUtils.getFieldFromJson(json, "$.message_id");
log.debug("MESSAGE: "+message_id);
log.debug(("TIPO: "+message_id.getClass().getName()));
if (message_id == null){
return null;
}
}
if (EventTypeEnum.ACTION.equals(type) && EventTypeEnum.START_SESSION.getName().equals(name)) {
type = EventTypeEnum.START_SESSION;
}
......@@ -60,7 +70,6 @@ public class ProcessMessageService {
} catch (Exception e) {
log.debug(e);
}
return messageProcessed;
}
......
......@@ -11,6 +11,7 @@ import com.bytesw.bytebot.etl.jdbc.ETLMessageJDBCRepository;
import com.bytesw.bytebot.etl.jdbc.ETLSessionBotJDBCRepository;
import com.bytesw.bytebot.etl.model.*;
import com.bytesw.bytebot.etl.utils.JsonUtils;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
......@@ -21,6 +22,7 @@ import java.math.BigDecimal;
import java.time.OffsetDateTime;
import java.util.Optional;
@Log4j2
@Service
@Transactional
public class UserMessageProcessed extends MessageProcessedSupport implements MessageProcessed {
......@@ -71,6 +73,7 @@ public class UserMessageProcessed extends MessageProcessedSupport implements Mes
if (message != null) {
int correlative = messageJDBCRepository.getLastCorrelativeBySession(message.getSessionId());
correlative++;
log.debug("CORRE: "+correlative);
message.setCorrelative(correlative);
messageRepository.save(message);
......@@ -94,7 +97,6 @@ public class UserMessageProcessed extends MessageProcessedSupport implements Mes
session.setLastEventDate(date);
if (channelIdentifier != null && session.getChannel() == null) {
Optional<Channel> channelFound = chanelRepository.findByName(channelIdentifier);
// Optional<ETLChannel> channelFound = channelRepository.findByIdentifier(channelIdentifier);
if (channelFound.isPresent()) {
session.setChannel(channelFound.get());
}
......@@ -132,8 +134,10 @@ public class UserMessageProcessed extends MessageProcessedSupport implements Mes
if (MessageTypeEnum.ACCEPTED.equals(message.getType())) {
String intentName = (String) JsonUtils.getFieldFromJson(json, this.fields.get(INTENT_NAME));
log.debug("INTENTNAME: "+intentName);
Optional<Intent> optionalIntent = intentRepository.findByIdentifier(intentName);
if (optionalIntent.isPresent()) {
log.debug("Intencion presente en mensaje");
message.setIntentId(optionalIntent.get().getId());
}
}
......
package com.bytesw.bytebot.jdbc;
import com.bytesw.bytebot.bean.DeploymentChannelParamValueBean;
import com.bytesw.bytebot.model.enums.AgentStatusEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
public class AgentJDBCRepository {
@Autowired
@Qualifier("sqlSessionFactory")
private SqlSessionFactory sqlsession;
public List<DeploymentChannelParamValueBean> getCredentialsFromAgentStatus(String status){
SqlSession session = sqlsession.openSession();
try{
Map<String,Object> params = new HashMap<>();
params.put("status",status);
return session.selectList("com.bytesw.bytebot.dao.jdbc.AgentMapper.getCredentialsFromAgentandChannel",params);
} finally {
session.close();
}
}
}
......@@ -18,48 +18,48 @@ import java.util.List;
@Entity
@Getter @Setter @ToString @EqualsAndHashCode(of = "id")
@NoArgsConstructor
@Table(name = "AVB_AGENT")
@Table(name = "avb_agent")
@NamedQuery(name = "Agent.findByPK", query = "Select u from Agent u where u.id = ?1")
public class Agent implements Serializable {
@Id
@Column(name = "AGEN_ID")
@Column(name = "agen_id")
@GeneratedValue(strategy = GenerationType.TABLE, generator = "AVB_AGENT_GENERATOR")
@TableGenerator(name = "AVB_AGENT_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_COUNT",
pkColumnValue = "AVB_AGENT_SEQ", allocationSize = 1)
private Long id;
@Column(name = "AGEN_IDEN")
@Column(name = "agen_iden")
private String name;
@Column(name = "AGEN_DESCR")
@Column(name = "agen_descr")
private String description;
@Column(name = "AGEN_VERS")
@Column(name = "agen_vers")
private String version;
@Column(name = "AGEN_LANG")
@Column(name = "agen_lang")
@Convert(converter = LanguageConverter.class)
private LanguageEnum language;
@Column(name = "AGEN_TZONE")
@Column(name = "agen_tzone")
private String timezone;
@Lob
@Type(type = "org.hibernate.type.TextType")
@Basic(fetch = FetchType.LAZY)
@Column(name = "AGEN_AVAT")
@Column(name = "agen_avat")
private String avatar;
@ManyToOne
@JoinColumn(name = "COUN_ID", referencedColumnName = "COUN_ID")
@JoinColumn(name = "coun_id", referencedColumnName = "coun_id")
private Country country;
@Column(name = "AGEN_STATE")
@Column(name = "agen_state")
@Convert(converter = AgentStatusConverter.class)
private AgentStatusEnum status;
@Column(name = "AGEN_TYPE")
@Column(name = "agen_type")
@Convert(converter = AgentTypeConverter.class)
private AgentTypeEnum type;
......
......@@ -11,18 +11,18 @@ import java.util.List;
@ToString
@EqualsAndHashCode(of = "id")
@NoArgsConstructor
@Table(name = "AVB_COUNTRY")
@Table(name = "avb_country")
@NamedQuery(name = "Country.findByPK", query = "Select u from Country u where u.id = ?1")
public class Country {
@Id
@Column(name = "COUN_ID")
@Column(name = "coun_id")
@GeneratedValue(strategy = GenerationType.TABLE, generator = "AVB_COUNTRY_GENERATOR")
@TableGenerator(name = "AVB_COUNTRY_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_COUNT",
pkColumnValue = "AVB_COUNTRY_SEQ", allocationSize = 1)
private Long id;
@Column(name = "COUN_NAME", nullable = false)
@Column(name = "coun_name", nullable = false)
private String name;
@OneToMany(mappedBy = "country")
......
......@@ -22,6 +22,7 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.Type;
@Entity
@Getter
......@@ -52,7 +53,7 @@ public class QuestionFile {
@Column(name = "QUFI_UDATE", columnDefinition = "TIMESTAMP")
private LocalDateTime uploadDate;
@Lob
@Type(type="org.hibernate.type.BinaryType")
@Basic(fetch = FetchType.LAZY)
@Column(name = "QUFI_DATA", length= 100000, nullable = false)
private byte[] data;
......
......@@ -19,20 +19,20 @@ import javax.persistence.*;
@Entity
@Getter @Setter @ToString @EqualsAndHashCode(of = "id")
@NoArgsConstructor
@Table(name = "AVB_TIMEZONE")
@Table(name = "avb_timezone")
public class Timezone {
@Id
@Column(name = "TZON_ID")
@Column(name = "tzon_id")
@GeneratedValue(strategy = GenerationType.TABLE, generator = "AVB_TIMEZONE_GENERATOR")
@TableGenerator(name = "AVB_TIMEZONE_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_COUNT",
pkColumnValue = "AVB_TIMEZONE_SEQ", allocationSize = 1)
private Long id;
@Column(name = "TZON_ZONE", nullable = false)
@Column(name = "tzon_zone", nullable = false)
private String timezone;
@ManyToOne
@JoinColumn(name = "COUN_ID", referencedColumnName = "COUN_ID")
@JoinColumn(name = "coun_id", referencedColumnName = "coun_id")
private Country country;
}
package com.bytesw.bytebot.model.enums;
import lombok.Getter;
import java.util.HashMap;
import java.util.Map;
@Getter
public enum AgentParameterEnum {
ACCESS_ID("account-identifier"),
ACCESS_TOKEN("authentication-token");
private static final Map<String, AgentParameterEnum> map = new HashMap<>();
private String name;
AgentParameterEnum(String name){ this.name = name;}
public String getName() {return name;}
static {
for (AgentParameterEnum type : AgentParameterEnum.values()) {
map.put(type.name, type);
}
}
public static AgentParameterEnum fromString(String name) {
return map.get(name);
}
}
package com.bytesw.bytebot.model.enums;
import lombok.Getter;
import java.util.HashMap;
import java.util.Map;
@Getter
public enum ProviderErrorEnum {
AUTHENTICATE("Authenticate"),
CONEXION("name resolution");
private static final Map<String, ProviderErrorEnum> map = new HashMap<>();
private String name;
ProviderErrorEnum(String name){ this.name = name;}
public String getName() {return name;}
static {
for (ProviderErrorEnum type : ProviderErrorEnum.values()) {
map.put(type.name, type);
}
}
public static ProviderErrorEnum fromString(String name) {
return map.get(name);
}
}
package com.bytesw.bytebot.repository;
import com.bytesw.bytebot.model.Agent;
import com.bytesw.bytebot.model.enums.AgentStatusEnum;
import com.bytesw.bytebot.bean.AgentBean;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
/**
* @author Sebastián Chicoma Sandmann.
* @version 9-sep-2020
......@@ -16,4 +20,6 @@ import org.springframework.data.repository.CrudRepository;
* licencia de uso que firmó con Byte.
*/
public interface AgentRepository extends CrudRepository<Agent, Long>, JpaSpecificationExecutor<Agent> {
List<Agent> findByStatus(AgentStatusEnum status);
}
......@@ -2,6 +2,7 @@ package com.bytesw.bytebot.service;
import com.bytesw.bytebot.bean.*;
import com.bytesw.bytebot.model.*;
import com.bytesw.bytebot.jdbc.AgentJDBCRepository;
import com.bytesw.bytebot.model.enums.*;
import com.bytesw.bytebot.repository.*;
import com.bytesw.xdf.config.AppContextManager;
......@@ -30,6 +31,9 @@ public class AgentService extends CustomPaginationService<Agent> {
@Autowired
private AgentRepository agentRepository;
@Autowired
private AgentJDBCRepository agentJDBCRepository;
@Autowired
private CountryRepository countryRepository;
......@@ -53,7 +57,19 @@ public class AgentService extends CustomPaginationService<Agent> {
@Autowired
private ProducerTemplate producerTemplate;
public List<DeploymentChannelParamValueBean> GetKeysFromAgents(AgentStatusEnum status){
List<DeploymentChannelParamValueBean> values = agentJDBCRepository.getCredentialsFromAgentStatus(status.getName());
if (values == null){
values = new ArrayList<>();
}
log.debug("LLegue al getkeysfromagents");
//log.debug(values);
return values;
}
public void searchByPagination(Pagination<AgentBean> pagination) {
if (pagination.getItemsPerPage() == 0) {
pagination.setItemsPerPage(10);
......
package com.bytesw.bytebot.service;
import com.bytesw.bytebot.bean.DeploymentChannelParamValueBean;
import com.bytesw.bytebot.model.Agent;
import com.bytesw.bytebot.model.DeploymentChannelParamValue;
import com.bytesw.bytebot.service.AgentService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import com.bytesw.bytebot.repository.AgentRepository;
import com.bytesw.bytebot.model.enums.AgentStatusEnum;
import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Log4j2
@Component
@Transactional
public class ProviderStartupService implements ApplicationRunner {
@Autowired
private AgentService agentService;
@Autowired
private AgentRepository agentRepository;
public static List<DeploymentChannelParamValueBean> agents = new ArrayList<>();
@Override
public void run(ApplicationArguments args) throws Exception{
log.debug("Iinitial agents");
List<DeploymentChannelParamValueBean> agentsBD;
agents = agentService.GetKeysFromAgents(AgentStatusEnum.DEPLOYED);
log.debug(agents);
}
}
package com.bytesw.bytebot.service.provider;
import com.bytesw.xdf.exception.NotFoundException;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang.NullArgumentException;
import com.twilio.exception.AuthenticationException;
import java.util.HashMap;
import java.util.Map;
@Log4j2
public abstract class ProviderService {
abstract void completeData(Map<String, Object> info, String SmsId, int Agent_id) throws AuthenticationException;
public Map<String,Object> generateInfo(String sid, Map<String, Object> params) throws AuthenticationException {
Map<String, Object> info = new HashMap<>();
if(params == null){
return info;
}
try {
int agen_id = (Integer) params.get("agent_id");
log.debug("AGEN_ID: " + agen_id);
this.completeData(info, sid, agen_id);
}catch (NotFoundException e){
throw new NotFoundException(e.getMessage());
}catch (java.lang.NullPointerException e){
throw new NullArgumentException("Entradas vacías");
}catch (AuthenticationException e){
throw new AuthenticationException(e.getMessage());
}catch (InternalError e){
throw new InternalError(e.getMessage());
}
return info;
}
}
package com.bytesw.bytebot.service.provider;
import com.bytesw.bytebot.bean.DeploymentChannelParamValueBean;
import com.bytesw.bytebot.model.enums.AgentParameterEnum;
import com.bytesw.bytebot.model.enums.ProviderErrorEnum;
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.base.ResourceSet;
import com.twilio.rest.api.v2010.account.message.Media;
import com.bytesw.bytebot.service.ProviderStartupService;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@Log4j2
@Service
public class TwilioService extends ProviderService{
@Autowired
private ProviderStartupService providerStartupService;
@Override
protected void completeData(Map<String, Object> info, String SmsId,int agent_id) throws AuthenticationException{
String sid = new String();
String token = new String();
int MAX_LIMIT = 999;
Map<String,Object> data = new HashMap<>();
try {
boolean exist_agent = false;
for (DeploymentChannelParamValueBean agent : providerStartupService.agents) {
if (agent.getAgen_id() == agent_id) {
if (agent.getChannelParamName().equals(AgentParameterEnum.ACCESS_ID.getName())) {
sid = agent.getValue();
}
if (agent.getChannelParamName().equals(AgentParameterEnum.ACCESS_TOKEN.getName())) {
token = agent.getValue();
}
}
}
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) {
Media.deleter(SmsId, record.getSid()).delete();
images_droped[cont] = record.getSid();
cont++;
}
if (cont == 0) {
throw new NotFoundException("No se encontraron imágenes para dicho mensaje");
} else {
data.put("images_droped", Arrays.copyOfRange(images_droped, 0, cont));
}
info.put("status", "success");
info.put("data", data);
}catch (com.twilio.exception.ApiException e){
if (e.getMessage().toString().equals(ProviderErrorEnum.AUTHENTICATE.getName())){
throw new AuthenticationException("Credenciales inválidas");
}else if(e.getMessage().toString().contains(ProviderErrorEnum.CONEXION.getName())){
throw new InternalError("Fallo en la conexión con Twilio API");
}else{
throw new NotFoundException("No se encontro el mensaje para dicho Sid");
}
}
}
}
......@@ -27,7 +27,7 @@ application:
byte-bot:
batch:
chunk: 1
cron: 0/50 * * * * *
cron: 0/500 * * * * *
show-side-bar: false
test: ENC(OEchnTXpIZnCVdPNthgCZBfQjMt1AUS1)
name: xdf-example
......@@ -42,7 +42,7 @@ application:
web:
server: docker # weblogic, docker
ignore:
path: /v2/api-docs, /configuration/**, /swagger-resources/**, /swagger-ui.html, /webjars/**, /api-docs/**, /resources/**, /css/**, /js/**, /fonts/**, /img/**, /modules/**, /system/**, /views/**, /font-awesome/**, /translations/**, /bower_components/**, /cache.manifest, /favicon.ico, /service/file
path: /v2/api-docs, /configuration/**, /swagger-resources/**, /swagger-ui.html, /webjars/**, /api-docs/**, /resources/**, /css/**, /js/**, /fonts/**, /img/**, /modules/**, /system/**, /views/**, /font-awesome/**, /translations/**, /bower_components/**, /cache.manifest, /favicon.ico, /service/file, /providers/**
goodbyeURL: /goodbye
api.info:
title: 'pilotoXDF Service'
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.bytesw.bytebot.dao.jdbc.AgentMapper" >
<!-- In Config XML file -->
<cache readOnly="true"></cache>
<select id="getCredentialsFromAgentandChannel" resultType="DeploymentChannelParamValue" flushCache="true">
SELECT chpv_id as id,
chpa_label as channelParamName,
chpv_value as value,
AG.agen_id as agen_id
FROM AVB_DEPLOYMENT_CHANNEL_PARAM_VALUE ADCP
JOIN AVB_CHANNEL_PARAM ACP ON ACP.chpa_id=ADCP.chpa_id
JOIN avb_deployment_channel AD on AD.dcha_id=ADCP.dcha_id
JOIN avb_agent AG on AG.agen_id=AD.agen_id
WHERE agen_state=#{status}
</select>
</mapper>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.bytesw.bytebot.dao.jdbc.AgentMapper" >
<!-- In Config XML file -->
<cache readOnly="true"></cache>
<select id="getCredentialsFromAgentandChannel" resultType="DeploymentChannelParamValue" flushCache="true">
SELECT chpv_id as id,
chpa_label as channelParamName,
chpv_value as value,
AG.agen_id as agen_id
FROM AVB_DEPLOYMENT_CHANNEL_PARAM_VALUE ADCP
JOIN AVB_CHANNEL_PARAM ACP ON ACP.chpa_id=ADCP.chpa_id
JOIN avb_deployment_channel AD on AD.dcha_id=ADCP.dcha_id
JOIN avb_agent AG on AG.agen_id=AD.agen_id
WHERE agen_state=#{status}
</select>
</mapper>
......@@ -10,6 +10,7 @@
<typeAlias type="com.bytesw.bytebot.bean.SummaryMessageBySentenceBean" alias="SummaryMessageBySentence"/>
<typeAlias type="com.bytesw.bytebot.bean.ActionSummaryByGoalBean" alias="ActionSummaryByGoal"/>
<typeAlias type="com.bytesw.bytebot.bean.MessageByIntentBean" alias="MessageByIntent"/>
<typeAlias type="com.bytesw.bytebot.bean.DeploymentChannelParamValueBean" alias="DeploymentChannelParamValue"/>
<typeAlias type="com.bytesw.bytebot.etl.beans.SessionBean" alias="Session"/>
</typeAliases>
......@@ -19,10 +20,12 @@
<mapper resource="config/mappers/bytebot/${database-type-xdf}/MessageMapper.xml"/>
<mapper resource="config/mappers/bytebot/${database-type-xdf}/ResponseMapper.xml"/>
<mapper resource="config/mappers/bytebot/${database-type-xdf}/ActionMapper.xml"/>
<mapper resource="config/mappers/bytebot/${database-type-xdf}/AgentMapper.xml"/>
<mapper resource="config/mappers/xdf/${database-type-xdf}/AuditMapper.xml"/>
<mapper resource="config/mappers/etl/${database-type-xdf}/SessionMapper.xml"/>
<mapper resource="config/mappers/etl/${database-type-xdf}/MessageMapper.xml"/>
<mapper resource="config/mappers/etl/${database-type-xdf}/ResponseMapper.xml"/>
</mappers>
</configuration>
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