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.plugins.odfsync.apogee.scc.AbstractApogeeSynchronizableContentsWithCatalogCollection; 029import org.ametys.plugins.repository.metadata.ModifiableCompositeMetadata; 030 031/** 032 * SCC for course contents. 033 */ 034public class CourseSynchronizableContentsCollection extends AbstractApogeeSynchronizableContentsWithCatalogCollection 035{ 036 /** SCC model id */ 037 public static final String MODEL_ID = "org.ametys.plugins.odfsync.apogee.scc.course"; 038 039 @Override 040 protected List<Map<String, Object>> _search(Map<String, Object> searchParams, Logger logger) 041 { 042 return _convertBigDecimal(_apogeeDAO.searchCourses(searchParams)); 043 } 044 045 @Override 046 protected String getMappingName() 047 { 048 return "course"; 049 } 050 051 @Override 052 protected boolean handleParent(ModifiableDefaultContent currentContent, ModifiableDefaultContent parentContent, Logger logger) 053 { 054 boolean hasChanges = false; 055 056 if (parentContent instanceof CourseList) 057 { 058 ModifiableCompositeMetadata cm = currentContent.getMetadataHolder(); 059 hasChanges = ExternalizableMetadataHelper.setMetadata(cm, Course.METADATA_PARENT_COURSE_LISTS, new Content[] {parentContent}); 060 hasChanges = _updateRelation(parentContent.getMetadataHolder(), CourseList.METADATA_CHILD_COURSES, currentContent) || hasChanges; 061 } 062 063 return hasChanges; 064 } 065 066 @Override 067 protected boolean handleChildren(ModifiableDefaultContent content, Logger logger) 068 { 069 return importOrSynchronizeChildren(content, CourseListSynchronizableContentsCollection.MODEL_ID, Course.METADATA_CHILD_COURSE_LISTS, CourseList.METADATA_PARENT_COURSES, logger); 070 } 071}