Skip to content

Commit

Permalink
Merge pull request #48 from consiglionazionaledellericerche/47-campi-…
Browse files Browse the repository at this point in the history
…mancanti-nel-dto-absencegroupsdto

aggiunti campi mancanti a dto AbsenceGroupsDto e sostituito metodo per valorizzare justifiedTime
  • Loading branch information
criluc authored Oct 7, 2024
2 parents a29488c + 23e78a4 commit ae2e6e6
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ public ResponseEntity<Boolean> secureCheck(
@GetMapping(ApiRoutes.SHOW)
public ResponseEntity<AbsenceShowDto> show(@NotNull @PathVariable("id") Long id) {
log.debug("AbsenceController::show id = {}", id);
val absence = absenceDao.byId(id)
Absence absence = absenceDao.byId(id)
.orElseThrow(() -> new EntityNotFoundException("Absence not found"));

rules.checkifPermitted(absence.getPersonDay().getPerson());

Set<GroupAbsenceType> involvedGroups = absence.absenceType.involvedGroupAbsenceType(true);
List<Object> objectAll = Lists.newArrayList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import it.cnr.iit.epas.dao.AbsenceTypeDao;
import it.cnr.iit.epas.dao.CategoryTabDao;
import it.cnr.iit.epas.dao.GroupAbsenceTypeDao;
import it.cnr.iit.epas.dao.UserDao;
import it.cnr.iit.epas.dao.absences.AbsenceComponentDao;
import it.cnr.iit.epas.dto.v4.AbsenceFormDto;
import it.cnr.iit.epas.dto.v4.AbsenceFormSaveDto;
Expand All @@ -59,12 +60,15 @@
import it.cnr.iit.epas.manager.services.absences.model.AbsencePeriod;
import it.cnr.iit.epas.manager.services.absences.model.DayInPeriod;
import it.cnr.iit.epas.manager.services.absences.model.DayInPeriod.TemplateRow;
import it.cnr.iit.epas.manager.services.absences.model.PeriodChain;
import it.cnr.iit.epas.models.Person;
import it.cnr.iit.epas.models.User;
import it.cnr.iit.epas.models.absences.AbsenceType;
import it.cnr.iit.epas.models.absences.CategoryGroupAbsenceType;
import it.cnr.iit.epas.models.absences.CategoryTab;
import it.cnr.iit.epas.models.absences.GroupAbsenceType;
import it.cnr.iit.epas.models.absences.JustifiedType;
import it.cnr.iit.epas.security.SecureUtils;
import it.cnr.iit.epas.security.SecurityRules;
import java.time.LocalDate;
import java.util.HashMap;
Expand Down Expand Up @@ -105,6 +109,7 @@
@RequestMapping(ApiRoutes.BASE_PATH + "/absencesGroups")
public class AbsencesGroupsController {


private final AbsenceGroupsRecapFactory absenceGroupsRecapFactory;
private final AbsenceGroupsMapper absenceGroupsMapper;
private final AbsenceFormMapper absenceFormMapper;
Expand All @@ -117,6 +122,7 @@ public class AbsencesGroupsController {
private final AbsenceManager absenceManager;
private final PersonFinder personFinder;
private final SecurityRules rules;
private final SecureUtils securityUtils;

/**
* Elenco delle assenze in un mese.
Expand Down Expand Up @@ -183,8 +189,10 @@ public ResponseEntity<AbsenceGroupsDto> groupStatus(
absGroupDto.setPeriodChain(newPeriodChain);

List<GroupAbsenceTypeDto> groupAbsenceTypeDto = Lists.newArrayList();
for (GroupAbsenceType gr : psrDto.categorySwitcher.groups()) {
groupAbsenceTypeDto.add(absenceGroupsMapper.convertGroupAbsenceType(gr));
if (psrDto.categorySwitcher != null) {
for (GroupAbsenceType gr : psrDto.categorySwitcher.groups()) {
groupAbsenceTypeDto.add(absenceGroupsMapper.convertGroupAbsenceType(gr));
}
}
absGroupDto.setGroups(groupAbsenceTypeDto);

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/it/cnr/iit/epas/dto/v4/AbsenceGroupsDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class AbsenceGroupsDto {
private LocalDate from;
private GroupAbsenceTypeDto groupAbsenceType;
private PeriodChainDto periodChain;
private boolean isAdmin;
private boolean admin;
private AbsenceFormDto categorySwitcher;
private List<GroupAbsenceTypeDto> groups;
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public abstract class AbsenceGroupMapper {
@Mapping(target = "justifiedType", source = "absence.justifiedType.name")
@Mapping(target = "externalId", source = "absence.externalIdentifier")
@Mapping(target = "justifiedTime",
expression = "java(absenceManager.getJustifiedMinutes(absence))")
expression = "java(absence.justifiedTime())")
@Mapping(target = "date", expression = "java(absence.getAbsenceDate())")
@Mapping(target = "replacingAbsencesGroup", source = "replacingAbsencesGroup")
@Mapping(target = "nothingJustified", expression = "java(absence.nothingJustified())")
Expand All @@ -60,7 +60,7 @@ public abstract class AbsenceGroupMapper {
@Mapping(target = "justifiedType", source = "absence.justifiedType.name")
@Mapping(target = "externalId", source = "absence.externalIdentifier")
@Mapping(target = "justifiedTime",
expression = "java(absenceManager.getJustifiedMinutes(absence))")
expression = "java(absence.justifiedTime())")
@Mapping(target = "nothingJustified", expression = "java(absence.nothingJustified())")
@Mapping(target = "date", expression = "java(absence.getAbsenceDate())")
public abstract AbsenceShowTerseDto convertTerse(Absence absence);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package it.cnr.iit.epas.dto.v4.mapper;

import it.cnr.iit.epas.dto.v4.AbsenceFormDto;
import it.cnr.iit.epas.dto.v4.AbsenceGroupsDto;
import it.cnr.iit.epas.dto.v4.AbsencePeriodTerseDto;
import it.cnr.iit.epas.dto.v4.AbsenceShowDto;
Expand All @@ -25,14 +26,17 @@
import it.cnr.iit.epas.dto.v4.DayInPeriodDto;
import it.cnr.iit.epas.dto.v4.GroupAbsenceTypeDto;
import it.cnr.iit.epas.dto.v4.PeriodChainDto;
import it.cnr.iit.epas.dto.v4.PersonShowDto;
import it.cnr.iit.epas.dto.v4.TakenAbsenceDto;
import it.cnr.iit.epas.dto.v4.TemplateRowDto;
import it.cnr.iit.epas.manager.recaps.absencegroups.AbsenceGroupsRecap;
import it.cnr.iit.epas.manager.services.absences.AbsenceForm;
import it.cnr.iit.epas.manager.services.absences.model.AbsencePeriod;
import it.cnr.iit.epas.manager.services.absences.model.ComplationAbsence;
import it.cnr.iit.epas.manager.services.absences.model.DayInPeriod;
import it.cnr.iit.epas.manager.services.absences.model.PeriodChain;
import it.cnr.iit.epas.manager.services.absences.model.TakenAbsence;
import it.cnr.iit.epas.models.Person;
import it.cnr.iit.epas.models.absences.Absence;
import it.cnr.iit.epas.models.absences.GroupAbsenceType;
import it.cnr.iit.epas.models.absences.JustifiedType;
Expand Down Expand Up @@ -67,7 +71,19 @@ public interface AbsenceGroupsMapper {

@Mapping(target = "absence.justifiedType", source = "absence.justifiedType.name")
ComplationAbsenceDto convert(ComplationAbsence complationAbsence);

@Mapping(target = "qualification", source = "person.qualification.id")
PersonShowDto convert(Person person);
@Mapping(target = "justifiedTypeSelected", source = "justifiedTypeSelected.name")
@Mapping(target = "hasGroupChoice", expression = "java(absenceForm.hasGroupChoice())")
@Mapping(target = "hasAbsenceTypeChoice", expression = "java(absenceForm.hasAbsenceTypeChoice())")
@Mapping(target = "hasJustifiedTypeChoice", expression = "java(absenceForm.hasJustifiedTypeChoice())")
// @Mapping(target = "theOnlyAbsenceType", expression = "java(absenceForm.theOnlyAbsenceType().getId())")
@Mapping(target = "hasHourMinutesChoice", expression = "java(absenceForm.hasHourMinutesChoice())")
@Mapping(target = "selectableHours", expression = "java(absenceForm.selectableHours())")
@Mapping(target = "selectableMinutes", expression = "java(absenceForm.selectableMinutes())")
AbsenceFormDto convert(AbsenceForm absenceForm);

@Mapping(target = "admin", source = "absenceGroupsRecap.isAdmin")
AbsenceGroupsDto convert(AbsenceGroupsRecap absenceGroupsRecap);

@Mapping(target = "absence", source = "rowRecap.absence")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ public abstract class AbsenceMapper {
@Mapping(target = "justifiedType", source = "absence.justifiedType.name")
@Mapping(target = "externalId", source = "absence.externalIdentifier")
@Mapping(target = "justifiedTime",
expression = "java(absenceManager.getJustifiedMinutes(absence))")
expression = "java(absence.justifiedTime())")
@Mapping(target = "date", expression = "java(absence.getAbsenceDate())")
@Mapping(target = "nothingJustified", expression = "java(absence.nothingJustified())")
public abstract AbsenceShowDto convert(Absence absence);

@Mapping(target = "justifiedType", source = "absence.justifiedType.name")
@Mapping(target = "externalId", source = "absence.externalIdentifier")
@Mapping(target = "justifiedTime",
expression = "java(absenceManager.getJustifiedMinutes(absence))")
expression = "java(absence.justifiedTime())")
@Mapping(target = "nothingJustified", expression = "java(absence.nothingJustified())")
@Mapping(target = "date", expression = "java(absence.getAbsenceDate())")
public abstract AbsenceShowTerseDto convertTerse(Absence absence);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@

package it.cnr.iit.epas.manager.recaps.absencegroups;

import it.cnr.iit.epas.dao.UserDao;
import it.cnr.iit.epas.dao.absences.AbsenceComponentDao;
import it.cnr.iit.epas.manager.services.absences.AbsenceForm;
import it.cnr.iit.epas.manager.services.absences.AbsenceService;
import it.cnr.iit.epas.manager.services.absences.model.PeriodChain;
import it.cnr.iit.epas.models.Person;
import it.cnr.iit.epas.models.User;
import it.cnr.iit.epas.models.absences.GroupAbsenceType;
import it.cnr.iit.epas.security.SecureUtils;
import java.time.LocalDate;
import it.cnr.iit.epas.models.Role;
import lombok.extern.slf4j.Slf4j;

/**
Expand All @@ -46,36 +50,37 @@ public class AbsenceGroupsRecap {
* @param absenceComponentDao absenceComponentDao
* @param absenceService absenceService
*/
public AbsenceGroupsRecap(AbsenceComponentDao absenceComponentDao,
AbsenceService absenceService, Person person, Long groupAbsenceTypeId, LocalDate from) {
public AbsenceGroupsRecap(UserDao userDao, AbsenceComponentDao absenceComponentDao,
AbsenceService absenceService, Person person, Long groupAbsenceTypeId,
LocalDate from, SecureUtils securityUtils) {

final long start = System.currentTimeMillis();
log.trace("inizio AbsenceGroupsRecap. Person = {}, from = {}",
person.getFullname(), from);

this.from = from;
this.isAdmin = false;
isAdmin = false;

groupAbsenceType = absenceComponentDao.groupAbsenceTypeById(groupAbsenceTypeId);
groupAbsenceType = groupAbsenceType.firstOfChain();

periodChain = absenceService.residual(person, groupAbsenceType, from);

//se l'user è amministratore visualizzo lo switcher del gruppo
// Optional<User> user = secureUtils.getCurrentUser();
// if (currentUser.isSystemUser()
// || userDao.getUsersWithRoles(person.getOffice(),
// Role.PERSONNEL_ADMIN, Role.PERSONNEL_ADMIN_MINI)
// .contains(currentUser)) {
// this.isAdmin = true;
// }

if (!groupAbsenceType.isAutomatic()) {
//XXX
}
categorySwitcher = absenceService
.buildForCategorySwitch(person, from, groupAbsenceType);
User currentUser = securityUtils.getCurrentUser().get();
if (currentUser.isSystemUser()
|| userDao.getUsersWithRoles(person.getOffice(),
Role.PERSONNEL_ADMIN, Role.PERSONNEL_ADMIN_MINI)
.contains(currentUser)) {
isAdmin = true;
}

/*if (!groupAbsenceType.isAutomatic()) {
categorySwitcher = null;
} else {*/
categorySwitcher = absenceService
.buildForCategorySwitch(person, from, groupAbsenceType);
//}
log.debug(
"fine creazione nuovo AbsenceGroupsRecap in {} ms. "
+ "Person = {} groupAbsenceType = {}, from = {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

package it.cnr.iit.epas.manager.recaps.absencegroups;

import it.cnr.iit.epas.dao.UserDao;
import it.cnr.iit.epas.dao.absences.AbsenceComponentDao;
import it.cnr.iit.epas.manager.services.absences.AbsenceService;
import it.cnr.iit.epas.models.Person;
import it.cnr.iit.epas.security.SecureUtils;
import java.time.LocalDate;
import javax.inject.Inject;
import org.springframework.stereotype.Component;
Expand All @@ -30,27 +32,31 @@
@Component
public class AbsenceGroupsRecapFactory {

private final UserDao userDao;
private final AbsenceComponentDao absenceComponentDao;
private final AbsenceService absenceService;
private final SecureUtils securityUtils;

/**
* Costruttore per l'injection.
*/
@Inject
AbsenceGroupsRecapFactory(AbsenceComponentDao absenceComponentDao,
AbsenceService absenceService) {
AbsenceGroupsRecapFactory(UserDao userDao, AbsenceComponentDao absenceComponentDao,
AbsenceService absenceService, SecureUtils securityUtils) {

this.absenceComponentDao = absenceComponentDao;
this.userDao = userDao;
this.absenceService = absenceService;
this.securityUtils = securityUtils;
}

/**
* Costruisce il riepilogo delle absence groups.
*/
public AbsenceGroupsRecap create(Person person, Long groupAbsenceTypeId, LocalDate from) {

return new AbsenceGroupsRecap(absenceComponentDao, absenceService,
person, groupAbsenceTypeId, from);
return new AbsenceGroupsRecap(userDao, absenceComponentDao, absenceService,
person, groupAbsenceTypeId, from, securityUtils);
}

}

0 comments on commit ae2e6e6

Please sign in to comment.