Commit b5f98f8b authored by Sebastian Chicoma's avatar Sebastian Chicoma

Nuevos cambios para soportar el envio a la web de: canales, parámetros y países

parent 34c3a4ef
......@@ -59,6 +59,9 @@ public class AgentBean {
@Expose
private List<DeploymentChannelBean> deploymentChannels;
@Expose
private List<FrequentQuestionBean> frequentQuestion;
public static AgentBean miniClone(Agent agent) {
AgentBean bean = new AgentBean();
......
package com.bytesw.bytebot.bean;
import com.bytesw.bytebot.model.Channel;
import com.bytesw.bytebot.model.ChannelParam;
import com.google.gson.annotations.Expose;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* @author Sebastian Chicoma Sandmann
* @version 10-sep-2020
* <p>
* Copyright (c) 2020 Byte, S.A. Todos los derechos reservados.
* <p>
* Este software constituye información confidencial y propietaria de Byte, S.A.
* ("Información Confidencial"). Usted no debe develar dicha Información
* Confidencial y debe usarla de acuerdo con los términos de aceptación de
* licencia de uso que firmó con Byte.
*/
@Getter
@Setter
@ToString
public class ChannelBean {
@Expose
private Long id;
@Expose
private String name;
@Expose
private String image;
@Expose
private List<ChannelParamBean> parameters;
public static ChannelBean clone(Channel channel) {
ChannelBean bean = new ChannelBean();
bean.setId(channel.getId());
bean.setName(channel.getName());
bean.setImage(channel.getImage());
bean.setParameters(new ArrayList<>());
if (channel.getParameters() != null) {
Collections.sort(channel.getParameters(), (o1, o2) -> o1.getOrder() - o2.getOrder());
for (ChannelParam param : channel.getParameters()) {
bean.getParameters().add(ChannelParamBean.clone(param));
}
}
return bean;
}
}
package com.bytesw.bytebot.bean;
import com.bytesw.bytebot.model.ChannelParam;
import com.google.gson.annotations.Expose;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* @author Sebastian Chicoma Sandmann
* @version 10-sep-2020
* <p>
* Copyright (c) 2020 Byte, S.A. Todos los derechos reservados.
* <p>
* Este software constituye información confidencial y propietaria de Byte, S.A.
* ("Información Confidencial"). Usted no debe develar dicha Información
* Confidencial y debe usarla de acuerdo con los términos de aceptación de
* licencia de uso que firmó con Byte.
*/
@Getter
@Setter
@ToString
public class ChannelParamBean {
@Expose
private String name;
@Expose
private String label;
@Expose
private Integer maxlength;
@Expose
private String type;
@Expose
private Boolean required;
@Expose
private Integer order;
@Expose
private String traductions;
public static ChannelParamBean clone(ChannelParam channelParam) {
ChannelParamBean bean = new ChannelParamBean();
bean.setName(channelParam.getName());
bean.setLabel(channelParam.getLabel());
bean.setMaxlength(channelParam.getMaxlength());
bean.setRequired(channelParam.isRequired());
bean.setType(channelParam.getType());
bean.setOrder(channelParam.getOrder());
bean.setTraductions(channelParam.getTraductions());
return bean;
}
}
package com.bytesw.bytebot.bean;
import com.bytesw.bytebot.model.Country;
import com.bytesw.bytebot.model.Timezone;
import com.google.gson.annotations.Expose;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.util.ArrayList;
import java.util.List;
/**
* @author Sebastian Chicoma Sandmann
* @version 10-sep-2020
* <p>
* Copyright (c) 2020 Byte, S.A. Todos los derechos reservados.
* <p>
* Este software constituye información confidencial y propietaria de Byte, S.A.
* ("Información Confidencial"). Usted no debe develar dicha Información
* Confidencial y debe usarla de acuerdo con los términos de aceptación de
* licencia de uso que firmó con Byte.
*/
@Getter
@Setter
@ToString
public class CountryBean {
@Expose
private Long id;
@Expose
private String name;
@Expose
private List<String> timezones;
public static CountryBean clone(Country country) {
CountryBean bean = new CountryBean();
bean.setId(country.getId());
bean.setName(country.getName());
bean.setTimezones(new ArrayList<>());
if (country.getTimezones() != null) {
for (Timezone timezone : country.getTimezones()) {
bean.getTimezones().add(timezone.getTimezone());
}
}
return bean;
}
}
......@@ -26,7 +26,7 @@ public class DeploymentChannelParamValueBean {
private Long id;
@Expose
private Long channelParamId;
private String channelParamName;
@Expose
private String value;
......
package com.bytesw.bytebot.bean;
import com.google.gson.annotations.Expose;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* @author Sebastian Chicoma Sandmann
* @version 09-sep-2020
* <p>
* Copyright (c) 2020 Byte, S.A. Todos los derechos reservados.
* <p>
* Este software constituye información confidencial y propietaria de Byte, S.A.
* ("Información Confidencial"). Usted no debe develar dicha Información
* Confidencial y debe usarla de acuerdo con los términos de aceptación de
* licencia de uso que firmó con Byte.
*/
@Getter
@Setter
@ToString
public class FrequentQuestionBean {
@Expose
private Long id;
@Expose
private String filename;
@Expose
private String description;
@Expose
private String status;
@Expose
private String user;
@Expose
private String uploadDate;
}
......@@ -47,7 +47,6 @@ public class AgentController {
}
}
@GetMapping(value = "/{id}")
@PreAuthorize("hasPermission(this, 'view')")
public ResponseEntity<String> getExternalSystemServiceById(@ApiParam(value = "id", required = true) @PathVariable("id") Long id) {
......@@ -128,4 +127,32 @@ public class AgentController {
return new ResponseEntity<>(gsonBuilder.create().toJson(ExceptionUtils.getFullStackTrace(e)), hs);
}
}
@GetMapping(value = "/countries")
public ResponseEntity<String> getCountries() {
HttpStatus hs = HttpStatus.OK;
try {
return new ResponseEntity<>(gsonBuilder.create().toJson(agentService.getCountries()), hs);
} catch (Exception e) {
log.error("Error detectado: ", e);
hs = HttpStatus.INTERNAL_SERVER_ERROR;
return new ResponseEntity<>(gsonBuilder.create().toJson(ExceptionUtils.getFullStackTrace(e)), hs);
}
}
@GetMapping(value = "/channels")
public ResponseEntity<String> getChannels() {
HttpStatus hs = HttpStatus.OK;
try {
return new ResponseEntity<>(gsonBuilder.create().toJson(agentService.getChannels()), hs);
} catch (Exception e) {
log.error("Error detectado: ", e);
hs = HttpStatus.INTERNAL_SERVER_ERROR;
return new ResponseEntity<>(gsonBuilder.create().toJson(ExceptionUtils.getFullStackTrace(e)), hs);
}
}
}
package com.bytesw.bytebot.model;
import com.bytesw.bytebot.model.converters.AgentStatusConverter;
import com.bytesw.bytebot.model.converters.AgentTypeConverter;
import com.bytesw.bytebot.model.converters.LanguageConverter;
import com.bytesw.bytebot.model.converters.StatusConverter;
import com.bytesw.bytebot.model.enums.AgentStatusEnum;
import com.bytesw.bytebot.model.enums.AgentTypeEnum;
import com.bytesw.bytebot.model.enums.LanguageEnum;
import com.bytesw.bytebot.model.enums.StatusEnum;
import lombok.*;
......@@ -18,10 +22,10 @@ import java.util.List;
public class Agent implements Serializable {
@Id
@TableGenerator(name = "BBOT_AGENT_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME",
valueColumnName = "SEQ_COUNT", pkColumnValue = "BBOT_AGENT_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.TABLE, generator = "BBOT_AGENT_GENERATOR")
@Column(name = "AGEN_ID")
@GeneratedValue(strategy = GenerationType.TABLE, generator = "BBOT_AGENT_GENERATOR")
@TableGenerator(name = "BBOT_AGENT_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_COUNT",
pkColumnValue = "BBOT_AGENT_SEQ")
private Long id;
@Column(name = "AGEN_IDEN")
......@@ -34,7 +38,8 @@ public class Agent implements Serializable {
private String version;
@Column(name = "AGEN_LANG")
private String language;
@Convert(converter = LanguageConverter.class)
private LanguageEnum language;
@Column(name = "AGEN_TZONE")
private String timezone;
......@@ -49,12 +54,13 @@ public class Agent implements Serializable {
private Country country;
@Column(name = "AGEN_STATE")
@Convert(converter = StatusConverter.class)
private StatusEnum status;
@Convert(converter = AgentStatusConverter.class)
private AgentStatusEnum status;
@Column(name = "AGEN_TYPE")
@Convert(converter = AgentTypeConverter.class)
private AgentTypeEnum type;
@OneToMany(mappedBy = "agent")
private List<DeploymentChannel> deploymentChannels;
......
......@@ -29,13 +29,17 @@ public class Channel {
@Id
@Column(name = "CHAN_ID")
@GeneratedValue(strategy = GenerationType.TABLE, generator = "BBOT_CHANNEL_SEQ")
@TableGenerator(name = "BBOT_CHANNEL_SEQ", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_VALUE")
@GeneratedValue(strategy = GenerationType.TABLE, generator = "BBOT_CHANNEL_GENERATOR")
@TableGenerator(name = "BBOT_CHANNEL_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_COUNT",
pkColumnValue = "BBOT_CHANNEL_SEQ")
private Long id;
@Column(name = "CHAN_IDEN")
private String name;
@Column(name = "CHAN_IMAG")
private String image;
@OneToMany(mappedBy = "channel")
private List<ChannelParam> parameters;
......
......@@ -29,8 +29,9 @@ public class ChannelParam {
@Id
@Column(name = "CHPA_ID")
@GeneratedValue(strategy = GenerationType.TABLE, generator = "BBOT_CHANNEL_PARAM_SEQ")
@TableGenerator(name = "BBOT_CHANNEL_PARAM_SEQ", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_VALUE")
@GeneratedValue(strategy = GenerationType.TABLE, generator = "BBOT_CHANNEL_PARAM_GENERATOR")
@TableGenerator(name = "BBOT_CHANNEL_PARAM_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_COUNT",
pkColumnValue = "BBOT_CHANNEL_PARAM_SEQ")
private Long id;
@Column(name = "CHPA_IDEN")
......@@ -53,6 +54,9 @@ public class ChannelParam {
@Column(name = "CHPA_TRADU")
private String traductions;
@Column(name = "CHPA_TYPE")
private String type;
@Column(name = "CHPA_MAXLE")
private Integer maxlength;
......
......@@ -3,21 +3,28 @@ package com.bytesw.bytebot.model;
import lombok.*;
import javax.persistence.*;
import java.util.List;
@Entity
@Getter @Setter @ToString @EqualsAndHashCode(of = "id")
@Getter
@Setter
@ToString
@EqualsAndHashCode(of = "id")
@NoArgsConstructor
@Table(name = "BBOT_COUNTRY")
@NamedQuery(name = "Country.findByPK", query = "Select u from Country u where u.id = ?1")
public class Country {
@Id
@TableGenerator(name = "BBOT_COUNTRY_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME",
valueColumnName = "SEQ_COUNT", pkColumnValue = "BBOT_COUNTRY_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.TABLE, generator = "BBOT_COUNTRY_GENERATOR")
@Column(name = "COUN_ID")
@GeneratedValue(strategy = GenerationType.TABLE, generator = "BBOT_COUNTRY_GENERATOR")
@TableGenerator(name = "BBOT_COUNTRY_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_COUNT",
pkColumnValue = "BBOT_COUNTRY_SEQ")
private Long id;
@Column(name = "COUN_NAME", nullable = false)
private String name;
@OneToMany(mappedBy = "country")
private List<Timezone> timezones;
}
......@@ -31,8 +31,9 @@ public class DeploymentChannel {
@Id
@Column(name = "DCHA_ID")
@GeneratedValue(strategy = GenerationType.TABLE, generator = "BBOT_DEPLOYMENT_CHANNEL_SEQ")
@TableGenerator(name = "BBOT_DEPLOYMENT_CHANNEL_SEQ", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_VALUE")
@GeneratedValue(strategy = GenerationType.TABLE, generator = "BBOT_DEPLOYMENT_CHANNEL_GENERATOR")
@TableGenerator(name = "BBOT_DEPLOYMENT_CHANNEL_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_COUNT",
pkColumnValue = "BBOT_DEPLOYMENT_CHANNEL_SEQ")
private Long id;
@Column(name = "DCHA_NAME")
......
......@@ -19,7 +19,7 @@ import javax.persistence.*;
* licencia de uso que firmó con Byte.
*/
@Entity
@Table(name = "BBOT_CHANNEL_PARAM_VALUE")
@Table(name = "BBOT_DEPLOYMENT_CHANNEL_PARAM_VALUE")
@Getter
@Setter
@ToString
......@@ -27,9 +27,10 @@ import javax.persistence.*;
public class DeploymentChannelParamValue {
@Id
@Column(name = "CPVA_ID")
@GeneratedValue(strategy = GenerationType.TABLE, generator = "BBOT_CHANNEL_PARAM_VALUE_SEQ")
@TableGenerator(name = "BBOT_CHANNEL_PARAM_VALUE_SEQ", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_VALUE")
@Column(name = "CHPV_ID")
@GeneratedValue(strategy = GenerationType.TABLE, generator = "BBOT_DEPLOYMENT_CHANNEL_PARAM_VALUE_GENERATOR")
@TableGenerator(name = "BBOT_DEPLOYMENT_CHANNEL_PARAM_VALUE_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_COUNT",
pkColumnValue = "BBOT_DEPLOYMENT_CHANNEL_PARAM_VALUE_SEQ")
private Long id;
@ManyToOne
......@@ -40,7 +41,7 @@ public class DeploymentChannelParamValue {
@JoinColumn(name = "DCHA_ID", referencedColumnName = "DCHA_ID")
private DeploymentChannel deploymentChannel;
@Column(name = "CHPA_VALUE")
@Column(name = "CHPV_VALUE")
private String value;
}
package com.bytesw.bytebot.model;
import com.bytesw.bytebot.model.converters.FrequentQuestionStatusConverter;
import com.bytesw.bytebot.model.converters.StatusConverter;
import com.bytesw.bytebot.model.enums.FrequentQuestionStatusEnum;
import com.bytesw.bytebot.model.enums.StatusEnum;
import lombok.EqualsAndHashCode;
import lombok.Getter;
......@@ -31,22 +33,23 @@ import java.time.OffsetDateTime;
public class FrequentQuestion {
@Id
@Column(name = "FQUE_ID")
@GeneratedValue(strategy = GenerationType.TABLE, generator = "BBOT_FREQUENT_QUESTION_SEQ")
@TableGenerator(name = "BBOT_FREQUENT_QUESTION_SEQ", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_VALUE")
@GeneratedValue(strategy = GenerationType.TABLE, generator = "BBOT_FREQUENT_QUESTION_GENERATOR")
@TableGenerator(name = "BBOT_FREQUENT_QUESTION_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_COUNT",
pkColumnValue = "BBOT_FREQUENT_QUESTION_SEQ")
private Long id;
@Column(name = "FQUE_PATH")
private String filePath;
//@Column(name = "FQUE_PATH")
//private String filePath;
@Column(name = "FQUE_NAME")
private String filename;
@Column(name = "FQUE_DESC")
private String description;
//@Column(name = "FQUE_DESC")
//private String description;
@Column(name = "FQUE_STATE")
@Convert(converter = StatusConverter.class)
private StatusEnum status;
@Convert(converter = FrequentQuestionStatusConverter.class)
private FrequentQuestionStatusEnum status;
@ManyToOne
@JoinColumn(name = "AGEN_ID", referencedColumnName = "AGEN_ID")
......
package com.bytesw.bytebot.model;
import lombok.*;
import javax.persistence.*;
/**
* @author Sebastian Chicoma Sandmann
* @version 10-sep-2020
*
* Copyright (c) 2020 Byte, S.A. Todos los derechos reservados.
*
* Este software constituye información confidencial y propietaria de Byte, S.A.
* ("Información Confidencial"). Usted no debe develar dicha Información
* Confidencial y debe usarla de acuerdo con los términos de aceptación de
* licencia de uso que firmó con Byte.
*/
@Entity
@Getter @Setter @ToString @EqualsAndHashCode(of = "id")
@NoArgsConstructor
@Table(name = "BBOT_TIMEZONE")
public class Timezone {
@Id
@Column(name = "TZON_ID")
@GeneratedValue(strategy = GenerationType.TABLE, generator = "BBOT_TIMEZONE_GENERATOR")
@TableGenerator(name = "BBOT_TIMEZONE_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_COUNT",
pkColumnValue = "BBOT_TIMEZONE_SEQ")
private Long id;
@Column(name = "TZON_ZONE", nullable = false)
private String timezone;
@ManyToOne
@JoinColumn(name = "COUN_ID", referencedColumnName = "COUN_ID")
private Country country;
}
package com.bytesw.bytebot.model.converters;
import com.bytesw.bytebot.model.enums.AgentStatusEnum;
import org.apache.camel.Converter;
import javax.persistence.AttributeConverter;
/**
* @author Sebastian Chicoma Sandmann
* @version 09-sep-2020
*
* Copyright (c) 2020 Byte, S.A. Todos los derechos reservados.
*
* Este software constituye información confidencial y propietaria de Byte, S.A.
* ("Información Confidencial"). Usted no debe develar dicha Información
* Confidencial y debe usarla de acuerdo con los términos de aceptación de
* licencia de uso que firmó con Byte.
*/
@Converter
public class AgentStatusConverter implements AttributeConverter<AgentStatusEnum, String> {
@Override
public String convertToDatabaseColumn(AgentStatusEnum value) {
return value.getName();
}
@Override
public AgentStatusEnum convertToEntityAttribute(String value) {
return AgentStatusEnum.fromString(value);
}
}
\ No newline at end of file
package com.bytesw.bytebot.model.converters;
import com.bytesw.bytebot.model.enums.AgentStatusEnum;
import com.bytesw.bytebot.model.enums.FrequentQuestionStatusEnum;
import org.apache.camel.Converter;
import javax.persistence.AttributeConverter;
/**
* @author Sebastian Chicoma Sandmann
* @version 10-sep-2020
*
* Copyright (c) 2020 Byte, S.A. Todos los derechos reservados.
*
* Este software constituye información confidencial y propietaria de Byte, S.A.
* ("Información Confidencial"). Usted no debe develar dicha Información
* Confidencial y debe usarla de acuerdo con los términos de aceptación de
* licencia de uso que firmó con Byte.
*/
@Converter
public class FrequentQuestionStatusConverter implements AttributeConverter<FrequentQuestionStatusEnum, String> {
@Override
public String convertToDatabaseColumn(FrequentQuestionStatusEnum value) {
return value.getName();
}
@Override
public FrequentQuestionStatusEnum convertToEntityAttribute(String value) {
return FrequentQuestionStatusEnum.fromString(value);
}
}
\ No newline at end of file
package com.bytesw.bytebot.model.converters;
import com.bytesw.bytebot.model.enums.LanguageEnum;
import org.apache.camel.Converter;
import javax.persistence.AttributeConverter;
/**
* @author Sebastian Chicoma Sandmann
* @version 09-sep-2020
*
* Copyright (c) 2020 Byte, S.A. Todos los derechos reservados.
*
* Este software constituye información confidencial y propietaria de Byte, S.A.
* ("Información Confidencial"). Usted no debe develar dicha Información
* Confidencial y debe usarla de acuerdo con los términos de aceptación de
* licencia de uso que firmó con Byte.
*/
@Converter
public class LanguageConverter implements AttributeConverter<LanguageEnum, String> {
@Override
public String convertToDatabaseColumn(LanguageEnum value) {
return value.getName();
}
@Override
public LanguageEnum convertToEntityAttribute(String value) {
return LanguageEnum.fromString(value);
}
}
\ No newline at end of file
package com.bytesw.bytebot.model.enums;
import lombok.Getter;
import java.util.HashMap;
import java.util.Map;
/**
* @author Sebastian Chicoma Sandmann
* @version 09-sep-2020
*
* Copyright (c) 2020 Byte, S.A. Todos los derechos reservados.
*
* Este software constituye información confidencial y propietaria de Byte, S.A.
* ("Información Confidencial"). Usted no debe develar dicha Información
* Confidencial y debe usarla de acuerdo con los términos de aceptación de
* licencia de uso que firmó con Byte.
*/
@Getter
public enum AgentStatusEnum {
CREATED("CR"),
DEPLOYED("DP"),
DELETED("DE");
private static final Map<String, AgentStatusEnum> map = new HashMap<>();
private String name;
AgentStatusEnum(String name) {
this.name = name;
}
static {
for (AgentStatusEnum type : AgentStatusEnum.values()) {
map.put(type.name, type);
}
}
public static AgentStatusEnum fromString(String name) {
return map.get(name);
}
}
......@@ -5,7 +5,7 @@ import java.util.Map;
import java.util.NoSuchElementException;
public enum AgentTypeEnum {
FREQUENT_QUESTION("F");
FREQUENT_QUESTION("FQ");
private final String name;
......
package com.bytesw.bytebot.model.enums;
import lombok.Getter;
import java.util.HashMap;
import java.util.Map;
/**
* @author Sebastian Chicoma Sandmann
* @version 09-sep-2020
*
* Copyright (c) 2020 Byte, S.A. Todos los derechos reservados.
*
* Este software constituye información confidencial y propietaria de Byte, S.A.
* ("Información Confidencial"). Usted no debe develar dicha Información
* Confidencial y debe usarla de acuerdo con los términos de aceptación de
* licencia de uso que firmó con Byte.
*/
@Getter
public enum FrequentQuestionStatusEnum {
ACTIVE("AC"),
UPLOADED("UP"),
DELETED("DE");
private static final Map<String, FrequentQuestionStatusEnum> map = new HashMap<>();
private String name;
FrequentQuestionStatusEnum(String name) {
this.name = name;
}
static {
for (FrequentQuestionStatusEnum type : FrequentQuestionStatusEnum.values()) {
map.put(type.name, type);
}
}
public static FrequentQuestionStatusEnum fromString(String name) {
return map.get(name);
}
}
package com.bytesw.bytebot.model.enums;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;
public enum LanguageEnum {
SPANISH("ES");
private final String name;
private static final Map<String, LanguageEnum> map = new HashMap<>();
static {
for (LanguageEnum type : LanguageEnum.values()) {
map.put(type.name, type);
}
}
LanguageEnum(String name) {
this.name = name;
}
public String getName() {
return name;
}
public static LanguageEnum fromString(String name) {
if (map.containsKey(name)) {
return map.get(name);
}
throw new NoSuchElementException(name + " not found");
}
}
......@@ -4,6 +4,8 @@ import com.bytesw.bytebot.model.Channel;
import com.bytesw.bytebot.model.ChannelParam;
import org.springframework.data.repository.CrudRepository;
import java.util.Optional;
/**
* @author Sebastián Chicoma Sandmann.
* @version 9-sep-2020
......@@ -16,4 +18,7 @@ import org.springframework.data.repository.CrudRepository;
* licencia de uso que firmó con Byte.
*/
public interface ChannelParamRepository extends CrudRepository<ChannelParam, Long> {
Optional<ChannelParam> findByName(String name);
}
package com.bytesw.bytebot.repository;
import com.bytesw.bytebot.model.DeploymentChannel;
import com.bytesw.bytebot.model.FrequentQuestion;
import org.springframework.data.repository.CrudRepository;
/**
* @author Sebastián Chicoma Sandmann.
* @version 9-sep-2020
* <p>
* Copyright (c) 2020 Byte, S.A. Todos los derechos reservados.
* <p>
* Este software constituye información confidencial y propietaria de Byte, S.A.
* ("Información Confidencial"). Usted no debe develar dicha Información
* Confidencial y debe usarla de acuerdo con los términos de aceptación de
* licencia de uso que firmó con Byte.
*/
public interface FrequentQuestionRepository extends CrudRepository<FrequentQuestion, Long> {
}
package com.bytesw.bytebot.service;
import com.bytesw.bytebot.bean.AgentBean;
import com.bytesw.bytebot.bean.DeploymentChannelBean;
import com.bytesw.bytebot.bean.DeploymentChannelParamValueBean;
import com.bytesw.bytebot.bean.*;
import com.bytesw.bytebot.model.*;
import com.bytesw.bytebot.model.enums.AgentTypeEnum;
import com.bytesw.bytebot.model.enums.StatusEnum;
import com.bytesw.bytebot.model.enums.*;
import com.bytesw.bytebot.repository.*;
import com.bytesw.xdf.sql.beans.Pagination;
import lombok.extern.log4j.Log4j2;
......@@ -19,7 +16,9 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.swing.text.html.Option;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
......@@ -46,6 +45,9 @@ public class AgentService extends CustomPaginationService<Agent> {
@Autowired
private ChannelParamRepository channelParamRepository;
@Autowired
private FrequentQuestionRepository frequentQuestionRepository;
@Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
public void searchByPagination(Pagination<AgentBean> pagination) {
if (pagination.getItemsPerPage() == 0) {
......@@ -65,7 +67,7 @@ public class AgentService extends CustomPaginationService<Agent> {
}
Specification<Agent> specification = (Specification<Agent>) (root, query, criteriaBuilder)
-> criteriaBuilder.notEqual(root.get("status"), StatusEnum.DELETED);
-> criteriaBuilder.notEqual(root.get("status"), AgentStatusEnum.DELETED);
if (pagination.getFilterExpression() != null && pagination.getFilterExpression().length() > 0) {
specification = createSpecification(pagination.getFilterExpression()).and(specification);
......@@ -103,7 +105,7 @@ public class AgentService extends CustomPaginationService<Agent> {
if (agent == null) {
agentBD = new Agent();
agentBD.setStatus(StatusEnum.ACTIVE);
agentBD.setStatus(AgentStatusEnum.CREATED);
isModify = false;
}
......@@ -112,7 +114,7 @@ public class AgentService extends CustomPaginationService<Agent> {
agentBD.setName(agent.getName());
agentBD.setDescription(agent.getDescription());
agentBD.setLanguage(agent.getLanguage());
agentBD.setLanguage(LanguageEnum.fromString(agent.getLanguage()));
agentBD.setTimezone(agent.getTimezone());
agentBD.setVersion(agent.getVersion());
agentBD.setType(AgentTypeEnum.fromString(agent.getType()));
......@@ -129,7 +131,52 @@ public class AgentService extends CustomPaginationService<Agent> {
}
// Frequent questions
if (agent.getFrequentQuestion() == null) {
agent.setFrequentQuestion(new ArrayList<>());
}
if (agentBD.getFrequentQuestions() != null) {
for (FrequentQuestion frequentQuestionBD : agentBD.getFrequentQuestions()) {
boolean found = false;
for (FrequentQuestionBean frequentQuestionBean : agent.getFrequentQuestion()) {
if (frequentQuestionBean.getId() != null && frequentQuestionBD.getId().compareTo(frequentQuestionBean.getId()) == 0) {
found = true;
break;
}
}
if (!found) {
frequentQuestionRepository.delete(frequentQuestionBD);
}
}
}
for (FrequentQuestionBean frequentQuestionBean : agent.getFrequentQuestion()) {
FrequentQuestion frequentQuestionBD = null;
if (frequentQuestionBean.getId() != null) {
Optional<FrequentQuestion> frequentQuestionFound = frequentQuestionRepository.findById(frequentQuestionBean.getId());
if (frequentQuestionFound.isPresent()) {
frequentQuestionBD = frequentQuestionFound.get();
}
}
if (frequentQuestionBD == null) {
frequentQuestionBD = new FrequentQuestion();
frequentQuestionBD.setStatus(FrequentQuestionStatusEnum.ACTIVE);
frequentQuestionBD.setUploadDate(LocalDateTime.now());
} else {
frequentQuestionBD.setAgent(agentBD);
frequentQuestionBD.setFilename(frequentQuestionBean.getFilename());
frequentQuestionBD.setStatus(FrequentQuestionStatusEnum.fromString(frequentQuestionBean.getStatus()));
frequentQuestionBD.setUser(frequentQuestionBean.getUser());
}
frequentQuestionRepository.save(frequentQuestionBD);
}
// Deployment channels
if (agent.getDeploymentChannels() == null) {
......@@ -183,6 +230,8 @@ public class AgentService extends CustomPaginationService<Agent> {
deploymentChannelBD.setChannel(null);
}
deploymentChannelRepository.save(deploymentChannelBD);
// Deployment Channel parameters
if (deploymentChannelBean.getParameters() == null) {
......@@ -226,8 +275,8 @@ public class AgentService extends CustomPaginationService<Agent> {
deploymentChannelParamValue.setDeploymentChannel(deploymentChannelBD);
deploymentChannelParamValue.setValue(deploymentChannelParamValueBean.getValue());
if (deploymentChannelParamValueBean.getChannelParamId() != null) {
Optional<ChannelParam> channelParamFound = channelParamRepository.findById(deploymentChannelParamValueBean.getChannelParamId());
if (deploymentChannelParamValueBean.getChannelParamName() != null) {
Optional<ChannelParam> channelParamFound = channelParamRepository.findByName(deploymentChannelParamValueBean.getChannelParamName());
if (channelParamFound.isPresent()) {
deploymentChannelParamValue.setParameter(channelParamFound.get());
......@@ -235,6 +284,8 @@ public class AgentService extends CustomPaginationService<Agent> {
}
deploymentChannelParamValue.setParameter(null);
deploymentChannelParamValueRepository.save(deploymentChannelParamValue);
}
}
......@@ -256,7 +307,7 @@ public class AgentService extends CustomPaginationService<Agent> {
bean.setName(agent.getName());
bean.setDescription(agent.getDescription());
bean.setVersion(agent.getVersion());
bean.setLanguage(agent.getLanguage());
bean.setLanguage(agent.getLanguage().getName());
bean.setTimezone(agent.getTimezone());
bean.setType(agent.getType().getName());
bean.setStatus(agent.getStatus().getName());
......@@ -291,7 +342,7 @@ public class AgentService extends CustomPaginationService<Agent> {
parameterBean.setValue(parameter.getValue());
if (parameter.getParameter() != null) {
parameterBean.setChannelParamId(parameter.getParameter().getId());
parameterBean.setChannelParamName(parameter.getParameter().getName());
}
deploymentChannelBean.getParameters().add(parameterBean);
......@@ -313,7 +364,7 @@ public class AgentService extends CustomPaginationService<Agent> {
if (agentFound.isPresent()) {
Agent agent = agentFound.get();
agent.setStatus(StatusEnum.DELETED);
agent.setStatus(AgentStatusEnum.DELETED);
agentRepository.save(agent);
}
......@@ -322,4 +373,27 @@ public class AgentService extends CustomPaginationService<Agent> {
return isValid;
}
@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
public List<CountryBean> getCountries() {
List<CountryBean> countriesBean = new ArrayList<>();
List<Country> countries = (List<Country>) countryRepository.findAll();
for (Country country : countries) {
countriesBean.add(CountryBean.clone(country));
}
return countriesBean;
}
@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
public List<ChannelBean> getChannels() {
List<ChannelBean> channelsBean = new ArrayList<>();
List<Channel> channels = (List<Channel>) channelRepository.findAll();
for (Channel channel : channels) {
channelsBean.add(ChannelBean.clone(channel));
}
return channelsBean;
}
}
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