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
0683f8b6
Commit
0683f8b6
authored
Dec 16, 2021
by
Roberto Loayza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ajustes en Controlador y Servicio de Goal
parent
22163f10
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
70 deletions
+44
-70
GoalController.java
...in/java/com/bytesw/bytebot/controller/GoalController.java
+1
-56
GoalService.java
src/main/java/com/bytesw/bytebot/service/GoalService.java
+43
-14
No files found.
src/main/java/com/bytesw/bytebot/controller/GoalController.java
View file @
0683f8b6
package
com
.
bytesw
.
bytebot
.
controller
;
package
com
.
bytesw
.
bytebot
.
controller
;
import
com.bytesw.bytebot.etl.beans.GoalBean
;
import
com.bytesw.bytebot.service.GoalService
;
import
com.bytesw.bytebot.service.GoalService
;
import
com.bytesw.xdf.annotation.ProgramSecurity
;
import
com.bytesw.xdf.annotation.ProgramSecurity
;
import
com.bytesw.xdf.controller.XDFController
;
import
com.bytesw.xdf.controller.XDFController
;
import
com.google.gson.GsonBuilder
;
import
com.google.gson.GsonBuilder
;
import
io.swagger.annotations.ApiParam
;
import
lombok.extern.log4j.Log4j2
;
import
lombok.extern.log4j.Log4j2
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -19,7 +14,7 @@ import java.util.Map;
...
@@ -19,7 +14,7 @@ import java.util.Map;
@RequestMapping
(
"/service/settings/goal"
)
@RequestMapping
(
"/service/settings/goal"
)
@ProgramSecurity
(
"GOAL"
)
@ProgramSecurity
(
"GOAL"
)
@Log4j2
@Log4j2
public
class
GoalController
extends
XDFController
<
GoalBean
,
Long
>
{
public
class
GoalController
extends
XDFController
<
Map
,
Long
>
{
@Autowired
@Autowired
private
GoalService
goalService
;
private
GoalService
goalService
;
...
@@ -30,54 +25,4 @@ public class GoalController extends XDFController<GoalBean, Long> {
...
@@ -30,54 +25,4 @@ public class GoalController extends XDFController<GoalBean, Long> {
super
(
service
);
super
(
service
);
}
}
@PostMapping
(
value
=
"/goalForAction"
)
@PreAuthorize
(
"hasPermission(this, 'view')"
)
public
ResponseEntity
<
String
>
createGoalForAction
(
@RequestBody
Map
<
String
,
Object
>
body
)
{
GoalBean
info
=
goalService
.
saveGoalForAction
(
body
);
return
new
ResponseEntity
(
gson
.
toJson
(
info
),
HttpStatus
.
OK
);
}
@PutMapping
(
value
=
"/goalForAction/{id}"
)
@PreAuthorize
(
"hasPermission(this, 'edit')"
)
public
ResponseEntity
<
String
>
updateConversationalAgent
(
@PathVariable
(
"id"
)
Long
id
,
@RequestBody
Map
<
String
,
Object
>
body
)
{
String
info
=
""
;
try
{
goalService
.
updateGoalForActions
(
body
,
id
);
info
=
"Ok"
;
return
new
ResponseEntity
(
gson
.
toJson
(
info
),
HttpStatus
.
OK
);
}
catch
(
Exception
e
)
{
info
=
e
.
getMessage
();
}
return
new
ResponseEntity
(
gson
.
toJson
(
info
),
HttpStatus
.
INTERNAL_SERVER_ERROR
);
}
@GetMapping
(
value
=
"/goalForAction/{id}"
)
@PreAuthorize
(
"hasPermission(this, 'view')"
)
public
ResponseEntity
<
String
>
getActionByGoalId
(
@ApiParam
(
value
=
"id"
,
required
=
true
)
@PathVariable
(
"id"
)
Long
id
)
{
HttpStatus
hs
=
HttpStatus
.
OK
;
try
{
return
new
ResponseEntity
<>(
gsonBuilder
.
create
().
toJson
(
goalService
.
getGoalForActions
(
id
)),
hs
);
}
catch
(
Exception
e
)
{
String
info
=
"Error detectado al obtener informacion"
;
hs
=
HttpStatus
.
INTERNAL_SERVER_ERROR
;
return
new
ResponseEntity
<>(
gsonBuilder
.
create
().
toJson
(
info
),
hs
);
}
}
@GetMapping
(
value
=
"/goalForAction/"
)
@PreAuthorize
(
"hasPermission(this, 'view')"
)
public
ResponseEntity
<
String
>
getActionByGoalIdAll
()
{
HttpStatus
hs
=
HttpStatus
.
OK
;
try
{
return
new
ResponseEntity
<>(
gsonBuilder
.
create
().
toJson
(
goalService
.
getGoalForActionsAll
()),
hs
);
}
catch
(
Exception
e
)
{
String
info
=
"Error detectado al obtener informacion"
;
hs
=
HttpStatus
.
INTERNAL_SERVER_ERROR
;
return
new
ResponseEntity
<>(
gsonBuilder
.
create
().
toJson
(
info
),
hs
);
}
}
}
}
src/main/java/com/bytesw/bytebot/service/GoalService.java
View file @
0683f8b6
...
@@ -19,7 +19,7 @@ import java.util.*;
...
@@ -19,7 +19,7 @@ import java.util.*;
@Service
@Service
@Transactional
@Transactional
@Log4j2
@Log4j2
public
class
GoalService
extends
XDFService
<
Goal
,
GoalBean
,
Long
>
{
public
class
GoalService
extends
XDFService
<
Goal
,
Map
,
Long
>
{
@Autowired
@Autowired
private
GoalRepository
goalRepository
;
private
GoalRepository
goalRepository
;
...
@@ -38,23 +38,28 @@ public class GoalService extends XDFService<Goal, GoalBean, Long> {
...
@@ -38,23 +38,28 @@ public class GoalService extends XDFService<Goal, GoalBean, Long> {
}
}
@Override
@Override
protected
Goal
toModel
(
Goal
model
,
GoalBean
bean
)
{
protected
Goal
toModel
(
Goal
model
,
Map
map
)
{
if
(
model
==
null
)
{
if
(
model
==
null
)
{
model
=
new
Goal
();
model
=
new
Goal
();
}
}
BeanUtils
.
copyProperties
(
bean
,
model
);
model
.
setId
((
Long
)
map
.
get
(
"id"
));
model
.
setIdentifier
(
String
.
valueOf
(
map
.
get
(
"ident"
)));
model
.
setAgenId
((
Long
)
map
.
get
(
"agentId"
));
return
model
;
return
model
;
}
}
@Override
@Override
protected
GoalBean
toBean
(
Goal
model
)
{
protected
Map
toBean
(
Goal
model
)
{
GoalBean
bean
=
new
GoalBean
();
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
BeanUtils
.
copyProperties
(
model
,
bean
);
map
.
put
(
"id"
,
model
.
getId
());
return
bean
;
map
.
put
(
"ident"
,
model
.
getIdentifier
());
map
.
put
(
"agentId"
,
model
.
getAgenId
());
return
map
;
}
}
@Override
@Transactional
(
propagation
=
Propagation
.
REQUIRED
)
@Transactional
(
propagation
=
Propagation
.
REQUIRED
)
public
GoalBean
saveGoalForAction
(
Map
<
String
,
Object
>
body
)
{
public
Map
create
(
Map
body
)
{
Goal
goal
=
new
Goal
();
Goal
goal
=
new
Goal
();
...
@@ -62,6 +67,11 @@ public class GoalService extends XDFService<Goal, GoalBean, Long> {
...
@@ -62,6 +67,11 @@ public class GoalService extends XDFService<Goal, GoalBean, Long> {
throw
new
NotFoundException
(
"No se encuentran parametros."
);
throw
new
NotFoundException
(
"No se encuentran parametros."
);
}
}
List
<
Object
>
actions
=
(
List
)
body
.
get
(
"actionList"
);
if
(
actions
.
isEmpty
())
{
throw
new
NotFoundException
(
"Debe poseer minimo un action."
);
}
Long
agenId
=
Long
.
valueOf
(
body
.
get
(
"AgentId"
).
toString
());
Long
agenId
=
Long
.
valueOf
(
body
.
get
(
"AgentId"
).
toString
());
if
(!
agentRepository
.
existsById
(
agenId
))
{
if
(!
agentRepository
.
existsById
(
agenId
))
{
...
@@ -78,7 +88,7 @@ public class GoalService extends XDFService<Goal, GoalBean, Long> {
...
@@ -78,7 +88,7 @@ public class GoalService extends XDFService<Goal, GoalBean, Long> {
goal
.
setAgenId
(
agenId
);
goal
.
setAgenId
(
agenId
);
goal
.
setIdentifier
(
ident
);
goal
.
setIdentifier
(
ident
);
goal
=
goalRepository
.
save
(
goal
);
goal
=
goalRepository
.
save
(
goal
);
goalForActionService
.
saveGoalForAction
(
goal
.
getId
(),
(
List
)
body
.
get
(
"actionList"
)
);
goalForActionService
.
saveGoalForAction
(
goal
.
getId
(),
actions
);
return
toBean
(
goal
);
return
toBean
(
goal
);
}
}
...
@@ -93,8 +103,9 @@ public class GoalService extends XDFService<Goal, GoalBean, Long> {
...
@@ -93,8 +103,9 @@ public class GoalService extends XDFService<Goal, GoalBean, Long> {
goalRepository
.
deleteById
(
goalId
);
goalRepository
.
deleteById
(
goalId
);
}
}
@Override
@Transactional
(
propagation
=
Propagation
.
REQUIRED
)
@Transactional
(
propagation
=
Propagation
.
REQUIRED
)
public
void
updateGoalForActions
(
Map
<
String
,
Object
>
body
,
Long
goalId
)
{
public
Map
update
(
Map
body
,
Long
goalId
)
{
if
(
body
.
isEmpty
())
{
if
(
body
.
isEmpty
())
{
throw
new
NotFoundException
(
"No se encuentran parametros."
);
throw
new
NotFoundException
(
"No se encuentran parametros."
);
...
@@ -104,6 +115,11 @@ public class GoalService extends XDFService<Goal, GoalBean, Long> {
...
@@ -104,6 +115,11 @@ public class GoalService extends XDFService<Goal, GoalBean, Long> {
throw
new
NotFoundException
(
"Goal no se encuenta registrado"
);
throw
new
NotFoundException
(
"Goal no se encuenta registrado"
);
}
}
List
<
Object
>
actions
=
(
List
)
body
.
get
(
"actionList"
);
if
(
actions
.
isEmpty
())
{
throw
new
NotFoundException
(
"Debe poseer minimo un action."
);
}
Long
agenId
=
Long
.
valueOf
(
body
.
get
(
"AgentId"
).
toString
());
Long
agenId
=
Long
.
valueOf
(
body
.
get
(
"AgentId"
).
toString
());
String
ident
=
body
.
get
(
"Ident"
).
toString
();
String
ident
=
body
.
get
(
"Ident"
).
toString
();
...
@@ -111,16 +127,27 @@ public class GoalService extends XDFService<Goal, GoalBean, Long> {
...
@@ -111,16 +127,27 @@ public class GoalService extends XDFService<Goal, GoalBean, Long> {
throw
new
NotFoundException
(
"Agente no registrado."
);
throw
new
NotFoundException
(
"Agente no registrado."
);
}
}
Optional
<
Goal
>
goalOptional
=
goalRepository
.
findByAgentAndIdent
(
agenId
,
ident
);
if
(
goalOptional
.
isPresent
())
{
if
(
goalOptional
.
get
().
getId
()
!=
goalId
)
{
throw
new
AlreadyExistsException
(
"Goal ya existe en la base de datos para el agente ingresado."
);
}
}
Goal
goal
=
new
Goal
();
Goal
goal
=
new
Goal
();
goal
.
setId
(
goalId
);
goal
.
setId
(
goalId
);
goal
.
setAgenId
(
agenId
);
goal
.
setAgenId
(
agenId
);
goal
.
setIdentifier
(
ident
);
goal
.
setIdentifier
(
ident
);
goal
=
goalRepository
.
save
(
goal
);
goal
=
goalRepository
.
save
(
goal
);
goalForActionService
.
updateGoalForAction
(
goal
.
getId
(),
(
List
)
body
.
get
(
"actionList"
));
goalForActionService
.
updateGoalForAction
(
goal
.
getId
(),
actions
);
return
toBean
(
goal
);
}
}
public
Map
<
String
,
Object
>
getGoalForActions
(
Long
id
){
@Override
public
Map
getById
(
Long
id
){
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
Optional
<
Goal
>
goal
=
goalRepository
.
findById
(
id
);
Optional
<
Goal
>
goal
=
goalRepository
.
findById
(
id
);
...
@@ -133,17 +160,19 @@ public class GoalService extends XDFService<Goal, GoalBean, Long> {
...
@@ -133,17 +160,19 @@ public class GoalService extends XDFService<Goal, GoalBean, Long> {
throw
new
NotFoundException
(
"Actions no encontrados"
);
throw
new
NotFoundException
(
"Actions no encontrados"
);
}
}
result
.
put
(
"id"
,
goal
.
get
().
getId
());
result
.
put
(
"AgentId"
,
goal
.
get
().
getAgenId
());
result
.
put
(
"AgentId"
,
goal
.
get
().
getAgenId
());
result
.
put
(
"Ident"
,
goal
.
get
().
getIdentifier
());
result
.
put
(
"Ident"
,
goal
.
get
().
getIdentifier
());
result
.
put
(
"actionList"
,
listAction
);
result
.
put
(
"actionList"
,
listAction
);
return
result
;
return
result
;
}
}
public
List
<
Map
>
getGoalForActionsAll
(){
@Override
public
List
<
Map
>
getAll
(){
List
<
Map
>
result
=
new
ArrayList
<>();
List
<
Map
>
result
=
new
ArrayList
<>();
List
<
Goal
>
list
=
(
List
<
Goal
>)
goalRepository
.
findAll
();
List
<
Goal
>
list
=
(
List
<
Goal
>)
goalRepository
.
findAll
();
for
(
Goal
goal:
list
)
{
for
(
Goal
goal:
list
)
{
result
.
add
(
get
GoalForActions
(
goal
.
getId
()));
result
.
add
(
get
ById
(
goal
.
getId
()));
}
}
return
result
;
return
result
;
}
}
...
...
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