001/*
002 *  Copyright 2016 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.search.solr.schema;
017
018import java.util.ArrayList;
019import java.util.Collection;
020import java.util.List;
021
022import org.apache.avalon.framework.service.ServiceException;
023import org.apache.avalon.framework.service.ServiceManager;
024import org.apache.avalon.framework.service.Serviceable;
025
026import org.ametys.cms.search.model.SystemProperty;
027import org.ametys.cms.search.model.SystemPropertyExtensionPoint;
028import org.ametys.cms.search.systemprop.IndexationAwareSystemProperty;
029import org.ametys.runtime.plugin.component.AbstractLogEnabled;
030
031/**
032 * Provides all the schema elements defined by system properties.
033 */
034public class SystemPropertySchemaDefinitionProvider extends AbstractLogEnabled implements SchemaDefinitionProvider, Serviceable
035{
036    
037    /** The system property extension point. */
038    protected SystemPropertyExtensionPoint _sysPropEP;
039    
040    @Override
041    public void service(ServiceManager manager) throws ServiceException
042    {
043        _sysPropEP = (SystemPropertyExtensionPoint) manager.lookup(SystemPropertyExtensionPoint.ROLE);
044    }
045    
046    @Override
047    public Collection<SchemaDefinition> getDefinitions()
048    {
049        List<SchemaDefinition> definitions = new ArrayList<>();
050        
051        for (String id : _sysPropEP.getExtensionsIds())
052        {
053            SystemProperty property = _sysPropEP.getExtension(id);
054            if (property instanceof IndexationAwareSystemProperty indexationAwareProperty)
055            {
056                definitions.addAll(indexationAwareProperty.getSchemaDefinitions());
057            }
058        }
059        
060        return definitions;
061    }
062
063}