diff --git a/README.md b/README.md index de68eb30..26f1dad3 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@ the document 'Details of the Asset Administration Shell', published on You can build the project using Maven by simply executing at the repository root: -`mvn clean install` +`mvn clean package` -or by integrating the respective modules as dependencies, for instance: +or by integrating the respective modules as dependencies from Maven Central Repository, for instance: ``` @@ -23,7 +23,6 @@ or by integrating the respective modules as dependencies, for instance: latest-version ``` -> **_NOTE:_** The library is yet not available as dependency but will be deployed via Maven Central in the future. # Project Structure @@ -45,21 +44,21 @@ We always look for contributions, bug reports, feature requests etc. Simply open # Contributors -| Name | Affiliation | Github Account | parent | core | aasx | json | xml | json-ld | validator| ---- | --- | --- | :---: | :---: | :---: | :---: | :---: | :---: | :---: +| Name | Affiliation | Github Account | parent | core | aasx | json | xml | json-ld | ua-nodeset | validator| +--- | --- | --- | :---: | :---: | :---: | :---: | :---: | :---: | :---:| :---: | Mohammad Alreeni | Fraunhofer IWU | []() | | | | | x | | | -| Sebastian Bader | Fraunhofer IAIS | [sebbader](https://github.com/sebbader) | x | | | | | x | x | -| Matthias Böckmann | Fraunhofer IAIS | [maboeckmann](https://github.com/maboeckmann) | x | | | | | x | x | -| Maximilian Conradi | Fraunhofer IESE | []() | | | x | | x | | | -| Helge Dickel | SAP SE | [heldic](https://github.com/heldic) | x | | | x | x | | | -| Daniel Espen | Fraunhofer IESE | [daespen](https://github.com/daespen) | | x | x | x | x | | | -| Michael Jacoby | Fraunhofer IOSB| [mjacoby](https://github.com/mjacoby) | x | x | | x | x | | | -| Jens Müller | Fraunhofer IOSB | [JensMueller2709](https://github.com/JensMueller2709) | | | | x | | | | -| Orthodoxos Kipouridis | SAP SE | [akiskips](https://github.com/akiskips) | x | | | x | x | | | -| Bastian Rössl | Fraunhofer IOSB-INA | [br-iosb](https://github.com/br-iosb) | | | | x | | | | -| Frank Schnicke | Fraunhofer IESE | [frankschnicke](https://github.com/frankschnicke) | | | x | | x | | | -| Manuel Sauer | SAP SE | [Manu3756](https://github.com/Manu3756) | x | | | | | | | -| Arno Weiss | Fraunhofer IWU | [alw-iwu](https://github.com/alw-iwu) | | | | x | | | | +| Sebastian Bader | Fraunhofer IAIS | [sebbader](https://github.com/sebbader) | x | | | | | x | | x | +| Matthias Böckmann | Fraunhofer IAIS | [maboeckmann](https://github.com/maboeckmann) | x | | | | | x | | x | +| Maximilian Conradi | Fraunhofer IESE | []() | | | x | | x | | | | +| Helge Dickel | SAP SE | [heldic](https://github.com/heldic) | x | | | x | x | | | | +| Daniel Espen | Fraunhofer IESE | [daespen](https://github.com/daespen) | | x | x | x | x | | | | +| Michael Jacoby | Fraunhofer IOSB| [mjacoby](https://github.com/mjacoby) | x | x | | x | x | | | | +| Jens Müller | Fraunhofer IOSB | [JensMueller2709](https://github.com/JensMueller2709) | | | | x | | | | | +| Orthodoxos Kipouridis | SAP SE | [akiskips](https://github.com/akiskips) | x | | | x | x | | | | +| Bastian Rössl | Fraunhofer IOSB-INA | [br-iosb](https://github.com/br-iosb) | | | | x | | | x | | +| Frank Schnicke | Fraunhofer IESE | [frankschnicke](https://github.com/frankschnicke) | | | x | | x | | | | +| Manuel Sauer | SAP SE | [Manu3756](https://github.com/Manu3756) | x | | | | | | | | +| Arno Weiss | Fraunhofer IWU | [alw-iwu](https://github.com/alw-iwu) | | | | x | | | x | | This project was initiated by SAP and Fraunhofer to provide a foundation for the AAS development and to foster its dissemination. diff --git a/dataformat-uanodeset/pom.xml b/dataformat-uanodeset/pom.xml index 5113b6be..8b3ad46a 100644 --- a/dataformat-uanodeset/pom.xml +++ b/dataformat-uanodeset/pom.xml @@ -60,8 +60,8 @@ maven-compiler-plugin 3.8.1 - 11 - 11 + ${maven.compiler.source} + ${maven.compiler.target} @@ -132,7 +132,7 @@ maven-javadoc-plugin - com.kscs.util.*:org.opcfoundation.*:io.adminshell.aas.v3.dataformat.i4aas.mappers:io.adminshell.aas.v3.dataformat.i4aas.mappers.* + com.kscs.util.*:org.opcfoundation.*:io.adminshell.aas.v3.dataformat.i4aas.mappers:io.adminshell.aas.v3.dataformat.i4aas.mappers.*:io.adminshell.aas.v3.dataformat.i4aas.parsers diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/I4AASDeserializer.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/I4AASDeserializer.java index fa2d2e40..73274876 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/I4AASDeserializer.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/I4AASDeserializer.java @@ -15,8 +15,14 @@ */ package io.adminshell.aas.v3.dataformat.i4aas; +import javax.xml.bind.JAXBException; + +import org.opcfoundation.ua._2011._03.uanodeset.UANodeSet; + import io.adminshell.aas.v3.dataformat.DeserializationException; import io.adminshell.aas.v3.dataformat.Deserializer; +import io.adminshell.aas.v3.dataformat.i4aas.parsers.EnvironmentParser; +import io.adminshell.aas.v3.dataformat.i4aas.parsers.ParserContext; import io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment; /** @@ -29,8 +35,15 @@ public class I4AASDeserializer implements Deserializer { * reads a I4AAS as string and return the model object */ @Override - public AssetAdministrationShellEnvironment read(String value) throws DeserializationException { - throw new UnsupportedOperationException("Not Implemented yet."); + public AssetAdministrationShellEnvironment read(String input) throws DeserializationException { + try { + UANodeSet unmarshall = new UANodeSetUnmarshaller().unmarshall(input); + ParserContext parserContext = new ParserContext(unmarshall); + AssetAdministrationShellEnvironment parsedEnvironment = new EnvironmentParser(parserContext.getEnvironment(), parserContext).parse(); + return parsedEnvironment; + } catch (JAXBException e) { + throw new DeserializationException("Deserialization failed on unmarshalling.", e); + } } @Override diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/I4AASSerializer.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/I4AASSerializer.java index 26bc48c5..367acbd8 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/I4AASSerializer.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/I4AASSerializer.java @@ -16,6 +16,7 @@ package io.adminshell.aas.v3.dataformat.i4aas; import javax.xml.bind.JAXBException; + import org.opcfoundation.ua._2011._03.uanodeset.UANodeSet; import org.opcfoundation.ua._2011._03.uanodeset.UAObject; @@ -30,6 +31,22 @@ * */ public class I4AASSerializer implements Serializer { + + private boolean addMissingSemanticIdsToDictionary; + + /** + * I4AASSerializer with addMissingSemanticIdsToDictionary defaults to true + */ + public I4AASSerializer() { + this(true); + } + + /** + * @param addMissingSemanticIdsToDictionary handles missing semanticIds in OPC UA Dictionary (caused by missing AAS Concept Description) by adding them automatically + */ + public I4AASSerializer(boolean addMissingSemanticIdsToDictionary) { + this.addMissingSemanticIdsToDictionary = addMissingSemanticIdsToDictionary; + } /** * takes a AAS model and returns a I4AAS as string. @@ -37,8 +54,8 @@ public class I4AASSerializer implements Serializer { @Override public String write(AssetAdministrationShellEnvironment aasEnvironment) throws SerializationException { MappingContext mappingContext = new MappingContext(aasEnvironment); + mappingContext.setAddMissingSemanticIdsToDictionary(addMissingSemanticIdsToDictionary); UAObject uaEnv = new EnvironmentMapper(mappingContext.getEnvironment(), mappingContext).map(); - //map action UANodeSet nodeset = mappingContext.getNodeSet(); diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/UANodeSetUnmarshaller.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/UANodeSetUnmarshaller.java index 32bbb518..784acfaf 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/UANodeSetUnmarshaller.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/UANodeSetUnmarshaller.java @@ -17,11 +17,9 @@ import java.io.InputStream; import java.io.StringReader; -import java.io.StringWriter; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; import org.opcfoundation.ua._2008._02.types.ListOfExtensionObject; diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/AdministrationMapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/AdministrationMapper.java index eabc9d1b..ac1261e1 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/AdministrationMapper.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/AdministrationMapper.java @@ -18,7 +18,6 @@ import org.opcfoundation.ua._2011._03.uanodeset.UAObject; import org.opcfoundation.ua._2011._03.uanodeset.UAVariable; -import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASUtils; import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; import io.adminshell.aas.v3.model.AdministrativeInformation; @@ -32,8 +31,8 @@ public AdministrationMapper(AdministrativeInformation src, MappingContext ctx) { @Override protected UAObject createTargetObject() { target = UAObject.builder().withNodeId(ctx.newModelNodeIdAsString()) - .withBrowseName(createI4AASBrowseName("Administration")) - .withDisplayName(createLocalizedText("Administration")).build(); + .withBrowseName(createI4AASBrowseName(ADMINISTRATION_BROWSENAME)) + .withDisplayName(createLocalizedText(ADMINISTRATION_BROWSENAME)).build(); addTypeReference(I4AASIdentifier.AASAdministrativeInformationType); return target; } @@ -43,13 +42,13 @@ protected void mapAndAttachChildren() { if (source != null) { String revision = source.getRevision(); if (revision != null) { - UAVariable revisionStringProperty = new StringPropertyMapper("Revision", revision, ctx, + UAVariable revisionStringProperty = new StringPropertyMapper(ADMINISTRATION_REVISION_BROWSENAME, revision, ctx, ctx.getI4aasNsIndex()).map(); attachAsProperty(target, revisionStringProperty); } String version = source.getVersion(); if (version != null) { - UAVariable versionStringProperty = new StringPropertyMapper("Version", version, ctx, + UAVariable versionStringProperty = new StringPropertyMapper(ADMINISTRATION_VERSION_BROWSENAME, version, ctx, ctx.getI4aasNsIndex()).map(); attachAsProperty(target, versionStringProperty); } diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/AssetAdministrationShellMapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/AssetAdministrationShellMapper.java index 99783e44..1f131195 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/AssetAdministrationShellMapper.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/AssetAdministrationShellMapper.java @@ -18,12 +18,10 @@ import java.util.List; import org.opcfoundation.ua._2011._03.uanodeset.UAObject; + import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; import io.adminshell.aas.v3.model.AssetAdministrationShell; import io.adminshell.aas.v3.model.AssetInformation; -import io.adminshell.aas.v3.model.DataTypeIEC61360; -import io.adminshell.aas.v3.model.HasDataSpecification; -import io.adminshell.aas.v3.model.Submodel; public class AssetAdministrationShellMapper extends IdentifiableMapper implements HasDataSpecificationMapper { @@ -49,17 +47,19 @@ protected void mapAndAttachChildren() { private void mapAsset() { AssetInformation assetInformation = source.getAssetInformation(); - UAObject uaAsset = new AssetInformationMapper(assetInformation, ctx).map(); - attachAsComponent(target, uaAsset); + if (assetInformation != null) { + UAObject uaAsset = new AssetInformationMapper(assetInformation, ctx).map(); + attachAsComponent(target, uaAsset); + } } private void mapSubmodels() { - UAObject smFolder = createReferenceList("Submodel"); + UAObject smFolder = createReferenceList(AAS_SUBMODELREFERENCES_LIST_BROWSENAME); List submodels = source.getSubmodels(); for (int i = 0; i < submodels.size(); i++) { io.adminshell.aas.v3.model.Reference reference = submodels.get(i); UAObject createSubmodelReferenceUaObject = new ReferenceMapper(reference, ctx, - "Submodel:" + reference.getKeys().get(0).getValue()).map(); + SM_DISPLAYNAME_PREFIX + reference.getKeys().get(0).getValue()).map(); attachAsComponent(smFolder, createSubmodelReferenceUaObject); } } @@ -67,7 +67,7 @@ private void mapSubmodels() { private void mapDerivedFrom() { io.adminshell.aas.v3.model.Reference derivedFrom = source.getDerivedFrom(); if (derivedFrom != null) { - UAObject uaDerivedFrom = new ReferenceMapper(derivedFrom, ctx, "DerivedFrom").map(); + UAObject uaDerivedFrom = new ReferenceMapper(derivedFrom, ctx, AAS_DERIVEDFROM_BROWSENAME).map(); attachAsComponent(target, uaDerivedFrom); } } diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/AssetInformationMapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/AssetInformationMapper.java index cf9f74c3..610030db 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/AssetInformationMapper.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/AssetInformationMapper.java @@ -21,9 +21,7 @@ import org.opcfoundation.ua._2011._03.uanodeset.UAVariable; import io.adminshell.aas.v3.dataformat.i4aas.mappers.sme.FileMapper; -import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASUtils; import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; -import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.UaIdentifier; import io.adminshell.aas.v3.model.AssetInformation; import io.adminshell.aas.v3.model.AssetKind; import io.adminshell.aas.v3.model.File; @@ -39,8 +37,8 @@ public AssetInformationMapper(AssetInformation src, MappingContext ctx) { @Override protected UAObject createTargetObject() { target = UAObject.builder().withNodeId(ctx.newModelNodeIdAsString()) - .withBrowseName(createI4AASBrowseName("AssetInformation")) - .withDisplayName(createLocalizedText("AssetInformation")).build(); + .withBrowseName(createI4AASBrowseName(AAS_ASSETINFORMATION_BROWSENAME)) + .withDisplayName(createLocalizedText(AAS_ASSETINFORMATION_BROWSENAME)).build(); addTypeReference(I4AASIdentifier.AASAssetInformationType); return target; } @@ -53,26 +51,26 @@ protected void mapAndAttachChildren() { Reference globalAssetId = source.getGlobalAssetId(); if (globalAssetId != null) { - UAObject uaIdentification = new ReferenceMapper(globalAssetId, ctx, "GlobalAssetId").map(); + UAObject uaIdentification = new ReferenceMapper(globalAssetId, ctx, ASSETINFO_GLOBAL_ASSET_ID_BROWSENAME).map(); attachAsComponent(target, uaIdentification); } - UAObject uaBomList = createReferenceList("BillOfMaterial"); + UAObject uaBomList = createReferenceList(ASSETINFO_BILL_OF_MATERIAL_BROWSENAME); List billOfMaterials = source.getBillOfMaterials(); for (int i = 0; i < billOfMaterials.size(); i++) { Reference reference = billOfMaterials.get(i); - UAObject uaBomListEntry = new ReferenceMapper(reference, ctx, "BillOfMaterial_" + i).map(); + UAObject uaBomListEntry = new ReferenceMapper(reference, ctx, ASSETINFO_BILL_OF_MATERIAL_BROWSENAME + "_" + i).map(); attachAsComponent(uaBomList, uaBomListEntry); } File defaultThumbnail = source.getDefaultThumbnail(); if (defaultThumbnail != null) { - UAObject uaThumbnail = new FileMapper(defaultThumbnail, ctx, "DefaultThumbnail", ctx.getI4aasNsIndex()) + UAObject uaThumbnail = new FileMapper(defaultThumbnail, ctx, ASSETINFO_DEFAULT_THUMBNAIL_BROWSENAME, ctx.getI4aasNsIndex()) .map(); attachAsComponent(target, uaThumbnail); } - UAObject folder = createIdentifierKeyValuePairList("SpecificAssetId"); + UAObject folder = createIdentifierKeyValuePairList(ASSETINFO_SPECIFIC_ASSET_ID_BROWSENAME); for (IdentifierKeyValuePair identifierKeyValuePair : source.getSpecificAssetIds()) { UAObject uaIdKVP = new IdentifierKeyValuePairMapper(identifierKeyValuePair, ctx).map(); attachAsComponent(folder, uaIdKVP); diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/BooleanPropertyMapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/BooleanPropertyMapper.java index 19e8320a..a11e0503 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/BooleanPropertyMapper.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/BooleanPropertyMapper.java @@ -20,7 +20,6 @@ import org.opcfoundation.ua._2008._02.types.ObjectFactory; import org.opcfoundation.ua._2011._03.uanodeset.UAVariable; -import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASUtils; import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.UaIdentifier; public class BooleanPropertyMapper extends I4AASMapper { diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/ConceptDescriptionMapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/ConceptDescriptionMapper.java index 31f82481..6411d5c5 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/ConceptDescriptionMapper.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/ConceptDescriptionMapper.java @@ -19,6 +19,7 @@ import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; import io.adminshell.aas.v3.model.ConceptDescription; +import io.adminshell.aas.v3.model.Identifier; import io.adminshell.aas.v3.model.IdentifierType; import io.adminshell.aas.v3.model.Reference; @@ -32,14 +33,22 @@ public ConceptDescriptionMapper(ConceptDescription src, MappingContext ctx) { protected UAObject createTargetObject() { target = super.createTargetObject(); - IdentifierType idType = source.getIdentification().getIdType(); - if (IdentifierType.IRI == idType) { - addTypeReference(I4AASIdentifier.AASIriConceptDescriptionType); - } else if (IdentifierType.IRDI == idType) { - addTypeReference(I4AASIdentifier.AASIrdiConceptDescriptionType); - } else if (IdentifierType.CUSTOM == idType) { - addTypeReference(I4AASIdentifier.AASCustomConceptDescriptionType); + Identifier identification = source.getIdentification(); + if (identification != null) { + IdentifierType idType = identification.getIdType(); + if (IdentifierType.IRI == idType) { + addTypeReference(I4AASIdentifier.AASIriConceptDescriptionType); + } else if (IdentifierType.IRDI == idType) { + addTypeReference(I4AASIdentifier.AASIrdiConceptDescriptionType); + } else if (IdentifierType.CUSTOM == idType) { + addTypeReference(I4AASIdentifier.AASCustomConceptDescriptionType); + } + if (identification.getIdentifier() != null) { + //conflict: I4AAS says idshort, OPC UA says value + target.setBrowseName(createModelBrowseName(identification.getIdentifier())); + } } + return target; } diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/DataSpecificationIEC61360Mapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/DataSpecificationIEC61360Mapper.java index adaef749..7c6cfce1 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/DataSpecificationIEC61360Mapper.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/DataSpecificationIEC61360Mapper.java @@ -18,7 +18,6 @@ import org.opcfoundation.ua._2011._03.uanodeset.UAObject; import org.opcfoundation.ua._2011._03.uanodeset.UAVariable; -import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASUtils; import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; import io.adminshell.aas.v3.model.DataSpecificationIEC61360; import io.adminshell.aas.v3.model.DataTypeIEC61360; @@ -47,7 +46,7 @@ protected UAObject createTargetObject() { @Override protected void mapAndAttachChildren() { - + DataTypeIEC61360 dataType = source.getDataType(); if (dataType != null) { UAVariable uaDataType = new I4AASEnumMapper(dataType, ctx).map(); @@ -56,53 +55,53 @@ protected void mapAndAttachChildren() { String sourceOfDefinition = source.getSourceOfDefinition(); if (sourceOfDefinition != null) { - UAVariable uaVariable = new StringPropertyMapper("SourceOfDefinition", sourceOfDefinition, ctx, ctx.getI4aasNsIndex()).map(); + UAVariable uaVariable = new StringPropertyMapper(IEC61360_SOURCE_OF_DEFINITION_BROWSENAME, sourceOfDefinition, ctx, ctx.getI4aasNsIndex()).map(); attachAsProperty(target, uaVariable); } String symbol = source.getSymbol(); if (symbol != null) { - UAVariable uaVariable = new StringPropertyMapper("Symbol", symbol, ctx, ctx.getI4aasNsIndex()).map(); + UAVariable uaVariable = new StringPropertyMapper(IEC61360_SYMBOL_BROWSENAME, symbol, ctx, ctx.getI4aasNsIndex()).map(); attachAsProperty(target, uaVariable); } String unit = source.getUnit(); if (unit != null) { - UAVariable uaVariable = new StringPropertyMapper("Unit", unit, ctx, ctx.getI4aasNsIndex()).map(); + UAVariable uaVariable = new StringPropertyMapper(IEC61360_UNIT_BROWSENAME, unit, ctx, ctx.getI4aasNsIndex()).map(); attachAsProperty(target, uaVariable); } String valueFormat = source.getValueFormat(); if (valueFormat != null) { - UAVariable uaVariable = new StringPropertyMapper("ValueFormat", valueFormat, ctx, ctx.getI4aasNsIndex()).map(); + UAVariable uaVariable = new StringPropertyMapper(IEC61360_VALUE_FORMAT_BROWSENAME, valueFormat, ctx, ctx.getI4aasNsIndex()).map(); attachAsProperty(target, uaVariable); } String value = source.getValue(); if (value != null) { - UAVariable uaVariable = new StringPropertyMapper("Value", value, ctx, ctx.getI4aasNsIndex()).map(); + UAVariable uaVariable = new StringPropertyMapper(IEC61360_VALUE_BROWSENAME, value, ctx, ctx.getI4aasNsIndex()).map(); attachAsProperty(target, uaVariable); } Reference unitId = source.getUnitId(); if (unitId != null) { - UAObject uaRef = new ReferenceMapper(unitId, ctx, "UnitId").map(); + UAObject uaRef = new ReferenceMapper(unitId, ctx, IEC61360_UNIT_ID_BROWSENAME).map(); attachAsComponent(target, uaRef); } Reference valueId = source.getValueId(); if (valueId != null) { - UAObject uaRef = new ReferenceMapper(valueId, ctx, "ValueId").map(); + UAObject uaRef = new ReferenceMapper(valueId, ctx, IEC61360_VALUE_ID_BROWSENAME).map(); attachAsComponent(target, uaRef); } - UAVariable uaDefinition = new LangStringPropertyMapper("Definition", source.getDefinitions(), ctx, ctx.getI4aasNsIndex()).map(); + UAVariable uaDefinition = new LangStringPropertyMapper(IEC61360_DEFINITION_BROWSENAME, source.getDefinitions(), ctx, ctx.getI4aasNsIndex()).map(); attachAsProperty(target, uaDefinition); - UAVariable uaPreferredNames = new LangStringPropertyMapper("PreferredName", source.getPreferredNames(), ctx, ctx.getI4aasNsIndex()).map(); + UAVariable uaPreferredNames = new LangStringPropertyMapper(IEC61360_PREFERRED_NAME_BROWSENAME, source.getPreferredNames(), ctx, ctx.getI4aasNsIndex()).map(); attachAsProperty(target, uaPreferredNames); - UAVariable uaShortName = new LangStringPropertyMapper("ShortName", source.getShortNames(), ctx, ctx.getI4aasNsIndex()).map(); + UAVariable uaShortName = new LangStringPropertyMapper(IEC61360_SHORT_NAME_BROWSENAME, source.getShortNames(), ctx, ctx.getI4aasNsIndex()).map(); attachAsProperty(target, uaShortName); } diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/EnvironmentMapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/EnvironmentMapper.java index 6b8a9380..5509d8ba 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/EnvironmentMapper.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/EnvironmentMapper.java @@ -17,11 +17,8 @@ import org.opcfoundation.ua._2011._03.uanodeset.ListOfReferences; import org.opcfoundation.ua._2011._03.uanodeset.Reference; -import org.opcfoundation.ua._2011._03.uanodeset.UANodeSet; import org.opcfoundation.ua._2011._03.uanodeset.UAObject; -import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASConstants; -import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASUtils; import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.UaIdentifier; import io.adminshell.aas.v3.model.AssetAdministrationShell; diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/HasDataSpecificationMapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/HasDataSpecificationMapper.java index 6eb19c2a..368b7506 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/HasDataSpecificationMapper.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/HasDataSpecificationMapper.java @@ -17,11 +17,10 @@ import java.util.List; -import org.opcfoundation.ua._2011._03.uanodeset.ListOfReferences; import org.opcfoundation.ua._2011._03.uanodeset.UAObject; +import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASConstants; import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; -import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.UaIdentifier; import io.adminshell.aas.v3.model.DataSpecificationContent; import io.adminshell.aas.v3.model.DataSpecificationIEC61360; import io.adminshell.aas.v3.model.EmbeddedDataSpecification; @@ -32,23 +31,26 @@ public interface HasDataSpecificationMapper { public default void mapDataSpecification(HasDataSpecification source, UAObject target, MappingContext ctx) { - UAObject folder = I4AASMapper.createFolder(target, "DataSpecification", ctx, I4AASIdentifier.AASReferenceList); + UAObject folder = I4AASMapper.createFolder(target, I4AASConstants.DATASPECIFICATION_BROWSENAME, ctx, + I4AASIdentifier.AASReferenceList); List embeddedDataSpecifications = source.getEmbeddedDataSpecifications(); for (int i = 0; i < embeddedDataSpecifications.size(); i++) { EmbeddedDataSpecification embeddedDataSpecification = embeddedDataSpecifications.get(i); Reference dataSpecification = embeddedDataSpecification.getDataSpecification(); + // TODO The embedding is not uniquely bound to the reference. Naming convention + // fixes this partially, but a wrapper object should be specified in I4AAS. if (dataSpecification != null) { - String dataSpecKey = dataSpecification.getKeys().get(0).getValue(); - UAObject uaObject = new ReferenceMapper(dataSpecification, ctx, dataSpecKey).map(); + UAObject uaObject = new ReferenceMapper(dataSpecification, ctx, "Reference_" + i).map(); I4AASMapper.attachAsComponent(folder, uaObject); } DataSpecificationContent dataSpecificationContent = embeddedDataSpecification.getDataSpecificationContent(); if (dataSpecificationContent instanceof DataSpecificationIEC61360) { UAObject uaIEC61360 = new DataSpecificationIEC61360Mapper( - (DataSpecificationIEC61360) dataSpecificationContent, ctx, "embedded_" + i, ctx.getModelNsIndex()).map(); + (DataSpecificationIEC61360) dataSpecificationContent, ctx, "Content_" + i, + ctx.getModelNsIndex()).map(); I4AASMapper.attachAsComponent(folder, uaIEC61360); } } diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/HasKindMapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/HasKindMapper.java index ecb093ec..ce7a2d41 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/HasKindMapper.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/HasKindMapper.java @@ -20,7 +20,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import io.adminshell.aas.v3.dataformat.core.serialization.EmbeddedDataSpecificationSerializer; import io.adminshell.aas.v3.model.HasKind; import io.adminshell.aas.v3.model.ModelingKind; diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/HasSemanticsMapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/HasSemanticsMapper.java index f9aee40d..04b6e2a0 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/HasSemanticsMapper.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/HasSemanticsMapper.java @@ -35,7 +35,11 @@ default void mapSemantics(HasSemantics source, UAObject target, MappingContext c Key key = semanticId.getKeys().get(0); if (nodeForIdentification == null && key.getValue() != null && !key.getValue().isBlank()) { - nodeForIdentification = fixConceptDescription(ctx, key); + if (ctx.isAddMissingSemanticIdsToDictionary()) { + nodeForIdentification = fixConceptDescription(ctx, key); + } else { + return; + } } if (nodeForIdentification != null) { diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/I4AASEnumMapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/I4AASEnumMapper.java index 469950ef..e748b07c 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/I4AASEnumMapper.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/I4AASEnumMapper.java @@ -18,11 +18,12 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; + import javax.xml.bind.JAXBElement; import org.opcfoundation.ua._2008._02.types.ObjectFactory; import org.opcfoundation.ua._2011._03.uanodeset.UAVariable; -import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASUtils; + import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.UaIdentifier; public class I4AASEnumMapper extends I4AASMapper, UAVariable> { @@ -82,13 +83,15 @@ protected UAVariable createTargetObject() { protected String deriveDefaultName() { if (source instanceof io.adminshell.aas.v3.model.IdentifierType) { - return "IdType"; + return IDENTIFICATION_IDTYPE_BROWSENAME; } return source.getClass().getSimpleName(); } public static Enum findMatch(Enum src) { - + if (src == null) { + return null; + } if (!enum2enumMap.containsKey(src.getClass())) { throw new IllegalArgumentException("Class " + src.getClass() + " is not supported by I4AASEnumMapper"); } diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/I4AASMapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/I4AASMapper.java index d8b00690..cbce55c3 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/I4AASMapper.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/I4AASMapper.java @@ -22,8 +22,9 @@ import org.opcfoundation.ua._2011._03.uanodeset.UANode; import org.opcfoundation.ua._2011._03.uanodeset.UAObject; import org.opcfoundation.ua._2011._03.uanodeset.UAVariable; + import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.BasicIdentifier; -import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASUtils; +import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASConstants; import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.UaIdentifier; import io.adminshell.aas.v3.model.LangString; @@ -34,7 +35,7 @@ * @param mapping source * @param mapping target */ -public abstract class I4AASMapper { +public abstract class I4AASMapper implements I4AASConstants{ protected MappingContext ctx; protected SOURCE source; @@ -175,8 +176,8 @@ protected static final void attachAsComponent(UAObject parent, UAObject child) { protected static final void attachAsOrderedComponent(UAObject parent, UAObject child) { child.setParentNodeId(parent.getNodeId()); attachAsType(parent, child, UaIdentifier.HasOrderedComponent); - } + protected static final void attachAsDictionaryEntry(UAObject parent, UAObject child) { attachAsType(parent, child, UaIdentifier.HasDictionaryEntry); } diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/IdentifiableMapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/IdentifiableMapper.java index 65ee049d..33cdc713 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/IdentifiableMapper.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/IdentifiableMapper.java @@ -16,12 +16,12 @@ package io.adminshell.aas.v3.dataformat.i4aas.mappers; import org.opcfoundation.ua._2011._03.uanodeset.UAObject; -import org.opcfoundation.ua._2011._03.uanodeset.UAVariable; import org.opcfoundation.ua._2011._03.uanodeset.UAObject.Builder; +import org.opcfoundation.ua._2011._03.uanodeset.UAVariable; -import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASUtils; import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; import io.adminshell.aas.v3.model.Identifiable; +import io.adminshell.aas.v3.model.Identifier; import io.adminshell.aas.v3.model.IdentifierType; public class IdentifiableMapper extends ReferableMapper { @@ -43,23 +43,24 @@ protected void mapAndAttachChildren() { } private void mapIdentification() { - IdentifierType sourceIdType = source.getIdentification().getIdType(); - String sourceIdentifierValue = source.getIdentification().getIdentifier(); - Builder coreUAObject = UAObject.builder().withNodeId(ctx.newModelNodeIdAsString()) - .withDisplayName(createLocalizedText("Identification")) - .withBrowseName(createI4AASBrowseName("Identification")); + .withDisplayName(createLocalizedText(IDENTIFICATION_BROWSENAME)) + .withBrowseName(createI4AASBrowseName(IDENTIFICATION_BROWSENAME)); UAObject uaObject = coreUAObject.build(); addTypeReferenceFor(uaObject, I4AASIdentifier.AASIdentifierType); addToNodeset(uaObject); attachAsComponent(target, uaObject); - UAVariable targetIdVar = new StringPropertyMapper("Id", sourceIdentifierValue, ctx, ctx.getI4aasNsIndex()) - .map(); - attachAsProperty(uaObject, targetIdVar); - - UAVariable mappedEnum = new I4AASEnumMapper(sourceIdType, ctx).map(); - attachAsProperty(uaObject, mappedEnum); + Identifier identification = source.getIdentification(); + if (identification != null) { + IdentifierType sourceIdType = identification.getIdType(); + String sourceIdentifierValue = identification.getIdentifier(); + UAVariable targetIdVar = new StringPropertyMapper(IDENTIFICATION_ID_BROWSENAME, sourceIdentifierValue, ctx, + ctx.getI4aasNsIndex()).map(); + attachAsProperty(uaObject, targetIdVar); + UAVariable mappedEnum = new I4AASEnumMapper(sourceIdType, ctx).map(); + attachAsProperty(uaObject, mappedEnum); + } ctx.addIdentifierUaObject(source.getIdentification(), target); } diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/IdentifierKeyValuePairMapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/IdentifierKeyValuePairMapper.java index 1720a2f4..1907d468 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/IdentifierKeyValuePairMapper.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/IdentifierKeyValuePairMapper.java @@ -18,7 +18,6 @@ import org.opcfoundation.ua._2011._03.uanodeset.UAObject; import org.opcfoundation.ua._2011._03.uanodeset.UAVariable; -import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASUtils; import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; import io.adminshell.aas.v3.model.IdentifierKeyValuePair; import io.adminshell.aas.v3.model.Reference; @@ -42,17 +41,17 @@ protected UAObject createTargetObject() { protected void mapAndAttachChildren() { Reference externalSubjectId = source.getExternalSubjectId(); if (externalSubjectId != null) { - UAObject uaExtSubId = new ReferenceMapper(externalSubjectId, ctx, "ExternalSubjectId").map(); + UAObject uaExtSubId = new ReferenceMapper(externalSubjectId, ctx, IKVP_EXTERNAL_SUBJECT_ID_BROWSENAME).map(); attachAsComponent(target, uaExtSubId); } String key = source.getKey(); if (key != null) { - UAVariable uaKey = new StringPropertyMapper("Key", key, ctx, ctx.getI4aasNsIndex()).map(); + UAVariable uaKey = new StringPropertyMapper(IKVP_KEY_BROWSENAME, key, ctx, ctx.getI4aasNsIndex()).map(); attachAsProperty(target, uaKey); } String value = source.getValue(); if (value != null) { - UAVariable uaValue = new StringPropertyMapper("Value", value, ctx, ctx.getI4aasNsIndex()).map(); + UAVariable uaValue = new StringPropertyMapper(IKVP_VALUE_BROWSENAME, value, ctx, ctx.getI4aasNsIndex()).map(); attachAsProperty(target, uaValue); } } diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/LangStringPropertyMapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/LangStringPropertyMapper.java index a0b0890f..5d99b200 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/LangStringPropertyMapper.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/LangStringPropertyMapper.java @@ -23,7 +23,6 @@ import org.opcfoundation.ua._2008._02.types.ObjectFactory; import org.opcfoundation.ua._2011._03.uanodeset.UAVariable; -import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASUtils; import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.UaIdentifier; import io.adminshell.aas.v3.model.LangString; diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/MappingContext.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/MappingContext.java index 6d366a80..c59532f9 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/MappingContext.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/MappingContext.java @@ -20,7 +20,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.TreeMap; import java.util.function.Function; import javax.xml.datatype.DatatypeFactory; @@ -30,7 +29,6 @@ import org.opcfoundation.ua._2011._03.uanodeset.ModelTable; import org.opcfoundation.ua._2011._03.uanodeset.ModelTableEntry; import org.opcfoundation.ua._2011._03.uanodeset.NodeIdAlias; -import org.opcfoundation.ua._2011._03.uanodeset.UANode; import org.opcfoundation.ua._2011._03.uanodeset.UANodeSet; import org.opcfoundation.ua._2011._03.uanodeset.UAObject; import org.opcfoundation.ua._2011._03.uanodeset.UriTable; @@ -41,10 +39,7 @@ import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.UaIdentifier; import io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment; import io.adminshell.aas.v3.model.Identifier; -import io.adminshell.aas.v3.model.Key; -import io.adminshell.aas.v3.model.KeyElements; import io.adminshell.aas.v3.model.Reference; -import io.adminshell.aas.v3.model.Submodel; public class MappingContext { @@ -60,6 +55,7 @@ public class MappingContext { private int nodeIdCounter = 1; private static Function modelNamespaceNamingStrategy = I4AASUtils::generateRandomNamespace; + private boolean addMissingSemanticIdsToDictionary = true; public static void setModelNamespaceNamingStrategy(Function strategy) { modelNamespaceNamingStrategy = strategy; @@ -201,4 +197,13 @@ private boolean match(Identifier identifier, Reference reference) { } } + + public void setAddMissingSemanticIdsToDictionary(boolean addMissingSemanticIdsToDictionary) { + this.addMissingSemanticIdsToDictionary = addMissingSemanticIdsToDictionary; + } + + public boolean isAddMissingSemanticIdsToDictionary() { + return addMissingSemanticIdsToDictionary; + } + } diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/QualifiableMapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/QualifiableMapper.java index dd01bd82..92c705e4 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/QualifiableMapper.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/QualifiableMapper.java @@ -19,6 +19,7 @@ import org.opcfoundation.ua._2011._03.uanodeset.UAObject; +import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASConstants; import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; import io.adminshell.aas.v3.model.Constraint; import io.adminshell.aas.v3.model.Qualifiable; @@ -28,13 +29,13 @@ public interface QualifiableMapper { public default void mapQualifiable(Qualifiable source, UAObject target, MappingContext ctx) { - UAObject folder = I4AASMapper.createFolder(target, "Qualifier", ctx, I4AASIdentifier.AASQualifierList); + UAObject folder = I4AASMapper.createFolder(target, I4AASConstants.QUALIFIABLE_BROWSENAME, ctx, I4AASIdentifier.AASQualifierList); List qualifiers = source.getQualifiers(); for (int i = 0; i < qualifiers.size(); i++) { Constraint constraint = qualifiers.get(i); if (constraint instanceof Qualifier) { - UAObject uaQualifier = new QualifierMapper((Qualifier) constraint, ctx, "qualifier_" + i, ctx.getModelNsIndex()).map(); + UAObject uaQualifier = new QualifierMapper((Qualifier) constraint, ctx, "Qualifier_" + i, ctx.getModelNsIndex()).map(); I4AASMapper.attachAsComponent(folder, uaQualifier); } } diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/ReferableMapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/ReferableMapper.java index fdfa329e..be273039 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/ReferableMapper.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/ReferableMapper.java @@ -40,7 +40,7 @@ protected UAObject createTargetObject() { protected void mapAndAttachChildren() { String category = source.getCategory() == null ? "" : source.getCategory(); - UAVariable categoryProperty = new StringPropertyMapper("Category", category, ctx, ctx.getI4aasNsIndex()).map(); + UAVariable categoryProperty = new StringPropertyMapper(CATEGORY_BROWSENAME, category, ctx, ctx.getI4aasNsIndex()).map(); attachAsProperty(target, categoryProperty); for (LangString description : source.getDescriptions()) { diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/ReferenceMapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/ReferenceMapper.java index a0744b87..5c1090d0 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/ReferenceMapper.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/ReferenceMapper.java @@ -28,7 +28,6 @@ import org.opcfoundation.ua.i4aas.v3.types.AASKeyElementsDataType; import org.opcfoundation.ua.i4aas.v3.types.AASKeyTypeDataType; -import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASUtils; import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.UaIdentifier; import io.adminshell.aas.v3.model.Key; @@ -59,8 +58,8 @@ protected UAObject createTargetObject() { protected void mapAndAttachChildren() { UAVariable UAKeyVariable = UAVariable.builder().withNodeId(ctx.newModelNodeIdAsString()) .withDataType(I4AASIdentifier.AASKeyDataType.getName()).withValueRank(1).withArrayDimensions("0") - .withAccessLevel(3L).withDisplayName(createLocalizedText("Keys")) - .withBrowseName(createI4AASBrowseName("Keys")).build(); + .withAccessLevel(3L).withDisplayName(createLocalizedText(REFERENCE_KEYS_BROWSENAME)) + .withBrowseName(createI4AASBrowseName(REFERENCE_KEYS_BROWSENAME)).build(); addTypeReferenceFor(UAKeyVariable, UaIdentifier.PropertyType); attachAsProperty(target, UAKeyVariable); addToNodeset(UAKeyVariable); diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/StringPropertyMapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/StringPropertyMapper.java index 046d5d70..1f11a4d3 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/StringPropertyMapper.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/StringPropertyMapper.java @@ -20,7 +20,6 @@ import org.opcfoundation.ua._2008._02.types.ObjectFactory; import org.opcfoundation.ua._2011._03.uanodeset.UAVariable; -import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASUtils; import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.UaIdentifier; public class StringPropertyMapper extends I4AASMapper { diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/SubmodelMapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/SubmodelMapper.java index ed02383a..fe864bdf 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/SubmodelMapper.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/SubmodelMapper.java @@ -18,9 +18,9 @@ import java.util.List; import org.opcfoundation.ua._2011._03.uanodeset.UAObject; + import io.adminshell.aas.v3.dataformat.i4aas.mappers.sme.SubmodelElementMappers; import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; -import io.adminshell.aas.v3.model.Qualifiable; import io.adminshell.aas.v3.model.Submodel; import io.adminshell.aas.v3.model.SubmodelElement; diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/sme/BlobMapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/sme/BlobMapper.java index bb86bf09..f9a921e7 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/sme/BlobMapper.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/sme/BlobMapper.java @@ -20,7 +20,6 @@ import io.adminshell.aas.v3.dataformat.i4aas.mappers.ByteStringPropertyMapper; import io.adminshell.aas.v3.dataformat.i4aas.mappers.MappingContext; -import io.adminshell.aas.v3.dataformat.i4aas.mappers.StringPropertyMapper; import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; import io.adminshell.aas.v3.model.Blob; diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/sme/FileMapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/sme/FileMapper.java index fa73d093..f10226e1 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/sme/FileMapper.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/sme/FileMapper.java @@ -19,8 +19,6 @@ import org.opcfoundation.ua._2011._03.uanodeset.UAVariable; import io.adminshell.aas.v3.dataformat.i4aas.mappers.MappingContext; -import io.adminshell.aas.v3.dataformat.i4aas.mappers.StringPropertyMapper; -import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASUtils; import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; import io.adminshell.aas.v3.model.File; diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/sme/MimeTypeMapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/sme/MimeTypeMapper.java index b6687307..d3202c4e 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/sme/MimeTypeMapper.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/sme/MimeTypeMapper.java @@ -19,14 +19,15 @@ import org.opcfoundation.ua._2008._02.types.ObjectFactory; import org.opcfoundation.ua._2011._03.uanodeset.UAVariable; + import io.adminshell.aas.v3.dataformat.i4aas.mappers.I4AASMapper; import io.adminshell.aas.v3.dataformat.i4aas.mappers.MappingContext; -import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASUtils; import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.UaIdentifier; public class MimeTypeMapper extends I4AASMapper { + public MimeTypeMapper(String src, MappingContext ctx) { super(src, ctx); } @@ -35,9 +36,9 @@ public MimeTypeMapper(String src, MappingContext ctx) { protected UAVariable createTargetObject() { JAXBElement idStringValue = new ObjectFactory().createString(source); org.opcfoundation.ua._2011._03.uanodeset.UAVariable.Builder idVarBuilder = UAVariable.builder() - .withValue().withAny(idStringValue).end().withDisplayName(createLocalizedText("MimeType")) + .withValue().withAny(idStringValue).end().withDisplayName(createLocalizedText(MIME_TYPE_BROWSENAME)) .withDataType(I4AASIdentifier.AASMimeDataType.getName()).withNodeId(ctx.newModelNodeIdAsString()) - .withBrowseName(createI4AASBrowseName("MimeType")).withAccessLevel(3L); + .withBrowseName(createI4AASBrowseName(MIME_TYPE_BROWSENAME)).withAccessLevel(3L); target = idVarBuilder.build(); addTypeReferenceFor(target, UaIdentifier.PropertyType); return target; diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/sme/PathTypeMapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/sme/PathTypeMapper.java index a4027d76..6ff3da43 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/sme/PathTypeMapper.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/sme/PathTypeMapper.java @@ -19,9 +19,9 @@ import org.opcfoundation.ua._2008._02.types.ObjectFactory; import org.opcfoundation.ua._2011._03.uanodeset.UAVariable; + import io.adminshell.aas.v3.dataformat.i4aas.mappers.I4AASMapper; import io.adminshell.aas.v3.dataformat.i4aas.mappers.MappingContext; -import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASUtils; import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.UaIdentifier; diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/sme/ValueTypeMapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/sme/ValueTypeMapper.java index a8d8bf77..355af10c 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/sme/ValueTypeMapper.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/sme/ValueTypeMapper.java @@ -17,6 +17,7 @@ import java.util.Map; import java.util.TreeMap; + import javax.xml.bind.JAXBElement; import org.opcfoundation.ua._2008._02.types.ObjectFactory; @@ -26,7 +27,6 @@ import io.adminshell.aas.v3.dataformat.i4aas.mappers.I4AASMapper; import io.adminshell.aas.v3.dataformat.i4aas.mappers.MappingContext; -import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASUtils; import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.UaIdentifier; public class ValueTypeMapper extends I4AASMapper { diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/utils/I4AASConstants.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/utils/I4AASConstants.java index b99eba53..894dced8 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/utils/I4AASConstants.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/utils/I4AASConstants.java @@ -24,9 +24,51 @@ public interface I4AASConstants { public final String I4AAS_MODEL_URI = "http://opcfoundation.org/UA/I4AAS/V3/"; public final String I4AAS_PUBDATE = "2021-06-04T00:00:00Z"; public final String I4AAS_VERSION = "1.0.0"; + + public final static String AAS_DISPLAYNAME_PREFIX = "AAS:"; + public final static String ASSET_DISPLAYNAME_PREFIX = "Asset:"; + public final static String SM_DISPLAYNAME_PREFIX = "Submodel:"; + + public static final String CATEGORY_BROWSENAME = "Category"; + + public static final String IDENTIFICATION_BROWSENAME = "Identification"; + public static final String IDENTIFICATION_ID_BROWSENAME = "Id"; + public static final String IDENTIFICATION_IDTYPE_BROWSENAME = "IdType"; - public final String AAS_DISPLAYNAME_PREFIX = "AAS:"; - public final String ASSET_DISPLAYNAME_PREFIX = "Asset:"; - public final String SM_DISPLAYNAME_PREFIX = "Submodel:"; + public static final String ADMINISTRATION_BROWSENAME = "Administration"; + public static final String ADMINISTRATION_REVISION_BROWSENAME = "Revision"; + public static final String ADMINISTRATION_VERSION_BROWSENAME = "Version"; + + public static final String DATASPECIFICATION_BROWSENAME = "DataSpecification"; + public static final String QUALIFIABLE_BROWSENAME = "Qualifier"; + + public static final String AAS_SUBMODELREFERENCES_LIST_BROWSENAME = "Submodel"; + public static final String AAS_DERIVEDFROM_BROWSENAME = "DerivedFrom"; + public static final String AAS_ASSETINFORMATION_BROWSENAME = "AssetInformation"; + + public static final String REFERENCE_KEYS_BROWSENAME = "Keys"; + public static final String IEC61360_SHORT_NAME_BROWSENAME = "ShortName"; + public static final String IEC61360_PREFERRED_NAME_BROWSENAME = "PreferredName"; + public static final String IEC61360_DEFINITION_BROWSENAME = "Definition"; + public static final String IEC61360_VALUE_ID_BROWSENAME = "ValueId"; + public static final String IEC61360_UNIT_ID_BROWSENAME = "UnitId"; + public static final String IEC61360_VALUE_BROWSENAME = "Value"; + public static final String IEC61360_VALUE_FORMAT_BROWSENAME = "ValueFormat"; + public static final String IEC61360_UNIT_BROWSENAME = "Unit"; + public static final String IEC61360_SYMBOL_BROWSENAME = "Symbol"; + public static final String IEC61360_SOURCE_OF_DEFINITION_BROWSENAME = "SourceOfDefinition"; + + public static final String ASSETINFO_SPECIFIC_ASSET_ID_BROWSENAME = "SpecificAssetId"; + public static final String ASSETINFO_DEFAULT_THUMBNAIL_BROWSENAME = "DefaultThumbnail"; + public static final String ASSETINFO_BILL_OF_MATERIAL_BROWSENAME = "BillOfMaterial"; + public static final String ASSETINFO_GLOBAL_ASSET_ID_BROWSENAME = "GlobalAssetId"; + + public static final String IKVP_EXTERNAL_SUBJECT_ID_BROWSENAME = "ExternalSubjectId"; + public static final String IKVP_KEY_BROWSENAME = "Key"; + public static final String IKVP_VALUE_BROWSENAME = "Value"; + + public static final String MIME_TYPE_BROWSENAME = "MimeType"; + + } diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/utils/I4AASUtils.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/utils/I4AASUtils.java index 71b10b0b..9b8b480e 100644 --- a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/utils/I4AASUtils.java +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/utils/I4AASUtils.java @@ -19,13 +19,11 @@ import org.opcfoundation.ua._2011._03.uanodeset.LocalizedText; import org.opcfoundation.ua._2011._03.uanodeset.UANodeSet; -import org.opcfoundation.ua._2011._03.uanodeset.UAObject; import io.adminshell.aas.v3.model.Asset; import io.adminshell.aas.v3.model.AssetAdministrationShell; import io.adminshell.aas.v3.model.Referable; import io.adminshell.aas.v3.model.Submodel; -import io.adminshell.aas.v3.model.View; public class I4AASUtils { diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/AnnotatedRelationshipElementParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/AnnotatedRelationshipElementParser.java new file mode 100644 index 00000000..45f4f913 --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/AnnotatedRelationshipElementParser.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import io.adminshell.aas.v3.model.AnnotatedRelationshipElement; +import io.adminshell.aas.v3.model.DataElement; +import io.adminshell.aas.v3.model.Reference; +import io.adminshell.aas.v3.model.SubmodelElement; +import io.adminshell.aas.v3.model.impl.DefaultAnnotatedRelationshipElement; + +public class AnnotatedRelationshipElementParser extends ReferableParser { + + public AnnotatedRelationshipElementParser(UANodeWrapper src, ParserContext ctx) { + super(src, ctx); + } + + @Override + protected AnnotatedRelationshipElement createTargetObject() { + return new DefaultAnnotatedRelationshipElement(); + } + + @Override + protected void parseAndAttachChildren() { + super.parseAndAttachChildren(); + source.getI4AASComponent("First").ifPresent(p -> { + p.getI4AASProperty(REFERENCE_KEYS_BROWSENAME).ifPresent(key -> { + Reference parse = new ReferenceParser(key, ctx).parse(); + target.setFirst(parse); + }); + }); + + source.getI4AASComponent("Second").ifPresent(p -> { + p.getI4AASProperty(REFERENCE_KEYS_BROWSENAME).ifPresent(key -> { + Reference parse = new ReferenceParser(key, ctx).parse(); + target.setSecond(parse); + }); + }); + + source.getI4AASComponent("Annotation").ifPresent(p -> { + p.getComponents().forEach(sme -> { + SubmodelElement parse = ParserUtils.parseSME(sme, ctx); + if (parse != null) { + target.getAnnotations().add((DataElement) parse); + } + }); + }); + + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/AssetAdministrationShellParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/AssetAdministrationShellParser.java new file mode 100644 index 00000000..de6c6c67 --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/AssetAdministrationShellParser.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; +import io.adminshell.aas.v3.model.AssetAdministrationShell; +import io.adminshell.aas.v3.model.AssetInformation; +import io.adminshell.aas.v3.model.Reference; +import io.adminshell.aas.v3.model.impl.DefaultAssetAdministrationShell; + +public class AssetAdministrationShellParser extends IdentifiableParser { + + public AssetAdministrationShellParser(UANodeWrapper src, ParserContext ctx) { + super(src, ctx); + } + + @Override + protected AssetAdministrationShell createTargetObject() { + DefaultAssetAdministrationShell defaultAssetAdministrationShell = new DefaultAssetAdministrationShell(); + return defaultAssetAdministrationShell; + } + + @Override + protected void parseAndAttachChildren() { + super.parseAndAttachChildren(); + + source.getI4AASComponent(AAS_SUBMODELREFERENCES_LIST_BROWSENAME).ifPresent(uanode -> { + uanode.getComponentsOfType(I4AASIdentifier.AASReferenceType).forEach(uaref -> { + uaref.getI4AASProperty(REFERENCE_KEYS_BROWSENAME).ifPresent(uaKeys -> { + Reference parse = new ReferenceParser(uaKeys, ctx).parse(); + target.getSubmodels().add(parse); + }); + }); + }); + + source.getI4AASComponent(AAS_ASSETINFORMATION_BROWSENAME).ifPresent(uanode -> { + AssetInformation parse = new AssetInformationParser(uanode, ctx).parse(); + target.setAssetInformation(parse); + }); + + source.getI4AASComponent(AAS_DERIVEDFROM_BROWSENAME).ifPresent(p -> { + p.getI4AASProperty(REFERENCE_KEYS_BROWSENAME).ifPresent(key -> { + Reference parse = new ReferenceParser(key, ctx).parse(); + target.setDerivedFrom(parse); + }); + }); + + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/AssetInformationParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/AssetInformationParser.java new file mode 100644 index 00000000..1364795a --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/AssetInformationParser.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; +import io.adminshell.aas.v3.model.AssetInformation; +import io.adminshell.aas.v3.model.AssetKind; +import io.adminshell.aas.v3.model.File; +import io.adminshell.aas.v3.model.IdentifierKeyValuePair; +import io.adminshell.aas.v3.model.Reference; +import io.adminshell.aas.v3.model.impl.DefaultAssetInformation; + +public class AssetInformationParser extends I4AASParser { + + public AssetInformationParser(UANodeWrapper src, ParserContext ctx) { + super(src, ctx); + } + + @Override + protected AssetInformation createTargetObject() { + return new DefaultAssetInformation(); + } + + @Override + protected void parseAndAttachChildren() { + source.getI4AASProperty("AssetKind").ifPresent(p -> { + AssetKind parse = (AssetKind) new I4AASGenericEnumParser(p, ctx, AssetKind.class).parse(); + target.setAssetKind(parse); + }); + + source.getI4AASComponent(ASSETINFO_BILL_OF_MATERIAL_BROWSENAME).ifPresent(p -> { + p.getComponentsOfType(I4AASIdentifier.AASReferenceType).forEach(ref -> { + p.getI4AASProperty(REFERENCE_KEYS_BROWSENAME).ifPresent(key -> { + Reference parse = new ReferenceParser(key, ctx).parse(); + target.getBillOfMaterials().add(parse); + }); + }); + }); + + source.getI4AASComponent(ASSETINFO_DEFAULT_THUMBNAIL_BROWSENAME).ifPresent(p -> { + File parse = new FileParser(p, ctx).parse(); + target.setDefaultThumbnail(parse); + }); + + source.getI4AASComponent(ASSETINFO_GLOBAL_ASSET_ID_BROWSENAME).ifPresent(p -> { + p.getI4AASProperty(REFERENCE_KEYS_BROWSENAME).ifPresent(key -> { + Reference parse = new ReferenceParser(key, ctx).parse(); + target.setGlobalAssetId(parse); + }); + }); + + source.getI4AASComponent(ASSETINFO_SPECIFIC_ASSET_ID_BROWSENAME).ifPresent(p -> { + p.getComponentsOfType(I4AASIdentifier.AASIdentifierKeyValuePairType).forEach(kv -> { + IdentifierKeyValuePair parse = new IdentifierKeyValuePairParser(kv, ctx).parse(); + target.getSpecificAssetIds().add(parse); + }); + }); + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/AssetParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/AssetParser.java new file mode 100644 index 00000000..464e4dee --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/AssetParser.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import io.adminshell.aas.v3.model.Asset; +import io.adminshell.aas.v3.model.impl.DefaultAsset; + +public class AssetParser extends IdentifiableParser { + + public AssetParser(UANodeWrapper src, ParserContext ctx) { + super(src, ctx); + } + + @Override + protected Asset createTargetObject() { + return new DefaultAsset(); + } + + @Override + protected void parseAndAttachChildren() { + super.parseAndAttachChildren(); + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/BlobParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/BlobParser.java new file mode 100644 index 00000000..b80329f7 --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/BlobParser.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import io.adminshell.aas.v3.model.Blob; +import io.adminshell.aas.v3.model.impl.DefaultBlob; + +public class BlobParser extends ReferableParser { + + public BlobParser(UANodeWrapper src, ParserContext ctx) { + super(src, ctx); + } + + @Override + protected Blob createTargetObject() { + return new DefaultBlob(); + } + + @Override + protected void parseAndAttachChildren() { + super.parseAndAttachChildren(); + source.getI4AASProperty(MIME_TYPE_BROWSENAME).ifPresent(p->{ + String valueAsString = ParserUtils.extractValueAsString(p.getNodeVariable()); + target.setMimeType(valueAsString); + }); + + source.getI4AASProperty("Value").ifPresent(p->{ + byte[] value = ParserUtils.extractValueAsByteString(p.getNodeVariable()); + target.setValue(value); + }); + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/CapabilityParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/CapabilityParser.java new file mode 100644 index 00000000..b19619c8 --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/CapabilityParser.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import io.adminshell.aas.v3.model.Capability; +import io.adminshell.aas.v3.model.impl.DefaultCapability; + +public class CapabilityParser extends ReferableParser { + + public CapabilityParser(UANodeWrapper src, ParserContext ctx) { + super(src, ctx); + } + + @Override + protected Capability createTargetObject() { + return new DefaultCapability(); + } + + @Override + protected void parseAndAttachChildren() { + super.parseAndAttachChildren(); + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/ConceptDescriptionParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/ConceptDescriptionParser.java new file mode 100644 index 00000000..3dfb7746 --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/ConceptDescriptionParser.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; +import io.adminshell.aas.v3.model.ConceptDescription; +import io.adminshell.aas.v3.model.Reference; +import io.adminshell.aas.v3.model.impl.DefaultConceptDescription; + +public class ConceptDescriptionParser extends IdentifiableParser { + + public ConceptDescriptionParser(UANodeWrapper src, ParserContext ctx) { + super(src, ctx); + } + + @Override + protected ConceptDescription createTargetObject() { + return new DefaultConceptDescription(); + } + + @Override + protected void parseAndAttachChildren() { + super.parseAndAttachChildren(); + source.getI4AASComponent("IsCaseOf").ifPresent(p->{ + p.getComponentsOfType(I4AASIdentifier.AASReferenceType).forEach(ref -> { + ref.getI4AASProperty(REFERENCE_KEYS_BROWSENAME).ifPresent(key -> { + Reference parse = new ReferenceParser(key, ctx).parse(); + target.getIsCaseOfs().add(parse); + }); + }); + }); + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/DataSpecificationIEC61360Parser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/DataSpecificationIEC61360Parser.java new file mode 100644 index 00000000..8af9a1e8 --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/DataSpecificationIEC61360Parser.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import java.util.List; + +import io.adminshell.aas.v3.model.DataSpecificationIEC61360; +import io.adminshell.aas.v3.model.DataTypeIEC61360; +import io.adminshell.aas.v3.model.LangString; +import io.adminshell.aas.v3.model.Reference; +import io.adminshell.aas.v3.model.impl.DefaultDataSpecificationIEC61360; + +public class DataSpecificationIEC61360Parser extends I4AASParser { + + public DataSpecificationIEC61360Parser(UANodeWrapper src, ParserContext ctx) { + super(src, ctx); + } + + @Override + protected DataSpecificationIEC61360 createTargetObject() { + return new DefaultDataSpecificationIEC61360(); + } + + @Override + protected void parseAndAttachChildren() { + source.getI4AASProperty("DataType").ifPresent(p -> { + DataTypeIEC61360 parse = (DataTypeIEC61360) new I4AASGenericEnumParser(p, ctx, DataTypeIEC61360.class) + .parse(); + target.setDataType(parse); + }); + + source.getI4AASProperty(IEC61360_DEFINITION_BROWSENAME).ifPresent(p -> { + List parse = ParserUtils.extractValueAsLangString(p.getNodeVariable()); + ; + target.setDefinitions(parse); + }); + + source.getI4AASProperty(IEC61360_PREFERRED_NAME_BROWSENAME).ifPresent(p -> { + List parse = ParserUtils.extractValueAsLangString(p.getNodeVariable()); + ; + target.setPreferredNames(parse); + }); + source.getI4AASProperty(IEC61360_SHORT_NAME_BROWSENAME).ifPresent(p -> { + List parse = ParserUtils.extractValueAsLangString(p.getNodeVariable()); + ; + target.setShortNames(parse); + }); + + source.getI4AASProperty(IEC61360_SOURCE_OF_DEFINITION_BROWSENAME).ifPresent(p -> { + String parse = ParserUtils.extractValueAsString(p.getNodeVariable()); + target.setSourceOfDefinition(parse); + }); + + source.getI4AASProperty(IEC61360_SYMBOL_BROWSENAME).ifPresent(p -> { + String parse = ParserUtils.extractValueAsString(p.getNodeVariable()); + target.setSymbol(parse); + }); + + source.getI4AASProperty(IEC61360_UNIT_BROWSENAME).ifPresent(p -> { + String parse = ParserUtils.extractValueAsString(p.getNodeVariable()); + target.setUnit(parse); + }); + + source.getI4AASComponent(IEC61360_UNIT_ID_BROWSENAME).ifPresent(p -> { + p.getI4AASProperty(REFERENCE_KEYS_BROWSENAME).ifPresent(key -> { + Reference parse = new ReferenceParser(key, ctx).parse(); + target.setUnitId(parse); + }); + }); + + source.getI4AASProperty(IEC61360_VALUE_BROWSENAME).ifPresent(p -> { + String parse = ParserUtils.extractValueAsString(p.getNodeVariable()); + target.setValue(parse); + }); + + source.getI4AASProperty(IEC61360_VALUE_FORMAT_BROWSENAME).ifPresent(p -> { + String parse = ParserUtils.extractValueAsString(p.getNodeVariable()); + target.setValueFormat(parse); + }); + + source.getI4AASComponent(IEC61360_VALUE_ID_BROWSENAME).ifPresent(p -> { + p.getI4AASProperty(REFERENCE_KEYS_BROWSENAME).ifPresent(key -> { + Reference parse = new ReferenceParser(key, ctx).parse(); + target.setValueId(parse); + }); + }); + + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/DataSpecificationsParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/DataSpecificationsParser.java new file mode 100644 index 00000000..90125a33 --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/DataSpecificationsParser.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; +import io.adminshell.aas.v3.model.DataSpecificationContent; +import io.adminshell.aas.v3.model.DataSpecificationIEC61360; +import io.adminshell.aas.v3.model.EmbeddedDataSpecification; +import io.adminshell.aas.v3.model.Reference; +import io.adminshell.aas.v3.model.impl.DefaultEmbeddedDataSpecification; + +public class DataSpecificationsParser extends I4AASParser> { + + int size = 0; + + public DataSpecificationsParser(UANodeWrapper src, ParserContext ctx) { + super(src, ctx); + } + + @Override + protected List createTargetObject() { + return new ArrayList<>(); + } + + + @Override + protected void parseAndAttachChildren() { + Map idx2Ref = new TreeMap<>(); + Map idx2Content = new TreeMap<>(); + + //TODO split("_") used for naming convention to fix I4AAS uniqueness issues + List references = source.getComponentsOfType(I4AASIdentifier.AASReferenceType); + for (UANodeWrapper reference : references) { + reference.getI4AASProperty(REFERENCE_KEYS_BROWSENAME).ifPresent(key -> { + int idx = Integer.parseInt(reference.getBrowseNameStringPart().split("_")[1]); + size = Math.max(size, idx); + Reference parse = new ReferenceParser(key, ctx).parse(); + idx2Ref.put(idx, parse); + }); + } + + List iecSpecifications = source.getComponentsOfType(I4AASIdentifier.AASDataSpecificationIEC61360Type); + for (UANodeWrapper content : iecSpecifications) { + int idx = Integer.parseInt(content.getBrowseNameStringPart().split("_")[1]); + size = Math.max(size, idx); + DataSpecificationIEC61360 parse = new DataSpecificationIEC61360Parser(content, ctx).parse(); + idx2Content.put(idx, parse); + } + + for (int idx = 0; idx <= size; idx++) { + DefaultEmbeddedDataSpecification targetElement = new DefaultEmbeddedDataSpecification(); + targetElement.setDataSpecification(idx2Ref.get(idx)); + targetElement.setDataSpecificationContent(idx2Content.get(idx)); + target.add(idx, targetElement); + } + + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/EntityParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/EntityParser.java new file mode 100644 index 00000000..93a94715 --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/EntityParser.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import io.adminshell.aas.v3.model.Entity; +import io.adminshell.aas.v3.model.EntityType; +import io.adminshell.aas.v3.model.IdentifierKeyValuePair; +import io.adminshell.aas.v3.model.Reference; +import io.adminshell.aas.v3.model.SubmodelElement; +import io.adminshell.aas.v3.model.impl.DefaultEntity; + +public class EntityParser extends ReferableParser { + + public EntityParser(UANodeWrapper src, ParserContext ctx) { + super(src, ctx); + } + + @Override + protected Entity createTargetObject() { + return new DefaultEntity(); + } + + @Override + protected void parseAndAttachChildren() { + super.parseAndAttachChildren(); + source.getI4AASProperty("EntityType").ifPresent(p -> { + EntityType parse = (EntityType) new I4AASGenericEnumParser(p, ctx, EntityType.class).parse(); + target.setEntityType(parse); + }); + + source.getI4AASComponent(ASSETINFO_GLOBAL_ASSET_ID_BROWSENAME).ifPresent(p -> { + p.getI4AASProperty(REFERENCE_KEYS_BROWSENAME).ifPresent(key -> { + Reference parse = new ReferenceParser(key, ctx).parse(); + target.setGlobalAssetId(parse); + }); + }); + + source.getI4AASComponent(ASSETINFO_SPECIFIC_ASSET_ID_BROWSENAME).ifPresent(p -> { + IdentifierKeyValuePair parse = new IdentifierKeyValuePairParser(p, ctx).parse(); + target.setSpecificAssetId(parse); + }); + + source.getI4AASComponent("Statement").ifPresent(p -> { + p.getComponents().forEach(sme -> { + SubmodelElement parse = ParserUtils.parseSME(sme, ctx); + if (parse != null) { + target.getStatements().add(parse); + } + }); + }); + + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/EnvironmentParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/EnvironmentParser.java new file mode 100644 index 00000000..811f3098 --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/EnvironmentParser.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; +import io.adminshell.aas.v3.model.Asset; +import io.adminshell.aas.v3.model.AssetAdministrationShell; +import io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment; +import io.adminshell.aas.v3.model.ConceptDescription; +import io.adminshell.aas.v3.model.Submodel; +import io.adminshell.aas.v3.model.impl.DefaultAssetAdministrationShellEnvironment; + +public class EnvironmentParser extends I4AASParser { + + public EnvironmentParser(UANodeWrapper src, ParserContext ctx) { + super(src, ctx); + } + + @Override + protected AssetAdministrationShellEnvironment createTargetObject() { + target = new DefaultAssetAdministrationShellEnvironment(); + return target; + } + + @Override + protected void parseAndAttachChildren() { + for (UANodeWrapper uaNodeWrapper : source.getComponentsOfType(I4AASIdentifier.AASSubmodelType)) { + Submodel parse = new SubmodelParser(uaNodeWrapper, ctx).parse(); + target.getSubmodels().add(parse); + } + for (UANodeWrapper uaNodeWrapper : source.getComponentsOfType(I4AASIdentifier.AASAssetAdministrationShellType)) { + AssetAdministrationShell parse = new AssetAdministrationShellParser(uaNodeWrapper, ctx).parse(); + target.getAssetAdministrationShells().add(parse); + } + for (UANodeWrapper uaNodeWrapper : source.getComponentsOfType(I4AASIdentifier.AASAssetType)) { + Asset asset = new AssetParser(uaNodeWrapper, ctx).parse(); + target.getAssets().add(asset); + } + for (UANodeWrapper uaNodeWrapper : ctx.getDictionaryEntries()) { + ConceptDescription conceptDescription = new ConceptDescriptionParser(uaNodeWrapper, ctx).parse(); + target.getConceptDescriptions().add(conceptDescription); + } + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/EventParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/EventParser.java new file mode 100644 index 00000000..98bfd86f --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/EventParser.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import io.adminshell.aas.v3.model.Event; +import io.adminshell.aas.v3.model.impl.DefaultBasicEvent; + +public class EventParser extends ReferableParser { + + public EventParser(UANodeWrapper src, ParserContext ctx) { + super(src, ctx); + } + + @Override + protected Event createTargetObject() { + return new DefaultBasicEvent(); + } + + @Override + protected void parseAndAttachChildren() { + super.parseAndAttachChildren(); + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/FileParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/FileParser.java new file mode 100644 index 00000000..aa8f5e91 --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/FileParser.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import io.adminshell.aas.v3.model.File; +import io.adminshell.aas.v3.model.impl.DefaultFile; + +public class FileParser extends ReferableParser { + + public FileParser(UANodeWrapper src, ParserContext ctx) { + super(src, ctx); + } + + @Override + protected File createTargetObject() { + return new DefaultFile(); + } + + @Override + protected void parseAndAttachChildren() { + super.parseAndAttachChildren(); + + source.getI4AASProperty(MIME_TYPE_BROWSENAME).ifPresent(p -> { + target.setMimeType(ParserUtils.extractValueAsString(p.getNodeVariable())); + }); + + source.getI4AASProperty("Value").ifPresent(p -> { + target.setValue(ParserUtils.extractValueAsString(p.getNodeVariable())); + }); + + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/I4AASGenericEnumParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/I4AASGenericEnumParser.java new file mode 100644 index 00000000..18e9fd26 --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/I4AASGenericEnumParser.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import org.opcfoundation.ua._2011._03.uanodeset.UAVariable; + +public class I4AASGenericEnumParser extends I4AASParser> { + + private Class> targetEnum; + + public I4AASGenericEnumParser(UANodeWrapper src, ParserContext ctx, Class> targetEnumClass) { + super(src, ctx); + this.targetEnum = targetEnumClass; + } + + @Override + protected Enum createTargetObject() { + UAVariable nodeVariable = source.getNodeVariable(); + + Class loadEnum; + try { + loadEnum = (Class) getClass().getClassLoader() + .loadClass("org.opcfoundation.ua.i4aas.v3.types." + nodeVariable.getDataType()); + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException(nodeVariable.getDataType() + " is not supported.", e); + } + + Integer enumIdx = ParserUtils.extractValueAsInteger(nodeVariable); + if (enumIdx == null) { + return null; + } + + Enum enumByIdx = loadEnum.getEnumConstants()[enumIdx]; + return findMatch(enumByIdx.name(), targetEnum); + + } + + public static final Enum findMatch(String name, Class> targetEnumClass) { + int lastUnderscore = name.lastIndexOf("_"); + String sourceEnumCandidateName = name.substring(0, lastUnderscore).toLowerCase(); + for (Enum enum1 : targetEnumClass.getEnumConstants()) { + if (enum1.name().toLowerCase().equals(sourceEnumCandidateName)) { + return enum1; + } + } + throw new IllegalArgumentException( + String.format("No match found in %s for %s", targetEnumClass.getSimpleName(), name)); + } + + @Override + protected void parseAndAttachChildren() { + // nothing to do + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/I4AASParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/I4AASParser.java new file mode 100644 index 00000000..d7fa49c7 --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/I4AASParser.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASConstants; + +public abstract class I4AASParser implements I4AASConstants { + + protected ParserContext ctx; + protected UANodeWrapper source; + protected TARGET target; + + public I4AASParser(UANodeWrapper src, ParserContext ctx) { + this.source = src; + this.ctx = ctx; + } + + protected abstract TARGET createTargetObject(); + + public final TARGET parse() { + target = createTargetObject(); + parseAndAttachChildren(); + return target; + } + + protected abstract void parseAndAttachChildren(); + + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/IdentifiableParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/IdentifiableParser.java new file mode 100644 index 00000000..6b0b4442 --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/IdentifiableParser.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import java.util.List; +import java.util.Optional; + +import io.adminshell.aas.v3.model.EmbeddedDataSpecification; +import io.adminshell.aas.v3.model.Identifiable; +import io.adminshell.aas.v3.model.IdentifierType; +import io.adminshell.aas.v3.model.impl.DefaultAdministrativeInformation; +import io.adminshell.aas.v3.model.impl.DefaultIdentifier; + +public abstract class IdentifiableParser extends ReferableParser { + + public IdentifiableParser(UANodeWrapper src, ParserContext ctx) { + super(src, ctx); + } + + @Override + protected void parseAndAttachChildren() { + super.parseAndAttachChildren(); + + Optional uaIdentification = source.getI4AASComponent(IDENTIFICATION_BROWSENAME); + uaIdentification.ifPresent(uaNode -> { + target.setIdentification(new DefaultIdentifier()); + uaNode.getI4AASProperty(IDENTIFICATION_ID_BROWSENAME).ifPresent(id -> { + target.getIdentification().setIdentifier(ParserUtils.extractValueAsString(id.getNodeVariable())); + }); + uaNode.getI4AASProperty(IDENTIFICATION_IDTYPE_BROWSENAME).ifPresent(idType -> { + IdentifierType parsedIdType; + parsedIdType = (IdentifierType) new I4AASGenericEnumParser(idType, ctx, IdentifierType.class).parse(); + target.getIdentification().setIdType(parsedIdType); + }); + }); + + Optional uaAdministration = source.getI4AASComponent(ADMINISTRATION_BROWSENAME); + uaAdministration.ifPresent(uaNode -> { + target.setAdministration(new DefaultAdministrativeInformation()); + uaNode.getI4AASProperty(ADMINISTRATION_VERSION_BROWSENAME).ifPresent(uaVar -> { + target.getAdministration().setVersion(ParserUtils.extractValueAsString(uaVar.getNodeVariable())); + }); + uaNode.getI4AASProperty(ADMINISTRATION_REVISION_BROWSENAME).ifPresent(uaVar -> { + target.getAdministration().setRevision(ParserUtils.extractValueAsString(uaVar.getNodeVariable())); + }); + + + uaNode.getI4AASComponent(DATASPECIFICATION_BROWSENAME).ifPresent(uaDataSpec -> { + List listOfEmbeddedDataSpecification = new DataSpecificationsParser(uaDataSpec, ctx).parse(); + target.getAdministration().setEmbeddedDataSpecifications(listOfEmbeddedDataSpecification); + }); + }); + + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/IdentifierKeyValuePairParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/IdentifierKeyValuePairParser.java new file mode 100644 index 00000000..a54ba1cd --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/IdentifierKeyValuePairParser.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import io.adminshell.aas.v3.model.IdentifierKeyValuePair; +import io.adminshell.aas.v3.model.Reference; +import io.adminshell.aas.v3.model.impl.DefaultIdentifierKeyValuePair; + +public class IdentifierKeyValuePairParser extends I4AASParser { + + public IdentifierKeyValuePairParser(UANodeWrapper src, ParserContext ctx) { + super(src, ctx); + } + + @Override + protected IdentifierKeyValuePair createTargetObject() { + return new DefaultIdentifierKeyValuePair(); + } + + @Override + protected void parseAndAttachChildren() { + source.getI4AASComponent(IKVP_EXTERNAL_SUBJECT_ID_BROWSENAME).ifPresent(p -> { + p.getI4AASProperty(REFERENCE_KEYS_BROWSENAME).ifPresent(key -> { + Reference parse = new ReferenceParser(key, ctx).parse(); + target.setExternalSubjectId(parse); + }); + }); + + source.getI4AASProperty(IKVP_KEY_BROWSENAME).ifPresent(p -> { + target.setKey(ParserUtils.extractValueAsString(p.getNodeVariable())); + }); + + source.getI4AASProperty(IKVP_VALUE_BROWSENAME).ifPresent(p -> { + target.setValue(ParserUtils.extractValueAsString(p.getNodeVariable())); + }); + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/KeyParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/KeyParser.java new file mode 100644 index 00000000..43491704 --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/KeyParser.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import org.opcfoundation.ua.i4aas.v3.types.AASKeyDataType; + +import io.adminshell.aas.v3.model.Key; +import io.adminshell.aas.v3.model.KeyElements; +import io.adminshell.aas.v3.model.KeyType; +import io.adminshell.aas.v3.model.impl.DefaultKey; + +public class KeyParser { + + private AASKeyDataType source; + + public KeyParser(AASKeyDataType key, ParserContext ctx) { + this.source = key; + } + + public Key parse() { + DefaultKey defaultKey = new DefaultKey(); + + defaultKey.setValue(source.getValue()); + + if (source.getIdType() != null) { + KeyType keyType = (KeyType) I4AASGenericEnumParser.findMatch(source.getIdType().name(), KeyType.class); + defaultKey.setIdType(keyType); + } + if (source.getType() != null) { + KeyElements keyElements = (KeyElements) I4AASGenericEnumParser.findMatch(source.getType().name(), KeyElements.class); + defaultKey.setType(keyElements); + } + + return defaultKey; + } + + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/MultiLanguagePropertyParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/MultiLanguagePropertyParser.java new file mode 100644 index 00000000..df6e880d --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/MultiLanguagePropertyParser.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import java.util.List; + +import io.adminshell.aas.v3.model.LangString; +import io.adminshell.aas.v3.model.MultiLanguageProperty; +import io.adminshell.aas.v3.model.Reference; +import io.adminshell.aas.v3.model.impl.DefaultMultiLanguageProperty; + +public class MultiLanguagePropertyParser extends ReferableParser { + + public MultiLanguagePropertyParser(UANodeWrapper src, ParserContext ctx) { + super(src, ctx); + } + + @Override + protected MultiLanguageProperty createTargetObject() { + return new DefaultMultiLanguageProperty(); + } + + @Override + protected void parseAndAttachChildren() { + super.parseAndAttachChildren(); + + source.getI4AASComponent("ValueId").ifPresent(p -> { + p.getI4AASProperty(REFERENCE_KEYS_BROWSENAME).ifPresent(key -> { + Reference parse = new ReferenceParser(key, ctx).parse(); + target.setValueId(parse); + }); + }); + + source.getI4AASProperty("Value").ifPresent(p -> { + List extractValueAsLangString = ParserUtils.extractValueAsLangString(p.getNodeVariable()); + target.setValues(extractValueAsLangString); + }); + + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/NodeIdResolver.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/NodeIdResolver.java new file mode 100644 index 00000000..4dfb09a9 --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/NodeIdResolver.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + +import org.opcfoundation.ua._2011._03.uanodeset.UANode; +import org.opcfoundation.ua._2011._03.uanodeset.UANodeSet; + +public class NodeIdResolver { + + private Map nodeId2NodeMap; + + public NodeIdResolver(UANodeSet nodeset) { + nodeId2NodeMap = nodeset.getUAObjectOrUAVariableOrUAMethod().stream() + .collect(Collectors.toMap(node -> node.getNodeId(), Function.identity())); + } + + public UANode getUANode(String nodeId) { + return nodeId2NodeMap.get(nodeId); + } +} \ No newline at end of file diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/OperationParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/OperationParser.java new file mode 100644 index 00000000..9ad1bc82 --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/OperationParser.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import io.adminshell.aas.v3.model.Operation; +import io.adminshell.aas.v3.model.impl.DefaultOperation; + +public class OperationParser extends ReferableParser { + + public OperationParser(UANodeWrapper src, ParserContext ctx) { + super(src, ctx); + } + + @Override + protected Operation createTargetObject() { + return new DefaultOperation(); + } + + @Override + protected void parseAndAttachChildren() { + super.parseAndAttachChildren(); + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/ParserContext.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/ParserContext.java new file mode 100644 index 00000000..a2ce4d49 --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/ParserContext.java @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import org.opcfoundation.ua._2011._03.uanodeset.ListOfReferences; +import org.opcfoundation.ua._2011._03.uanodeset.Reference; +import org.opcfoundation.ua._2011._03.uanodeset.UANode; +import org.opcfoundation.ua._2011._03.uanodeset.UANodeSet; + +import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASConstants; +import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; +import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.UaIdentifier; + +public class ParserContext { + + protected UANodeSet uaNodeset; + protected Map namespaceIdxMap = new HashMap<>(); + private int i4aasNsIdx; + + protected NodeIdResolver nodeId2NodeMap; + + private UANodeWrapper uaEnvironment; + private List conceptDictionaries; + + public ParserContext(UANodeSet uaNodeset) { + this.uaNodeset = uaNodeset; + + nodeId2NodeMap = new NodeIdResolver(uaNodeset); + + parseNamespaces(); + + Optional environmentNode = findNodeOfAASEnvironmentType(); + if (environmentNode.isPresent()) { + uaEnvironment = new UANodeWrapper(environmentNode.get(), nodeId2NodeMap, this); + } else { + // log no environment found + } + + conceptDictionaries = findNodesOfAASConceptDictionaryType(); + } + + private void parseNamespaces() { + for (int i = 0; i < uaNodeset.getNamespaceUris().getUri().size(); i++) { + String namespace = uaNodeset.getNamespaceUris().getUri().get(i); + int nsIdx = i + 1; + namespaceIdxMap.put(namespace, nsIdx); + if (namespace.equals(I4AASConstants.I4AAS_MODEL_URI)) { + i4aasNsIdx = nsIdx; + } + } + } + + protected Optional findNodeOfAASEnvironmentType() { + for (UANode uaNode : uaNodeset.getUAObjectOrUAVariableOrUAMethod()) { + ListOfReferences references = uaNode.getReferences(); + if (references != null) { + Optional aasEnvironmentNodeId = getTypeDefinitons(references) + .filter(ofType(I4AASIdentifier.AASEnvironmentType)).findAny(); + if (aasEnvironmentNodeId.isPresent()) { + return Optional.of(uaNode); + } + } + } + return Optional.empty(); + } + + protected List findNodesOfAASConceptDictionaryType() { + ArrayList result = new ArrayList<>(); + for (UANode uaNode : uaNodeset.getUAObjectOrUAVariableOrUAMethod()) { + ListOfReferences references = uaNode.getReferences(); + if (references != null) { + if (getTypeDefinitons(references).filter(ofTypeAASConcetpDescription()).findAny().isPresent()) { + result.add(new UANodeWrapper(uaNode, nodeId2NodeMap, this)); + } + } + } + return result; + } + + protected Stream getTypeDefinitons(ListOfReferences references) { + return getNodeIdsOfType(references, hasTypeDefinition()); + } + + protected Stream getComponents(ListOfReferences references) { + return getNodeIdsOfType(references, hasComponent()); + } + + protected Stream getProperties(ListOfReferences references) { + return getNodeIdsOfType(references, hasProperty()); + } + + protected Stream getDictionaryEntries(ListOfReferences references) { + return getNodeIdsOfType(references, hasDictionaryEntry()); + } + + protected Stream getNodeIdsOfType(ListOfReferences references, Predicate referenceType) { + return references != null ? references.getReference().stream().filter(referenceType).map(toValue()) + : Stream.empty(); + } + + private Predicate ofType(I4AASIdentifier identifier) { + return str -> str.equals(nodeIdOf(identifier)); + } + + protected String nodeIdOf(I4AASIdentifier identifier) { + return String.format("ns=%s;i=%s", getI4aasNsIdx(), identifier.getId()); + } + + protected String nodeIdOf(UaIdentifier identifier) { + return String.format("i=%s", identifier.getId()); + } + + protected Function toValue() { + return ref -> ref.getValue(); + } + + protected Predicate hasTypeDefinition() { + return typeOf(UaIdentifier.HasTypeDefinition); + } + + protected Predicate hasComponent() { + return typeOf(UaIdentifier.HasComponent).or(typeOf(UaIdentifier.HasOrderedComponent)); + } + + protected Predicate hasProperty() { + return typeOf(UaIdentifier.HasProperty); + } + + protected Predicate hasDictionaryEntry() { + return typeOf(UaIdentifier.HasDictionaryEntry); + } + + protected Predicate ofTypeAASConcetpDescription() { + return str -> str.equals(nodeIdOf(I4AASIdentifier.AASCustomConceptDescriptionType)) + || str.equals(nodeIdOf(I4AASIdentifier.AASIriConceptDescriptionType)) + || str.equals(nodeIdOf(I4AASIdentifier.AASCustomConceptDescriptionType)); + } + + + protected Predicate typeOf(UaIdentifier id) { + return ref -> ref.getReferenceType().equals(id.getName()) && ref.isIsForward(); + } + + public UANodeWrapper getEnvironment() { + return uaEnvironment; + } + + public int getI4aasNsIdx() { + return i4aasNsIdx; + } + + public List getDictionaryEntries() { + return conceptDictionaries; + } + +} \ No newline at end of file diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/ParserUtils.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/ParserUtils.java new file mode 100644 index 00000000..d8ae2f9a --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/ParserUtils.java @@ -0,0 +1,216 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import java.util.ArrayList; +import java.util.Base64; +import java.util.List; + +import javax.xml.bind.JAXBElement; + +import org.opcfoundation.ua._2008._02.types.ListOfLocalizedText; +import org.opcfoundation.ua._2008._02.types.LocalizedText; +import org.opcfoundation.ua._2011._03.uanodeset.UAVariable; +import org.opcfoundation.ua._2011._03.uanodeset.UAVariable.Value; + +import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; +import io.adminshell.aas.v3.model.AnnotatedRelationshipElement; +import io.adminshell.aas.v3.model.Blob; +import io.adminshell.aas.v3.model.Capability; +import io.adminshell.aas.v3.model.Entity; +import io.adminshell.aas.v3.model.Event; +import io.adminshell.aas.v3.model.File; +import io.adminshell.aas.v3.model.LangString; +import io.adminshell.aas.v3.model.MultiLanguageProperty; +import io.adminshell.aas.v3.model.Operation; +import io.adminshell.aas.v3.model.Property; +import io.adminshell.aas.v3.model.Range; +import io.adminshell.aas.v3.model.ReferenceElement; +import io.adminshell.aas.v3.model.RelationshipElement; +import io.adminshell.aas.v3.model.SubmodelElement; +import io.adminshell.aas.v3.model.SubmodelElementCollection; + +public class ParserUtils { + + public static String extractValueAsString(UAVariable nodeVariable) { + Value uaValue = nodeVariable.getValue(); + if (uaValue != null) { + Object any = uaValue.getAny(); + if (any instanceof JAXBElement) { + JAXBElement anyJaxbElement = (JAXBElement) any; + if (anyJaxbElement.getValue() instanceof String) { + return (String) anyJaxbElement.getValue(); + } else if (anyJaxbElement.getValue() != null) { + new UnsupportedOperationException( + "Unsupported Type " + anyJaxbElement.getValue().getClass().getName()); + } + } else if (any != null) { + new UnsupportedOperationException("Unsupported Type " + any.getClass().getName()); + } + } + return null; + } + + public static Integer extractValueAsInteger(UAVariable nodeVariable) { + Value uaValue = nodeVariable.getValue(); + if (uaValue != null) { + Object any = uaValue.getAny(); + if (any instanceof JAXBElement) { + JAXBElement anyJaxbElement = (JAXBElement) any; + if (anyJaxbElement.getValue() instanceof Integer) { + return (Integer) anyJaxbElement.getValue(); + } else if (anyJaxbElement.getValue() != null) { + new UnsupportedOperationException( + "Unsupported Type " + anyJaxbElement.getValue().getClass().getName()); + } + } else if (any != null) { + new UnsupportedOperationException("Unsupported Type " + any.getClass().getName()); + } + } + return null; + } + + public static List extractValueAsLangString(UAVariable nodeVariable) { + List result = new ArrayList<>(); + Value uaValue = nodeVariable.getValue(); + if (uaValue != null) { + Object any = uaValue.getAny(); + if (any instanceof JAXBElement) { + JAXBElement anyJaxbElement = (JAXBElement) any; + if (anyJaxbElement.getValue() instanceof ListOfLocalizedText) { + List localizedTexts = ((ListOfLocalizedText) anyJaxbElement.getValue()) + .getLocalizedText(); + for (LocalizedText localizedText : localizedTexts) { + LangString langString = new LangString(localizedText.getLocale().getValue(), + localizedText.getText().getValue()); + result.add(langString); + } + } else if (anyJaxbElement.getValue() != null) { + new UnsupportedOperationException( + "Unsupported Type " + anyJaxbElement.getValue().getClass().getName()); + } + } else if (any != null) { + new UnsupportedOperationException("Unsupported Type " + any.getClass().getName()); + } + } + return result; + } + + public static byte[] extractValueAsByteString(UAVariable nodeVariable) { + String byteString = extractValueAsString(nodeVariable); + if (byteString == null) { + return null; + } + byte[] bytes = Base64.getDecoder().decode(byteString); + return bytes; + } + + + public static Boolean extractValueAsBoolean(UAVariable nodeVariable) { + Value uaValue = nodeVariable.getValue(); + if (uaValue != null) { + Object any = uaValue.getAny(); + if (any instanceof JAXBElement) { + JAXBElement anyJaxbElement = (JAXBElement) any; + if (anyJaxbElement.getValue() instanceof Boolean) { + return (Boolean) anyJaxbElement.getValue(); + } else if (anyJaxbElement.getValue() != null) { + new UnsupportedOperationException( + "Unsupported Type " + anyJaxbElement.getValue().getClass().getName()); + } + } else if (any != null) { + new UnsupportedOperationException("Unsupported Type " + any.getClass().getName()); + } + } + return null; + } + + public static SubmodelElement parseSME(UANodeWrapper source, ParserContext ctx) { + + if (source.getType().equals(I4AASIdentifier.AASBlobType)) { + Blob parse = new BlobParser(source, ctx).parse(); + return parse; + } + + if (source.getType().equals(I4AASIdentifier.AASCapabilityType)) { + Capability parse = new CapabilityParser(source, ctx).parse(); + return parse; + } + + if (source.getType().equals(I4AASIdentifier.AASEntityType)) { + Entity parse = new EntityParser(source, ctx).parse(); + return parse; + } + + if (source.getType().equals(I4AASIdentifier.AASEventType)) { + Event parse = new EventParser(source, ctx).parse(); + return parse; + } + + if (source.getType().equals(I4AASIdentifier.AASFileType)) { + File parse = new FileParser(source, ctx).parse(); + return parse; + } + + if (source.getType().equals(I4AASIdentifier.AASMultiLanguagePropertyType)) { + MultiLanguageProperty parse = new MultiLanguagePropertyParser(source, ctx).parse(); + return parse; + } + + if (source.getType().equals(I4AASIdentifier.AASOperationType)) { + Operation parse = new OperationParser(source, ctx).parse(); + return parse; + } + + if (source.getType().equals(I4AASIdentifier.AASPropertyType)) { + Property parse = new PropertyParser(source, ctx).parse(); + return parse; + } + + if (source.getType().equals(I4AASIdentifier.AASRangeType)) { + Range parse = new RangeParser(source, ctx).parse(); + return parse; + } + + if (source.getType().equals(I4AASIdentifier.AASReferenceElementType)) { + ReferenceElement parse = new ReferenceElementParser(source, ctx).parse(); + return parse; + } + + if (source.getType().equals(I4AASIdentifier.AASRelationshipElementType)) { + RelationshipElement parse = new RelationshipElementParser(source, ctx).parse(); + return parse; + } + + if (source.getType().equals(I4AASIdentifier.AASAnnotatedRelationshipElementType)) { + AnnotatedRelationshipElement parse = new AnnotatedRelationshipElementParser(source, ctx).parse(); + return parse; + } + + if (source.getType().equals(I4AASIdentifier.AASSubmodelElementCollectionType)) { + SubmodelElementCollection parse = new SubmodelElementCollectionParser(source, ctx, false).parse(); + return parse; + } + + if (source.getType().equals(I4AASIdentifier.AASOrderedSubmodelElementCollectionType)) { + SubmodelElementCollection parse = new SubmodelElementCollectionParser(source, ctx, true).parse(); + return parse; + } + + return null; + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/PropertyParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/PropertyParser.java new file mode 100644 index 00000000..bc1b78b1 --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/PropertyParser.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import io.adminshell.aas.v3.model.Property; +import io.adminshell.aas.v3.model.Reference; +import io.adminshell.aas.v3.model.impl.DefaultProperty; + +public class PropertyParser extends ReferableParser { + + public PropertyParser(UANodeWrapper src, ParserContext ctx) { + super(src, ctx); + } + + @Override + protected Property createTargetObject() { + return new DefaultProperty(); + } + + @Override + protected void parseAndAttachChildren() { + super.parseAndAttachChildren(); + + source.getI4AASProperty("Value").ifPresent(p -> { + target.setValue(ParserUtils.extractValueAsString(p.getNodeVariable())); + }); + + source.getI4AASComponent("ValueId").ifPresent(p -> { + p.getI4AASProperty(REFERENCE_KEYS_BROWSENAME).ifPresent(key -> { + Reference parse = new ReferenceParser(key, ctx).parse(); + target.setValueId(parse); + }); + }); + + source.getI4AASComponent("ValueType").ifPresent(p -> { + target.setValueType(ParserUtils.extractValueAsString(p.getNodeVariable())); + }); + + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/QualifierParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/QualifierParser.java new file mode 100644 index 00000000..1b5fa6aa --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/QualifierParser.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import io.adminshell.aas.v3.model.Qualifier; +import io.adminshell.aas.v3.model.Reference; +import io.adminshell.aas.v3.model.impl.DefaultQualifier; + +public class QualifierParser extends I4AASParser { + + public QualifierParser(UANodeWrapper src, ParserContext ctx) { + super(src, ctx); + } + + @Override + protected Qualifier createTargetObject() { + return new DefaultQualifier(); + } + + @Override + protected void parseAndAttachChildren() { + source.getI4AASProperty("Type").ifPresent(p -> { + String parse = ParserUtils.extractValueAsString(p.getNodeVariable()); + target.setType(parse); + }); + + source.getI4AASProperty("Value").ifPresent(p -> { + String parse = ParserUtils.extractValueAsString(p.getNodeVariable()); + target.setValue(parse); + }); + + source.getI4AASProperty("ValueId").ifPresent(p -> { + p.getI4AASProperty(REFERENCE_KEYS_BROWSENAME).ifPresent(key -> { + Reference parse = null; + target.setValueId(parse); + }); + }); + + source.getI4AASProperty("ValueType").ifPresent(p -> { + String parse = ParserUtils.extractValueAsString(p.getNodeVariable()); + target.setValueType(parse); + }); + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/RangeParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/RangeParser.java new file mode 100644 index 00000000..ccfc8744 --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/RangeParser.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import io.adminshell.aas.v3.model.Range; +import io.adminshell.aas.v3.model.impl.DefaultRange; + +public class RangeParser extends ReferableParser { + + public RangeParser(UANodeWrapper src, ParserContext ctx) { + super(src, ctx); + } + + @Override + protected Range createTargetObject() { + return new DefaultRange(); + } + + @Override + protected void parseAndAttachChildren() { + super.parseAndAttachChildren(); + + source.getI4AASProperty("Max").ifPresent(p -> { + String parse = ParserUtils.extractValueAsString(p.getNodeVariable()); + target.setMax(parse); + }); + + source.getI4AASProperty("Min").ifPresent(p -> { + String parse = ParserUtils.extractValueAsString(p.getNodeVariable()); + target.setMin(parse); + }); + + source.getI4AASProperty("ValueType").ifPresent(p -> { + String parse = ParserUtils.extractValueAsString(p.getNodeVariable()); + target.setValueType(parse); + }); + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/ReferableParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/ReferableParser.java new file mode 100644 index 00000000..ade15ffd --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/ReferableParser.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import java.util.List; +import java.util.Optional; + +import org.opcfoundation.ua._2011._03.uanodeset.LocalizedText; +import org.opcfoundation.ua._2011._03.uanodeset.UAVariable; + +import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; +import io.adminshell.aas.v3.model.ConceptDescription; +import io.adminshell.aas.v3.model.Constraint; +import io.adminshell.aas.v3.model.EmbeddedDataSpecification; +import io.adminshell.aas.v3.model.HasDataSpecification; +import io.adminshell.aas.v3.model.HasKind; +import io.adminshell.aas.v3.model.HasSemantics; +import io.adminshell.aas.v3.model.Identifier; +import io.adminshell.aas.v3.model.KeyType; +import io.adminshell.aas.v3.model.LangString; +import io.adminshell.aas.v3.model.ModelingKind; +import io.adminshell.aas.v3.model.Qualifiable; +import io.adminshell.aas.v3.model.Referable; +import io.adminshell.aas.v3.model.impl.DefaultKey; +import io.adminshell.aas.v3.model.impl.DefaultReference; + +public abstract class ReferableParser extends I4AASParser { + + public ReferableParser(UANodeWrapper src, ParserContext ctx) { + super(src, ctx); + } + + @Override + protected void parseAndAttachChildren() { + target.setIdShort(source.getBrowseNameStringPart()); + + for (LocalizedText localizedText : source.getDescription()) { + LangString langString = new LangString(localizedText.getLocale(), localizedText.getValue()); + target.getDescriptions().add(langString); + } + + for (LocalizedText localizedText : source.getDisplayName()) { + LangString langString = new LangString(localizedText.getLocale(), localizedText.getValue()); + target.getDisplayNames().add(langString); + } + + Optional i4aasCategoryProperty = source.getI4AASProperty(CATEGORY_BROWSENAME); + if (i4aasCategoryProperty.isPresent()) { + UAVariable nodeVariable = i4aasCategoryProperty.get().getNodeVariable(); + target.setCategory(ParserUtils.extractValueAsString(nodeVariable)); + } + + if (target instanceof HasDataSpecification) { + parseHasDataSpecification((HasDataSpecification) target); + } + + if (target instanceof Qualifiable) { + parseQualifiable((Qualifiable) target); + } + + if (target instanceof HasKind) { + parseHasKind((HasKind) target); + } + + if (target instanceof HasSemantics) { + parseSemantics((HasSemantics) target); + } + } + + private void parseSemantics(HasSemantics target) { + source.getAASDictionaryEntry().ifPresent(p -> { + ConceptDescription cd = new ConceptDescriptionParser(p, ctx).parse(); + Identifier identification = cd.getIdentification(); + target.setSemanticId(new DefaultReference.Builder() + .key(new DefaultKey.Builder().idType(KeyType.valueOf(identification.getIdType().name())) + .value(identification.getIdentifier()).build()) + .build()); + }); + + } + + private void parseHasKind(HasKind target) { + source.getI4AASProperty("ModelingKind").ifPresent(p -> { + ModelingKind parse = (ModelingKind) new I4AASGenericEnumParser(p, ctx, ModelingKind.class).parse(); + target.setKind(parse); + }); + } + + private void parseQualifiable(Qualifiable target) { + source.getI4AASComponent(QUALIFIABLE_BROWSENAME).ifPresent(p -> { + p.getComponentsOfType(I4AASIdentifier.AASQualifierType).forEach(q -> { + Constraint parse = new QualifierParser(q, ctx).parse(); + target.getQualifiers().add(parse); + }); + }); + } + + private void parseHasDataSpecification(HasDataSpecification target) { + source.getI4AASComponent(DATASPECIFICATION_BROWSENAME).ifPresent(uaDataSpec -> { + List listOfEmbeddedDataSpecification = new DataSpecificationsParser(uaDataSpec, + ctx).parse(); + target.setEmbeddedDataSpecifications(listOfEmbeddedDataSpecification); + }); + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/ReferenceElementParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/ReferenceElementParser.java new file mode 100644 index 00000000..cc7b9065 --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/ReferenceElementParser.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import io.adminshell.aas.v3.model.Reference; +import io.adminshell.aas.v3.model.ReferenceElement; +import io.adminshell.aas.v3.model.impl.DefaultReferenceElement; + +public class ReferenceElementParser extends ReferableParser { + + public ReferenceElementParser(UANodeWrapper src, ParserContext ctx) { + super(src, ctx); + } + + @Override + protected ReferenceElement createTargetObject() { + return new DefaultReferenceElement(); + } + + @Override + protected void parseAndAttachChildren() { + super.parseAndAttachChildren(); + source.getI4AASComponent("Value").ifPresent(p->{ + p.getI4AASProperty(REFERENCE_KEYS_BROWSENAME).ifPresent(key ->{ + Reference parse = new ReferenceParser(key, ctx).parse(); + target.setValue(parse); + }); + }); + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/ReferenceParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/ReferenceParser.java new file mode 100644 index 00000000..17def511 --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/ReferenceParser.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import java.util.List; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; + +import org.opcfoundation.ua._2008._02.types.ExtensionObject; +import org.opcfoundation.ua._2008._02.types.ListOfExtensionObject; +import org.opcfoundation.ua._2011._03.uanodeset.UAVariable.Value; +import org.opcfoundation.ua.i4aas.v3.types.AASKeyDataType; +import org.w3c.dom.Node; + +import io.adminshell.aas.v3.model.Key; +import io.adminshell.aas.v3.model.Reference; +import io.adminshell.aas.v3.model.impl.DefaultReference; + +public class ReferenceParser extends I4AASParser { + + static JAXBContext aasKeyJaxbCtx; + static { + try { + aasKeyJaxbCtx = org.eclipse.persistence.jaxb.JAXBContextFactory + .createContext(new Class[] { AASKeyDataType.class }, null); + } catch (JAXBException e) { + new IllegalStateException("Unable to create JAXBContext to unmarshal reference keys.", e); + } + } + + public ReferenceParser(UANodeWrapper src, ParserContext ctx) { + super(src, ctx); + } + + @Override + protected Reference createTargetObject() { + return new DefaultReference(); + } + + @Override + protected void parseAndAttachChildren() { + Value value = source.getNodeVariable().getValue(); + if (value != null && value.getAny() instanceof JAXBElement) { + JAXBElement jaxb_leo = (JAXBElement) value.getAny(); + List keysExtObjList = jaxb_leo.getValue().getExtensionObject(); + for (ExtensionObject keyExtObj : keysExtObjList) { + Object nodeWithKey = keyExtObj.getBody().getValue().getAny(); + try { + JAXBElement jaxb_aasKeyDataType = aasKeyJaxbCtx.createUnmarshaller() + .unmarshal((Node) nodeWithKey, AASKeyDataType.class); + AASKeyDataType aasKeyDataType = jaxb_aasKeyDataType.getValue(); + Key parse = new KeyParser(aasKeyDataType, ctx).parse(); + target.getKeys().add(parse); + } catch (Exception e) { + new UnsupportedOperationException("Unable to read AASKeyDataType from content.", e); + } + } + } + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/RelationshipElementParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/RelationshipElementParser.java new file mode 100644 index 00000000..98283ee0 --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/RelationshipElementParser.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import io.adminshell.aas.v3.model.Reference; +import io.adminshell.aas.v3.model.RelationshipElement; +import io.adminshell.aas.v3.model.impl.DefaultRelationshipElement; + +public class RelationshipElementParser extends ReferableParser { + + public RelationshipElementParser(UANodeWrapper src, ParserContext ctx) { + super(src, ctx); + } + + @Override + protected RelationshipElement createTargetObject() { + return new DefaultRelationshipElement(); + } + + @Override + protected void parseAndAttachChildren() { + super.parseAndAttachChildren(); + + source.getI4AASComponent("First").ifPresent(p -> { + p.getI4AASProperty(REFERENCE_KEYS_BROWSENAME).ifPresent(key -> { + Reference parse = new ReferenceParser(key, ctx).parse(); + target.setFirst(parse); + }); + }); + + source.getI4AASComponent("Second").ifPresent(p -> { + p.getI4AASProperty(REFERENCE_KEYS_BROWSENAME).ifPresent(key -> { + Reference parse = new ReferenceParser(key, ctx).parse(); + target.setSecond(parse); + }); + }); + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/SubmodelElementCollectionParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/SubmodelElementCollectionParser.java new file mode 100644 index 00000000..ee41dd2f --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/SubmodelElementCollectionParser.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import io.adminshell.aas.v3.model.SubmodelElement; +import io.adminshell.aas.v3.model.SubmodelElementCollection; +import io.adminshell.aas.v3.model.impl.DefaultSubmodelElementCollection; + +public class SubmodelElementCollectionParser extends ReferableParser { + + private boolean ordered; + + public SubmodelElementCollectionParser(UANodeWrapper src, ParserContext ctx, boolean ordered) { + super(src, ctx); + this.ordered = ordered; + } + + @Override + protected SubmodelElementCollection createTargetObject() { + return new DefaultSubmodelElementCollection(); + } + + @Override + protected void parseAndAttachChildren() { + super.parseAndAttachChildren(); + target.setOrdered(ordered); + + source.getI4AASProperty("AllowDuplicates").ifPresent(p -> { + Boolean parse = ParserUtils.extractValueAsBoolean(p.getNodeVariable()); + target.setAllowDuplicates(parse); + }); + + source.getComponents().forEach(p -> { + SubmodelElement parse = ParserUtils.parseSME(p, ctx); + if (parse != null) { + target.getValues().add(parse); + } + }); + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/SubmodelParser.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/SubmodelParser.java new file mode 100644 index 00000000..61d0955d --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/SubmodelParser.java @@ -0,0 +1,48 @@ +/* +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import io.adminshell.aas.v3.model.Submodel; +import io.adminshell.aas.v3.model.SubmodelElement; +import io.adminshell.aas.v3.model.impl.DefaultSubmodel; + +public class SubmodelParser extends IdentifiableParser { + + public SubmodelParser(UANodeWrapper src, ParserContext ctx) { + super(src, ctx); + } + + @Override + protected Submodel createTargetObject() { + DefaultSubmodel defaultSubmodel = new DefaultSubmodel(); + return defaultSubmodel; + } + + @Override + protected void parseAndAttachChildren() { + super.parseAndAttachChildren(); + + source.getComponents().forEach(sme -> { + SubmodelElement parse = ParserUtils.parseSME(sme, ctx); + if (parse != null) { + target.getSubmodelElements().add(parse); + } + }); + + } + +} diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/TypeResolver.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/TypeResolver.java new file mode 100644 index 00000000..2207c1bb --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/TypeResolver.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import java.util.Arrays; +import java.util.Optional; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.BasicIdentifier; +import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; +import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.UaIdentifier; + +public class TypeResolver { + + private final int i4aasNsIdx; + + private final static Pattern ns0NodeIdPattern = Pattern.compile("^i=(\\d+)$"); + private final static Pattern nsXNodeIdPattern = Pattern.compile("^ns=(\\d+);i=(\\d+)$"); + + public TypeResolver(int i4aasNsIdx) { + this.i4aasNsIdx = i4aasNsIdx; + } + + public Optional getType(String typeId) { + Matcher ns0matcher = ns0NodeIdPattern.matcher(typeId); + if (ns0matcher.matches()) { + int parsedId = Integer.parseInt(ns0matcher.group(1)); + return Arrays.stream(UaIdentifier.values()).filter(identifier -> parsedId == identifier.getId()) + .findFirst(); + } + + Matcher nsXmatcher = nsXNodeIdPattern.matcher(typeId); + if (nsXmatcher.matches()) { + int parsedNs = Integer.parseInt(nsXmatcher.group(1)); + int parsedId = Integer.parseInt(nsXmatcher.group(2)); + if (parsedNs == i4aasNsIdx) { + return Arrays.stream(I4AASIdentifier.values()).filter(identifier -> parsedId == identifier.getId()) + .findFirst(); + } + } + + return Optional.empty(); + } + +} \ No newline at end of file diff --git a/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/UANodeWrapper.java b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/UANodeWrapper.java new file mode 100644 index 00000000..7751f9e5 --- /dev/null +++ b/dataformat-uanodeset/src/main/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/UANodeWrapper.java @@ -0,0 +1,223 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +import org.opcfoundation.ua._2011._03.uanodeset.ListOfExtensions; +import org.opcfoundation.ua._2011._03.uanodeset.ListOfReferences; +import org.opcfoundation.ua._2011._03.uanodeset.LocalizedText; +import org.opcfoundation.ua._2011._03.uanodeset.UANode; +import org.opcfoundation.ua._2011._03.uanodeset.UAObject; +import org.opcfoundation.ua._2011._03.uanodeset.UAVariable; + +import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.BasicIdentifier; +import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; + +/** + * This class provides some basic functionalities and preparsed attributes for a + * more convenient usage + * + */ +public class UANodeWrapper { + + private final static Pattern browseNamePattern = Pattern.compile("^(\\d+):(.*)$"); + + private UANode node; + private TypeResolver typeResolver; + private ParserContext ctx; + + private List components; + private List properties; + private List dictionaryEntries; + // UaIdentifier.HasDictionaryEntry + + private BasicIdentifier type; + + private int browseNameNamespace; + private String browseNameString; + + public UANodeWrapper(UANode node, NodeIdResolver nodeIdResolver, ParserContext parserContext) { + this.node = node; + this.ctx = parserContext; + typeResolver = new TypeResolver(parserContext.getI4aasNsIdx()); + // parse components + components = ctx.getComponents(getReferences()).map(nodeIdResolver::getUANode).filter(Objects::nonNull) + .map(uaNode -> new UANodeWrapper(uaNode, nodeIdResolver, ctx)).collect(Collectors.toList()); + // parse properties + properties = ctx.getProperties(getReferences()).map(nodeIdResolver::getUANode).filter(Objects::nonNull) + .map(uaNode -> new UANodeWrapper(uaNode, nodeIdResolver, ctx)).collect(Collectors.toList()); + // parse dictionaryEntries + dictionaryEntries = ctx.getDictionaryEntries(getReferences()).map(nodeIdResolver::getUANode) + .filter(Objects::nonNull).map(uaNode -> new UANodeWrapper(uaNode, nodeIdResolver, ctx)) + .collect(Collectors.toList()); + + // parse type definition + ctx.getTypeDefinitons(getReferences()).map(typeResolver::getType).findFirst().ifPresent(id -> type = id.get()); + parseBrowseName(node.getBrowseName()); + } + + private void parseBrowseName(String browseName) { + Matcher browseNameMatcher = browseNamePattern.matcher(browseName); + if (browseNameMatcher.matches()) { + browseNameNamespace = Integer.parseInt(browseNameMatcher.group(1)); + browseNameString = browseNameMatcher.group(2); + } + } + + public List getDisplayName() { + return node.getDisplayName(); + } + + public List getDescription() { + return node.getDescription(); + } + + public ListOfReferences getReferences() { + return node.getReferences(); + } + + public ListOfExtensions getExtensions() { + return node.getExtensions(); + } + + public String getNodeId() { + return node.getNodeId(); + } + + public String getBrowseName() { + return node.getBrowseName(); + } + + /** + * @return all Nodes which are referenced by HasComponent + */ + public List getComponents() { + return components; + } + + /** + * @return all Nodes which are referenced by HasProperty + */ + public List getProperties() { + return properties; + } + + /** + * @return all Nodes which are referenced by HasDictionaryEntries for + * hasSemantics + */ + public List getDictionaryEntries() { + return dictionaryEntries; + } + + public Optional getAASDictionaryEntry() { + return dictionaryEntries.stream().filter(node -> { + return node.getType().equals(I4AASIdentifier.AASCustomConceptDescriptionType) + || node.getType().equals(I4AASIdentifier.AASIrdiConceptDescriptionType) + || node.getType().equals(I4AASIdentifier.AASIriConceptDescriptionType); + }).findFirst(); + } + + public List getPropertiesAndComponents() { + List propertiesAndComponents = new ArrayList<>(); + propertiesAndComponents.addAll(properties); + propertiesAndComponents.addAll(components); + return propertiesAndComponents; + } + + /** + * @return Identifier of the Reference with Type HasTypeDefinition + */ + public BasicIdentifier getType() { + return type; + } + + /** + * see https://reference.opcfoundation.org/v104/Core/docs/Part3/5.2.4/ + * + * @return string part of the browse name + */ + public String getBrowseNameStringPart() { + return browseNameString; + } + + /** + * see https://reference.opcfoundation.org/v104/Core/docs/Part3/5.2.4/ + * + * @return namespace part of the browse name + */ + public int getBrowseNameNamespacePart() { + return browseNameNamespace; + } + + /** + * @param filterName string part of the I4AAS predefined browse name + * @return UANodeWrapper which is a component of the this UANodeWrapper and + * matches the given name + */ + public Optional getI4AASComponent(String filterName) { + return getComponents().stream().filter(c -> c.getBrowseNameNamespacePart() == ctx.getI4aasNsIdx() + && filterName.equals(c.getBrowseNameStringPart())).findFirst(); + } + + /** + * @param filterName string part of the I4AAS predefined browse name + * @return UANodeWrapper which is a property of the this UANodeWrapper and + * matches the given name + */ + public Optional getI4AASProperty(String filterName) { + return getProperties().stream().filter(c -> c.getBrowseNameNamespacePart() == ctx.getI4aasNsIdx() + && filterName.equals(c.getBrowseNameStringPart())).findFirst(); + } + + /** + * @param filterType filter type + * @return all UANodeWrapper which are components of the this UANodeWrapper and + * matches the given type + */ + public List getComponentsOfType(BasicIdentifier filterType) { + return getComponents().stream().filter(c -> c.getType() == filterType).collect(Collectors.toList()); + } + + /** + * @param filterType filter type + * @return all UANodeWrapper which are properties of the this UANodeWrapper and + * matches the given type + */ + public List getPropertiesOfType(BasicIdentifier filterType) { + return getProperties().stream().filter(c -> c.getType() == filterType).collect(Collectors.toList()); + } + + public UANode getNode() { + return node; + } + + public UAVariable getNodeVariable() { + return (UAVariable) node; + } + + public UAObject getNodeObject() { + return (UAObject) node; + } + +} diff --git a/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/AASExamples.java b/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/AASExamples.java new file mode 100644 index 00000000..93724f73 --- /dev/null +++ b/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/AASExamples.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas; + +import io.adminshell.aas.v3.model.AssetAdministrationShell; +import io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment; +import io.adminshell.aas.v3.model.AssetKind; +import io.adminshell.aas.v3.model.DataTypeIEC61360; +import io.adminshell.aas.v3.model.IdentifierType; +import io.adminshell.aas.v3.model.KeyElements; +import io.adminshell.aas.v3.model.KeyType; +import io.adminshell.aas.v3.model.LangString; +import io.adminshell.aas.v3.model.ModelingKind; +import io.adminshell.aas.v3.model.impl.DefaultAdministrativeInformation; +import io.adminshell.aas.v3.model.impl.DefaultAssetAdministrationShell; +import io.adminshell.aas.v3.model.impl.DefaultAssetAdministrationShellEnvironment; +import io.adminshell.aas.v3.model.impl.DefaultAssetInformation; +import io.adminshell.aas.v3.model.impl.DefaultDataSpecificationIEC61360; +import io.adminshell.aas.v3.model.impl.DefaultEmbeddedDataSpecification; +import io.adminshell.aas.v3.model.impl.DefaultFile; +import io.adminshell.aas.v3.model.impl.DefaultIdentifier; +import io.adminshell.aas.v3.model.impl.DefaultIdentifierKeyValuePair; +import io.adminshell.aas.v3.model.impl.DefaultKey; +import io.adminshell.aas.v3.model.impl.DefaultReference; + +public class AASExamples { + + private AASExamples() { + } + + private static final AssetAdministrationShell AAS_1 = new DefaultAssetAdministrationShell.Builder() + .idShort("aas_idshort") + .identification(new DefaultIdentifier.Builder().idType(IdentifierType.IRI) + .identifier("http://aas.org/example").build()) + .assetInformation(new DefaultAssetInformation.Builder().assetKind(AssetKind.INSTANCE) + .globalAssetId(new DefaultReference.Builder().key(new DefaultKey.Builder().type(KeyElements.ASSET) + .value("http://asset.org/example").idType(KeyType.IRI).build()).build()) + .specificAssetId(new DefaultIdentifierKeyValuePair.Builder().key("testkey").value("testvalue") + .externalSubjectId(new DefaultReference.Builder() + .key(new DefaultKey.Builder().type(KeyElements.GLOBAL_REFERENCE) + .value("http://externalsubjectid.org/example").idType(KeyType.IRI).build()) + .build()) + .build()) + .defaultThumbnail(new DefaultFile.Builder().kind(ModelingKind.INSTANCE).idShort("thumbnail") + .mimeType("image/png").value("http://image.org/example.png").build()) + .build()) + .administration( + new DefaultAdministrativeInformation.Builder().version("1.0").revision("b") + .embeddedDataSpecification(new DefaultEmbeddedDataSpecification.Builder() + .dataSpecification(new DefaultReference.Builder() + .key(new DefaultKey.Builder().type(KeyElements.CONCEPT_DESCRIPTION) + .value("http://dataspec.org/example").idType(KeyType.IRI).build()) + .build()) + .dataSpecificationContent(new DefaultDataSpecificationIEC61360.Builder() + .dataType(DataTypeIEC61360.BOOLEAN) + .definition(new LangString("en", "mydefinition")).symbol("iec61360_symbol") + .build()) + .build()) + .build()) + .build(); + + public static final AssetAdministrationShellEnvironment AAS_ENV_1 = new DefaultAssetAdministrationShellEnvironment.Builder() + .assetAdministrationShells(AAS_1).build(); +} diff --git a/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/AASFull.java b/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/AASFull.java index a5fbad80..bfad04ea 100644 --- a/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/AASFull.java +++ b/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/AASFull.java @@ -15,11 +15,52 @@ */ package io.adminshell.aas.v3.dataformat.i4aas; -import io.adminshell.aas.v3.model.*; -import io.adminshell.aas.v3.model.impl.*; import java.util.Base64; import java.util.List; +import io.adminshell.aas.v3.model.AssetAdministrationShell; +import io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment; +import io.adminshell.aas.v3.model.AssetKind; +import io.adminshell.aas.v3.model.ConceptDescription; +import io.adminshell.aas.v3.model.DataTypeIEC61360; +import io.adminshell.aas.v3.model.EntityType; +import io.adminshell.aas.v3.model.IdentifierType; +import io.adminshell.aas.v3.model.KeyElements; +import io.adminshell.aas.v3.model.KeyType; +import io.adminshell.aas.v3.model.LangString; +import io.adminshell.aas.v3.model.LevelType; +import io.adminshell.aas.v3.model.ModelingKind; +import io.adminshell.aas.v3.model.Submodel; +import io.adminshell.aas.v3.model.impl.DefaultAdministrativeInformation; +import io.adminshell.aas.v3.model.impl.DefaultAnnotatedRelationshipElement; +import io.adminshell.aas.v3.model.impl.DefaultAssetAdministrationShell; +import io.adminshell.aas.v3.model.impl.DefaultAssetAdministrationShellEnvironment; +import io.adminshell.aas.v3.model.impl.DefaultAssetInformation; +import io.adminshell.aas.v3.model.impl.DefaultBasicEvent; +import io.adminshell.aas.v3.model.impl.DefaultBlob; +import io.adminshell.aas.v3.model.impl.DefaultCapability; +import io.adminshell.aas.v3.model.impl.DefaultConceptDescription; +import io.adminshell.aas.v3.model.impl.DefaultDataSpecificationIEC61360; +import io.adminshell.aas.v3.model.impl.DefaultEmbeddedDataSpecification; +import io.adminshell.aas.v3.model.impl.DefaultEntity; +import io.adminshell.aas.v3.model.impl.DefaultFile; +import io.adminshell.aas.v3.model.impl.DefaultIdentifier; +import io.adminshell.aas.v3.model.impl.DefaultKey; +import io.adminshell.aas.v3.model.impl.DefaultMultiLanguageProperty; +import io.adminshell.aas.v3.model.impl.DefaultOperation; +import io.adminshell.aas.v3.model.impl.DefaultOperationVariable; +import io.adminshell.aas.v3.model.impl.DefaultProperty; +import io.adminshell.aas.v3.model.impl.DefaultQualifier; +import io.adminshell.aas.v3.model.impl.DefaultRange; +import io.adminshell.aas.v3.model.impl.DefaultReference; +import io.adminshell.aas.v3.model.impl.DefaultReferenceElement; +import io.adminshell.aas.v3.model.impl.DefaultRelationshipElement; +import io.adminshell.aas.v3.model.impl.DefaultSubmodel; +import io.adminshell.aas.v3.model.impl.DefaultSubmodelElementCollection; +import io.adminshell.aas.v3.model.impl.DefaultValueList; +import io.adminshell.aas.v3.model.impl.DefaultValueReferencePair; +import io.adminshell.aas.v3.model.impl.DefaultView; + public class AASFull { public static final java.io.File FILE = new java.io.File("src/test/resources/test_demo_full_example.json"); diff --git a/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/AASSimple.java b/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/AASSimple.java index ce1a2caf..774ce49b 100644 --- a/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/AASSimple.java +++ b/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/AASSimple.java @@ -15,14 +15,38 @@ */ package io.adminshell.aas.v3.dataformat.i4aas; -import io.adminshell.aas.v3.model.*; -import io.adminshell.aas.v3.model.impl.*; - import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import io.adminshell.aas.v3.model.AssetAdministrationShell; +import io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment; +import io.adminshell.aas.v3.model.AssetKind; +import io.adminshell.aas.v3.model.ConceptDescription; +import io.adminshell.aas.v3.model.DataTypeIEC61360; +import io.adminshell.aas.v3.model.IdentifierType; +import io.adminshell.aas.v3.model.KeyElements; +import io.adminshell.aas.v3.model.KeyType; +import io.adminshell.aas.v3.model.LangString; +import io.adminshell.aas.v3.model.ModelingKind; +import io.adminshell.aas.v3.model.Submodel; +import io.adminshell.aas.v3.model.impl.DefaultAdministrativeInformation; +import io.adminshell.aas.v3.model.impl.DefaultAssetAdministrationShell; +import io.adminshell.aas.v3.model.impl.DefaultAssetAdministrationShellEnvironment; +import io.adminshell.aas.v3.model.impl.DefaultAssetInformation; +import io.adminshell.aas.v3.model.impl.DefaultConceptDescription; +import io.adminshell.aas.v3.model.impl.DefaultDataSpecificationIEC61360; +import io.adminshell.aas.v3.model.impl.DefaultEmbeddedDataSpecification; +import io.adminshell.aas.v3.model.impl.DefaultFile; +import io.adminshell.aas.v3.model.impl.DefaultIdentifier; +import io.adminshell.aas.v3.model.impl.DefaultIdentifierKeyValuePair; +import io.adminshell.aas.v3.model.impl.DefaultKey; +import io.adminshell.aas.v3.model.impl.DefaultProperty; +import io.adminshell.aas.v3.model.impl.DefaultReference; +import io.adminshell.aas.v3.model.impl.DefaultSubmodel; +import io.adminshell.aas.v3.model.impl.DefaultSubmodelElementCollection; + public class AASSimple { private static final String DOCUMENT_DEF = "Feste und geordnete Menge von für die Verwendung durch Personen bestimmte Informationen, die verwaltet und als Einheit zwischen Benutzern und System ausgetauscht werden kann."; diff --git a/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/DeserializerTest.java b/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/DeserializerTest.java index aa8f5d70..fb5c75b1 100644 --- a/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/DeserializerTest.java +++ b/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/DeserializerTest.java @@ -29,7 +29,6 @@ public class DeserializerTest { @Test - @Ignore public void testAASSimple() throws SerializationException, IllegalArgumentException, IllegalAccessException, DeserializationException, IOException { //arrange diff --git a/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/IntegrationTests.java b/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/IntegrationTests.java new file mode 100644 index 00000000..1d7404c7 --- /dev/null +++ b/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/IntegrationTests.java @@ -0,0 +1,228 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import io.adminshell.aas.v3.dataformat.DeserializationException; +import io.adminshell.aas.v3.dataformat.SerializationException; +import io.adminshell.aas.v3.dataformat.i4aas.mappers.MappingContext; +import io.adminshell.aas.v3.model.Asset; +import io.adminshell.aas.v3.model.AssetAdministrationShell; +import io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment; +import io.adminshell.aas.v3.model.AssetInformation; +import io.adminshell.aas.v3.model.AssetKind; +import io.adminshell.aas.v3.model.Blob; +import io.adminshell.aas.v3.model.ConceptDescription; +import io.adminshell.aas.v3.model.IdentifierKeyValuePair; +import io.adminshell.aas.v3.model.IdentifierType; +import io.adminshell.aas.v3.model.KeyType; +import io.adminshell.aas.v3.model.LangString; +import io.adminshell.aas.v3.model.MultiLanguageProperty; +import io.adminshell.aas.v3.model.Submodel; +import io.adminshell.aas.v3.model.SubmodelElementCollection; +import io.adminshell.aas.v3.model.impl.DefaultAsset; +import io.adminshell.aas.v3.model.impl.DefaultAssetAdministrationShell; +import io.adminshell.aas.v3.model.impl.DefaultAssetAdministrationShellEnvironment; +import io.adminshell.aas.v3.model.impl.DefaultAssetInformation; +import io.adminshell.aas.v3.model.impl.DefaultBlob; +import io.adminshell.aas.v3.model.impl.DefaultConceptDescription; +import io.adminshell.aas.v3.model.impl.DefaultFile; +import io.adminshell.aas.v3.model.impl.DefaultIdentifier; +import io.adminshell.aas.v3.model.impl.DefaultIdentifierKeyValuePair; +import io.adminshell.aas.v3.model.impl.DefaultKey; +import io.adminshell.aas.v3.model.impl.DefaultMultiLanguageProperty; +import io.adminshell.aas.v3.model.impl.DefaultReference; +import io.adminshell.aas.v3.model.impl.DefaultSubmodel; +import io.adminshell.aas.v3.model.impl.DefaultSubmodelElementCollection; + +public class IntegrationTests { + + private I4AASSerializer serializer; + private I4AASDeserializer deserializer; + + private AssetAdministrationShellEnvironment env; + private AssetAdministrationShell aas; + private Asset asset; + private Submodel sm; + private ConceptDescription cd; + + @Before + public void before() { + MappingContext.setModelNamespaceNamingStrategy(nodeset -> "http://example.org/IntegrationTest"); + serializer = new I4AASSerializer(); + deserializer = new I4AASDeserializer(); + + // test frame model + env = new DefaultAssetAdministrationShellEnvironment(); + aas = new DefaultAssetAdministrationShell(); + asset = new DefaultAsset(); + sm = new DefaultSubmodel(); + cd = new DefaultConceptDescription(); + env.getAssetAdministrationShells().add(aas); + env.getAssets().add(asset); + env.getSubmodels().add(sm); + env.getConceptDescriptions().add(cd); + } + + @Test + public void testBlobWithSemantics() throws SerializationException, DeserializationException { + // ARRANGE + Blob blob = new DefaultBlob(); + blob.setMimeType("testmime"); + blob.setValue("testvalue".getBytes()); + blob.setIdShort("testblob"); + + blob.setSemanticId(new DefaultReference.Builder() + .key(new DefaultKey.Builder().value("mySemanticId").idType(KeyType.CUSTOM).build()).build()); + + sm.getSubmodelElements().add(blob); + + // ACT + AssetAdministrationShellEnvironment result = inAndOut(); + + // ASSERT + Blob submodelElement = (Blob) result.getSubmodels().get(0).getSubmodelElements().get(0); + Assert.assertEquals(blob.getMimeType(), submodelElement.getMimeType()); + Assert.assertEquals(blob.getIdShort(), submodelElement.getIdShort()); + Assert.assertArrayEquals(blob.getValue(), submodelElement.getValue()); + + Assert.assertEquals("mySemanticId", submodelElement.getSemanticId().getKeys().get(0).getValue()); + Assert.assertEquals(KeyType.CUSTOM, submodelElement.getSemanticId().getKeys().get(0).getIdType()); + } + + @Test + public void testMultiLanguageProperty() throws SerializationException, DeserializationException { + // ARRANGE + MultiLanguageProperty defaultMultiLanguageProperty = new DefaultMultiLanguageProperty(); + defaultMultiLanguageProperty.setIdShort("mymultilang"); + + List values = new ArrayList<>(); + values.add(new LangString("de", "delang")); + values.add(new LangString("en", "enlang")); + defaultMultiLanguageProperty.setValues(values); + sm.getSubmodelElements().add(defaultMultiLanguageProperty); + + // ACT + AssetAdministrationShellEnvironment result = inAndOut(); + + // ASSERT + MultiLanguageProperty submodelElement = (MultiLanguageProperty) result.getSubmodels().get(0) + .getSubmodelElements().get(0); + Assert.assertEquals("de", submodelElement.getValues().get(0).getLanguage()); + Assert.assertEquals("delang", submodelElement.getValues().get(0).getValue()); + Assert.assertEquals("en", submodelElement.getValues().get(1).getLanguage()); + Assert.assertEquals("enlang", submodelElement.getValues().get(1).getValue()); + } + + @Test + public void testSMECollection() throws SerializationException, DeserializationException { + // ARRANGE + SubmodelElementCollection smec = new DefaultSubmodelElementCollection(); + smec.setIdShort("collection"); + smec.setAllowDuplicates(true); + smec.setOrdered(true); + + Blob blob = new DefaultBlob(); + blob.setMimeType("testmime"); + blob.setValue("testvalue".getBytes()); + blob.setIdShort("testblob"); + + smec.getValues().add(blob); + sm.getSubmodelElements().add(smec); + + // ACT + AssetAdministrationShellEnvironment result = inAndOut(); + + // ASSERT + SubmodelElementCollection submodelElement = (SubmodelElementCollection) result.getSubmodels().get(0) + .getSubmodelElements().get(0); + Assert.assertEquals(true, submodelElement.getAllowDuplicates()); + Assert.assertEquals(true, submodelElement.getOrdered()); + Object[] smecContent = submodelElement.getValues().toArray(); + Assert.assertEquals("testblob", ((Blob) smecContent[0]).getIdShort()); + + } + + @Test + public void testAssetInformation() throws SerializationException, DeserializationException { + // ARRANGE + DefaultAssetInformation defaultAssetInformation = new DefaultAssetInformation(); + defaultAssetInformation.setAssetKind(AssetKind.TYPE); + defaultAssetInformation.setDefaultThumbnail(new DefaultFile.Builder().value("/path/to/img.png").build()); + List list = new ArrayList<>(); + list.add(new DefaultIdentifierKeyValuePair.Builder().key("mykey").value("myvalue").build()); + defaultAssetInformation.setSpecificAssetIds(list); + aas.setAssetInformation(defaultAssetInformation); + + // ACT + AssetAdministrationShellEnvironment result = inAndOut(); + + // ASSERT + AssetInformation assetInformationResult = result.getAssetAdministrationShells().get(0).getAssetInformation(); + Assert.assertEquals(defaultAssetInformation.getAssetKind(), assetInformationResult.getAssetKind()); + Assert.assertEquals(defaultAssetInformation.getDefaultThumbnail().getValue(), + assetInformationResult.getDefaultThumbnail().getValue()); + Assert.assertEquals(defaultAssetInformation.getSpecificAssetIds().get(0).getKey(), + assetInformationResult.getSpecificAssetIds().get(0).getKey()); + } + + @Test + public void testConceptDescription() throws SerializationException, DeserializationException { + // ARRANGE + cd.setIdentification(new DefaultIdentifier.Builder().identifier("myCD").idType(IdentifierType.CUSTOM).build()); + cd.getIsCaseOfs().add(new DefaultReference.Builder() + .key(new DefaultKey.Builder().value("myCaseOfRef").idType(KeyType.CUSTOM).build()).build()); + + // ACT + AssetAdministrationShellEnvironment result = inAndOut(); + + // ASSERT + ConceptDescription conceptDescription = result.getConceptDescriptions().get(0); + Assert.assertEquals(cd.getIdentification(), conceptDescription.getIdentification()); + Assert.assertEquals(cd.getIsCaseOfs().get(0).getKeys().get(0).getValue(), + conceptDescription.getIsCaseOfs().get(0).getKeys().get(0).getValue()); + } + + @Test + public void testAASFull() throws SerializationException, DeserializationException { + // ARRANGE + Assert.assertEquals(4, AASFull.ENVIRONMENT.getAssetAdministrationShells().size()); + Assert.assertEquals(7, AASFull.ENVIRONMENT.getSubmodels().size()); + Assert.assertEquals(4, AASFull.ENVIRONMENT.getConceptDescriptions().size()); + + // ACT + serializer = new I4AASSerializer(false); //false = do not add semanticIds automaitcally to concept description + deserializer = new I4AASDeserializer(); + AssetAdministrationShellEnvironment result = deserializer.read(serializer.write(AASFull.ENVIRONMENT)); + + // ASSERT + Assert.assertEquals(4, result.getAssetAdministrationShells().size()); + Assert.assertEquals(7, result.getSubmodels().size()); + Assert.assertEquals(4, result.getConceptDescriptions().size()); + } + + public AssetAdministrationShellEnvironment inAndOut() throws SerializationException, DeserializationException { + AssetAdministrationShellEnvironment out = deserializer.read(serializer.write(env)); + return out; + } + +} diff --git a/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/TestUANodeset.java b/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/TestUANodeset.java new file mode 100644 index 00000000..0af7df85 --- /dev/null +++ b/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/TestUANodeset.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas; + +import java.io.InputStream; + +import javax.xml.bind.JAXBException; + +import org.opcfoundation.ua._2011._03.uanodeset.UANodeSet; + +import io.adminshell.aas.v3.dataformat.i4aas.parsers.ParserContextTest; + +public class TestUANodeset { + + public static UANodeSet AAS_SIMPLE_V3_DRAFT; + + public static UANodeSet AAS_EXAMPLE_1; + + static { + AAS_SIMPLE_V3_DRAFT = readFromFile("/AASSimple_V3Draft.xml"); + + String i4aasString; + try { + i4aasString = new I4AASSerializer().write(AASExamples.AAS_ENV_1); + AAS_EXAMPLE_1 = readFromString(i4aasString); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static UANodeSet getAASSimpleV3Draft() { + return AAS_SIMPLE_V3_DRAFT; + } + + public static UANodeSet readFromFile(String name) { + try (InputStream testResourceAsStream = ParserContextTest.class.getResourceAsStream(name)) { + UANodeSet uaNodeSet = new UANodeSetUnmarshaller().unmarshall(testResourceAsStream); + return uaNodeSet; + } catch (Exception e) { + throw new IllegalArgumentException("test resource '" + name + "' is not available", e); + } + } + + + public static UANodeSet readFromString(String input) { + UANodeSet uaNodeSet = null; + try { + uaNodeSet = new UANodeSetUnmarshaller().unmarshall(input); + } catch (JAXBException e) { + e.printStackTrace(); + } + return uaNodeSet; + } +} diff --git a/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/SubmodelMapperTest.java b/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/SubmodelMapperTest.java index 74e8d4b2..cf8c4d8f 100644 --- a/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/SubmodelMapperTest.java +++ b/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/mappers/SubmodelMapperTest.java @@ -15,11 +15,9 @@ */ package io.adminshell.aas.v3.dataformat.i4aas.mappers; -import static org.junit.Assert.*; import javax.xml.bind.JAXBException; -import org.junit.Assert; import org.junit.Test; import org.opcfoundation.ua._2011._03.uanodeset.UANodeSet; import org.opcfoundation.ua._2011._03.uanodeset.UAObject; @@ -36,7 +34,6 @@ public void test() throws JAXBException { UAObject map = tesling.map(); UANodeSet nodeSet = tesling.ctx.getNodeSet(); String marshallAsString = new UANodeSetMarshaller(nodeSet).marshallAsString(); - //System.out.println(marshallAsString); } } diff --git a/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/EnvironmentParserTest.java b/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/EnvironmentParserTest.java new file mode 100644 index 00000000..5bd9ab29 --- /dev/null +++ b/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/EnvironmentParserTest.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; + +import io.adminshell.aas.v3.dataformat.i4aas.TestUANodeset; +import io.adminshell.aas.v3.model.AdministrativeInformation; +import io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment; +import io.adminshell.aas.v3.model.DataSpecificationContent; +import io.adminshell.aas.v3.model.DataSpecificationIEC61360; +import io.adminshell.aas.v3.model.IdentifierType; +import io.adminshell.aas.v3.model.Reference; + +public class EnvironmentParserTest { + + @Test + public void testEnvironmentParser() { + ParserContext context = new ParserContext(TestUANodeset.getAASSimpleV3Draft()); + AssetAdministrationShellEnvironment aasEnv = new EnvironmentParser(context.getEnvironment(), context).parse(); + + // test referable + String aasIdShort = aasEnv.getAssetAdministrationShells().get(0).getIdShort(); + Assert.assertEquals("ExampleMotor", aasIdShort); + Assert.assertEquals("", aasEnv.getAssetAdministrationShells().get(0).getCategory()); + + // test identifiable + Assert.assertEquals("http://customer.com/aas/9175_7013_7091_9168", + aasEnv.getAssetAdministrationShells().get(0).getIdentification().getIdentifier()); + Assert.assertEquals(IdentifierType.IRI, + aasEnv.getAssetAdministrationShells().get(0).getIdentification().getIdType()); + } + + @Test + public void testAdministrativeParser() { + ParserContext context = new ParserContext(TestUANodeset.AAS_EXAMPLE_1); + AssetAdministrationShellEnvironment aasEnv = new EnvironmentParser(context.getEnvironment(), context).parse(); + + // test referable + AdministrativeInformation adminInfo = aasEnv.getAssetAdministrationShells().get(0).getAdministration(); + Assert.assertEquals("1.0", adminInfo.getVersion()); + Assert.assertEquals("b", adminInfo.getRevision()); + + Reference dataSpecification = adminInfo.getEmbeddedDataSpecifications().get(0).getDataSpecification(); + DataSpecificationContent dataSpecificationContent = adminInfo.getEmbeddedDataSpecifications().get(0) + .getDataSpecificationContent(); + + Assert.assertTrue(dataSpecificationContent instanceof DataSpecificationIEC61360); + Assert.assertEquals("http://dataspec.org/example", dataSpecification.getKeys().get(0).getValue()); + Assert.assertEquals("iec61360_symbol", ((DataSpecificationIEC61360) dataSpecificationContent).getSymbol()); + Assert.assertEquals("mydefinition", ((DataSpecificationIEC61360) dataSpecificationContent).getDefinitions().get(0).getValue()); + } + + @Test + public void testSubmodelReferenceParser() { + ParserContext context = new ParserContext(TestUANodeset.getAASSimpleV3Draft()); + AssetAdministrationShellEnvironment aasEnv = new EnvironmentParser(context.getEnvironment(), context).parse(); + + List smReferences = aasEnv.getAssetAdministrationShells().get(0).getSubmodels(); + Assert.assertEquals(3, smReferences.size()); + + Assert.assertNotNull(smReferences.get(0).getKeys().get(0).getValue()); + Assert.assertNotNull(smReferences.get(0).getKeys().get(0).getIdType()); + Assert.assertNotNull(smReferences.get(0).getKeys().get(0).getType()); + } +} diff --git a/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/ParserContextTest.java b/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/ParserContextTest.java new file mode 100644 index 00000000..9620de31 --- /dev/null +++ b/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/ParserContextTest.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; +import java.io.InputStream; + +import javax.xml.bind.JAXBException; + +import org.junit.Test; +import org.opcfoundation.ua._2011._03.uanodeset.UANodeSet; + +import io.adminshell.aas.v3.dataformat.i4aas.UANodeSetUnmarshaller; +import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; + +public class ParserContextTest { + + @Test + public void testGetPreparsedEnvironment() throws IOException, JAXBException { + try (InputStream testResourceAsStream = ParserContextTest.class.getResourceAsStream("/AASSimple_V3Draft.xml")) { + UANodeSet uaNodeSet = new UANodeSetUnmarshaller().unmarshall(testResourceAsStream); + ParserContext parserContext = new ParserContext(uaNodeSet); + assertEquals(2, parserContext.getI4aasNsIdx()); + UANodeWrapper preparsedEnvironment = parserContext.getEnvironment(); + assertNotNull(preparsedEnvironment); + assertEquals("ns=1;i=1", preparsedEnvironment.getNodeId()); + assertEquals(4, preparsedEnvironment.getComponents().size()); + assertEquals(I4AASIdentifier.AASEnvironmentType, preparsedEnvironment.getType()); + assertFalse(preparsedEnvironment.getComponentsOfType(I4AASIdentifier.AASSubmodelType).isEmpty()); + } + + } + +} \ No newline at end of file diff --git a/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/TypeResolverTest.java b/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/TypeResolverTest.java new file mode 100644 index 00000000..78908556 --- /dev/null +++ b/dataformat-uanodeset/src/test/java/io/adminshell/aas/v3/dataformat/i4aas/parsers/TypeResolverTest.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.adminshell.aas.v3.dataformat.i4aas.parsers; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.Optional; + +import org.junit.Test; + +import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.BasicIdentifier; +import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.I4AASIdentifier; +import io.adminshell.aas.v3.dataformat.i4aas.mappers.utils.UaIdentifier; + +public class TypeResolverTest { + + @Test + public void testGetBasicType() { + TypeResolver typeResolver = new TypeResolver(5); + Optional type = typeResolver.getType("i=" + UaIdentifier.FolderType.getId()); + assertFalse(type.isEmpty()); + assertTrue(UaIdentifier.FolderType == type.get()); + } + + @Test + public void testGetI4aasType() { + TypeResolver typeResolver = new TypeResolver(5); + Optional type = typeResolver.getType("ns=5;i=" + I4AASIdentifier.AASSubmodelType.getId()); + assertFalse(type.isEmpty()); + assertTrue(I4AASIdentifier.AASSubmodelType == type.get()); + } +} \ No newline at end of file diff --git a/dataformat-uanodeset/src/test/resources/AASSimple_V3Draft.xml b/dataformat-uanodeset/src/test/resources/AASSimple_V3Draft.xml index e6ac0e25..68404f7d 100644 --- a/dataformat-uanodeset/src/test/resources/AASSimple_V3Draft.xml +++ b/dataformat-uanodeset/src/test/resources/AASSimple_V3Draft.xml @@ -5,7 +5,7 @@ http://opcfoundation.org/UA/I4AAS/V3/ - + @@ -93,7 +93,7 @@ ns=1;i=153 - + Title ns=2;i=1025 @@ -160,8 +160,8 @@ ns=1;i=9 - - embedded_0 + + Content_0 ns=2;i=1028 ns=1;i=10 @@ -263,7 +263,7 @@ ns=1;i=2 - + DigitalFile ns=2;i=1025 @@ -330,8 +330,8 @@ ns=1;i=24 - - embedded_0 + + Content_0 ns=2;i=1028 ns=1;i=25 @@ -433,7 +433,7 @@ ns=1;i=17 - + MaxRotationSpeed ns=2;i=1024 @@ -530,8 +530,8 @@ ns=1;i=42 - - embedded_0 + + Content_0 ns=2;i=1028 ns=1;i=43 @@ -660,7 +660,7 @@ ns=1;i=32 - + RotationSpeed ns=2;i=1025 @@ -727,8 +727,8 @@ ns=1;i=59 - - embedded_0 + + Content_0 ns=2;i=1028 ns=1;i=60 @@ -866,7 +866,7 @@ ns=1;i=52 - + Document ns=2;i=1025 @@ -933,8 +933,8 @@ ns=1;i=76 - - embedded_0 + + Content_0 ns=2;i=1028 ns=1;i=77 @@ -1027,7 +1027,7 @@ ns=1;i=69 - + Submodel:TechnicalData ns=2;i=1006 @@ -1099,7 +1099,7 @@ 1 - + 0173-1#01-AFZ615#016 ns=2;i=1024 @@ -1254,7 +1254,7 @@ ns=1;i=84 - + Submodel:Documentation ns=2;i=1006 @@ -1534,7 +1534,7 @@ ns=1;i=108 - + Submodel:OperationalData ns=2;i=1006 diff --git a/pom.xml b/pom.xml index 523aef2f..59eb36ca 100644 --- a/pom.xml +++ b/pom.xml @@ -41,8 +41,8 @@ 1.0.2 ${revision} - 1.8 - 1.8 + 11 + 11 UTF-8 UTF-8 1.2.2