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 java.math.BigDecimal; 019import java.rmi.RemoteException; 020import java.time.LocalDate; 021import java.util.List; 022import java.util.stream.Stream; 023 024import org.apache.avalon.framework.component.Component; 025import org.apache.avalon.framework.service.ServiceException; 026import org.apache.avalon.framework.service.ServiceManager; 027import org.apache.avalon.framework.service.Serviceable; 028import org.apache.commons.lang3.StringUtils; 029 030import org.ametys.cms.data.ContentDataHelper; 031import org.ametys.cms.data.ContentValue; 032import org.ametys.cms.repository.Content; 033import org.ametys.odf.course.Course; 034import org.ametys.odf.courselist.CourseList; 035import org.ametys.odf.orgunit.OrgUnit; 036import org.ametys.odf.program.AbstractProgram; 037import org.ametys.odf.program.Container; 038import org.ametys.odf.program.SubProgram; 039import org.ametys.plugins.odfsync.apogee.ws.structure.AbstractApogeeStructure; 040import org.ametys.plugins.repository.AmetysObjectResolver; 041import org.ametys.runtime.config.Config; 042import org.ametys.runtime.plugin.component.AbstractLogEnabled; 043 044import gouv.education.apogee.commun.client.ws.creationse.CreationSEMetierServiceInterface; 045import gouv.education.apogee.commun.client.ws.creationse.CreationSEMetierServiceInterfaceServiceLocator; 046import gouv.education.apogee.commun.transverse.dto.offreformation.creerse.CentreInsPedagogiDTO; 047import gouv.education.apogee.commun.transverse.dto.offreformation.creerse.CentreInsPedagogiDTO2; 048import gouv.education.apogee.commun.transverse.dto.offreformation.creerse.CmpHabiliteeVdiDTO; 049import gouv.education.apogee.commun.transverse.dto.offreformation.creerse.ComposanteCGEDTO; 050import gouv.education.apogee.commun.transverse.dto.offreformation.creerse.DiplomeDTO; 051import gouv.education.apogee.commun.transverse.dto.offreformation.creerse.ElementPedagogiDTO4; 052import gouv.education.apogee.commun.transverse.dto.offreformation.creerse.ElementPedagogiDTO6; 053import gouv.education.apogee.commun.transverse.dto.offreformation.creerse.EtapeDTO; 054import gouv.education.apogee.commun.transverse.dto.offreformation.creerse.LienVetElpLseDTO; 055import gouv.education.apogee.commun.transverse.dto.offreformation.creerse.ListeElementPedagogiDTO3; 056import gouv.education.apogee.commun.transverse.dto.offreformation.creerse.Nullable2Int; 057import gouv.education.apogee.commun.transverse.dto.offreformation.creerse.Nullable3Int; 058import gouv.education.apogee.commun.transverse.dto.offreformation.creerse.NullableDecimal; 059import gouv.education.apogee.commun.transverse.dto.offreformation.creerse.NullableInt; 060import gouv.education.apogee.commun.transverse.dto.offreformation.creerse.RegimeDTO; 061import gouv.education.apogee.commun.transverse.dto.offreformation.creerse.VdiFractionnerVetDTO; 062import gouv.education.apogee.commun.transverse.dto.offreformation.creerse.VersionDiplomeDTO; 063import gouv.education.apogee.commun.transverse.dto.offreformation.creerse.VersionEtapeDTO; 064 065 066/** 067 * The component to create ODF element in Apogee 068 * In most cases : 069 * DIP / VDI (diplome / version de diplome) : it is a program 070 * ETP / VET (etape / version d'etape) : it is a subprogram or a container of type year 071 * LSE (liste d'elements) : it is a course list 072 * ELP (element pedagogique) : it is a course or a container of type semester 073 */ 074public class ApogeeWS extends AbstractLogEnabled implements Serviceable, Component 075{ 076 /** Avalon ROLE */ 077 public static final String ROLE = ApogeeWS.class.getName(); 078 079 /** The ametys object resolver */ 080 protected AmetysObjectResolver _resolver; 081 082 public void service(ServiceManager manager) throws ServiceException 083 { 084 _resolver = (AmetysObjectResolver) manager.lookup(AmetysObjectResolver.ROLE); 085 } 086 087 /** 088 * Get the service to create element in Apogee 089 * @return the service 090 * @throws javax.xml.rpc.ServiceException if an error occurred getting the service 091 */ 092 public CreationSEMetierServiceInterface getCreationService() throws javax.xml.rpc.ServiceException 093 { 094 String wsURL = Config.getInstance().getValue("apogee.ws.url"); 095 CreationSEMetierServiceInterfaceServiceLocator locator = new CreationSEMetierServiceInterfaceServiceLocator(); 096 locator.setCreationSEMetierEndpointAddress(wsURL); // TODO user and mdp ???? 097 098 return locator.getCreationSEMetier(); 099 } 100 101 /** 102 * Create a Apogee DIP from a content 103 * @param content the content 104 * @param title the DIP title. Can be null, in this case we take the content title 105 * @param codDip the code DIP 106 * @throws RemoteException if a web service error occurred 107 * @throws javax.xml.rpc.ServiceException if an error occurred getting the service 108 */ 109 public void createDIP(Content content, String title, String codDip) throws RemoteException, javax.xml.rpc.ServiceException 110 { 111 createDIP(content, title, codDip, getCreationService()); 112 } 113 114 /** 115 * Create a Apogee DIP from a content 116 * @param content the content 117 * @param title the DIP title. Can be null, in this case we take the content title 118 * @param codDip the code DIP 119 * @param creationSEMetierServiceInterface the service to create element in Apogee 120 * @throws RemoteException if a web service error occurred 121 */ 122 public void createDIP(Content content, String title, String codDip, CreationSEMetierServiceInterface creationSEMetierServiceInterface) throws RemoteException 123 { 124 // Code diplome 125 String computedTitle = StringUtils.isNotBlank(title) ? title : content.getTitle(); 126 127 // codDip='Code diplôme (obligatoire)' " 128 // libDip='Libellé long diplôme (non obligatoire)' " 129 // licDip='Libellé court diplôme (obligatoire)' " 130 // codNdi='Code nature diplôme (obligatoire)'" 131 // codCycle='Code cycle SISE (obligatoire)'" 132 // codTypDip='Code type diplôme (obligatoire)'" 133 DiplomeDTO dip = new DiplomeDTO(); 134 dip.setCodDip(codDip); 135 dip.setLibDip(computedTitle); 136 dip.setLicDip(StringUtils.substring(computedTitle, 0, 24)); // need to cut to 25 max 137 138 String educationKindId = ContentDataHelper.getContentIdFromContentData(content, AbstractProgram.EDUCATION_KIND); 139 Content educationKindContent = _resolver.resolveById(educationKindId); 140 dip.setCodNdi(educationKindContent.getValue(AbstractApogeeStructure.CODE_APOGEE_ATTRIBUTE_NAME)); 141 142 dip.setCodCycle(content.getValue("cycleApogee/codeApogee")); 143 144 String degreeCodeId = ContentDataHelper.getContentIdFromContentData(content, AbstractProgram.DEGREE); 145 Content degreeContent = _resolver.resolveById(degreeCodeId); 146 dip.setCodTypDip(degreeContent.getValue(AbstractApogeeStructure.CODE_APOGEE_ATTRIBUTE_NAME)); 147 148 creationSEMetierServiceInterface.creerDIP(dip); 149 } 150 151 /** 152 * Create a Apogee VDI from a content 153 * @param content the content 154 * @param title the VDI title. Can be null, in this case we take the content title 155 * @param codDip the code of the diplome in Apogee 156 * @param versionDIP the version of the diplome in Apogee 157 * @throws RemoteException if a web service error occurred 158 * @throws javax.xml.rpc.ServiceException if an error occurred getting the service 159 */ 160 public void createVDI(Content content, String title, String codDip, Long versionDIP) throws RemoteException, javax.xml.rpc.ServiceException 161 { 162 createVDI(content, title, codDip, versionDIP, getCreationService()); 163 } 164 165 /** 166 * Create a Apogee VDI from a content 167 * @param content the content 168 * @param title the VDI title. Can be null, in this case we take the content title 169 * @param codDip the code of the diplome in Apogee 170 * @param versionDIP the version of the diplome in Apogee 171 * @param creationSEMetierServiceInterface the service to create element in Apogee 172 * @throws RemoteException if a web service error occurred 173 */ 174 public void createVDI(Content content, String title, String codDip, Long versionDIP, CreationSEMetierServiceInterface creationSEMetierServiceInterface) throws RemoteException 175 { 176 String computedTitle = StringUtils.isNotBlank(title) ? title : content.getTitle(); 177 178 // codDip='Code diplôme (obligatoire)' " 179 // codVersionDip='Code version diplôme (obligatoire)' " 180 // licVersionDip='Libellé court version diplôme (non obligatoire)' " 181 // debutRecrutement='Année universitaire début recrutement (obligatoire)' " 182 // finRecrutement='Année universitaire fin recrutement (obligatoire)' " 183 // debutValidation='Année universitaire début validation (obligatoire)' " 184 // finValidation='Année universitaire fin validation (obligatoire)' " 185 // listComposantesHabilitees='Code composante 1,Code composante 2,... (obligatoire)' " 186 VersionDiplomeDTO vdi = new VersionDiplomeDTO(); 187 vdi.setCodDip(codDip); 188 189 vdi.setCodVersionDip(new NullableInt(versionDIP.intValue())); 190 vdi.setLicVersionDip(StringUtils.substring(computedTitle, 0, 24)); 191 192 LocalDate startRecruitmentDate = content.getValue("start-date-recruitment"); 193 LocalDate endRecruitmentDate = content.getValue("end-date-recruitment"); 194 vdi.setDebutRecrutement(String.valueOf(startRecruitmentDate.getYear())); 195 vdi.setFinRecrutement(String.valueOf(endRecruitmentDate.getYear())); 196 197 LocalDate startValidationDate = content.getValue("start-date-validation"); 198 LocalDate endValidationDate = content.getValue("end-date-validation"); 199 vdi.setDebutValidation(String.valueOf(startValidationDate.getYear())); 200 vdi.setFinValidation(String.valueOf(endValidationDate.getYear())); 201 202 // Create tab of orgUnits VDI 203 CmpHabiliteeVdiDTO[] tabCmpHabiliteeVDIs = ContentDataHelper.getContentIdsListFromMultipleContentData(content, AbstractProgram.ORG_UNITS_REFERENCES) 204 .stream() 205 .map(id -> _getOrgUnitById(id)) 206 .filter(o -> o != null) 207 .map(o -> _createCmpHabiliteeVdiDTO(o)) 208 .toArray(CmpHabiliteeVdiDTO[]::new); 209 vdi.setListComposantesHabilitees(tabCmpHabiliteeVDIs); 210 211 creationSEMetierServiceInterface.creerVDI(vdi); 212 } 213 214 /** 215 * Create a Apogee ETP from a content 216 * @param content the content 217 * @param title the ETP title. Can be null, in this case we take the content title 218 * @param codETP the code ETP 219 * @throws RemoteException if a web service error occurred 220 * @throws javax.xml.rpc.ServiceException if an error occurred getting the service 221 */ 222 public void createETP(Content content, String title, String codETP) throws RemoteException, javax.xml.rpc.ServiceException 223 { 224 createETP(content, title, codETP, getCreationService()); 225 } 226 227 /** 228 * Create a Apogee ETP from a content 229 * @param content the content 230 * @param title the ETP title. Can be null, in this case we take the content title 231 * @param codETP the code ETP 232 * @param creationSEMetierServiceInterface the service to create element in Apogee 233 * @throws RemoteException if a web service error occurred 234 */ 235 public void createETP(Content content, String title, String codETP, CreationSEMetierServiceInterface creationSEMetierServiceInterface) throws RemoteException 236 { 237 String computedTitle = StringUtils.isNotBlank(title) ? title : content.getTitle(); 238 239 // codEtp='Code étape (obligatoire)' " 240 // licEtp='Libellé court étape (obligatoire)' " 241 // libEtp='Libellé long étape (non obligatoire)' " 242 // codCycle='Code cycle SISE (obligatoire)' " 243 // listComposantesCGE='[Code composante 1 (obligatoire),Code CGE 1 (obligatoire),capacité accueil 1 (non obligatoire)];[Code composante 2 (obligatoire),Code CGE 2 (obligatoire),capacité accueil 2 (non obligatoire)];... (obligatoire)' " 244 EtapeDTO etp = new EtapeDTO(); 245 etp.setCodEtp(codETP); 246 etp.setLicEtp(StringUtils.substring(computedTitle, 0, 24)); // need to cut to 25 max 247 etp.setLibEtp(computedTitle); 248 249 etp.setCodCycle(content.getValue("cycleApogee/codeApogee")); 250 251 if (content instanceof SubProgram) 252 { 253 // Create tab of orgUnits CGE 254 ComposanteCGEDTO[] tabComp = ((SubProgram) content).getOrgUnits() 255 .stream() 256 .map(id -> _getOrgUnitById(id)) 257 .filter(o -> o != null) 258 .map(o -> _createComposanteCGEDTO(o)) 259 .toArray(ComposanteCGEDTO[]::new); 260 etp.setListComposantesCGE(tabComp); 261 } 262 else if (content instanceof Container) 263 { 264 ContentValue value = content.getValue("orgUnit"); 265 ComposanteCGEDTO[] tabComp = new ComposanteCGEDTO[1]; 266 tabComp[0] = _createComposanteCGEDTO((OrgUnit) value.getContent()); 267 etp.setListComposantesCGE(tabComp); 268 } 269 270 creationSEMetierServiceInterface.creerETP(etp); 271 } 272 273 /** 274 * Create a Apogee VET from a content 275 * @param content the content 276 * @param title the VET title. Can be null, in this case we take the content title 277 * @param codETP the ETP code in Apogee 278 * @param versionETP the version ETP in Apogee 279 * @throws RemoteException if a web service error occurred 280 * @throws javax.xml.rpc.ServiceException if an error occurred getting the service 281 */ 282 public void createVET(Content content, String title, String codETP, Long versionETP) throws RemoteException, javax.xml.rpc.ServiceException 283 { 284 createVET(content, title, codETP, versionETP, getCreationService()); 285 } 286 287 /** 288 * Create a Apogee VET from a content 289 * @param content the content 290 * @param title the VET title. Can be null, in this case we take the content title 291 * @param codETP the ETP code in Apogee 292 * @param versionETP the version ETP in Apogee 293 * @param creationSEMetierServiceInterface the service to create element in Apogee 294 * @throws RemoteException if a web service error occurred 295 */ 296 public void createVET(Content content, String title, String codETP, Long versionETP, CreationSEMetierServiceInterface creationSEMetierServiceInterface) throws RemoteException 297 { 298 String computedTitle = StringUtils.isNotBlank(title) ? title : content.getTitle(); 299 300 // codEtp='Code étape (obligatoire)' " 301 // codVersionEtp='Code version étape (obligatoire)' " 302 // libWeb='Libellé web version étape (non obligatoire)' " 303 // codDureeEtp='Code durée étape' (obligatoire)' " 304 // codComposante='Code composante organisatrice (obligatoire)' " 305 // listRegimes='Code régime 1,Code régime 2,... (obligatoire)' " 306 // listCIP='[Code centre d'inscription pédagogique 1 (obligatoire),Témoin IA avant IP 1 (non obligatoire),Témoin inscription automatique aux éléments obligatoires 1 (non obligatoire)];[Code centre d'inscription pédagogique 2 (obligatoire),Témoin ...];... (obligatoire)' " 307 VersionEtapeDTO vet = new VersionEtapeDTO(); 308 vet.setCodEtp(codETP); 309 vet.setCodVersionEtp(new NullableInt(versionETP.intValue())); 310 vet.setLibWeb(computedTitle); 311 312 vet.setCodDureeEtp(content.getValue("duration-apogee/codeApogee")); 313 314 if (content instanceof SubProgram) // TODO prendre orgunit principale 315 { 316 String orgUnitId = ((SubProgram) content).getOrgUnits().get(0); 317 OrgUnit orgUnit = _getOrgUnitById(orgUnitId); 318 vet.setCodComposante(orgUnit.getValue(AbstractApogeeStructure.CODE_APOGEE_ATTRIBUTE_NAME)); 319 } 320 else if (content instanceof Container) 321 { 322 ContentValue value = content.getValue("orgUnit"); 323 vet.setCodComposante(value.getContent().getValue(AbstractApogeeStructure.CODE_APOGEE_ATTRIBUTE_NAME)); 324 } 325 326 // Create tab of regime 327 String[] inscriptionTypes = content.getValue("inscription-types/codeApogee", true); 328 RegimeDTO[] tabRegimes = Stream.of(inscriptionTypes) 329 .map(it -> _createRegime(it)) 330 .toArray(RegimeDTO[]::new); 331 vet.setListRegimes(tabRegimes); 332 333 // Create tab of CIP 334 String[] cips = content.getValue("cips/codeApogee", true); 335 CentreInsPedagogiDTO2[] tabCIP = Stream.of(cips) 336 .map(cip -> _createCIPVET(cip)) 337 .toArray(CentreInsPedagogiDTO2[]::new); 338 vet.setListCIP(tabCIP); 339 340 creationSEMetierServiceInterface.creerVET(vet); 341 } 342 343 /** 344 * Create in Apogee the link between a DIP and a ETP 345 * @param codDIP the DIP code in Apogee 346 * @param versionDIP the DIP version in Apogee 347 * @param codETP the ETP code in Apogee 348 * @param versionETP the ETP version in Apogee 349 * @throws RemoteException if a web service error occurred 350 * @throws javax.xml.rpc.ServiceException if an error occurred getting the service 351 */ 352 public void createLinkDIPETP(String codDIP, Long versionDIP, String codETP, Long versionETP) throws RemoteException, javax.xml.rpc.ServiceException 353 { 354 createLinkDIPETP(codDIP, versionDIP, codETP, versionETP, getCreationService()); 355 } 356 357 /** 358 * Create in Apogee the link between a DIP and a ETP 359 * @param codDIP the DIP code in Apogee 360 * @param versionDIP the DIP version in Apogee 361 * @param codETP the ETP code in Apogee 362 * @param versionETP the ETP version in Apogee 363 * @param creationSEMetierServiceInterface the service to create element in Apogee 364 * @throws RemoteException if a web service error occurred 365 */ 366 public void createLinkDIPETP(String codDIP, Long versionDIP, String codETP, Long versionETP, CreationSEMetierServiceInterface creationSEMetierServiceInterface) throws RemoteException 367 { 368 // codDip='Code diplôme (obligatoire)' " 369 // codVersionDip='Code version diplôme (obligatoire)' " 370 // codEtp='Code étape (obligatoire)' " 371 // codVersionEtp='Code version étape (obligatoire)'" 372 // anMinEtpDip='Année minimale étape pour diplôme (obligatoire)' " 373 // anMaxEtpDip='Année maximale étape pour diplôme (obligatoire)' " 374 VdiFractionnerVetDTO lien = new VdiFractionnerVetDTO(); 375 lien.setCodDip(codDIP); 376 lien.setCodVersionDip(new Nullable3Int(versionDIP.intValue())); 377 lien.setCodEtp(codETP); 378 lien.setCodVersionEtp(new Nullable3Int(versionETP.intValue())); 379 lien.setAnMinEtpDip(new NullableInt("1")); //TODO 380 lien.setAnMaxEtpDip(new NullableInt("2")); //TODO 381 382 creationSEMetierServiceInterface.creerLienVetVdi(lien); 383 } 384 385 /** 386 * Create in Apogee the link between a ETP and a LSE or ELP 387 * @param codETP the ETP code in Apogee. Can be null if codELP is set. 388 * @param versionETP the ETP version in Apogee. Can be null if codELP is set. 389 * @param codLSE the LSE code in Apogee. 390 * @param codELP the ELP version in Apogee. Can be null if codETP and versionETP is set. 391 * @param nbELP the number of ELP. Can be null if the LSE is mandatory or optional. 392 * @param ectsMin the min number of ects. Can be null if the LSE is mandatory or optional. 393 * @param ectsMax the max number of ects. Can be null if the LSE is mandatory or optional. 394 * @throws RemoteException if a web service error occurred 395 * @throws javax.xml.rpc.ServiceException if an error occurred getting the service 396 */ 397 public void createLinkETPELPLSE(String codETP, Long versionETP, String codLSE, String codELP, Long nbELP, Double ectsMin, Double ectsMax) throws RemoteException, javax.xml.rpc.ServiceException 398 { 399 createLinkETPELPLSE(codETP, versionETP, codLSE, codELP, nbELP, ectsMin, ectsMax, getCreationService()); 400 } 401 402 /** 403 * Create in Apogee the link between a ETP and a LSE or ELP 404 * @param codETP the ETP code in Apogee. Can be null if codELP is set. 405 * @param versionETP the ETP version in Apogee. Can be null if codELP is set. 406 * @param codLSE the LSE code in Apogee. 407 * @param codELP the ELP version in Apogee. Can be null if codETP and versionETP is set. 408 * @param nbELP the number of ELP. Can be null if the LSE is mandatory or optional. 409 * @param ectsMin the min number of ects. Can be null if the LSE is mandatory or optional. 410 * @param ectsMax the max number of ects. Can be null if the LSE is mandatory or optional. 411 * @param creationSEMetierServiceInterface the service to create element in Apogee 412 * @throws RemoteException if a web service error occurred 413 */ 414 public void createLinkETPELPLSE(String codETP, Long versionETP, String codLSE, String codELP, Long nbELP, Double ectsMin, Double ectsMax, CreationSEMetierServiceInterface creationSEMetierServiceInterface) throws RemoteException 415 { 416 // codElp='Code élément pédagogique (obligatoire)' " 417 // codEtp='Code étape (obligatoire)'" 418 // codVersionEtp='Code version étape (obligatoire)'" 419 // codListeElp='Code Liste d'éléments pédagogiques (obligatoire)'" 420 // nbrMinElp='Nombre minimum d'éléments à choisir dans la liste'" 421 // nbrMaxElp='Nombre maximum d'éléments à choisir dans la liste'" 422 // nbrMinCredits='Nombre minimum de crédits ECTS à choisir dans la liste'" 423 // nbrMaxCredits='Nombre maximum de crédits ECTS à choisir dans la liste'" 424 425 LienVetElpLseDTO lien = new LienVetElpLseDTO(); 426 if (StringUtils.isNotBlank(codETP)) 427 { 428 lien.setCodEtp(codETP); 429 } 430 431 if (versionETP != null) 432 { 433 lien.setCodVersionEtp(new Nullable3Int(versionETP.intValue())); 434 } 435 else 436 { 437 lien.setCodVersionEtp(new Nullable3Int()); 438 } 439 440 lien.setCodListeElp(codLSE); 441 lien.setCodElp(codELP); 442 443 if (nbELP != null) 444 { 445 lien.setNbrMinElp(new Nullable2Int(nbELP.intValue())); 446 lien.setNbrMaxElp(new Nullable2Int(nbELP.intValue())); 447 448 lien.setNbrMinCredits(new NullableDecimal(new BigDecimal(ectsMin))); 449 lien.setNbrMaxCredits(new NullableDecimal(new BigDecimal(ectsMax))); 450 } 451 creationSEMetierServiceInterface.creerLienVetElpLse(lien); 452 } 453 454 /** 455 * Create a Apogee LSE from a course list 456 * @param courseList the course list 457 * @param title the LSE title. Can be null, in this case we take the content title 458 * @param codLSE the code LSE 459 * @throws RemoteException if a web service error occurred 460 * @throws javax.xml.rpc.ServiceException if an error occurred getting the service 461 */ 462 public void createLSE(CourseList courseList, String title, String codLSE) throws RemoteException, javax.xml.rpc.ServiceException 463 { 464 createLSE(courseList, title, codLSE, getCreationService()); 465 } 466 467 /** 468 * Create a Apogee LSE from a course list 469 * @param courseList the course list 470 * @param title the LSE title. Can be null, in this case we take the content title 471 * @param codLSE the code LSE 472 * @param creationSEMetierServiceInterface the service to create element in Apogee 473 * @throws RemoteException if a web service error occurred 474 */ 475 public void createLSE(CourseList courseList, String title, String codLSE, CreationSEMetierServiceInterface creationSEMetierServiceInterface) throws RemoteException 476 { 477 String computedTitle = StringUtils.isNotBlank(title) ? title : courseList.getTitle(); 478 479 // Création du tableau d'ELP 480 int i = 0; 481 List<Course> courses = courseList.getCourses(); 482 ElementPedagogiDTO4[] tabELP = new ElementPedagogiDTO4[courses.size()]; 483 for (Course course : courses) 484 { 485 tabELP[i] = new ElementPedagogiDTO4(course.getValue(AbstractApogeeStructure.CODE_APOGEE_ATTRIBUTE_NAME)); 486 i++; 487 } 488 489 // codListeElp='Code Liste d'éléments pédagogiques (obligatoire)' " 490 // typListeElp='Code type de liste (obligatoire)' " 491 // libCourtListeElp='Libellé court liste d'éléments pédagogiques (obligatoire)'" 492 // libListeElp='Libelle long liste d'éléments pédagogiques (obligatoire)'" 493 // listElementPedagogi='Code élément pédagogique,Code élément pédagogique 2,Code élément pédagogique 3,... (au moins 1 codElp, obligatoire)'" 494 ListeElementPedagogiDTO3 lse = new ListeElementPedagogiDTO3(); 495 lse.setCodListeElp(codLSE); 496 497 String choiceTypeAmetys = courseList.getValue("choiceType"); 498 String typList = "O"; 499 if (choiceTypeAmetys.equals("MANDATORY")) 500 { 501 typList = "F"; 502 } 503 else if (choiceTypeAmetys.equals("CHOICE")) 504 { 505 typList = "X"; 506 } 507 lse.setTypListeElp(typList); 508 lse.setLibCourtListeElp(StringUtils.substring(computedTitle, 0, 24)); 509 lse.setLibListeElp(computedTitle); 510 lse.setListElementPedagogi(tabELP); 511 512 creationSEMetierServiceInterface.creerLSE(lse); 513 } 514 515 /** 516 * Create a Apogee mandatory LSE with his ELP 517 * @param titleLSE the title of the LSE 518 * @param codLSE the code of the LSE 519 * @param codELP the code of the ELP 520 * @throws RemoteException if a web service error occurred 521 * @throws javax.xml.rpc.ServiceException if an error occurred getting the service 522 */ 523 public void createMandatoryLSE(String titleLSE, String codLSE, String codELP) throws RemoteException, javax.xml.rpc.ServiceException 524 { 525 createMandatoryLSE(titleLSE, codLSE, codELP, getCreationService()); 526 } 527 528 /** 529 * Create a Apogee mandatory LSE with his ELP 530 * @param titleLSE the title of the LSE 531 * @param codLSE the code of the LSE 532 * @param codELP the code of the ELP 533 * @param creationSEMetierServiceInterface the service to create element in Apogee 534 * @throws RemoteException if a web service error occurred 535 */ 536 public void createMandatoryLSE(String titleLSE, String codLSE, String codELP, CreationSEMetierServiceInterface creationSEMetierServiceInterface) throws RemoteException 537 { 538 // Création du tableau d'ELP 539 ElementPedagogiDTO4[] tabELP = new ElementPedagogiDTO4[1]; 540 tabELP[0] = new ElementPedagogiDTO4(codELP); 541 542 // codListeElp='Code Liste d'éléments pédagogiques (obligatoire)' " 543 // typListeElp='Code type de liste (obligatoire)' " 544 // libCourtListeElp='Libellé court liste d'éléments pédagogiques (obligatoire)'" 545 // libListeElp='Libelle long liste d'éléments pédagogiques (obligatoire)'" 546 // listElementPedagogi='Code élément pédagogique,Code élément pédagogique 2,Code élément pédagogique 3,... (au moins 1 codElp, obligatoire)'" 547 ListeElementPedagogiDTO3 lse = new ListeElementPedagogiDTO3(); 548 lse.setCodListeElp(codLSE); 549 550 lse.setTypListeElp("F"); 551 lse.setLibCourtListeElp(StringUtils.substring(titleLSE, 0, 24)); 552 lse.setLibListeElp(titleLSE); 553 lse.setListElementPedagogi(tabELP); 554 555 creationSEMetierServiceInterface.creerLSE(lse); 556 } 557 558 /** 559 * Create a Apogee ELP from a content 560 * @param content the content 561 * @param title the ELP title. Can be null, in this case we take the content title 562 * @param codELP the code ELP 563 * @throws RemoteException if a web service error occurred 564 * @throws javax.xml.rpc.ServiceException if an error occurred getting the service 565 */ 566 public void createELP(Content content, String title, String codELP) throws RemoteException, javax.xml.rpc.ServiceException 567 { 568 createELP(content, title, codELP, getCreationService()); 569 } 570 571 /** 572 * Create a Apogee ELP from a content 573 * @param content the content 574 * @param title the ELP title. Can be null, in this case we take the content title 575 * @param codELP the code ELP 576 * @param creationSEMetierServiceInterface the service to create element in Apogee 577 * @throws RemoteException if a web service error occurred 578 */ 579 public void createELP(Content content, String title, String codELP, CreationSEMetierServiceInterface creationSEMetierServiceInterface) throws RemoteException 580 { 581 String computedTitle = StringUtils.isNotBlank(title) ? title : content.getTitle(); 582 583 // Create the ELP DTO 584 // codElp='Code élément pédagogique (obligatoire)' " 585 // libCourtElp='Libellé court élément pédagogique pédagogiques (obligatoire)'" 586 // libElp='Libelle long élément pédagogique (obligatoire)'" 587 // codNatureElp='Code de la nature ELP' (obligatoire)" 588 // codComposante='Code composante' (obligatoire)" 589 // listCentreInsPedagogi='Code CIP 1,Code CIP 2,Code CIP 3, ... (au moins 1 codCip, obligatoire)'" 590 ElementPedagogiDTO6 elp = new ElementPedagogiDTO6(); 591 elp.setCodElp(codELP); 592 elp.setLibElp(computedTitle); 593 elp.setLibCourtElp(StringUtils.substring(computedTitle, 0, 24)); 594 595 if (content instanceof Container) 596 { 597 ContentValue value = content.getValue("nature"); 598 elp.setCodNatureElp(value.getContent().getValue(AbstractApogeeStructure.CODE_APOGEE_ATTRIBUTE_NAME)); 599 } 600 else if (content instanceof Course) 601 { 602 ContentValue value = content.getValue("courseType"); 603 elp.setCodNatureElp(value.getContent().getValue(AbstractApogeeStructure.CODE_APOGEE_ATTRIBUTE_NAME)); 604 } 605 606 if (content instanceof Course) // TODO prendre orgunit principale 607 { 608 String orgUnitId = ((Course) content).getOrgUnits().get(0); 609 OrgUnit orgUnit = _getOrgUnitById(orgUnitId); 610 elp.setCodComposante(orgUnit.getValue(AbstractApogeeStructure.CODE_APOGEE_ATTRIBUTE_NAME)); 611 } 612 else if (content instanceof Container) 613 { 614 ContentValue value = content.getValue("orgUnit"); 615 elp.setCodComposante(value.getContent().getValue(AbstractApogeeStructure.CODE_APOGEE_ATTRIBUTE_NAME)); 616 } 617 618 // Create tab of CIP 619 String[] cips = content.getValue("cips/codeApogee", true); 620 CentreInsPedagogiDTO[] tabCIP = Stream.of(cips) 621 .map(cip -> _createCIPELP(cip)) 622 .toArray(CentreInsPedagogiDTO[]::new); 623 elp.setListCentreInsPedagogi(tabCIP); 624 625 creationSEMetierServiceInterface.creerELP_v2(elp); 626 } 627 628 /** 629 * Get orgUnit content from id 630 * @param orgUnitId the orgUnit id 631 * @return the orgUnit content 632 */ 633 private OrgUnit _getOrgUnitById(String orgUnitId) 634 { 635 try 636 { 637 OrgUnit orgUnit = _resolver.resolveById(orgUnitId); 638 return orgUnit; 639 } 640 catch (Exception e) 641 { 642 getLogger().warn("Can't get orgunit from id " + orgUnitId, e); 643 return null; 644 } 645 } 646 647 /** 648 * Create CIP object for VET Apogee 649 * @param code the code of the CIP 650 * @return the CIP object 651 */ 652 private CentreInsPedagogiDTO2 _createCIPVET(String code) 653 { 654 CentreInsPedagogiDTO2 cip = new CentreInsPedagogiDTO2(); 655 cip.setCodCIP(code); 656 657 return cip; 658 } 659 660 /** 661 * Create CIP object for ELP Apogee 662 * @param code the code of the CIP 663 * @return the CIP object 664 */ 665 private CentreInsPedagogiDTO _createCIPELP(String code) 666 { 667 return new CentreInsPedagogiDTO(code); 668 } 669 670 /** 671 * Create Regime object for Apogee 672 * @param code the code of the regime 673 * @return the Regime object 674 */ 675 private RegimeDTO _createRegime(String code) 676 { 677 RegimeDTO regime = new RegimeDTO(); 678 regime.setCodRegime(code); 679 680 return regime; 681 } 682 683 /** 684 * Create the orgUnit CGE for Apogee 685 * @param orgUnit the Ametys orgUnit 686 * @return the orgUnit CGE 687 */ 688 private ComposanteCGEDTO _createComposanteCGEDTO(OrgUnit orgUnit) 689 { 690 ComposanteCGEDTO comp = new ComposanteCGEDTO(); 691 comp.setCodComposante(orgUnit.getValue(AbstractApogeeStructure.CODE_APOGEE_ATTRIBUTE_NAME)); 692 comp.setCodCGE(orgUnit.getValue("codeCGE")); 693 694 return comp; 695 } 696 697 /** 698 * Create the orgUnit VDI for Apogee 699 * @param orgUnit the Ametys orgUnit 700 * @return the orgUnit VDI 701 */ 702 private CmpHabiliteeVdiDTO _createCmpHabiliteeVdiDTO(OrgUnit orgUnit) 703 { 704 CmpHabiliteeVdiDTO comp = new CmpHabiliteeVdiDTO(); 705 comp.setCodComposanteHabilitee(orgUnit.getValue(AbstractApogeeStructure.CODE_APOGEE_ATTRIBUTE_NAME)); 706 707 return comp; 708 } 709}