diff --git a/src/main/java/it/cnr/iit/epas/controller/v4/AbsencesController.java b/src/main/java/it/cnr/iit/epas/controller/v4/AbsencesController.java index 02d57fc..9fc2904 100644 --- a/src/main/java/it/cnr/iit/epas/controller/v4/AbsencesController.java +++ b/src/main/java/it/cnr/iit/epas/controller/v4/AbsencesController.java @@ -169,11 +169,11 @@ public ResponseEntity secureCheck( @GetMapping(ApiRoutes.SHOW) public ResponseEntity 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 involvedGroups = absence.absenceType.involvedGroupAbsenceType(true); List objectAll = Lists.newArrayList(); diff --git a/src/main/java/it/cnr/iit/epas/controller/v4/AbsencesGroupsController.java b/src/main/java/it/cnr/iit/epas/controller/v4/AbsencesGroupsController.java index 81e3a1e..5886786 100644 --- a/src/main/java/it/cnr/iit/epas/controller/v4/AbsencesGroupsController.java +++ b/src/main/java/it/cnr/iit/epas/controller/v4/AbsencesGroupsController.java @@ -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; @@ -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; @@ -105,6 +109,7 @@ @RequestMapping(ApiRoutes.BASE_PATH + "/absencesGroups") public class AbsencesGroupsController { + private final AbsenceGroupsRecapFactory absenceGroupsRecapFactory; private final AbsenceGroupsMapper absenceGroupsMapper; private final AbsenceFormMapper absenceFormMapper; @@ -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. @@ -183,8 +189,10 @@ public ResponseEntity groupStatus( absGroupDto.setPeriodChain(newPeriodChain); List 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); diff --git a/src/main/java/it/cnr/iit/epas/dto/v4/AbsenceGroupsDto.java b/src/main/java/it/cnr/iit/epas/dto/v4/AbsenceGroupsDto.java index 135caee..4c1a6c0 100644 --- a/src/main/java/it/cnr/iit/epas/dto/v4/AbsenceGroupsDto.java +++ b/src/main/java/it/cnr/iit/epas/dto/v4/AbsenceGroupsDto.java @@ -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 groups; } \ No newline at end of file diff --git a/src/main/java/it/cnr/iit/epas/dto/v4/mapper/AbsenceGroupMapper.java b/src/main/java/it/cnr/iit/epas/dto/v4/mapper/AbsenceGroupMapper.java index f847af1..e158b3f 100644 --- a/src/main/java/it/cnr/iit/epas/dto/v4/mapper/AbsenceGroupMapper.java +++ b/src/main/java/it/cnr/iit/epas/dto/v4/mapper/AbsenceGroupMapper.java @@ -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())") @@ -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); diff --git a/src/main/java/it/cnr/iit/epas/dto/v4/mapper/AbsenceGroupsMapper.java b/src/main/java/it/cnr/iit/epas/dto/v4/mapper/AbsenceGroupsMapper.java index 20aa646..31c740e 100644 --- a/src/main/java/it/cnr/iit/epas/dto/v4/mapper/AbsenceGroupsMapper.java +++ b/src/main/java/it/cnr/iit/epas/dto/v4/mapper/AbsenceGroupsMapper.java @@ -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; @@ -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; @@ -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") diff --git a/src/main/java/it/cnr/iit/epas/dto/v4/mapper/AbsenceMapper.java b/src/main/java/it/cnr/iit/epas/dto/v4/mapper/AbsenceMapper.java index 98360f8..0ec5ea7 100644 --- a/src/main/java/it/cnr/iit/epas/dto/v4/mapper/AbsenceMapper.java +++ b/src/main/java/it/cnr/iit/epas/dto/v4/mapper/AbsenceMapper.java @@ -50,7 +50,7 @@ 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); @@ -58,7 +58,7 @@ 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 = "nothingJustified", expression = "java(absence.nothingJustified())") @Mapping(target = "date", expression = "java(absence.getAbsenceDate())") public abstract AbsenceShowTerseDto convertTerse(Absence absence); diff --git a/src/main/java/it/cnr/iit/epas/manager/recaps/absencegroups/AbsenceGroupsRecap.java b/src/main/java/it/cnr/iit/epas/manager/recaps/absencegroups/AbsenceGroupsRecap.java index 29f61f6..e5b17ca 100644 --- a/src/main/java/it/cnr/iit/epas/manager/recaps/absencegroups/AbsenceGroupsRecap.java +++ b/src/main/java/it/cnr/iit/epas/manager/recaps/absencegroups/AbsenceGroupsRecap.java @@ -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; /** @@ -46,15 +50,16 @@ 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(); @@ -62,20 +67,20 @@ public AbsenceGroupsRecap(AbsenceComponentDao absenceComponentDao, periodChain = absenceService.residual(person, groupAbsenceType, from); //se l'user รจ amministratore visualizzo lo switcher del gruppo - // Optional 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 = {}", diff --git a/src/main/java/it/cnr/iit/epas/manager/recaps/absencegroups/AbsenceGroupsRecapFactory.java b/src/main/java/it/cnr/iit/epas/manager/recaps/absencegroups/AbsenceGroupsRecapFactory.java index 3bf734b..7e502b3 100644 --- a/src/main/java/it/cnr/iit/epas/manager/recaps/absencegroups/AbsenceGroupsRecapFactory.java +++ b/src/main/java/it/cnr/iit/epas/manager/recaps/absencegroups/AbsenceGroupsRecapFactory.java @@ -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; @@ -30,18 +32,22 @@ @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; } /** @@ -49,8 +55,8 @@ public class AbsenceGroupsRecapFactory { */ 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); } }