--- /dev/null
+package com.pentila.entSavoie.synchroLdap.impl;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import com.liferay.contacts.util.OrganizationConstants;
+import com.liferay.portal.kernel.json.JSONFactoryUtil;
+import com.liferay.portal.kernel.log.Log;
+import com.liferay.portal.kernel.log.LogFactoryUtil;
+import com.liferay.portal.model.Organization;
+import com.liferay.portal.model.User;
+import com.liferay.portal.service.UserLocalServiceUtil;
+import com.pentila.entSavoie.groupAdmin.service.GroupAdminLocalServiceUtil;
+import com.pentila.entSavoie.internalMessaging.ThreadSendMessage;
+import com.pentila.entSavoie.synchroLdap.impl.SynchronizationManager.RoleEnum;
+import com.pentila.entSavoie.utils.ENTMainUtilsLocalServiceUtil;
+import com.pentila.entSavoie.utils.ENTOrganizationsUtil;
+
+/**
+ * Class used to generate a full report on the synchronization process
+ * @author Cedric Lecarpentier
+ *
+ */
+public class SynchronizationReport {
+
+ private static long companyId;
+
+ // User synchronization
+ private static int userSyncTime;
+
+ // Creation
+ private static int nbCreatedUsers;
+ private static Map<Long, List<User>> studentCreationMap;
+ private static Map<Long, List<User>> parentCreationMap;
+ private static Map<Long, List<User>> teacherCreationMap;
+ private static Map<Long, List<User>> otherCreationMap;
+
+ // Deactivation
+ private static int nbDeactivatedUsers;
+ private static Map<Long, List<User>> studentDeactivationMap;
+ private static Map<Long, List<User>> parentDeactivationMap;
+ private static Map<Long, List<User>> teacherDeactivationMap;
+ private static Map<Long, List<User>> otherDeactivationMap;
+
+ // Reactivation
+ private static int nbReactivatedUsers;
+ private static Map<Long, List<User>> studentReactivationMap;
+ private static Map<Long, List<User>> parentReactivationMap;
+ private static Map<Long, List<User>> teacherReactivationMap;
+ private static Map<Long, List<User>> otherReactivationMap;
+
+ // Group synchronization
+ private static int groupSyncTime;
+ private static int nbCreatedGroups;
+ private static int nbEmptyGroups;
+ private static int nbExpiredUsers;
+
+ // Student membership
+ private static int studentMembershipTime;
+ private static int nbStudentCreatedMemberships;
+ private static int nbStudentRemovedMemberships;
+ private static Map<Long, Map<Long, List<String>>> studentMembershipCreationMap;
+ private static Map<Long, Map<Long, List<String>>> studentMembershipRemovalMap;
+
+ // For each school id, the list of students entering the school
+ private static Map<Long, List<User>> studentIncommingSchoolMap;
+
+ // For each school id, the list of students leaving the school
+ private static Map<Long, List<User>> studentLeavingSchoolMap;
+
+
+ // Parent membership
+ private static int parentMembershipTime;
+ private static int nbParentCreatedMemberships;
+ private static int nbParentRemovedMemberships;
+
+ // Teacher membership
+ private static int teacherMembershipTime;
+ private static int nbTeacherCreatedMemberships;
+ private static int nbTeacherRemovedMemberships;
+ private static Map<Long, Map<Long, List<String>>> teacherMembershipCreationMap;
+ private static Map<Long, Map<Long, List<String>>> teacherMembershipRemovalMap;
+
+ // For each school id, the list of teachers entering the school
+ private static Map<Long, List<User>> teacherIncommingSchoolMap;
+
+ // For each school id, the list of teachers leaving the school
+ private static Map<Long, List<User>> teacherLeavingSchoolMap;
+
+ // Other profiles membership
+ private static int otherMembershipTime;
+ private static int nbOtherCreatedMemberships;
+ private static int nbOtherRemovedMemberships;
+
+ // For each school id, the list of other users entering the school
+ private static Map<Long, List<User>> otherIncommingSchoolMap;
+
+ // For each school id, the list of other users leaving the school
+ private static Map<Long, List<User>> otherLeavingSchoolMap;
+
+
+ // Child-parent map
+ private static Map<Long, List<Long>> childParentsMap;
+
+
+ /**
+ * Generate the report at the end of the synchronization process
+ * @return the report
+ */
+ public static String generateSynchroReport() {
+
+ String tab = " ";
+ String report = "";
+
+ report += "<b>User synchronization</b> took "+userSyncTime+" minutes: </br>";
+ report += tab + "Number of created users : " + nbCreatedUsers + "</br>";
+ report += tab + "Number of reactivated users : " + nbReactivatedUsers + "</br>";
+ report += tab + "Number of deactivated users : " + nbDeactivatedUsers + "</br></br>";
+
+ report += "<b>Group synchronization</b> took "+groupSyncTime+" minutes: </br>";
+ report += tab + "Number of created groups : " + nbCreatedGroups + "</br>";
+ report += tab + "Number of empty groups : " + nbEmptyGroups + "</br>";
+ report += tab + "Number of expired users : " + nbExpiredUsers + "</br></br>";
+
+ report += "<b>Student membership synchronization</b> took "+studentMembershipTime+" minutes: </br>";
+ report += tab + "Number of created memberships for students : " + nbStudentCreatedMemberships + "</br>";
+ report += tab + "Number of removed memberships for students : " + nbStudentRemovedMemberships + "</br></br>";
+
+ report += "<b>Parent membership synchronization</b> took "+parentMembershipTime+" minutes: </br>";
+ report += tab + "Number of created memberships for parents : " + nbParentCreatedMemberships + "</br>";
+ report += tab + "Number of removed memberships for parents : " + nbParentRemovedMemberships + "</br></br>";
+
+ report += "<b>Teacher membership synchronization</b> took "+teacherMembershipTime+" minutes: </br>";
+ report += tab + "Number of created memberships for teachers : " + nbTeacherCreatedMemberships + "</br>";
+ report += tab + "Number of removed memberships for teachers : " + nbTeacherRemovedMemberships + "</br></br>";
+
+ report += "<b>Other profiles membership synchronization</b> took "+otherMembershipTime+" minutes: </br>";
+ report += tab + "Number of created memberships for other profiles : " + nbOtherCreatedMemberships + "</br>";
+ report += tab + "Number of removed memberships for other profiles : " + nbOtherRemovedMemberships + "</br>";
+
+ return report;
+ }
+
+ /**
+ * Notify the creation of a user
+ * @param school : the user school
+ * @param student : the student
+ */
+ public static void notifyCreation(Organization school, User user, RoleEnum roleEnum) {
+
+ nbCreatedUsers++;
+ switch (roleEnum) {
+ case STUDENT_ROLE : addUserToMap(school, user, studentCreationMap); _log.info("notifyCreation student "+user.getFullName() + " for school "+school.getName()); break;
+ case PARENT_ROLE : addUserToMap(school, user, parentCreationMap); _log.info("notifyCreation parent "+user.getFullName() + " for school "+school.getName()); break;
+ case TEACHER_ROLE : addUserToMap(school, user, teacherCreationMap); _log.info("notifyCreation teacher "+user.getFullName() + " for school "+school.getName()); break;
+ case OTHER_ROLE : addUserToMap(school, user, otherCreationMap); _log.info("notifyCreation other "+user.getFullName() + " for school "+school.getName()); break;
+ }
+ }
+
+
+ /**
+ * Notify the reactivation of a user
+ * @param school : the user school
+ * @param student : the student
+ */
+ public static void notifyReactivation(Organization school, User user, RoleEnum roleEnum) {
+
+ nbReactivatedUsers++;
+ switch (roleEnum) {
+ case STUDENT_ROLE : addUserToMap(school, user, studentReactivationMap); _log.info("notifyReactivation student "+user.getFullName()); break;
+ case PARENT_ROLE : addUserToMap(school, user, parentReactivationMap); _log.info("notifyReactivation parent "+user.getFullName()); break;
+ case TEACHER_ROLE : addUserToMap(school, user, teacherReactivationMap); _log.info("notifyReactivation teacher "+user.getFullName()); break;
+ case OTHER_ROLE : addUserToMap(school, user, otherReactivationMap); _log.info("notifyReactivation other "+user.getFullName()); break;
+ }
+ }
+
+ /**
+ * Notify the deactivation of a user
+ * @param school : the user school
+ * @param user : the user
+ */
+ public static void notifyDeactivation(Organization school, User user, RoleEnum roleEnum) {
+
+ nbDeactivatedUsers++;
+ switch (roleEnum) {
+ case STUDENT_ROLE : addUserToMap(school, user, studentDeactivationMap); _log.info("notifyDeactivation student "+user.getFullName()); break;
+ case PARENT_ROLE : addUserToMap(school, user, parentDeactivationMap); _log.info("notifyDeactivation parent "+user.getFullName()); break;
+ case TEACHER_ROLE : addUserToMap(school, user, teacherDeactivationMap); _log.info("notifyDeactivation teacher "+user.getFullName()); break;
+ case OTHER_ROLE : addUserToMap(school, user, otherDeactivationMap); _log.info("notifyDeactivation other "+user.getFullName()); break;
+ }
+ }
+
+
+
+ /**
+ * Method that adds a user to the corresponding map
+ * @param school
+ * @param user
+ * @param map
+ */
+ private static void addUserToMap(Organization school, User user, Map<Long, List<User>> map) {
+
+ if (school != null) {
+ if (map.containsKey(school.getOrganizationId())) {
+ map.get(school.getOrganizationId()).add(user);
+ } else {
+ List<User> userList = new ArrayList<User>();
+ userList.add(user);
+ map.put(school.getOrganizationId(), userList);
+ }
+ }
+ }
+
+ /**
+ * Method that adds a student to the corresponding map
+ * @param school
+ * @param user
+ * @param schoolMap schoolId - userId - List of classGroup names
+ */
+ private static void addUserToClassMap(Organization school, User user, Organization classGroup, Map<Long, Map<Long, List<String>>> schoolMap) {
+
+ if (school != null) {
+
+ // Build group/class name
+ String classGroupName = classGroup.getName().substring(school.getName().length() + 3);
+
+ // Skip ' - Parents', '- Personnel' and '- Enseignants' organizations
+ if (classGroup.getName().endsWith(OrganizationConstants.ORG_SUFFIX_PARENTS) || classGroup.getName().endsWith(OrganizationConstants.ORG_SUFFIX_TEACHERS) || classGroup.getName().endsWith(OrganizationConstants.ORG_SUFFIX_PERSONNELS)) {
+ return;
+ }
+
+ Map<Long, List<String>> userMap;
+ if (schoolMap.containsKey(school.getOrganizationId())) {
+ userMap = schoolMap.get(school.getOrganizationId());
+ } else {
+ userMap = new HashMap<Long, List<String>>();
+ }
+
+ if (userMap.containsKey(user.getUserId())) {
+ // Avoid duplicate classes (for example classic class + same class as main teacher)
+ if (!userMap.get(user.getUserId()).contains(classGroupName)) {
+ userMap.get(user.getUserId()).add(classGroupName);
+ }
+ } else {
+ List<String> classGroupList = new ArrayList<String>();
+ classGroupList.add(classGroupName);
+ userMap.put(user.getUserId(), classGroupList);
+ }
+ schoolMap.put(school.getOrganizationId(), userMap);
+ }
+ }
+
+
+
+ /**
+ * Notify the creation of a student membership from a classGroup
+ * @param school : the student school
+ * @param student : the student
+ * @param classGroup : the organizationId of the class or group
+ */
+ public static void notifyStudentMembershipCreation(User student, Organization classGroup) {
+
+ nbStudentCreatedMemberships++;
+ try {
+ Organization parentOrg = classGroup.getParentOrganization();
+ if (parentOrg.getParentOrganizationId() == 0) {
+ _log.info("notifyStudentMembershipCreation : ClassGroup "+classGroup.getName()+" is a school : adding it to studentIncommingSchoolMap");
+ // classGroup is a school, then its parent is the root org, and then we add the teacher to the 'incoming' list for this school
+ if (studentIncommingSchoolMap.containsKey(classGroup.getOrganizationId())) {
+ studentIncommingSchoolMap.get(classGroup.getOrganizationId()).add(student);
+ _log.info("notifyStudentMembershipCreation : ClassGroup "+classGroup.getName()+" is a school : adding it to studentIncommingSchoolMap1 : "+classGroup.getOrganizationId()+" / "+student.getFullName());
+ } else {
+ List<User> userList = new ArrayList<User>();
+ userList.add(student);
+ studentIncommingSchoolMap.put(classGroup.getOrganizationId(), userList);
+ _log.info("notifyStudentMembershipCreation : ClassGroup "+classGroup.getName()+" is a school : adding it to studentIncommingSchoolMap2 : "+classGroup.getOrganizationId()+" / "+student.getFullName());
+ }
+ } else {
+ // classGroup is a class or a group, then its parent is the school
+ _log.info("notifyStudentMembershipCreation : ClassGroup "+classGroup.getName()+" is a class/group");
+ addUserToClassMap(parentOrg, student, classGroup, studentMembershipCreationMap);
+ }
+ } catch (Exception e) {
+ _log.error("Error when notifying student membership creation from org "+classGroup.getName(), e);
+ }
+
+ }
+
+
+ /**
+ * Notify the removal of a given student from a classGroup
+ * @param student : the student
+ * @param classGroup : the organizationId of the class or group
+ */
+ public static void notifyStudentMembershipRemoval(User student, Organization classGroup) {
+
+ nbStudentRemovedMemberships++;
+ try {
+ Organization parentOrg = classGroup.getParentOrganization();
+ if (parentOrg.getParentOrganizationId() == 0) {
+ _log.info("notifyStudentMembershipRemoval : ClassGroup "+classGroup.getName()+" is a school : adding it to studentLeavingSchoolMap");
+ // classGroup is a school, then its parent is the root org, and then we add the student to the 'incoming' list for this school
+ if (studentLeavingSchoolMap.containsKey(classGroup.getOrganizationId())) {
+ studentLeavingSchoolMap.get(classGroup.getOrganizationId()).add(student);
+ _log.info("notifyStudentMembershipRemoval : ClassGroup "+classGroup.getName()+" is a school : adding it to studentLeavingSchoolMap1 : "+classGroup.getOrganizationId()+" / "+student.getFullName());
+ } else {
+ List<User> userList = new ArrayList<User>();
+ userList.add(student);
+ studentLeavingSchoolMap.put(classGroup.getOrganizationId(), userList);
+ _log.info("notifyStudentMembershipRemoval : ClassGroup "+classGroup.getName()+" is a school : adding it to studentLeavingSchoolMap2 : "+classGroup.getOrganizationId()+" / "+student.getFullName());
+ }
+ } else {
+ // classGroup is a class or a group, then its parent is the school
+ _log.info("notifyStudentMembershipRemoval : ClassGroup "+classGroup.getName()+" is a class/group");
+ addUserToClassMap(parentOrg, student, classGroup, studentMembershipRemovalMap);
+ }
+ } catch (Exception e) {
+ _log.error("Error when notifying student membership removal from org "+classGroup.getName(), e);
+ }
+ }
+
+ /**
+ * Notify the creation of a teacher membership from a classGroup
+ * @param student : the teacher
+ * @param classGroup : the organizationId of the class or group
+ */
+ public static void notifyTeacherMembershipCreation(User teacher, Organization classGroup) {
+
+ nbTeacherCreatedMemberships++;
+ try {
+ Organization parentOrg = classGroup.getParentOrganization();
+ if (parentOrg.getParentOrganizationId() == 0) {
+ _log.debug("notifyTeacherMembershipCreation : ClassGroup "+classGroup.getName()+" is a school : adding it to teacherIncommingSchoolMap");
+ // classGroup is a school, then its parent is the root org, and then we add the teacher to the 'incoming' list for this school
+ if (teacherIncommingSchoolMap.containsKey(classGroup.getOrganizationId())) {
+ teacherIncommingSchoolMap.get(classGroup.getOrganizationId()).add(teacher);
+ _log.debug("notifyTeacherMembershipCreation : ClassGroup "+classGroup.getName()+" is a school : adding it to teacherIncommingSchoolMap1 : "+classGroup.getOrganizationId()+" / "+teacher.getFullName());
+ } else {
+ List<User> userList = new ArrayList<User>();
+ userList.add(teacher);
+ teacherIncommingSchoolMap.put(classGroup.getOrganizationId(), userList);
+ _log.debug("notifyTeacherMembershipCreation : ClassGroup "+classGroup.getName()+" is a school : adding it to teacherIncommingSchoolMap2 : "+classGroup.getOrganizationId()+" / "+teacher.getFullName());
+ }
+ } else {
+ // classGroup is a class or a group, then its parent is the school
+ _log.debug("notifyTeacherMembershipCreation : ClassGroup "+classGroup.getName()+" is a class/group");
+ addUserToClassMap(parentOrg, teacher, classGroup, teacherMembershipCreationMap);
+ }
+ } catch (Exception e) {
+ _log.error("Error when notifying teacher membership creation into org "+classGroup.getName(), e);
+ }
+
+ }
+
+
+ /**
+ * Notify the removal of a given teacher from a classGroup
+ * @param student : the teacher
+ * @param classGroup : the organizationId of the class or group
+ */
+ public static void notifyTeacherMembershipRemoval(User teacher, Organization classGroup) {
+
+ nbTeacherRemovedMemberships++;
+ try {
+ Organization parentOrg = classGroup.getParentOrganization();
+ if (parentOrg.getParentOrganizationId() == 0) {
+ // classGroup is a school, then its parent is the root org, and then we add the teacher to the 'leaving' list for this school
+ _log.info("notifyTeacherMembershipRemoval : ClassGroup "+classGroup.getName()+" is a school : adding it to teacherLeavingSchoolMap");
+ if (teacherLeavingSchoolMap.containsKey(classGroup.getOrganizationId())) {
+ teacherLeavingSchoolMap.get(classGroup.getOrganizationId()).add(teacher);
+ _log.info("notifyTeacherMembershipRemoval : ClassGroup "+classGroup.getName()+" is a school : adding it to teacherLeavingSchoolMap1 : "+classGroup.getOrganizationId()+" / "+teacher.getFullName());
+ } else {
+ List<User> userList = new ArrayList<User>();
+ userList.add(teacher);
+ teacherLeavingSchoolMap.put(classGroup.getOrganizationId(), userList);
+ _log.info("notifyTeacherMembershipRemoval : ClassGroup "+classGroup.getName()+" is a school : adding it to teacherLeavingSchoolMap2 : "+classGroup.getOrganizationId()+" / "+teacher.getFullName());
+ }
+ } else {
+ // classGroup is a class or a group, then its parent is the school
+ _log.info("notifyTeacherMembershipRemoval : ClassGroup "+classGroup.getName()+" is a class/group");
+ addUserToClassMap(parentOrg, teacher, classGroup, teacherMembershipRemovalMap);
+ }
+ } catch (Exception e) {
+ _log.error("Error when notifying teacher membership removal from org "+classGroup.getName(), e);
+ }
+ }
+
+ /**
+ * Notify the creation of a user membership from a classGroup
+ * @param student : the user
+ * @param classGroup : the organizationId of the class or group
+ */
+ public static void notifyOtherMembershipCreation(User user, Organization classGroup) {
+
+ nbOtherCreatedMemberships++;
+ try {
+ Organization parentOrg = classGroup.getParentOrganization();
+ if (parentOrg.getParentOrganizationId() == 0) {
+ // classGroup is a school, then its parent is the root org, and then we add the user to the 'incomming' list for this school
+ _log.info("notifyOtherMembershipCreation : ClassGroup "+classGroup.getName()+" is a school : adding it to otherIncommingSchoolMap");
+ if (otherIncommingSchoolMap.containsKey(classGroup.getOrganizationId())) {
+ otherIncommingSchoolMap.get(classGroup.getOrganizationId()).add(user);
+ } else {
+ List<User> userList = new ArrayList<User>();
+ userList.add(user);
+ otherIncommingSchoolMap.put(classGroup.getOrganizationId(), userList);
+ }
+ } else {
+ // classGroup is a school-level organization => do nothing
+ _log.info("notifyOtherMembershipCreation : ClassGroup "+classGroup.getName()+" is a school-level organization => do nothing");
+ }
+ } catch (Exception e) {
+ _log.error("Error when notifying other membership removal from org "+classGroup.getName(), e);
+ }
+ }
+
+
+ /**
+ * Notify the removal of a given user from a classGroup
+ * @param user : the user
+ * @param classGroup : the organizationId of the class or group
+ */
+ public static void notifyOtherMembershipRemoval(User user, Organization classGroup) {
+
+ nbOtherRemovedMemberships++;
+ try {
+ Organization parentOrg = classGroup.getParentOrganization();
+ if (parentOrg.getParentOrganizationId() == 0) {
+ // classGroup is a school, then its parent is the root org, and then we add the user to the 'leaving' list for this school
+ _log.info("notifyOtherMembershipRemoval : ClassGroup "+classGroup.getName()+" is a school : adding it to otherLeavingSchoolMap");
+ if (otherLeavingSchoolMap.containsKey(classGroup.getOrganizationId())) {
+ otherLeavingSchoolMap.get(classGroup.getOrganizationId()).add(user);
+ } else {
+ List<User> userList = new ArrayList<User>();
+ userList.add(user);
+ otherLeavingSchoolMap.put(classGroup.getOrganizationId(), userList);
+ }
+ } else {
+ // classGroup is a school-level organization => do nothing
+ _log.info("notifyOtherMembershipRemoval : ClassGroup "+classGroup.getName()+" is a school-level organization => do nothing");
+ }
+ } catch (Exception e) {
+ _log.error("Error when notifying parent membership removal from org "+classGroup.getName(), e);
+ }
+ }
+
+
+ /**
+ * Entry point for the report generation for school managers
+ */
+ public static void generateReportForSchoolManagers() {
+
+ try {
+ // Technical team user
+ Long defaultSender = ENTMainUtilsLocalServiceUtil.getEntConfirmationSenderId(companyId);
+ User admin = UserLocalServiceUtil.getUser(defaultSender);
+ String today = new SimpleDateFormat("dd/MM/yyyy").format(new Date());
+
+ //ResourceBundle messages = ResourceBundle.getBundle("content.Language", admin.getLocale());
+
+ // Get the school list
+ Organization rootOrg = ENTOrganizationsUtil.getOrCreateRootOrg(companyId);
+
+ // Loop over the map schools
+ for (Organization school : rootOrg.getSuborganizations()) {
+
+ if (!isEvolutionInSchool(school.getOrganizationId())) {
+ _log.info("No evolution to notice in school "+school.getName()+" => no report email sent");
+ continue;
+ }
+
+ // Get the list of school managers
+ List<User> schoolManagerList = getSchoolManagers(school);
+
+ Set<Long> recipientList = new HashSet<Long>();
+ for (User schoolManager : schoolManagerList) {
+ recipientList.add(schoolManager.getUserId());
+ }
+
+ // Build message subject and content
+ String reportSubject = "Rapport de synchronisation AAF du "+today;
+
+ String reportContent =
+ "<style>" +
+ " div.notification-container {width: 96%;border-radius: 5px 5px 5px 5px;border: 2px solid #8b9ea8;} " +
+ " div.notification-header {height: 17px;padding: 8px;font-size: 16px;color: #fff;background:#8b9ea8} " +
+ " .notification-content {margin: 8px;padding: 5px;font-family: \"Open sans\"}" +
+ "</style>" +
+ "<div class='notification-container'>"+
+ " <div class='notification-header'>Rapport de synchronisation</div>" +
+ " <p class='notification-content'>Bonjour,</p>" +
+ " <p class='notification-content'>" +
+ " Voici le rapport détaillé de la synchronisation des données AAF " +
+ "(Annuaire académique fédérateur) issues de vos bases STSWeb et " +
+ "Siècle à la date du " + today +
+ "</p>";
+
+ reportContent += generateStudentAndParentReport(school);
+ reportContent += generateTeacherReport(school);
+ reportContent += generateOtherReport(school);
+ reportContent += "</div>";
+
+ _log.info("Sending message for school "+school.getName()+" : report="+reportContent);
+ ThreadSendMessage message = new ThreadSendMessage(admin, recipientList, reportSubject, reportContent, JSONFactoryUtil.createJSONArray(), true, false);
+ message.start();
+
+ }
+ } catch (Exception e) {
+ _log.error("Error when sending report to school managers ", e);
+ }
+ }
+
+
+ /**
+ * Returns a list of recipeints for a given school : school managers + local admins
+ * @param school
+ * @return
+ */
+ private static List<User> getSchoolManagers(Organization school) {
+
+ List<User> schoolManagerList = new ArrayList<User>();
+
+ List<Organization> userOrgList = new ArrayList<Organization>();
+ userOrgList.add(school);
+
+ // Get local admins
+ List<User> localAdminList = GroupAdminLocalServiceUtil.getGroupAdminsFromEtab(userOrgList, companyId);
+ if (localAdminList != null) {
+ for (User adminUser : localAdminList) {
+ _log.info("Found local admin for school "+school.getName()+" : "+adminUser.getFullName());
+ schoolManagerList.add(adminUser);
+ }
+ } else {
+ _log.error("The retrieved local admin list is null for school "+school.getName());
+ }
+ return schoolManagerList;
+ }
+
+
+ /**
+ * Generate the report for students
+ * @param school
+ * @return
+ */
+ private static String generateStudentAndParentReport(Organization school) {
+ String studentReport = "";
+
+ try {
+
+ if (isStudentEvolution(school.getOrganizationId())) {
+
+ _log.info("there is student evolution");
+ studentReport += "<p class='notification-content'>";
+ studentReport += "<b>Elèves et responsables</b></br>";
+
+ // Incomming students
+ if (isStudentIncoming(school.getOrganizationId())) {
+ _log.info("there is student incomming");
+ List<User> incomingStudents = getIncommingStudents(school);
+
+ studentReport += "Entrées: ";
+ studentReport += SynchronizationUtils.printAsString(incomingStudents);
+ studentReport += "</br>";
+ }
+
+
+ // Leaving students
+ List<Long> leavingStudentList = new ArrayList<Long>();
+ if (isStudentLeaving(school.getOrganizationId())) {
+ _log.info("there is student leaving");
+ List<User> leavingStudents = getLeavingStudents(school);
+ for (User leavingStudent : leavingStudents) {
+ leavingStudentList.add(leavingStudent.getUserId());
+ }
+ studentReport += "Sorties: ";
+ studentReport += SynchronizationUtils.printAsString(leavingStudents);
+ }
+ studentReport += "</br>";
+
+
+ // Memberships
+ if (isStudentMembershipEvolution(school.getOrganizationId())) {
+
+ studentReport += "Mouvements dans les classes et groupes (hors sorties de l'établissement):</br>";
+
+ studentReport += "<table border=\"1\" style=\"width:100%\">";
+ studentReport += "<tr>";
+ studentReport += "<th>Elève</th>";
+ studentReport += "<th>Responsables</th>";
+ studentReport += "<th>Groupes et classes intégrés</th>";
+ studentReport += "<th>Groupes et classes quittés</th>";
+ studentReport += "</tr>";
+
+ List<Long> processedStudentList = new ArrayList<Long>();
+
+ // For each student : added memberships
+ if (isStudentMembershipCreation(school.getOrganizationId())) {
+ Map<Long, List<String>> studentMap = studentMembershipCreationMap.get(school.getOrganizationId());
+ if (studentMap != null && studentMap.keySet().size() > 0) {
+ for (Long studentId : studentMap.keySet()) {
+ processedStudentList.add(studentId);
+ try {
+ User student = UserLocalServiceUtil.getUser(studentId);
+
+ // Get removed memberships for this student
+ List<String> leftGroups = new ArrayList<String>();
+ if (isStudentMembershipRemoval(school.getOrganizationId()) && studentMembershipRemovalMap.get(school.getOrganizationId()).containsKey(studentId)) {
+ leftGroups = studentMembershipRemovalMap.get(school.getOrganizationId()).get(studentId);
+ }
+
+ studentReport += "<tr>";
+ studentReport += "<td>" + student.getFullName() + "</td><td>"+getParentNames(student)+"</td><td>"+getGroupClassNames(studentMap.get(studentId)) + "</td><td>"+getGroupClassNames(leftGroups)+"</td>";
+ studentReport += "</tr>";
+ } catch (Exception e) {
+ _log.error("Error when generating report for student "+studentId);
+ }
+ }
+ }
+ }
+
+ // Now print students that have only removed memberships
+ if (isStudentMembershipRemoval(school.getOrganizationId())) {
+ Map<Long, List<String>> studentMap = studentMembershipRemovalMap.get(school.getOrganizationId());
+ if (studentMap != null && studentMap.keySet().size() > 0) {
+ for (Long studentId : studentMap.keySet()) {
+ // Do not print students already processed for membership creation and also students that are leaving the school
+ if (processedStudentList.contains(studentId) || leavingStudentList.contains(studentId)) {
+ continue;
+ }
+ try {
+ User student = UserLocalServiceUtil.getUser(studentId);
+
+ studentReport += "<tr>";
+ studentReport += "<td>" + student.getFullName() + "</td><td>"+getParentNames(student)+"</td><td></td><td>"+getGroupClassNames(studentMap.get(studentId)) + "</td>";
+ studentReport += "</tr>";
+ } catch (Exception e) {
+ _log.error("Error when generating report for student "+studentId);
+ }
+ }
+ }
+ }
+
+ studentReport += "</table>";
+ }
+
+ studentReport += "</br>Remarque : les responsables légaux ne quittent pas l'établissement si au moins un des enfants de la fratrie est encore inscrit.</br>";
+ studentReport += "</p>";
+
+ }
+ } catch (Exception e) {
+ _log.error("Error when generating student report for school "+school.getName());
+ }
+ return studentReport;
+ }
+
+
+ /**
+ * Generate report for all other people
+ * @param school
+ * @return
+ */
+ private static String generateTeacherReport(Organization school) {
+
+ String teacherReport = "";
+ try {
+
+ if (isTeacherEvolution(school.getOrganizationId())) {
+
+ _log.info("there is teacher evolution");
+ teacherReport += "<p class='notification-content'>";
+ teacherReport += "<b>Enseignants</b></br>";
+
+ // Created and reactivated teachers
+ if (isTeacherIncoming(school.getOrganizationId())) {
+ _log.info("Teachers are incomming");
+ List<User> incomingTeachers = getIncommingTeachers(school);
+ teacherReport += "Entrées: ";
+ teacherReport += SynchronizationUtils.printAsString(incomingTeachers) + "</br>";
+ }
+
+
+ // Deactivated teachers
+ List<Long> leavingTeacherList = new ArrayList<Long>();
+ if (isTeacherLeaving(school.getOrganizationId())) {
+ _log.info("Teachers are leaving");
+ List<User> leavingTeachers = getLeavingTeachers(school);
+ for (User leavingTeacher : leavingTeachers) {
+ leavingTeacherList.add(leavingTeacher.getUserId());
+ }
+
+ teacherReport += "Sorties: ";
+ teacherReport += SynchronizationUtils.printAsString(leavingTeachers) + "</br></br>";
+ }
+
+ // Membership
+ if (isTeacherMembershipEvolution(school.getOrganizationId())) {
+
+ teacherReport += "Les mouvements d'enseignants sont les suivants:</br>";
+
+ teacherReport += "<table border=\"1\" style=\"width:100%\">";
+ teacherReport += "<tr>";
+ teacherReport += "<th>Enseignant</th>";
+ teacherReport += "<th>Groupes et classes nouvellement affectés</th>";
+ teacherReport += "<th>Groupes et classes quittés</th>";
+ teacherReport += "</tr>";
+
+ List<Long> processedTeacherList = new ArrayList<Long>();
+
+ // For each teacher : added memberships
+ if (isTeacherMembershipCreation(school.getOrganizationId())) {
+ Map<Long, List<String>> teacherMap = teacherMembershipCreationMap.get(school.getOrganizationId());
+ if (teacherMap != null && teacherMap.keySet().size() > 0) {
+ for (Long teacherId : teacherMap.keySet()) {
+ processedTeacherList.add(teacherId);
+ try {
+ User teacher = UserLocalServiceUtil.getUser(teacherId);
+
+ // Get removed memberships for this teacher
+ List<String> leftGroups = new ArrayList<String>();
+ if (isTeacherMembershipRemoval(school.getOrganizationId())) {
+ if (teacherMembershipRemovalMap.get(school.getOrganizationId()).containsKey(teacherId)) {
+ leftGroups = teacherMembershipRemovalMap.get(school.getOrganizationId()).get(teacherId);
+ }
+ }
+
+ teacherReport += "<tr>";
+ //HtmlUtil.escape(html);
+ teacherReport += "<td>" + teacher.getFullName() + "</td><td>"+getGroupClassNames(teacherMap.get(teacherId)) + "</td><td>"+getGroupClassNames(leftGroups)+"</td>";
+ teacherReport += "</tr>";
+ } catch (Exception e) {
+ _log.error("Error when generating report for teacher "+teacherId);
+ }
+ }
+ }
+ }
+
+ // Add removed teacher memberships
+ if (isTeacherMembershipRemoval(school.getOrganizationId())) {
+ Map<Long, List<String>> teacherMap = teacherMembershipRemovalMap.get(school.getOrganizationId());
+ if (teacherMap != null && teacherMap.keySet().size() > 0) {
+ for (Long teacherId : teacherMap.keySet()) {
+ // Skip teachers that leave the school or that have been processed in the 'incomming' previous loop
+ if (leavingTeacherList.contains(teacherId) || processedTeacherList.contains(teacherId)) {
+ _log.info("Already processed teacher "+teacherId);
+ continue;
+ }
+ try {
+ User teacher = UserLocalServiceUtil.getUser(teacherId);
+
+ teacherReport += "<tr>";
+ //HtmlUtil.escape(html);
+ teacherReport += "<td>" + teacher.getFullName() + "</td><td></td><td>"+getGroupClassNames(teacherMap.get(teacherId))+"</td>";
+ teacherReport += "</tr>";
+ } catch (Exception e) {
+ _log.error("Error when generating report for teacher "+teacherId);
+ }
+ }
+ }
+ }
+ teacherReport += "</table>";
+ teacherReport += "</p>";
+ }
+ }
+ } catch (Exception e) {
+ _log.error("Error when generating teacher report for school "+school.getName());
+ }
+ return teacherReport;
+ }
+
+ /**
+ * Generate report for all other people
+ * @param school
+ * @return
+ */
+ private static String generateOtherReport(Organization school) {
+ String otherReport = "";
+
+ try {
+ if (isOtherEvolution(school.getOrganizationId())) {
+ _log.info("generateOtherReport : is other evolution");
+ otherReport += "<p class='notification-content'>";
+ otherReport += "<b>Personnels</b></br>";
+
+ // Created and reactivated users + created memberships
+ if (isOtherIncoming(school.getOrganizationId())) {
+ _log.info("generateOtherReport : is other incomming");
+ List<User> incomingOthers = getIncommingOthers(school);
+
+ otherReport += "Entrées: ";
+ otherReport += SynchronizationUtils.printAsString(incomingOthers);
+ otherReport += "</br>";
+ }
+
+
+ // Deactivated users + removed memberships
+ if (isOtherLeaving(school.getOrganizationId())) {
+ _log.info("generateOtherReport : is other leaving");
+ List<User> leavingOthers = getLeavingOthers(school);
+
+ otherReport += "Sorties: ";
+ otherReport += SynchronizationUtils.printAsString(leavingOthers);
+ otherReport += "</br>";
+ }
+ otherReport += "</br>";
+ otherReport += "</p>";
+
+ }
+ } catch (Exception e) {
+ _log.error("Error when generating other report for school "+school.getName());
+ }
+ return otherReport;
+ }
+
+
+ /**
+ * Returns the list of students incomming in the given school
+ * @param school
+ * @return
+ */
+ private static List<User> getIncommingStudents(Organization school) {
+
+ List<User> incomingStudents = new ArrayList<User>();
+ if (studentCreationMap.get(school.getOrganizationId()) != null) {
+ _log.info("getIncommingStudents : "+studentCreationMap.get(school.getOrganizationId()).size()+" newly created students for school "+school.getName());
+ incomingStudents.addAll(studentCreationMap.get(school.getOrganizationId()));
+ }
+ if (studentReactivationMap.get(school.getOrganizationId()) != null) {
+ _log.info("getIncommingStudents : "+studentReactivationMap.get(school.getOrganizationId()).size()+" reactivated students for school "+school.getName());
+ incomingStudents.addAll(studentReactivationMap.get(school.getOrganizationId()));
+ }
+ if (studentIncommingSchoolMap.get(school.getOrganizationId()) != null) {
+ _log.info("getIncommingStudents : "+studentIncommingSchoolMap.get(school.getOrganizationId()).size()+" incomming students for school "+school.getName());
+ incomingStudents.addAll(studentIncommingSchoolMap.get(school.getOrganizationId()));
+ }
+
+ _log.info("getIncommingStudents : total of "+incomingStudents.size()+" incomming students for school "+school.getName());
+ return SynchronizationUtils.unique(incomingStudents);
+ }
+
+ /**
+ * Returns the list of students leaving the given school
+ * @param school
+ * @return
+ */
+ private static List<User> getLeavingStudents(Organization school) {
+
+ List<User> leavingStudents = new ArrayList<User>();
+ if (studentDeactivationMap.get(school.getOrganizationId()) != null) {
+ _log.info("getLeavingStudents : "+studentDeactivationMap.get(school.getOrganizationId()).size()+" deactivated students for school "+school.getName());
+ leavingStudents.addAll(studentDeactivationMap.get(school.getOrganizationId()));
+ }
+ if (studentLeavingSchoolMap.get(school.getOrganizationId()) != null) {
+ leavingStudents.addAll(studentLeavingSchoolMap.get(school.getOrganizationId()));
+ _log.info("getLeavingStudents : "+studentLeavingSchoolMap.get(school.getOrganizationId()).size()+" leaving students for school "+school.getName());
+ }
+ _log.info("getLeavingStudents : total of "+leavingStudents.size()+" leaving students for school "+school.getName());
+ return SynchronizationUtils.unique(leavingStudents);
+ }
+
+
+ /**
+ * Returns the list of teachers incomming in the given school
+ * @param school
+ * @return
+ */
+ private static List<User> getIncommingTeachers(Organization school) {
+
+ List<User> incomingTeachers = new ArrayList<User>();
+ if (teacherCreationMap.get(school.getOrganizationId()) != null) {
+ _log.info("getIncommingTeachers : "+teacherCreationMap.get(school.getOrganizationId()).size()+" newly created teachers for school "+school.getName());
+ incomingTeachers.addAll(teacherCreationMap.get(school.getOrganizationId()));
+ }
+ if (teacherReactivationMap.get(school.getOrganizationId()) != null) {
+ _log.info("getIncommingTeachers : "+teacherReactivationMap.get(school.getOrganizationId()).size()+" reactivated teachers for school "+school.getName());
+ incomingTeachers.addAll(teacherReactivationMap.get(school.getOrganizationId()));
+ }
+ if (teacherIncommingSchoolMap.get(school.getOrganizationId()) != null) {
+ _log.info("getIncommingTeachers : "+teacherIncommingSchoolMap.get(school.getOrganizationId()).size()+" incomming teachers for school "+school.getName());
+ incomingTeachers.addAll(teacherIncommingSchoolMap.get(school.getOrganizationId()));
+ }
+
+ _log.info("getIncommingTeachers : total of "+incomingTeachers.size()+" incomming teachers for school "+school.getName());
+ return SynchronizationUtils.unique(incomingTeachers);
+ }
+
+ /**
+ * Returns the list of teachers leaving the given school
+ * @param school
+ * @return
+ */
+ private static List<User> getLeavingTeachers(Organization school) {
+
+ List<User> leavingTeachers = new ArrayList<User>();
+ if (teacherDeactivationMap.get(school.getOrganizationId()) != null) {
+ _log.info("getLeavingTeachers : "+teacherDeactivationMap.get(school.getOrganizationId()).size()+" deactivated teachers for school "+school.getName());
+ leavingTeachers.addAll(teacherDeactivationMap.get(school.getOrganizationId()));
+ }
+ if (teacherLeavingSchoolMap.get(school.getOrganizationId()) != null) {
+ leavingTeachers.addAll(teacherLeavingSchoolMap.get(school.getOrganizationId()));
+ _log.info("getLeavingTeachers : "+teacherLeavingSchoolMap.get(school.getOrganizationId()).size()+" leaving teachers for school "+school.getName());
+ }
+ _log.info("getLeavingTeachers : total of "+leavingTeachers.size()+" leaving teachers for school "+school.getName());
+ return SynchronizationUtils.unique(leavingTeachers);
+ }
+
+ /**
+ * Returns the list of incomming other users in the given school
+ * @param school
+ * @return
+ */
+ private static List<User> getIncommingOthers(Organization school) {
+
+ List<User> incomingOthers = new ArrayList<User>();
+ if (otherCreationMap.get(school.getOrganizationId()) != null) {
+ incomingOthers.addAll(otherCreationMap.get(school.getOrganizationId()));
+ }
+ if (otherReactivationMap.get(school.getOrganizationId()) != null) {
+ incomingOthers.addAll(otherReactivationMap.get(school.getOrganizationId()));
+ }
+ if (otherIncommingSchoolMap.get(school.getOrganizationId()) != null) {
+ incomingOthers.addAll(otherIncommingSchoolMap.get(school.getOrganizationId()));
+ }
+ _log.info("getIncommingOthers returns "+incomingOthers.size()+" users for school "+school.getName());
+ return SynchronizationUtils.unique(incomingOthers);
+ }
+
+ /**
+ * Returns the list of leaving other users in the given school
+ * @param school
+ * @return
+ */
+ private static List<User> getLeavingOthers(Organization school) {
+
+ List<User> leavingOthers = new ArrayList<User>();
+ if (otherDeactivationMap.get(school.getOrganizationId()) != null) {
+ leavingOthers.addAll(otherDeactivationMap.get(school.getOrganizationId()));
+ }
+ if (otherLeavingSchoolMap.get(school.getOrganizationId()) != null) {
+ leavingOthers.addAll(otherLeavingSchoolMap.get(school.getOrganizationId()));
+ }
+ _log.info("getLeavingOthers returns "+leavingOthers.size()+" users for school "+school.getName());
+ return SynchronizationUtils.unique(leavingOthers);
+ }
+
+
+ /**
+ * Register a child with one of its parent
+ * @param child
+ * @param parent
+ */
+ public static void addChildParentLink(User child, User parent) {
+
+ if (childParentsMap.containsKey(child.getUserId())) {
+ // Add parent if not present
+ if (!childParentsMap.get(child.getUserId()).contains(parent.getUserId())) {
+ childParentsMap.get(child.getUserId()).add(parent.getUserId());
+ }
+ } else {
+ List<Long> parentList = new ArrayList<Long>();
+ parentList.add(parent.getUserId());
+ childParentsMap.put(child.getUserId(), parentList);
+ }
+
+ }
+
+ /**
+ * Returns a string that concatenates the list of student's parents
+ * @param child
+ * @return
+ */
+ private static String getParentNames(User child) {
+ String parentNames = "";
+ if (childParentsMap.containsKey(child.getUserId())) {
+ List<Long> parentUserIds = childParentsMap.get(child.getUserId());
+ if (parentUserIds != null && parentUserIds.size() > 0) {
+ for (int idx = 0 ; idx < parentUserIds.size() ; idx++) {
+ Long parentId = parentUserIds.get(idx);
+ try {
+ User parent = UserLocalServiceUtil.getUser(parentId);
+ parentNames += parent.getFullName();
+ if (idx != parentUserIds.size() - 1) {
+ parentNames += ", ";
+ }
+ } catch (Exception e) {
+ _log.error("Error when getting parent with id "+parentId);
+ }
+ }
+ } else {
+ _log.error("Error : child "+child.getFullName()+" should have parents linked to");
+ }
+ } else {
+ _log.error("Error : child "+child.getFullName()+" should have parents linked to");
+ }
+ return parentNames;
+ }
+
+
+ private static String getGroupClassNames(List<String> groupClassList) {
+
+ String res = "";
+ for (int idx = 0 ; idx < groupClassList.size() ; idx++) {
+ String groupClassName = groupClassList.get(idx);
+ res += groupClassName;
+ if (idx != groupClassList.size() - 1) {
+ res += ", ";
+ }
+ }
+ return res;
+ }
+
+ /**
+ * Return true if there is at least 1 modification amongst students, parents, teachers and other users
+ * @param school
+ * @return
+ */
+ private static boolean isEvolutionInSchool (Long schoolId) {
+
+ return isStudentEvolution(schoolId) || isTeacherEvolution(schoolId) || isOtherEvolution(schoolId);
+ }
+
+
+ /**
+ * Return true if there is at least 1 modification amongst students and parents
+ * @param schoolId
+ * @return
+ */
+ private static boolean isStudentEvolution(Long schoolId) {
+ return isStudentIncoming(schoolId) || isStudentLeaving(schoolId) || isStudentMembershipEvolution(schoolId);
+ }
+
+ private static boolean isStudentIncoming(Long schoolId) {
+ return ((studentCreationMap.get(schoolId) != null && studentCreationMap.get(schoolId).size() > 0)
+ || (studentReactivationMap.get(schoolId) != null && studentReactivationMap.get(schoolId).size() > 0)
+ || (studentIncommingSchoolMap.get(schoolId) != null && studentIncommingSchoolMap.get(schoolId).size() > 0));
+ }
+
+ private static boolean isStudentLeaving(Long schoolId) {
+ return ((studentDeactivationMap.get(schoolId) != null && studentDeactivationMap.get(schoolId).size() > 0)
+ || (studentLeavingSchoolMap.get(schoolId) != null && studentLeavingSchoolMap.get(schoolId).size() > 0));
+ }
+
+ private static boolean isStudentMembershipEvolution(Long schoolId) {
+ return isStudentMembershipCreation(schoolId) || isStudentMembershipRemoval(schoolId);
+ }
+
+ private static boolean isStudentMembershipCreation(Long schoolId) {
+ return (studentMembershipCreationMap.get(schoolId) != null && studentMembershipCreationMap.get(schoolId).size() > 0);
+ }
+
+ private static boolean isStudentMembershipRemoval(Long schoolId) {
+ return (studentMembershipRemovalMap.get(schoolId) != null && studentMembershipRemovalMap.get(schoolId).size() > 0);
+ }
+
+ /**
+ * Return true if there is at least 1 modification amongst teachers
+ * @param schoolId
+ * @return
+ */
+ private static boolean isTeacherEvolution(Long schoolId) {
+ return isTeacherIncoming(schoolId) || isTeacherLeaving(schoolId) || isTeacherMembershipEvolution(schoolId);
+ }
+
+ private static boolean isTeacherIncoming(Long schoolId) {
+ return ((teacherCreationMap.get(schoolId) != null && teacherCreationMap.get(schoolId).size() > 0)
+ || (teacherReactivationMap.get(schoolId) != null && teacherReactivationMap.get(schoolId).size() > 0)
+ || (teacherIncommingSchoolMap.get(schoolId) != null && teacherIncommingSchoolMap.get(schoolId).size() > 0));
+ }
+
+ private static boolean isTeacherLeaving(Long schoolId) {
+ return ((teacherDeactivationMap.get(schoolId) != null && teacherDeactivationMap.get(schoolId).size() > 0)
+ || (teacherLeavingSchoolMap.get(schoolId) != null && teacherLeavingSchoolMap.get(schoolId).size() > 0));
+ }
+
+ private static boolean isTeacherMembershipEvolution(Long schoolId) {
+ return isTeacherMembershipCreation(schoolId) || isTeacherMembershipRemoval(schoolId);
+ }
+
+ private static boolean isTeacherMembershipCreation(Long schoolId) {
+ return (teacherMembershipCreationMap.get(schoolId) != null && teacherMembershipCreationMap.get(schoolId).size() > 0);
+ }
+
+ private static boolean isTeacherMembershipRemoval(Long schoolId) {
+ return (teacherMembershipRemovalMap.get(schoolId) != null && teacherMembershipRemovalMap.get(schoolId).size() > 0);
+ }
+
+
+ /**
+ * Return true if there is at least 1 modification amongst other users
+ * @param schoolId
+ * @return
+ */
+ private static boolean isOtherEvolution(Long schoolId) {
+
+ return isOtherIncoming(schoolId) || isOtherLeaving(schoolId);
+
+ }
+
+ private static boolean isOtherIncoming(Long schoolId) {
+ return ((otherCreationMap.get(schoolId) != null && otherCreationMap.get(schoolId).size() > 0)
+ || (otherReactivationMap.get(schoolId) != null && otherReactivationMap.get(schoolId).size() > 0)
+ || (otherIncommingSchoolMap.get(schoolId) != null && otherIncommingSchoolMap.get(schoolId).size() > 0));
+ }
+
+ private static boolean isOtherLeaving(Long schoolId) {
+ return ((otherDeactivationMap.get(schoolId) != null && otherDeactivationMap.get(schoolId).size() > 0)
+ || (otherLeavingSchoolMap.get(schoolId) != null && otherLeavingSchoolMap.get(schoolId).size() > 0));
+ }
+
+
+
+ public static void addEmptyGroup() {
+ nbEmptyGroups++;
+ }
+
+ public static void addExpiredUser() {
+ nbExpiredUsers++;
+ }
+
+ public static void setUserSyncTime(int time) {
+ userSyncTime = time;
+ }
+
+ public static void setGroupSyncTime(int time) {
+ groupSyncTime = time;
+ }
+
+ public static void setStudentMembershipTime(int time) {
+ studentMembershipTime = time;
+ }
+
+ public static void setParentMembershipTime(int time) {
+ parentMembershipTime = time;
+ }
+
+ public static void setTeacherMembershipTime(int time) {
+ teacherMembershipTime = time;
+ }
+
+ public static void setOtherMembershipTime(int time) {
+ otherMembershipTime = time;
+ }
+
+
+ public static void initReport(long _companyId) {
+
+ companyId = _companyId;
+
+ // Global
+
+ // Synchronization
+ userSyncTime = 0;
+
+ // Creation
+ nbCreatedUsers = 0;
+ studentCreationMap = new HashMap<Long, List<User>>();
+ parentCreationMap = new HashMap<Long, List<User>>();
+ teacherCreationMap = new HashMap<Long, List<User>>();
+ otherCreationMap = new HashMap<Long, List<User>>();
+
+ // Reactivation
+ nbReactivatedUsers = 0;
+ studentReactivationMap = new HashMap<Long, List<User>>();
+ parentReactivationMap = new HashMap<Long, List<User>>();
+ teacherReactivationMap = new HashMap<Long, List<User>>();
+ otherReactivationMap = new HashMap<Long, List<User>>();
+
+ // Deactivation
+ nbDeactivatedUsers = 0;
+ studentDeactivationMap = new HashMap<Long, List<User>>();
+ parentDeactivationMap = new HashMap<Long, List<User>>();
+ teacherDeactivationMap = new HashMap<Long, List<User>>();
+ otherDeactivationMap = new HashMap<Long, List<User>>();
+
+ // Group
+ groupSyncTime = 0;
+ nbCreatedGroups = 0;
+ nbEmptyGroups = 0;
+ nbExpiredUsers = 0;
+
+ // Student memberships
+ studentMembershipTime = 0;
+ nbStudentCreatedMemberships = 0;
+ nbStudentRemovedMemberships = 0;
+ studentMembershipCreationMap = new HashMap<Long, Map<Long, List<String>>>();
+ studentMembershipRemovalMap = new HashMap<Long, Map<Long, List<String>>>();
+ studentIncommingSchoolMap = new HashMap<Long, List<User>>();
+ studentLeavingSchoolMap = new HashMap<Long, List<User>>();
+
+ // Parent memberships
+ parentMembershipTime = 0;
+ nbParentCreatedMemberships = 0;
+ nbParentRemovedMemberships = 0;
+
+ // Teacher memberships
+ teacherMembershipTime = 0;
+ nbTeacherCreatedMemberships = 0;
+ nbTeacherRemovedMemberships = 0;
+ teacherMembershipCreationMap = new HashMap<Long, Map<Long, List<String>>>();
+ teacherMembershipRemovalMap = new HashMap<Long, Map<Long, List<String>>>();
+ teacherIncommingSchoolMap = new HashMap<Long, List<User>>();
+ teacherLeavingSchoolMap = new HashMap<Long, List<User>>();
+
+ // Other memberships
+ otherMembershipTime = 0;
+ nbOtherCreatedMemberships = 0;
+ nbOtherRemovedMemberships = 0;
+ otherIncommingSchoolMap = new HashMap<Long, List<User>>();
+ otherLeavingSchoolMap = new HashMap<Long, List<User>>();
+
+ childParentsMap = new HashMap<Long, List<Long>>();
+ }
+
+ private static Log _log = LogFactoryUtil.getLog(SynchronizationReport.class);
+
+}