Skip to content

Commit d25ea7d

Browse files
committed
Merge branch 'develop'
2 parents e2dbf8e + 213a52f commit d25ea7d

File tree

13 files changed

+205
-122
lines changed

13 files changed

+205
-122
lines changed
Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,8 @@
11
package org.fugerit.java.doc.playground.convert;
22

3-
public class ConvertInput {
3+
import org.fugerit.java.doc.playground.facade.BasicInput;
4+
5+
public class ConvertInput extends BasicInput {
46

5-
private String inputFormat;
6-
private String outputFormat;
7-
private String docContent;
8-
9-
public String getInputFormat() {
10-
return inputFormat;
11-
}
12-
public void setInputFormat(String inputFormat) {
13-
this.inputFormat = inputFormat;
14-
}
15-
public String getOutputFormat() {
16-
return outputFormat;
17-
}
18-
public void setOutputFormat(String outputFormat) {
19-
this.outputFormat = outputFormat;
20-
}
21-
public String getDocContent() {
22-
return docContent;
23-
}
24-
public void setDocContent(String docContent) {
25-
this.docContent = docContent;
26-
}
27-
28-
297

308
}
Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package org.fugerit.java.doc.playground.convert;
22

3-
public class ConvertOutput {
3+
import org.fugerit.java.doc.playground.facade.BasicOutput;
4+
5+
public class ConvertOutput extends BasicOutput {
46

57
private String docOutput;
68

7-
private String message;
8-
99
public String getDocOutput() {
1010
return docOutput;
1111
}
@@ -14,12 +14,4 @@ public void setDocOutput(String docOutput) {
1414
this.docOutput = docOutput;
1515
}
1616

17-
public String getMessage() {
18-
return message;
19-
}
20-
21-
public void setMessage(String message) {
22-
this.message = message;
23-
}
24-
2517
}

fj-doc-playground-quarkus/src/main/java/org/fugerit/java/doc/playground/convert/ConvertRest.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import org.fugerit.java.doc.json.parse.DocJsonToXml;
77
import org.fugerit.java.doc.json.parse.DocXmlToJson;
8+
import org.fugerit.java.doc.playground.facade.InputFacade;
89
import org.slf4j.Logger;
910
import org.slf4j.LoggerFactory;
1011

@@ -26,10 +27,6 @@ public class ConvertRest {
2627

2728
private final static Logger logger = LoggerFactory.getLogger(ConvertRest.class);
2829

29-
private final static String FORMAT_XML = "XML";
30-
private final static String FORMAT_JSON = "JSON";
31-
private final static String FORMAT_YAML = "YAML";
32-
3330
@POST
3431
@Consumes(MediaType.APPLICATION_JSON)
3532
@Produces(MediaType.APPLICATION_JSON)
@@ -45,14 +42,14 @@ public Response convertDoc( ConvertInput input ) {
4542
logger.info( "format input : {} -> output : {}", inputFormat, outputFormat );
4643
ObjectMapper mapper = new ObjectMapper();
4744
ObjectMapper yamlMapper = new ObjectMapper( new YAMLFactory() );
48-
if ( FORMAT_XML.equalsIgnoreCase( inputFormat ) ) {
49-
if ( FORMAT_JSON.equalsIgnoreCase( outputFormat ) ) {
45+
if ( InputFacade.FORMAT_XML.equalsIgnoreCase( inputFormat ) ) {
46+
if ( InputFacade.FORMAT_JSON.equalsIgnoreCase( outputFormat ) ) {
5047
DocXmlToJson helper = new DocXmlToJson();
5148
try ( StringReader reader = new StringReader( docContent ) ) {
5249
JsonNode node = helper.convertToJsonNode( reader );
5350
docOutput = node.toPrettyString();
5451
}
55-
} else if ( FORMAT_YAML.equalsIgnoreCase( outputFormat ) ) {
52+
} else if ( InputFacade.FORMAT_YAML.equalsIgnoreCase( outputFormat ) ) {
5653
DocXmlToJson helper = new DocXmlToJson( yamlMapper );
5754
try ( StringReader reader = new StringReader( docContent ) ) {
5855
JsonNode node = helper.convertToJsonNode( reader );
@@ -61,31 +58,31 @@ public Response convertDoc( ConvertInput input ) {
6158
} else {
6259
output.setMessage( "Invalid output format : "+outputFormat );
6360
}
64-
} else if ( FORMAT_JSON.equalsIgnoreCase( inputFormat ) ) {
65-
if ( FORMAT_XML.equalsIgnoreCase( outputFormat ) ) {
61+
} else if ( InputFacade.FORMAT_JSON.equalsIgnoreCase( inputFormat ) ) {
62+
if ( InputFacade.FORMAT_XML.equalsIgnoreCase( outputFormat ) ) {
6663
DocJsonToXml helper = new DocJsonToXml();
6764
try ( StringReader reader = new StringReader( docContent );
6865
StringWriter writer = new StringWriter() ) {
6966
helper.writerAsXml(reader, writer);
7067
docOutput = writer.toString();
7168
}
72-
} else if ( FORMAT_YAML.equalsIgnoreCase( outputFormat ) ) {
69+
} else if ( InputFacade.FORMAT_YAML.equalsIgnoreCase( outputFormat ) ) {
7370
try ( StringReader reader = new StringReader( docContent ) ) {
7471
JsonNode node = mapper.readTree( reader );
7572
docOutput = yamlMapper.writeValueAsString( node );
7673
}
7774
} else {
7875
output.setMessage( "Invalid output format : "+outputFormat );
7976
}
80-
} else if ( FORMAT_YAML.equalsIgnoreCase( inputFormat ) ) {
81-
if ( FORMAT_XML.equalsIgnoreCase( outputFormat ) ) {
77+
} else if ( InputFacade.FORMAT_YAML.equalsIgnoreCase( inputFormat ) ) {
78+
if ( InputFacade.FORMAT_XML.equalsIgnoreCase( outputFormat ) ) {
8279
DocJsonToXml helper = new DocJsonToXml( yamlMapper );
8380
try ( StringReader reader = new StringReader( docContent );
8481
StringWriter writer = new StringWriter() ) {
8582
helper.writerAsXml(reader, writer);
8683
docOutput = writer.toString();
8784
}
88-
} else if ( FORMAT_JSON.equalsIgnoreCase( outputFormat ) ) {
85+
} else if ( InputFacade.FORMAT_JSON.equalsIgnoreCase( outputFormat ) ) {
8986
try ( StringReader reader = new StringReader( docContent ) ) {
9087
JsonNode node = yamlMapper.readTree( reader );
9188
docOutput = mapper.writerWithDefaultPrettyPrinter().writeValueAsString( node );
Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,7 @@
11
package org.fugerit.java.doc.playground.doc;
22

3-
public class GenerateInput {
3+
import org.fugerit.java.doc.playground.facade.BasicInput;
44

5-
private String outputFormat;
6-
7-
private String docContent;
8-
9-
public String getOutputFormat() {
10-
return outputFormat;
11-
}
12-
13-
public void setOutputFormat(String outputFormat) {
14-
this.outputFormat = outputFormat;
15-
}
16-
17-
public String getDocContent() {
18-
return docContent;
19-
}
20-
21-
public void setDocContent(String docContent) {
22-
this.docContent = docContent;
23-
}
5+
public class GenerateInput extends BasicInput {
246

257
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.fugerit.java.doc.playground.doc;
2+
3+
import org.fugerit.java.doc.playground.facade.BasicOutput;
4+
5+
public class GenerateOutput extends BasicOutput {
6+
7+
private String docOutputBase64;
8+
9+
public String getDocOutputBase64() {
10+
return docOutputBase64;
11+
}
12+
13+
public void setDocOutputBase64(String docOutputBase64) {
14+
this.docOutputBase64 = docOutputBase64;
15+
}
16+
17+
}

fj-doc-playground-quarkus/src/main/java/org/fugerit/java/doc/playground/doc/GenerateRest.java

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

33
import java.io.ByteArrayOutputStream;
44
import java.io.StringReader;
5+
import java.util.Base64;
56

6-
import org.fugerit.java.doc.base.config.DocConfig;
77
import org.fugerit.java.doc.base.config.DocInput;
88
import org.fugerit.java.doc.base.config.DocOutput;
99
import org.fugerit.java.doc.base.config.DocTypeHandler;
10+
import org.fugerit.java.doc.base.facade.DocFacadeSource;
11+
import org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlFragmentTypeHandler;
1012
import org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandler;
1113
import org.fugerit.java.doc.mod.fop.PdfFopTypeHandler;
1214
import org.fugerit.java.doc.mod.poi.XlsxPoiTypeHandler;
15+
import org.fugerit.java.doc.playground.facade.InputFacade;
1316
import org.slf4j.Logger;
1417
import org.slf4j.LoggerFactory;
1518

@@ -27,12 +30,20 @@ public class GenerateRest {
2730

2831
private final static Logger logger = LoggerFactory.getLogger(GenerateRest.class);
2932

30-
private byte[] generateHelper( GenerateInput input, DocTypeHandler handler ) throws Exception {
33+
private byte[] generateHelper( GenerateInput input, DocTypeHandler handler) throws Exception {
3134
byte[] result = null;
3235
if ( input.getDocContent() != null ) {
3336
try ( StringReader reader = new StringReader( input.getDocContent() );
3437
ByteArrayOutputStream baos = new ByteArrayOutputStream() ) {
35-
DocInput docInput = DocInput.newInput( DocConfig.TYPE_PDF , reader );
38+
int sourceType = DocFacadeSource.SOURCE_TYPE_XML;
39+
if ( InputFacade.FORMAT_JSON.equalsIgnoreCase( input.getInputFormat() ) ) {
40+
sourceType = DocFacadeSource.SOURCE_TYPE_JSON;
41+
} else if ( InputFacade.FORMAT_YAML.equalsIgnoreCase( input.getInputFormat() ) ) {
42+
sourceType = DocFacadeSource.SOURCE_TYPE_YAML;
43+
}
44+
String type = input.getOutputFormat().toLowerCase();
45+
logger.info( "output format : {}", type );
46+
DocInput docInput = DocInput.newInput( type, reader , sourceType );
3647
DocOutput docOutput = DocOutput.newOutput( baos );
3748
handler.handle(docInput, docOutput);
3849
result = baos.toByteArray();
@@ -89,5 +100,29 @@ public Response xlsx( GenerateInput input) {
89100
}
90101
return res;
91102
}
103+
104+
@POST
105+
@Consumes(MediaType.APPLICATION_JSON)
106+
@Produces(MediaType.APPLICATION_JSON)
107+
@Path("/document")
108+
public Response output( GenerateInput input) {
109+
Response res = Response.status(Response.Status.BAD_REQUEST).build();
110+
try {
111+
DocTypeHandler handler = new PdfFopTypeHandler();;
112+
if ( "XLSX".equalsIgnoreCase( input.getOutputFormat() ) ) {
113+
handler = XlsxPoiTypeHandler.HANDLER;
114+
} else if ( "HTML".equalsIgnoreCase( input.getOutputFormat() ) ) {
115+
handler = FreeMarkerHtmlFragmentTypeHandler.HANDLER;
116+
}
117+
byte[] data = this.generateHelper(input, handler);
118+
GenerateOutput output = new GenerateOutput();
119+
output.setDocOutputBase64( Base64.getEncoder().encodeToString( data ) );
120+
res = Response.ok().entity( output ).build();
121+
} catch (Exception e) {
122+
logger.info("Error : " + e, e);
123+
res = Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
124+
}
125+
return res;
126+
}
92127

93128
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.fugerit.java.doc.playground.facade;
2+
3+
public class BasicInput {
4+
5+
private String inputFormat;
6+
7+
private String outputFormat;
8+
9+
private String docContent;
10+
11+
public String getInputFormat() {
12+
return inputFormat;
13+
}
14+
15+
public void setInputFormat(String inputFormat) {
16+
this.inputFormat = inputFormat;
17+
}
18+
19+
public String getOutputFormat() {
20+
return outputFormat;
21+
}
22+
23+
public void setOutputFormat(String outputFormat) {
24+
this.outputFormat = outputFormat;
25+
}
26+
27+
public String getDocContent() {
28+
return docContent;
29+
}
30+
31+
public void setDocContent(String docContent) {
32+
this.docContent = docContent;
33+
}
34+
35+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.fugerit.java.doc.playground.facade;
2+
3+
public class BasicOutput {
4+
5+
private String message;
6+
7+
public String getMessage() {
8+
return message;
9+
}
10+
11+
public void setMessage(String message) {
12+
this.message = message;
13+
}
14+
15+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.fugerit.java.doc.playground.facade;
2+
3+
public class InputFacade {
4+
5+
public final static String FORMAT_XML = "XML";
6+
public final static String FORMAT_JSON = "JSON";
7+
public final static String FORMAT_YAML = "YAML";
8+
9+
}
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
package org.fugerit.java.doc.playground.val;
22

3-
public class ValOutput {
3+
import org.fugerit.java.doc.playground.facade.BasicOutput;
4+
5+
public class ValOutput extends BasicOutput {
46

57
private boolean valid;
68

7-
private String message;
8-
99
public ValOutput(boolean valid, String message) {
1010
super();
1111
this.valid = valid;
12-
this.message = message;
12+
this.setMessage(message);
1313
}
1414

1515
public boolean isValid() {
1616
return valid;
1717
}
18-
19-
public String getMessage() {
20-
return message;
21-
}
2218

2319
}

0 commit comments

Comments
 (0)