First proposition for introduction to spring-yarg (#2540)
This commit is contained in:
parent
aaa3d117e2
commit
86c1d6d22d
|
@ -514,6 +514,11 @@
|
|||
<artifactId>hirondelle-date4j</artifactId>
|
||||
<version>${hirondelle-date4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.haulmont.yarg</groupId>
|
||||
<artifactId>yarg</artifactId>
|
||||
<version>2.0.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
|
@ -534,6 +539,14 @@
|
|||
<name>OpenGeo Maven Repository</name>
|
||||
<url>http://repo.opengeo.org</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<id>bintray-cuba-platform-main</id>
|
||||
<name>bintray</name>
|
||||
<url>http://dl.bintray.com/cuba-platform/main</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<multiverse.version>0.7.0</multiverse.version>
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.baeldung.yarg;
|
||||
|
||||
import com.haulmont.yarg.formatters.factory.DefaultFormatterFactory;
|
||||
import com.haulmont.yarg.loaders.factory.DefaultLoaderFactory;
|
||||
import com.haulmont.yarg.loaders.impl.JsonDataLoader;
|
||||
import com.haulmont.yarg.reporting.Reporting;
|
||||
import com.haulmont.yarg.reporting.RunParams;
|
||||
import com.haulmont.yarg.structure.Report;
|
||||
import com.haulmont.yarg.structure.ReportBand;
|
||||
import com.haulmont.yarg.structure.ReportOutputType;
|
||||
import com.haulmont.yarg.structure.impl.BandBuilder;
|
||||
import com.haulmont.yarg.structure.impl.ReportBuilder;
|
||||
import com.haulmont.yarg.structure.impl.ReportTemplateBuilder;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class DocumentController {
|
||||
|
||||
@RequestMapping(path = "/generate/doc", method = RequestMethod.GET)
|
||||
public void generateDocument(HttpServletResponse response) throws IOException {
|
||||
ReportBuilder reportBuilder = new ReportBuilder();
|
||||
ReportTemplateBuilder reportTemplateBuilder = new ReportTemplateBuilder()
|
||||
.documentPath("./src/main/resources/Letter.docx")
|
||||
.documentName("Letter.docx")
|
||||
.outputType(ReportOutputType.docx)
|
||||
.readFileFromPath();
|
||||
reportBuilder.template(reportTemplateBuilder.build());
|
||||
BandBuilder bandBuilder = new BandBuilder();
|
||||
String json = FileUtils.readFileToString(new File("./src/main/resources/Data.json"));
|
||||
ReportBand main = bandBuilder.name("Main")
|
||||
.query("Main", "parameter=param1 $.main", "json")
|
||||
.build();
|
||||
reportBuilder.band(main);
|
||||
Report report = reportBuilder.build();
|
||||
|
||||
Reporting reporting = new Reporting();
|
||||
reporting.setFormatterFactory(new DefaultFormatterFactory());
|
||||
reporting.setLoaderFactory(
|
||||
new DefaultLoaderFactory()
|
||||
.setJsonDataLoader(new JsonDataLoader()));
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
|
||||
reporting.runReport(new RunParams(report).param("param1", json), response.getOutputStream());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"main": {
|
||||
"title" : "INTRODUCTION TO YARG",
|
||||
"name" : "Baeldung",
|
||||
"content" : "This is the content of the letter, can be anything we like."
|
||||
}
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue