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
532d1d70
Commit
532d1d70
authored
Nov 26, 2021
by
Cristian Aguirre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Calendar
parent
dfca8e2e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
260 additions
and
0 deletions
+260
-0
CalendarBean.java
src/main/java/com/bytesw/bytebot/bean/CalendarBean.java
+24
-0
CalendarController.java
...ava/com/bytesw/bytebot/controller/CalendarController.java
+19
-0
Calendar.java
src/main/java/com/bytesw/bytebot/model/Calendar.java
+40
-0
CalendarRepository.java
...ava/com/bytesw/bytebot/repository/CalendarRepository.java
+8
-0
CalendarService.java
...main/java/com/bytesw/bytebot/service/CalendarService.java
+169
-0
No files found.
src/main/java/com/bytesw/bytebot/bean/CalendarBean.java
0 → 100644
View file @
532d1d70
package
com
.
bytesw
.
bytebot
.
bean
;
import
com.google.gson.annotations.Expose
;
import
lombok.Getter
;
import
lombok.Setter
;
import
java.io.Serializable
;
import
java.util.List
;
@Getter
@Setter
public
class
CalendarBean
implements
Serializable
{
@Expose
private
String
id
;
@Expose
private
long
version
;
@Expose
private
String
name
;
// @TODO: Revisar List<WeekScheduler> weekSchedulerList de la clase Calendar
// @Expose private List<WeekSchedulerBean> weekSchedulerBeanList;
// @Expose private List<CalendarExceptionBean> calendarExceptionBeanList;
@Expose
private
List
<
String
>
weekSchedulerBeanList
;
@Expose
private
List
<
String
>
calendarExceptionBeanList
;
}
\ No newline at end of file
src/main/java/com/bytesw/bytebot/controller/CalendarController.java
0 → 100644
View file @
532d1d70
package
com
.
bytesw
.
bytebot
.
controller
;
import
com.bytesw.bytebot.bean.CalendarBean
;
import
com.bytesw.xdf.annotation.ProgramSecurity
;
import
com.bytesw.xdf.controller.XDFController
;
import
com.bytesw.bytebot.service.CalendarService
;
import
lombok.extern.log4j.Log4j2
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
()
@RequestMapping
(
"/service/settings/calendar"
)
@ProgramSecurity
(
"CALENDAR"
)
@Log4j2
public
class
CalendarController
extends
XDFController
<
CalendarBean
,
String
>
{
public
CalendarController
(
CalendarService
service
)
{
super
(
service
);
}
}
src/main/java/com/bytesw/bytebot/model/Calendar.java
0 → 100644
View file @
532d1d70
package
com
.
bytesw
.
bytebot
.
model
;
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.util.List
;
@Audited
@Entity
@Table
(
name
=
"avb_calendar"
)
@NamedQuery
(
name
=
"Calendar.findByPK"
,
query
=
"Select u from Calendar u where u.id = ?1"
)
@Getter
@Setter
@EqualsAndHashCode
@ToString
(
exclude
=
"id"
)
public
class
Calendar
implements
Serializable
{
@Id
@Column
(
name
=
"cale_id"
)
private
String
id
;
@Version
@Column
(
name
=
"cale_version"
)
@Basic
(
optional
=
false
)
private
long
version
;
@Column
(
name
=
"cale_name"
,
nullable
=
false
)
private
String
name
;
// @OneToMany(mappedBy = "calendar")
// private List<WeekScheduler> weekSchedulerList;
@OneToMany
(
mappedBy
=
"calendar"
)
private
List
<
String
>
weekSchedulerList
;
}
src/main/java/com/bytesw/bytebot/repository/CalendarRepository.java
0 → 100644
View file @
532d1d70
package
com
.
bytesw
.
bytebot
.
repository
;
import
com.bytesw.bytebot.model.Calendar
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.data.repository.CrudRepository
;
public
interface
CalendarRepository
extends
CrudRepository
<
Calendar
,
String
>,
JpaSpecificationExecutor
<
Calendar
>
{
}
\ No newline at end of file
src/main/java/com/bytesw/bytebot/service/CalendarService.java
0 → 100644
View file @
532d1d70
package
com
.
bytesw
.
bytebot
.
service
;
import
com.bytesw.bytebot.bean.CalendarBean
;
import
com.bytesw.bytebot.model.Calendar
;
import
com.bytesw.bytebot.repository.CalendarRepository
;
import
com.bytesw.xdf.exception.AlreadyExistsException
;
import
com.bytesw.xdf.exception.NotFoundException
;
import
com.bytesw.xdf.exception.ReferentialIntegrityException
;
import
com.bytesw.xdf.service.XDFService
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
javax.transaction.Transactional
;
import
java.util.Optional
;
@Service
@Transactional
public
class
CalendarService
extends
XDFService
<
Calendar
,
CalendarBean
,
String
>
{
@Autowired
private
WeekSchedulerService
weekSchedulerService
;
@Autowired
private
WeekSchedulerRepository
weekSchedulerRepository
;
@Autowired
private
SchedulerTaskRepository
schedulerTaskRepository
;
@Autowired
private
CalendarExceptionRepository
calendarExceptionRepository
;
@Autowired
private
CalendarRepository
calendarRepository
;
@Autowired
private
CalendarExceptionService
calendarExceptionService
;
protected
CalendarService
(
CalendarRepository
repository
)
{
super
(
repository
);
}
@Override
protected
Calendar
toModel
(
Calendar
model
,
CalendarBean
bean
)
{
if
(
model
==
null
)
{
model
=
new
Calendar
();
}
BeanUtils
.
copyProperties
(
bean
,
model
);
return
model
;
}
@Override
protected
CalendarBean
toBean
(
Calendar
model
)
{
CalendarBean
bean
=
new
CalendarBean
();
BeanUtils
.
copyProperties
(
model
,
bean
);
bean
.
setWeekSchedulerBeanList
(
this
.
weekSchedulerService
.
getWeekSchedulerByCalId
(
model
.
getId
()));
return
bean
;
}
@Override
public
void
delete
(
String
id
)
{
Optional
<
Calendar
>
found
=
this
.
calendarRepository
.
findById
(
id
);
if
(!
found
.
isPresent
())
{
throw
new
NotFoundException
();
}
Optional
<
List
<
SchedulerTask
>>
schedulerTaskList
=
this
.
schedulerTaskRepository
.
findByCalendarId
(
id
);
if
(
schedulerTaskList
.
isPresent
())
{
throw
new
ReferentialIntegrityException
(
"CALENDAR_EXCEPTION_DELETE_SCHEDULER_TASK"
);
}
Optional
<
List
<
CalendarException
>>
calendarExceptionList
=
this
.
calendarExceptionRepository
.
findByCalendarId
(
id
);
calendarExceptionList
.
ifPresent
(
list
->
this
.
calendarExceptionRepository
.
deleteAll
(
list
));
Optional
<
List
<
WeekScheduler
>>
weekSchedulerList
=
this
.
weekSchedulerRepository
.
findByCalendarId
(
id
);
weekSchedulerList
.
ifPresent
(
list
->
this
.
weekSchedulerRepository
.
deleteAll
(
list
));
this
.
calendarRepository
.
delete
(
found
.
get
());
}
@Override
public
CalendarBean
create
(
CalendarBean
bean
)
{
if
(
this
.
calendarRepository
.
existsById
(
bean
.
getId
()))
{
throw
new
AlreadyExistsException
(
"errors.form.duplicated.id"
);
}
Calendar
model
=
new
Calendar
();
model
=
this
.
calendarRepository
.
save
(
this
.
toModel
(
model
,
bean
));
saveWeekScheduler
(
bean
,
model
);
saveCalendarException
(
bean
,
model
);
return
this
.
toBean
(
model
);
}
@Override
public
CalendarBean
update
(
CalendarBean
bean
,
String
id
)
{
Optional
<
Calendar
>
found
=
this
.
calendarRepository
.
findById
(
id
);
if
(!
found
.
isPresent
())
{
throw
new
NotFoundException
();
}
Calendar
calendar
=
this
.
toModel
(
found
.
get
(),
bean
);
BeanUtils
.
copyProperties
(
calendar
,
found
.
get
());
calendar
=
this
.
calendarRepository
.
save
(
found
.
get
());
saveWeekScheduler
(
bean
,
calendar
);
saveCalendarException
(
bean
,
calendar
);
return
this
.
toBean
(
calendar
);
}
private
void
saveWeekScheduler
(
CalendarBean
bean
,
Calendar
calendar
)
{
List
<
WeekSchedulerBean
>
weekSchedulerBeanList
=
bean
.
getWeekSchedulerBeanList
();
for
(
WeekSchedulerBean
weekSchedulerBean
:
weekSchedulerBeanList
)
{
WeekScheduler
weekScheduler
;
boolean
delete
=
weekSchedulerBean
.
getFrom
()
==
null
;
if
(
weekSchedulerBean
.
getId
()
!=
null
)
{
Optional
<
WeekScheduler
>
weekSchedulerOptional
=
this
.
weekSchedulerRepository
.
findById
(
weekSchedulerBean
.
getId
());
if
(
weekSchedulerOptional
.
isPresent
())
{
if
(
delete
){
this
.
weekSchedulerRepository
.
delete
(
weekSchedulerOptional
.
get
());
continue
;
}
weekScheduler
=
weekSchedulerOptional
.
get
();
}
else
{
weekScheduler
=
new
WeekScheduler
();
weekScheduler
.
setDayOfWeek
(
weekSchedulerBean
.
getDayOfWeek
());
}
weekScheduler
.
setCalendar
(
calendar
);
weekScheduler
.
setFrom
(
weekSchedulerBean
.
getFrom
());
weekScheduler
.
setTo
(
weekSchedulerBean
.
getTo
());
this
.
weekSchedulerRepository
.
save
(
weekScheduler
);
}
else
if
(!
delete
)
{
weekScheduler
=
new
WeekScheduler
();
weekScheduler
.
setCalendar
(
calendar
);
weekScheduler
.
setDayOfWeek
(
weekSchedulerBean
.
getDayOfWeek
());
weekScheduler
.
setFrom
(
weekSchedulerBean
.
getFrom
());
weekScheduler
.
setTo
(
weekSchedulerBean
.
getTo
());
this
.
weekSchedulerRepository
.
save
(
weekScheduler
);
}
}
}
private
void
saveCalendarException
(
CalendarBean
bean
,
Calendar
calendar
)
{
List
<
CalendarExceptionBean
>
calendarExceptionBeanList
=
bean
.
getCalendarExceptionBeanList
();
CalendarException
calendarException
=
null
;
for
(
CalendarExceptionBean
calendarExceptionBean
:
calendarExceptionBeanList
)
{
if
(
calendarExceptionBean
.
getId
()
!=
null
)
{
Optional
<
CalendarException
>
calendarExceptionOptional
=
calendarExceptionRepository
.
findById
(
calendarExceptionBean
.
getId
());
if
(
calendarExceptionBean
.
isDelete
())
{
calendarExceptionRepository
.
delete
(
calendarExceptionOptional
.
get
());
continue
;
}
// modificar
if
(!
calendarExceptionOptional
.
get
().
getFrequencyType
().
equals
(
calendarExceptionBean
.
getFrequencyType
()))
{
calendarExceptionRepository
.
delete
(
calendarExceptionOptional
.
get
());
}
else
{
calendarExceptionBean
.
setCalendar
(
bean
);
calendarException
=
calendarExceptionService
.
toModel
(
calendarExceptionOptional
.
get
(),
calendarExceptionBean
);
calendarExceptionRepository
.
save
(
calendarException
);
continue
;
}
}
// Nueva excepción
calendarException
=
calendarExceptionService
.
getCalendarException
(
calendarExceptionBean
);
calendarExceptionBean
.
setCalendar
(
bean
);
calendarException
=
calendarExceptionService
.
toModel
(
calendarException
,
calendarExceptionBean
);
calendarException
.
setCalendar
(
calendar
);
calendarExceptionRepository
.
save
(
calendarException
);
}
}
}
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