Error in loading models in Azure Digitial Twins

GuidoL 310 Reputation points
2023-04-13T18:12:07.1366667+00:00

Hi, i obtain the following error when i try to upload some json files in to my ADT instance: immagine

I don't understand the reason: syntax is correct. Here's an code example of json that is impossible to load.

{
  "@id": "dtmi:digitaltwins:org:w3id:rec:agents:Person;1",
  "@type": "Interface",
  "contents": [
    {
      "@type": "Property",
      "description": {
        "en": "A name for some Agent."
      },
      "displayName": {
        "en": "name"
      },
      "name": "name",
      "schema": "string",
      "writable": true
    },
    {
      "@type": "Property",
      "description": {
        "en": "A person's last name (if they have one; this varies across cultural contexts)."
      },
      "displayName": {
        "en": "last name"
      },
      "name": "lastName",
      "schema": "string",
      "writable": true
    },
    {
      "@type": "Property",
      "description": {
        "en": "URL link to an image that represents the person."
      },
      "displayName": {
        "en": "image"
      },
      "name": "image",
      "schema": "string",
      "writable": true
    },
    {
      "@type": "Property",
      "description": {
        "en": "A person's personal, individual name."
      },
      "displayName": {
        "en": "given name"
      },
      "name": "givenName",
      "schema": "string",
      "writable": true
    },
    {
      "@type": "Property",
      "description": {
        "en": "A gender designation for a Person."
      },
      "displayName": {
        "en": "gender"
      },
      "name": "gender",
      "schema": "string",
      "writable": true
    },
    {
      "@type": "Property",
      "description": {
        "en": "A person's first name (if they have one; this varies across cultural contexts)."
      },
      "displayName": {
        "en": "first name"
      },
      "name": "firstName",
      "schema": "string",
      "writable": true
    },
    {
      "@type": "Property",
      "description": {
        "en": "A person's family name."
      },
      "displayName": {
        "en": "family name"
      },
      "name": "familyName",
      "schema": "string",
      "writable": true
    }
  ],
  "description": {
    "en": "A natural person (i.e., an individual human being)."
  },
  "displayName": {
    "en": "Person"
  },
  "extends": "dtmi:digitaltwins:org:w3id:rec:core:Agent;1",
  "@context": "dtmi:dtdl:context;2"
}

and here is an other json model that its upload works; both were generated by OWL2DTDL Converter starting from on ontology i developed using Protege. Thanks in advance. Guido

{
  "@id": "dtmi:digitaltwins:org:w3id:rec:core:Agent;1",
  "@type": "Interface",
  "contents": [
    {
      "@type": "Property",
      "displayName": {
        "en": "Custom Tags"
      },
      "name": "customTags",
      "dtmi:dtdl:property:schema;2": {
        "@type": "Map",
        "dtmi:dtdl:property:mapKey;2": {
          "name": "tagName",
          "schema": "string"
        },
        "dtmi:dtdl:property:mapValue;2": {
          "name": "tagValue",
          "schema": "string"
        }
      },
      "writable": true
    },
    {
      "@type": "Property",
      "displayName": {
        "en": "External IDs"
      },
      "name": "externalIds",
      "dtmi:dtdl:property:schema;2": {
        "@type": "Map",
        "dtmi:dtdl:property:mapKey;2": {
          "name": "externalIdName",
          "schema": "string"
        },
        "dtmi:dtdl:property:mapValue;2": {
          "name": "externalIdValue",
          "schema": "string"
        }
      },
      "writable": true
    },
    {
      "@type": "Property",
      "displayName": {
        "en": "name"
      },
      "name": "name",
      "schema": "string",
      "writable": true
    }
  ],
  "description": {
    "en": "The human, group, or machine that consumes or acts upon an object or data. This higher-level grouping allows properties that are shared among its subclasses (Person, Organization, Company, Department...) to be anchored in one joint place, on the Agent class."
  },
  "displayName": {
    "en": "Agent"
  },
  "@context": "dtmi:dtdl:context;2"
}
Azure Digital Twins
Azure Digital Twins
An Azure platform that is used to create digital representations of real-world things, places, business processes, and people.
228 questions
0 comments No comments
{count} votes

Accepted answer
  1. LeelaRajeshSayana-MSFT 14,676 Reputation points Microsoft Employee
    2023-04-14T12:58:55.5566667+00:00

    Hi @GuidoL , You can automate the bulk import of models using a .Net SDK by implementing the code sample provided in the Upload a model section of the client App. You can make the code iterate through all your models and create them on to your Azure Digital Twin instance. The following piece of code checks for any errors that may arise during the model creation and provides a detailed message.

    try
    {
        await client.CreateModelsAsync(models);
        Console.WriteLine("Models uploaded to the instance:");
    }
    catch (RequestFailedException e)
    {
        Console.WriteLine($"Upload model error: {e.Status}: {e.Message}");
    }
    
    

    Please refer the documentation on DTDL V2 which provides more details and limitations on the properties of the models. Here are the details for your reference. User's image

    i got an error message about lenght limit for @type interface (lenght limit for this type is 128);

    The error message you see is because the ID field might have exceeded the 128-character limit.

    i think OWL2DTDL converter have to report this limit to avoid this error

    I believe the OWL2DTDL Converter sample provided does not have the limitation checks implemented on top of it prior to conversion. I appreciate it if you can report this issue to the GitHub. It would be great if the conversion tool catches these errors before conversion. Please let us know if you still have any additional questions on this or need further assistance. Thank you.


1 additional answer

Sort by: Most helpful
  1. Sander van de Velde | MVP 31,851 Reputation points MVP
    2023-04-13T19:36:32.4866667+00:00

    Hello @GuidoL , I first tried to upload the Person model. This gave an issue due to an unknown Agent model.

    I then uploaded the Agent Model first and it succeeded. When I uploaded the Person model again, I got this error:

    RestError: None of the models in this request could be created due to a problem with one or more models: dtmi:digitaltwins:org:w3id:rec:agents:Person;1, because it transitively extends dtmi:digitaltwins:org:w3id:rec:core:Agent;1, has property 'contents' that contains more than one element whose property 'name' has value 'name'. Either change the value of property 'name' to a unique string value, or remove one or more extends properties so that 'contents' will not be imported.. See model documentation(https://aka.ms/ADTv2Models) for supported format.
        at new t (https://explorer.digitaltwins.azure.net/static/js/2.c69de75d.chunk.js:2:14584145)
        at https://explorer.digitaltwins.azure.net/static/js/2.c69de75d.chunk.js:2:14589431
        at https://explorer.digitaltwins.azure.net/static/js/2.c69de75d.chunk.js:2:14590116
    

    As the error explains, there is a collision regarding the 'name' property. Personally, I expected an Agent to extend a person, not the other way around. But I removed the name property from the person and it works: User's image

    Please check the DTDL documentation again if this does not fit you. If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.