Skip to content

Commit

Permalink
Aggiunto servizio REST per esportazione lista delle sedi.
Browse files Browse the repository at this point in the history
Aggiunto campo externalId ai tipi di assenza.
Nell'esportazione via REST del riepilogo mensile dei dipendenti aggiunto
nuovo campo externalId del tipo di assenza.
  • Loading branch information
criluc committed Mar 6, 2024
1 parent d4df9a9 commit 9f4b584
Show file tree
Hide file tree
Showing 20 changed files with 185 additions and 33 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [2.14.0] - UNRELEASED
### Added
- Aggiunto piano ferie 15+2

- Aggiunto servizio REST per esportazione lista delle sedi
- Aggiunto campo externalId ai tipi di assenza

### Changed
- Corretta lista persone in Straordinario mensili gruppo, filtrando le persone non più affiliate
- Cambiata la gestione dei codici 71D e seguenti con la stessa logica del 7M
- Corretta possibilità di inserire più richieste di cambio reperibilità non ancora confermate nello stesso mese

- Nell'esportazione via REST del riepilogo mensile dei dipendenti aggiunto nuovo campo externalId del tipo di assenza

## [2.13.0] - 2024-02-13
### Added
Expand Down
7 changes: 4 additions & 3 deletions app/cnr/sync/dto/v3/AbsenceShowTerseDto.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 Consiglio Nazionale delle Ricerche
* Copyright (C) 2024 Consiglio Nazionale delle Ricerche
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand All @@ -14,7 +14,6 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package cnr.sync.dto.v3;

import com.fasterxml.jackson.annotation.JsonIgnore;
Expand Down Expand Up @@ -49,8 +48,9 @@ public class AbsenceShowTerseDto {
private String justifiedType;
private String note;
private String externalId;
private String externalTypeId;
private LocalDateTime updatedAt;

@JsonIgnore
@Inject
static ModelMapper modelMapper;
Expand All @@ -69,6 +69,7 @@ public static AbsenceShowTerseDto build(Absence absence) {
absenceDto.setDate(JodaConverters.jodaToJavaLocalDate(absence.getAbsenceDate()));
if (absence.getAbsenceType() != null) {
absenceDto.setAbsenceTypeId(absence.getAbsenceType().getId());
absenceDto.setExternalTypeId(absence.getAbsenceType().getExternalId());
}
return absenceDto;
}
Expand Down
82 changes: 82 additions & 0 deletions app/cnr/sync/dto/v3/OfficeShowTerseDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (C) 2024 Consiglio Nazionale delle Ricerche
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package cnr.sync.dto.v3;

import cnr.sync.dto.v2.GroupShowDto;
import cnr.sync.dto.v2.PersonShowTerseDto;
import helpers.validators.PeriodEndDateCheck;
import java.time.LocalDateTime;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.validation.constraints.NotNull;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.val;
import models.Institute;
import models.Office;
import models.Person;
import org.joda.time.LocalDate;
import org.modelmapper.ModelMapper;
import play.data.validation.CheckWith;
import play.data.validation.Required;
import play.data.validation.Unique;

/**
* Dati esportati in Json per l'Ufficio.
*
* @author Cristian Lucchesi
*
*/
@ToString
@Data
public class OfficeShowTerseDto {

private Long id;
private Long perseoId;
private String name;

//Codice della sede, per esempio per la sede di Pisa è "044000"
private String code;

//sedeId, serve per l'invio degli attestati, per esempio per la sede di Pisa è "223400"
private String codeId;
private String address;
private LocalDate joiningDate;
private LocalDate beginDate;
private LocalDate endDate;

private Long instituteId;
private boolean headQuarter = false;
private LocalDateTime updatedAt;

/**
* Nuova instanza di un OfficeShowTerseDto contenente i valori
* dell'oggetto Office passato.
*/
public static OfficeShowTerseDto build(Office office) {
ModelMapper modelMapper = new ModelMapper();
modelMapper.getConfiguration().setAmbiguityIgnored(true);
val officeDto = modelMapper.map(office, OfficeShowTerseDto.class);
if (office.getInstitute() != null) {
officeDto.setInstituteId(office.getInstitute().getId());
}
return officeDto;
}
}
3 changes: 1 addition & 2 deletions app/cnr/sync/dto/v3/PersonDayShowDto.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Consiglio Nazionale delle Ricerche
* Copyright (C) 2024 Consiglio Nazionale delle Ricerche
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand All @@ -14,7 +14,6 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package cnr.sync.dto.v3;

import cnr.sync.dto.v2.PersonShowTerseDto;
Expand Down
1 change: 1 addition & 0 deletions app/controllers/rest/v2/Groups.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.gson.GsonBuilder;
import common.security.SecurityRules;
import controllers.Resecure;
import controllers.rest.v3.Offices;
import dao.GroupDao;
import helpers.JsonResponse;
import helpers.rest.RestUtils;
Expand Down
1 change: 1 addition & 0 deletions app/controllers/rest/v2/Leaves.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.gson.GsonBuilder;
import common.security.SecurityRules;
import controllers.Resecure;
import controllers.rest.v3.Offices;
import dao.AbsenceDao;
import dao.PersonDao;
import helpers.JodaConverters;
Expand Down
1 change: 1 addition & 0 deletions app/controllers/rest/v2/Persons.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import common.security.SecurityRules;
import controllers.Resecure;
import controllers.Resecure.BasicAuth;
import controllers.rest.v3.Offices;
import dao.PersonDao;
import helpers.JodaConverters;
import helpers.JsonResponse;
Expand Down
1 change: 1 addition & 0 deletions app/controllers/rest/v2/WorkingTimeTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.gson.GsonBuilder;
import common.security.SecurityRules;
import controllers.Resecure;
import controllers.rest.v3.Offices;
import dao.WorkingTimeTypeDao;
import helpers.JsonResponse;
import helpers.rest.RestUtils;
Expand Down
1 change: 0 additions & 1 deletion app/controllers/rest/v3/BadgeReaders.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.gson.GsonBuilder;
import common.security.SecurityRules;
import controllers.Resecure;
import controllers.rest.v2.Offices;
import dao.BadgeReaderDao;
import helpers.JsonResponse;
import helpers.rest.RestUtils;
Expand Down
1 change: 0 additions & 1 deletion app/controllers/rest/v3/BadgeSystems.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.gson.GsonBuilder;
import common.security.SecurityRules;
import controllers.Resecure;
import controllers.rest.v2.Offices;
import dao.BadgeSystemDao;
import helpers.JsonResponse;
import helpers.rest.RestUtils;
Expand Down
1 change: 0 additions & 1 deletion app/controllers/rest/v3/Badges.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.google.gson.GsonBuilder;
import common.security.SecurityRules;
import controllers.Resecure;
import controllers.rest.v2.Offices;
import controllers.rest.v2.Persons;
import dao.BadgeDao;
import dao.BadgeSystemDao;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Consiglio Nazionale delle Ricerche
* Copyright (C) 2024 Consiglio Nazionale delle Ricerche
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand All @@ -14,15 +14,26 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package controllers.rest.v3;

package controllers.rest.v2;

import cnr.sync.dto.v3.OfficeShowTerseDto;
import com.beust.jcommander.internal.Lists;
import com.google.common.base.Optional;
import com.google.gson.GsonBuilder;
import common.security.SecurityRules;
import controllers.Resecure;
import controllers.Resecure.BasicAuth;
import dao.OfficeDao;
import helpers.JodaConverters;
import helpers.JsonResponse;
import helpers.rest.RestUtils;
import helpers.rest.RestUtils.HttpMethod;
import it.cnr.iit.epas.DateUtility;
import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;
import javax.inject.Inject;
import lombok.val;
import lombok.extern.slf4j.Slf4j;
import models.Office;
import play.mvc.Controller;
Expand All @@ -40,6 +51,38 @@ public class Offices extends Controller {
static OfficeDao officeDao;
@Inject
static SecurityRules rules;
@Inject
static GsonBuilder gsonBuilder;

/**
* Lista JSON delle persone che appartengono alla sede
* individuata con i parametri passati.
*/
@BasicAuth
public static void all(LocalDate atDate) {
RestUtils.checkMethod(request, HttpMethod.GET);
log.debug("rest.Offices::all atDate = {}", atDate);
List<Office> offices = Lists.newArrayList();
if (atDate != null) {
offices = officeDao.allOffices(JodaConverters.javaToJodaLocalDate(atDate));
} else {
offices = officeDao.allEnabledOffices();
}
val list =
offices.stream().map(o -> OfficeShowTerseDto.build(o)).collect(Collectors.toList());
renderJSON(gsonBuilder.create().toJson(list));
}

/**
* Restituisce il JSON con i dati dell'ufficio individuato con i parametri
* passati.
*/
public static void show(Long id, String code, String codeId) {
RestUtils.checkMethod(request, HttpMethod.GET);
val office = getOfficeFromRequest(id, code, codeId);
rules.checkIfPermitted(office);
renderJSON(gsonBuilder.create().toJson(OfficeShowTerseDto.build(office)));
}

/**
* Cerca l'ufficio in funzione dei parametri passati.
Expand Down
28 changes: 13 additions & 15 deletions app/controllers/rest/v3/PersonDays.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Consiglio Nazionale delle Ricerche
* Copyright (C) 2024 Consiglio Nazionale delle Ricerche
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand All @@ -14,7 +14,6 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package controllers.rest.v3;

import cnr.sync.dto.v2.PersonShowTerseDto;
Expand All @@ -29,7 +28,6 @@
import common.security.SecurityRules;
import controllers.PersonDays.MealTicketDecision;
import controllers.Resecure;
import controllers.rest.v2.Offices;
import controllers.rest.v2.Persons;
import dao.PersonDao;
import dao.PersonDayDao;
Expand All @@ -43,8 +41,8 @@
import java.util.Set;
import java.util.stream.Collectors;
import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import lombok.extern.slf4j.Slf4j;
import manager.ConsistencyManager;
import manager.PersonManager;
import models.Office;
Expand Down Expand Up @@ -120,7 +118,7 @@ public static void getMonthSituationByOffice(Long id, String code, String codeId
}
val office =
Offices.getOfficeFromRequest(id, code, Strings.isNullOrEmpty(codeId) ? sedeId : codeId);
rules.checkIfPermitted(office);
rules.checkIfPermitted(office);

org.joda.time.LocalDate date = new org.joda.time.LocalDate(year, month, 1);

Expand All @@ -132,15 +130,15 @@ public static void getMonthSituationByOffice(Long id, String code, String codeId
personDays.stream().collect(Collectors.groupingBy(PersonDay::getPerson));

List<PersonMonthRecapDto> monthRecaps = Lists.newArrayList();
personDayMap.forEach((p, pds) -> {
monthRecaps.add(PersonMonthRecapDto.builder()
.person(PersonShowTerseDto.build(p))
.year(year).month(month)
.personDays(
pds.stream().map(pd -> PersonDayShowTerseDto.build(pd))
.collect(Collectors.toList()))
.build());
});
personDayMap.forEach((p, pds) -> {
monthRecaps.add(PersonMonthRecapDto.builder()
.person(PersonShowTerseDto.build(p))
.year(year).month(month)
.personDays(
pds.stream().map(pd -> PersonDayShowTerseDto.build(pd))
.collect(Collectors.toList()))
.build());
});

val gson = gsonBuilder.create();
renderJSON(gson.toJson(monthRecaps));
Expand Down Expand Up @@ -205,7 +203,7 @@ public static void getMonthSituationByPerson(Long id, String email, String eppn,
.collect(Collectors.toList()))
.build();
val gson = gsonBuilder.create();
renderJSON(gson.toJson(monthRecap));
renderJSON(gson.toJson(monthRecap));
}

/**
Expand Down
7 changes: 7 additions & 0 deletions app/dao/OfficeDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,11 @@ public List<Office> allEnabledOffices() {
.or(office.endDate.after(LocalDate.now()))).fetch();
}

public List<Office> allOffices(LocalDate atDate) {
final QOffice office = QOffice.office;
BooleanBuilder conditions = new BooleanBuilder(office.beginDate.before(atDate));
conditions.and(office.endDate.isNull().or(office.endDate.after(atDate)));
return queryFactory.selectFrom(office).where(conditions).fetch();
}

}
5 changes: 3 additions & 2 deletions app/helpers/LocalDateJavaBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
public class LocalDateJavaBinder implements TypeBinder<LocalDate> {

//Questo formato è utilizzato nelle form HTML
static final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/yyyy");
static final String ITALIAN_DATE_PATTERN = "dd/MM/yyyy";
static final DateTimeFormatter dtf = DateTimeFormatter.ofPattern(ITALIAN_DATE_PATTERN);

@SuppressWarnings("rawtypes")
@Override
Expand All @@ -45,7 +46,7 @@ public Object bind(String name, Annotation[] annotations, String value,
try {
return LocalDate.parse(value, dtf);
} catch (Exception ignored) {
log.debug("Exception during java LocalDate binding, value={}", value);
log.debug("Enable to bind java LocalDate using pattern {}, value={}", ITALIAN_DATE_PATTERN, value);
}
//Nei metodi REST le date vengono passate nel formato ISO
return LocalDate.from(DateTimeFormatter.ISO_LOCAL_DATE.parse(value));
Expand Down
Loading

0 comments on commit 9f4b584

Please sign in to comment.