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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Projects extension dependencies

jensc
17-Peridot

Projects extension dependencies

Hello community,

 

I am trying to build a service that can check all of our thingworx platforms for projects that uses one of our extensions we have built.

 

To do this I am currently using the project entities "ListExternalDependencies" service and from that information filtering on the containerName (which is the name of the extension).

 

I was wondering though, is there perhaps a better way of doing this that I have missed?

Because I am look at:

jensc_0-1700657897534.png

 

And thinking that perhaps there is some service I could use to just straight up get the same information that is used to built the list of extension dependencies shown in the project entity.

 

I had a look in the developer tool and found:

jensc_2-1700657980546.png

So here I am thinking I might be able to use something similar to this endpoint?

 

Any pointers would be greatly appreciated.

 

Regards,

Jens C

 

1 ACCEPTED SOLUTION

Accepted Solutions

I do not think there is a better way.

You are executing a Project's service that delivers exactly the information you need, so from efficiency standpoint, it's as it should be.

The Developer tools shows you the GET output for the whole entity, so if you would have wanted to use a GET request on the entity itself and read the "dependsOn" key, while you get the same information, the GET itself retrieves all that entity's model information, making it less performant (as a side note, in reality it will probably have the same performance and impact, because you get data which is in memory, but theoretically speaking you get more data than what you need).

 

Of course, if you already executed a GET for that Project entity already, you can use the data there (you no longer need to execute "ListExternalDependencies")...up to you,

 

(As a side question, have you encountered any performance issues related to this, or you're just optimizing to the best ?)

 

BR,

View solution in original post

2 REPLIES 2

I do not think there is a better way.

You are executing a Project's service that delivers exactly the information you need, so from efficiency standpoint, it's as it should be.

The Developer tools shows you the GET output for the whole entity, so if you would have wanted to use a GET request on the entity itself and read the "dependsOn" key, while you get the same information, the GET itself retrieves all that entity's model information, making it less performant (as a side note, in reality it will probably have the same performance and impact, because you get data which is in memory, but theoretically speaking you get more data than what you need).

 

Of course, if you already executed a GET for that Project entity already, you can use the data there (you no longer need to execute "ListExternalDependencies")...up to you,

 

(As a side question, have you encountered any performance issues related to this, or you're just optimizing to the best ?)

 

BR,

Hello @VladimirRosu,

 

Thanks for your response.

 

I get what you mean.

While I don't think my solution is optimal in any way (built quickly to get something out the door), it does work for what I want it to do.

Using the whole entities information from the GET request, I also do not have the option of counting how many times an extension is used in the project (this information could come to use later).

 

Here is my solution:

let externalDependenciesURL = 
          "https://" +
          Input.PlatformURL + '/Thingworx/Projects/' +
          project.name + 
          "/Services/ListExternalDependencies";

      let params = {
        headers: {
          //'appkey': me.appKey,
          "Content-Type": "application/json",
          Accept: "application/json",
        },
        username: USERNAME,
        password: PASSWORD,
        ignoreSSLErrors: true, // To avoid PKIX error
        url: externalDependenciesURL /* STRING */,
      };

      let dependenciesRawData;
      try {
        dependenciesRawData = Resources["ContentLoaderFunctions"].PostJSON(params);
      } catch (err) {
        logger.error("Platform: " + Input.TwxURL + " is not responding, could it be down?");
        let errMsg = "Project [{}] Thing [{}] Service [{}] error at line [{}] : {}";
        logger.error(errMsg, me.GetProjectName(), me.name, err.fileName, err.lineNumber, err);
      }

      const foundationalProducts = ["MyExtensionName"];

      dependenciesRawData.rows.forEach((dependency) => {
        if (foundationalProducts.some((product) => dependency.containerName.includes(product))) {
          let projectJSON = {
            Comment: "Foundational component is being used in project: " + project.name,
            Description: "Foundational component version: " + dependency.containerVersion,
            Instance: Input.Instance,
            Name: dependency.containerName,
            ServerName: Input.ServerName,
            Timestamp: dateFormat(new Date(), me.DateFormat), // server time
            TypeOfEntity: "FoundationalProductDependency",
          };
          foundationalProductsDataJSON.FoundationalProducts.push(projectJSON);
        }
      });

 

I think the worst thing is that we do all of this manipulation of the data for each project on each platform that we have.

Even though this is run "async" using subscription, I fear that some servers might timeout. But so far I haven't seen that issue.

 

So my question was really just to see if perhaps there was a better solution out there.

I might take the time to try and optimize this, but will leave it for now.

 

Thanks,

Jens C.

Top Tags