Commit 0f3e3745 authored by Roberto Loayza's avatar Roberto Loayza

Merge remote-tracking branch 'origin/dev_mg' into dev_mg

parents 1ed2b328 c001f3e9
...@@ -13,17 +13,17 @@ public class SchedulerTaskBean implements Serializable { ...@@ -13,17 +13,17 @@ public class SchedulerTaskBean implements Serializable {
@Expose @Expose
private BigInteger id; private BigInteger id;
@Expose @Expose
long version; private long version;
@Expose @Expose
String description; private String description;
@Expose @Expose
String internals; private String internals;
@Expose @Expose
String cronExpression; private String cronExpression;
@Expose @Expose
String stringParameters; private String stringParameters;
@Expose @Expose
String calendar; private String calendarID;
@Expose @Expose
String calendarName; private String calendarName;
} }
...@@ -21,6 +21,7 @@ public class WeekSchedulerBean { ...@@ -21,6 +21,7 @@ public class WeekSchedulerBean {
@Expose @Expose
private OffsetTime to; private OffsetTime to;
@Expose @Expose
private CalendarBean calendar; private String calendarID;
@Expose
private String calendarName;
} }
package com.bytesw.bytebot.controller;
import com.bytesw.bytebot.bean.CalendarExceptionBean;
import com.bytesw.bytebot.service.CalendarExceptionService;
import com.bytesw.xdf.annotation.ProgramSecurity;
import com.bytesw.xdf.controller.XDFController;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.math.BigInteger;
import java.util.List;
import java.util.Map;
@RestController()
@RequestMapping("/calendar-exception")
@ProgramSecurity("calendar-exception")
@Log4j2
public class CalendarExceptionController extends XDFController<CalendarExceptionBean, BigInteger> {
@Autowired
CalendarExceptionService service;
public CalendarExceptionController(CalendarExceptionService service) {
super(service);
}
@ApiResponses({@ApiResponse(
code = 200,
message = "Success",
response = ResponseEntity.class
), @ApiResponse(
code = 404,
message = "Not Found"
), @ApiResponse(
code = 505,
message = "Internal Server Error"
)})
@RequestMapping(
value = {"/find-by-calendar-id"},
method = {RequestMethod.POST}
)
@ResponseBody
@PreAuthorize("hasPermission(this, 'view')")
public ResponseEntity<String> getCalendarExceptionbyID(@RequestBody Map<String, String> parametersCalendar, HttpServletRequest req) {
List<CalendarExceptionBean> calendarExceptionBeanList = this.service.getCalendarExceptionbyID(parametersCalendar);
return new ResponseEntity(this.gson.toJson(calendarExceptionBeanList), HttpStatus.OK);
}
}
...@@ -12,7 +12,7 @@ import java.util.List; ...@@ -12,7 +12,7 @@ import java.util.List;
@Audited @Audited
@Entity @Entity
@Table(name = "avb_calendar") @Table(name = "AVB_CALENDAR")
@NamedQuery(name = "Calendar.findByPK", query = "Select u from Calendar u where u.id = ?1") @NamedQuery(name = "Calendar.findByPK", query = "Select u from Calendar u where u.id = ?1")
@Getter @Getter
@Setter @Setter
......
...@@ -17,7 +17,7 @@ import java.math.BigInteger; ...@@ -17,7 +17,7 @@ import java.math.BigInteger;
@Inheritance( @Inheritance(
strategy = InheritanceType.SINGLE_TABLE strategy = InheritanceType.SINGLE_TABLE
) )
@DiscriminatorColumn(name="CAEX_FRECU", discriminatorType = DiscriminatorType.STRING) @DiscriminatorColumn(name="CALE_EXC_FRECU", discriminatorType = DiscriminatorType.STRING)
@Table(name = "AVB_CALENDAR_EXCEPTION") @Table(name = "AVB_CALENDAR_EXCEPTION")
@Getter @Getter
@Setter @Setter
......
...@@ -5,6 +5,8 @@ import lombok.EqualsAndHashCode; ...@@ -5,6 +5,8 @@ import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.envers.Audited; import org.hibernate.envers.Audited;
import javax.persistence.*; import javax.persistence.*;
...@@ -13,8 +15,8 @@ import java.math.BigInteger; ...@@ -13,8 +15,8 @@ import java.math.BigInteger;
@Audited @Audited
@Entity @Entity
@Table(name = "GTW_SCHEDULER_TASK") @Table(name = "AVB_SCHEDULER_TASK")
@NamedQuery(name = "SchedulerTasks.findByPK", query = "Select u from SchedulerTask u where u.id = ?1") @NamedQuery(name = "SchedulerTask.findByPK", query = "Select u from SchedulerTask u where u.id = ?1")
@Getter @Getter
@Setter @Setter
@EqualsAndHashCode @EqualsAndHashCode
...@@ -23,12 +25,12 @@ public class SchedulerTask implements Serializable { ...@@ -23,12 +25,12 @@ public class SchedulerTask implements Serializable {
@Id @Id
@Column(name = "SHTA_ID") @Column(name = "SHTA_ID")
@SequenceGenerator(name = "GTW_SCHEDULER_TASK_GENERATOR", sequenceName = "GTW_SCHEDULER_TASK_SEQ", initialValue = 1, allocationSize = 1) @SequenceGenerator(name = "AVB_SCHEDULER_TASK_GENERATOR", sequenceName = "AVB_SCHEDULER_TASK_SEQ", initialValue = 1, allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "GTW_SCHEDULER_TASK_GENERATOR") @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "AVB_SCHEDULER_TASK_GENERATOR")
private BigInteger id; private BigInteger id;
@Version @Version
@Column(name = "VERSION") @Column(name = "SHTA_VERSION")
@Basic(optional = false) @Basic(optional = false)
private long version; private long version;
...@@ -45,8 +47,12 @@ public class SchedulerTask implements Serializable { ...@@ -45,8 +47,12 @@ public class SchedulerTask implements Serializable {
@Column(name = "SHTA_PARAM") @Column(name = "SHTA_PARAM")
private String stringParameters; private String stringParameters;
@Column(name = "CALE_ID")
private String calendarID;
@ManyToOne(optional = false) @ManyToOne(optional = false)
@JoinColumn(name = "CALE_ID", referencedColumnName = "CALE_ID", nullable = false) @NotFound(action = NotFoundAction.IGNORE)
@JoinColumn(name = "cale_id", referencedColumnName = "cale_id", nullable = false)
private Calendar calendar; private Calendar calendar;
} }
...@@ -4,6 +4,8 @@ import lombok.EqualsAndHashCode; ...@@ -4,6 +4,8 @@ import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.envers.Audited; import org.hibernate.envers.Audited;
import javax.persistence.*; import javax.persistence.*;
...@@ -41,8 +43,12 @@ public class WeekScheduler implements Serializable { ...@@ -41,8 +43,12 @@ public class WeekScheduler implements Serializable {
@Column(name = "WESC_TO", nullable = false) @Column(name = "WESC_TO", nullable = false)
private OffsetTime to; private OffsetTime to;
@Column(name = "CALE_ID")
private String calendarID;
@ManyToOne(optional = false) @ManyToOne(optional = false)
@JoinColumn(name = "CALE_ID", referencedColumnName = "CALE_ID", nullable = false) @NotFound(action = NotFoundAction.IGNORE)
@JoinColumn(name = "cale_id", referencedColumnName = "cale_id", nullable = false)
private Calendar calendar; private Calendar calendar;
} }
...@@ -11,6 +11,7 @@ import java.util.List; ...@@ -11,6 +11,7 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
public interface WeekSchedulerRepository extends CrudRepository<WeekScheduler, BigInteger>, JpaSpecificationExecutor<WeekScheduler> { 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); Optional<List<WeekScheduler>> findByCalendarId(@Param("caleId") String caleId);
} }
...@@ -62,7 +62,7 @@ public class CalendarService extends XDFService<Calendar, CalendarBean, String> ...@@ -62,7 +62,7 @@ public class CalendarService extends XDFService<Calendar, CalendarBean, String>
protected CalendarBean toBean(Calendar model) { protected CalendarBean toBean(Calendar model) {
CalendarBean bean = new CalendarBean(); CalendarBean bean = new CalendarBean();
BeanUtils.copyProperties(model, bean); BeanUtils.copyProperties(model, bean);
bean.setWeekSchedulerBeanList(this.weekSchedulerService.getWeekSchedulerByCalId(model.getId())); bean.setWeekSchedulerBeanList(this.weekSchedulerService.getWeekSchedulerByCalId(model.getId().trim()));
return bean; return bean;
} }
......
...@@ -20,9 +20,6 @@ import java.util.*; ...@@ -20,9 +20,6 @@ import java.util.*;
@Transactional @Transactional
public class SchedulerTaskService extends XDFService<SchedulerTask, SchedulerTaskBean, BigInteger> { public class SchedulerTaskService extends XDFService<SchedulerTask, SchedulerTaskBean, BigInteger> {
@Autowired
private CalendarService calendarService;
@Autowired @Autowired
private CalendarService CalendarService; private CalendarService CalendarService;
...@@ -41,14 +38,16 @@ public class SchedulerTaskService extends XDFService<SchedulerTask, SchedulerTas ...@@ -41,14 +38,16 @@ public class SchedulerTaskService extends XDFService<SchedulerTask, SchedulerTas
BeanUtils.copyProperties(bean, model); BeanUtils.copyProperties(bean, model);
model.setInternals("Y".equals(bean.getInternals())); model.setInternals("Y".equals(bean.getInternals()));
if (bean.getCalendar() == null) { if (bean.getCalendarID() == null) {
throw new NotFoundException("Calendar can not be null"); throw new NotFoundException("Calendar can not be null");
} }
Optional<Calendar> calendarOptional = this.calendarRepository.findById(bean.getCalendar());
Optional<Calendar> calendarOptional = this.calendarRepository.findById(bean.getCalendarID());
if (!calendarOptional.isPresent()) { if (!calendarOptional.isPresent()) {
throw new NotFoundException("Calendar not found " + bean.getCalendar()); throw new NotFoundException("Calendar not found " + bean.getCalendarID());
} }
model.setCalendar(calendarOptional.get()); model.setCalendar(calendarOptional.get());
return model; return model;
} }
...@@ -57,8 +56,13 @@ public class SchedulerTaskService extends XDFService<SchedulerTask, SchedulerTas ...@@ -57,8 +56,13 @@ public class SchedulerTaskService extends XDFService<SchedulerTask, SchedulerTas
SchedulerTaskBean bean = new SchedulerTaskBean(); SchedulerTaskBean bean = new SchedulerTaskBean();
BeanUtils.copyProperties(model, bean); BeanUtils.copyProperties(model, bean);
bean.setInternals(model.getInternals().booleanValue() ? "Y" : "N"); bean.setInternals(model.getInternals().booleanValue() ? "Y" : "N");
bean.setCalendar(model.getCalendar().getId());
bean.setCalendarName(model.getCalendar().getName()); CalendarBean found = this.CalendarService.getById(bean.getCalendarID().trim());
if(found != null){
bean.setCalendarName(found.getName());
}
return bean; return bean;
} }
......
package com.bytesw.bytebot.service; package com.bytesw.bytebot.service;
import com.bytesw.bytebot.bean.CalendarBean;
import com.bytesw.bytebot.bean.WeekSchedulerBean; import com.bytesw.bytebot.bean.WeekSchedulerBean;
import com.bytesw.bytebot.model.Calendar; import com.bytesw.bytebot.model.Calendar;
import com.bytesw.bytebot.model.WeekScheduler; import com.bytesw.bytebot.model.WeekScheduler;
...@@ -22,11 +23,16 @@ import java.util.Optional; ...@@ -22,11 +23,16 @@ import java.util.Optional;
public class WeekSchedulerService extends XDFService<WeekScheduler, WeekSchedulerBean, BigInteger> { public class WeekSchedulerService extends XDFService<WeekScheduler, WeekSchedulerBean, BigInteger> {
@Autowired @Autowired
private WeekSchedulerRepository weekSchedulerRepository; private WeekSchedulerRepository weekSchedulerRepository;
@Autowired @Autowired
private CalendarService calendarService; private CalendarService calendarService;
@Autowired @Autowired
private CalendarRepository calendarRepository; private CalendarRepository calendarRepository;
@Autowired
private CalendarService CalendarService;
protected WeekSchedulerService(WeekSchedulerRepository repository) { protected WeekSchedulerService(WeekSchedulerRepository repository) {
super(repository); super(repository);
} }
...@@ -37,13 +43,16 @@ public class WeekSchedulerService extends XDFService<WeekScheduler, WeekSchedule ...@@ -37,13 +43,16 @@ public class WeekSchedulerService extends XDFService<WeekScheduler, WeekSchedule
model = new WeekScheduler(); model = new WeekScheduler();
} }
BeanUtils.copyProperties(bean, model); BeanUtils.copyProperties(bean, model);
if (bean.getCalendar() == null) {
if (bean.getCalendarID() == null) {
throw new NotFoundException("Calendar can not be 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()) { if (!calendarOptional.isPresent()) {
throw new NotFoundException("Calendar not found " + bean.getCalendar().getId()); throw new NotFoundException("Calendar not found " + bean.getCalendarID());
} }
model.setCalendar(calendarOptional.get()); model.setCalendar(calendarOptional.get());
return model; return model;
} }
...@@ -52,13 +61,20 @@ public class WeekSchedulerService extends XDFService<WeekScheduler, WeekSchedule ...@@ -52,13 +61,20 @@ public class WeekSchedulerService extends XDFService<WeekScheduler, WeekSchedule
protected WeekSchedulerBean toBean(WeekScheduler model) { protected WeekSchedulerBean toBean(WeekScheduler model) {
WeekSchedulerBean bean = new WeekSchedulerBean(); WeekSchedulerBean bean = new WeekSchedulerBean();
BeanUtils.copyProperties(model, bean); 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; return bean;
} }
public List<WeekSchedulerBean> getWeekSchedulerByCalId(String caleID) { public List<WeekSchedulerBean> getWeekSchedulerByCalId(String caleID) {
List<WeekSchedulerBean> weekSchedulerBeanList = new ArrayList<>(7); 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()) { if (!weekSchedulerOptional.isPresent()) {
for (int i = 0; i < 7; i++) { for (int i = 0; i < 7; i++) {
weekSchedulerBeanList.add(i, new WeekSchedulerBean()); 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