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
d07682b4
Commit
d07682b4
authored
Nov 26, 2021
by
jgomez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SchedulerTask
Creaciòn de Bean, Controller, Service y Repository
parent
7274ba0a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
248 additions
and
0 deletions
+248
-0
SchedulerTaskBean.java
src/main/java/com/bytesw/bytebot/bean/SchedulerTaskBean.java
+29
-0
SchedulerTaskController.java
...om/bytesw/bytebot/controller/SchedulerTaskController.java
+78
-0
SchedulerTask.java
src/main/java/com/bytesw/bytebot/model/SchedulerTask.java
+55
-0
SchedulerTaskRepository.java
...om/bytesw/bytebot/repository/SchedulerTaskRepository.java
+17
-0
SchedulerTaskService.java
...java/com/bytesw/bytebot/service/SchedulerTaskService.java
+69
-0
No files found.
src/main/java/com/bytesw/bytebot/bean/SchedulerTaskBean.java
0 → 100644
View file @
d07682b4
package
com
.
bytesw
.
bytebot
.
bean
;
import
com.google.gson.annotations.Expose
;
import
lombok.Getter
;
import
lombok.Setter
;
import
java.io.Serializable
;
import
java.math.BigInteger
;
@Getter
@Setter
public
class
SchedulerTaskBean
implements
Serializable
{
@Expose
private
BigInteger
id
;
@Expose
long
version
;
@Expose
String
description
;
@Expose
String
internals
;
@Expose
String
cronExpression
;
@Expose
String
stringParameters
;
@Expose
String
calendar
;
@Expose
String
calendarName
;
}
src/main/java/com/bytesw/bytebot/controller/SchedulerTaskController.java
0 → 100644
View file @
d07682b4
package
com
.
bytesw
.
bytebot
.
controller
;
import
com.bytesw.bytebot.bean.SchedulerTaskBean
;
import
com.bytesw.bytebot.service.SchedulerTaskService
;
import
com.bytesw.xdf.annotation.ProgramSecurity
;
import
com.bytesw.xdf.controller.XDFController
;
import
com.bytesw.xdf.sql.beans.Pagination
;
import
io.swagger.annotations.ApiResponse
;
import
io.swagger.annotations.ApiResponses
;
import
lombok.extern.log4j.Log4j2
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.*
;
import
java.math.BigInteger
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Objects
;
@RestController
()
@RequestMapping
(
"/service/scheduler-task"
)
@ProgramSecurity
(
"scheduler"
)
@Log4j2
public
class
SchedulerTaskController
extends
XDFController
<
SchedulerTaskBean
,
BigInteger
>
{
public
SchedulerTaskController
(
SchedulerTaskService
service
)
{
super
(
service
);
}
@ApiResponses
({
@ApiResponse
(
code
=
200
,
message
=
"Success"
,
response
=
ResponseEntity
.
class
),
@ApiResponse
(
code
=
505
,
message
=
"Internal Server Error"
)})
@RequestMapping
(
method
=
{
RequestMethod
.
POST
},
value
=
{
"/page"
}
)
@ResponseBody
@Override
@PreAuthorize
(
"hasPermission(this, 'view')"
)
public
ResponseEntity
<
String
>
findAllByPagination
(
@RequestBody
Pagination
<
SchedulerTaskBean
>
pagination
)
{
if
(!
Objects
.
isNull
(
pagination
.
getFilterExpression
())
&&
!
pagination
.
getFilterExpression
().
isEmpty
())
{
String
filterExpression
=
pagination
.
getFilterExpression
();
if
(
filterExpression
.
contains
(
"(internals==Y)"
))
{
filterExpression
=
filterExpression
.
replace
(
"(internals==Y)"
,
"(internals==true)"
);
}
if
(
filterExpression
.
contains
(
"calendarName"
))
{
filterExpression
=
filterExpression
.
replace
(
"calendarName"
,
"calendar.name"
);
}
pagination
.
setFilterExpression
(
filterExpression
);
}
this
.
service
.
searchByPagination
(
pagination
);
return
new
ResponseEntity
(
this
.
gson
.
toJson
(
pagination
),
HttpStatus
.
OK
);
}
@ApiResponses
({
@ApiResponse
(
code
=
200
,
message
=
"Success"
,
response
=
ResponseEntity
.
class
),
@ApiResponse
(
code
=
505
,
message
=
"Internal Server Error"
)})
@RequestMapping
(
method
=
{
RequestMethod
.
GET
},
value
=
{
"/initial-data"
}
)
@ResponseBody
@PreAuthorize
(
"hasPermission(this, 'view')"
)
public
ResponseEntity
<
String
>
getInitialData
()
{
Map
<
String
,
List
>
initialData
=
((
SchedulerTaskService
)
this
.
service
).
getInitialData
();
return
new
ResponseEntity
(
this
.
gson
.
toJson
(
initialData
),
HttpStatus
.
OK
);
}
}
src/main/java/com/bytesw/bytebot/model/SchedulerTask.java
0 → 100644
View file @
d07682b4
package
com
.
bytesw
.
bytebot
.
model
;
import
com.bytesw.xdf.model.converter.BooleanToStringConverter
;
import
lombok.EqualsAndHashCode
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.ToString
;
import
org.hibernate.envers.Audited
;
import
javax.persistence.*
;
import
java.io.Serializable
;
import
java.math.BigInteger
;
@Audited
@Entity
@Table
(
name
=
"GTW_SCHEDULER_TASK"
)
@NamedQuery
(
name
=
"SchedulerTasks.findByPK"
,
query
=
"Select u from SchedulerTask u where u.id = ?1"
)
@Getter
@Setter
@EqualsAndHashCode
@ToString
(
exclude
=
"id"
)
public
class
SchedulerTask
implements
Serializable
{
@Id
@Column
(
name
=
"SHTA_ID"
)
@SequenceGenerator
(
name
=
"GTW_SCHEDULER_TASK_GENERATOR"
,
sequenceName
=
"GTW_SCHEDULER_TASK_SEQ"
,
initialValue
=
1
,
allocationSize
=
1
)
@GeneratedValue
(
strategy
=
GenerationType
.
SEQUENCE
,
generator
=
"GTW_SCHEDULER_TASK_GENERATOR"
)
private
BigInteger
id
;
@Version
@Column
(
name
=
"VERSION"
)
@Basic
(
optional
=
false
)
private
long
version
;
@Column
(
name
=
"SHTA_DESCR"
,
nullable
=
false
)
private
String
description
;
@Column
(
name
=
"SHTA_INTER"
,
nullable
=
false
)
@Convert
(
converter
=
BooleanToStringConverter
.
class
)
private
Boolean
internals
;
@Column
(
name
=
"SHTA_CROEX"
,
nullable
=
false
)
private
String
cronExpression
;
@Column
(
name
=
"SHTA_PARAM"
)
private
String
stringParameters
;
// @ManyToOne(optional = false)
// @JoinColumn(name = "CALE_ID", referencedColumnName = "CALE_ID", nullable = false)
// private Calendar calendar;
@ManyToOne
(
optional
=
false
)
@JoinColumn
(
name
=
"CALE_ID"
,
referencedColumnName
=
"CALE_ID"
,
nullable
=
false
)
private
String
calendar
;
}
src/main/java/com/bytesw/bytebot/repository/SchedulerTaskRepository.java
0 → 100644
View file @
d07682b4
package
com
.
bytesw
.
bytebot
.
repository
;
import
com.bytesw.bytebot.model.SchedulerTask
;
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.math.BigInteger
;
import
java.util.List
;
import
java.util.Optional
;
public
interface
SchedulerTaskRepository
extends
CrudRepository
<
SchedulerTask
,
BigInteger
>,
JpaSpecificationExecutor
<
SchedulerTask
>
{
@Query
(
"select b from SchedulerTask b where b.calendar.id = :calendarId"
)
Optional
<
List
<
SchedulerTask
>>
findByCalendarId
(
@Param
(
"calendarId"
)
String
calendarId
);
}
src/main/java/com/bytesw/bytebot/service/SchedulerTaskService.java
0 → 100644
View file @
d07682b4
package
com
.
bytesw
.
bytebot
.
service
;
import
com.bytesw.bytebot.bean.SchedulerTaskBean
;
import
com.bytesw.bytebot.model.SchedulerTask
;
import
com.bytesw.bytebot.repository.SchedulerTaskRepository
;
import
com.bytesw.xdf.exception.NotFoundException
;
import
com.bytesw.xdf.service.XDFService
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.math.BigInteger
;
import
java.util.*
;
@Service
@Transactional
public
class
SchedulerTaskService
extends
XDFService
<
SchedulerTask
,
SchedulerTaskBean
,
BigInteger
>
{
// @Autowired
// private CalendarService calendarService;
// @Autowired
// private CalendarService CalendarService;
// @Autowired
// private CalendarRepository calendarRepository;
protected
SchedulerTaskService
(
SchedulerTaskRepository
repository
)
{
super
(
repository
);
}
@Override
protected
SchedulerTask
toModel
(
SchedulerTask
model
,
SchedulerTaskBean
bean
)
{
if
(
model
==
null
)
{
model
=
new
SchedulerTask
();
}
BeanUtils
.
copyProperties
(
bean
,
model
);
model
.
setInternals
(
"Y"
.
equals
(
bean
.
getInternals
()));
// Optional<Calendar> calendarOptional = calendarRepository.findById(bean.getCalendar());
// if (!calendarOptional.isPresent()) {
// throw new NotFoundException("Calendar not found " + bean.getCalendar());
// }
// model.setCalendar(calendarOptional.get());
model
.
setCalendar
(
"Mientras Se implementa Calendario en Backend"
);
return
model
;
}
@Override
protected
SchedulerTaskBean
toBean
(
SchedulerTask
model
)
{
SchedulerTaskBean
bean
=
new
SchedulerTaskBean
();
BeanUtils
.
copyProperties
(
model
,
bean
);
bean
.
setInternals
(
model
.
getInternals
().
booleanValue
()
?
"Y"
:
"N"
);
// bean.setCalendar(model.getCalendar().getId());
bean
.
setCalendar
(
model
.
getCalendar
());
// bean.setCalendarName(model.getCalendar().getName());
bean
.
setCalendarName
(
model
.
getCalendar
());
return
bean
;
}
public
Map
<
String
,
List
>
getInitialData
()
{
// List<CalendarBean> calendarBeanList = CalendarService.getAll();
List
<
String
>
calendarBeanList
=
new
ArrayList
<>();
calendarBeanList
.
add
(
"Hola Mundo"
);
Map
<
String
,
List
>
initialData
=
new
HashMap
<>();
initialData
.
put
(
"calendarList"
,
calendarBeanList
);
return
initialData
;
}
}
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