001/* 002 * Copyright 2026 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.skill; 017 018import java.util.Objects; 019import java.util.Set; 020import java.util.stream.Collectors; 021 022import org.apache.avalon.framework.service.ServiceException; 023import org.apache.avalon.framework.service.ServiceManager; 024 025import org.ametys.cms.model.properties.AbstractIndexableContentProperty; 026import org.ametys.cms.model.properties.Property; 027import org.ametys.cms.repository.Content; 028import org.ametys.cms.repository.ModifiableContent; 029import org.ametys.odf.program.AbstractProgram; 030import org.ametys.odf.program.Program; 031import org.ametys.odf.skill.workflow.SkillEditionFunction; 032 033/** 034 * {@link Property} for acquired skills of child courses on a {@link AbstractProgram} 035 */ 036public class ProgramComputedMicroSkillsProperty extends AbstractIndexableContentProperty<Content> 037{ 038 private ODFSkillsHelper _skillsHelper; 039 040 @Override 041 public void service(ServiceManager manager) throws ServiceException 042 { 043 super.service(manager); 044 _skillsHelper = (ODFSkillsHelper) manager.lookup(ODFSkillsHelper.ROLE); 045 } 046 047 @Override 048 protected Set<? extends ModifiableContent> _getLinkedContents(Content content) 049 { 050 if (content instanceof Program program) 051 { 052 Set<ModifiableContent> values = _skillsHelper.getReferencedMicroSkills(program) 053 .stream() 054 .map(contentValue -> contentValue.getContentIfExists().orElse(null)) 055 .filter(Objects::nonNull) 056 .collect(Collectors.toSet()); 057 058 return values; 059 } 060 061 return null; 062 } 063 064 @Override 065 public boolean isMultiple() 066 { 067 return true; 068 } 069 070 public String getContentTypeId() 071 { 072 return SkillEditionFunction.MICRO_SKILL_TYPE; 073 } 074}