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.configuration.Configuration; 022import org.apache.avalon.framework.configuration.ConfigurationException; 023 024import org.ametys.plugins.odfsync.generic.scc.AbstractMappingHelper; 025import org.ametys.runtime.i18n.I18nizableText; 026 027/** 028 * Helper for the Pégase SCC (COF). 029 */ 030public class PegaseSCCMappingHelper extends AbstractMappingHelper 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 try 057 { 058 _ametysTypeForPegaseOFType = _readMapping(_baseUri); 059 } 060 catch (Exception e) 061 { 062 getLogger().error("Error reading mapping for Pégase type: {}", pegaseType, e); 063 } 064 } 065 066 return _ametysTypeForPegaseOFType.get(pegaseType); 067 } 068 069 @Override 070 protected I18nizableText getCacheLabel() 071 { 072 return new I18nizableText("plugin.odf-sync", "PLUGINS_ODF_SYNC_CACHE_MAPPING_TYPES_LABEL", Map.of("name", new I18nizableText(_implementationName))); 073 } 074 075 @Override 076 protected I18nizableText getCacheDescription() 077 { 078 return new I18nizableText("plugin.odf-sync", "PLUGINS_ODF_SYNC_CACHE_MAPPING_TYPES_DESCRIPTION", Map.of("name", new I18nizableText(_implementationName))); 079 } 080}