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

Unable to use InfoTable from custom service on Mashup

SOLVED
Newbie

Unable to use InfoTable from custom service on Mashup

Hi Team,

I have a thing template created in JAVA extension, this template has few properties and a service. Once this extension is imported I create a thing from thingtemplate created using extension and test the service inherited from thingtemplate. Works well. No issues here. I can see the infotable along with set of data too when I execute the service. But, when I use this service on Mashup for example Label chart I could not see any poperties under ALL DATA. Screenshot is below. Please tell me what is the wrong I am doing here.

GFT.png

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Unable to use InfoTable from custom service on Mashup

azim hawaldar​,

As per my understanding; Service Result definition should be something like:

@ThingworxServiceResult(name = "Result", description = "", baseType = "INFOTABLE", aspects = {

            "isEntityDataShape:true", "dataShape:InfotableDataShapeName" })

Update the InfotableDataShapeName according to your Data Shape Name.

View solution in original post

7 REPLIES 7

Re: Unable to use InfoTable from custom service on Mashup

Hi azim hawaldar​,

So, if I understand your query correctly; this service returns infotable. Does that info-table has a DataShape?

Can you share the Java Code showing the Structure of your Service?

Re: Unable to use InfoTable from custom service on Mashup

Yeah Ankit Gupta​, you are right this service returns infotable. Below is the code for service.

@ThingworxServiceDefinition(name = "GenerateFFTFromStream", description = "", category = "", isAllowOverride = false, aspects = {

  "isAsync:false" })

  @ThingworxServiceResult(name = "Result", description = "", baseType = "INFOTABLE", aspects = {

  "isEntityDataShape:true" })

  public InfoTable GenerateFFTFromStream() throws Exception {

  System.out.println("Entering Service: GenerateFFTFromStream");

  Thing wheeThing = (Thing) EntityUtilities.findEntity("WheelThing", ThingworxRelationshipTypes.Thing);

  System.out.println("GenerateFFTFromStream: Got the wheelThing" + wheeThing.toString());

  _logger.info("GenerateFFTFromStream: Got the wheelThing" + wheeThing.toString());

  InfoTable infoTable = null;

  try {

  infoTable = wheeThing.QueryPropertyHistory(null, null, null, true, null);

  } catch (Exception e) {

  _logger.error("Exception in GenerateFFTFromStream", e);

  System.out.println("Exception in GenerateFFTFromStream");

  e.printStackTrace();

  return null;

  }

  System.out.println("Exiting Service: GenerateFFTFromStream");

  _logger.warn("Exiting Service: GenerateFFTFromStream");

  return calculateFFT(infoTable);

  }

  private InfoTable calculateFFT(InfoTable infoTable) throws Exception {

  DataShapeDefinition dataShape = infoTable.getDataShape();

  DataShapeDefinition outputDataShape = dataShape.clone();

  outputDataShape.addFieldDefinition(new FieldDefinition("frequency", "NUMBER"));

  ValueCollection row = null;

  List<Double> xAxisList = new ArrayList<Double>();

  List<Double> yAxisList = new ArrayList<Double>();

  System.out.println("" + infoTable.getLength());

  for (int i = 0; i < infoTable.getLength(); i++) {

  row = infoTable.getRow(i);

  System.out.println(row);

  System.out.println("Prop_xaxis:" + row.getPrimitive("Prop_xaxis"));

  System.out.println("Prop_xaxis:" + row.getValue("Prop_xaxis"));

  System.out.println("Prop_yaxis:" + row.getPrimitive("Prop_yaxis"));

  System.out.println("Prop_yaxis:" + row.getValue("Prop_yaxis"));

  if (null != row.getValue("Prop_xaxis") && null != row.getValue("Prop_yaxis")

  && null != row.getValue("Prop_time")) {

  xAxisList.add((Double) row.getValue("Prop_xaxis"));

  yAxisList.add((Double) row.getValue("Prop_yaxis"));

  }

  }

  System.out.println("Raw data x: " + xAxisList);

  System.out.println("Raw data y: " + yAxisList);

  double[] xaxis = convertDouble(xAxisList);

  double[] yaxis = convertDouble(yAxisList);

  System.out.println("Double data x: " + Arrays.toString(xaxis));

  System.out.println("Double data y: " + Arrays.toString(yaxis));

  double[] xaxisFFT = transform(xaxis);

  double[] yaxisFFT = transform(yaxis);

  System.out.println("FFT data x: " + Arrays.toString(xaxisFFT));

  System.out.println("FFT data y: " + Arrays.toString(yaxisFFT));

  InfoTable output = constructInfoTable(outputDataShape, xaxisFFT, yaxisFFT);

  return output;

  }

  private InfoTable constructInfoTable(DataShapeDefinition outputDataShape, double[] xaxisFFT, double[] yaxisFFT)

  throws Exception {

  System.out.println("Constructing info table: ");

  InfoTable output = new InfoTable(outputDataShape);

  ValueCollection rowValue = null;

  for (int i = 0; i < xaxisFFT.length; i++) {

  rowValue = new ValueCollection();

  rowValue.SetNumberValue("Prop_xaxis", xaxisFFT);

  rowValue.SetNumberValue("Prop_yaxis", yaxisFFT);

  rowValue.SetNumberValue("frequency", i + 1);

  output.addRow(rowValue);

  }

  return output;

  }

  public double[] convertDouble(List<Double> doubleList) {

  double[] ret = new double[doubleList.size()];

  for (int i = 0; i < doubleList.size(); i++) {

  ret = doubleList.get(i).doubleValue();

  }

  return ret;

  }

Re: Unable to use InfoTable from custom service on Mashup

azim hawaldar​,

As per my understanding; Service Result definition should be something like:

@ThingworxServiceResult(name = "Result", description = "", baseType = "INFOTABLE", aspects = {

            "isEntityDataShape:true", "dataShape:InfotableDataShapeName" })

Update the InfotableDataShapeName according to your Data Shape Name.

View solution in original post

Re: Unable to use InfoTable from custom service on Mashup

Azim the best way to go about checking what data is returned from your service and whether or not correct datashape is assigned to the result would be to Test the service and on the result page you shall have something like this

use this option to create your DataShape and assign this to the returning result of your service if the output is of type Infotable. With this you'll make sure that the DataShape is exactly according to the data returned by your service.

As to the check in the mashup you can now test by creating a demo mashup and use Grid widget, call that service which you'd want to bind to the chart for plotting , and bind it to the Grid and view mashup.


With this you can get the idea whether or not your service is returning the right result with right datashape or not.

Re: Unable to use InfoTable from custom service on Mashup

Hello Ankit Gupta​,

Thanks again for helping me . This has solved my issue.

Thanks again,

Azim

Re: Unable to use InfoTable from custom service on Mashup

Sushant Pandey​,

Thank you this is the other way of assigning a datashape to an Info Table. Appreciate your help.

Thanks,

Azim

Re: Unable to use InfoTable from custom service on Mashup

I am glad it helped.

Announcements

Thingworx Navigate content has a new home! Click here to access the new Thingworx Navigate forum! ______________________________