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.export.ExportReport; 027import org.ametys.plugins.odfsync.export.ExportReport.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, ExportReport 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.setStatus(ExportStatus.CONTENT_STRUCTURE_INVALID); 053 } 054 } 055 056 @Override 057 public void checkSubProgram(SubProgram subProgram, ExportReport report) 058 { 059 throw new UnsupportedOperationException("No subprogram in this structure"); 060 } 061 062 @Override 063 public void checkContainerAsYear(Container container, ExportReport report, String containerNatureCode) 064 { 065 throw new UnsupportedOperationException("No year container in this structure"); 066 } 067 068 @Override 069 public void checkCourseList(CourseList courseList, ExportReport report) 070 { 071 throw new UnsupportedOperationException("No course list in this structure"); 072 } 073 074 @Override 075 public void checkCourse(Course course, ExportReport report) 076 { 077 throw new UnsupportedOperationException("No course in this structure"); 078 } 079 080 @Override 081 public void createProgram(Program program, ExportReport report) 082 { 083 try 084 { 085 CreationSEMetierServiceInterface creationService = _apogeeWS.getCreationService(); 086 String codDIP = getCodeApogee(program); 087 Long versionDIP = getVersionApogee(program); 088 _apogeeWS.createDIP(program, null, codDIP, creationService); 089 _apogeeWS.createVDI(program, null, codDIP, versionDIP, creationService); 090 } 091 catch (Exception e) 092 { 093 report.setStatus(ExportStatus.ERROR); 094 getLogger().error("An error occurred exporting the program '{}' ({}) in Apogee", program.getTitle(), program.getId(), e); 095 } 096 } 097}