Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
ejercicio2-framework-back
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Josue
ejercicio2-framework-back
Commits
f65e07bb
Commit
f65e07bb
authored
Sep 15, 2020
by
Sebastian Chicoma
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cambios y correcciones para:
Sincronización de archivos de preguntas frecuentes Gestion de agentes
parent
0631a1b3
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
438 additions
and
301 deletions
+438
-301
pom.xml
pom.xml
+285
-281
FrequentQuestionBean.java
...in/java/com/bytesw/bytebot/bean/FrequentQuestionBean.java
+3
-0
CamelConfig.java
src/main/java/com/bytesw/bytebot/config/CamelConfig.java
+25
-0
AgentController.java
...n/java/com/bytesw/bytebot/controller/AgentController.java
+19
-4
FrequentQuestion.java
src/main/java/com/bytesw/bytebot/model/FrequentQuestion.java
+2
-2
FrequentQuestionRepository.java
...bytesw/bytebot/repository/FrequentQuestionRepository.java
+5
-0
QuestionFileRepository.java
...com/bytesw/bytebot/repository/QuestionFileRepository.java
+4
-0
SFTPRoute.java
src/main/java/com/bytesw/bytebot/routes/SFTPRoute.java
+28
-0
AgentService.java
src/main/java/com/bytesw/bytebot/service/AgentService.java
+49
-3
application.yml
src/main/resources/application.yml
+18
-11
No files found.
pom.xml
View file @
f65e07bb
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
<properties>
<properties>
<xdf.version>
3.1.0
</xdf.version>
<xdf.version>
3.1.0
</xdf.version>
<camel.version>
2.22.0
</camel.version>
<docker.image.prefix>
bytesw
</docker.image.prefix>
<docker.image.prefix>
bytesw
</docker.image.prefix>
<docker.image.name>
bytebot-service
</docker.image.name>
<docker.image.name>
bytebot-service
</docker.image.name>
...
@@ -126,9 +127,12 @@
...
@@ -126,9 +127,12 @@
<artifactId>
mysql-connector-java
</artifactId>
<artifactId>
mysql-connector-java
</artifactId>
</dependency>
</dependency>
<!-- camel -->
<dependency>
<groupId>
org.apache.camel
</groupId>
<artifactId>
camel-ftp
</artifactId>
<version>
${camel.version}
</version>
</dependency>
<!-- test -->
<!-- test -->
<dependency>
<dependency>
...
...
src/main/java/com/bytesw/bytebot/bean/FrequentQuestionBean.java
View file @
f65e07bb
...
@@ -25,6 +25,9 @@ public class FrequentQuestionBean {
...
@@ -25,6 +25,9 @@ public class FrequentQuestionBean {
@Expose
@Expose
private
Long
id
;
private
Long
id
;
@Expose
private
String
uuid
;
@Expose
@Expose
private
String
filename
;
private
String
filename
;
...
...
src/main/java/com/bytesw/bytebot/config/CamelConfig.java
0 → 100644
View file @
f65e07bb
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
);
}
}
src/main/java/com/bytesw/bytebot/controller/AgentController.java
View file @
f65e07bb
...
@@ -11,7 +11,9 @@ import com.bytesw.xdf.sql.beans.Pagination;
...
@@ -11,7 +11,9 @@ import com.bytesw.xdf.sql.beans.Pagination;
import
com.google.gson.Gson
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
com.google.gson.GsonBuilder
;
import
io.swagger.annotations.ApiParam
;
import
io.swagger.annotations.ApiParam
;
import
java.util.UUID
;
import
java.util.UUID
;
import
lombok.extern.log4j.Log4j2
;
import
lombok.extern.log4j.Log4j2
;
import
org.apache.commons.lang.exception.ExceptionUtils
;
import
org.apache.commons.lang.exception.ExceptionUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -174,4 +176,17 @@ public class AgentController {
...
@@ -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
);
}
}
}
}
src/main/java/com/bytesw/bytebot/model/FrequentQuestion.java
View file @
f65e07bb
...
@@ -38,8 +38,8 @@ public class FrequentQuestion {
...
@@ -38,8 +38,8 @@ public class FrequentQuestion {
pkColumnValue
=
"BBOT_FREQUENT_QUESTION_SEQ"
)
pkColumnValue
=
"BBOT_FREQUENT_QUESTION_SEQ"
)
private
Long
id
;
private
Long
id
;
//@Column(name = "FQUE_PATH
")
@Column
(
name
=
"FQUE_UUID
"
)
//private String filePath
;
private
String
uuid
;
@Column
(
name
=
"FQUE_NAME"
)
@Column
(
name
=
"FQUE_NAME"
)
private
String
filename
;
private
String
filename
;
...
...
src/main/java/com/bytesw/bytebot/repository/FrequentQuestionRepository.java
View file @
f65e07bb
...
@@ -2,8 +2,11 @@ package com.bytesw.bytebot.repository;
...
@@ -2,8 +2,11 @@ package com.bytesw.bytebot.repository;
import
com.bytesw.bytebot.model.DeploymentChannel
;
import
com.bytesw.bytebot.model.DeploymentChannel
;
import
com.bytesw.bytebot.model.FrequentQuestion
;
import
com.bytesw.bytebot.model.FrequentQuestion
;
import
com.bytesw.bytebot.model.enums.FrequentQuestionStatusEnum
;
import
org.springframework.data.repository.CrudRepository
;
import
org.springframework.data.repository.CrudRepository
;
import
java.util.List
;
/**
/**
* @author Sebastián Chicoma Sandmann.
* @author Sebastián Chicoma Sandmann.
* @version 9-sep-2020
* @version 9-sep-2020
...
@@ -16,4 +19,6 @@ import org.springframework.data.repository.CrudRepository;
...
@@ -16,4 +19,6 @@ import org.springframework.data.repository.CrudRepository;
* licencia de uso que firmó con Byte.
* licencia de uso que firmó con Byte.
*/
*/
public
interface
FrequentQuestionRepository
extends
CrudRepository
<
FrequentQuestion
,
Long
>
{
public
interface
FrequentQuestionRepository
extends
CrudRepository
<
FrequentQuestion
,
Long
>
{
public
List
<
FrequentQuestion
>
findAllByAgentIdAndStatus
(
Long
id
,
FrequentQuestionStatusEnum
status
);
}
}
src/main/java/com/bytesw/bytebot/repository/QuestionFileRepository.java
View file @
f65e07bb
...
@@ -8,6 +8,8 @@ package com.bytesw.bytebot.repository;
...
@@ -8,6 +8,8 @@ package com.bytesw.bytebot.repository;
import
com.bytesw.bytebot.model.QuestionFile
;
import
com.bytesw.bytebot.model.QuestionFile
;
import
org.springframework.data.repository.CrudRepository
;
import
org.springframework.data.repository.CrudRepository
;
import
java.util.Optional
;
/**
/**
* @author Hernán Uriarte Melchor.
* @author Hernán Uriarte Melchor.
* @version 13-sep-2020
* @version 13-sep-2020
...
@@ -21,4 +23,6 @@ import org.springframework.data.repository.CrudRepository;
...
@@ -21,4 +23,6 @@ import org.springframework.data.repository.CrudRepository;
*/
*/
public
interface
QuestionFileRepository
extends
CrudRepository
<
QuestionFile
,
Long
>
{
public
interface
QuestionFileRepository
extends
CrudRepository
<
QuestionFile
,
Long
>
{
public
Optional
<
QuestionFile
>
findByUuid
(
String
uuid
);
}
}
src/main/java/com/bytesw/bytebot/routes/SFTPRoute.java
0 → 100644
View file @
f65e07bb
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} "
);
}
}
src/main/java/com/bytesw/bytebot/service/AgentService.java
View file @
f65e07bb
...
@@ -6,6 +6,8 @@ import com.bytesw.bytebot.model.enums.*;
...
@@ -6,6 +6,8 @@ import com.bytesw.bytebot.model.enums.*;
import
com.bytesw.bytebot.repository.*
;
import
com.bytesw.bytebot.repository.*
;
import
com.bytesw.xdf.sql.beans.Pagination
;
import
com.bytesw.xdf.sql.beans.Pagination
;
import
lombok.extern.log4j.Log4j2
;
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.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.domain.PageRequest
;
...
@@ -16,11 +18,11 @@ import org.springframework.stereotype.Service;
...
@@ -16,11 +18,11 @@ 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.io.File
;
import
java.io.IOException
;
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.*
;
import
java.util.List
;
import
java.util.Optional
;
@Service
@Service
@Log4j2
@Log4j2
...
@@ -47,6 +49,12 @@ public class AgentService extends CustomPaginationService<Agent> {
...
@@ -47,6 +49,12 @@ public class AgentService extends CustomPaginationService<Agent> {
@Autowired
@Autowired
private
FrequentQuestionRepository
frequentQuestionRepository
;
private
FrequentQuestionRepository
frequentQuestionRepository
;
@Autowired
private
QuestionFileRepository
questionFileRepository
;
@Autowired
private
ProducerTemplate
producerTemplate
;
@Transactional
(
transactionManager
=
"bytebotTransactionManager"
,
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
)
{
...
@@ -170,6 +178,7 @@ public class AgentService extends CustomPaginationService<Agent> {
...
@@ -170,6 +178,7 @@ public class AgentService extends CustomPaginationService<Agent> {
frequentQuestionBD
=
new
FrequentQuestion
();
frequentQuestionBD
=
new
FrequentQuestion
();
frequentQuestionBD
.
setStatus
(
FrequentQuestionStatusEnum
.
PENDING_SYNCHRONIZED
);
frequentQuestionBD
.
setStatus
(
FrequentQuestionStatusEnum
.
PENDING_SYNCHRONIZED
);
frequentQuestionBD
.
setUploadDate
(
LocalDateTime
.
now
());
frequentQuestionBD
.
setUploadDate
(
LocalDateTime
.
now
());
frequentQuestionBD
.
setUuid
(
frequentQuestionBean
.
getUuid
());
}
}
frequentQuestionBD
.
setAgent
(
agentBD
);
frequentQuestionBD
.
setAgent
(
agentBD
);
...
@@ -420,4 +429,41 @@ public class AgentService extends CustomPaginationService<Agent> {
...
@@ -420,4 +429,41 @@ public class AgentService extends CustomPaginationService<Agent> {
return
channelsBean
;
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
);
}
}
}
}
src/main/resources/application.yml
View file @
f65e07bb
spring.autoconfigure.exclude
:
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration, org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration, org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration
spring.autoconfigure.exclude
:
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration, org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration, org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration
server
:
server
:
servlet.context-path
:
${APPLICATION_PATH:/
bytebot
}
servlet.context-path
:
${APPLICATION_PATH:/}
port
:
${APPLICATION_PORT:9077}
port
:
${APPLICATION_PORT:9077}
web
:
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 /
#NOTA debe terminar con /
security
:
security
:
...
@@ -32,7 +32,7 @@ application:
...
@@ -32,7 +32,7 @@ application:
hosts
:
38F9D38DD09
hosts
:
38F9D38DD09
type
:
web
# web o service
type
:
web
# web o service
security
:
security
:
enabled
:
tru
e
enabled
:
fals
e
encryption-key
:
ENC(0WRfEFi8lYjlJj2bj37z4TRu4zmPnmXl4zM4Jpdh1H8=)*
encryption-key
:
ENC(0WRfEFi8lYjlJj2bj37z4TRu4zmPnmXl4zM4Jpdh1H8=)*
web
:
web
:
server
:
docker
# weblogic, docker
server
:
docker
# weblogic, docker
...
@@ -64,6 +64,12 @@ application:
...
@@ -64,6 +64,12 @@ application:
messaging
:
messaging
:
queue-test
:
action_queue.fifo
queue-test
:
action_queue.fifo
topic-test
:
topic-test
topic-test
:
topic-test
bytebot-integration
:
ftp
:
host
:
192.168.27.36
username
:
testuser
password
:
byte2k20
directory
:
uploadFS/IMG/
# email.info:
# email.info:
# smtp:
# smtp:
# host: smtp.gmail.com
# host: smtp.gmail.com
...
@@ -89,31 +95,32 @@ spring:
...
@@ -89,31 +95,32 @@ spring:
name
:
xdf-example
name
:
xdf-example
datasource
:
datasource
:
database-type
:
mysql
database-type
:
mysql
schemaName
:
BYTE
SGA
schemaName
:
BYTE
BOT
url
:
jdbc:mysql://localhost:
43306/BYTESGA
?useSSL=false
url
:
jdbc:mysql://localhost:
3306/BYTEBOT
?useSSL=false
driverClassName
:
'
com.mysql.cj.jdbc.Driver'
driverClassName
:
'
com.mysql.cj.jdbc.Driver'
username
:
root
username
:
root
password
:
secre
t
password
:
roo
t
minimum-idle
:
10
minimum-idle
:
10
maximum-pool-size
:
10
maximum-pool-size
:
10
validationQuery
:
SELECT 1
validationQuery
:
SELECT 1
testWhileIdle
:
true
testWhileIdle
:
true
hikari.registerMbeans
:
true
hikari.registerMbeans
:
true
security
:
security
:
basepath
:
http://
localhost:9077/piloto-xdf
basepath
:
http://
127.0.0.1:9077/
provider
:
byte
# oracle, amazon
provider
:
byte
# oracle, amazon
oauth2-client
:
oauth2-client
:
clientId
:
xdf-client
clientId
:
xdf-client
clientSecret
:
xdf-secret
clientSecret
:
xdf-secret
accessTokenUri
:
http://
192.168.1.100:8080
/oauth/token
accessTokenUri
:
http://
localhost:1102
/oauth/token
userAuthorizationUri
:
http://
192.168.1.100:8080
/oauth/authorize
userAuthorizationUri
:
http://
localhost:1102
/oauth/authorize
oauth2-resource
:
oauth2-resource
:
userInfoUri
:
http://
192.168.1.100:8080
/oauth/userinfo
userInfoUri
:
http://
localhost:1102
/oauth/userinfo
logoutUri
:
http://
192.168.1.100:8080
/oauth/userlogout
logoutUri
:
http://
localhost:1102
/oauth/userlogout
jpa
:
jpa
:
open-in-view
:
false
open-in-view
:
false
properties.hibernate
:
properties.hibernate
:
dialect
:
org.hibernate.dialect.MySQL5Dialect
dialect
:
org.hibernate.dialect.MySQL5Dialect
#dialect: org.hibernate.dialect.Oracle12cDialect
format_sql
:
false
format_sql
:
false
hbm2ddl.auto
:
none
hbm2ddl.auto
:
none
show-sql
:
true
show-sql
:
true
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment