Skip to content

Commit

Permalink
Merge pull request #45 from consiglionazionaledellericerche/44-errore…
Browse files Browse the repository at this point in the history
…-durante-laggiornamento-dei-contratti-per-chiave-duplicata-in-contractmonthrecat

Corretta gestione merge e persist nell'aggiornamento contratti.
  • Loading branch information
criluc authored Sep 9, 2024
2 parents b6f3159 + bc5e719 commit a29488c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 22 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.1
0.4.2
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
@Configuration
@OpenAPIDefinition(
info = @Info(title = "ePAS Service",
version = "4.0.0-beta.2",
version = "4.0.0-beta.3",
description = "ePAS Service contains all the business logic and related REST endpoints"
+ " to manage all the personnel information."),
servers = {@Server(url = "/", description = "ePAS Service URL")}
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/it/cnr/iit/epas/dao/wrapper/WrapperContract.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@

package it.cnr.iit.epas.dao.wrapper;

import java.time.LocalDate;
import java.time.YearMonth;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import javax.inject.Inject;

import org.springframework.stereotype.Component;

import it.cnr.iit.epas.dao.AbsenceDao;
import it.cnr.iit.epas.models.Contract;
import it.cnr.iit.epas.models.ContractMonthRecap;
Expand All @@ -25,13 +35,6 @@
import it.cnr.iit.epas.models.absences.JustifiedType.JustifiedTypeName;
import it.cnr.iit.epas.utils.DateInterval;
import it.cnr.iit.epas.utils.DateUtility;
import java.time.LocalDate;
import java.time.YearMonth;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import javax.inject.Inject;
import org.springframework.stereotype.Component;

/**
* Contract con alcune funzionalità aggiuntive.
Expand Down
20 changes: 15 additions & 5 deletions src/main/java/it/cnr/iit/epas/manager/ConsistencyManagerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,11 @@ private ContractMonthRecap populateContractMonthFromSource(IWrapperContract cont
cmr.buoniPastoDaInizializzazione = 0;
cmr.remainingMealTickets = 0;
}
emp.get().persist(cmr);
if (emp.get().contains(cmr)) {
emp.get().merge(cmr);
} else {
emp.get().persist(cmr);
}
//cmr.save();
contract.getValue().contractMonthRecaps.add(cmr);
emp.get().merge(contract.getValue());
Expand All @@ -529,17 +533,24 @@ private ContractMonthRecap populateContractMonthFromSource(IWrapperContract cont
// Caso complesso, combinare inizializzazione e database.

ContractMonthRecap cmr = buildContractMonthRecap(contract, yearMonthToCompute);

contract.getValue().contractMonthRecaps.add(cmr);
emp.get().merge(cmr);
if (emp.get().contains(cmr)) {
emp.get().merge(cmr);
} else {
emp.get().persist(cmr);
}
//cmr.save();

// Informazioni relative ai residui
List<Absence> otherCompensatoryRest = Lists.newArrayList();
contractMonthRecapManager.computeResidualModule(cmr, Optional.<ContractMonthRecap>empty(),
yearMonthToCompute, LocalDate.now().minusDays(1), otherCompensatoryRest, Optional.empty());

emp.get().merge(cmr);
if (emp.get().contains(cmr)) {
emp.get().merge(cmr);
} else {
emp.get().persist(cmr);
}
//cmr.save();

emp.get().merge(contract.getValue());
Expand All @@ -556,7 +567,6 @@ private ContractMonthRecap buildContractMonthRecap(IWrapperContract contract,
YearMonth yearMonth) {

Optional<ContractMonthRecap> cmrOld = contract.getContractMonthRecap(yearMonth);

if (cmrOld.isPresent()) {
cmrOld.get().clean();
return cmrOld.get();
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/it/cnr/iit/epas/manager/ContractManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public void recomputeContract(final Contract contract, final Optional<LocalDate>
// TODO: anche quelli sulle ferie quando ci saranno
for (ContractMonthRecap cmr : contract.contractMonthRecaps) {
if (!yearMonthFrom.isAfter(YearMonth.of(cmr.year, cmr.month))) {
if (cmr.getId() != null) {
if (emp.get().contains(cmr)) {
emp.get().remove(cmr);
}
}
Expand Down Expand Up @@ -554,13 +554,12 @@ public boolean applyPreviousContractLink(Contract contract, boolean linkedToPrev
}
} else {
Contract temp = contract.getPreviousContract();
if (temp == null) {
return false;
}
contract.setPreviousContract(null);
if (temp.getEndDate() != null
&& contract.getBeginDate().minusDays(1).isEqual(temp.getEndDate())) {
splitVacationPeriods(contract);
if (temp != null) {
contract.setPreviousContract(null);
if (temp.getEndDate() != null
&& contract.getBeginDate().minusDays(1).isEqual(temp.getEndDate())) {
splitVacationPeriods(contract);
}
}
}
return true;
Expand Down

0 comments on commit a29488c

Please sign in to comment.