001/*
002 *  Copyright 2022 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.lheo;
017
018import java.util.List;
019import java.util.Map;
020import java.util.stream.Collectors;
021
022import org.apache.avalon.framework.component.Component;
023import org.apache.avalon.framework.service.ServiceException;
024import org.apache.avalon.framework.service.ServiceManager;
025import org.apache.avalon.framework.service.Serviceable;
026
027import org.ametys.odf.catalog.CatalogsManager;
028import org.ametys.odf.program.AbstractProgram;
029import org.ametys.odf.program.Program;
030import org.ametys.plugins.repository.AmetysObjectIterable;
031import org.ametys.runtime.plugin.component.AbstractLogEnabled;
032
033/**
034 * Helper to get abstract programs to export for LHEO
035 * Can be overridden in projects to have specific query for abstract programs
036 */
037public class LHEOQueryManager extends AbstractLogEnabled implements Serviceable, Component
038{
039    /** The Avalon role */
040    public static final String ROLE = LHEOQueryManager.class.getName();
041    
042    /** The catalogs manager */
043    protected CatalogsManager _catalogsManager;
044    
045    @Override
046    public void service(ServiceManager smanager) throws ServiceException
047    {
048        _catalogsManager = (CatalogsManager) smanager.lookup(CatalogsManager.ROLE);
049    }
050    
051    /**
052     * Get abstract programs to export in LHEO
053     * @param catalog the catalog
054     * @param lang the lang
055     * @param additionalParameters the additional parameters
056     * @return the list of abstract programs
057     */
058    public List<AbstractProgram> getAbstractProgramsToExport(String catalog, String lang, Map<String, Object> additionalParameters)
059    {
060        // Get only programs for default implementation for legacy purpose
061        AmetysObjectIterable<Program> programs = _catalogsManager.getPrograms(catalog, lang);
062        return programs.stream().collect(Collectors.toList());
063    }
064}