Index: main/plugin-odf-sync/src/org/ametys/plugins/odfsync/apogee/ApogeeSynchronizationManager.java =================================================================== --- main/plugin-odf-sync/src/org/ametys/plugins/odfsync/apogee/ApogeeSynchronizationManager.java (revision 34856) +++ main/plugin-odf-sync/src/org/ametys/plugins/odfsync/apogee/ApogeeSynchronizationManager.java (working copy) @@ -16,6 +16,7 @@ package org.ametys.plugins.odfsync.apogee; import java.util.HashMap; +import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -23,7 +24,6 @@ import org.apache.avalon.framework.service.ServiceException; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; - import org.ametys.cms.repository.ContentLanguageExpression; import org.ametys.cms.repository.ContentQueryHelper; import org.ametys.cms.repository.ContentTypeExpression; @@ -900,15 +900,18 @@ protected boolean synchronizeCourseList(String syncCode, CourseList courseList, ApogeeCourseListRemoteItem remoteCL, SynchronizationReport report, Logger logger) throws WorkflowException, AmetysRepositoryException { boolean hasChanges = false; - + report.info("Synchronisation de la liste d'ELP " + syncCode + " ..."); // Metadata hasChanges = _synchroHelper.synchronizeCourseListFields(courseList, remoteCL, report, getLogger(), false) || hasChanges; - + // Remote ELP children List remoteCourses = _apogeeDAO.getCourseListChildren(syncCode); + // Course list order + List courseListOrder = new LinkedList(remoteCourses); + // Current ELP children List currentCourses = courseList.getCourses(); @@ -922,6 +925,9 @@ // The course still linked to course list in Apogee, do not synchronize it, it will be done separately // The course list already exists, so remove it from remote course to import remoteCourses.remove(code); + + // Replace the elpCode by the courseId + courseListOrder.set(courseListOrder.indexOf(code), courseId); } else { @@ -929,6 +935,9 @@ String warn = "L'ELP " + code + " n'est plus liée à la liste " + syncCode + ", elle devra être supprimée manuellement."; report.warn(warn); logger.warn(warn); + + // Add the removed course to the end of the courseList + courseListOrder.add(courseId); } } @@ -946,11 +955,23 @@ report.info(info); logger.info(info); hasChanges = true; + + // Replace the elpCode by the courseId + courseListOrder.set(courseListOrder.indexOf(elpCode), course.getId()); + } + } + + // Re-order the courseList + for (String courseId : courseListOrder) + { + // Control if an ELP code is still there (should not happen) + if (courseId.startsWith("courseContent://")) + { + courseList.orderCourseBefore(courseId, null); } } } - if (courseList.needsSave()) { courseList.saveChanges(); Index: main/plugin-odf-sync/src/org/ametys/plugins/odfsync/cdmfr/AbstractCDMFrManager.java =================================================================== --- main/plugin-odf-sync/src/org/ametys/plugins/odfsync/cdmfr/AbstractCDMFrManager.java (revision 34856) +++ main/plugin-odf-sync/src/org/ametys/plugins/odfsync/cdmfr/AbstractCDMFrManager.java (working copy) @@ -22,6 +22,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -47,7 +48,6 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; - import org.ametys.cms.contenttype.ContentTypeExtensionPoint; import org.ametys.cms.observation.Event; import org.ametys.cms.observation.ObservationConstants; @@ -906,6 +906,10 @@ boolean hasChanges = false; Map remoteCourses = new LinkedHashMap(); + + // Course list order + List courseListOrder = new LinkedList(); + NodeList itemNodes = clNode.getChildNodes(); for (int j = 0; j < itemNodes.getLength(); j++) { @@ -913,10 +917,12 @@ Node courseNode = _xPathProcessor.selectSingleNode(doc.getFirstChild(), "course[@CDMid ='" + cdmCode + "']"); if (courseNode != null) { - remoteCourses.put(_xPathProcessor.evaluateAsString(courseNode, "elpCode"), courseNode); + String elpCode = _xPathProcessor.evaluateAsString(courseNode, "elpCode"); + remoteCourses.put(elpCode, courseNode); + courseListOrder.add(elpCode); } } - + List currentCourses = courseList.getCourses(); for (String courseId : currentCourses) { @@ -946,6 +952,9 @@ // The course list already exists, so remove it from remote course to import remoteCourses.remove(code); + + // Replace the elpCode by the courseId + courseListOrder.set(courseListOrder.indexOf(code), courseId); } else { @@ -956,6 +965,9 @@ } else { + // Add the removed course to the end of the courseList + courseListOrder.add(courseId); + // The course list is not linked anymore to container in CDM-fr String warn = "L'ELP \"" + course.getTitle() + " (" + course.getCdmCode() + ")\" n'est plus liée à la liste " + (courseList.getCode() == null ? courseList.getName() : courseList.getCode()) + ", elle devra être supprimée manuellement."; report.warn(warn); @@ -1006,6 +1018,19 @@ // Direct validation if permitted validateContent(course, report, logger); } + + // Replace the elpCode by the courseId + courseListOrder.set(courseListOrder.indexOf(elpCode), course.getId()); + } + } + + // Re-order the courseList + for (String courseId : courseListOrder) + { + // Control if an ELP code is still there (should not happen) + if (courseId.startsWith("courseContent://")) + { + courseList.orderCourseBefore(courseId, null); } }