001/*
002 *  Copyright 2024 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 */
016
017package org.ametys.plugins.odfsync.pegase.scc;
018
019import java.util.Map;
020
021import org.apache.avalon.framework.component.Component;
022import org.apache.avalon.framework.configuration.Configuration;
023import org.apache.avalon.framework.configuration.ConfigurationException;
024
025import org.ametys.plugins.odfsync.generic.scc.AbstractMappingHelper;
026
027/**
028 * Helper for the Pégase SCC (COF).
029 */
030public class PegaseSCCMappingHelper extends AbstractMappingHelper implements Component
031{
032    /** Role */
033    public static final String ROLE = PegaseSCCMappingHelper.class.getName();
034    /** The base uri */
035    protected String _baseUri;
036    /** Mappings Pégase codes - Ametys code */
037    protected Map<String, String> _ametysTypeForPegaseOFType;
038    
039    @Override
040    public void configure(Configuration configuration) throws ConfigurationException
041    {
042        super.configure(configuration);
043        
044        _baseUri = configuration.getChild("baseUri").getValue();
045    }
046    
047    /**
048     * Get the Ametys type from the Pégase type
049     * @param pegaseType The Pégase type
050     * @return The Ametys type
051     */
052    public String getAmetysType(String pegaseType)
053    {
054        if (_ametysTypeForPegaseOFType == null)
055        {
056            _ametysTypeForPegaseOFType = _readMapping(_baseUri);
057        }
058        
059        return _ametysTypeForPegaseOFType.get(pegaseType);
060    }
061}