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
33929e84
Commit
33929e84
authored
Dec 22, 2021
by
Roberto Loayza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Base de conocimiento
parent
8bb9f91d
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
332 additions
and
43 deletions
+332
-43
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
+18
-3
BdcControlController.java
...a/com/bytesw/bytebot/controller/BdcControlController.java
+3
-3
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
BcdControlService.java
...in/java/com/bytesw/bytebot/service/BcdControlService.java
+9
-10
BucketService.java
src/main/java/com/bytesw/bytebot/service/BucketService.java
+76
-0
FileManagementService.java
...ava/com/bytesw/bytebot/service/FileManagementService.java
+16
-6
KnowledgeService.java
...ain/java/com/bytesw/bytebot/service/KnowledgeService.java
+41
-0
OrquestadorService.java
...n/java/com/bytesw/bytebot/service/OrquestadorService.java
+117
-0
No files found.
pom.xml
View file @
33929e84
...
...
@@ -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 @
33929e84
...
...
@@ -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 @
33929e84
...
...
@@ -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,20 @@ 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
)
{
e
.
printStackTrace
();
return
new
ResponseEntity
<>(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
}
}
@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
)
{
...
...
src/main/java/com/bytesw/bytebot/controller/B
cd
ControlController.java
→
src/main/java/com/bytesw/bytebot/controller/B
dc
ControlController.java
View file @
33929e84
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/http/FileValidationResponse.java
View file @
33929e84
...
...
@@ -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 @
33929e84
...
...
@@ -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 @
33929e84
...
...
@@ -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 @
33929e84
...
...
@@ -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 @
33929e84
...
...
@@ -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 @
8bb9f91d
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 @
33929e84
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/BcdControlService.java
View file @
33929e84
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 @
33929e84
package
com
.
bytesw
.
bytebot
.
service
;
import
com.amazonaws.services.s3.model.Bucket
;
import
com.bytesw.bytebot.http.FileValidationResponse
;
import
com.bytesw.bytebot.model.BusinessParameter
;
import
com.bytesw.bytebot.repository.BusinessParameterRepository
;
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.regions.Regions
;
import
com.amazonaws.services.s3.AmazonS3
;
import
com.amazonaws.services.s3.AmazonS3ClientBuilder
;
import
com.amazonaws.services.s3.model.PutObjectRequest
;
import
java.io.File
;
import
java.io.FileOutputStream
;
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
;
@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
);
mainFile
.
delete
();
result
=
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
"Error al cargar archivo"
);
}
return
result
;
}
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 @
33929e84
...
...
@@ -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 @
33929e84
package
com
.
bytesw
.
bytebot
.
service
;
import
com.bytesw.bytebot.http.FileValidationResponse
;
import
lombok.extern.log4j.Log4j2
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
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.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
java.io.IOException
;
@Service
@Log4j2
public
class
KnowledgeService
{
@Value
(
"${application.bucket.tenant}"
)
private
String
tenant
;
@Value
(
"${application.knowledge.url}"
)
private
String
url
;
public
void
generate
(
FileValidationResponse
response
)
throws
IOException
{
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
);
httppost
.
setEntity
(
entity
);
httppost
.
setHeader
(
"Accept"
,
"application/json"
);
httppost
.
setHeader
(
"Content-type"
,
"application/json"
);
CloseableHttpResponse
res
=
httpclient
.
execute
(
httppost
);
httpclient
.
close
();
}
public
void
delete
()
{
HttpPost
httpPost
=
new
HttpPost
();
}
}
src/main/java/com/bytesw/bytebot/service/OrquestadorService.java
View file @
33929e84
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."
);
}
model
.
setStatus
(
StatusBcdEnum
.
INDEXANDO
.
getName
());
model
=
bdcControlRepository
.
save
(
model
);
//Generacion del modelo
knowledgeService
.
generate
(
response
);
bdcControlRepository
.
delete
(
model
);
response
.
setStatus
(
FrequentQuestionStatusEnum
.
CORRECTO
.
getName
());
}
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
);
}
if
(
model
.
getStatus
().
equals
(
StatusBcdEnum
.
INDEXANDO
.
getName
()))
{
knowledgeService
.
generate
(
response
);
}
bdcControlRepository
.
delete
(
model
);
response
.
setStatus
(
FrequentQuestionStatusEnum
.
CORRECTO
.
getName
());
}
catch
(
IOException
e
)
{
response
.
setStatus
(
FrequentQuestionStatusEnum
.
ERROR
.
getName
());
}
return
response
;
}
public
void
deleteBcd
(
String
uuid
)
{
}
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
;
}
}
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