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 generator script #88

Merged
merged 2 commits into from
Mar 2, 2023
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
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/bamm-cli-*.jar
/Start.txt

.DS_Store

.BAMMCLI
.idea
.ttl-artifacts
static

*-artifacts/

69 changes: 69 additions & 0 deletions generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#! /bin/sh
#######################################################################
# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH
# Copyright (c) 2023 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This work is made available under the terms of the
# Creative Commons Attribution 4.0 International (CC-BY-4.0) license,
# which is available at
# https://creativecommons.org/licenses/by/4.0/legalcode.
#
# SPDX-License-Identifier: CC-BY-4.0
#######################################################################


# REMARKS:
# ========
# This script generates a set of artifacts for a given SAMM model in a ttl-file.
# Preconditiions:
# -internet connection to download specified SAMM CLI provided in $SAMMCLI folder and Catena-X CSS style

# Usage:
# Apply script to a single file
# ./generate.sh io.catenax.vehicle.product_description/2.0.0/ProductDescription.ttl
# To generate files for all models in repo
# find ./ -type f -name "*.ttl" -exec ./generate.sh "{}" \;



# Adjust if SAMM CLI version changes
JARNAME=bamm-cli-2.1.3.jar
SAMMFOLDER=.SAMMCLI/
SAMMCLI=$SAMMFOLDER$JARNAME
# Adjust if BAMM CLI version changes
SAMMCLIURL=https://github.com/eclipse-esmf/esmf-sdk/releases/download/v2.1.3/bamm-cli-2.1.3.jar

CATENAXCSS=$SAMMFOLDER/catena-template.css
CATENAXCUSTOMCSSURL=https://raw.githubusercontent.com/eclipse-tractusx/sldt-semantic-hub/main/backend/src/main/resources/catena-template.css

echo "Check availability of SAMM CLI"
if [ ! -f "$SAMMCLI" ]; then
echo "$SAMMCLI does not exist. Will download"
mkdir $SAMMFOLDER

cd $SAMMFOLDER && { curl -LJO $SAMMCLIURL ; cd -; }
fi

if [ ! -f "$CATENAXCSS" ]; then
echo "$CATENAXCSS does not exist. Will download"
mkdir $SAMMFOLDER

cd $SAMMFOLDER && { curl -LJO $CATENAXCUSTOMCSSURL ; cd -; }
fi

echo "Generate artifacts for $1"
MODELNAME="$(basename $1 .ttl)"
DIR="$(dirname "$1")"
PATHTEMPLATE=$DIR"/gen/"$MODELNAME

commands=(aas schema json openapi html)
endings=(-aas.json -schema.json .json .yml .html)
toggles=("-f json" "" "" " -b=catenax.io" "-c $CATENAXCSS")

for i in ${!commands[@]}; do
echo "generate ${commands[$i]} into $PATHTEMPLATE${endings[$i]}"
java -jar $SAMMCLI aspect "$1" to ${commands[$i]} ${toggles[$i]} -o $PATHTEMPLATE${endings[$i]}
done