Skip to content

Commit

Permalink
Merge pull request #459 from bci-oss/fix_#432_several_aas_issues_hind…
Browse files Browse the repository at this point in the history
…ering_import_to_aas_package_explorer

Fix #432 several aas issues hindering import to aas package explorer
  • Loading branch information
atextor authored Nov 9, 2023
2 parents ae9f5ae + 647dc6e commit ae63e63
Show file tree
Hide file tree
Showing 5 changed files with 256 additions and 235 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import org.eclipse.esmf.metamodel.Aspect;

import com.fasterxml.jackson.databind.JsonNode;
import org.eclipse.digitaltwin.aas4j.v3.dataformat.SerializationException;
import org.eclipse.digitaltwin.aas4j.v3.dataformat.Serializer;
import org.eclipse.digitaltwin.aas4j.v3.dataformat.aasx.AASXSerializer;
Expand All @@ -29,17 +32,14 @@
import org.eclipse.digitaltwin.aas4j.v3.model.Submodel;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultEnvironment;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodel;
import org.eclipse.esmf.metamodel.Aspect;

import com.fasterxml.jackson.databind.JsonNode;

/**
* Generator that generates an AASX file containing an AAS submodel for a given Aspect model
*/
public class AspectModelAASGenerator {

/**
* Generates an AASX archive file for a given Aspect and writes it to a given OutputStream provided by <code>nameMapper<code/>
* Generates an AASX archive file for a given Aspect and writes it to a given OutputStream provided by {@code nameMapper}
*
* @param aspect the Aspect for which an AASX archive shall be generated
* @param nameMapper a Name Mapper implementation, which provides an OutputStream for a given filename
Expand All @@ -53,7 +53,7 @@ public void generateAASXFile( final Aspect aspect, final Function<String, Output
}

/**
* Generates an AAS XML archive file for a given Aspect and writes it to a given OutputStream provided by <code>nameMapper<code/>
* Generates an AAS XML archive file for a given Aspect and writes it to a given OutputStream provided by {@code nameMapper}
*
* @param aspect the Aspect for which an xml file shall be generated
* @param nameMapper a Name Mapper implementation, which provides an OutputStream for a given filename
Expand All @@ -74,7 +74,7 @@ public void generateAasXmlFile(
}

/**
* Generates an AAS JSON file for a given Aspect and writes it to a given OutputStream provided by <code>nameMapper<code/>
* Generates an AAS JSON file for a given Aspect and writes it to a given OutputStream provided by {@code nameMapper}
*
* @param aspect the Aspect for which an JSON shall be generated
* @param nameMapper a Name Mapper implementation, which provides an OutputStream for a given filename
Expand All @@ -94,7 +94,8 @@ protected ByteArrayOutputStream generateXmlOutput( final Map<Aspect, JsonNode> a
aspectsWithData.entrySet().stream()
.map( aspectWithData -> {
final Submodel submodel = new DefaultSubmodel.Builder().build();
final Environment environment = new DefaultEnvironment.Builder().submodels( Collections.singletonList( submodel ) ).build();
final Environment environment = new DefaultEnvironment.Builder().submodels( Collections.singletonList( submodel ) )
.build();
final Context context = new Context( environment, submodel );
context.setEnvironment( environment );
context.setAspectData( aspectWithData.getValue() );
Expand All @@ -113,9 +114,9 @@ protected ByteArrayOutputStream generateXmlOutput( final Map<Aspect, JsonNode> a
}

private Environment mergeEnvironments( final Map<Aspect, Environment> aspectEnvironments ) {
final Submodel submodel = new DefaultSubmodel.Builder().build();
return new DefaultEnvironment.Builder()
.assetAdministrationShells( aspectEnvironments.values().stream().flatMap( e -> e.getAssetAdministrationShells().stream() ).toList() )
.assetAdministrationShells(
aspectEnvironments.values().stream().flatMap( e -> e.getAssetAdministrationShells().stream() ).toList() )
.submodels( aspectEnvironments.values().stream().flatMap( e -> e.getSubmodels().stream() ).toList() )
.conceptDescriptions( aspectEnvironments.values().stream().flatMap( e -> e.getConceptDescriptions().stream() ).toList() )
.build();
Expand All @@ -138,11 +139,11 @@ protected ByteArrayOutputStream generateXmlOutput( final Aspect aspect ) throws
return generate( new XmlSerializer(), aspect );
}

protected ByteArrayOutputStream generateJsonOutput( Aspect aspect ) throws IOException {
protected ByteArrayOutputStream generateJsonOutput( final Aspect aspect ) throws IOException {
return generate( new JsonSerializer(), aspect );
}

protected ByteArrayOutputStream generate( Serializer serializer, Aspect aspect ) throws IOException {
protected ByteArrayOutputStream generate( final Serializer serializer, final Aspect aspect ) throws IOException {
final AspectModelAASVisitor visitor = new AspectModelAASVisitor();
final Environment environment = visitor.visitAspect( aspect, null );

Expand Down
Loading

0 comments on commit ae63e63

Please sign in to comment.