2 Replies Latest reply on Sep 14, 2016 5:46 AM by pborderie RSS
    pborderie Newbie

    Extension - ThingTemplate - SetHomeMashup

    Hi,

     

    I am developping an extension for ThingWorx, and I can't find a way to set the HomeMashup for a ThingTemplate.

     

    I tried using com.thingworx.entities.RootEntity.SetHomeMashup(String name) with my template mashup's name, in initializeEntity() and in initialiazeThing(), but when I load my extension on the server the HomeMashup setting is blank.

     

    I tried setting it with a JavaScript service on the server, and it works :

    var params = {

        name: "SLBTemplateMashup" /* MASHUPNAME */

    };

    // no return

    ThingTemplates["SLBThingTemplate"].SetHomeMashup(params);

     

    Is there another way to set the HomeMashup on a ThingTemplate from the extension ? Am I missing something ?

     

    Thank you for your answers.

      • Re: Extension - ThingTemplate - SetHomeMashup
        Ankit Gupta Ninja

        Hi Pierre,

         

        Try following and see if it helps:

        ThingTemplate tt = (ThingTemplate) EntityUtilities.findEntity("Thing_Template_Name_Here", ThingworxRelationshipTypes.ThingTemplate);

        tt.SetHomeMashup("Home_Mashup_Name_Here");

         

        You would need to import:

        import com.thingworx.thingtemplates.ThingTemplate;

        import com.thingworx.entities.utils.EntityUtilities;

         

        Hope it helps.

         

        Thanks,

        Ankit Gupta

          • Re: Extension - ThingTemplate - SetHomeMashup
            pborderie Newbie

            I tried it in initializeEntity(), initializeThing() and processStartNotification(), it doesn't work, HomeMashup is not set.

             

            Here is a part of my code :

            @ThingworxBaseTemplateDefinition(name = "RemoteThing")
            @ThingworxPropertyDefinitions(properties = { @ThingworxPropertyDefinition(name = "S1", description = "", category = "Outputs", baseType = "NUMBER", isLocalOnly = false, aspects = { "dataChangeType:Always", "isRemote:true", "units:%", "isLogged:true" }), @ThingworxPropertyDefinition(name = "S2", description = "", category = "Outputs", baseType = "NUMBER", isLocalOnly = false, aspects = { "dataChangeType:Always", "isRemote:true", "units:%", "isLogged:true" }), @ThingworxPropertyDefinition(name = "S3", description = "", category = "Outputs", baseType = "NUMBER", isLocalOnly = false, aspects = { "dataChangeType:Always", "isRemote:true", "units:%", "isLogged:true" }), @ThingworxPropertyDefinition(name = "S4", description = "", category = "Outputs", baseType = "NUMBER", isLocalOnly = false, aspects = { "dataChangeType:Always", "isRemote:true", "units:%", "isLogged:true" }), @ThingworxPropertyDefinition(name = "S5", description = "", category = "Outputs", baseType = "NUMBER", isLocalOnly = false, aspects = { "dataChangeType:Always", "isRemote:true", "units:%", "isLogged:true" }), @ThingworxPropertyDefinition(name = "S6", description = "", category = "Outputs", baseType = "NUMBER", isLocalOnly = false, aspects = { "dataChangeType:Always", "isRemote:true", "units:%", "isLogged:true" }) })
            public class SLBThingTemplate extends RemoteThing {
            
                protected static Logger _logger = LogUtilities.getInstance().getApplicationLogger(SLBThingTemplate.class);
            
                @Override
                public void initializeEntity() throws Exception {
                    super.initializeEntity();
                    _logger.info("in:SLBThingTemplate.initializeEntity()");
                    //
                    ThingTemplate tpl = (ThingTemplate) EntityUtilities.findEntity("SLBThingTemplate", ThingworxRelationshipTypes.ThingTemplate);
                    _logger.info(tpl.getName() + " found!");
                    _logger.info("(before set) HomeMashup = " + tpl.GetHomeMashup());
                    tpl.SetHomeMashup("SLBTemplateMashup");
                    _logger.info("(after set) HomeMashup = " + tpl.GetHomeMashup());
            //        SetHomeMashup("SLBTemplateMashup"); // doesn't work
                    // automatically bind properties to remote properties exposed by the remote device
                    // Outputs:
                    this.SetRemotePropertyBinding("S1", "S1", 0, DataChangeType.NEVER.toString(), 0.);
                    this.SetRemotePropertyBinding("S2", "S2", 0, DataChangeType.NEVER.toString(), 0.);
                    this.SetRemotePropertyBinding("S3", "S3", 0, DataChangeType.NEVER.toString(), 0.);
                    this.SetRemotePropertyBinding("S4", "S4", 0, DataChangeType.NEVER.toString(), 0.);
                    this.SetRemotePropertyBinding("S5", "S5", 0, DataChangeType.NEVER.toString(), 0.);
                    this.SetRemotePropertyBinding("S6", "S6", 0, DataChangeType.NEVER.toString(), 0.);
                    //
                    _logger.info("out:SLBThingTemplate.initializeEntity()");
                }
                @Override
                public void initializeThing() throws Exception {
                    super.initializeThing();
                    _logger.info("in:SLBThingTemplate.initializeThing()");
                    //
                    ThingTemplate tpl = (ThingTemplate) EntityUtilities.findEntity("SLBThingTemplate", ThingworxRelationshipTypes.ThingTemplate);
                    _logger.info(tpl.getName() + " found!");
                    _logger.info("(before set) HomeMashup = " + tpl.GetHomeMashup());
                    tpl.SetHomeMashup("SLBTemplateMashup");
                    _logger.info("(after set) HomeMashup = " + tpl.GetHomeMashup());
                    _logger.info("out:SLBThingTemplate.initializeThing()");
                }
                @Override
                public void processStartNotification() {
                    super.processStartNotification();
                    try {
                        _logger.info("in:SLBThingTemplate.processStartNotification()");
                        //
                        ThingTemplate tpl = (ThingTemplate) EntityUtilities.findEntity("SLBThingTemplate", ThingworxRelationshipTypes.ThingTemplate);
                        _logger.info(tpl.getName() + " found!");
                        _logger.info("(before set) HomeMashup = " + tpl.GetHomeMashup());
                        tpl.SetHomeMashup("SLBTemplateMashup");
                        _logger.info("(after set) HomeMashup = " + tpl.GetHomeMashup());
                    } catch (Exception e) {
                        _logger.error(e.getMessage());
                    }
                    _logger.info("out:SLBThingTemplate.processStartNotification()");
                }
            }