cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

Java - Empty InfoTable

sch1
4-Participant

Java - Empty InfoTable

I'm trying to create InfoTable in Java, but it's always empty. What do I do wrong? 

 

Created "ThingWorx Extension Project" in Eclipse 2022-03 with "ThingWorx Eclipse Plugin 9.0.1" installed, using SDK 9.2.0, Gradle 6.9.1 and Amazon Corretto 11.0.10.

 

public static void main(String[] args) throws Exception {
	
	// Create InfoTable
	DataShapeDefinition ds = new DataShapeDefinition();
	ds.addFieldDefinition(new FieldDefinition("field1", BaseTypes.NUMBER));

	InfoTable table = new InfoTable(ds);
	ValueCollection row = new ValueCollection();
	
	row.SetNumberValue("field1", 1);
	table.addRow(row.clone());
}

 

Also, tried `new InfoTableFunctions().FromJSON(myJsonInfoTable)` and it doesn't work too.

 

// Create InfoTable from JSON
JSONObject infoTableJson = new JSONObject("{\"dataShape\":{\"fieldDefinitions\":{\"id\":{\"name\":\"id\",\"description\":\"id\",\"baseType\":\"STRING\"}}},\"rows\":[{\"id\":\"someString\"}]}");

InfoTableFunctions fns = new InfoTableFunctions();
InfoTable table = fns.FromJSON(infoTableJson);

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
nmutter
14-Alexandrite
(To:sch1)

You are not able to execute/test your logic without having it deployed in ThingWorx. If you deploy the extension you should see the result (if it works - I did not check the code).

The extensionSDK just has Dummy implementations - so Infotable.addRow(x) has no implementation. As well as toJson has {return null} as implementation. It just does nothing. A real pain for (unit)testing anything. If deployed in the platform the real implementation will be used.

(That was the state when I last checked it more than 1 year ago)

View solution in original post

3 REPLIES 3
sch1
4-Participant
(To:sch1)

You can reproduce it.

 

I downloaded your completed "MyThingworxWeatherExtension" example ExtensionSampleFiles.zip from this tutorial Create An Extension.

I'm still getting an empty InfoTable.

 

Added new class InfoTableCreator with the code below:

 

package com.thingworx.weather;

import com.thingworx.metadata.DataShapeDefinition;
import com.thingworx.metadata.FieldDefinition;
import com.thingworx.types.BaseTypes;
import com.thingworx.types.InfoTable;
import com.thingworx.types.collections.ValueCollection;

public class InfoTableCreator {
	
	public static void main(String[] args) throws Exception {

		// Create InfoTable
		InfoTable table1 = createInfoTable();
		
		// => null
		System.out.println(table1.toJSON());
	}

	public static InfoTable createInfoTable() throws Exception {
		DataShapeDefinition ds = new DataShapeDefinition();
		ds.addFieldDefinition(new FieldDefinition("field1", BaseTypes.NUMBER));

		InfoTable table = new InfoTable(ds);
		ValueCollection row = new ValueCollection();

		row.SetNumberValue("field1", 1);
		table.addRow(row);
		
		return table;
	}
}

 

java-sdk-empty-infotable-issue.png

nmutter
14-Alexandrite
(To:sch1)

You are not able to execute/test your logic without having it deployed in ThingWorx. If you deploy the extension you should see the result (if it works - I did not check the code).

The extensionSDK just has Dummy implementations - so Infotable.addRow(x) has no implementation. As well as toJson has {return null} as implementation. It just does nothing. A real pain for (unit)testing anything. If deployed in the platform the real implementation will be used.

(That was the state when I last checked it more than 1 year ago)

sch1
4-Participant
(To:nmutter)


@nmutter wrote:

A real pain for (unit)testing anything.


Exactly.

 

BTW It's possible to create InfoTables using Edge SDK (not Extensions SDK).

Top Tags