001/* 002 * Copyright 2017 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.odfsync.apogee.scc.impl; 017 018import java.util.List; 019import java.util.Map; 020 021import org.slf4j.Logger; 022 023import org.ametys.cms.content.external.ExternalizableMetadataHelper; 024import org.ametys.cms.repository.Content; 025import org.ametys.cms.repository.ModifiableDefaultContent; 026import org.ametys.odf.course.Course; 027import org.ametys.odf.courselist.CourseList; 028import org.ametys.odf.program.ProgramPart; 029import org.ametys.odf.program.TraversableProgramPart; 030import org.ametys.plugins.odfsync.apogee.scc.AbstractApogeeSynchronizableContentsWithCatalogCollection; 031import org.ametys.plugins.repository.metadata.ModifiableCompositeMetadata; 032 033/** 034 * SCC for course lsit contents. 035 */ 036public class CourseListSynchronizableContentsCollection extends AbstractApogeeSynchronizableContentsWithCatalogCollection 037{ 038 /** SCC model id */ 039 public static final String MODEL_ID = "org.ametys.plugins.odfsync.apogee.scc.courselist"; 040 041 @Override 042 protected List<Map<String, Object>> _search(Map<String, Object> searchParams, Logger logger) 043 { 044 return _convertBigDecimal(_apogeeDAO.searchCourseLists(searchParams)); 045 } 046 047 @Override 048 protected String getMappingName() 049 { 050 return "courselist"; 051 } 052 053 @Override 054 protected boolean handleParent(ModifiableDefaultContent currentContent, ModifiableDefaultContent parentContent, Logger logger) 055 { 056 boolean hasChanges = false; 057 058 if (parentContent instanceof Course) 059 { 060 ModifiableCompositeMetadata cm = currentContent.getMetadataHolder(); 061 hasChanges = ExternalizableMetadataHelper.setMetadata(cm, CourseList.METADATA_PARENT_COURSES, new Content[] {parentContent}); 062 hasChanges = _updateRelation(parentContent.getMetadataHolder(), Course.METADATA_CHILD_COURSE_LISTS, currentContent) || hasChanges; 063 } 064 else if (parentContent instanceof ProgramPart) 065 { 066 ModifiableCompositeMetadata cm = currentContent.getMetadataHolder(); 067 hasChanges = ExternalizableMetadataHelper.setMetadata(cm, ProgramPart.METADATA_PARENT_PROGRAM_PARTS, new Content[] {parentContent}); 068 hasChanges = _updateRelation(parentContent.getMetadataHolder(), TraversableProgramPart.METADATA_CHILD_PROGRAM_PARTS, currentContent) || hasChanges; 069 } 070 071 return hasChanges; 072 } 073 074 @Override 075 protected boolean handleChildren(ModifiableDefaultContent content, Logger logger) 076 { 077 return importOrSynchronizeChildren(content, CourseSynchronizableContentsCollection.MODEL_ID, CourseList.METADATA_CHILD_COURSES, Course.METADATA_PARENT_COURSE_LISTS, logger); 078 } 079}