Skip to content

Commit bbd0657

Browse files
committed
Added full support for Datasets and merged payloads
- Added write support for Datasets - Made it so the nodes are not destructive on the payload. They now merge results.
1 parent 7d4353e commit bbd0657

5 files changed

Lines changed: 27 additions & 18 deletions

File tree

IgnitionNodeRED-build/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<moduleId>org.imdc.nodered.IgnitionNodeRED</moduleId>
4848
<moduleName>${module-name}</moduleName>
4949
<moduleDescription>${module-description}</moduleDescription>
50-
<moduleVersion>1.5.14.${timestamp}</moduleVersion>
50+
<moduleVersion>1.5.15.${timestamp}</moduleVersion>
5151
<requiredIgnitionVersion>${ignition-platform-version}</requiredIgnitionVersion>
5252
<requiredFrameworkVersion>8</requiredFrameworkVersion>
5353
<licenseFile>license.html</licenseFile>

IgnitionNodeRED-gateway/src/main/java/org/imdc/nodered/servlet/NodeREDServlet.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import com.inductiveautomation.ignition.common.browsing.Results;
77
import com.inductiveautomation.ignition.common.model.values.QualifiedValue;
88
import com.inductiveautomation.ignition.common.model.values.QualityCode;
9-
import com.inductiveautomation.ignition.common.script.builtin.DatasetUtilities;
109
import com.inductiveautomation.ignition.common.tags.browsing.NodeDescription;
1110
import com.inductiveautomation.ignition.common.tags.model.TagPath;
1211
import com.inductiveautomation.ignition.common.tags.paths.parser.TagPathParser;
@@ -144,12 +143,13 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
144143
} else if (command.equals("tagWrite")) {
145144
List<Object> values = new ArrayList<>();
146145
if (input.has("value")) {
147-
values.add(input.get("value"));
146+
Object value = input.get("value");
147+
values.add(checkJSONObject(logger, value));
148148
} else {
149149
JSONArray valuesArray = input.getJSONArray("values");
150150
for (int i = 0; i < valuesArray.length(); i++) {
151151
Object value = valuesArray.get(i);
152-
values.add(value);
152+
values.add(checkJSONObject(logger, value));
153153
}
154154
}
155155

@@ -229,7 +229,22 @@ public static void setTagValue(List<TagPath> tagPaths, List<QualifiedValue> tagV
229229

230230
public static Object checkObject(Object value) {
231231
if (value instanceof Dataset) {
232-
return DatasetUtilities.toJSONObject((Dataset) value);
232+
return TypeUtilities.datasetToJSON((Dataset) value);
233+
}
234+
235+
return value;
236+
}
237+
238+
public static Object checkJSONObject(Logger logger, Object value) {
239+
if (value instanceof JSONObject) {
240+
JSONObject jsonObj = (JSONObject) value;
241+
if (jsonObj.has("columns") && jsonObj.has("rows")) {
242+
try {
243+
return TypeUtilities.datasetFromJSON(jsonObj);
244+
} catch (Throwable t) {
245+
logger.error("Error converting JSON object to Dataset", t);
246+
}
247+
}
233248
}
234249

235250
return value;
@@ -294,7 +309,7 @@ private void tagWrite(GatewayContext context, final List<TagPath> tagPaths, fina
294309
QualityCode quality = writeResult.get(0);
295310
Object value = writeValues.get(0);
296311
result.put("tagPath", tagPath.toStringFull());
297-
result.put("value", value);
312+
result.put("value", checkObject(value));
298313
setQuality(result, quality);
299314
audit(context, ipAddress, validation, tagPath, value, quality);
300315
} else {
@@ -305,7 +320,7 @@ private void tagWrite(GatewayContext context, final List<TagPath> tagPaths, fina
305320
QualityCode quality = writeResult.get(i);
306321
Object value = writeValues.get(i);
307322
tagObject.put("tagPath", tagPath.toStringFull());
308-
tagObject.put("value", value);
323+
tagObject.put("value", checkObject(value));
309324
setQuality(tagObject, quality);
310325
resultValues.put(tagObject);
311326
audit(context, ipAddress, validation, tagPath, value, quality);

node-red-contrib-ignition/error-handling.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
*/
1616
module.exports = {
1717
HandleResponse: function (RED, node, config, msg, result, statusCode, nodeErrorMessage, errorMessage){
18-
result.statusCode = statusCode;
19-
result.errorMessage = errorMessage;
20-
2118
switch (config.valueType) {
2219
case "msg":
2320
if(!config.value || config.value == ""){
@@ -28,7 +25,7 @@ module.exports = {
2825
config.value = "payload";
2926
}
3027

31-
RED.util.setMessageProperty(msg, config.value, result, true);
28+
RED.util.setMessageProperty(msg, config.value + ".ignitionResult", result.ignitionResult, true);
3229

3330
if(statusCode > 1){
3431
node.status({ fill: "red", shape: "ring", text: nodeErrorMessage });
@@ -40,9 +37,6 @@ module.exports = {
4037
},
4138

4239
HandleWSResponse: function (RED, node, config, result, statusCode, nodeErrorMessage, errorMessage){
43-
result.statusCode = statusCode;
44-
result.errorMessage = errorMessage;
45-
4640
var msg;
4741
if (node.wholemsg) {
4842
msg = result;

node-red-contrib-ignition/node-handlers.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var IgnitionNodesImpl = (function () {
4444
}
4545

4646
IgnitionNodesImpl.prototype.addMsg = function (msg) {
47-
var result = { ignitionResult: { statusCode: 1, errorMessage:"" } };
47+
var result = { ignitionResult: { } };
4848

4949
if(!this.serverConfig){
5050
errorHandling.HandleResponse(RED, this.node, this.config, msg, result, 2, "Configuration error", "Configuration error");
@@ -153,7 +153,7 @@ var IgnitionNodesImpl = (function () {
153153
var finalTagValues = [];
154154

155155
function checkTagValueObjects(tp, tv, finalTagPaths, finalTagValues) {
156-
if(tv != null && typeof tv == 'object'){
156+
if(tv != null && typeof tv == 'object' && !(tv.hasOwnProperty("columns") && tv.hasOwnProperty("rows"))){
157157
for (const key in tv) {
158158
var ktp = tp + "/" + key;
159159
var ktv = tv[key];
@@ -312,7 +312,7 @@ var IgnitionWSNodesImpl = (function () {
312312
};
313313

314314
IgnitionWSNodesImpl.prototype.handleEvent = function (id, socket, event, data, flags) {
315-
var result = { ignitionResult: { statusCode: 1, errorMessage:"" } };
315+
var result = { ignitionResult: { } };
316316
var statusCode = 1;
317317
var nodeErrorMessage = "";
318318
var errorMessage = "";

node-red-contrib-ignition/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-contrib-ignition-nodes",
3-
"version": "1.5.14",
3+
"version": "1.5.15",
44
"description": "Adds support for reading, writing, and browsing tags in Ignition",
55
"dependencies": {
66
"ws": "^7.5.3",

0 commit comments

Comments
 (0)