Commit f65e07bb authored by Sebastian Chicoma's avatar Sebastian Chicoma

Cambios y correcciones para:

Sincronización de archivos de preguntas frecuentes
Gestion de agentes
parent 0631a1b3
This diff is collapsed.
......@@ -25,6 +25,9 @@ public class FrequentQuestionBean {
@Expose
private Long id;
@Expose
private String uuid;
@Expose
private String filename;
......
package com.bytesw.bytebot.config;
import com.bytesw.bytebot.routes.SFTPRoute;
import lombok.extern.log4j.Log4j2;
import org.apache.camel.CamelContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
@Configuration
@Log4j2
public class CamelConfig {
@Autowired
private CamelContext camelContext;
@Autowired
private SFTPRoute sftpRoute;
@PostConstruct
public void addBuilder() throws Exception {
camelContext.addRoutes(sftpRoute);
}
}
......@@ -11,7 +11,9 @@ import com.bytesw.xdf.sql.beans.Pagination;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.swagger.annotations.ApiParam;
import java.util.UUID;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -29,7 +31,7 @@ public class AgentController {
@Autowired
private AgentService agentService;
@Autowired
private FileManagementService fileManagementService;
......@@ -160,13 +162,13 @@ public class AgentController {
return new ResponseEntity<>(gsonBuilder.create().toJson(ExceptionUtils.getFullStackTrace(e)), hs);
}
}
@PostMapping("/file-upload")
public ResponseEntity<String> uploadFile(@RequestParam("file") MultipartFile file) {
Gson gson = new GsonBuilder().create();
try {
String uuid = UUID.randomUUID().toString();
FileValidationResponse response = fileManagementService.validateAndSaveFile(uuid, file);
String uuid = UUID.randomUUID().toString();
FileValidationResponse response = fileManagementService.validateAndSaveFile(uuid, file);
return new ResponseEntity<>(gson.toJson(response), HttpStatus.OK);
} catch (Exception e) {
e.printStackTrace();
......@@ -174,4 +176,17 @@ public class AgentController {
}
}
@GetMapping("/synchronize/{id}")
public ResponseEntity<String> synchronizeFiles(@PathVariable("id") Long id,
@RequestParam("user") String user) {
Gson gson = new GsonBuilder().create();
try {
agentService.synchronizeFiles(id, user);
return new ResponseEntity<>(HttpStatus.OK);
} catch (Exception e) {
e.printStackTrace();
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
......@@ -38,8 +38,8 @@ public class FrequentQuestion {
pkColumnValue = "BBOT_FREQUENT_QUESTION_SEQ")
private Long id;
//@Column(name = "FQUE_PATH")
//private String filePath;
@Column(name = "FQUE_UUID")
private String uuid;
@Column(name = "FQUE_NAME")
private String filename;
......
......@@ -2,8 +2,11 @@ package com.bytesw.bytebot.repository;
import com.bytesw.bytebot.model.DeploymentChannel;
import com.bytesw.bytebot.model.FrequentQuestion;
import com.bytesw.bytebot.model.enums.FrequentQuestionStatusEnum;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
/**
* @author Sebastián Chicoma Sandmann.
* @version 9-sep-2020
......@@ -16,4 +19,6 @@ import org.springframework.data.repository.CrudRepository;
* licencia de uso que firmó con Byte.
*/
public interface FrequentQuestionRepository extends CrudRepository<FrequentQuestion, Long> {
public List<FrequentQuestion> findAllByAgentIdAndStatus(Long id, FrequentQuestionStatusEnum status);
}
......@@ -8,6 +8,8 @@ package com.bytesw.bytebot.repository;
import com.bytesw.bytebot.model.QuestionFile;
import org.springframework.data.repository.CrudRepository;
import java.util.Optional;
/**
* @author Hernán Uriarte Melchor.
* @version 13-sep-2020
......@@ -20,5 +22,7 @@ import org.springframework.data.repository.CrudRepository;
* licencia de uso que firmó con Byte.
*/
public interface QuestionFileRepository extends CrudRepository<QuestionFile, Long> {
public Optional<QuestionFile> findByUuid(String uuid);
}
package com.bytesw.bytebot.routes;
import org.apache.camel.builder.RouteBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
public class SFTPRoute extends RouteBuilder {
@Value("${application.bytebot-integration.ftp.username}")
private String username;
@Value("${application.bytebot-integration.ftp.password}")
private String password;
@Value("${application.bytebot-integration.ftp.directory:}")
private String directory;
@Value("${application.bytebot-integration.ftp.host}")
private String host;
@Override
public void configure() throws Exception {
from("direct:transferFile")
.toF("ftp://%s@%s/%s?password=%s&binary=true", username, host, directory, password)
.log("Transfered file .${file:name} ");
}
}
......@@ -6,6 +6,8 @@ import com.bytesw.bytebot.model.enums.*;
import com.bytesw.bytebot.repository.*;
import com.bytesw.xdf.sql.beans.Pagination;
import lombok.extern.log4j.Log4j2;
import org.apache.camel.ProducerTemplate;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
......@@ -16,11 +18,11 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.*;
@Service
@Log4j2
......@@ -47,6 +49,12 @@ public class AgentService extends CustomPaginationService<Agent> {
@Autowired
private FrequentQuestionRepository frequentQuestionRepository;
@Autowired
private QuestionFileRepository questionFileRepository;
@Autowired
private ProducerTemplate producerTemplate;
@Transactional(transactionManager = "bytebotTransactionManager", readOnly = true, propagation = Propagation.NOT_SUPPORTED)
public void searchByPagination(Pagination<AgentBean> pagination) {
if (pagination.getItemsPerPage() == 0) {
......@@ -170,6 +178,7 @@ public class AgentService extends CustomPaginationService<Agent> {
frequentQuestionBD = new FrequentQuestion();
frequentQuestionBD.setStatus(FrequentQuestionStatusEnum.PENDING_SYNCHRONIZED);
frequentQuestionBD.setUploadDate(LocalDateTime.now());
frequentQuestionBD.setUuid(frequentQuestionBean.getUuid());
}
frequentQuestionBD.setAgent(agentBD);
......@@ -420,4 +429,41 @@ public class AgentService extends CustomPaginationService<Agent> {
return channelsBean;
}
@Transactional(transactionManager = "bytebotTransactionManager", propagation = Propagation.REQUIRED)
public void synchronizeFiles(Long id, String user) {
List<FrequentQuestion> frequentQuestions = frequentQuestionRepository.findAllByAgentIdAndStatus(id, FrequentQuestionStatusEnum.PENDING_SYNCHRONIZED);
Map<String, Object> headers = new HashMap<>();
for (FrequentQuestion frequentQuestion : frequentQuestions) {
Optional<QuestionFile> questionFileFound = questionFileRepository.findByUuid(frequentQuestion.getUuid());
if (questionFileFound.isPresent()) {
headers.put("CamelFileName", questionFileFound.get().getName());
// try {
// FileUtils.writeByteArrayToFile(new File("/home/schicoma/Escritorio/" + questionFileFound.get().getName()), questionFileFound.get().getData());
// } catch (IOException e) {
// e.printStackTrace();
// }
producerTemplate.sendBodyAndHeaders("direct:transferFile", questionFileFound.get().getData(), headers);
}
frequentQuestion.setStatus(FrequentQuestionStatusEnum.UPLOADED);
frequentQuestion.setUser(user);
frequentQuestion.setUploadDate(LocalDateTime.now());
frequentQuestionRepository.save(frequentQuestion);
}
Optional<Agent> agentFound = agentRepository.findById(id);
if (agentFound.isPresent()) {
Agent agent = agentFound.get();
agent.setStatus(AgentStatusEnum.DEPLOYED);
agentRepository.save(agent);
}
}
}
spring.autoconfigure.exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration, org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration, org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration
server:
servlet.context-path: ${APPLICATION_PATH:/bytebot}
servlet.context-path: ${APPLICATION_PATH:/}
port: ${APPLICATION_PORT:9077}
web:
static-content-location: file:e:/proyects/BYTE_BOT/bytebot-projects/dist/bytebot-html/
static-content-location: file:/home/schicoma/Documentos/Proyectos/git/BYTEBOT/bytebot-workspace/dist/bytebot-html/
#NOTA debe terminar con /
security:
......@@ -32,7 +32,7 @@ application:
hosts: 38F9D38DD09
type: web # web o service
security:
enabled: true
enabled: false
encryption-key: ENC(0WRfEFi8lYjlJj2bj37z4TRu4zmPnmXl4zM4Jpdh1H8=)*
web:
server: docker # weblogic, docker
......@@ -64,6 +64,12 @@ application:
messaging:
queue-test: action_queue.fifo
topic-test: topic-test
bytebot-integration:
ftp:
host: 192.168.27.36
username: testuser
password: byte2k20
directory: uploadFS/IMG/
# email.info:
# smtp:
# host: smtp.gmail.com
......@@ -89,31 +95,32 @@ spring:
name: xdf-example
datasource:
database-type: mysql
schemaName: BYTESGA
url: jdbc:mysql://localhost:43306/BYTESGA?useSSL=false
schemaName: BYTEBOT
url: jdbc:mysql://localhost:3306/BYTEBOT?useSSL=false
driverClassName: 'com.mysql.cj.jdbc.Driver'
username: root
password: secret
password: root
minimum-idle: 10
maximum-pool-size: 10
validationQuery: SELECT 1
testWhileIdle: true
hikari.registerMbeans: true
security:
basepath: http://localhost:9077/piloto-xdf
basepath: http://127.0.0.1:9077/
provider: byte # oracle, amazon
oauth2-client:
clientId: xdf-client
clientSecret: xdf-secret
accessTokenUri: http://192.168.1.100:8080/oauth/token
userAuthorizationUri: http://192.168.1.100:8080/oauth/authorize
accessTokenUri: http://localhost:1102/oauth/token
userAuthorizationUri: http://localhost:1102/oauth/authorize
oauth2-resource:
userInfoUri: http://192.168.1.100:8080/oauth/userinfo
logoutUri: http://192.168.1.100:8080/oauth/userlogout
userInfoUri: http://localhost:1102/oauth/userinfo
logoutUri: http://localhost:1102/oauth/userlogout
jpa:
open-in-view: false
properties.hibernate:
dialect: org.hibernate.dialect.MySQL5Dialect
#dialect: org.hibernate.dialect.Oracle12cDialect
format_sql: false
hbm2ddl.auto: none
show-sql: true
......
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