Kenmegne
6 days ago 6494941037ae2670876de9940853d50538eb5129
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.megatim.reporting.adhoc.process;
 
import com.megatim.reporting.adhoc.pojo.DescriptionEtat;
import com.megatim.reporting.adhoc.pojo.DescriptionSousEtat;
import com.megatim.reporting.adhoc.pojo.ElementToDisplay;
import com.megatim.reporting.adhoc.pojo.ProcessorElements;
import com.megatim.reporting.adhoc.pojo.ReportDefinition;
import com.megatim.reporting.adhoc.pojo.SubReportDefinition;
import java.util.ArrayList;
import java.util.List;
 
/**
 *
 * @author ASUS
 */
public class Processor {
 
    /**
     * Point d'entrée dans le moteur de reporting
     * @param desc :  objet contenant l'ensemble des éléments de l'état(liste des colonnes à imprimer, liste des sous-rapports, 
     * liste des éléments d'entête, etc)
     * @return
     * @throws Exception 
     */
    public String process(DescriptionEtat desc) throws Exception {
        ProcessorElements elements = constructReportElements(desc);
 
        return new SecondProcessor().generateJasperFile(elements);
    }
 
    private ProcessorElements constructReportElements(DescriptionEtat desc) {
        ReportDefinition repDef = reportDefinition(desc);
        List<SubReportDefinition> liste = new ArrayList<>();
 
        for (DescriptionSousEtat ds : desc.getSubReportDescriptions()) {
            SubReportDefinition subRepDef = subReportDefinition(ds);
            liste.add(subRepDef);
        }
        repDef.getSubReportDefs().addAll(liste);
 
        ProcessorElements elements = new ProcessorElements(desc.getTemplateFile(),
                desc.getRepositoryFolder(), desc.getRepositoryFolder(), repDef);
 
        return elements;
    }
 
    private SubReportDefinition subReportDefinition(DescriptionSousEtat ds) {
        SubReportDefinition subRepDef = new SubReportDefinition(ds.getSubReportName(), ds.getDataField().getName(), ds.getReportTitle(), ds.getRangSousEtat());
 
        subRepDef.setHaveLineNumber(ds.isHaveLineNumber());
        List<ElementToDisplay> subEltToDisplay = new ArrayList<>();
 
        for (ElementToDisplay e : ds.getElementsToDisplay()) {
            ElementToDisplay elt = new ElementToDisplay(
                    e.getLibelle(), e.getValue());
            elt.setPosition(e.getPosition());
            elt.setElementType(e.getElementType());
 
            subEltToDisplay.add(elt);
        }
 
        subRepDef.getElementsToDisplay().addAll(subEltToDisplay);
        subRepDef.getCustomFields().addAll(ds.getFieldsToDisplay());
 
        return subRepDef;
    }
 
    private ReportDefinition reportDefinition(DescriptionEtat desc) {
        ReportDefinition repDef = new ReportDefinition(desc.getReportName());
        repDef.setDetail(desc.isDetail());
        List<ElementToDisplay> eltToDisplay = new ArrayList<>();
 
        repDef.setHaveLineNumber(desc.isHaveLineNumber());
 
        for (ElementToDisplay e : desc.getElementsToDisplay()) {
            ElementToDisplay elt = new ElementToDisplay(e.getLibelle(), e.getValue());
            elt.setPosition(e.getPosition());
            elt.setElementType(e.getElementType());
 
            eltToDisplay.add(elt);
        }
        repDef.getElementsToDisplay().addAll(eltToDisplay);
 
        repDef.getCustomFields().addAll(desc.getFieldsToDisplay());
 
        return repDef;
    }
}