|
16 | 16 | */
|
17 | 17 | package io.github.project.openubl.xmlbuilderlib.facade;
|
18 | 18 |
|
19 |
| -import io.github.project.openubl.xmlbuilderlib.config.XMLBuilderConfig; |
| 19 | +import io.github.project.openubl.xmlbuilderlib.clock.SystemClockSingleton; |
| 20 | +import io.github.project.openubl.xmlbuilderlib.config.Config; |
20 | 21 | import io.github.project.openubl.xmlbuilderlib.freemarker.FreemarkerExecutor;
|
| 22 | +import io.github.project.openubl.xmlbuilderlib.hibernate.validator.ValidatorSingleton; |
21 | 23 | import io.github.project.openubl.xmlbuilderlib.models.input.constraints.CompleteValidation;
|
22 | 24 | import io.github.project.openubl.xmlbuilderlib.models.input.standard.invoice.InvoiceInputModel;
|
23 | 25 | import io.github.project.openubl.xmlbuilderlib.models.input.standard.note.creditNote.CreditNoteInputModel;
|
|
34 | 36 | import io.github.project.openubl.xmlbuilderlib.models.output.sunat.SummaryDocumentOutputModel;
|
35 | 37 | import io.github.project.openubl.xmlbuilderlib.models.output.sunat.VoidedDocumentOutputModel;
|
36 | 38 | import io.github.project.openubl.xmlbuilderlib.utils.InputToOutput;
|
37 |
| -import io.github.project.openubl.xmlbuilderlib.utils.SystemClock; |
| 39 | +import io.github.project.openubl.xmlbuilderlib.clock.SystemClock; |
38 | 40 |
|
39 | 41 | import javax.validation.*;
|
40 |
| -import java.util.Calendar; |
41 | 42 | import java.util.Set;
|
42 |
| -import java.util.TimeZone; |
43 | 43 |
|
44 |
| -public class DocumentFacade { |
| 44 | +public class DocumentManager { |
45 | 45 |
|
46 |
| - private DocumentFacade() { |
| 46 | + private DocumentManager() { |
47 | 47 | // Only static methods
|
48 | 48 | }
|
49 | 49 |
|
50 | 50 | private static SystemClock getDefaultSystemClock() {
|
51 |
| - return new SystemClock() { |
52 |
| - @Override |
53 |
| - public TimeZone getTimeZone() { |
54 |
| - return TimeZone.getTimeZone("America/Lima"); |
55 |
| - } |
56 |
| - |
57 |
| - @Override |
58 |
| - public Calendar getCalendarInstance() { |
59 |
| - return Calendar.getInstance(); |
60 |
| - } |
61 |
| - }; |
| 51 | + return SystemClockSingleton.getInstance().getClock(); |
62 | 52 | }
|
63 | 53 |
|
64 | 54 | private static void validateInput(Object input) {
|
65 |
| - ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); |
66 |
| - Validator validator = factory.getValidator(); |
| 55 | + Validator validator = ValidatorSingleton.getInstance().getValidator(); |
67 | 56 | Set<ConstraintViolation<Object>> violations = validator.validate(input, CompleteValidation.class);
|
68 | 57 | if (!violations.isEmpty()) {
|
69 | 58 | throw new ConstraintViolationException(violations);
|
70 | 59 | }
|
71 | 60 | }
|
72 | 61 |
|
73 |
| - public static DocumentWrapper<InvoiceOutputModel> createXML(InvoiceInputModel input, XMLBuilderConfig config) { |
| 62 | + public static DocumentWrapper<InvoiceOutputModel> createXML(InvoiceInputModel input, Config config) { |
74 | 63 | validateInput(input);
|
75 | 64 | InvoiceOutputModel output = InputToOutput.toOutput(input, config, getDefaultSystemClock());
|
76 | 65 | String xml = FreemarkerExecutor.createXML(output);
|
77 | 66 | return new DocumentWrapper<>(xml, output);
|
78 | 67 | }
|
79 | 68 |
|
80 |
| - public static DocumentWrapper<InvoiceOutputModel> createXML(InvoiceInputModel input, XMLBuilderConfig config, SystemClock systemClock) { |
| 69 | + public static DocumentWrapper<InvoiceOutputModel> createXML(InvoiceInputModel input, Config config, SystemClock systemClock) { |
81 | 70 | validateInput(input);
|
82 | 71 | InvoiceOutputModel output = InputToOutput.toOutput(input, config, systemClock);
|
83 | 72 | String xml = FreemarkerExecutor.createXML(output);
|
84 | 73 | return new DocumentWrapper<>(xml, output);
|
85 | 74 | }
|
86 | 75 |
|
87 |
| - public static DocumentWrapper<CreditNoteOutputModel> createXML(CreditNoteInputModel input, XMLBuilderConfig config) { |
| 76 | + public static DocumentWrapper<CreditNoteOutputModel> createXML(CreditNoteInputModel input, Config config) { |
88 | 77 | validateInput(input);
|
89 | 78 | CreditNoteOutputModel output = InputToOutput.toOutput(input, config, getDefaultSystemClock());
|
90 | 79 | String xml = FreemarkerExecutor.createXML(output);
|
91 | 80 | return new DocumentWrapper<>(xml, output);
|
92 | 81 | }
|
93 | 82 |
|
94 |
| - public static DocumentWrapper<CreditNoteOutputModel> createXML(CreditNoteInputModel input, XMLBuilderConfig config, SystemClock systemClock) { |
| 83 | + public static DocumentWrapper<CreditNoteOutputModel> createXML(CreditNoteInputModel input, Config config, SystemClock systemClock) { |
95 | 84 | validateInput(input);
|
96 | 85 | CreditNoteOutputModel output = InputToOutput.toOutput(input, config, systemClock);
|
97 | 86 | String xml = FreemarkerExecutor.createXML(output);
|
98 | 87 | return new DocumentWrapper<>(xml, output);
|
99 | 88 | }
|
100 | 89 |
|
101 |
| - public static DocumentWrapper<DebitNoteOutputModel> createXML(DebitNoteInputModel input, XMLBuilderConfig config) { |
| 90 | + public static DocumentWrapper<DebitNoteOutputModel> createXML(DebitNoteInputModel input, Config config) { |
102 | 91 | validateInput(input);
|
103 | 92 | DebitNoteOutputModel output = InputToOutput.toOutput(input, config, getDefaultSystemClock());
|
104 | 93 | String xml = FreemarkerExecutor.createXML(output);
|
105 | 94 | return new DocumentWrapper<>(xml, output);
|
106 | 95 | }
|
107 | 96 |
|
108 |
| - public static DocumentWrapper<DebitNoteOutputModel> createXML(DebitNoteInputModel input, XMLBuilderConfig config, SystemClock systemClock) { |
| 97 | + public static DocumentWrapper<DebitNoteOutputModel> createXML(DebitNoteInputModel input, Config config, SystemClock systemClock) { |
109 | 98 | DebitNoteOutputModel output = InputToOutput.toOutput(input, config, systemClock);
|
110 | 99 | String xml = FreemarkerExecutor.createXML(output);
|
111 | 100 | return new DocumentWrapper<>(xml, output);
|
112 | 101 | }
|
113 | 102 |
|
114 |
| - public static DocumentWrapper<VoidedDocumentOutputModel> createXML(VoidedDocumentInputModel input, XMLBuilderConfig config) { |
| 103 | + public static DocumentWrapper<VoidedDocumentOutputModel> createXML(VoidedDocumentInputModel input, Config config) { |
115 | 104 | validateInput(input);
|
116 | 105 | VoidedDocumentOutputModel output = InputToOutput.toOutput(input, config, getDefaultSystemClock());
|
117 | 106 | String xml = FreemarkerExecutor.createXML(output);
|
118 | 107 | return new DocumentWrapper<>(xml, output);
|
119 | 108 | }
|
120 | 109 |
|
121 |
| - public static DocumentWrapper<VoidedDocumentOutputModel> createXML(VoidedDocumentInputModel input, XMLBuilderConfig config, SystemClock systemClock) { |
| 110 | + public static DocumentWrapper<VoidedDocumentOutputModel> createXML(VoidedDocumentInputModel input, Config config, SystemClock systemClock) { |
122 | 111 | validateInput(input);
|
123 | 112 | VoidedDocumentOutputModel output = InputToOutput.toOutput(input, config, systemClock);
|
124 | 113 | String xml = FreemarkerExecutor.createXML(output);
|
125 | 114 | return new DocumentWrapper<>(xml, output);
|
126 | 115 | }
|
127 | 116 |
|
128 |
| - public static DocumentWrapper<SummaryDocumentOutputModel> createXML(SummaryDocumentInputModel input, XMLBuilderConfig config) { |
| 117 | + public static DocumentWrapper<SummaryDocumentOutputModel> createXML(SummaryDocumentInputModel input, Config config) { |
129 | 118 | validateInput(input);
|
130 | 119 | SummaryDocumentOutputModel output = InputToOutput.toOutput(input, config, getDefaultSystemClock());
|
131 | 120 | String xml = FreemarkerExecutor.createXML(output);
|
132 | 121 | return new DocumentWrapper<>(xml, output);
|
133 | 122 | }
|
134 | 123 |
|
135 |
| - public static DocumentWrapper<SummaryDocumentOutputModel> createXML(SummaryDocumentInputModel input, XMLBuilderConfig config, SystemClock systemClock) { |
| 124 | + public static DocumentWrapper<SummaryDocumentOutputModel> createXML(SummaryDocumentInputModel input, Config config, SystemClock systemClock) { |
136 | 125 | validateInput(input);
|
137 | 126 | SummaryDocumentOutputModel output = InputToOutput.toOutput(input, config, systemClock);
|
138 | 127 | String xml = FreemarkerExecutor.createXML(output);
|
139 | 128 | return new DocumentWrapper<>(xml, output);
|
140 | 129 | }
|
141 | 130 |
|
142 |
| - public static DocumentWrapper<PerceptionOutputModel> createXML(PerceptionInputModel input, XMLBuilderConfig config) { |
| 131 | + public static DocumentWrapper<PerceptionOutputModel> createXML(PerceptionInputModel input, Config config) { |
143 | 132 | validateInput(input);
|
144 | 133 | PerceptionOutputModel output = InputToOutput.toOutput(input, config, getDefaultSystemClock());
|
145 | 134 | String xml = FreemarkerExecutor.createXML(output);
|
146 | 135 | return new DocumentWrapper<>(xml, output);
|
147 | 136 | }
|
148 | 137 |
|
149 |
| - public static DocumentWrapper<PerceptionOutputModel> createXML(PerceptionInputModel input, XMLBuilderConfig config, SystemClock systemClock) { |
| 138 | + public static DocumentWrapper<PerceptionOutputModel> createXML(PerceptionInputModel input, Config config, SystemClock systemClock) { |
150 | 139 | validateInput(input);
|
151 | 140 | PerceptionOutputModel output = InputToOutput.toOutput(input, config, systemClock);
|
152 | 141 | String xml = FreemarkerExecutor.createXML(output);
|
153 | 142 | return new DocumentWrapper<>(xml, output);
|
154 | 143 | }
|
155 | 144 |
|
156 |
| - public static DocumentWrapper<RetentionOutputModel> createXML(RetentionInputModel input, XMLBuilderConfig config) { |
| 145 | + public static DocumentWrapper<RetentionOutputModel> createXML(RetentionInputModel input, Config config) { |
157 | 146 | validateInput(input);
|
158 | 147 | RetentionOutputModel output = InputToOutput.toOutput(input, config, getDefaultSystemClock());
|
159 | 148 | String xml = FreemarkerExecutor.createXML(output);
|
160 | 149 | return new DocumentWrapper<>(xml, output);
|
161 | 150 | }
|
162 | 151 |
|
163 |
| - public static DocumentWrapper<RetentionOutputModel> createXML(RetentionInputModel input, XMLBuilderConfig config, SystemClock systemClock) { |
| 152 | + public static DocumentWrapper<RetentionOutputModel> createXML(RetentionInputModel input, Config config, SystemClock systemClock) { |
164 | 153 | validateInput(input);
|
165 | 154 | RetentionOutputModel output = InputToOutput.toOutput(input, config, systemClock);
|
166 | 155 | String xml = FreemarkerExecutor.createXML(output);
|
|
0 commit comments