Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X
Hi all,
I check JAVA sample code, and it use ThingworxPropertyDefinitions to push properties to ThingWorx.
If I want to add a new properties in ThingworxPropertyDefinitions at runtime, how can I achieve this...?
Thank you.
@ThingworxPropertyDefinitions(properties = {
@ThingworxPropertyDefinition(name="Temperature", description="Current Temperature", baseType="NUMBER", category="Status", aspects={"isReadOnly:true"}),
@ThingworxPropertyDefinition(name="Pressure", description="Current Pressure", baseType="NUMBER", category="Status", aspects={"isReadOnly:true"}),
@ThingworxPropertyDefinition(name="FaultStatus", description="Fault status", baseType="BOOLEAN", category="Faults", aspects={"isReadOnly:true"}),
@ThingworxPropertyDefinition(name="InletValve", description="Inlet valve state", baseType="BOOLEAN", category="Status", aspects={"isReadOnly:true"}),
@ThingworxPropertyDefinition(name="TemperatureLimit", description="Temperature fault limit", baseType="NUMBER", category="Faults", aspects={"isReadOnly:false"}),
@ThingworxPropertyDefinition(name="TotalFlow", description="Total flow", baseType="NUMBER", category="Aggregates", aspects={"isReadOnly:true"}),
})
Solved! Go to Solution.
Hi Brandon,
See below a snippet (I tested a value received from XML to see if is number, boolean or string and created specific property per type):
Also note at the end the use of super.initialize(); instead of super.initializeFromAnnotations() (you can either use one or another as I've seen)
PropertyDefinition pd;
AspectCollection aspects = new AspectCollection();
if (NumberUtils.isNumber(str_AttributeValue)) {
pd = new PropertyDefinition(str_AttributeName,
" ", BaseTypes.NUMBER);
} else if (str_AttributeValue == "true"
| str_AttributeValue == "false") {
pd = new PropertyDefinition(str_AttributeName,
" ", BaseTypes.BOOLEAN);
} else
pd = new PropertyDefinition(str_AttributeName,
" ", BaseTypes.STRING);
aspects.put(
Aspects.ASPECT_DATACHANGETYPE,
new StringPrimitive(DataChangeType.VALUE.name()));
// Add the dataChangeThreshold aspect
aspects.put(Aspects.ASPECT_DATACHANGETHRESHOLD,
new NumberPrimitive(0.0));
// Add the cacheTime aspect
aspects.put(Aspects.ASPECT_CACHETIME,
new IntegerPrimitive(0));
// Add the isPersistent aspect
aspects.put(Aspects.ASPECT_ISPERSISTENT,
new BooleanPrimitive(true));
// Add the isReadOnly aspect
aspects.put(Aspects.ASPECT_ISREADONLY,
new BooleanPrimitive(true));
// Add the pushType aspect
aspects.put("pushType", new StringPrimitive(
DataChangeType.VALUE.name()));
aspects.put(Aspects.ASPECT_ISLOGGED,
new BooleanPrimitive(true));
pd.setAspects(aspects);
super.defineProperty(pd);
super.initialize();
Hi Brandon,
See below a snippet (I tested a value received from XML to see if is number, boolean or string and created specific property per type):
Also note at the end the use of super.initialize(); instead of super.initializeFromAnnotations() (you can either use one or another as I've seen)
PropertyDefinition pd;
AspectCollection aspects = new AspectCollection();
if (NumberUtils.isNumber(str_AttributeValue)) {
pd = new PropertyDefinition(str_AttributeName,
" ", BaseTypes.NUMBER);
} else if (str_AttributeValue == "true"
| str_AttributeValue == "false") {
pd = new PropertyDefinition(str_AttributeName,
" ", BaseTypes.BOOLEAN);
} else
pd = new PropertyDefinition(str_AttributeName,
" ", BaseTypes.STRING);
aspects.put(
Aspects.ASPECT_DATACHANGETYPE,
new StringPrimitive(DataChangeType.VALUE.name()));
// Add the dataChangeThreshold aspect
aspects.put(Aspects.ASPECT_DATACHANGETHRESHOLD,
new NumberPrimitive(0.0));
// Add the cacheTime aspect
aspects.put(Aspects.ASPECT_CACHETIME,
new IntegerPrimitive(0));
// Add the isPersistent aspect
aspects.put(Aspects.ASPECT_ISPERSISTENT,
new BooleanPrimitive(true));
// Add the isReadOnly aspect
aspects.put(Aspects.ASPECT_ISREADONLY,
new BooleanPrimitive(true));
// Add the pushType aspect
aspects.put("pushType", new StringPrimitive(
DataChangeType.VALUE.name()));
aspects.put(Aspects.ASPECT_ISLOGGED,
new BooleanPrimitive(true));
pd.setAspects(aspects);
super.defineProperty(pd);
super.initialize();
Hi Vladimir,
Thanks for your reply, this method works.
But I have one more question, I want to push a table like below structure to ThingWorx by using JAVA SDK.
Bind the table data to PieChart and then display it.
How do I define the table and pass value?
Name | Value |
---|---|
fieldName1 | 5 |
fieldName2 | 10 |
fieldName3 | 15 |
... | ... |