Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert json into aasx fails #250

Closed
Kuchsn opened this issue Mar 11, 2024 · 4 comments
Closed

convert json into aasx fails #250

Kuchsn opened this issue Mar 11, 2024 · 4 comments
Labels
question Further information is requested

Comments

@Kuchsn
Copy link

Kuchsn commented Mar 11, 2024

Hey together,
i try now since 3 days to read a json from Festo(Example) and safe it as a aasx file.
But the file doesn't contain the expected data.
What i am doing wrong?

from basyx.aas import model
from basyx.aas.adapter import aasx
from basyx.aas.adapter import json as aas_json
from basyx.aas.adapter import xml as aas_xml


##################################################################
# Step 1: Reading the Serialized AAS Objects From JSON/XML Files #
##################################################################
with open('./data/Festo.json', encoding='utf-8-sig') as json_file:
    json_file_data = aas_json.read_aas_json_file(json_file)

# For holding auxiliary files, which will eventually be added to an AASX package, we need a SupplementaryFileContainer.
file_store = aasx.DictSupplementaryFileContainer()

######################################################################
# Step 2: Writing AAS objects and auxiliary files to an AASX package #
######################################################################

with aasx.AASXWriter("./data/Festo.aasx") as writer:
    # Write the AAS and everything belonging to it to the AASX package
    # The `write_aas()` method will automatically fetch the AAS object with the given id

    #I don't know the id, so i iterate over every obj int the dictionary

    for obj in json_file_data:
        writer.write_aas(aas_ids=obj.id,
                     object_store=json_file_data,
                     file_store=file_store)
        writer.close()

Festo.json
This programm end without an error.
If i try to upload it on a local server:

import requests
# Define the endpoint URL
url = 'http://192.168.11.79:5001/packages'

# Specify the file path of the AASX file
aasx_file_path = './data/Festo2.aasx'

# Prepare the data to be sent in the POST request
files = {'file': open(aasx_file_path, 'rb')}

# Send the POST request
response = requests.post(url, files=files)

# Check the response
if response.status_code == 200:
    print("AASX file uploaded successfully.")
else:
    print("Failed to upload AASX file. Status code:", response.status_code)
    print("Response:", response.text)

i get this response:

Failed to upload AASX file. Status code: 500
Response: {
  "messages": [
    {
      "code": "InternalServerError",
      "correlationId": null,
      "messageType": "Error",
      "text": "While reading the ./aasxs/Festo2.aasx (and indirectly over /tmp/tmppTj8iJ.aasx) at /AdminShellPackageEnv.cs:line 420 gave: Unable to find AASX origin. Aborting!",
      "timestamp": "03/11/2024 13:59:46"
    }
  ]
}
Festo2$ ls -lR
.:
total 12
drwxrwxr-x 3 user user 4096 Mär 11 15:02  aasx
-rw------- 1 user user  446 Jan  1  1980 '[Content_Types].xml'
drwxrwxr-x 2 user user 4096 Mär 11 15:02  _rels

./aasx:
total 4
-rw------- 1 user user    0 Jan  1  1980 aasx-origin
drwxrwxr-x 2 user user 4096 Mär 11 15:02 _rels

./aasx/_rels:
total 4
-rw------- 1 user user 139 Jan  1  1980 aasx-origin.rels

./_rels:
total 0
@Kuchsn
Copy link
Author

Kuchsn commented Mar 11, 2024

i figured out, that "json_file_data" is empty?

with open('./data/Festo.json', encoding='utf-8-sig') as json_file:
    json_file_data = aas_json.read_aas_json_file(json_file)
print("Type of json_file_data:", type(json_file_data))
print("Number of AAS objects in json_file_data:", len(json_file_data))
Type of json_file_data: <class 'basyx.aas.model.provider.DictObjectStore'>
Number of AAS objects in json_file_data: 0

if i read the json normal i can see all

with open('./data/Festo.json', 'r') as file:
    data = json.load(file)
print(data)

@jkhsjdhjs
Copy link
Contributor

i get this response:

"text": "While reading the ./aasxs/Festo2.aasx (and indirectly over /tmp/tmppTj8iJ.aasx) at /AdminShellPackageEnv.cs:line 420 gave: Unable to find AASX origin. Aborting!",

Same issue as #185, the server you're using is probably using outdated OPC Relationship types.

As for the issue with the seemingly empty JSON file: It's possible that the file uses incorrect attribute names, that aren't recognized by our SDK. You can try validating this file against the official schemata using our compliance tool: https://basyx-python-sdk.readthedocs.io/en/latest/compliance_tool/index.html

@s-heppner s-heppner added the question Further information is requested label Mar 14, 2024
@Kuchsn
Copy link
Author

Kuchsn commented Mar 14, 2024

Related to eclipse-aaspe #161 and #232
Edit: most aasx, json and xml EXAMPLE file are old specification!

@Kuchsn Kuchsn closed this as completed Mar 14, 2024
@s-heppner
Copy link
Contributor

Yes, that is the case.
Currently, as far as I know, the IDTA has no maintenance process for submodel templates, therefore there is no one responsible for updating them.
However, I have heard that they are aware of this problem and are working on a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants