Commit a577f209 authored by jgomez's avatar jgomez

SchedulerTask, calendar, calendarExeption

Correccion de dependencias.
parent d07682b4
......@@ -13,12 +13,15 @@ import java.util.List;
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 long version;
@Expose
private String name;
//@TODO: Revisar List<WeekScheduler> weekSchedulerList de la clase Calendar
@Expose private List<String> weekSchedulerBeanList;
@Expose private List<String> calendarExceptionBeanList;
@Expose
private List<WeekSchedulerBean> weekSchedulerBeanList;
@Expose
private List<CalendarExceptionBean> calendarExceptionBeanList;
}
\ No newline at end of file
......@@ -13,23 +13,38 @@ import java.time.OffsetDateTime;
public class CalendarExceptionBean {
@Expose
private BigInteger id;
@Expose private long version;
@Expose private String description;
//@Expose private CalendarBean calendar;
@Expose private String calendar;
@Expose private String calendarExceptionType;
@Expose
private long version;
@Expose
private String description;
@Expose
private CalendarBean calendar;
@Expose
private String calendarExceptionType;
//Frecuencia
@Expose private String frequencyType;
@Expose
private String frequencyType;
//annualCalendar y UniqueWeekly
@Expose private int month;
@Expose private int dayOfMonth;
@Expose private int weekOfMonth;
@Expose private int dayOfWeek;
@Expose
private int month;
@Expose
private int dayOfMonth;
@Expose
private int weekOfMonth;
@Expose
private int dayOfWeek;
//UniqueCalendar
@Expose private LocalDate date;
//rangeCalendar
@Expose private OffsetDateTime from;
@Expose private OffsetDateTime to;
@Expose private boolean delete;
@Expose
private LocalDate date;
//rangeCalendar
@Expose
private OffsetDateTime from;
@Expose
private OffsetDateTime to;
@Expose
private boolean delete;
}
......@@ -12,10 +12,15 @@ import java.time.OffsetTime;
public class WeekSchedulerBean {
@Expose
private BigInteger id;
@Expose private long version;
@Expose private int dayOfWeek;
@Expose private OffsetTime from;
@Expose private OffsetTime to;
//@Expose private CalendarBean calendar;
@Expose private String calendar;
@Expose
private long version;
@Expose
private int dayOfWeek;
@Expose
private OffsetTime from;
@Expose
private OffsetTime to;
@Expose
private CalendarBean calendar;
}
......@@ -32,9 +32,7 @@ public class Calendar implements Serializable {
@Column(name = "cale_name", nullable = false)
private String name;
// @OneToMany(mappedBy = "calendar")
// private List<WeekScheduler> weekSchedulerList;
@OneToMany(mappedBy = "calendar")
private List<String> weekSchedulerList;
private List<WeekScheduler> weekSchedulerList;
}
package com.bytesw.bytebot.model;
import com.bytesw.bytebot.model.converters.CalendarExceptionTypeConverter;
import com.bytesw.bytebot.model.enums.CalendarExceptionType;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
......@@ -35,9 +37,8 @@ public abstract class CalendarException implements Serializable {
private long version;
@Column(name = "CALE_EXC_TYPE")
//@Convert(converter = CalendarExceptionTypeConverter.class)
//private CalendarExceptionType calendarExceptionType;
private String calendarExceptionType;
@Convert(converter = CalendarExceptionTypeConverter.class)
private CalendarExceptionType calendarExceptionType;
@Column(name = "CALE_EXC_FRECU", insertable = false, updatable = false)
private String frequencyType;
......@@ -47,6 +48,6 @@ public abstract class CalendarException implements Serializable {
@ManyToOne(optional = false)
@JoinColumn(name = "CALE_ID", referencedColumnName = "CALE_ID", nullable = false)
//private Calendar calendar;
private String calendar;
private Calendar calendar;
}
\ No newline at end of file
......@@ -45,11 +45,8 @@ public class SchedulerTask implements Serializable {
@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;
private Calendar calendar;
}
......@@ -43,7 +43,6 @@ public class WeekScheduler implements Serializable {
@ManyToOne(optional = false)
@JoinColumn(name = "CALE_ID", referencedColumnName = "CALE_ID", nullable = false)
//private Calendar calendar;
private String calendar;
private Calendar calendar;
}
package com.bytesw.bytebot.model.converters;
import com.bytesw.bytebot.model.enums.CalendarExceptionType;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
/**
* @author Renzo Carranza
* @version 26/08/2021
* <p>
* Copyright (c) 2019 Byte, S.A. Todos los derechos reservados.
* <p>
* Este software constituye información confidencial y propietaria de Byte, S.A.
* ("Información Confidencial"). Usted no debe develar dicha Información
* Confidencial y debe usarla de acuerdo con los términos de aceptación de
* licencia de uso que firmó con Byte.
*/
@Converter
public class CalendarExceptionTypeConverter implements AttributeConverter<CalendarExceptionType, String> {
@Override
public String convertToDatabaseColumn(CalendarExceptionType calendarExceptionType) {
if (calendarExceptionType == null) return null;
return calendarExceptionType.getName();
}
@Override
public CalendarExceptionType convertToEntityAttribute(String s) {
return CalendarExceptionType.fromString(s);
}
}
package com.bytesw.bytebot.repository;
import com.bytesw.bytebot.model.CalendarException;
import com.bytesw.bytebot.model.enums.CalendarExceptionType;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
......@@ -13,7 +14,8 @@ import java.util.List;
import java.util.Optional;
public interface CalendarExceptionRepository extends CrudRepository<CalendarException, BigInteger>, JpaSpecificationExecutor<CalendarException> {
/*@Query("select s from RangeCalendarException s where s.calendar.id = :calendarId and s.from < :date and s.to > :date and s.calendarExceptionType = :type")
@Query("select s from RangeCalendarException s where s.calendar.id = :calendarId and s.from < :date and s.to > :date and s.calendarExceptionType = :type")
Optional<CalendarException> findByRangeExceptionByCalendarIdAndDateAndType(@Param("calendarId") String calendarId, @Param("date") OffsetDateTime date, @Param("type") CalendarExceptionType type);
@Query("select s from AnnualCalendarException s where s.calendar.id = :calendarId and s.month = :month and s.dayOfMonth = :dayOfMonth")
......@@ -29,6 +31,6 @@ public interface CalendarExceptionRepository extends CrudRepository<CalendarExce
Optional<CalendarException> findByRangeExceptionByCalendarIdFromDateAndType(@Param("calendarId") String calendarId, @Param("date") OffsetDateTime date, @Param("type") CalendarExceptionType type);
@Query("select s from CalendarException s where s.calendar.id = :calendarId")
Optional<List<CalendarException>> findByCalendarId(@Param("calendarId") String calendarId);*/
Optional<List<CalendarException>> findByCalendarId(@Param("calendarId") String calendarId);
}
......@@ -11,6 +11,6 @@ import java.util.List;
import java.util.Optional;
public interface WeekSchedulerRepository extends CrudRepository<WeekScheduler, BigInteger>, JpaSpecificationExecutor<WeekScheduler> {
//@Query("select b from WeekScheduler b where b.calendar.id = :caleId")
//Optional<List<WeekScheduler>> findByCalendarId(@Param("caleId") String caleId);
@Query("select b from WeekScheduler b where b.calendar.id = :caleId")
Optional<List<WeekScheduler>> findByCalendarId(@Param("caleId") String caleId);
}
......@@ -2,8 +2,10 @@ package com.bytesw.bytebot.service;
import com.bytesw.bytebot.bean.CalendarExceptionBean;
import com.bytesw.bytebot.model.*;
import com.bytesw.bytebot.model.Calendar;
import com.bytesw.bytebot.model.enums.CalendarExceptionType;
import com.bytesw.bytebot.repository.CalendarExceptionRepository;
import com.bytesw.bytebot.repository.CalendarRepository;
import com.bytesw.xdf.dao.rsql.CustomRsqlVisitor;
import com.bytesw.xdf.exception.NotFoundException;
import com.bytesw.xdf.service.XDFService;
......@@ -23,18 +25,15 @@ import java.util.*;
@Transactional
public class CalendarExceptionService extends XDFService<CalendarException, CalendarExceptionBean, BigInteger> {
//@Autowired
//CalendarRepository calendarRepository;
@Autowired
CalendarRepository calendarRepository;
//@Autowired
//CalendarService gatewayCalendarService;
@Autowired
CalendarService calendarService;
@Autowired
CalendarExceptionRepository calendarExceptionRepository;
//@Autowired
//BusinessFlowService businessFlowService;
protected CalendarExceptionService(CalendarExceptionRepository repository) {
super(repository);
}
......@@ -49,7 +48,7 @@ public class CalendarExceptionService extends XDFService<CalendarException, Cale
if (bean.getCalendar() == null) {
throw new NotFoundException("Calendar can not be null");
}
Optional<Calendar> calendarOptional = calendarRepository.findById(bean.getCalendar().getId());
Optional<Calendar> calendarOptional = this.calendarRepository.findById(bean.getCalendar().getId());
if (!calendarOptional.isPresent()) {
throw new NotFoundException("Calendar not found " + bean.getCalendar().getId());
}
......@@ -86,7 +85,6 @@ public class CalendarExceptionService extends XDFService<CalendarException, Cale
CalendarExceptionBean bean = new CalendarExceptionBean();
BeanUtils.copyProperties(model, bean);
bean.setCalendar(this.calendarService.toBean(model.getCalendar()));
bean.setCalendarExceptionType(model.getCalendarExceptionType().getName());
bean.setFrequencyType(model.getFrequencyType());
return bean;
......
package com.bytesw.bytebot.service;
import com.bytesw.bytebot.bean.CalendarBean;
import com.bytesw.bytebot.bean.CalendarExceptionBean;
import com.bytesw.bytebot.bean.WeekSchedulerBean;
import com.bytesw.bytebot.model.Calendar;
import com.bytesw.bytebot.model.CalendarException;
import com.bytesw.bytebot.model.SchedulerTask;
import com.bytesw.bytebot.model.WeekScheduler;
import com.bytesw.bytebot.repository.CalendarExceptionRepository;
import com.bytesw.bytebot.repository.CalendarRepository;
import com.bytesw.bytebot.repository.SchedulerTaskRepository;
import com.bytesw.bytebot.repository.WeekSchedulerRepository;
import com.bytesw.xdf.exception.AlreadyExistsException;
import com.bytesw.xdf.exception.NotFoundException;
import com.bytesw.xdf.exception.ReferentialIntegrityException;
......@@ -12,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.List;
import java.util.Optional;
@Service
......@@ -20,15 +29,19 @@ 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;
......@@ -76,7 +89,7 @@ public class CalendarService extends XDFService<Calendar, CalendarBean, String>
@Override
public CalendarBean create(CalendarBean bean) {
if( this.calendarRepository.existsById(bean.getId())) {
if (this.calendarRepository.existsById(bean.getId())) {
throw new AlreadyExistsException("errors.form.duplicated.id");
}
Calendar model = new Calendar();
......@@ -109,7 +122,7 @@ public class CalendarService extends XDFService<Calendar, CalendarBean, String>
if (weekSchedulerBean.getId() != null) {
Optional<WeekScheduler> weekSchedulerOptional = this.weekSchedulerRepository.findById(weekSchedulerBean.getId());
if (weekSchedulerOptional.isPresent()) {
if(delete){
if (delete) {
this.weekSchedulerRepository.delete(weekSchedulerOptional.get());
continue;
}
......@@ -157,6 +170,7 @@ public class CalendarService extends XDFService<Calendar, CalendarBean, String>
}
}
// Nueva excepción
calendarException = calendarExceptionService.getCalendarException(calendarExceptionBean);
calendarExceptionBean.setCalendar(bean);
......
package com.bytesw.bytebot.service;
import com.bytesw.bytebot.bean.CalendarBean;
import com.bytesw.bytebot.bean.SchedulerTaskBean;
import com.bytesw.bytebot.model.Calendar;
import com.bytesw.bytebot.model.SchedulerTask;
import com.bytesw.bytebot.repository.CalendarRepository;
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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -16,12 +20,14 @@ import java.util.*;
@Transactional
public class SchedulerTaskService extends XDFService<SchedulerTask, SchedulerTaskBean, BigInteger> {
// @Autowired
// private CalendarService calendarService;
// @Autowired
// private CalendarService CalendarService;
// @Autowired
// private CalendarRepository calendarRepository;
@Autowired
private CalendarService calendarService;
@Autowired
private CalendarService CalendarService;
@Autowired
private CalendarRepository calendarRepository;
protected SchedulerTaskService(SchedulerTaskRepository repository) {
super(repository);
......@@ -35,14 +41,14 @@ public class SchedulerTaskService extends XDFService<SchedulerTask, SchedulerTas
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");
if (bean.getCalendar() == null) {
throw new NotFoundException("Calendar can not be null");
}
Optional<Calendar> calendarOptional = this.calendarRepository.findById(bean.getCalendar());
if (!calendarOptional.isPresent()) {
throw new NotFoundException("Calendar not found " + bean.getCalendar());
}
model.setCalendar(calendarOptional.get());
return model;
}
......@@ -51,17 +57,13 @@ public class SchedulerTaskService extends XDFService<SchedulerTask, SchedulerTas
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());
bean.setCalendar(model.getCalendar().getId());
bean.setCalendarName(model.getCalendar().getName());
return bean;
}
public Map<String, List> getInitialData() {
// List<CalendarBean> calendarBeanList = CalendarService.getAll();
List<String> calendarBeanList = new ArrayList<>();
calendarBeanList.add("Hola Mundo");
List<CalendarBean> calendarBeanList = this.CalendarService.getAll();
Map<String, List> initialData = new HashMap<>();
initialData.put("calendarList", calendarBeanList);
return initialData;
......
package com.bytesw.bytebot.service;
import com.bytesw.bytebot.bean.WeekSchedulerBean;
import com.bytesw.bytebot.model.Calendar;
import com.bytesw.bytebot.model.WeekScheduler;
import com.bytesw.bytebot.repository.CalendarRepository;
import com.bytesw.bytebot.repository.WeekSchedulerRepository;
import com.bytesw.xdf.exception.NotFoundException;
import com.bytesw.xdf.service.XDFService;
......@@ -46,17 +48,17 @@ public class WeekSchedulerService extends XDFService<WeekScheduler, WeekSchedule
return model;
}
// @Override
// protected WeekSchedulerBean toBean(WeekScheduler model) {
// WeekSchedulerBean bean = new WeekSchedulerBean();
// BeanUtils.copyProperties(model, bean);
// bean.setCalendar(gatewayCalendarService.toBean(model.getCalendar()));
// return bean;
// }
@Override
protected WeekSchedulerBean toBean(WeekScheduler model) {
WeekSchedulerBean bean = new WeekSchedulerBean();
BeanUtils.copyProperties(model, bean);
bean.setCalendar(calendarService.toBean(model.getCalendar()));
return bean;
}
public List<WeekSchedulerBean> getWeekSchedulerByCalId(String caleID) {
List<WeekSchedulerBean> weekSchedulerBeanList = new ArrayList<>(7);
Optional<List<WeekScheduler>> weekSchedulerOptional = weekSchedulerRepository.findByCalendarId(caleID);
Optional<List<WeekScheduler>> weekSchedulerOptional = this.weekSchedulerRepository.findByCalendarId(caleID);
if (!weekSchedulerOptional.isPresent()) {
for (int i = 0; i < 7; i++) {
weekSchedulerBeanList.add(i, new WeekSchedulerBean());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment