Commit 29d37eb7 authored by jgomez's avatar jgomez

WeekScheduler

Correccion en recuperacion de Calendar asociado
parent cf1a0441
......@@ -13,17 +13,17 @@ public class SchedulerTaskBean implements Serializable {
@Expose
private BigInteger id;
@Expose
long version;
private long version;
@Expose
String description;
private String description;
@Expose
String internals;
private String internals;
@Expose
String cronExpression;
private String cronExpression;
@Expose
String stringParameters;
private String stringParameters;
@Expose
String calendarID;
private String calendarID;
@Expose
String calendarName;
private String calendarName;
}
......@@ -21,6 +21,7 @@ public class WeekSchedulerBean {
@Expose
private OffsetTime to;
@Expose
private CalendarBean calendar;
private String calendarID;
@Expose
private String calendarName;
}
......@@ -4,6 +4,8 @@ import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.envers.Audited;
import javax.persistence.*;
......@@ -41,7 +43,11 @@ public class WeekScheduler implements Serializable {
@Column(name = "WESC_TO", nullable = false)
private OffsetTime to;
@Column(name = "CALE_ID")
private String calendarID;
@ManyToOne(optional = false)
@NotFound(action = NotFoundAction.IGNORE)
@JoinColumn(name = "CALE_ID", referencedColumnName = "CALE_ID", nullable = false)
private Calendar calendar;
......
......@@ -11,6 +11,7 @@ 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")
@Query("select b from WeekScheduler b where b.calendarID = :caleId")
Optional<List<WeekScheduler>> findByCalendarId(@Param("caleId") String caleId);
}
......@@ -62,7 +62,7 @@ public class CalendarService extends XDFService<Calendar, CalendarBean, String>
protected CalendarBean toBean(Calendar model) {
CalendarBean bean = new CalendarBean();
BeanUtils.copyProperties(model, bean);
//bean.setWeekSchedulerBeanList(this.weekSchedulerService.getWeekSchedulerByCalId(model.getId()));
bean.setWeekSchedulerBeanList(this.weekSchedulerService.getWeekSchedulerByCalId(model.getId()));
return bean;
}
......
package com.bytesw.bytebot.service;
import com.bytesw.bytebot.bean.CalendarBean;
import com.bytesw.bytebot.bean.WeekSchedulerBean;
import com.bytesw.bytebot.model.Calendar;
import com.bytesw.bytebot.model.WeekScheduler;
......@@ -22,11 +23,16 @@ import java.util.Optional;
public class WeekSchedulerService extends XDFService<WeekScheduler, WeekSchedulerBean, BigInteger> {
@Autowired
private WeekSchedulerRepository weekSchedulerRepository;
@Autowired
private CalendarService calendarService;
@Autowired
private CalendarRepository calendarRepository;
@Autowired
private CalendarService CalendarService;
protected WeekSchedulerService(WeekSchedulerRepository repository) {
super(repository);
}
......@@ -37,13 +43,16 @@ public class WeekSchedulerService extends XDFService<WeekScheduler, WeekSchedule
model = new WeekScheduler();
}
BeanUtils.copyProperties(bean, model);
if (bean.getCalendar() == null) {
if (bean.getCalendarID() == null) {
throw new NotFoundException("Calendar can not be null");
}
Optional<Calendar> calendarOptional = calendarRepository.findById(bean.getCalendar().getId());
Optional<Calendar> calendarOptional = calendarRepository.findById(bean.getCalendarID().trim());
if (!calendarOptional.isPresent()) {
throw new NotFoundException("Calendar not found " + bean.getCalendar().getId());
throw new NotFoundException("Calendar not found " + bean.getCalendarID());
}
model.setCalendar(calendarOptional.get());
return model;
}
......@@ -52,13 +61,20 @@ public class WeekSchedulerService extends XDFService<WeekScheduler, WeekSchedule
protected WeekSchedulerBean toBean(WeekScheduler model) {
WeekSchedulerBean bean = new WeekSchedulerBean();
BeanUtils.copyProperties(model, bean);
bean.setCalendar(calendarService.toBean(model.getCalendar()));
bean.setCalendarID(model.getCalendarID());
CalendarBean found = this.CalendarService.getById(bean.getCalendarID().trim());
if(found != null){
bean.setCalendarName(found.getName());
}
return bean;
}
public List<WeekSchedulerBean> getWeekSchedulerByCalId(String caleID) {
List<WeekSchedulerBean> weekSchedulerBeanList = new ArrayList<>(7);
Optional<List<WeekScheduler>> weekSchedulerOptional = this.weekSchedulerRepository.findByCalendarId(caleID);
Optional<List<WeekScheduler>> weekSchedulerOptional = this.weekSchedulerRepository.findByCalendarId(caleID.trim());
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