Skip to content

Commit 7b56bb2

Browse files
authored
IGN-12973: Fix broken report-datasource example. (#136)
1 parent bee703f commit 7b56bb2

File tree

14 files changed

+178
-138
lines changed

14 files changed

+178
-138
lines changed

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ Creates an example device in the Gateway. The device will create tags that are v
4040
Adds a Smiley shaped component to the Report Designer.
4141

4242
##### [Report Datasource](report-datasource)
43-
> [!WARNING]
44-
> This example is pending an update to the SDK. Will be **FAULTED** when installed on the Gateway
45-
4643
Adds a datasource to the report designer that can retrieve JSON data via a REST call to a website.
4744

4845
##### [Scripting Function (RPC)](scripting-function)

build-all.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
set -e # Exit on any error
77

88
# Projects to ignore (temporarily broken or excluded from builds)
9-
IGNORE_LIST=("report-datasource")
9+
IGNORE_LIST=()
1010

1111
# Color output for better readability
1212
RED='\033[0;31m'

report-datasource/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# Report Datasource Example
2-
> [!WARNING]
3-
> This example will be **FAULTED** when installed. It will be updated when API changes are merged into Ignition
4-
5-
This example demonstrates how to add a `DataSource` to the Ignition Reporting module. In this example we utilitize some
6-
open source libraries to very quickly add datasources in the form of JSON responses from REST endpoints on the web.
2+
This example demonstrates how to add a `DataSource` to the Ignition Reporting module. We will create a new DataSource
3+
that can be used in the Reporting module to retrieve data from REST endpoints.
74

85
### Information
96
The Reporting API provides a simple process to add DataSources. It requires a few things:
107

118
1. Create the DataSource by implementing `ReportDataSource` in the Gateway Scope.
12-
2. Create a Java-serializable data object that can be passed between the Gateway and Designer
9+
2. Create a `DataSourceConfigObject` that can be passed between the Gateway and Designer. The object is serialized
10+
for RPC by overriding the `toJson()` method. It should be coupled with a static `fromJson()` methods to handle the
11+
deserialization of the object.
1312
3. Register the DataSource in the GatewayHook by calling `GatewayDataSourceRegistry.get().register()` in the hook's `startup()` method.
1413
4. Create a DataSource UI for configuration by extending `DataSourceConfigPanel`, and implementing `AbstractDataSourceConfigFactory` within it.
14+
This config panel is used to view and edit the `DataSourceConfigObject` created in step 2.
1515
5. Register the factory with the DesignerHook.
1616

1717
The `DataSource` itself simply provides a way to add to the existing `Map<String, Object>`. While there may be some

report-datasource/pom.xml

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</modules>
1818

1919
<properties>
20-
<ignition-platform-version>8.3.0</ignition-platform-version>
20+
<ignition-platform-version>8.3.2-SNAPSHOT</ignition-platform-version>
2121
<ignition-sdk-version>${ignition-platform-version}</ignition-sdk-version>
2222
<module-name>Report Datasource Example</module-name>
2323
<module-description>Adds a REST/Json datasource to Ignition's reporting module as a datasource
@@ -26,40 +26,10 @@
2626
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2727
</properties>
2828

29-
<build>
30-
<pluginManagement>
31-
<plugins>
32-
<plugin>
33-
<groupId>org.apache.maven.plugins</groupId>
34-
<artifactId>maven-compiler-plugin</artifactId>
35-
<version>3.3</version>
36-
<configuration>
37-
<source>17</source>
38-
<target>17</target>
39-
</configuration>
40-
</plugin>
41-
</plugins>
42-
</pluginManagement>
43-
</build>
44-
45-
<pluginRepositories>
46-
<pluginRepository>
47-
<id>releases</id>
48-
<url>https://nexus.inductiveautomation.com/repository/inductiveautomation-release</url>
49-
<releases>
50-
<enabled>true</enabled>
51-
<updatePolicy>always</updatePolicy>
52-
</releases>
53-
<snapshots>
54-
<enabled>false</enabled>
55-
</snapshots>
56-
</pluginRepository>
57-
</pluginRepositories>
58-
5929
<repositories>
6030
<repository>
6131
<id>ia-releases</id>
62-
<url>https://nexus.inductiveautomation.com/repository/inductiveautomation-releases</url>
32+
<url>https://nexus.inductiveautomation.com/repository/inductiveautomation-beta</url>
6333
<snapshots>
6434
<enabled>false</enabled>
6535
</snapshots>
@@ -68,7 +38,6 @@
6838
<updatePolicy>always</updatePolicy>
6939
</releases>
7040
</repository>
71-
7241
<repository>
7342
<id>ia-snapshots</id>
7443
<url>https://nexus.inductiveautomation.com/repository/inductiveautomation-snapshots</url>
@@ -80,7 +49,6 @@
8049
<enabled>false</enabled>
8150
</releases>
8251
</repository>
83-
8452
<repository>
8553
<id>ia-thirdparty</id>
8654
<url>https://nexus.inductiveautomation.com/repository/inductiveautomation-thirdparty</url>
@@ -92,11 +60,23 @@
9260
<enabled>false</enabled>
9361
</snapshots>
9462
</repository>
95-
9663
<repository>
9764
<id>ia-beta</id>
9865
<url>https://nexus.inductiveautomation.com/repository/inductiveautomation-beta</url>
9966
</repository>
10067
</repositories>
10168

102-
</project>
69+
<pluginRepositories>
70+
<pluginRepository>
71+
<id>releases</id>
72+
<url>https://nexus.inductiveautomation.com/repository/inductiveautomation-releases</url>
73+
<releases>
74+
<enabled>true</enabled>
75+
<updatePolicy>always</updatePolicy>
76+
</releases>
77+
<snapshots>
78+
<enabled>false</enabled>
79+
</snapshots>
80+
</pluginRepository>
81+
</pluginRepositories>
82+
</project>

report-datasource/report-datasource-build/pom.xml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<modelVersion>4.0.0</modelVersion>
66

77
<parent>
8-
<artifactId>report-datasource</artifactId>
98
<groupId>com.inductiveautomation.ignition.examples</groupId>
9+
<artifactId>report-datasource</artifactId>
1010
<version>1.3.0-SNAPSHOT</version>
1111
</parent>
1212

@@ -15,17 +15,17 @@
1515
<dependencies>
1616
<dependency>
1717
<groupId>com.inductiveautomation.ignition.examples</groupId>
18-
<artifactId>report-datasource-designer</artifactId>
18+
<artifactId>report-datasource-common</artifactId>
1919
<version>${project.version}</version>
2020
</dependency>
2121
<dependency>
2222
<groupId>com.inductiveautomation.ignition.examples</groupId>
23-
<artifactId>report-datasource-gateway</artifactId>
23+
<artifactId>report-datasource-designer</artifactId>
2424
<version>${project.version}</version>
2525
</dependency>
2626
<dependency>
2727
<groupId>com.inductiveautomation.ignition.examples</groupId>
28-
<artifactId>report-datasource-common</artifactId>
28+
<artifactId>report-datasource-gateway</artifactId>
2929
<version>${project.version}</version>
3030
</dependency>
3131
</dependencies>
@@ -67,16 +67,13 @@
6767
<moduleName>${module-name}</moduleName>
6868
<moduleDescription>${module-description}</moduleDescription>
6969
<moduleVersion>${project.version}</moduleVersion>
70-
<requiredIgnitionVersion>${ignition-platform-version}</requiredIgnitionVersion>
70+
<!-- <requiredIgnitionVersion>${ignition-platform-version}</requiredIgnitionVersion>-->
71+
<requiredIgnitionVersion>8.3.0</requiredIgnitionVersion>
7172

7273
<depends>
7374
<depend>
74-
<scope>G</scope>
75-
<moduleId>rept</moduleId>
76-
</depend>
77-
<depend>
78-
<scope>D</scope>
79-
<moduleId>rept</moduleId>
75+
<scope>DG</scope>
76+
<moduleId>com.inductiveautomation.reporting</moduleId>
8077
</depend>
8178
</depends>
8279

@@ -94,4 +91,4 @@
9491
</plugin>
9592
</plugins>
9693
</build>
97-
</project>
94+
</project>

report-datasource/report-datasource-common/pom.xml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,26 @@
55
<modelVersion>4.0.0</modelVersion>
66

77
<parent>
8-
<artifactId>report-datasource</artifactId>
98
<groupId>com.inductiveautomation.ignition.examples</groupId>
9+
<artifactId>report-datasource</artifactId>
1010
<version>1.3.0-SNAPSHOT</version>
1111
</parent>
1212

1313
<artifactId>report-datasource-common</artifactId>
14+
1415
<dependencies>
1516
<dependency>
1617
<groupId>com.inductiveautomation.ignitionsdk</groupId>
1718
<artifactId>reporting-common</artifactId>
1819
<version>${ignition-sdk-version}</version>
19-
<scope>provided</scope>
2020
<type>pom</type>
21+
<scope>provided</scope>
22+
<exclusions>
23+
<exclusion>
24+
<groupId>com.inductiveautomation.reporting</groupId>
25+
<artifactId>web-ui</artifactId>
26+
</exclusion>
27+
</exclusions>
2128
</dependency>
2229
</dependencies>
23-
</project>
30+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.inductiveautomation.ignition.examples.reporting.datasource.common;
2+
3+
public class ExampleReportDatasourceModule {
4+
private ExampleReportDatasourceModule() {
5+
throw new UnsupportedOperationException("Utility class cannot be instantiated");
6+
}
7+
8+
public static final String REPORTING_MODULE_ID = "com.inductiveautomation.reporting";
9+
}

report-datasource/report-datasource-common/src/main/java/com/inductiveautomation/ignition/examples/reporting/datasource/common/RestJsonDataObject.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package com.inductiveautomation.ignition.examples.reporting.datasource.common;
22

3-
import java.io.Serializable;
3+
4+
import com.inductiveautomation.ignition.common.gson.JsonObject;
5+
import com.inductiveautomation.reporting.common.resource.DataSourceConfigObject;
46

57
/**
68
* Provides a small serializable object that contains data and key in the form of a String. This data object
79
* is sent via RPC call between the Report Workspace and the gateway during report design/preview.
810
* @author Perry Arellano-Jones
911
*/
10-
public class RestJsonDataObject implements Serializable {
12+
public class RestJsonDataObject implements DataSourceConfigObject {
1113
public static final String ID = "com.ia.reporting.examples.rest.json.datasource";
1214
private static final long serialVersionUID = 1;
1315

@@ -58,4 +60,21 @@ public boolean equals(Object obj) {
5860

5961
return true;
6062
}
61-
}
63+
64+
@Override
65+
public JsonObject toJson() {
66+
JsonObject json = new JsonObject();
67+
json.addProperty("key", key);
68+
json.addProperty("url", url);
69+
return json;
70+
}
71+
72+
public static RestJsonDataObject fromJson(JsonObject json) {
73+
if (json == null) {
74+
return null;
75+
}
76+
String key = json.get("key") != null ? json.get("key").getAsString() : null;
77+
String url = json.get("url") != null ? json.get("url").getAsString() : null;
78+
return new RestJsonDataObject(key, url);
79+
}
80+
}

report-datasource/report-datasource-designer/pom.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<modelVersion>4.0.0</modelVersion>
66

77
<parent>
8-
<artifactId>report-datasource</artifactId>
98
<groupId>com.inductiveautomation.ignition.examples</groupId>
9+
<artifactId>report-datasource</artifactId>
1010
<version>1.3.0-SNAPSHOT</version>
1111
</parent>
1212

@@ -40,5 +40,4 @@
4040
<version>${project.version}</version>
4141
</dependency>
4242
</dependencies>
43-
44-
</project>
43+
</project>

report-datasource/report-datasource-designer/src/main/java/com/inductiveautomation/ignition/examples/reporting/datasource/designer/ui/RestJsonDataConfigPanel.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package com.inductiveautomation.ignition.examples.reporting.datasource.designer.ui;
22

33
import javax.swing.JTextField;
4-
import java.io.Serializable;
54

65
import com.google.common.base.Optional;
76
import com.inductiveautomation.ignition.client.util.gui.HeaderLabel;
87
import com.inductiveautomation.ignition.client.util.gui.ValidatedTextField;
98
import com.inductiveautomation.ignition.designer.model.DesignerContext;
9+
import com.inductiveautomation.reporting.common.resource.DataSourceConfig;
10+
import com.inductiveautomation.reporting.common.resource.DataSourceConfigObject;
1011
import com.inductiveautomation.reporting.common.resource.ReportResource;
1112
import com.inductiveautomation.reporting.designer.api.AbstractDataSourceConfigFactory;
1213
import com.inductiveautomation.reporting.designer.api.DataSourceConfigFactory;
@@ -39,19 +40,19 @@ public class RestJsonDataConfigPanel extends DataSourceConfigPanel {
3940
public static final DataSourceConfigFactory FACTORY =
4041
new AbstractDataSourceConfigFactory(RestJsonDataObject.ID, "datasource.DataSource.Type" ) {
4142
@Override
42-
public Serializable newConfigObject() {
43-
return new RestJsonDataObject("NasaMeteorData", "https://data.nasa.gov/resource/mc52-syum.json");
43+
public DataSourceConfigObject newConfigObject() {
44+
return new RestJsonDataObject("cat_facts", "https://catfact.ninja/fact");
4445
}
4546

4647
@Override
47-
public DataSourceConfigPanel createConfigPanel(DesignerContext designerContext, ReportResource reportResource, Serializable dataObject) {
48+
public DataSourceConfigPanel createConfigPanel(DesignerContext designerContext, ReportResource reportResource, DataSourceConfigObject dataObject) {
4849
RestJsonDataObject obj = (RestJsonDataObject) dataObject;
4950
return new RestJsonDataConfigPanel(obj);
5051
}
5152

5253
@Override
53-
public Optional getDataKeyForConfigObject(Serializable dataObject) {
54-
RestJsonDataObject restJsonDataObject = (RestJsonDataObject) dataObject;
54+
public Optional<String> getDataKeyForConfigObject(DataSourceConfig config) {
55+
RestJsonDataObject restJsonDataObject = RestJsonDataObject.fromJson(config.getConfigObjectJson());
5556
return Optional.fromNullable(restJsonDataObject.getKey());
5657
}
5758
};
@@ -75,7 +76,6 @@ protected String validate(String s) {
7576
} else {
7677
return i18n("datasource.Data.InvalidKey");
7778
}
78-
7979
}
8080
};
8181

@@ -92,7 +92,7 @@ protected String validate(String s) {
9292

9393

9494
@Override
95-
public Serializable getConfigObject() {
95+
public DataSourceConfigObject getConfigObject() {
9696
return new RestJsonDataObject(dataKeyTextField.getText(), urlField.getText());
9797
}
98-
}
98+
}

0 commit comments

Comments
 (0)