001/*
002 *  Copyright 2019 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.odfsync.apogee.ws;
017
018import org.apache.avalon.framework.service.ServiceException;
019import org.apache.avalon.framework.service.ServiceManager;
020
021import org.ametys.odf.program.Program;
022import org.ametys.plugins.odfsync.export.AbstractExportStructure;
023import org.ametys.plugins.odfsync.export.AbstractStructureComponent;
024import org.ametys.plugins.odfsync.export.ExportReport;
025import org.ametys.plugins.odfsync.export.ExportReport.ExportStatus;
026
027/**
028 * Component for Apogee export
029 */
030public class ApogeeStructureComponent extends AbstractStructureComponent
031{
032    /** Avalon Role */
033    public static final String ROLE = ApogeeStructureComponent.class.getName();
034    
035    /** The apogee export extension point */
036    protected ApogeeExportExtensionPoint _exportApogeeEP;
037    
038    @Override
039    public void service(ServiceManager manager) throws ServiceException
040    {
041        super.service(manager);
042        _exportApogeeEP = (ApogeeExportExtensionPoint) manager.lookup(ApogeeExportExtensionPoint.ROLE);
043    }
044    
045    /**
046     * Get the Apogee export report of the program id
047     * @param program the program id
048     * @return the Apogee export report
049     */
050    @Override
051    public ExportReport getExportReport(Program program)
052    {
053        ExportReport report = new ExportReport(program);
054        for (String implementationId : _exportApogeeEP.getExtensionsIds())
055        {
056            AbstractExportStructure exportApogeeStructure = _exportApogeeEP.getExtension(implementationId);
057
058            // Check if the structure is good
059            // Do nothing  if the structure is invalid and continue to check the other Apogee implementations
060            exportApogeeStructure.checkProgram(program, report);
061            if (report.getStatus() != ExportStatus.CONTENT_STRUCTURE_INVALID)
062            {
063                report.setExportStructure(exportApogeeStructure);
064                return report;
065            }
066        }
067        
068        // No implementation for this program structure 
069        report.setStatus(ExportStatus.CONTENT_STRUCTURE_INVALID);
070        return report;
071    }
072}