2 Replies Latest reply on Jan 13, 2018 8:59 PM by byang RSS
    byang Newbie

    How to dynamic add properties by using JAVA Edge SDK

    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"}),


      • Re: How to dynamic add properties by using JAVA Edge SDK
        vladimirros Creator

        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);




                                        new StringPrimitive(DataChangeType.VALUE.name()));


                                // Add the dataChangeThreshold aspect



                                        new NumberPrimitive(0.0));


                                // Add the cacheTime aspect



                                        new IntegerPrimitive(0));


                                // Add the isPersistent aspect



                                        new BooleanPrimitive(true));


                                // Add the isReadOnly aspect



                                        new BooleanPrimitive(true));


                                // Add the pushType aspect


                                aspects.put("pushType", new StringPrimitive(



                                        new BooleanPrimitive(true));