Commit d07682b4 authored by jgomez's avatar jgomez

SchedulerTask

Creaciòn de Bean, Controller, Service y Repository
parent 7274ba0a
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;
}
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);
}
}
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;
}
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);
}
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;
}
}
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