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.init;
017
018import java.util.HashMap;
019import java.util.Map;
020
021import org.ametys.core.util.MapUtils;
022import org.ametys.runtime.plugin.component.AbstractThreadSafeComponentPrioritizableExtensionPoint;
023
024/**
025 * The {@link OdfRefTableData} extension point to list all available CSV files to import.
026 */
027public class OdfRefTableDataExtensionPoint extends AbstractThreadSafeComponentPrioritizableExtensionPoint<OdfRefTableData>
028{
029    /** Avalon Role */
030    public static final String ROLE = OdfRefTableDataExtensionPoint.class.getName();
031    
032    /**
033     * Data to import for all the extension points {@link OdfRefTableData}.
034     * If we have the same content type id twice, only the first one is kept. There is a priorization, less is the priority number, more it is prior.
035     * @return Path of CSV files to import by content type id.
036     */
037    public Map<String, String> getDataToImport()
038    {
039        return getExtensionsIds()
040            .stream()
041            .map(this::getExtension)
042            .map(OdfRefTableData::getDataToImport)
043            .reduce(new HashMap<>(), MapUtils::merge);
044    }
045}