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.cms.properties.section; 017 018import java.util.List; 019import java.util.Set; 020import java.util.stream.Stream; 021 022import org.apache.avalon.framework.service.ServiceException; 023import org.apache.avalon.framework.service.ServiceManager; 024 025import org.ametys.cms.properties.section.exclusion.PropertySectionExclusion; 026import org.ametys.cms.properties.section.exclusion.PropertySectionExclusionExtensionPoint; 027import org.ametys.plugins.repository.AmetysObject; 028import org.ametys.runtime.plugin.component.AbstractThreadSafeComponentPrioritizableSupporterExtensionPoint; 029 030/** 031 * The property section extension point. Each section is added to the properties tool. 032 */ 033public class PropertySectionExtensionPoint extends AbstractThreadSafeComponentPrioritizableSupporterExtensionPoint<PropertySection, AmetysObject> 034{ 035 /** Avalon Role */ 036 public static final String ROLE = PropertySectionExtensionPoint.class.getName(); 037 038 private PropertySectionExclusionExtensionPoint _propertySectionExclusionEP; 039 040 @Override 041 public void service(ServiceManager manager) throws ServiceException 042 { 043 super.service(manager); 044 _propertySectionExclusionEP = (PropertySectionExclusionExtensionPoint) manager.lookup(PropertySectionExclusionExtensionPoint.ROLE); 045 } 046 047 @Override 048 protected Stream<PropertySection> _getSupportingExtensions(AmetysObject element) 049 { 050 // Get excluded sections for the current element 051 List<String> excludedSections = _propertySectionExclusionEP.getSupportingExtensions(element) 052 .stream() 053 .map(PropertySectionExclusion::getExcludedSections) 054 .flatMap(Set::stream) 055 .distinct() 056 .toList(); 057 058 return super._getSupportingExtensions(element) 059 // Exclude sections 060 .filter(section -> !excludedSections.contains(section.getId())); 061 } 062}