001/* 002 * Copyright 2024 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.tree; 017 018import java.util.List; 019import java.util.Map; 020 021import org.apache.commons.lang3.StringUtils; 022 023import org.ametys.cms.repository.Content; 024import org.ametys.odf.course.Course; 025import org.ametys.odf.coursepart.CoursePart; 026import org.ametys.runtime.i18n.I18nizableText; 027 028/** 029 * {@link ODFTreeIndicator} to indicate if a course has shared course part 030 */ 031public class SharedCoursePartIndicator extends AbstractStaticODFTreeIndicator 032{ 033 public IndicatorData getIndicatorData(Content content) 034 { 035 if (content instanceof Course course) 036 { 037 if (_hasSharedCoursePart(course)) 038 { 039 return new IndicatorData(new I18nizableText("plugin.odf", "PLUGINS_ODF_CONTENTS_TREE_INDICATORS_HAS_SHARED_COURSE_PART"), null, "odficon-course-part-shared", Map.of()); 040 } 041 } 042 043 return null; 044 } 045 046 private boolean _hasSharedCoursePart(Course content) 047 { 048 return content.getCourseParts().stream() // parcourt toutes les heures d'enseignement du cours 049 .map(CoursePart::getCourses) // récupère la liste des cours lié à chaque heure d'enseignement 050 .flatMap(List::stream) // parcourt la liste 051 .anyMatch(c -> !StringUtils.equals(c.getId(), content.getId())); // vérifie si un des cours n'est pas le cours actuel 052 } 053}