001/* 002 * Copyright 2023 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.odf.program.properties; 017 018import java.util.Set; 019 020import org.apache.avalon.framework.service.ServiceException; 021import org.apache.avalon.framework.service.ServiceManager; 022 023import org.ametys.cms.model.properties.AbstractContentProperty; 024import org.ametys.cms.repository.Content; 025import org.ametys.cms.repository.ModifiableContent; 026import org.ametys.odf.ODFHelper; 027import org.ametys.odf.ProgramItem; 028import org.ametys.odf.coursepart.CoursePart; 029import org.ametys.odf.program.SubProgramFactory; 030 031/** 032 * Property to get the parent subprograms of a program item or course part. 033 */ 034public class ParentSubProgramsProperty extends AbstractContentProperty<Content> 035{ 036 /** The ODF Helper */ 037 protected ODFHelper _odfHelper; 038 039 @Override 040 public void service(ServiceManager manager) throws ServiceException 041 { 042 super.service(manager); 043 _odfHelper = (ODFHelper) manager.lookup(ODFHelper.ROLE); 044 } 045 046 @Override 047 protected Set<? extends ModifiableContent> _getLinkedContents(Content content) 048 { 049 if (content instanceof ProgramItem programItem) 050 { 051 return _odfHelper.getParentSubPrograms(programItem, true); 052 } 053 if (content instanceof CoursePart coursePart) 054 { 055 return _odfHelper.getParentSubPrograms(coursePart, true); 056 } 057 return null; 058 } 059 060 @Override 061 public boolean isMultiple() 062 { 063 return true; 064 } 065 066 public String getContentTypeId() 067 { 068 return SubProgramFactory.SUBPROGRAM_CONTENT_TYPE; 069 } 070}