Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP:Added a module reporting from devonfw #194

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<module>batch</module>
<module>web</module>
<module>basic</module>
<module>reporting</module>
</modules>

<dependencyManagement>
Expand Down
44 changes: 44 additions & 0 deletions modules/reporting/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.devonfw.java.dev</groupId>
<artifactId>devon4j-modules</artifactId>
<version>dev-SNAPSHOT</version>
</parent>
<groupId>com.devonfw.java.modules</groupId>
<artifactId>devon4j-reporting</artifactId>
<version>${devon4j.version}</version>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<description>Module for reporting.</description>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.devonfw.java.modules</groupId>
<artifactId>devon4j-test</artifactId>
<scope>test</scope>
</dependency>
<!-- JASPER REPORTS LIBRARY -->
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>net.sf.m-m-m</groupId>
<artifactId>mmm-util-exception</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.devonfw.module.reporting.common;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* This is the entry point for unit tests.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is for Unit tests, why is it in src/main then rather than src/test?

*
*/
@SpringBootApplication
public class ReportingModuleApp {
/**
* Entry point for spring-boot based app
*
* @param args - arguments
*/
public static void main(String[] args) {

SpringApplication.run(ReportingModuleApp.class, args);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.devonfw.module.reporting.common.api;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Class to encapsulate a report
*
* @param <T> type of the data that is provided to be included in the report
*/
public class Report<T> {
private String name;

private String dataSourceName;

private List<T> data;

private String templatePath;

private HashMap<String, Object> params;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HashMap is a specific implementation. Use Map instead as "API".


/**
* @return name
*/
public String getName() {

return this.name;
}

/**
* @param name new value of {@link #getName}.
*/
public void setName(String name) {

this.name = name;
}

/**
* @return dataSourceName
*/
public String getDataSourceName() {

return this.dataSourceName;
}

/**
* @param dataSourceName new value of {@link #getDataSourceName}.
*/
public void setDataSourceName(String dataSourceName) {

this.dataSourceName = dataSourceName;
}

/**
* @return data
*/
public List<T> getData() {

return this.data;
}

/**
* @param data new value of {@link #getData}.
*/
public void setData(List<T> data) {

this.data = data;
}

/**
* @return templatePath
*/
public String getTemplatePath() {

return this.templatePath;
}

/**
* @param templatePath new value of {@link #getTemplatePath}.
*/
public void setTemplatePath(String templatePath) {

this.templatePath = templatePath;
}

/**
* @return params
*/
public Map<String, Object> getParams() {

return this.params;
}

/**
* @param params new value of {@link #getParams}.
*/
public void setParams(HashMap<String, Object> params) {

this.params = params;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.devonfw.module.reporting.common.api;

import java.io.File;
import java.io.OutputStream;
import java.util.List;

/**
* This is the interface for a simple facade to generate a report based on Jasper Reports library.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO this is an API that abstracts from the underlying implementation. Hence Jasper Reports library is "just" the current or default implementation.

*
* @param <T> type of the data that is provided to be included in the report.
*/
public interface Reporting<T> {

/**
* Generates a report file with the given data, the template located in the templatePath and the type of file.
* specified.
*
* @param report the {@link Report} that encapsulates the data to be included in the report, the location of the
* report template and the values of the parameters defined in the report template (in case template uses
* parameters).
* @param file the file where the report must be created.
* @param format - report format
*/
public void generateReport(Report report, File file, String format);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • omit public keyword inside interface
  • use default method delegating to generateReport with OutputStream?
  • is File still the state of the art type of choice or should we support java.nio.Path?


/**
* Generates a report stream with the given data, the template located in the templatePath and the type of file.
*
* @param report the {@link Report} that encapsulates the data to be included in the report, the location of the
* report template and the values of the parameters defined in the report template (in case template uses
* parameters).
* @param stream the stream where the report will be written.
* @param format - report format
*/
public void generateReport(Report report, OutputStream stream, String format);

/**
* Generates a file with a main report that stores other sub-reports.
*
* @param masterReport the main {@link Report}.
* @param reports a list of {@link Report} reports to be included within the main report.
* @param file the file where the report must be created.
* @param format - report format
*/
public void generateSubreport(Report masterReport, List<Report> reports, File file, String format);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who. This is quite a sophisticated API. From the JavaDoc I do not really get what it will do.
I will see if I understand it when reading the implementation but JavaDoc should be more expressive.


/**
* Generates a stream with a main report that stores other sub-reports.
*
* @param masterReport the main {@link Report}.
* @param reports a list of {@link Report} reports to be included within the main report.
* @param stream the stream to manage the resultant report.
* @param format - report format
*/
public void generateSubreport(Report masterReport, List<Report> reports, OutputStream stream, String format);

/**
* Generates a report file that contains a concatenation of reports.
*
* @param reports the list of reports to be included in the report file.
* @param file the file where the report must be created.
* @param format - report format
*/
public void concatenateReports(List<Report> reports, File file, String format);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does concat mean in this context? If I concat two PDF files, I will get garbage.
So is the content of the reports concatenated to a single file. Is this a regular use-case. Might be cool in some cases. So I get a table of contents for the entire document similar to what we do with asciidoc and includes... Maybe the JavaDoc can again clarify the questions that obviously came to my mind here...


/**
* Generates a stream that contains a concatenation of reports.
*
* @param reports the list of reports to be included in the report stream.
* @param stream the stream to manage the resultant report.
* @param format - report format
*/
public void concatenateReports(List<Report> reports, OutputStream stream, String format);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.devonfw.module.reporting.common.api.exception;

import net.sf.mmm.util.exception.api.NlsRuntimeException;
import net.sf.mmm.util.nls.api.NlsMessage;

/**
* This is the checked exception for Reporting module.
*
*/
public class ReportingException extends NlsRuntimeException {

private static final long serialVersionUID = 1L;

/**
* The constructor.
*
* @param message the error {@link #getNlsMessage() message}.
*/
public ReportingException(NlsMessage message) {

super(message);
}

/**
* Constructs an {@code ReportingException} with the root cause.
*
* @param cause the error {@link #getCause() cause}.
* @param message the error {@link #getNlsMessage() message}.
*/
public ReportingException(Throwable cause, NlsMessage message) {

super(cause, message);
}

/**
* The constructor.
*
* @param cause the error {@link #getCause() cause}.
* @param message the error message.
*/
public ReportingException(Throwable cause, String message) {

super(cause, message);
}

}
Loading