Search in sources :

Example 1 with ExportDossierCandidature

use of fr.univlorraine.ecandidat.utils.bean.export.ExportDossierCandidature 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);
    }
}
Also used : Options(fr.opensagres.xdocreport.converter.Options) IContext(fr.opensagres.xdocreport.template.IContext) ExportDossierAvis(fr.univlorraine.ecandidat.utils.bean.export.ExportDossierAvis) ExportDossierCursusPro(fr.univlorraine.ecandidat.utils.bean.export.ExportDossierCursusPro) Commission(fr.univlorraine.ecandidat.entities.ecandidat.Commission) SecurityCommission(fr.univlorraine.ecandidat.services.security.SecurityCommission) ArrayList(java.util.ArrayList) ExportDossierCandidat(fr.univlorraine.ecandidat.utils.bean.export.ExportDossierCandidat) Candidat(fr.univlorraine.ecandidat.entities.ecandidat.Candidat) ExportLettreCandidat(fr.univlorraine.ecandidat.utils.bean.export.ExportLettreCandidat) ExportDossierCandidat(fr.univlorraine.ecandidat.utils.bean.export.ExportDossierCandidat) ExportDossierCursusExterne(fr.univlorraine.ecandidat.utils.bean.export.ExportDossierCursusExterne) ExportDossierCandidature(fr.univlorraine.ecandidat.utils.bean.export.ExportDossierCandidature) ExportDossierBac(fr.univlorraine.ecandidat.utils.bean.export.ExportDossierBac) ByteArrayInOutStream(fr.univlorraine.ecandidat.utils.ByteArrayInOutStream) IXDocReport(fr.opensagres.xdocreport.document.IXDocReport) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ExportDossierCursusInterne(fr.univlorraine.ecandidat.utils.bean.export.ExportDossierCursusInterne) ExportDossierMotivationAvis(fr.univlorraine.ecandidat.utils.bean.export.ExportDossierMotivationAvis) IOException(java.io.IOException) XDocConverterException(fr.opensagres.xdocreport.converter.XDocConverterException) XDocReportException(fr.opensagres.xdocreport.core.XDocReportException) CompteMinima(fr.univlorraine.ecandidat.entities.ecandidat.CompteMinima) ExportDossierDate(fr.univlorraine.ecandidat.utils.bean.export.ExportDossierDate) ExportDossierPj(fr.univlorraine.ecandidat.utils.bean.export.ExportDossierPj) ExportDossierStage(fr.univlorraine.ecandidat.utils.bean.export.ExportDossierStage) Formation(fr.univlorraine.ecandidat.entities.ecandidat.Formation)

Aggregations

Options (fr.opensagres.xdocreport.converter.Options)1 XDocConverterException (fr.opensagres.xdocreport.converter.XDocConverterException)1 XDocReportException (fr.opensagres.xdocreport.core.XDocReportException)1 IXDocReport (fr.opensagres.xdocreport.document.IXDocReport)1 IContext (fr.opensagres.xdocreport.template.IContext)1 Candidat (fr.univlorraine.ecandidat.entities.ecandidat.Candidat)1 Commission (fr.univlorraine.ecandidat.entities.ecandidat.Commission)1 CompteMinima (fr.univlorraine.ecandidat.entities.ecandidat.CompteMinima)1 Formation (fr.univlorraine.ecandidat.entities.ecandidat.Formation)1 SecurityCommission (fr.univlorraine.ecandidat.services.security.SecurityCommission)1 ByteArrayInOutStream (fr.univlorraine.ecandidat.utils.ByteArrayInOutStream)1 ExportDossierAvis (fr.univlorraine.ecandidat.utils.bean.export.ExportDossierAvis)1 ExportDossierBac (fr.univlorraine.ecandidat.utils.bean.export.ExportDossierBac)1 ExportDossierCandidat (fr.univlorraine.ecandidat.utils.bean.export.ExportDossierCandidat)1 ExportDossierCandidature (fr.univlorraine.ecandidat.utils.bean.export.ExportDossierCandidature)1 ExportDossierCursusExterne (fr.univlorraine.ecandidat.utils.bean.export.ExportDossierCursusExterne)1 ExportDossierCursusInterne (fr.univlorraine.ecandidat.utils.bean.export.ExportDossierCursusInterne)1 ExportDossierCursusPro (fr.univlorraine.ecandidat.utils.bean.export.ExportDossierCursusPro)1 ExportDossierDate (fr.univlorraine.ecandidat.utils.bean.export.ExportDossierDate)1 ExportDossierMotivationAvis (fr.univlorraine.ecandidat.utils.bean.export.ExportDossierMotivationAvis)1