Commit b071cfc8 authored by R.W.Majeed's avatar R.W.Majeed

report API updated

parent e1cee569
package org.aktin.report;
import java.time.Instant;
import org.aktin.report.GeneratedReport;
/**
......@@ -8,10 +10,17 @@ import org.aktin.report.GeneratedReport;
*
*/
public interface ArchivedReport extends GeneratedReport {
public enum Status{
Waiting, Completed, Failed
}
/**
* Get the id of the generated report within the archive.
* @return unique id
*/
int getId();
String getUserId();
Instant getCreatedTimestamp();
Status getStatus();
}
package org.aktin.report;
import java.time.Instant;
import java.util.HashMap;
import java.util.Map;
class BasicReportInfo implements ReportInfo{
private Report report;
private Instant start;
private Instant end;
private Map<String, String> prefs;
public BasicReportInfo(Report report, Instant startTime, Instant endTime){
this.report = report;
this.start = startTime;
this.end = endTime;
this.prefs = new HashMap<>();
}
@Override
public Instant getStartTimestamp() { return start; }
@Override
public Instant getEndTimestamp() { return end; }
@Override
public String getTemplateId() { return report.getId(); }
@Override
public String getTemplateVersion() { return report.getVersion(); }
@Override
public Map<String, String> getPreferences() {
return prefs;
}
}
......@@ -2,9 +2,8 @@ package org.aktin.report;
import java.nio.file.Path;
import java.time.Instant;
import java.util.Map;
public interface GeneratedReport {
public interface GeneratedReport extends ReportInfo{
/**
* Media Type (MIME) for the report data.
* @return media type
......@@ -15,37 +14,9 @@ public interface GeneratedReport {
* @return path location of the report data.
*/
Path getLocation();
/**
* Start timestamp of the report interval
* @return timestamp
*/
Instant getStartTimestamp();
/**
* End timestamp of the report interval
* @return timestamp
*/
Instant getEndTimestamp();
/**
* Timestamp when the report was generated
* @return timestamp
*/
Instant getDataTimestamp();
/**
* Get the report template id. For the version, see {@link #getTemplateVersion()}.
* @return template id
*/
String getTemplateId();
/**
* Get the version string for the report template indicated by {@link #getTemplateId()}
* @return version string
*/
String getTemplateVersion();
/**
* Preferences used for the generation of the report. The preferences consist of
* key value pairs and include system preferences requested by the report template
* as well as configuration options which can be specified by the user (e.g. display
* configurations).
* @return preference map
*/
Map<String,String> getPreferences();
}
......@@ -3,6 +3,7 @@ package org.aktin.report;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.time.Instant;
import java.time.Period;
import java.util.Arrays;
......@@ -108,6 +109,10 @@ public interface Report {
default String[] getRequiredPreferenceKeys(){
return new String[]{};
}
default ReportInfo createReportInfo(Instant start, Instant end){
return new BasicReportInfo(this, start, end);
}
/**
* Copies all scripts and resource needed for the Rscript invocation
* to the specified working directory. The file names of all copied
......
......@@ -11,14 +11,17 @@ import org.aktin.report.GeneratedReport;
*
*/
public interface ReportArchive{
void setReportFailure(int id, Throwable cause) throws IOException;
ArchivedReport setReportResult(int id, GeneratedReport report) throws IOException;
/**
* Add a generated report to the archive. Returns unique id string.
* @param generated report
* Add a report to the archive. Returns unique id. The report may not have been generated yet.
* @param report report info to create
* @param userId user id
* @return report id within the archive
* @throws IOException if the report could not be added
*/
ArchivedReport addReport(GeneratedReport report) throws IOException;
ArchivedReport addReport(ReportInfo report, String userId) throws IOException;
/**
* Retrieve a report by it's id
......
package org.aktin.report;
import java.time.Instant;
import java.util.Map;
public interface ReportInfo {
/**
* Start timestamp of the report interval
* @return timestamp
*/
Instant getStartTimestamp();
/**
* End timestamp of the report interval
* @return timestamp
*/
Instant getEndTimestamp();
/**
* Get the report template id. For the version, see {@link #getTemplateVersion()}.
* @return template id
*/
String getTemplateId();
/**
* Get the version string for the report template indicated by {@link #getTemplateId()}
* @return version string
*/
String getTemplateVersion();
/**
* Preferences used for the generation of the report. The preferences consist of
* key value pairs and include system preferences requested by the report template
* as well as configuration options which can be specified by the user (e.g. display
* configurations).
* @return preference map
*/
Map<String,String> getPreferences();
}
......@@ -11,7 +11,29 @@ public interface ReportManager {
Report getReport(String id);
/**
* Generate a report asynchronously.
*
* @param report report template
* @param fromTimestamp start timestamp
* @param endTimestamp end timestamp
* @param reportDestination destination for the generated report. Usually a file name.
* @return completable future receiving the report
* @throws IOException IO error
*/
@Deprecated
CompletableFuture<? extends GeneratedReport> generateReport(Report report, Instant fromTimestamp, Instant endTimestamp,
Path reportDestination) throws IOException;
/**
* Generate a report asynchronously.
*
* @param report report information
* @param reportDestination destination. Can be {@code null} to let the report manager create a temporary file/folder
* @return completable future
* @throws IOException IO Error
* @throws IllegalArgumentException if the reportInfo can not be used for report generation. e.g. a non-existing template id
*/
CompletableFuture<? extends GeneratedReport> generateReport(ReportInfo reportInfo, Path reportDestination) throws IOException, IllegalArgumentException;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment