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.export;
018
019import org.apache.avalon.framework.service.ServiceException;
020import org.apache.avalon.framework.service.ServiceManager;
021import org.apache.avalon.framework.service.Serviceable;
022import org.apache.commons.lang3.StringUtils;
023
024import org.ametys.core.util.I18nUtils;
025import org.ametys.odf.enumeration.OdfReferenceTableHelper;
026import org.ametys.odf.program.Container;
027import org.ametys.odf.program.Program;
028import org.ametys.plugins.repository.AmetysObjectResolver;
029import org.ametys.runtime.plugin.component.AbstractLogEnabled;
030
031/**
032 * The abstract class to handle an export in a connector (Pégase, Apogée...)
033 */
034public abstract class AbstractExportStructure extends AbstractLogEnabled implements Serviceable
035{
036    /** The i18n utils */
037    protected I18nUtils _i18nUtils;
038    /** The Ametys object resolver */
039    protected AmetysObjectResolver _resolver;
040    
041    /** The ODF reference table helper */
042    protected OdfReferenceTableHelper _odfRefTableHelper;
043    
044    public void service(ServiceManager manager) throws ServiceException
045    {
046        _i18nUtils = (I18nUtils) manager.lookup(I18nUtils.ROLE);
047        _resolver = (AmetysObjectResolver) manager.lookup(AmetysObjectResolver.ROLE);
048        _odfRefTableHelper = (OdfReferenceTableHelper) manager.lookup(OdfReferenceTableHelper.ROLE);
049    }
050    
051    /**
052     * Get the code of the container nature
053     * @param container the container
054     * @return the code of the nature
055     */
056    protected String getContainerNatureCode(Container container)
057    {
058        String nature = container.getNature();
059        
060        if (StringUtils.isNotBlank(nature))
061        {
062            return _odfRefTableHelper.getItemCode(nature);
063        }
064        
065        return null;
066    }
067    
068    /**
069     * Check if the program structure is matching
070     * @param program the program
071     * @param report the export report
072     */
073    public abstract void checkProgram(Program program, ExportReport report);
074    
075    /**
076     * Create a program through the export connector 
077     * @param program the program to export
078     * @param report the export report
079     */
080    public abstract void createProgram(Program program, ExportReport report);
081}