Search in sources :

Example 1 with ApostilaDTO

use of com.tomasio.projects.trainning.dto.ApostilaDTO in project trainning by fernandotomasio.

the class Apostila method createDTO.

public ApostilaDTO createDTO() {
    ApostilaDTO dto = new ApostilaDTO();
    dto.setId(id);
    dto.setDefinicoes(definicoes);
    dto.setFolderId(folderId);
    dto.setIntroducao(introducao);
    dto.setAssetsFolderId(assetsFolderId);
    if (disciplina != null) {
        dto.setDisciplina(disciplina.createDTO());
    }
    return dto;
}
Also used : ApostilaDTO(com.tomasio.projects.trainning.dto.ApostilaDTO)

Example 2 with ApostilaDTO

use of com.tomasio.projects.trainning.dto.ApostilaDTO in project trainning by fernandotomasio.

the class TeachingDocumentsServiceSimpleImpl method findAllApostilas.

@Override
@Transactional(readOnly = true)
@SuppressWarnings({ "BroadCatchBlock", "TooBroadCatch" })
public ApostilaDTO[] findAllApostilas(Long curriculoMinimoId) {
    ApostilaDAO dao = factory.getApostilaDAO();
    ApostilaDTO[] apostilasArray = null;
    try {
        List<Apostila> apostilas = dao.findAllApostilas(curriculoMinimoId);
        apostilasArray = new ApostilaDTO[apostilas.size()];
        for (int i = 0; i < apostilasArray.length; i++) {
            apostilasArray[i] = apostilas.get(i).createDTO();
        }
    } catch (DAOException ex) {
        throw new CoreException("Erro de de acesso ao banco de dados: " + ex.getMessage());
    } catch (Exception ex) {
        throw new CoreException("Erro de sistema: " + ex.toString());
    }
    return apostilasArray;
}
Also used : DAOException(com.tomasio.projects.trainning.exception.DAOException) CoreException(com.tomasio.projects.trainning.exeption.CoreException) AnexoApostilaDTO(com.tomasio.projects.trainning.dto.AnexoApostilaDTO) SecaoApostilaDTO(com.tomasio.projects.trainning.dto.SecaoApostilaDTO) ApostilaDTO(com.tomasio.projects.trainning.dto.ApostilaDTO) CapituloApostilaDTO(com.tomasio.projects.trainning.dto.CapituloApostilaDTO) AnexoApostila(com.tomasio.projects.trainning.model.AnexoApostila) Apostila(com.tomasio.projects.trainning.model.Apostila) CapituloApostila(com.tomasio.projects.trainning.model.CapituloApostila) SecaoApostila(com.tomasio.projects.trainning.model.SecaoApostila) CoreException(com.tomasio.projects.trainning.exeption.CoreException) DAOException(com.tomasio.projects.trainning.exception.DAOException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with ApostilaDTO

use of com.tomasio.projects.trainning.dto.ApostilaDTO in project trainning by fernandotomasio.

the class DOC003PDF method makeReport.

@Override
public void makeReport() {
    teachingDocumentsService = (TeachingDocumentsService) services.get("teachingDocumentsService");
    document = documentManager.getDocumentPortrait();
    os = documentManager.prepareDocument(document);
    writer = documentManager.getWritter();
    ChapterSectionTOC eventHandler = new ChapterSectionTOC();
    writer.setPageEvent(eventHandler);
    document.open();
    CSSResolver cssResolver = new StyleAttrCSSResolver();
    CssFile cssFile = null;
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    String cssStylePath = classLoader.getResource("doc3-styles.css").getPath();
    cssFile = XMLWorkerHelper.getCSS(classLoader.getResourceAsStream("doc3-styles.css"));
    cssResolver.addCss(cssFile);
    XMLWorkerFontProvider fontProvider = new XMLWorkerFontProvider(XMLWorkerFontProvider.DONTLOOKFORFONTS);
    String fontFilePath = classLoader.getResource("MyriadPro-Regular.otf").getPath();
    // fontProvider.register(fontFilePath);
    CssAppliers cssAppliers = new CssAppliersImpl(fontProvider);
    HtmlPipelineContext htmlContext = new HtmlPipelineContext(cssAppliers);
    htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
    PdfWriterPipeline pdf = new PdfWriterPipeline(document, writer);
    HtmlPipeline html = new HtmlPipeline(htmlContext, pdf);
    CssResolverPipeline css = new CssResolverPipeline(cssResolver, html);
    XMLWorker worker = new XMLWorker(css, true);
    p = new XMLParser(worker);
    try {
        String apostilaIdParam = (String) params.get("apostilaId");
        Long apostilaId = Long.parseLong(apostilaIdParam);
        ApostilaDTO apostila = teachingDocumentsService.findApostila(apostilaId);
        CurriculoMinimoDTO curriculo = teachingDocumentsService.findCurriculoMinimo(apostila.getDisciplina().getCurriculoMinimo().getId());
        buildCover(document, curriculo, apostila);
        CapituloApostilaDTO[] capitulos = teachingDocumentsService.findAllCapitulosApostila(apostilaId);
        for (CapituloApostilaDTO capitulo : capitulos) {
            Chapter ch = buildCapitulo(capitulo, p, document);
            document.add(ch);
        }
        document.add(buildReferencias(apostilaId));
        document.add(buildSumario(eventHandler.titles));
    } catch (DocumentException e) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, e);
        throw new CoreException(e.getMessage());
    } catch (IOException ex) {
        Logger.getLogger(DOC003PDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        document.close();
    }
    try {
        PdfReader reader = new PdfReader(os.toByteArray());
        int n = reader.getNumberOfPages();
        String pagesInterval = String.format("1-2,%d, 3-%d", n, n - 1);
        reader.selectPages(pagesInterval);
        os = new ByteArrayOutputStream();
        PdfStamper stamper = new PdfStamper(reader, os);
        stamper.close();
        reader.close();
    } catch (IOException | DocumentException ex) {
        Logger.getLogger(DOC003PDF.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : StyleAttrCSSResolver(com.itextpdf.tool.xml.css.StyleAttrCSSResolver) CssFile(com.itextpdf.tool.xml.css.CssFile) PdfReader(com.itextpdf.text.pdf.PdfReader) CssAppliersImpl(com.itextpdf.tool.xml.html.CssAppliersImpl) CSSResolver(com.itextpdf.tool.xml.pipeline.css.CSSResolver) StyleAttrCSSResolver(com.itextpdf.tool.xml.css.StyleAttrCSSResolver) DocumentException(com.itextpdf.text.DocumentException) CapituloApostilaDTO(com.tomasio.projects.trainning.dto.CapituloApostilaDTO) CurriculoMinimoDTO(com.tomasio.projects.trainning.dto.CurriculoMinimoDTO) XMLParser(com.itextpdf.tool.xml.parser.XMLParser) HtmlPipeline(com.itextpdf.tool.xml.pipeline.html.HtmlPipeline) SecaoApostilaDTO(com.tomasio.projects.trainning.dto.SecaoApostilaDTO) ApostilaDTO(com.tomasio.projects.trainning.dto.ApostilaDTO) CapituloApostilaDTO(com.tomasio.projects.trainning.dto.CapituloApostilaDTO) Chapter(com.itextpdf.text.Chapter) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CssResolverPipeline(com.itextpdf.tool.xml.pipeline.css.CssResolverPipeline) XMLWorkerFontProvider(com.itextpdf.tool.xml.XMLWorkerFontProvider) XMLWorker(com.itextpdf.tool.xml.XMLWorker) CoreException(com.tomasio.projects.trainning.exeption.CoreException) CssAppliers(com.itextpdf.tool.xml.html.CssAppliers) PdfWriterPipeline(com.itextpdf.tool.xml.pipeline.end.PdfWriterPipeline) PdfStamper(com.itextpdf.text.pdf.PdfStamper) HtmlPipelineContext(com.itextpdf.tool.xml.pipeline.html.HtmlPipelineContext)

Example 4 with ApostilaDTO

use of com.tomasio.projects.trainning.dto.ApostilaDTO in project trainning by fernandotomasio.

the class DOC003PDF method buildReferencias.

private Chapter buildReferencias(Long apostilaId) {
    ApostilaDTO apostila = teachingDocumentsService.findApostila(apostilaId);
    ReferenciaDTO[] referencias = teachingDocumentsService.findAllReferenciasByDisciplina(apostila.getDisciplina().getId());
    String referenciasLabel = "REFERÊNCIAS";
    Paragraph referenciasChapter = new Paragraph(referenciasLabel, fontManager.getBoldFont());
    referenciasChapter.setAlignment(Element.ALIGN_CENTER);
    Chapter ch = new Chapter(referenciasChapter, 0);
    ch.setNumberDepth(0);
    ch.add(Chunk.NEWLINE);
    for (ReferenciaDTO referencia : referencias) {
        ch.add(new Paragraph(referencia.getTexto(), fontManager.getDefaultFont()));
    }
    return ch;
}
Also used : ReferenciaDTO(com.tomasio.projects.trainning.dto.ReferenciaDTO) SecaoApostilaDTO(com.tomasio.projects.trainning.dto.SecaoApostilaDTO) ApostilaDTO(com.tomasio.projects.trainning.dto.ApostilaDTO) CapituloApostilaDTO(com.tomasio.projects.trainning.dto.CapituloApostilaDTO) Chapter(com.itextpdf.text.Chapter) Paragraph(com.itextpdf.text.Paragraph)

Example 5 with ApostilaDTO

use of com.tomasio.projects.trainning.dto.ApostilaDTO in project trainning by fernandotomasio.

the class ApostilasController method detailApostila.

@RequestMapping("/detail")
public String detailApostila(Model model, WebRequest request) {
    String apostilaIdParam = request.getParameter("apostilaId");
    Long apostilaId = Long.parseLong(apostilaIdParam);
    ApostilaDTO apostila = teachingDocumentsService.findApostila(apostilaId);
    model.addAttribute("apostila", apostila);
    CapituloApostilaDTO[] capitulos = teachingDocumentsService.findAllCapitulosApostila(apostila.getId());
    List capitulosDataList = new ArrayList();
    for (CapituloApostilaDTO capitulo : capitulos) {
        Map itemCapitulo = new HashMap();
        itemCapitulo.put("id", capitulo.getId());
        UnidadeDidaticaDTO unidadeDidatica = teachingDocumentsService.findUnidadeDidatica(capitulo.getUnidadeDidatica().getId());
        itemCapitulo.put("numero", unidadeDidatica.getNumeroGeral());
        itemCapitulo.put("titulo", capitulo.getUnidadeDidatica().getDescricao());
        SecaoApostilaDTO[] secoes = teachingDocumentsService.findAllSecoesApostila(capitulo.getId());
        List secoesApostilaDataList = new ArrayList();
        for (SecaoApostilaDTO secao : secoes) {
            Map itemSecao = new HashMap();
            itemSecao.put("id", secao.getId());
            itemSecao.put("titulo", secao.getSubunidadeDidatica().getDescricao());
            SubunidadeDidaticaDTO subunidadeDidatica = teachingDocumentsService.findSubunidadeDidatica(secao.getSubunidadeDidatica().getId());
            itemSecao.put("numero", subunidadeDidatica.getNumeroGeral());
            secoesApostilaDataList.add(itemSecao);
        }
        itemCapitulo.put("secoes", secoesApostilaDataList);
        capitulosDataList.add(itemCapitulo);
    }
    List anexosDataList = new ArrayList();
    AnexoApostilaDTO[] anexos = teachingDocumentsService.findAllAnexosApostilas(apostila.getId());
    for (AnexoApostilaDTO anexo : anexos) {
        Map item = new HashMap();
        item.put("id", anexo.getId());
        item.put("titulo", anexo.getTitulo());
        anexosDataList.add(item);
    }
    model.addAttribute("capitulosDataList", capitulosDataList);
    model.addAttribute("anexosDataList", anexosDataList);
    return "apostilas/detail";
}
Also used : HashMap(java.util.HashMap) AnexoApostilaDTO(com.tomasio.projects.trainning.dto.AnexoApostilaDTO) ApostilaDTO(com.tomasio.projects.trainning.dto.ApostilaDTO) CapituloApostilaDTO(com.tomasio.projects.trainning.dto.CapituloApostilaDTO) SecaoApostilaDTO(com.tomasio.projects.trainning.dto.SecaoApostilaDTO) ArrayList(java.util.ArrayList) SubunidadeDidaticaDTO(com.tomasio.projects.trainning.dto.SubunidadeDidaticaDTO) UnidadeDidaticaDTO(com.tomasio.projects.trainning.dto.UnidadeDidaticaDTO) SecaoApostilaDTO(com.tomasio.projects.trainning.dto.SecaoApostilaDTO) CapituloApostilaDTO(com.tomasio.projects.trainning.dto.CapituloApostilaDTO) ArrayList(java.util.ArrayList) List(java.util.List) AnexoApostilaDTO(com.tomasio.projects.trainning.dto.AnexoApostilaDTO) HashMap(java.util.HashMap) Map(java.util.Map) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ApostilaDTO (com.tomasio.projects.trainning.dto.ApostilaDTO)9 CapituloApostilaDTO (com.tomasio.projects.trainning.dto.CapituloApostilaDTO)8 SecaoApostilaDTO (com.tomasio.projects.trainning.dto.SecaoApostilaDTO)8 AnexoApostilaDTO (com.tomasio.projects.trainning.dto.AnexoApostilaDTO)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 Chapter (com.itextpdf.text.Chapter)2 DisciplinaDTO (com.tomasio.projects.trainning.dto.DisciplinaDTO)2 SubunidadeDidaticaDTO (com.tomasio.projects.trainning.dto.SubunidadeDidaticaDTO)2 UnidadeDidaticaDTO (com.tomasio.projects.trainning.dto.UnidadeDidaticaDTO)2 CoreException (com.tomasio.projects.trainning.exeption.CoreException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DocumentException (com.itextpdf.text.DocumentException)1 Paragraph (com.itextpdf.text.Paragraph)1 PdfReader (com.itextpdf.text.pdf.PdfReader)1 PdfStamper (com.itextpdf.text.pdf.PdfStamper)1 XMLWorker (com.itextpdf.tool.xml.XMLWorker)1 XMLWorkerFontProvider (com.itextpdf.tool.xml.XMLWorkerFontProvider)1 CssFile (com.itextpdf.tool.xml.css.CssFile)1