001/*
002 *  Copyright 2023 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.csv;
017
018import java.util.Collections;
019import java.util.LinkedHashMap;
020import java.util.Map;
021
022import org.apache.avalon.framework.activity.Initializable;
023
024import org.ametys.runtime.i18n.I18nizableText;
025import org.ametys.runtime.model.Enumerator;
026
027/**
028 * {@link Enumerator} for the memory caches.
029 */
030public class SynchronizeModeEnumerator implements Enumerator<String>, Initializable
031{
032    /** Avalon role */
033    public static final String ROLE = SynchronizeModeEnumerator.class.getName();
034
035    /**
036     * The import mode
037     */
038    public enum ImportMode
039    {
040        /** This mode will both create and update contents*/
041        CREATE_AND_UPDATE,
042        /** This mode will only create contents. If the content already exists, it will fail, 
043         *  if the subcontent exists, the subcontconent will not be updated, and the content will be only partially imported */
044        CREATE_ONLY,
045        /** This mode will only update existing contents. If the content does not exists, it will fail, 
046         *  if the subcontent does not exists, the subcontconent will not be created, and the content will be only partially imported */
047        UPDATE_ONLY
048    }
049    
050    private Map<String, I18nizableText> _synchronizeModes;
051
052    @Override
053    public I18nizableText getEntry(String value)
054    {
055        return _synchronizeModes.get(value);
056    }
057    
058    @Override
059    public Map<String, I18nizableText> getEntries()
060    {
061        return Collections.unmodifiableMap(_synchronizeModes);
062    }
063
064    public void initialize() throws Exception
065    {
066        String catalogName = "plugin.contentio";
067        _synchronizeModes = new LinkedHashMap<>(3);
068        _synchronizeModes.put(ImportMode.CREATE_AND_UPDATE.toString(), new I18nizableText(catalogName, "PLUGINS_CONTENTIO_CONTENT_IMPORT_DIALOG_SYNCHRONIZE_MODE_CREATE_AND_UPDATE"));
069        _synchronizeModes.put(ImportMode.CREATE_ONLY.toString(), new I18nizableText(catalogName, "PLUGINS_CONTENTIO_CONTENT_IMPORT_DIALOG_SYNCHRONIZE_MODE_CREATE_ONLY"));
070        _synchronizeModes.put(ImportMode.UPDATE_ONLY.toString(), new I18nizableText(catalogName, "PLUGINS_CONTENTIO_CONTENT_IMPORT_DIALOG_SYNCHRONIZE_MODE_UPDATE_ONLY"));
071    }
072    
073}