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
d136e061
Commit
d136e061
authored
Dec 23, 2021
by
Roberto Loayza Miljanovich
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev_marcos' into 'developer'
Dev marcos See merge request ByteBot/web/bytebot-service!20
parents
7535be84
b99dc87c
Changes
20
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
505 additions
and
63 deletions
+505
-63
pom.xml
pom.xml
+8
-0
BdcControlBean.java
src/main/java/com/bytesw/bytebot/bean/BdcControlBean.java
+6
-2
AgentController.java
...n/java/com/bytesw/bytebot/controller/AgentController.java
+31
-3
BdcControlController.java
...a/com/bytesw/bytebot/controller/BdcControlController.java
+3
-3
BusinessParameterController.java
...ytesw/bytebot/controller/BusinessParameterController.java
+1
-1
SchedulerTaskController.java
...om/bytesw/bytebot/controller/SchedulerTaskController.java
+2
-2
FileValidationResponse.java
.../java/com/bytesw/bytebot/http/FileValidationResponse.java
+0
-2
ValidationStatusEnum.java
...a/com/bytesw/bytebot/http/enums/ValidationStatusEnum.java
+1
-0
BdcControl.java
src/main/java/com/bytesw/bytebot/model/BdcControl.java
+16
-4
FrequentQuestionStatusEnum.java
...ytesw/bytebot/model/enums/FrequentQuestionStatusEnum.java
+3
-1
StatusBcdEnum.java
...in/java/com/bytesw/bytebot/model/enums/StatusBcdEnum.java
+4
-4
BcdControlRepository.java
...a/com/bytesw/bytebot/repository/BcdControlRepository.java
+0
-8
BdcControlRepository.java
...a/com/bytesw/bytebot/repository/BdcControlRepository.java
+14
-0
AgentService.java
src/main/java/com/bytesw/bytebot/service/AgentService.java
+5
-1
BcdControlService.java
...in/java/com/bytesw/bytebot/service/BcdControlService.java
+9
-10
BucketService.java
src/main/java/com/bytesw/bytebot/service/BucketService.java
+122
-0
FileManagementService.java
...ava/com/bytesw/bytebot/service/FileManagementService.java
+16
-6
KnowledgeService.java
...ain/java/com/bytesw/bytebot/service/KnowledgeService.java
+91
-0
OrquestadorService.java
...n/java/com/bytesw/bytebot/service/OrquestadorService.java
+149
-0
application.yml
src/main/resources/application.yml
+24
-16
No files found.
pom.xml
View file @
d136e061
...
...
@@ -246,6 +246,14 @@
<artifactId>
twilio
</artifactId>
<version>
8.22.0
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk -->
<dependency>
<groupId>
com.amazonaws
</groupId>
<artifactId>
aws-java-sdk
</artifactId>
<version>
1.12.129
</version>
</dependency>
</dependencies>
<build>
...
...
src/main/java/com/bytesw/bytebot/bean/B
cd
ControlBean.java
→
src/main/java/com/bytesw/bytebot/bean/B
dc
ControlBean.java
View file @
d136e061
...
...
@@ -7,8 +7,12 @@ import lombok.Setter;
import
java.io.Serializable
;
@Getter
@Setter
public
class
B
cd
ControlBean
implements
Serializable
{
public
class
B
dc
ControlBean
implements
Serializable
{
@Expose
private
Long
id
;
@Expose
private
Long
agentId
;
@Expose
private
String
uuid
;
@Expose
private
String
fileName
;
@Expose
private
String
status
;
@Expose
private
String
user
;
@Expose
private
String
date
;
@Expose
private
Long
fileId
;
}
src/main/java/com/bytesw/bytebot/controller/AgentController.java
View file @
d136e061
...
...
@@ -3,8 +3,7 @@ package com.bytesw.bytebot.controller;
import
com.bytesw.bytebot.bean.AgentBean
;
import
com.bytesw.bytebot.controller.bean.ResponseController
;
import
com.bytesw.bytebot.http.FileValidationResponse
;
import
com.bytesw.bytebot.service.AgentService
;
import
com.bytesw.bytebot.service.FileManagementService
;
import
com.bytesw.bytebot.service.*
;
import
com.bytesw.xdf.annotation.ProgramSecurity
;
import
com.bytesw.xdf.sql.beans.Pagination
;
import
com.google.gson.Gson
;
...
...
@@ -38,6 +37,9 @@ public class AgentController {
@Autowired
private
GsonBuilder
gsonBuilder
;
@Autowired
private
OrquestadorService
orquestadorService
;
@PostMapping
(
value
=
"/page"
)
@PreAuthorize
(
"hasPermission(this, 'view')"
)
public
ResponseEntity
<
String
>
paginationConversationalAgent
(
@RequestBody
Pagination
<
AgentBean
>
pagination
)
{
...
...
@@ -168,7 +170,7 @@ public class AgentController {
Gson
gson
=
gsonBuilder
.
create
();
try
{
String
uuid
=
UUID
.
randomUUID
().
toString
();
FileValidationResponse
response
=
fileManagementService
.
validateAndSaveFile
(
uuid
,
file
);
FileValidationResponse
response
=
orquestadorService
.
executeGenerateBCD
(
uuid
,
file
);
response
.
setUser
(
principal
!=
null
?
principal
.
getName
()
:
null
);
return
new
ResponseEntity
<>(
gson
.
toJson
(
response
),
HttpStatus
.
OK
);
}
catch
(
Exception
e
)
{
...
...
@@ -177,6 +179,32 @@ public class AgentController {
}
}
@PutMapping
(
"/file-upload/{uuid}"
)
public
ResponseEntity
<
String
>
uploadFile
(
@PathVariable
(
"uuid"
)
String
uuid
,
Principal
principal
)
{
Gson
gson
=
gsonBuilder
.
create
();
try
{
FileValidationResponse
response
=
orquestadorService
.
retry
(
uuid
);
response
.
setUser
(
principal
!=
null
?
principal
.
getName
()
:
null
);
return
new
ResponseEntity
<>(
gson
.
toJson
(
response
),
HttpStatus
.
OK
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
new
ResponseEntity
<>(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
}
}
@DeleteMapping
(
"/file-upload/{uuid}"
)
public
ResponseEntity
<
String
>
deleteBdc
(
@ApiParam
(
value
=
"uuid"
,
required
=
true
)
@PathVariable
(
"uuid"
)
String
uuid
)
{
Gson
gson
=
gsonBuilder
.
create
();
try
{
orquestadorService
.
deleteBcd
(
uuid
);
String
response
=
"Todo Ok"
;
return
new
ResponseEntity
<>(
gson
.
toJson
(
response
),
HttpStatus
.
OK
);
}
catch
(
Exception
e
)
{
log
.
error
(
"Error detectado: "
,
e
);
return
new
ResponseEntity
<>(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
}
}
@GetMapping
(
"/synchronize/{id}"
)
public
ResponseEntity
<
String
>
synchronizeFiles
(
@PathVariable
(
"id"
)
Long
id
,
@RequestParam
(
"user"
)
String
user
)
{
...
...
src/main/java/com/bytesw/bytebot/controller/B
cd
ControlController.java
→
src/main/java/com/bytesw/bytebot/controller/B
dc
ControlController.java
View file @
d136e061
package
com
.
bytesw
.
bytebot
.
controller
;
import
com.bytesw.bytebot.bean.B
cd
ControlBean
;
import
com.bytesw.bytebot.bean.B
dc
ControlBean
;
import
com.bytesw.bytebot.service.BcdControlService
;
import
com.bytesw.xdf.annotation.ProgramSecurity
;
import
com.bytesw.xdf.controller.XDFController
;
...
...
@@ -12,8 +12,8 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping
(
"/service/settings/bcdControl"
)
@ProgramSecurity
(
"BCDCONTROL"
)
@Log4j2
public
class
B
cdControlController
extends
XDFController
<
Bcd
ControlBean
,
Long
>
{
public
B
cd
ControlController
(
BcdControlService
service
)
{
public
class
B
dcControlController
extends
XDFController
<
Bdc
ControlBean
,
Long
>
{
public
B
dc
ControlController
(
BcdControlService
service
)
{
super
(
service
);
}
}
src/main/java/com/bytesw/bytebot/controller/BusinessParameterController.java
View file @
d136e061
...
...
@@ -30,7 +30,7 @@ import java.util.List;
@RestController
()
@RequestMapping
(
"/service/settings/business-parameter"
)
@ProgramSecurity
(
"
business-parameters
"
)
@ProgramSecurity
(
"
BUSINESS-PARAMETERS
"
)
@Log4j2
public
class
BusinessParameterController
extends
XDFController
<
BusinessParameterBean
,
BigInteger
>
{
@Autowired
BusinessParameterService
service
;
...
...
src/main/java/com/bytesw/bytebot/controller/SchedulerTaskController.java
View file @
d136e061
...
...
@@ -19,8 +19,8 @@ import java.util.Map;
import
java.util.Objects
;
@RestController
()
@RequestMapping
(
"/service/scheduler-task"
)
@ProgramSecurity
(
"
scheduler
"
)
@RequestMapping
(
"/service/s
ettings/s
cheduler-task"
)
@ProgramSecurity
(
"
SCHEDULER-TASK
"
)
@Log4j2
public
class
SchedulerTaskController
extends
XDFController
<
SchedulerTaskBean
,
BigInteger
>
{
public
SchedulerTaskController
(
SchedulerTaskService
service
)
{
...
...
src/main/java/com/bytesw/bytebot/http/FileValidationResponse.java
View file @
d136e061
...
...
@@ -8,8 +8,6 @@ package com.bytesw.bytebot.http;
import
lombok.Getter
;
import
lombok.Setter
;
import
java.time.LocalDate
;
@Getter
@Setter
public
class
FileValidationResponse
{
...
...
src/main/java/com/bytesw/bytebot/http/enums/ValidationStatusEnum.java
View file @
d136e061
...
...
@@ -11,6 +11,7 @@ import java.util.NoSuchElementException;
public
enum
ValidationStatusEnum
{
OK
(
"OK"
),
ERROR
(
"ERROR"
),
INCOMPATIBLE_EXTENSION
(
"IE"
),
HEADER_ERROR
(
"HE"
),
CONTENT_ERROR
(
"CE"
);
...
...
src/main/java/com/bytesw/bytebot/model/B
cd
Control.java
→
src/main/java/com/bytesw/bytebot/model/B
dc
Control.java
View file @
d136e061
...
...
@@ -10,8 +10,8 @@ import java.io.Serializable;
@Setter
@ToString
@Table
(
name
=
"avb_bcd_control"
)
@NamedQuery
(
name
=
"B
cdControl.findByPK"
,
query
=
"Select u from Bcd
Control u where u.id = ?1"
)
public
class
B
cdControl
implements
Serializable
{
@NamedQuery
(
name
=
"B
dcControl.findByPK"
,
query
=
"Select u from Bdc
Control u where u.id = ?1"
)
public
class
B
dcControl
implements
Serializable
{
@Id
@Column
(
name
=
"bcd_id"
)
...
...
@@ -19,10 +19,22 @@ public class BcdControl implements Serializable {
@GeneratedValue
(
strategy
=
GenerationType
.
SEQUENCE
,
generator
=
"AVB_BCD_CONTROL_GENERATOR"
)
private
Long
id
;
@Column
(
name
=
"agen_id"
)
private
Long
agentId
;
@Column
(
name
=
"bcd_uuid"
)
private
String
uuid
;
@Column
(
name
=
"bcd_file"
)
private
String
fileName
;
@Column
(
name
=
"bcd_file_id"
)
private
Long
fileId
;
@Column
(
name
=
"bcd_status"
)
private
String
status
;
@Column
(
name
=
"bcd_user"
)
private
String
user
;
@Column
(
name
=
"bcd_date"
)
private
String
date
;
}
src/main/java/com/bytesw/bytebot/model/enums/FrequentQuestionStatusEnum.java
View file @
d136e061
...
...
@@ -21,7 +21,9 @@ public enum FrequentQuestionStatusEnum {
PENDING_SYNCHRONIZED
(
"PS"
),
UPLOADED
(
"LO"
),
DELETED
(
"DE"
);
DELETED
(
"DE"
),
ERROR
(
"ER"
),
CORRECTO
(
"OK"
);
private
static
final
Map
<
String
,
FrequentQuestionStatusEnum
>
map
=
new
HashMap
<>();
...
...
src/main/java/com/bytesw/bytebot/model/enums/StatusBcdEnum.java
View file @
d136e061
...
...
@@ -8,10 +8,10 @@ import java.util.Map;
@Getter
public
enum
StatusBcdEnum
{
CARGANDO
(
"C
G
"
),
CARGADO
(
"C
GD
"
),
INDEXANDO
(
"I
DX
"
),
INDEXADO
(
"I
DXD
"
);
CARGANDO
(
"C
argando
"
),
CARGADO
(
"C
argado
"
),
INDEXANDO
(
"I
ndexando
"
),
INDEXADO
(
"I
ndexado
"
);
private
static
final
Map
<
String
,
StatusBcdEnum
>
map
=
new
HashMap
<>();
...
...
src/main/java/com/bytesw/bytebot/repository/BcdControlRepository.java
deleted
100644 → 0
View file @
7535be84
package
com
.
bytesw
.
bytebot
.
repository
;
import
com.bytesw.bytebot.model.BcdControl
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.data.repository.CrudRepository
;
public
interface
BcdControlRepository
extends
CrudRepository
<
BcdControl
,
Long
>,
JpaSpecificationExecutor
<
BcdControl
>
{
}
src/main/java/com/bytesw/bytebot/repository/BdcControlRepository.java
0 → 100644
View file @
d136e061
package
com
.
bytesw
.
bytebot
.
repository
;
import
com.bytesw.bytebot.model.BdcControl
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.repository.CrudRepository
;
import
org.springframework.data.repository.query.Param
;
import
java.util.Optional
;
public
interface
BdcControlRepository
extends
CrudRepository
<
BdcControl
,
Long
>,
JpaSpecificationExecutor
<
BdcControl
>
{
@Query
(
"select s from BdcControl s where s.uuid = :uuid"
)
Optional
<
BdcControl
>
findByUuid
(
@Param
(
"uuid"
)
String
uuid
);
}
src/main/java/com/bytesw/bytebot/service/AgentService.java
View file @
d136e061
...
...
@@ -376,6 +376,7 @@ public class AgentService extends CustomPaginationService<Agent> {
for
(
FrequentQuestion
frequentQuestion
:
agent
.
getFrequentQuestions
())
{
FrequentQuestionBean
frequentQuestionBean
=
new
FrequentQuestionBean
();
frequentQuestionBean
.
setId
(
frequentQuestion
.
getId
());
frequentQuestionBean
.
setUuid
(
frequentQuestion
.
getUuid
());
frequentQuestionBean
.
setDescription
(
frequentQuestion
.
getDescription
());
frequentQuestionBean
.
setUser
(
frequentQuestion
.
getUser
());
frequentQuestionBean
.
setFilename
(
frequentQuestion
.
getFilename
());
...
...
@@ -389,7 +390,6 @@ public class AgentService extends CustomPaginationService<Agent> {
}
// Deployment channel
bean
.
setDeploymentChannels
(
new
ArrayList
<>());
for
(
DeploymentChannel
deploymentChannel
:
agent
.
getDeploymentChannels
())
{
...
...
@@ -462,6 +462,10 @@ public class AgentService extends CustomPaginationService<Agent> {
List
<
Channel
>
channels
=
(
List
<
Channel
>)
channelRepository
.
findAll
();
for
(
Channel
channel
:
channels
)
{
List
<
ChannelParam
>
channelParamList
=
channel
.
getParameters
();
for
(
ChannelParam
channelParam
:
channelParamList
)
{
channelParam
.
setTraductions
(
channelParam
.
getTraductions
().
replace
(
"\\"
,
""
));
}
channelsBean
.
add
(
ChannelBean
.
clone
(
channel
));
}
...
...
src/main/java/com/bytesw/bytebot/service/BcdControlService.java
View file @
d136e061
package
com
.
bytesw
.
bytebot
.
service
;
import
com.bytesw.bytebot.bean.B
cd
ControlBean
;
import
com.bytesw.bytebot.model.B
cd
Control
;
import
com.bytesw.bytebot.repository.B
cd
ControlRepository
;
import
com.bytesw.bytebot.bean.B
dc
ControlBean
;
import
com.bytesw.bytebot.model.B
dc
Control
;
import
com.bytesw.bytebot.repository.B
dc
ControlRepository
;
import
com.bytesw.xdf.service.XDFService
;
import
lombok.extern.log4j.Log4j2
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.data.repository.CrudRepository
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
@Service
@Transactional
@Log4j2
public
class
BcdControlService
extends
XDFService
<
B
cdControl
,
Bcd
ControlBean
,
Long
>
{
protected
BcdControlService
(
B
cd
ControlRepository
repository
)
{
public
class
BcdControlService
extends
XDFService
<
B
dcControl
,
Bdc
ControlBean
,
Long
>
{
protected
BcdControlService
(
B
dc
ControlRepository
repository
)
{
super
(
repository
);
}
@Override
protected
B
cdControl
toModel
(
BcdControl
model
,
Bcd
ControlBean
bean
)
{
protected
B
dcControl
toModel
(
BdcControl
model
,
Bdc
ControlBean
bean
)
{
if
(
model
==
null
)
{
model
=
new
B
cd
Control
();
model
=
new
B
dc
Control
();
}
BeanUtils
.
copyProperties
(
bean
,
model
);
return
model
;
}
@Override
protected
B
cdControlBean
toBean
(
Bcd
Control
model
)
{
B
cdControlBean
bean
=
new
Bcd
ControlBean
();
protected
B
dcControlBean
toBean
(
Bdc
Control
model
)
{
B
dcControlBean
bean
=
new
Bdc
ControlBean
();
BeanUtils
.
copyProperties
(
model
,
bean
);
return
bean
;
}
...
...
src/main/java/com/bytesw/bytebot/service/BucketService.java
0 → 100644
View file @
d136e061
package
com
.
bytesw
.
bytebot
.
service
;
import
com.amazonaws.AmazonServiceException
;
import
com.amazonaws.SdkClientException
;
import
com.amazonaws.services.s3.model.Bucket
;
import
com.amazonaws.services.s3.model.DeleteObjectRequest
;
import
com.amazonaws.services.s3.model.ObjectMetadata
;
import
com.bytesw.bytebot.http.FileValidationResponse
;
import
com.bytesw.bytebot.model.BusinessParameter
;
import
com.bytesw.bytebot.model.QuestionFile
;
import
com.bytesw.bytebot.repository.BusinessParameterRepository
;
import
com.bytesw.bytebot.repository.QuestionFileRepository
;
import
com.bytesw.xdf.exception.NotFoundException
;
import
lombok.extern.log4j.Log4j2
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
com.amazonaws.services.s3.AmazonS3
;
import
com.amazonaws.services.s3.AmazonS3ClientBuilder
;
import
com.amazonaws.services.s3.model.PutObjectRequest
;
import
java.io.ByteArrayInputStream
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.InputStream
;
import
java.util.List
;
import
java.util.Optional
;
@Service
@Log4j2
public
class
BucketService
{
@Value
(
"${application.bucket.tenant}"
)
private
String
tenant
;
@Value
(
"${application.bucket.region}"
)
private
String
region
;
@Value
(
"${application.bucket.fileBucket}"
)
private
String
fileDir
;
@Value
(
"${application.bucket.modelBucket}"
)
private
String
modelDir
;
@Autowired
private
QuestionFileRepository
questionFileRepository
;
@Autowired
private
BusinessParameterRepository
businessParameterRepository
;
private
AmazonS3
getS3Client
()
{
return
AmazonS3ClientBuilder
.
standard
()
.
withRegion
(
region
)
.
build
();
}
public
boolean
generate
(
byte
[]
file
,
FileValidationResponse
response
)
{
Optional
<
BusinessParameter
>
businessParameter
=
businessParameterRepository
.
findByKey
(
"Bucket"
);
boolean
result
=
false
;
if
(!
businessParameter
.
isPresent
())
{
throw
new
NotFoundException
(
"No existe el parametro de negocio del bucket."
);
}
String
bucketName
=
businessParameter
.
get
().
getDefaultValue
();
File
mainFile
=
new
File
(
response
.
getFileName
());
try
{
FileOutputStream
stream
=
new
FileOutputStream
(
mainFile
);
stream
.
write
(
file
);
String
newFile
=
String
.
format
(
"%s/%s/1.0/%s/%s"
,
tenant
,
response
.
getUuid
(),
fileDir
,
mainFile
.
getName
());
PutObjectRequest
request
=
new
PutObjectRequest
(
bucketName
,
newFile
,
mainFile
);
AmazonS3
amazonS3
=
getS3Client
();
amazonS3
.
putObject
(
request
);
String
modelFile
=
String
.
format
(
"%s/%s/1.0/%s"
,
tenant
,
response
.
getUuid
(),
modelDir
);
createFolder
(
bucketName
,
modelFile
,
amazonS3
);
mainFile
.
delete
();
result
=
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
"Error al cargar archivo"
);
}
return
result
;
}
public
static
void
createFolder
(
String
bucketName
,
String
folderName
,
AmazonS3
client
)
{
ObjectMetadata
metadata
=
new
ObjectMetadata
();
metadata
.
setContentLength
(
0
);
InputStream
emptyContent
=
new
ByteArrayInputStream
(
new
byte
[
0
]);
PutObjectRequest
putObjectRequest
=
new
PutObjectRequest
(
bucketName
,
folderName
+
"/"
,
emptyContent
,
metadata
);
client
.
putObject
(
putObjectRequest
);
}
public
void
delete
(
String
uuid
)
{
Optional
<
BusinessParameter
>
businessParameter
=
businessParameterRepository
.
findByKey
(
"Bucket"
);
if
(!
businessParameter
.
isPresent
())
{
throw
new
NotFoundException
(
"No existe el parametro de negocio del bucket."
);
}
String
bucketName
=
businessParameter
.
get
().
getDefaultValue
();
try
{
AmazonS3
s3Client
=
getS3Client
();
Optional
<
QuestionFile
>
questionFile
=
questionFileRepository
.
findByUuid
(
uuid
);
if
(!
questionFile
.
isPresent
())
{
throw
new
NotFoundException
(
"El uuid no se encuentra enlazado con un file"
);
}
String
keyName
=
String
.
format
(
"%s/%s/1.0/%s/%s"
,
tenant
,
uuid
,
fileDir
,
questionFile
.
get
().
getName
());
s3Client
.
deleteObject
(
new
DeleteObjectRequest
(
bucketName
,
keyName
));
keyName
=
String
.
format
(
"%s/%s/1.0/%s/"
,
tenant
,
uuid
,
modelDir
);
s3Client
.
deleteObject
(
new
DeleteObjectRequest
(
bucketName
,
keyName
));
}
catch
(
AmazonServiceException
e
)
{
e
.
printStackTrace
();
}
catch
(
SdkClientException
e
)
{
e
.
printStackTrace
();
}
}
public
void
list
()
{
AmazonS3
s3
=
getS3Client
();
List
<
Bucket
>
buckets
=
s3
.
listBuckets
();
System
.
out
.
println
(
"Your {S3} buckets are:"
);
for
(
Bucket
b
:
buckets
)
{
System
.
out
.
println
(
"* "
+
b
.
getName
());
}
}
}
src/main/java/com/bytesw/bytebot/service/FileManagementService.java
View file @
d136e061
...
...
@@ -5,6 +5,7 @@
*/
package
com
.
bytesw
.
bytebot
.
service
;
import
com.bytesw.bytebot.etl.model.GoalForActions
;
import
com.bytesw.bytebot.http.FileValidationResponse
;
import
com.bytesw.bytebot.http.FileValidationResult
;
import
com.bytesw.bytebot.http.enums.ValidationStatusEnum
;
...
...
@@ -16,12 +17,9 @@ import java.io.ByteArrayInputStream;
import
java.io.IOException
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.*
;
import
com.bytesw.xdf.exception.NotFoundException
;
import
lombok.extern.log4j.Log4j2
;
import
org.apache.commons.io.FilenameUtils
;
import
org.apache.poi.ss.usermodel.Cell
;
...
...
@@ -282,4 +280,16 @@ public class FileManagementService {
}
return
isFileHeader
;
}
@Transactional
(
propagation
=
Propagation
.
REQUIRED
)
public
void
deleteGoalForAction
(
Long
id
)
{
Optional
<
QuestionFile
>
file
=
questionFileRepository
.
findById
(
id
);
if
(!
file
.
isPresent
())
{
throw
new
NotFoundException
(
"File no econtrado."
);
}
questionFileRepository
.
delete
(
file
.
get
());
}
}
src/main/java/com/bytesw/bytebot/service/KnowledgeService.java
0 → 100644
View file @
d136e061
package
com
.
bytesw
.
bytebot
.
service
;
import
com.bytesw.bytebot.etl.utils.JsonUtils
;
import
com.bytesw.bytebot.http.FileValidationResponse
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
lombok.extern.log4j.Log4j2
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.client.ClientProtocolException
;
import
org.apache.http.client.ResponseHandler
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpDelete
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.util.EntityUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.Map
;
@Service
@Log4j2
public
class
KnowledgeService
{
@Value
(
"${application.bucket.tenant}"
)
private
String
tenant
;
@Value
(
"${application.knowledge.url}"
)
private
String
url
;
public
boolean
generate
(
FileValidationResponse
response
)
throws
IOException
{
boolean
result
=
false
;
CloseableHttpClient
httpclient
=
HttpClients
.
createDefault
();
HttpPost
httppost
=
new
HttpPost
(
String
.
format
(
"%s/clients/%s/versions/1.0"
,
url
,
tenant
));
String
json
=
String
.
format
(
"{\"filename_csv\": \"%s\", \"index_name\": \"%s\"}"
,
response
.
getFileName
(),
response
.
getUuid
());
StringEntity
entity
=
new
StringEntity
(
json
);
try
{
httppost
.
setEntity
(
entity
);
httppost
.
setHeader
(
"Accept"
,
"application/json"
);
httppost
.
setHeader
(
"Content-type"
,
"application/json"
);
ResponseHandler
<
String
>
responseHandler
=
resp
->
{
int
status
=
resp
.
getStatusLine
().
getStatusCode
();
if
(
status
>=
200
&&
status
<
300
)
{
HttpEntity
entityRes
=
resp
.
getEntity
();
return
entityRes
!=
null
?
EntityUtils
.
toString
(
entityRes
)
:
null
;
}
else
{
throw
new
ClientProtocolException
(
"Error inesperado: "
+
status
);
}
};
String
res
=
httpclient
.
execute
(
httppost
,
responseHandler
);
String
status
=
(
String
)
JsonUtils
.
getFieldFromJson
(
res
,
"$.message.status"
);
if
(
status
.
equals
(
"success"
)){
result
=
true
;
}
}
catch
(
IOException
e
)
{
log
.
error
(
e
.
getMessage
());
}
return
result
;
}
public
boolean
delete
(
String
uuid
)
{
boolean
result
=
false
;
try
{
HttpDelete
httpDelete
=
new
HttpDelete
(
String
.
format
(
"%s/clients/%s/indexes/%s/versions/1.0"
,
url
,
tenant
,
uuid
));
System
.
out
.
println
(
"Executing request "
+
httpDelete
.
getRequestLine
());
ResponseHandler
<
String
>
responseHandler
=
response
->
{
int
status
=
response
.
getStatusLine
().
getStatusCode
();
if
(
status
>=
200
&&
status
<
300
)
{
HttpEntity
entity
=
response
.
getEntity
();
return
entity
!=
null
?
EntityUtils
.
toString
(
entity
)
:
null
;
}
else
{
throw
new
ClientProtocolException
(
"Error inesperado: "
+
status
);
}
};
CloseableHttpClient
httpclient
=
HttpClients
.
createDefault
();
String
res
=
httpclient
.
execute
(
httpDelete
,
responseHandler
);
httpclient
.
close
();
String
status
=
(
String
)
JsonUtils
.
getFieldFromJson
(
res
,
"$.message.status"
);
if
(
status
.
equals
(
"success"
)){
result
=
true
;
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
result
;
}
}
src/main/java/com/bytesw/bytebot/service/OrquestadorService.java
View file @
d136e061
package
com
.
bytesw
.
bytebot
.
service
;
import
com.bytesw.bytebot.http.FileValidationResponse
;
import
com.bytesw.bytebot.http.FileValidationResult
;
import
com.bytesw.bytebot.http.enums.ValidationStatusEnum
;
import
com.bytesw.bytebot.model.BdcControl
;
import
com.bytesw.bytebot.model.QuestionFile
;
import
com.bytesw.bytebot.model.enums.FrequentQuestionStatusEnum
;
import
com.bytesw.bytebot.model.enums.StatusBcdEnum
;
import
com.bytesw.bytebot.repository.BdcControlRepository
;
import
com.bytesw.bytebot.repository.QuestionFileRepository
;
import
com.bytesw.xdf.exception.NotFoundException
;
import
lombok.extern.log4j.Log4j2
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
import
java.util.Optional
;
@Service
@Transactional
@Log4j2
public
class
OrquestadorService
{
@Autowired
private
FileManagementService
fileManagementService
;
@Autowired
private
BucketService
bucketService
;
@Autowired
private
BdcControlRepository
bdcControlRepository
;
@Autowired
private
QuestionFileRepository
questionFileRepository
;
@Autowired
private
KnowledgeService
knowledgeService
;
public
FileValidationResponse
executeGenerateBCD
(
String
uuid
,
MultipartFile
file
)
{
BdcControl
model
=
new
BdcControl
();
FileValidationResponse
response
=
new
FileValidationResponse
();
boolean
step
=
false
;
try
{
//Valida y guarda en base de datos
response
=
fileManagementService
.
validateAndSaveFile
(
uuid
,
file
);
if
(
response
.
getFileValidationResult
().
getStatus
().
getName
()
!=
ValidationStatusEnum
.
OK
.
getName
())
{
response
.
setStatus
(
FrequentQuestionStatusEnum
.
ERROR
.
getName
());
return
response
;
}
model
.
setUuid
(
response
.
getUuid
());
model
.
setFileId
(
response
.
getId
());
model
.
setFileName
(
response
.
getFileName
());
model
.
setDate
(
response
.
getUploadDate
());
model
.
setStatus
(
StatusBcdEnum
.
CARGADO
.
getName
());
model
=
bdcControlRepository
.
save
(
model
);
//Carga archivo a bucket
step
=
bucketService
.
generate
(
file
.
getBytes
(),
response
);
if
(!
step
)
{
throw
new
NotFoundException
(
"Error a cargar archivo."
);
}
step
=
false
;
model
.
setStatus
(
StatusBcdEnum
.
INDEXANDO
.
getName
());
model
=
bdcControlRepository
.
save
(
model
);
//Generacion del modelo
step
=
knowledgeService
.
generate
(
response
);
if
(!
step
)
{
throw
new
NotFoundException
(
"Error a cargar archivo."
);
}
response
.
setStatus
(
FrequentQuestionStatusEnum
.
CORRECTO
.
getName
());
model
.
setStatus
(
StatusBcdEnum
.
INDEXADO
.
getName
());
model
=
bdcControlRepository
.
save
(
model
);
}
catch
(
Exception
e
)
{
response
.
setStatus
(
FrequentQuestionStatusEnum
.
ERROR
.
getName
());
}
return
response
;
}
public
FileValidationResponse
retry
(
String
uuid
)
{
Optional
<
BdcControl
>
modelBdc
=
bdcControlRepository
.
findByUuid
(
uuid
);
if
(!
modelBdc
.
isPresent
())
{
throw
new
NotFoundException
(
"No se subio archivo a la BD"
);
}
boolean
step
=
false
;
BdcControl
model
=
modelBdc
.
get
();
FileValidationResponse
response
=
modelToFileValidation
(
model
);
try
{
if
(
model
.
getStatus
().
equals
(
StatusBcdEnum
.
CARGADO
.
getName
()))
{
Optional
<
QuestionFile
>
questionFile
=
questionFileRepository
.
findByUuid
(
uuid
);
if
(!
questionFile
.
isPresent
())
{
throw
new
NotFoundException
(
"No se encontro archivo en la BD"
);
}
step
=
bucketService
.
generate
(
questionFile
.
get
().
getData
(),
response
);
if
(!
step
)
{
throw
new
NotFoundException
(
"Error a cargar archivo."
);
}
model
.
setStatus
(
StatusBcdEnum
.
INDEXANDO
.
getName
());
model
=
bdcControlRepository
.
save
(
model
);
step
=
false
;
}
if
(
model
.
getStatus
().
equals
(
StatusBcdEnum
.
INDEXANDO
.
getName
()))
{
step
=
knowledgeService
.
generate
(
response
);
if
(!
step
)
{
throw
new
NotFoundException
(
"Error a cargar knowledge."
);
}
}
model
.
setStatus
(
StatusBcdEnum
.
INDEXADO
.
getName
());
model
=
bdcControlRepository
.
save
(
model
);
response
.
setStatus
(
FrequentQuestionStatusEnum
.
CORRECTO
.
getName
());
}
catch
(
IOException
e
)
{
response
.
setStatus
(
FrequentQuestionStatusEnum
.
ERROR
.
getName
());
}
return
response
;
}
public
void
deleteBcd
(
String
uuid
)
{
Optional
<
BdcControl
>
bdcControl
=
bdcControlRepository
.
findByUuid
(
uuid
);
if
(!
bdcControl
.
isPresent
())
{
throw
new
NotFoundException
(
"Control no encontrado."
);
}
BdcControl
model
=
bdcControl
.
get
();
if
(
model
.
getStatus
().
equals
(
StatusBcdEnum
.
INDEXADO
.
getName
()))
{
boolean
step
=
knowledgeService
.
delete
(
uuid
);
if
(!
step
)
{
throw
new
NotFoundException
(
"Error a eliminar modelo del bucket"
);
}
model
.
setStatus
(
StatusBcdEnum
.
INDEXANDO
.
getName
());
model
=
bdcControlRepository
.
save
(
model
);
}
if
(
model
.
getStatus
().
equals
(
StatusBcdEnum
.
INDEXANDO
.
getName
()))
{
bucketService
.
delete
(
uuid
);
model
.
setStatus
(
StatusBcdEnum
.
CARGADO
.
getName
());
model
=
bdcControlRepository
.
save
(
model
);
}
Optional
<
QuestionFile
>
questionFile
=
questionFileRepository
.
findByUuid
(
uuid
);
if
(
questionFile
.
isPresent
())
{
questionFileRepository
.
deleteById
(
bdcControl
.
get
().
getFileId
());
}
bdcControlRepository
.
delete
(
model
);
}
private
FileValidationResponse
modelToFileValidation
(
BdcControl
model
){
FileValidationResponse
response
=
new
FileValidationResponse
();
response
.
setId
(
model
.
getId
());
response
.
setStatus
(
model
.
getStatus
());
response
.
setUuid
(
model
.
getUuid
());
response
.
setFileName
(
model
.
getFileName
());
response
.
setUploadDate
(
model
.
getDate
());
FileValidationResult
result
=
new
FileValidationResult
();
result
.
setStatus
(
ValidationStatusEnum
.
OK
);
response
.
setFileValidationResult
(
result
);
return
response
;
}
}
src/main/resources/application.yml
View file @
d136e061
...
...
@@ -4,7 +4,8 @@ server:
servlet.context-path
:
${APPLICATION_PATH:/bytebot}
port
:
${APPLICATION_PORT:9077}
web
:
static-content-location
:
file:/home/cristian/Documents/AVB_Backend/bytebot-html/
#static-content-location: file:/home/mgutierrez/Documentos/Bytesw/bytebot-workspace/dist/bytebot-html/
static-content-location
:
file:/home/mgutierrez/Descargas/dist-1/dist/bytebot-html/
#NOTA debe terminar con /
security
:
...
...
@@ -55,7 +56,7 @@ application:
multi-tenant-conf
:
exclude-service
:
/
authorization-service.url
:
http://localhost:17580
security
:
oauth2sso
# none, basic, oauth2sso
security
:
none
#
oauth2sso # none, basic, oauth2sso
security.method
:
true
security-exclude
:
/service/oauth/userinfo, /actuator/**, /mylogout, /login, /logout, /goodbye, /error, /anon, /cache.manifest, /favicon.ico, /service/file, /goodbye /byteboot
messaging
:
...
...
@@ -93,6 +94,13 @@ application:
host
:
localhost
port
:
8161
queue-name
:
task_queue
bucket
:
tenant
:
T186A1
region
:
us-east-1
fileBucket
:
KB_Files
modelBucket
:
KB_Model
knowledge
:
url
:
"
http://127.0.0.1:3000/byteknowledgebaseApi"
spring
:
main
:
...
...
@@ -104,7 +112,7 @@ spring:
datasource
:
database-type
:
postgres
schemaName
:
avb
url
:
jdbc:postgresql://
localhost
:5432/bytebot?useSSL=false¤tSchema=avb
url
:
jdbc:postgresql://
192.168.0.115
:5432/bytebot?useSSL=false¤tSchema=avb
driverClassName
:
'
org.postgresql.Driver'
username
:
postgres
password
:
postgres
...
...
@@ -120,11 +128,11 @@ spring:
oauth2-client
:
clientId
:
xdf-client
clientSecret
:
xdf-secret
accessTokenUri
:
http://192.168.
1.6
:18080/oauth/token
userAuthorizationUri
:
http://192.168.
1.6
:18080/oauth/authorize
accessTokenUri
:
http://192.168.
0.115
:18080/oauth/token
userAuthorizationUri
:
http://192.168.
0.115
:18080/oauth/authorize
oauth2-resource
:
userInfoUri
:
http://192.168.
1.6
:18080/oauth/userinfo
logoutUri
:
http://192.168.
1.6
:18080/oauth/userlogout
userInfoUri
:
http://192.168.
0.115
:18080/oauth/userinfo
logoutUri
:
http://192.168.
0.115
:18080/oauth/userlogout
tenants
:
-
id
:
T186A1
...
...
@@ -132,7 +140,7 @@ spring:
datasource
:
database-type
:
postgres
schemaName
:
avb
url
:
jdbc:postgresql://
localhost
:5432/bytebot?useSSL=false¤tSchema=avb
url
:
jdbc:postgresql://
192.168.0.115
:5432/bytebot?useSSL=false¤tSchema=avb
driverClassName
:
'
org.postgresql.Driver'
username
:
postgres
password
:
postgres
...
...
@@ -142,16 +150,16 @@ spring:
testWhileIdle
:
true
hikari.registerMbeans
:
true
security
:
basepath
:
http://
192.168.1.6
:9077/bytebot
basepath
:
http://
localhost
:9077/bytebot
provider
:
byte
# oracle, amazon
oauth2-client
:
clientId
:
xdf-client
clientSecret
:
xdf-secret
accessTokenUri
:
http://192.168.
1.6
:18080/oauth/token
userAuthorizationUri
:
http://192.168.
1.6
:18080/oauth/authorize
accessTokenUri
:
http://192.168.
0.115
:18080/oauth/token
userAuthorizationUri
:
http://192.168.
0.115
:18080/oauth/authorize
oauth2-resource
:
userInfoUri
:
http://192.168.
1.6
:18080/oauth/userinfo
logoutUri
:
http://192.168.
1.6
:18080/oauth/userlogout
userInfoUri
:
http://192.168.
0.115
:18080/oauth/userinfo
logoutUri
:
http://192.168.
0.115
:18080/oauth/userlogout
jpa
:
...
...
@@ -174,11 +182,11 @@ batch:
datasource
:
jdbc-driver
:
'
org.postgresql.Driver'
username
:
postgres
password
:
jdbc-url
:
jdbc:postgresql://
192.168.21.74:5432/avb?useSSL=false
password
:
postgres
jdbc-url
:
jdbc:postgresql://
localhost:5432/bytebot?useSSL=false¤tSchema=avb
query
:
'
select
*
from
events
WHERE
id
>
%d
order
by
id
asc'
logging.level.root
:
DEBUG
logging.level.root
:
INFO
logging.pattern.console
:
'
%d{dd-MM-yyyy
HH:mm:ss.SSS}
%magenta([%thread])
%highlight(%-5level)
%logger.%M
-
%msg%n'
logging.level.com.zaxxer.hikari
:
ERROR
...
...
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