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.program.ProgramPart; 027import org.ametys.odf.program.TraversableProgramPart; 028import org.ametys.plugins.odfsync.apogee.scc.AbstractApogeeSynchronizableContentsWithCatalogCollection; 029import org.ametys.plugins.repository.metadata.ModifiableCompositeMetadata; 030 031/** 032 * SCC for container contents. 033 */ 034public class ContainerSynchronizableContentsCollection extends AbstractApogeeSynchronizableContentsWithCatalogCollection 035{ 036 /** SCC model id */ 037 public static final String MODEL_ID = "org.ametys.plugins.odfsync.apogee.scc.container"; 038 039 @Override 040 protected List<Map<String, Object>> _search(Map<String, Object> searchParams, Logger logger) 041 { 042 return _convertBigDecimal(_apogeeDAO.searchContainers(searchParams)); 043 } 044 045 @Override 046 protected String getMappingName() 047 { 048 return "container"; 049 } 050 051 @Override 052 protected boolean handleParent(ModifiableDefaultContent currentContent, ModifiableDefaultContent parentContent, Logger logger) 053 { 054 boolean hasChanges = false; 055 056 if (parentContent instanceof ProgramPart) 057 { 058 ModifiableCompositeMetadata cm = currentContent.getMetadataHolder(); 059 hasChanges = ExternalizableMetadataHelper.setMetadata(cm, ProgramPart.METADATA_PARENT_PROGRAM_PARTS, new Content[] {parentContent}); 060 hasChanges = _updateRelation(parentContent.getMetadataHolder(), TraversableProgramPart.METADATA_CHILD_PROGRAM_PARTS, 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, TraversableProgramPart.METADATA_CHILD_PROGRAM_PARTS, ProgramPart.METADATA_PARENT_PROGRAM_PARTS, logger); 070 } 071}