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