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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

How to get entity basetype?

fmanniti
10-Marble

How to get entity basetype?

Is it possible to determine what a entity is?

I will explain myself:

I would like to make a service which has both as input and output a string.

I insert the name of a entity and it returns

"This entity is a Thing"

"This entity is a Data shape"

"This entity is a username"

Is this possible?

ACCEPTED SOLUTION

Accepted Solutions
aseaton
12-Amethyst
(To:fmanniti)

Hi Fabio,

Here is the solution for your question.

Community Solution.PNG

Hope it helps!

Andy

View solution in original post

9 REPLIES 9
aseaton
12-Amethyst
(To:fmanniti)

Hi Fabio,

Here is the solution for your question.

Community Solution.PNG

Hope it helps!

Andy

Thank you!

That's my method

function getEntityDescription(myEntityName) {

    var collectionName = 'Things';

    var entityType ='Thing';

    var isThing = true;

    var isThingTemplate = false;

    var isThingShape = false;

    var isDataShape = false;

    var isModelTag = false;

    var isNetwork = false;

    var isDataTag = false;

    var isOrganization = false;

    var entity = Things[myEntityName];

    if (entity==null) {

        isThing = false;

        entity = ThingTemplates[myEntityName];

        isThingTemplate=true;

        collectionName = 'ThingTemplates';

        entityType = 'ThingTemplate';

     }

    if (entity==null) {

        isThingTemplate=false;

        entity = ThingShapes[myEntityName];

        isThingShape = true;

        collectionName = 'ThingShapes';

        entityType = 'ThingShape';

     }

    if (entity==null) {

        isThingShape=false;

        entity = DataShapes[myEntityName];

        isDataShape = true;

        collectionName = 'DataShapes';

        entityType = 'DataShape';

     }

    if (entity==null) {

        isDataShape=false;

        entity = ModelTags[myEntityName];

        isModelTag = true;

        collectionName = 'ModelTags';

        entityType = 'ModelTagVocabulary';

     }

    if (entity==null) {

        isModelTag=false;

        entity = Networks[myEntityName];

        isNetwork = true;

        collectionName = 'Networks';

        entityType = 'Network';

     }

    if (entity==null) {

        isNetwork=false;

        entity = DataTags[myEntityName];

        isDataTag = true;

        collectionName = 'DataTags';

        entityType = 'DataTagVocabulary';

     }

    if (entity==null) {

        isDataTags=false;

        entity = Organizations[myEntityName];

        isOrganization = true;

        collectionName = 'Organizations';

        entityType = 'Organitzation';

    }

     return {

    name: myEntityName,

        entity: entity,

        isThingShape: isThingShape,

        isThing: isThing,

        isThingTemplate: isThingTemplate,

        isDataShape: isDataShape,

    isModelTag: isModelTag,

    isNetwork: isNetwork,

    isDataTag: isDataTag,

    isOrganization: isOrganization,

        collectionName: collectionName,

        type: entityType

     };

}

Would be good to know which method it's faster...

Ok I did some tests,

Iterating 1000 times over both functions, my method last at max 10ms ( for 1000 iterations ), the SearchModelEntities method lasts for 15000ms ...

Oh, that's a great point.

Even because your method was quite similar to mine.

I have this input which can be Username, Thing, ThingTemplate.

My metod was

var isUser = (Users[myInput]) ? true : false;

var isThing = (Things[myInput]) ? true : false;

var isTemplate = (ThingTemplates[myInput]) ? true : false;

so, tecnically, it's even faster since it has to choose between three.

I just asked because I believed it was not too orthodox

Your are good to go with you method.


With Search method you must use Search resources, with ModelEntityCollection[] method you are working with In-Memory objects, that's why it's a way faster.

One second, your solution Fabio has a problem, look at my General Performance Recommendations and some perks (unofficial) document.

You should check always explicit --> (Users[myInput])? true : false; should be (Users[myInput]!==null)

and so on.

Oh, ok. Thanks!

Announcements


Top Tags