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
1aaa0bc6
Commit
1aaa0bc6
authored
Dec 06, 2021
by
Roberto Loayza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mantenimiento GoalForAction:
- Get - GetAll
parent
09ba7810
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
95 additions
and
19 deletions
+95
-19
GoalController.java
...in/java/com/bytesw/bytebot/controller/GoalController.java
+33
-5
GoalForActionService.java
...java/com/bytesw/bytebot/service/GoalForActionService.java
+26
-4
GoalService.java
src/main/java/com/bytesw/bytebot/service/GoalService.java
+36
-10
No files found.
src/main/java/com/bytesw/bytebot/controller/GoalController.java
View file @
1aaa0bc6
package
com
.
bytesw
.
bytebot
.
controller
;
import
com.bytesw.bytebot.bean.AgentBean
;
import
com.bytesw.bytebot.etl.beans.GoalBean
;
import
com.bytesw.bytebot.service.GoalService
;
import
com.bytesw.xdf.annotation.ProgramSecurity
;
import
com.bytesw.xdf.controller.XDFController
;
import
com.
bytesw.xdf.sql.beans.Pagination
;
import
com.
google.gson.GsonBuilder
;
import
io.swagger.annotations.ApiParam
;
import
lombok.extern.log4j.Log4j2
;
import
org.apache.commons.lang.exception.ExceptionUtils
;
...
...
@@ -21,10 +20,13 @@ import java.util.Map;
@RequestMapping
(
"/service/settings/goal"
)
@ProgramSecurity
(
"GOAL"
)
@Log4j2
public
class
GoalController
extends
XDFController
<
GoalBean
,
Stri
ng
>
{
public
class
GoalController
extends
XDFController
<
GoalBean
,
Lo
ng
>
{
@Autowired
private
GoalService
goalService
;
@Autowired
private
GsonBuilder
gsonBuilder
;
public
GoalController
(
GoalService
service
)
{
super
(
service
);
}
...
...
@@ -32,7 +34,7 @@ public class GoalController extends XDFController<GoalBean, String> {
@PostMapping
(
value
=
"/goalForAction"
)
@PreAuthorize
(
"hasPermission(this, 'view')"
)
public
ResponseEntity
<
String
>
createGoalForAction
(
@RequestBody
Map
<
String
,
Object
>
body
)
{
GoalBean
info
=
goalService
.
save
(
body
);
GoalBean
info
=
goalService
.
save
GoalForAction
(
body
);
return
new
ResponseEntity
(
gson
.
toJson
(
info
),
HttpStatus
.
OK
);
}
...
...
@@ -41,7 +43,7 @@ public class GoalController extends XDFController<GoalBean, String> {
public
ResponseEntity
<
String
>
GoalForAction
(
@ApiParam
(
value
=
"id"
,
required
=
true
)
@PathVariable
(
"id"
)
Long
id
)
{
String
info
=
""
;
try
{
goalService
.
delete
(
id
);
goalService
.
delete
GoalForAction
(
id
);
info
=
id
.
toString
();
return
new
ResponseEntity
(
gson
.
toJson
(
info
),
HttpStatus
.
OK
);
}
catch
(
Exception
e
)
{
...
...
@@ -63,4 +65,30 @@ public class GoalController extends XDFController<GoalBean, String> {
}
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/GoalForActionService.java
View file @
1aaa0bc6
package
com
.
bytesw
.
bytebot
.
service
;
import
com.bytesw.bytebot.etl.beans.ActionBean
;
import
com.bytesw.bytebot.etl.beans.GoalForActionsBean
;
import
com.bytesw.bytebot.etl.dao.ActionRepository
;
import
com.bytesw.bytebot.etl.model.Action
;
import
com.bytesw.bytebot.etl.model.GoalForActions
;
import
com.bytesw.bytebot.repository.GoalForActionsRepository
;
import
com.bytesw.bytebot.repository.GoalRepository
;
...
...
@@ -51,7 +53,7 @@ public class GoalForActionService extends XDFService<GoalForActions, GoalForActi
}
@Transactional
(
propagation
=
Propagation
.
REQUIRED
)
public
void
save
(
Long
idGoal
,
List
<
Object
>
actions
)
{
public
void
save
GoalForAction
(
Long
idGoal
,
List
<
Object
>
actions
)
{
if
(!
goalRepository
.
existsById
(
idGoal
))
{
throw
new
NotFoundException
(
"Goal no registrado."
);
}
...
...
@@ -69,7 +71,7 @@ public class GoalForActionService extends XDFService<GoalForActions, GoalForActi
}
@Transactional
(
propagation
=
Propagation
.
REQUIRED
)
public
void
delete
(
Long
goalId
)
{
public
void
delete
GoalForAction
(
Long
goalId
)
{
Optional
<
List
<
GoalForActions
>>
listGoalForActions
=
goalForActionsRepository
.
findGoalForActionsByGoalId
(
goalId
);
if
(!
listGoalForActions
.
isPresent
())
{
...
...
@@ -82,7 +84,7 @@ public class GoalForActionService extends XDFService<GoalForActions, GoalForActi
}
@Transactional
(
propagation
=
Propagation
.
REQUIRED
)
public
void
update
(
Long
idGoal
,
List
<
Object
>
actions
)
{
public
void
update
GoalForAction
(
Long
idGoal
,
List
<
Object
>
actions
)
{
Optional
<
List
<
GoalForActions
>>
listActual
=
goalForActionsRepository
.
findGoalForActionsByGoalId
(
idGoal
);
if
(!
listActual
.
isPresent
())
{
throw
new
NotFoundException
(
"GoalForActions no encontrados."
);
...
...
@@ -109,7 +111,27 @@ public class GoalForActionService extends XDFService<GoalForActions, GoalForActi
newGoalForActions
.
setActionId
(
id
);
goalForActionsRepository
.
save
(
newGoalForActions
);
}
}
public
List
<
Map
>
getGoalForAction
(
Long
id
)
{
List
<
Map
>
list
=
new
ArrayList
<>();
Optional
<
List
<
GoalForActions
>>
goalForActions
=
goalForActionsRepository
.
findGoalForActionsByGoalId
(
id
);
if
(!
goalForActions
.
isPresent
())
{
throw
new
NotFoundException
(
"No se encontraron actions."
);
}
for
(
GoalForActions
actions
:
goalForActions
.
get
())
{
Action
action
=
actionRepository
.
findById
(
actions
.
getActionId
()).
get
();
if
(
action
==
null
)
{
log
.
debug
(
"No se encontró la accion."
);
continue
;
}
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"IdAction"
,
String
.
valueOf
(
action
.
getId
()));
map
.
put
(
"desc"
,
action
.
getIdentifier
());
list
.
add
(
map
);
}
return
list
;
}
}
src/main/java/com/bytesw/bytebot/service/GoalService.java
View file @
1aaa0bc6
...
...
@@ -2,6 +2,7 @@ package com.bytesw.bytebot.service;
import
com.bytesw.bytebot.etl.beans.GoalBean
;
import
com.bytesw.bytebot.etl.model.Goal
;
import
com.bytesw.bytebot.etl.model.GoalForActions
;
import
com.bytesw.bytebot.repository.*
;
import
com.bytesw.xdf.exception.AlreadyExistsException
;
import
com.bytesw.xdf.exception.NotFoundException
;
...
...
@@ -13,9 +14,7 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.*
;
@Service
@Transactional
...
...
@@ -55,7 +54,7 @@ public class GoalService extends XDFService<Goal, GoalBean, Long> {
}
@Transactional
(
propagation
=
Propagation
.
REQUIRED
)
public
GoalBean
save
(
Map
<
String
,
Object
>
body
)
{
public
GoalBean
save
GoalForAction
(
Map
<
String
,
Object
>
body
)
{
Goal
goal
=
new
Goal
();
...
...
@@ -64,12 +63,12 @@ public class GoalService extends XDFService<Goal, GoalBean, Long> {
}
Long
agenId
=
Long
.
valueOf
(
body
.
get
(
"AgentId"
).
toString
());
String
ident
=
body
.
get
(
"Ident"
).
toString
();
if
(!
agentRepository
.
existsById
(
agenId
))
{
throw
new
NotFoundException
(
"Agente no registrado."
);
}
String
ident
=
body
.
get
(
"Ident"
).
toString
();
Optional
<
Goal
>
goalOptional
=
goalRepository
.
findByAgentAndIdent
(
agenId
,
ident
);
if
(
goalOptional
.
isPresent
())
{
...
...
@@ -79,20 +78,19 @@ public class GoalService extends XDFService<Goal, GoalBean, Long> {
goal
.
setAgenId
(
agenId
);
goal
.
setIdentifier
(
ident
);
goal
=
goalRepository
.
save
(
goal
);
goalForActionService
.
save
(
goal
.
getId
(),
(
List
)
body
.
get
(
"actionList"
));
goalForActionService
.
save
GoalForAction
(
goal
.
getId
(),
(
List
)
body
.
get
(
"actionList"
));
return
toBean
(
goal
);
}
@Override
@Transactional
(
propagation
=
Propagation
.
REQUIRED
)
public
void
delete
(
Long
goalId
)
{
public
void
delete
GoalForAction
(
Long
goalId
)
{
if
(!
goalRepository
.
existsById
(
goalId
)){
throw
new
NotFoundException
(
"Goal no registrado."
);
}
goalForActionService
.
delete
(
goalId
);
goalForActionService
.
delete
GoalForAction
(
goalId
);
goalRepository
.
deleteById
(
goalId
);
}
...
...
@@ -120,6 +118,34 @@ public class GoalService extends XDFService<Goal, GoalBean, Long> {
goal
.
setIdentifier
(
ident
);
goal
=
goalRepository
.
save
(
goal
);
goalForActionService
.
update
(
goal
.
getId
(),
(
List
)
body
.
get
(
"actionList"
));
goalForActionService
.
updateGoalForAction
(
goal
.
getId
(),
(
List
)
body
.
get
(
"actionList"
));
}
public
Map
<
String
,
Object
>
getGoalForActions
(
Long
id
){
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
Optional
<
Goal
>
goal
=
goalRepository
.
findById
(
id
);
if
(!
goal
.
isPresent
())
{
throw
new
NotFoundException
(
"Goal no se encuenta registrado"
);
}
List
<
Map
>
listAction
=
goalForActionService
.
getGoalForAction
(
id
);
if
(
listAction
.
isEmpty
())
{
throw
new
NotFoundException
(
"Actions no encontrados"
);
}
result
.
put
(
"AgentId"
,
goal
.
get
().
getAgenId
());
result
.
put
(
"Ident"
,
goal
.
get
().
getIdentifier
());
result
.
put
(
"actionList"
,
listAction
);
return
result
;
}
public
List
<
Map
>
getGoalForActionsAll
(){
List
<
Map
>
result
=
new
ArrayList
<>();
List
<
Goal
>
list
=
(
List
<
Goal
>)
goalRepository
.
findAll
();
for
(
Goal
goal:
list
)
{
result
.
add
(
getGoalForActions
(
goal
.
getId
()));
}
return
result
;
}
}
\ No newline at end of file
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