Commit cf6d3f18 authored by Sebastian Chicoma's avatar Sebastian Chicoma

Cambios y correcciones para lógica de negocio

parent b5f98f8b
...@@ -60,7 +60,7 @@ public class AgentBean { ...@@ -60,7 +60,7 @@ public class AgentBean {
private List<DeploymentChannelBean> deploymentChannels; private List<DeploymentChannelBean> deploymentChannels;
@Expose @Expose
private List<FrequentQuestionBean> frequentQuestion; private List<FrequentQuestionBean> frequentQuestions;
public static AgentBean miniClone(Agent agent) { public static AgentBean miniClone(Agent agent) {
AgentBean bean = new AgentBean(); AgentBean bean = new AgentBean();
......
...@@ -44,8 +44,8 @@ public class FrequentQuestion { ...@@ -44,8 +44,8 @@ public class FrequentQuestion {
@Column(name = "FQUE_NAME") @Column(name = "FQUE_NAME")
private String filename; private String filename;
//@Column(name = "FQUE_DESC") @Column(name = "FQUE_DESC")
//private String description; private String description;
@Column(name = "FQUE_STATE") @Column(name = "FQUE_STATE")
@Convert(converter = FrequentQuestionStatusConverter.class) @Convert(converter = FrequentQuestionStatusConverter.class)
......
...@@ -19,8 +19,8 @@ import java.util.Map; ...@@ -19,8 +19,8 @@ import java.util.Map;
@Getter @Getter
public enum FrequentQuestionStatusEnum { public enum FrequentQuestionStatusEnum {
ACTIVE("AC"), PENDING_SYNCHRONIZED("PS"),
UPLOADED("UP"), UPLOADED("LO"),
DELETED("DE"); DELETED("DE");
private static final Map<String, FrequentQuestionStatusEnum> map = new HashMap<>(); private static final Map<String, FrequentQuestionStatusEnum> map = new HashMap<>();
......
...@@ -19,6 +19,6 @@ import java.util.Optional; ...@@ -19,6 +19,6 @@ import java.util.Optional;
*/ */
public interface ChannelParamRepository extends CrudRepository<ChannelParam, Long> { public interface ChannelParamRepository extends CrudRepository<ChannelParam, Long> {
Optional<ChannelParam> findByName(String name); Optional<ChannelParam> findByNameAndChannelId(String name, Long id);
} }
...@@ -16,7 +16,6 @@ import org.springframework.stereotype.Service; ...@@ -16,7 +16,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -48,7 +47,7 @@ public class AgentService extends CustomPaginationService<Agent> { ...@@ -48,7 +47,7 @@ public class AgentService extends CustomPaginationService<Agent> {
@Autowired @Autowired
private FrequentQuestionRepository frequentQuestionRepository; private FrequentQuestionRepository frequentQuestionRepository;
@Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED) @Transactional(transactionManager = "bytebotTransactionManager", readOnly = true, propagation = Propagation.NOT_SUPPORTED)
public void searchByPagination(Pagination<AgentBean> pagination) { public void searchByPagination(Pagination<AgentBean> pagination) {
if (pagination.getItemsPerPage() == 0) { if (pagination.getItemsPerPage() == 0) {
pagination.setItemsPerPage(10); pagination.setItemsPerPage(10);
...@@ -88,7 +87,7 @@ public class AgentService extends CustomPaginationService<Agent> { ...@@ -88,7 +87,7 @@ public class AgentService extends CustomPaginationService<Agent> {
pagination.setData(list); pagination.setData(list);
} }
@Transactional(propagation = Propagation.REQUIRED) @Transactional(transactionManager = "bytebotTransactionManager", propagation = Propagation.REQUIRED)
public void save(AgentBean agent) { public void save(AgentBean agent) {
boolean isModify = true; boolean isModify = true;
...@@ -103,11 +102,13 @@ public class AgentService extends CustomPaginationService<Agent> { ...@@ -103,11 +102,13 @@ public class AgentService extends CustomPaginationService<Agent> {
} }
} }
if (agent == null) { if (agentBD == null) {
agentBD = new Agent(); agentBD = new Agent();
agentBD.setStatus(AgentStatusEnum.CREATED); agentBD.setStatus(AgentStatusEnum.CREATED);
isModify = false; isModify = false;
} else {
agentBD.setStatus(AgentStatusEnum.fromString(agent.getStatus()));
} }
// General Information // General Information
...@@ -130,16 +131,18 @@ public class AgentService extends CustomPaginationService<Agent> { ...@@ -130,16 +131,18 @@ public class AgentService extends CustomPaginationService<Agent> {
agentBD.setCountry(null); agentBD.setCountry(null);
} }
agentBD = agentRepository.save(agentBD);
// Frequent questions // Frequent questions
if (agent.getFrequentQuestion() == null) { if (agent.getFrequentQuestions() == null) {
agent.setFrequentQuestion(new ArrayList<>()); agent.setFrequentQuestions(new ArrayList<>());
} }
if (agentBD.getFrequentQuestions() != null) { if (agentBD.getFrequentQuestions() != null) {
for (FrequentQuestion frequentQuestionBD : agentBD.getFrequentQuestions()) { for (FrequentQuestion frequentQuestionBD : agentBD.getFrequentQuestions()) {
boolean found = false; boolean found = false;
for (FrequentQuestionBean frequentQuestionBean : agent.getFrequentQuestion()) { for (FrequentQuestionBean frequentQuestionBean : agent.getFrequentQuestions()) {
if (frequentQuestionBean.getId() != null && frequentQuestionBD.getId().compareTo(frequentQuestionBean.getId()) == 0) { if (frequentQuestionBean.getId() != null && frequentQuestionBD.getId().compareTo(frequentQuestionBean.getId()) == 0) {
found = true; found = true;
break; break;
...@@ -152,7 +155,7 @@ public class AgentService extends CustomPaginationService<Agent> { ...@@ -152,7 +155,7 @@ public class AgentService extends CustomPaginationService<Agent> {
} }
} }
for (FrequentQuestionBean frequentQuestionBean : agent.getFrequentQuestion()) { for (FrequentQuestionBean frequentQuestionBean : agent.getFrequentQuestions()) {
FrequentQuestion frequentQuestionBD = null; FrequentQuestion frequentQuestionBD = null;
if (frequentQuestionBean.getId() != null) { if (frequentQuestionBean.getId() != null) {
...@@ -165,15 +168,16 @@ public class AgentService extends CustomPaginationService<Agent> { ...@@ -165,15 +168,16 @@ public class AgentService extends CustomPaginationService<Agent> {
if (frequentQuestionBD == null) { if (frequentQuestionBD == null) {
frequentQuestionBD = new FrequentQuestion(); frequentQuestionBD = new FrequentQuestion();
frequentQuestionBD.setStatus(FrequentQuestionStatusEnum.ACTIVE); frequentQuestionBD.setStatus(FrequentQuestionStatusEnum.PENDING_SYNCHRONIZED);
frequentQuestionBD.setUploadDate(LocalDateTime.now()); frequentQuestionBD.setUploadDate(LocalDateTime.now());
} else {
frequentQuestionBD.setAgent(agentBD);
frequentQuestionBD.setFilename(frequentQuestionBean.getFilename());
frequentQuestionBD.setStatus(FrequentQuestionStatusEnum.fromString(frequentQuestionBean.getStatus()));
frequentQuestionBD.setUser(frequentQuestionBean.getUser());
} }
frequentQuestionBD.setAgent(agentBD);
frequentQuestionBD.setDescription(frequentQuestionBean.getDescription());
frequentQuestionBD.setFilename(frequentQuestionBean.getFilename());
frequentQuestionBD.setStatus(FrequentQuestionStatusEnum.fromString(frequentQuestionBean.getStatus()));
frequentQuestionBD.setUser(frequentQuestionBean.getUser());
frequentQuestionRepository.save(frequentQuestionBD); frequentQuestionRepository.save(frequentQuestionBD);
} }
...@@ -276,15 +280,16 @@ public class AgentService extends CustomPaginationService<Agent> { ...@@ -276,15 +280,16 @@ public class AgentService extends CustomPaginationService<Agent> {
deploymentChannelParamValue.setValue(deploymentChannelParamValueBean.getValue()); deploymentChannelParamValue.setValue(deploymentChannelParamValueBean.getValue());
if (deploymentChannelParamValueBean.getChannelParamName() != null) { if (deploymentChannelParamValueBean.getChannelParamName() != null) {
Optional<ChannelParam> channelParamFound = channelParamRepository.findByName(deploymentChannelParamValueBean.getChannelParamName()); Optional<ChannelParam> channelParamFound = channelParamRepository.findByNameAndChannelId(
deploymentChannelParamValueBean.getChannelParamName(), deploymentChannelBean.getChannelId());
if (channelParamFound.isPresent()) { if (channelParamFound.isPresent()) {
deploymentChannelParamValue.setParameter(channelParamFound.get()); deploymentChannelParamValue.setParameter(channelParamFound.get());
} }
} else {
deploymentChannelParamValue.setParameter(null);
} }
deploymentChannelParamValue.setParameter(null);
deploymentChannelParamValueRepository.save(deploymentChannelParamValue); deploymentChannelParamValueRepository.save(deploymentChannelParamValue);
} }
...@@ -292,8 +297,11 @@ public class AgentService extends CustomPaginationService<Agent> { ...@@ -292,8 +297,11 @@ public class AgentService extends CustomPaginationService<Agent> {
} }
@Transactional(propagation = Propagation.NOT_SUPPORTED) @Transactional(transactionManager = "bytebotTransactionManager", propagation = Propagation.NOT_SUPPORTED)
public AgentBean getAgent(Long id) { public AgentBean getAgent(Long id) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
AgentBean bean = null; AgentBean bean = null;
Optional<Agent> agentFound = agentRepository.findById(id); Optional<Agent> agentFound = agentRepository.findById(id);
...@@ -318,10 +326,26 @@ public class AgentService extends CustomPaginationService<Agent> { ...@@ -318,10 +326,26 @@ public class AgentService extends CustomPaginationService<Agent> {
bean.setCountryId(agent.getCountry().getId()); bean.setCountryId(agent.getCountry().getId());
} }
bean.setDeploymentChannels(new ArrayList<>()); // Deployment channel
bean.setFrequentQuestions(new ArrayList<>());
for (FrequentQuestion frequentQuestion : agent.getFrequentQuestions()) {
FrequentQuestionBean frequentQuestionBean = new FrequentQuestionBean();
frequentQuestionBean.setId(frequentQuestion.getId());
frequentQuestionBean.setDescription(frequentQuestion.getDescription());
frequentQuestionBean.setUser(frequentQuestion.getUser());
frequentQuestionBean.setFilename(frequentQuestion.getFilename());
frequentQuestionBean.setUploadDate(frequentQuestion.getUploadDate().format(formatter));
frequentQuestionBean.setStatus(frequentQuestion.getStatus().getName());
bean.getFrequentQuestions().add(frequentQuestionBean);
}
// Deployment channel // Deployment channel
bean.setDeploymentChannels(new ArrayList<>());
for (DeploymentChannel deploymentChannel : agent.getDeploymentChannels()) { for (DeploymentChannel deploymentChannel : agent.getDeploymentChannels()) {
DeploymentChannelBean deploymentChannelBean = new DeploymentChannelBean(); DeploymentChannelBean deploymentChannelBean = new DeploymentChannelBean();
deploymentChannelBean.setId(deploymentChannel.getId()); deploymentChannelBean.setId(deploymentChannel.getId());
...@@ -355,7 +379,7 @@ public class AgentService extends CustomPaginationService<Agent> { ...@@ -355,7 +379,7 @@ public class AgentService extends CustomPaginationService<Agent> {
return bean; return bean;
} }
@Transactional(propagation = Propagation.REQUIRED) @Transactional(transactionManager = "bytebotTransactionManager", propagation = Propagation.REQUIRED)
public boolean delete(Long id) { public boolean delete(Long id) {
boolean isValid = true; boolean isValid = true;
...@@ -385,7 +409,7 @@ public class AgentService extends CustomPaginationService<Agent> { ...@@ -385,7 +409,7 @@ public class AgentService extends CustomPaginationService<Agent> {
return countriesBean; return countriesBean;
} }
@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true) @Transactional(transactionManager = "bytebotTransactionManager", propagation = Propagation.NOT_SUPPORTED, readOnly = true)
public List<ChannelBean> getChannels() { public List<ChannelBean> getChannels() {
List<ChannelBean> channelsBean = new ArrayList<>(); List<ChannelBean> channelsBean = new ArrayList<>();
List<Channel> channels = (List<Channel>) channelRepository.findAll(); List<Channel> channels = (List<Channel>) channelRepository.findAll();
......
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