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
033    /** Avalon role */
034    public static final String ROLE = SynchronizeModeEnumerator.class.getName();
035
036    /**
037     * The import mode
038     */
039    public enum ImportMode
040    {
041        /** This mode will both create and update contents*/
042        CREATE_AND_UPDATE,
043        /** This mode will only create contents. If the content already exists, it will fail, 
044         *  if the subcontent exists, the subcontconent will not be updated, and the content will be only partially imported */
045        CREATE_ONLY,
046        /** This mode will only update existing contents. If the content does not exists, it will fail, 
047         *  if the subcontent does not exists, the subcontconent will not be created, and the content will be only partially imported */
048        UPDATE_ONLY
049    }
050    
051    private Map<String, I18nizableText> _synchronizeModes;
052
053    @Override
054    public I18nizableText getEntry(String value)
055    {
056        return _synchronizeModes.get(value);
057    }
058    
059    @Override
060    public Map<String, I18nizableText> getTypedEntries()
061    {
062        return Collections.unmodifiableMap(_synchronizeModes);
063    }
064
065    public void initialize() throws Exception
066    {
067        String catalogName = "plugin.contentio";
068        _synchronizeModes = new LinkedHashMap<>(3);
069        _synchronizeModes.put(ImportMode.CREATE_AND_UPDATE.toString(), new I18nizableText(catalogName, "PLUGINS_CONTENTIO_CONTENT_IMPORT_DIALOG_SYNCHRONIZE_MODE_CREATE_AND_UPDATE"));
070        _synchronizeModes.put(ImportMode.CREATE_ONLY.toString(), new I18nizableText(catalogName, "PLUGINS_CONTENTIO_CONTENT_IMPORT_DIALOG_SYNCHRONIZE_MODE_CREATE_ONLY"));
071        _synchronizeModes.put(ImportMode.UPDATE_ONLY.toString(), new I18nizableText(catalogName, "PLUGINS_CONTENTIO_CONTENT_IMPORT_DIALOG_SYNCHRONIZE_MODE_UPDATE_ONLY"));
072    }
073    
074}