From 45a041cc8308db68b9e9a2145ff6bb23fcda9349 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Thu, 20 Oct 2022 18:50:44 +0200 Subject: [PATCH] Aggiornato il supporto a Pers Orario --- .../cnr/isti/epasmed/domain/PersOrario.java | 297 ++++++++++++++++++ .../repository/PersOrarioRepository.java | 18 ++ .../epasmed/service/PersOrarioService.java | 215 +++++++++++++ .../service/mapper/PersOrarioMapper.java | 51 +++ .../it/cnr/isti/epasmed/sync/SyncService.java | 55 +++- .../isti/epasmed/web/rest/LeavesResource.java | 2 +- .../epasmed/web/rest/PersOrarioResource.java | 167 ++++++++++ .../00000000000000_initial_schema.xml | 28 ++ 8 files changed, 824 insertions(+), 9 deletions(-) create mode 100644 src/main/java/it/cnr/isti/epasmed/domain/PersOrario.java create mode 100644 src/main/java/it/cnr/isti/epasmed/repository/PersOrarioRepository.java create mode 100644 src/main/java/it/cnr/isti/epasmed/service/PersOrarioService.java create mode 100644 src/main/java/it/cnr/isti/epasmed/service/mapper/PersOrarioMapper.java create mode 100644 src/main/java/it/cnr/isti/epasmed/web/rest/PersOrarioResource.java diff --git a/src/main/java/it/cnr/isti/epasmed/domain/PersOrario.java b/src/main/java/it/cnr/isti/epasmed/domain/PersOrario.java new file mode 100644 index 0000000..ce39e70 --- /dev/null +++ b/src/main/java/it/cnr/isti/epasmed/domain/PersOrario.java @@ -0,0 +1,297 @@ +package it.cnr.isti.epasmed.domain; + +import java.io.Serializable; +import java.time.LocalDate; +import java.time.LocalDateTime; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.validation.constraints.NotNull; + +/** + * Leaves + */ +@Entity +@Table(name = "persorario") +public class PersOrario implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + private Integer id; + + private Integer idPersona; + + @NotNull + @Column(nullable = false) + private String cf; + + @NotNull + @Column(nullable = false) + private LocalDate dal; + + private LocalDate al; + + private String descrizione; + + private Integer lun; + private Integer mar; + private Integer mer; + private Integer gio; + private Integer ven; + private Integer sab; + + private Integer percentuale; + + private String turno; + private Integer oreTurno; + private String festivo; + private String notturno; + + @NotNull + @Column(nullable = false) + private LocalDateTime dataMod; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getIdPersona() { + return idPersona; + } + + public void setIdPersona(Integer idPersona) { + this.idPersona = idPersona; + } + + public String getCf() { + return cf; + } + + public void setCf(String cf) { + this.cf = cf; + } + + public LocalDate getDal() { + return dal; + } + + public void setDal(LocalDate dal) { + this.dal = dal; + } + + public LocalDate getAl() { + return al; + } + + public void setAl(LocalDate al) { + this.al = al; + } + + public String getDescrizione() { + return descrizione; + } + + public void setDescrizione(String descrizione) { + this.descrizione = descrizione; + } + + public Integer getLun() { + return lun; + } + + public void setLun(Integer lun) { + this.lun = lun; + } + + public Integer getMar() { + return mar; + } + + public void setMar(Integer mar) { + this.mar = mar; + } + + public Integer getMer() { + return mer; + } + + public void setMer(Integer mer) { + this.mer = mer; + } + + public Integer getGio() { + return gio; + } + + public void setGio(Integer gio) { + this.gio = gio; + } + + public Integer getVen() { + return ven; + } + + public void setVen(Integer ven) { + this.ven = ven; + } + + public Integer getSab() { + return sab; + } + + public void setSab(Integer sab) { + this.sab = sab; + } + + public Integer getPercentuale() { + return percentuale; + } + + public void setPercentuale(Integer percentuale) { + this.percentuale = percentuale; + } + + public String getTurno() { + return turno; + } + + public void setTurno(String turno) { + this.turno = turno; + } + + public Integer getOreTurno() { + return oreTurno; + } + + public void setOreTurno(Integer oreTurno) { + this.oreTurno = oreTurno; + } + + public String getFestivo() { + return festivo; + } + + public void setFestivo(String festivo) { + this.festivo = festivo; + } + + public String getNotturno() { + return notturno; + } + + public void setNotturno(String notturno) { + this.notturno = notturno; + } + + public LocalDateTime getDataMod() { + return dataMod; + } + + public void setDataMod(LocalDateTime dataMod) { + this.dataMod = dataMod; + } + + @Override + public String toString() { + return "PersOrario [id=" + id + ", idPersona=" + idPersona + ", cf=" + cf + ", dal=" + dal + ", al=" + al + + ", descrizione=" + descrizione + ", lun=" + lun + ", mar=" + mar + ", mer=" + mer + ", gio=" + gio + + ", ven=" + ven + ", sab=" + sab + ", percentuale=" + percentuale + ", turno=" + turno + ", oreTurno=" + + oreTurno + ", festivo=" + festivo + ", notturno=" + notturno + ", dataMod=" + dataMod + "]"; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof PersOrario)) { + return false; + } + return id != null && id.equals(((PersOrario) o).id); + } + + public boolean same(PersOrario l) { + boolean same = false; + + if (id != null && id.compareTo(l.getId()) == 0) { + if (cf != null && cf.compareTo(l.getCf()) == 0) { + if (idPersona != null && idPersona.compareTo(l.getIdPersona()) == 0) { + if (dal != null && dal.compareTo(l.getDal()) == 0) { + if (al == null && l.getAl() == null) { + sameOthersFields(l); + } else { + if (al != null && al.compareTo(l.getAl()) == 0) { + sameOthersFields(l); + } + } + } + } + } + } + + return same; + } + + private boolean sameOthersFields(PersOrario l) { + boolean someOthers = false; + if (lun == l.getLun() && mar == l.getMar() && mer == l.getMer() && gio == l.getGio() && ven == l.getVen() + && sab == l.getSab() && percentuale == l.getPercentuale()) { + if (turno != null && turno.compareTo(l.getTurno()) == 0) { + if (oreTurno == l.getOreTurno()) { + if (festivo != null && festivo.compareTo(l.getFestivo()) == 0) { + if (notturno != null && notturno.compareTo(l.getNotturno()) == 0) { + return true; + } else { + if (notturno == null && l.getNotturno() == null) { + return true; + } + } + } else { + if (festivo == null && l.getFestivo() == null) { + if (notturno != null && notturno.compareTo(l.getNotturno()) == 0) { + return true; + } else { + if (notturno == null && l.getNotturno() == null) { + return true; + } + } + } + } + } + } else { + if (turno == null && l.getTurno() == null) { + if (oreTurno == l.getOreTurno()) { + if (festivo != null && festivo.compareTo(l.getFestivo()) == 0) { + if (notturno != null && notturno.compareTo(l.getNotturno()) == 0) { + return true; + } else { + if (notturno == null && l.getNotturno() == null) { + return true; + } + } + } else { + if (festivo == null && l.getFestivo() == null) { + if (notturno != null && notturno.compareTo(l.getNotturno()) == 0) { + return true; + } else { + if (notturno == null && l.getNotturno() == null) { + return true; + } + } + } + } + } + } + } + } + return someOthers; + } + +} diff --git a/src/main/java/it/cnr/isti/epasmed/repository/PersOrarioRepository.java b/src/main/java/it/cnr/isti/epasmed/repository/PersOrarioRepository.java new file mode 100644 index 0000000..a558331 --- /dev/null +++ b/src/main/java/it/cnr/isti/epasmed/repository/PersOrarioRepository.java @@ -0,0 +1,18 @@ +package it.cnr.isti.epasmed.repository; + +import java.util.Optional; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import it.cnr.isti.epasmed.domain.PersOrario; + +/** + * Spring Data JPA repository for the {@link PersOrario} entity. + */ +@Repository +public interface PersOrarioRepository extends JpaRepository { + + Optional findOneByCf(String cf); + + } diff --git a/src/main/java/it/cnr/isti/epasmed/service/PersOrarioService.java b/src/main/java/it/cnr/isti/epasmed/service/PersOrarioService.java new file mode 100644 index 0000000..4cd6b42 --- /dev/null +++ b/src/main/java/it/cnr/isti/epasmed/service/PersOrarioService.java @@ -0,0 +1,215 @@ +package it.cnr.isti.epasmed.service; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Optional; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import it.cnr.isti.epasmed.domain.PersOrario; +import it.cnr.isti.epasmed.repository.PersOrarioRepository; + +/** + * Service class for managing PersOrario. + */ +@Service +@Transactional("epasMedTransactionManager") +public class PersOrarioService { + + private final Logger log = LoggerFactory.getLogger(PersOrarioService.class); + + private final PersOrarioRepository persOrarioRepository; + + public PersOrarioService(PersOrarioRepository persOrarioRepository) { + this.persOrarioRepository = persOrarioRepository; + } + + @Transactional(value = "epasMedTransactionManager", readOnly = true) + public Page getAllPersOrario(Pageable pageable) { + log.debug("PersOrarioService getAllPersOrario(): {}", pageable); + persOrarioRepository.findAll(); + return persOrarioRepository.findAll(pageable); + } + + @Transactional(value = "epasMedTransactionManager", readOnly = true) + public List getAllPersOrario() { + log.debug("PersOrarioService getAllPersOrario()"); + return persOrarioRepository.findAll(); + } + + @Transactional(value = "epasMedTransactionManager", readOnly = true) + public Optional getPersOrarioById(Integer id) { + return persOrarioRepository.findById(id); + } + + public PersOrario createPersOrario(PersOrario persOrarioDTO) { + log.debug("Creating new PersOrario: {}", persOrarioDTO); + PersOrario persOrario = new PersOrario(); + persOrario.setId(persOrarioDTO.getId()); + persOrario.setIdPersona(persOrarioDTO.getIdPersona()); + persOrario.setCf(persOrarioDTO.getCf()); + persOrario.setDal(persOrarioDTO.getDal()); + persOrario.setAl(persOrarioDTO.getAl()); + persOrario.setDescrizione(persOrarioDTO.getDescrizione()); + persOrario.setLun(persOrarioDTO.getLun()); + persOrario.setMar(persOrarioDTO.getMar()); + persOrario.setMer(persOrarioDTO.getMer()); + persOrario.setGio(persOrarioDTO.getGio()); + persOrario.setVen(persOrarioDTO.getVen()); + persOrario.setSab(persOrarioDTO.getSab()); + persOrario.setPercentuale(persOrarioDTO.getPercentuale()); + persOrario.setTurno(persOrarioDTO.getTurno()); + persOrario.setOreTurno(persOrarioDTO.getOreTurno()); + persOrario.setFestivo(persOrarioDTO.getFestivo()); + persOrario.setNotturno(persOrarioDTO.getNotturno()); + persOrario.setDataMod(persOrarioDTO.getDataMod()); + persOrarioRepository.save(persOrario); + + log.debug("Created PersOrario: {}", persOrario); + return persOrario; + } + + /** + * Update all information + * + * @param persOrarioDTO pers orario to update. + * @return updated table. + */ + public Optional updatePersOrario(PersOrario persOrarioDTO) { + Optional po = persOrarioRepository.findById(persOrarioDTO.getId()); + if (po.isPresent()) { + PersOrario persOrario = po.get(); + persOrario.setId(persOrarioDTO.getId()); + persOrario.setIdPersona(persOrarioDTO.getIdPersona()); + persOrario.setCf(persOrarioDTO.getCf()); + persOrario.setDal(persOrarioDTO.getDal()); + persOrario.setAl(persOrarioDTO.getAl()); + persOrario.setDescrizione(persOrarioDTO.getDescrizione()); + persOrario.setLun(persOrarioDTO.getLun()); + persOrario.setMar(persOrarioDTO.getMar()); + persOrario.setMer(persOrarioDTO.getMer()); + persOrario.setGio(persOrarioDTO.getGio()); + persOrario.setVen(persOrarioDTO.getVen()); + persOrario.setSab(persOrarioDTO.getSab()); + persOrario.setPercentuale(persOrarioDTO.getPercentuale()); + persOrario.setTurno(persOrarioDTO.getTurno()); + persOrario.setOreTurno(persOrarioDTO.getOreTurno()); + persOrario.setFestivo(persOrarioDTO.getFestivo()); + persOrario.setNotturno(persOrarioDTO.getNotturno()); + persOrario.setDataMod(persOrarioDTO.getDataMod()); + persOrario = persOrarioRepository.save(persOrario); + log.debug("Changed Information for : {}", persOrario); + return Optional.of(persOrario); + } else { + return po; + } + } + + public void deletePersOrario(Integer id) { + persOrarioRepository.findById(id).ifPresent(perOrario -> { + persOrarioRepository.delete(perOrario); + log.debug("Deleted PersOrario: {}", perOrario); + }); + } + + public void updatePersOrario(String id, String idPersona, String cf, String dal, String al, String descrizione, + String lun, String mar, String mer, String gio, String ven, String sab, String percentuale, String turno, + String oreTurno, String festivo, String notturno, String dataMod) { + + Optional.of(persOrarioRepository.findById(Integer.valueOf(id))).filter(Optional::isPresent).map(Optional::get) + .map(persOrario -> { + LocalDate dataI = null; + LocalDate dataF = null; + LocalDateTime dataM = null; + + if (dal != null && !dal.isEmpty()) { + dataI = LocalDate.parse(dal); + } + if (al != null && !al.isEmpty()) { + dataF = LocalDate.parse(al); + } + + if (dataMod != null && !dataMod.isEmpty()) { + dataM = LocalDateTime.parse(dataMod); + } + + Integer lu = null; + try { + lu = Integer.valueOf(lun); + } catch (NumberFormatException e) { + log.error(e.getLocalizedMessage(), e); + } + Integer ma = null; + try { + ma = Integer.valueOf(mar); + } catch (NumberFormatException e) { + log.error(e.getLocalizedMessage(), e); + } + Integer me = null; + try { + me = Integer.valueOf(mer); + } catch (NumberFormatException e) { + log.error(e.getLocalizedMessage(), e); + } + Integer gi = null; + try { + gi = Integer.valueOf(gio); + } catch (NumberFormatException e) { + log.error(e.getLocalizedMessage(), e); + } + Integer ve = null; + try { + ve = Integer.valueOf(ven); + } catch (NumberFormatException e) { + log.error(e.getLocalizedMessage(), e); + } + Integer sa = null; + try { + sa = Integer.valueOf(sab); + } catch (NumberFormatException e) { + log.error(e.getLocalizedMessage(), e); + } + + Integer perc = null; + try { + perc = Integer.valueOf(percentuale); + } catch (NumberFormatException e) { + log.error(e.getLocalizedMessage(), e); + } + + Integer oreTu = null; + try { + oreTu = Integer.valueOf(oreTurno); + } catch (NumberFormatException e) { + log.error(e.getLocalizedMessage(), e); + } + + persOrario.setIdPersona(Integer.valueOf(idPersona)); + persOrario.setCf(cf); + persOrario.setDal(dataI); + persOrario.setAl(dataF); + persOrario.setDescrizione(descrizione); + persOrario.setLun(lu); + persOrario.setMar(ma); + persOrario.setMer(me); + persOrario.setGio(gi); + persOrario.setVen(ve); + persOrario.setSab(sa); + persOrario.setPercentuale(perc); + persOrario.setTurno(turno); + persOrario.setOreTurno(oreTu); + persOrario.setFestivo(festivo); + persOrario.setNotturno(notturno); + persOrario.setDataMod(dataM); + log.debug("Changed Information for PersOrario: {}", persOrario); + return persOrario; + }); + } + +} diff --git a/src/main/java/it/cnr/isti/epasmed/service/mapper/PersOrarioMapper.java b/src/main/java/it/cnr/isti/epasmed/service/mapper/PersOrarioMapper.java new file mode 100644 index 0000000..bb8fe0a --- /dev/null +++ b/src/main/java/it/cnr/isti/epasmed/service/mapper/PersOrarioMapper.java @@ -0,0 +1,51 @@ +package it.cnr.isti.epasmed.service.mapper; + +import java.text.SimpleDateFormat; +import java.time.LocalDate; + +import org.springframework.stereotype.Service; + +import it.cnr.isti.epasmed.domain.PersOrario; +import it.cnr.isti.epasmed.sistemainformativo.model.SIPersOrario; + +@Service +public class PersOrarioMapper { + + private final SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd"); + + public PersOrario siPersOrarioToPersOrario(SIPersOrario siPersOrario) { + if (siPersOrario == null) { + return null; + } else { + PersOrario persOrario = new PersOrario(); + persOrario.setId(siPersOrario.getId()); + persOrario.setIdPersona(siPersOrario.getIdpersona()); + persOrario.setCf(siPersOrario.getCf()); + LocalDate dataInizio = null; + if (siPersOrario.getDal() != null) { + dataInizio = LocalDate.parse(sdfDate.format(siPersOrario.getDal())); + } + LocalDate dataFine = null; + if (siPersOrario.getAl() != null) { + dataFine = LocalDate.parse(sdfDate.format(siPersOrario.getAl())); + } + + persOrario.setDal(dataInizio); + persOrario.setAl(dataFine); + persOrario.setDescrizione(siPersOrario.getDescrizione()); + persOrario.setLun(siPersOrario.getLun()); + persOrario.setMar(siPersOrario.getMar()); + persOrario.setMer(siPersOrario.getMer()); + persOrario.setGio(siPersOrario.getGio()); + persOrario.setVen(siPersOrario.getVen()); + persOrario.setSab(siPersOrario.getSab()); + persOrario.setPercentuale(siPersOrario.getPercentuale()); + persOrario.setTurno(siPersOrario.getTurno()); + persOrario.setOreTurno(siPersOrario.getOre_turno()); + persOrario.setFestivo(siPersOrario.getFestivo()); + persOrario.setNotturno(siPersOrario.getNotturno()); + persOrario.setDataMod(siPersOrario.getData_mod().toLocalDateTime()); + return persOrario; + } + } +} diff --git a/src/main/java/it/cnr/isti/epasmed/sync/SyncService.java b/src/main/java/it/cnr/isti/epasmed/sync/SyncService.java index e2a4810..e64cda2 100755 --- a/src/main/java/it/cnr/isti/epasmed/sync/SyncService.java +++ b/src/main/java/it/cnr/isti/epasmed/sync/SyncService.java @@ -26,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import it.cnr.isti.epasmed.domain.Leaves; +import it.cnr.isti.epasmed.domain.PersOrario; import it.cnr.isti.epasmed.domain.TabsSI; import it.cnr.isti.epasmed.domain.TimeCardsReporting; import it.cnr.isti.epasmed.epas.dto.EPASAffiliationsDTO; @@ -58,9 +59,11 @@ import it.cnr.isti.epasmed.epas.service.EPASTimeCardsService; import it.cnr.isti.epasmed.epas.service.EPASValidatesService; import it.cnr.isti.epasmed.epas.service.EPASWorkingTimeTypesService; import it.cnr.isti.epasmed.service.LeavesService; +import it.cnr.isti.epasmed.service.PersOrarioService; import it.cnr.isti.epasmed.service.TabsSIService; import it.cnr.isti.epasmed.service.TimeCardsReportingService; import it.cnr.isti.epasmed.service.mapper.LeavesMapper; +import it.cnr.isti.epasmed.service.mapper.PersOrarioMapper; import it.cnr.isti.epasmed.sistemainformativo.model.SIAnagrafico; import it.cnr.isti.epasmed.sistemainformativo.model.SIAspettative; import it.cnr.isti.epasmed.sistemainformativo.model.SICartellini; @@ -112,7 +115,11 @@ public class SyncService { LeavesService leavesService; @Autowired LeavesMapper leavesMapper; - + @Autowired + PersOrarioService persOrarioService; + @Autowired + PersOrarioMapper persOrarioMapper; + @Autowired SIMasterLogService siMasterLogService; @Autowired @@ -1421,7 +1428,8 @@ public class SyncService { } else { logger.info("PersonWorkingTimeDTOList size: {}", epasPersonWorkingTimeDTOList.size()); } - + + int count=0; // SI for (EPASPersonWorkingTimeDTO pwtDTO : epasPersonWorkingTimeDTOList) { logger.info("Writing Person Working Time: {}", pwtDTO); @@ -1491,22 +1499,55 @@ public class SyncService { LocalDateTime dMod = now.truncatedTo(ChronoUnit.SECONDS); Timestamp dataMod = Timestamp.valueOf(dMod); + SIPersOrario siPersOrario = new SIPersOrario(id, idPersona, pwtDTO.getCf(), startDate, endDate, pwtDTO.getDescrizione(), pwtDTO.getLun(), pwtDTO.getMar(), pwtDTO.getMer(), pwtDTO.getGio(), pwtDTO.getVen(), pwtDTO.getSab(), pwtDTO.getPercentuale(), pwtDTO.getTurno(), pwtDTO.getOre_turno(), pwtDTO.getFestivo(), pwtDTO.getNotturno(), dataMod, SI_FLAG_DEL_FALSE, fluxId); - logger.info("Write SIPersOrario: {}", siPersOrario); - siPersOrarioService.writeNewFlux(fluxId, siPersOrario); - + + if (checkSIPersOrarioIsUpgradeable(siPersOrario)) { + logger.info("Write SIPersOrario: {}", siPersOrario); + count=count+1; + siPersOrarioService.writeNewFlux(fluxId, siPersOrario); + } + + } + logger.info("Peronale Orario scritto su SI: {}",count); + logger.info("SIPersOrario Updated"); - bpers_orario = true; tab.setIdFlusso(fluxId); tab.setLastUpdate(now); tabsSIService.updateTabsSI(tab); } + + private boolean checkSIPersOrarioIsUpgradeable(SIPersOrario siPersOrario) { + boolean upgradeable = false; + try { + Optional persOrario = persOrarioService.getPersOrarioById(siPersOrario.getId()); + if (persOrario.isPresent()) { + PersOrario found = persOrario.get(); + PersOrario persOrarioDTO = persOrarioMapper.siPersOrarioToPersOrario(siPersOrario); + if (!found.same(persOrarioDTO)) { + upgradeable = true; + persOrarioService.updatePersOrario(persOrarioDTO); + } + } else { + upgradeable = true; + PersOrario persOrarioDTO = persOrarioMapper.siPersOrarioToPersOrario(siPersOrario); + persOrarioService.createPersOrario(persOrarioDTO); + } + } catch (Exception e) { + logger.error("Error in check SI Per Orario: {}", e.getLocalizedMessage(), e); + } + + return upgradeable; + + } + + private void syncCartelliniRendicontazioni(Long fluxId, TabsSI tab, String year, String month, LocalDateTime now, TimeCardsReporting timeCardsReporting) throws Exception { @@ -1762,8 +1803,6 @@ public class SyncService { if (epasPersonDay.getAbsences() != null && epasPersonDay.getAbsences().length > 0) { for (EPASAbsences epasAbsences : epasPersonDay.getAbsences()) { motivo.append("["); - // motivo.append(epasAbsences.getJustifiedType()); - // motivo.append("-"); motivo.append(epasAbsences.getCode()); if (epasAbsenceTypeMap != null && !epasAbsenceTypeMap.isEmpty()) { diff --git a/src/main/java/it/cnr/isti/epasmed/web/rest/LeavesResource.java b/src/main/java/it/cnr/isti/epasmed/web/rest/LeavesResource.java index 5f067ff..5318628 100644 --- a/src/main/java/it/cnr/isti/epasmed/web/rest/LeavesResource.java +++ b/src/main/java/it/cnr/isti/epasmed/web/rest/LeavesResource.java @@ -96,7 +96,7 @@ public class LeavesResource { * * @param leavesDTO Leave to create. * @return the {@link ResponseEntity} with status {@code 201 (Created)} and with - * body the new table SI, or with status {@code 400 (Bad Request)} if + * body the new Leave, or with status {@code 400 (Bad Request)} if * the id is already in use. * @throws URISyntaxException if the Location URI syntax is incorrect. */ diff --git a/src/main/java/it/cnr/isti/epasmed/web/rest/PersOrarioResource.java b/src/main/java/it/cnr/isti/epasmed/web/rest/PersOrarioResource.java new file mode 100644 index 0000000..596d65e --- /dev/null +++ b/src/main/java/it/cnr/isti/epasmed/web/rest/PersOrarioResource.java @@ -0,0 +1,167 @@ +package it.cnr.isti.epasmed.web.rest; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +import javax.validation.Valid; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; + +import io.github.jhipster.web.util.HeaderUtil; +import io.github.jhipster.web.util.PaginationUtil; +import io.github.jhipster.web.util.ResponseUtil; +import it.cnr.isti.epasmed.config.Constants; +import it.cnr.isti.epasmed.domain.Leaves; +import it.cnr.isti.epasmed.domain.PersOrario; +import it.cnr.isti.epasmed.security.AuthoritiesConstants; +import it.cnr.isti.epasmed.service.PersOrarioService; +import it.cnr.isti.epasmed.web.rest.errors.BadRequestAlertException; + +/** + * REST controller for managing PersOrario. + *

+ * This class accesses the {@link Leaves} entity. + * + * + */ +@RestController +@RequestMapping("/api") +public class PersOrarioResource { + private static final List ALLOWED_ORDERED_PROPERTIES = Collections + .unmodifiableList(Arrays.asList("id", "idPersona", "cf", "dal", + "al","descrizione","dataMod")); + + + private final Logger logger = LoggerFactory.getLogger(PersOrarioResource.class); + + @Value("${jhipster.clientApp.name}") + private String applicationName; + + private final PersOrarioService persOrarioService; + + public PersOrarioResource(PersOrarioService persOrarioService) { + this.persOrarioService = persOrarioService; + + } + + /** + * {@code GET /persorario} : get all pers orario. + * + * @param pageable the pagination information. + * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body + * all pers orario. + */ + @GetMapping("/persorario") + public ResponseEntity> getAllPersOrario(Pageable pageable) { + logger.info("REST request to read PersOrario : {}", pageable); + + if (!onlyContainsAllowedProperties(pageable)) { + return ResponseEntity.badRequest().build(); + } + + final Page page = persOrarioService.getAllPersOrario(pageable); + HttpHeaders headers = PaginationUtil + .generatePaginationHttpHeaders(ServletUriComponentsBuilder.fromCurrentRequest(), page); + return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK); + } + + private boolean onlyContainsAllowedProperties(Pageable pageable) { + return pageable.getSort().stream().map(Sort.Order::getProperty).allMatch(ALLOWED_ORDERED_PROPERTIES::contains); + } + + /** + * {@code POST /persorario} : Creates a new pers orario. + *

+ * + * @param persOrarioDTO PersOrario to create. + * @return the {@link ResponseEntity} with status {@code 201 (Created)} and with + * body the new PersOrario, or with status {@code 400 (Bad Request)} if + * the id is already in use. + * @throws URISyntaxException if the Location URI syntax is incorrect. + */ + @PostMapping("/persorario") + @PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")") + public ResponseEntity createPersOrario(@Valid @RequestBody PersOrario persOrarioDTO) throws URISyntaxException { + logger.info("REST request to save PersOrario : {}", persOrarioDTO); + + if (persOrarioDTO.getId() != null) { + throw new BadRequestAlertException("A new pers orario cannot already have an ID", "PersOrario", "idexists"); + } else { + PersOrario persOrario = persOrarioService.createPersOrario(persOrarioDTO); + return ResponseEntity.created(new URI("/api/persorario/" + persOrario.getId())).headers(HeaderUtil + .createAlert(applicationName, "A pers orario is created with identifier " + persOrario.getId(), persOrario.getCf())) + .body(persOrario); + } + } + + /** + * {@code PUT /persorario} : Updates pers orario. + * + * @param persOrarioDTO the pers orario to update. + * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body + * the updated pers orario. + * + */ + @PutMapping("/persorario") + @PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")") + public ResponseEntity updatePersOrario(@Valid @RequestBody PersOrario persOrarioDTO) { + logger.debug("REST request to update PersOrario : {}", persOrarioDTO); + Optional updatedLeaves = persOrarioService.updatePersOrario(persOrarioDTO); + + return ResponseUtil.wrapOrNotFound(updatedLeaves, HeaderUtil.createAlert(applicationName, + "A pers orario is updated with identifier " + persOrarioDTO.getId(), persOrarioDTO.getCf())); + } + + /** + * {@code GET /persorario/:id} : get the "id" of pers orario. + * + * @param id the id of the pers orario to find. + * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body + * the pers orario, or with status {@code 404 (Not Found)}. + */ + @GetMapping("/persorario/{id:" + Constants.VALID_NUMBER_REGEX + "}") + public ResponseEntity getPersOrario(@PathVariable String id) { + logger.debug("REST request to get Pers Orario : {}", id); + return ResponseUtil.wrapOrNotFound(persOrarioService.getPersOrarioById(Integer.valueOf(id))); + + } + + /** + * {@code DELETE /persorario/:id} : delete the "id" Leave. + * + * @param id the id of the pers orario to delete. + * @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}. + */ + @DeleteMapping("/persorario/{id:" + Constants.VALID_NUMBER_REGEX + "}") + @PreAuthorize("hasAuthority(\"" + AuthoritiesConstants.ADMIN + "\")") + public ResponseEntity deletePersOrario(@PathVariable String id) { + logger.debug("REST request to delete Pers Orario id: {}", id); + persOrarioService.deletePersOrario(Integer.valueOf(id)); + return ResponseEntity.noContent() + .headers(HeaderUtil.createAlert(applicationName, "A Pers Orario is deleted with identifier " + id, id)) + .build(); + } + +} diff --git a/src/main/resources/config/liquibase/epasmed/changelog/00000000000000_initial_schema.xml b/src/main/resources/config/liquibase/epasmed/changelog/00000000000000_initial_schema.xml index efb4fca..f43e598 100755 --- a/src/main/resources/config/liquibase/epasmed/changelog/00000000000000_initial_schema.xml +++ b/src/main/resources/config/liquibase/epasmed/changelog/00000000000000_initial_schema.xml @@ -240,4 +240,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +