[PATCH] Added more metadata to chart exports

Wald Commits scm-commit at wald.intevation.org
Mon Oct 1 17:45:36 CEST 2018


# HG changeset patch
# User gernotbelger
# Date 1538408743 -7200
# Node ID 9dc6427059b2d94479f6249d2a7a438e7602d6a0
# Parent  d421c2bf0195d8d963b3e406b15d445c7dee077f
Added more metadata to chart exports

diff -r d421c2bf0195 -r 9dc6427059b2 artifacts/src/main/java/org/dive4elements/river/exports/AbstractChartGenerator.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/AbstractChartGenerator.java	Mon Oct 01 17:08:50 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/AbstractChartGenerator.java	Mon Oct 01 17:45:43 2018 +0200
@@ -34,6 +34,7 @@
 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
 import org.dive4elements.artifactdatabase.state.Settings;
 import org.dive4elements.artifacts.Artifact;
+import org.dive4elements.artifacts.ArtifactCollection;
 import org.dive4elements.artifacts.ArtifactNamespaceContext;
 import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.artifacts.CallMeta;
@@ -488,16 +489,21 @@
             return;
 
         final Collection<String> metadata = buildMetadata();
-        final String text = StringUtils.join(metadata, " - ");
 
-        /** The default font. */
-        final Font titleFont = new Font("SansSerif", Font.ITALIC, 10);
+        for (final String text : metadata) {
 
-        final TextTitle subtitle = new TextTitle(text, titleFont);
-        subtitle.setHorizontalAlignment(HorizontalAlignment.LEFT);
-        subtitle.setMargin(new RectangleInsets(10, 10, 10, 10));
+            /** The default font. */
+            final Font titleFont = new Font("SansSerif", Font.ITALIC, 10);
 
-        chart.addSubtitle(subtitle);
+            final TextTitle subtitle = new TextTitle(text, titleFont);
+            subtitle.setHorizontalAlignment(HorizontalAlignment.LEFT);
+            subtitle.setTextAlignment(HorizontalAlignment.LEFT);
+            subtitle.setMargin(new RectangleInsets(5, 10, 0, 10));
+            subtitle.setPadding(RectangleInsets.ZERO_INSETS);
+            subtitle.getFrame();
+
+            chart.addSubtitle(subtitle);
+        }
     }
 
     private Collection<String> buildMetadata() {
@@ -509,23 +515,57 @@
             return Collections.emptyList();
         }
 
+        final CollectionCallContext ccc = (CollectionCallContext) this.context;
+        final ArtifactCollection collection = ccc.getCollection();
+
         final List<String> subtitles = new ArrayList<>();
 
+        final List<String> firstLine = new ArrayList<>();
+        final List<String> secondLine = new ArrayList<>();
+
         /* version */
         final String version = FLYS.VERSION;
-        subtitles.add(Resources.getMsg(meta, "chart.subtitle.metadata.version", "default", version));
+        firstLine.add(Resources.getMsg(meta, "chart.subtitle.metadata.version", "default", version));
 
         /* user */
         // REMARK: the use inside the collection is a fake user and hence we cant use it here.
         // final User user = collection.getUser();
         final String userName = CalculationUtils.findArtifactUser(this.context, getArtifact());
-        subtitles.add(Resources.getMsg(meta, "chart.subtitle.metadata.user", "default", userName));
+        firstLine.add(Resources.getMsg(meta, "chart.subtitle.metadata.user", "default", userName));
 
         /* creation date */
         final Locale locale = Resources.getLocale(meta);
         final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
         final String dateText = df.format(new Date());
-        subtitles.add(Resources.getMsg(meta, "chart.subtitle.metadata.creationdate", "default", dateText));
+        firstLine.add(Resources.getMsg(meta, "chart.subtitle.metadata.creationdate", "default", dateText));
+
+        /* project name */
+        final String collectionName = collection.getName();
+        final String collectionID = collection.identifier();
+        final String projectName = collectionName == null || collectionName.isEmpty() ? collectionID : collectionName;
+        secondLine.add(Resources.getMsg(meta, "chart.subtitle.metadata.projectname", "default", projectName));
+
+        /* module name */
+        final String moduleName = Resources.getMsg(meta, "module." + this.master.getName());
+        secondLine.add(Resources.getMsg(meta, "chart.subtitle.metadata.modulename", "default", moduleName));
+
+        /* calculation mode */
+        if (this.master instanceof D4EArtifact) {
+
+            final D4EArtifact artifact = (D4EArtifact) this.master;
+            // REMARK: relies on the fact that all modules use the same data-key 'calculation_mode'
+            final String calculationMode = artifact.getDataAsString("calculation_mode");
+            if (calculationMode != null) {
+                /* but not all modules have that (i.e. Chart, Map, ...) */
+
+                final String calculationName = Resources.getMsg(meta, calculationMode, "XXX");
+                if (!"XXX".contentEquals(calculationName))
+                    secondLine.add(Resources.getMsg(meta, "chart.subtitle.metadata.calcmode", "calcmode", calculationName));
+            }
+        }
+
+        subtitles.add(StringUtils.join(firstLine, " - "));
+        subtitles.add(StringUtils.join(secondLine, " - "));
 
         return subtitles;
     }
diff -r d421c2bf0195 -r 9dc6427059b2 artifacts/src/main/resources/messages.properties
--- a/artifacts/src/main/resources/messages.properties	Mon Oct 01 17:08:50 2018 +0200
+++ b/artifacts/src/main/resources/messages.properties	Mon Oct 01 17:45:43 2018 +0200
@@ -1349,6 +1349,9 @@
 chart.subtitle.metadata.version = FLYS Version: {0}
 chart.subtitle.metadata.user = User: {0}
 chart.subtitle.metadata.creationdate = Time of Creation: {0}
+chart.subtitle.metadata.projectname = Project: {0}
+chart.subtitle.metadata.modulename = Module: {0}
+chart.subtitle.metadata.calcmode = Calculation: {0}
 
 state.title.distance_state = Choose Calculation Range [km]
 state.title.location_distance_state = Choose Calculation Location(s)/Range [km] 
diff -r d421c2bf0195 -r 9dc6427059b2 artifacts/src/main/resources/messages_de.properties
--- a/artifacts/src/main/resources/messages_de.properties	Mon Oct 01 17:08:50 2018 +0200
+++ b/artifacts/src/main/resources/messages_de.properties	Mon Oct 01 17:45:43 2018 +0200
@@ -1349,6 +1349,9 @@
 chart.subtitle.metadata.version = FLYS-Version: {0}
 chart.subtitle.metadata.user = Bearbeiter: {0}
 chart.subtitle.metadata.creationdate = Datum der Erstellung: {0}
+chart.subtitle.metadata.projectname = Projekt: {0}
+chart.subtitle.metadata.modulename = Modul: {0}
+chart.subtitle.metadata.calcmode = Berechnungsart: {0}
 
 state.title.distance_state = Berechnungsstrecke w\u00e4hlen [km]
 state.title.location_distance_state = Berechnungsort(e)/-strecke w\u00e4hlen [km] 


More information about the Dive4Elements-commits mailing list