001/*
002 *  Copyright 2020 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.plugins.contentio.archive;
017
018import java.util.Map;
019
020import org.ametys.runtime.i18n.I18nizableText;
021
022/**
023 * A partial import, i.e. an element which is importable, proposed to the end user.
024 */
025public interface PartialImport
026{
027    /**
028     * Gets the key. Must be unique across the whole application (you should prefix it, for instance "plugins/my-plugin").
029     * @return the key
030     */
031    String getKey();
032    
033    /**
034     * Gets the label
035     * @return the label
036     */
037    I18nizableText getLabel();
038    
039    /**
040     * Jsonify this partial import for client-side
041     * @return the JSON representation of this partial import
042     */
043    default Map<String, Object> toJson()
044    {
045        return Map.of(
046                "key", getKey(), 
047                "label", getLabel());
048    }
049    
050    /**
051     * Builds a partial import.
052     * @param key the key
053     * @param label the label
054     * @return a partial import
055     */
056    public static PartialImport of(String key, I18nizableText label)
057    {
058        return new PartialImport()
059        {
060            @Override
061            public String getKey()
062            {
063                return key;
064            }
065            
066            @Override
067            public I18nizableText getLabel()
068            {
069                return label;
070            }
071        };
072    }
073}