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

Add conversion of AML data #3

Merged
merged 10 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Test

on: pull_request

jobs:
lint:
name: Linting and formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
name: Install Python
with:
python-version: "3.x"

- name: Install tox
run: python -m pip install tox

- name: Run test suite
run: python -m tox -p -e flake8,black,yamllint

test_tox:
name: Run full tests
needs: lint
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
name: Install Python
with:
python-version: "3.x"

- name: Install tox
run: python -m pip install tox

- name: Run test suite
run: python -m tox -e py3
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,36 @@ Or you can pip install it from pypi.
pip install domus-tdd-api-plugin-aid
```

## Testing with example data

Have a fuseki running (and the config.toml/environment variables) set to the SPARQL endpoint route

Install the plugin (see above), then

```
cd domus-tdd-api-plugin-aid
source env_name/bin/activate
domus-tdd-api run
```

In another terminal in the `domus-tdd-api-plugin-aid` folder

```
curl -XPOST -iH "Content-Type: application/aml+xml" -d@"./domus_tdd_api_plugin_aid/tests/data/aml/aml_example.xml" http://localhost:5000/aas

```

## New routes

- `/aas` : POST an anonymous TD
- `/aas` : POST to create an anonymous Asset Administration Shell Object
- `/aas/<ID>` : PUT, DELETE, GET

Accepted mime-types:

- `application/aml+xml`: for AML xml files. They will be translated into AAS objects (AmlBasedSubmodel)
- `application/aas+json` or `application/json`: a JSON AAS file
- RDF mimetypes (`application/rdf+xml`, `text/turtle`, `text/n3`, `application/n-quads`, `application/n-triples`,`application/trig`, `application/ld+json`): a RDF representation in the format corresponding to the mimetype of the AAS object. Using the AAS ontology.

## Data sources

- td-context.ttl: in the transformation, the AID requires short names that
Expand Down
15 changes: 14 additions & 1 deletion domus_tdd_api_plugin_aid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
put_aas_rdf_in_sparql,
validate_aas,
)
from domus_tdd_api_plugin_aid.aml import translate_aml_to_aas

blueprint = Blueprint("domus_tdd_api_plugin_aid", __name__, url_prefix="/aas")

Expand Down Expand Up @@ -50,9 +51,15 @@ def create_aas(id):
json_ld_content = request.get_data()
content = validate_aas(json_ld_content, uri=id)
updated, uri = put_aas_json_in_sparql(content, uri=id)
elif mimetype == "application/aml+xml":
aml_data = request.get_data()
uri, rdf_aas_data = translate_aml_to_aas(aml_data, uri=id)
updated, uri = put_aas_rdf_in_sparql(
rdf_aas_data, "application/n-triples", uri=uri
)
elif mimetype in POSSIBLE_MIMETYPES:
rdf_content = request.get_data()
updated, uri = put_aas_rdf_in_sparql(rdf_content, mimetype)
updated, uri = put_aas_rdf_in_sparql(rdf_content, mimetype, uri=id)
else:
raise WrongMimeType(mimetype)

Expand All @@ -69,6 +76,12 @@ def create_anonymous_aas():
json_ld_content = request.get_data()
content = validate_aas(json_ld_content)
updated, uri = put_aas_json_in_sparql(content, delete_if_exists=False)
elif mimetype == "application/aml+xml":
aml_data = request.get_data()
uri, rdf_aas_data = translate_aml_to_aas(aml_data)
updated, uri = put_aas_rdf_in_sparql(
rdf_aas_data, "application/n-triples", uri=uri
)
elif mimetype in POSSIBLE_MIMETYPES:
content = request.get_data()
updated, uri = put_aas_rdf_in_sparql(content, mimetype, delete_if_exists=False)
Expand Down
Loading
Loading