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.structure;
017
018import java.util.List;
019
020import org.ametys.odf.course.Course;
021import org.ametys.odf.courselist.CourseList;
022import org.ametys.odf.program.Container;
023import org.ametys.odf.program.Program;
024import org.ametys.odf.program.ProgramPart;
025import org.ametys.odf.program.SubProgram;
026import org.ametys.plugins.odfsync.apogee.ws.ApogeeExportReport;
027import org.ametys.plugins.odfsync.apogee.ws.ApogeeExportReport.ExportStatus;
028
029import gouv.education.apogee.commun.client.ws.creationse.CreationSEMetierServiceInterface;
030
031/**
032 * The structure to export in Apogee the following program
033 * <br>Program into DIP-VDI
034 */
035public class ApogeeSingleProgramStructure extends AbstractApogeeStructure
036{
037    @Override
038    public void checkProgram(Program program, ApogeeExportReport report)
039    {
040        // Check mandatory data for program
041        checkMandatoryDataForContent(program, getDIPMandatoryData(program), report);
042        checkMandatoryDataForContent(program, getVDIMandatoryData(program), report);
043        
044        // Check mandatory data for program orgUnits
045        checkMandatoryDataForOrgunits(program, program.getOrgUnits(), getOrgUnitMandatoryDataForDIP(), report);
046        
047        // Check the program structure
048        List<ProgramPart> programPartChildren = program.getProgramPartChildren();
049        if (!programPartChildren.isEmpty())
050        {
051            // The structure is not handled by this export
052            report.setExportStatus(ExportStatus.CONTENT_STRUCTURE_INVALID);
053        }
054    }
055    
056    @Override
057    public void checkSubProgram(SubProgram subProgram, ApogeeExportReport report)
058    {
059        throw new UnsupportedOperationException("No subprogram in this structure");
060    }
061    
062    @Override
063    public void checkContainerAsYear(Container container, ApogeeExportReport report)
064    {
065        throw new UnsupportedOperationException("No year container in this structure");
066    }
067    
068    @Override
069    public void checkContainerAsSemester(Container container, ApogeeExportReport report)
070    {
071        throw new UnsupportedOperationException("No semester container in this structure");
072    }
073    
074    @Override
075    public void checkCourseList(CourseList courseList, ApogeeExportReport report)
076    {
077        throw new UnsupportedOperationException("No course list in this structure");
078    }
079    
080    @Override
081    public void checkCourse(Course course, ApogeeExportReport report)
082    {
083        throw new UnsupportedOperationException("No course in this structure");
084    }
085    
086    @Override
087    public void createProgram(Program program, ApogeeExportReport report)
088    {
089        try
090        {
091            CreationSEMetierServiceInterface creationService = _apogeeWS.getCreationService();
092            String codDIP = getCodeApogee(program);
093            Long versionDIP = getVersionApogee(program);
094            _apogeeWS.createDIP(program, null, codDIP, creationService);
095            _apogeeWS.createVDI(program, null, codDIP, versionDIP, creationService);
096        }
097        catch (Exception e)
098        {
099            report.setExportStatus(ExportStatus.ERROR);
100            getLogger().error("An error occurred exporting the program '{}' ({}) in Apogee", program.getTitle(), program.getId(), e);
101        }
102    }
103}