001/* 002 * Copyright 2022 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.generic.scc; 018 019import java.util.Optional; 020 021import org.apache.avalon.framework.configuration.Configuration; 022import org.apache.avalon.framework.configuration.ConfigurationException; 023 024import org.ametys.odf.enumeration.OdfReferenceTableEntry; 025import org.ametys.plugins.odfsync.scc.operator.ODFSynchronizingContentOperatorHelper; 026 027/** 028 * Get mapped values from connector to Ametys. 029 */ 030public class ImportSynchronizingContentOperatorHelper extends ODFSynchronizingContentOperatorHelper 031{ 032 private String _fieldName; 033 034 @Override 035 public void configure(Configuration configuration) throws ConfigurationException 036 { 037 super.configure(configuration); 038 _fieldName = configuration.getChild("field-name").getValue(); 039 } 040 041 @Override 042 protected Optional<OdfReferenceTableEntry> _getReferenceTableEntry(String contentTypeId, String connectorCode) 043 { 044 return Optional.of(connectorCode) 045 .map(code -> _odfRefTableHelper.getItemFromConnector(contentTypeId, code, _fieldName)) // First check if we find the content from code of connector 046 .or(() -> super._getReferenceTableEntry(contentTypeId, connectorCode)); // Then check if we find the content from XML mapping 047 } 048}