use of fr.univlorraine.ecandidat.utils.bean.export.ExportDossierStage in project esup-ecandidat by EsupPortail.
the class CandidatureController method generateDossier.
/**
* @param candidature
* @param listePresentation
* @param listeDatePresentation
* @param adresse
* @param listePj
* @param listeForm
* @return l'InputStream d'export
* @throws IOException
* @throws XDocReportException
*/
private ByteArrayInputStream generateDossier(final Candidature candidature, final List<SimpleTablePresentation> listePresentation, final List<SimpleTablePresentation> listeDatePresentation, final List<PjPresentation> listePj, final List<FormulairePresentation> listeForm) throws IOException, XDocReportException {
InputStream in = null;
final ByteArrayInOutStream out = new ByteArrayInOutStream();
try {
// 1) Load Docx file by filling Velocity template engine and cache
// it to the registry
in = MethodUtils.getXDocReportTemplate(ConstanteUtils.TEMPLATE_DOSSIER, i18nController.getLangueCandidat(), cacheController.getLangueDefault().getCodLangue());
if (in == null) {
return null;
}
/* Chargement des données utiles */
final Candidat candidat = candidature.getCandidat();
final CompteMinima cptMin = candidat.getCompteMinima();
final Formation formation = candidature.getFormation();
final Commission commission = formation.getCommission();
/* Utilisation de la demat */
final Boolean isDematerialisation = isCandidatureDematerialise(candidature);
/* On place les données dans des bean speciales export */
final ExportDossierCandidature exportCandidature = new ExportDossierCandidature(campagneController.getLibelleCampagne(cptMin.getCampagne()), commission.getLibComm(), adresseController.getLibelleAdresse(commission.getAdresse(), "\n"), commission.getMailComm(), commission.getTelComm(), formation, MethodUtils.formatToExportHtml(i18nController.getI18nTraduction(commission.getI18nCommentRetourComm())));
final ExportDossierCandidat exportCandidat = new ExportDossierCandidat(cptMin, candidat, formatterDate.format(candidat.getDatNaissCandidat()), adresseController.getLibelleAdresse(candidat.getAdresse(), "\n"), candidat.getIneCandidat(), candidat.getCleIneCandidat());
final ExportDossierBac exportDossierBac = new ExportDossierBac(candidat);
final List<ExportDossierCursusInterne> listeCursusInterne = new ArrayList<>();
candidat.getCandidatCursusInternes().forEach(e -> listeCursusInterne.add(new ExportDossierCursusInterne(e)));
listeCursusInterne.sort((p1, p2) -> p1.getAnnee().compareTo(p2.getAnnee()));
final List<ExportDossierCursusExterne> listeCursusExterne = new ArrayList<>();
candidat.getCandidatCursusPostBacs().forEach(e -> listeCursusExterne.add(new ExportDossierCursusExterne(e, tableRefController.getLibelleObtenuCursusByCode(e.getObtenuCursus()))));
listeCursusExterne.sort((p1, p2) -> p1.getAnnee().compareTo(p2.getAnnee()));
final List<ExportDossierStage> listeStage = new ArrayList<>();
candidat.getCandidatStage().forEach(e -> listeStage.add(new ExportDossierStage(e)));
listeStage.sort((p1, p2) -> p1.getAnnee().compareTo(p2.getAnnee()));
final List<ExportDossierCursusPro> listeCursusPro = new ArrayList<>();
candidat.getCandidatCursusPros().forEach(e -> listeCursusPro.add(new ExportDossierCursusPro(e)));
listeCursusPro.sort((p1, p2) -> p1.getAnnee().compareTo(p2.getAnnee()));
final List<ExportDossierMotivationAvis> listeMotivationAvis = new ArrayList<>();
final List<ExportDossierAvis> listeAvis = new ArrayList<>();
final List<ExportDossierPj> listeExportPj = new ArrayList<>();
if (!isDematerialisation) {
listePj.forEach(e -> {
if (!(e.getFilePj() == null && e.getPJConditionnel() && e.getCodStatut() != null && e.getCodStatut().equals(NomenclatureUtils.TYP_STATUT_PIECE_NON_CONCERNE))) {
listeExportPj.add(new ExportDossierPj(e.getLibPj(), e.getLibStatut(), e.getCommentaire()));
}
});
// listePj.forEach(e->listeExportPj.add(new
// ExportDossierPj(e.getLibPj(),e.getLibStatut(),e.getCommentaire())));
motivationAvisController.getMotivationAvisEnServiceByCtrCand(commission.getCentreCandidature()).forEach(e -> listeMotivationAvis.add(new ExportDossierMotivationAvis(i18nController.getI18nTraduction(e.getI18nLibMotiv()))));
typeDecisionController.getTypeDecisionsEnServiceByCtrCand(commission.getCentreCandidature()).forEach(e -> listeAvis.add(new ExportDossierAvis(i18nController.getI18nTraduction(e.getI18nLibTypDec()), e.getTypeAvis().getCodTypAvis())));
listeAvis.sort((p1, p2) -> p1.getOrder().compareTo(p2.getOrder()));
} else {
listePj.forEach(e -> {
final ExportDossierPj exportDossierPj = new ExportDossierPj(e.getLibPj(), e.getLibStatut(), e.getCommentaire());
if (e.getFilePj() != null && e.getFilePj().getFileFichier() != null) {
exportDossierPj.setLibFichier(e.getFilePj().getNomFichier());
}
listeExportPj.add(exportDossierPj);
});
}
final ExportDossierDate listeDates = new ExportDossierDate(MethodUtils.getLibByPresentationCode(listeDatePresentation, "candidature." + Candidature_.formation.getName() + "." + Formation_.datRetourForm.getName()), MethodUtils.getLibByPresentationCode(listeDatePresentation, "candidature." + Candidature_.formation.getName() + "." + Formation_.datConfirmForm.getName()), MethodUtils.getLibByPresentationCode(listeDatePresentation, "candidature." + Candidature_.formation.getName() + "." + Formation_.datJuryForm.getName()), MethodUtils.getLibByPresentationCode(listeDatePresentation, "candidature." + Candidature_.formation.getName() + "." + Formation_.datPubliForm.getName()));
final IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in, TemplateEngineKind.Velocity);
// 2) Create fields metadata to manage lazy loop (#foreach velocity) for table
// row.
/* FieldsMetadata metadata = report.createFieldsMetadata(); metadata.load(
* "cursusInterne", ExportDossierCursusInterne.class, true ); */
// 3) Create context Java model
final IContext context = report.createContext();
// Register project
context.put("dateheure", formatterDateTime.format(LocalDateTime.now()));
context.put("adresseEcandidat", loadBalancingController.getApplicationPathForCandidat());
context.put("candidature", exportCandidature);
context.put("candidat", exportCandidat);
context.put("bac", exportDossierBac);
context.put("cursusInternes", listeCursusInterne);
context.put("affichageCursusInterne", listeCursusInterne.size() > 0);
context.put("cursusExternes", listeCursusExterne);
context.put("affichageCursusExterne", listeCursusExterne.size() > 0);
context.put("stages", listeStage);
context.put("affichageStage", listeStage.size() > 0);
context.put("cursusPros", listeCursusPro);
context.put("affichageCursusPro", listeCursusPro.size() > 0);
context.put("listeAvis", listeAvis);
context.put("listeMotivationAvis", listeMotivationAvis);
context.put("dates", listeDates);
context.put("listePiecesJustifs", listeExportPj);
context.put("non-dematerialisation", !isDematerialisation);
context.put("affichagePjDemat", (listeExportPj.size() > 0 && isDematerialisation));
// 4) Generate report by merging Java model with the Docx
final Options options = Options.getTo(ConverterTypeTo.PDF).via(ConverterTypeVia.XWPF);
report.convert(context, options, out);
in.close();
return out.getInputStream();
} catch (final Exception e) {
return null;
} finally {
// fermeture des fichiers
MethodUtils.closeRessource(in);
MethodUtils.closeRessource(out);
}
}
Aggregations