Skip to content

Commit

Permalink
Merge pull request #670 from tiagoppinho/FIST-795
Browse files Browse the repository at this point in the history
Fix campus on Teacher Authorizations FIST-795 #resolve
  • Loading branch information
ricardorcr authored Aug 30, 2019
2 parents ff66d3f + a6d440a commit 106c1d4
Showing 1 changed file with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
public class UpdateTeacherAuthorizationsForSemesterFromSap {

private static final int minimumDaysForActivity = 90;
private Map<String, TeacherCategory> categoryMap = new HashMap<String, TeacherCategory>();
private Map<String, TeacherCategory> categoryMap = new HashMap<>();

public String updateTeacherAuthorization(ExecutionSemester executionSemester) {
StringBuilder output = new StringBuilder();
Expand All @@ -55,8 +55,8 @@ public String updateTeacherAuthorization(ExecutionSemester executionSemester) {
final SapStaff sapStaff = new SapStaff();
final SapStructure sapStructure = new SapStructure();

Map<User, Department> userDepartment = new HashMap<User, Department>();
Map<User, Set<ColaboratorSituation>> colaboratorSituationsMap = new HashMap<User, Set<ColaboratorSituation>>();
Map<User, Department> userDepartment = new HashMap<>();
Map<User, Set<ColaboratorSituation>> colaboratorSituationsMap = new HashMap<>();
final JsonObject params = new JsonObject();
params.addProperty("institution", SapSdkConfiguration.getConfiguration().sapServiceInstitutionCode());

Expand All @@ -69,7 +69,7 @@ public String updateTeacherAuthorization(ExecutionSemester executionSemester) {

Set<ColaboratorSituation> colaboratorSituations = colaboratorSituationsMap.get(user);
if (colaboratorSituations == null) {
colaboratorSituations = new HashSet<ColaboratorSituation>();
colaboratorSituations = new HashSet<>();
}
colaboratorSituations.add(colaboratorSituation);
colaboratorSituationsMap.put(user, colaboratorSituations);
Expand All @@ -92,7 +92,7 @@ public String updateTeacherAuthorization(ExecutionSemester executionSemester) {
}
});

Set<TeacherAuthorization> processedAuthorizations = new HashSet<TeacherAuthorization>();
Set<TeacherAuthorization> processedAuthorizations = new HashSet<>();

for (User user : colaboratorSituationsMap.keySet()) {
Person person = user.getPerson();
Expand All @@ -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++;
Expand All @@ -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);
}
Expand Down Expand Up @@ -175,14 +179,10 @@ public String updateTeacherAuthorization(ExecutionSemester executionSemester) {

private SortedSet<ColaboratorSituation> getValidPersonContractSituations(
Map<User, Set<ColaboratorSituation>> situationsMap, User user, Interval semesterInterval) {
SortedSet<ColaboratorSituation> validPersonContractSituations = new TreeSet<ColaboratorSituation>(
new Comparator<ColaboratorSituation>() {
@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<ColaboratorSituation> 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());
Expand Down

0 comments on commit 106c1d4

Please sign in to comment.