diff --git a/fenixedu-ist-giaf-contracts/src/main/java/pt/ist/fenixedu/contracts/service/UpdateTeacherAuthorizationsForSemesterFromSap.java b/fenixedu-ist-giaf-contracts/src/main/java/pt/ist/fenixedu/contracts/service/UpdateTeacherAuthorizationsForSemesterFromSap.java index 776d9d14b7f..c2a58b6bad0 100644 --- a/fenixedu-ist-giaf-contracts/src/main/java/pt/ist/fenixedu/contracts/service/UpdateTeacherAuthorizationsForSemesterFromSap.java +++ b/fenixedu-ist-giaf-contracts/src/main/java/pt/ist/fenixedu/contracts/service/UpdateTeacherAuthorizationsForSemesterFromSap.java @@ -43,7 +43,7 @@ public class UpdateTeacherAuthorizationsForSemesterFromSap { private static final int minimumDaysForActivity = 90; - private Map categoryMap = new HashMap(); + private Map categoryMap = new HashMap<>(); public String updateTeacherAuthorization(ExecutionSemester executionSemester) { StringBuilder output = new StringBuilder(); @@ -55,8 +55,8 @@ public String updateTeacherAuthorization(ExecutionSemester executionSemester) { final SapStaff sapStaff = new SapStaff(); final SapStructure sapStructure = new SapStructure(); - Map userDepartment = new HashMap(); - Map> colaboratorSituationsMap = new HashMap>(); + Map userDepartment = new HashMap<>(); + Map> colaboratorSituationsMap = new HashMap<>(); final JsonObject params = new JsonObject(); params.addProperty("institution", SapSdkConfiguration.getConfiguration().sapServiceInstitutionCode()); @@ -69,7 +69,7 @@ public String updateTeacherAuthorization(ExecutionSemester executionSemester) { Set colaboratorSituations = colaboratorSituationsMap.get(user); if (colaboratorSituations == null) { - colaboratorSituations = new HashSet(); + colaboratorSituations = new HashSet<>(); } colaboratorSituations.add(colaboratorSituation); colaboratorSituationsMap.put(user, colaboratorSituations); @@ -92,7 +92,7 @@ public String updateTeacherAuthorization(ExecutionSemester executionSemester) { } }); - Set processedAuthorizations = new HashSet(); + Set processedAuthorizations = new HashSet<>(); for (User user : colaboratorSituationsMap.keySet()) { Person person = user.getPerson(); @@ -118,10 +118,26 @@ public String updateTeacherAuthorization(ExecutionSemester executionSemester) { teacherCategory); TeacherAuthorization existing = teacher .getTeacherAuthorization(executionSemester.getAcademicInterval()).orElse(null); + + Space campus = null; + + switch (colaboratorSituation.campus()) { + case "Alameda": + campus = FenixFramework.getDomainObject("2448131360897"); + break; + case "Tagus Park": + campus = FenixFramework.getDomainObject("2448131360898"); + break; + case "CTN": + campus = FenixFramework.getDomainObject("2448131392438"); + break; + } + if (existing != null) { if (existing.getDepartment().equals(department) && existing.isContracted() && existing.getLessonHours().equals(lessonHours) - && existing.getTeacherCategory().equals(teacherCategory)) { + && existing.getTeacherCategory().equals(teacherCategory) + && existing.getCampus().equals(campus)) { teacherAuthorization = existing; } else { countEdited++; @@ -131,18 +147,6 @@ public String updateTeacherAuthorization(ExecutionSemester executionSemester) { countNew++; } if (teacherAuthorization == null) { - Space campus = null; - switch (colaboratorSituation.campus()) { - case "Alameda": - campus = FenixFramework.getDomainObject("2448131360897"); - break; - case "Tagus Park": - campus = FenixFramework.getDomainObject("2448131360898"); - break; - case "CTN": - campus = FenixFramework.getDomainObject("2448131392438"); - break; - } teacherAuthorization = TeacherAuthorization.createOrUpdate(teacher, department, executionSemester, teacherCategory, true, lessonHours, campus); } @@ -175,14 +179,10 @@ public String updateTeacherAuthorization(ExecutionSemester executionSemester) { private SortedSet getValidPersonContractSituations( Map> situationsMap, User user, Interval semesterInterval) { - SortedSet validPersonContractSituations = new TreeSet( - new Comparator() { - @Override - public int compare(ColaboratorSituation c1, ColaboratorSituation c2) { - int compare = c1.beginDate().compareTo(c2.beginDate()); - return compare == 0 ? (c1.equals(c2) ? 0 : 1) : compare; - } - }); + SortedSet validPersonContractSituations = new TreeSet<>((c1, c2) -> { + int compare = c1.beginDate().compareTo(c2.beginDate()); + return compare == 0 ? (c1.equals(c2) ? 0 : 1) : compare; + }); validPersonContractSituations.addAll(situationsMap.get(user).stream().filter(cs -> { return cs.inExercise() && !cs.endSituation() && isValidAndOverlaps(cs, semesterInterval) && isValidCategoryAndCategoryType(cs.categoryName(), cs.categoryTypeName());