Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Adjust FileMapper to read id short and ViewMapper to use attribute path
Browse files Browse the repository at this point in the history
  • Loading branch information
JensMueller2709 committed Sep 15, 2021
1 parent f3169a0 commit e798a87
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.adminshell.aas.v3.dataformat.core.util.AasUtils;
import io.adminshell.aas.v3.dataformat.mapping.MappingException;
import io.adminshell.aas.v3.model.File;

import java.beans.PropertyDescriptor;
import java.util.List;

Expand All @@ -35,8 +36,8 @@ public class FileMapper extends DefaultMapper<File> {
protected static PropertyDescriptor PROPERTY_MIME_TYPE = AasUtils.getProperty(File.class, "mimeType");

private static final String FILE_DATA_REFERENCE = "AssetAdministrationShellInterfaceClassLib/FileDataReference";
private static final String MIME_TYPE_ATTRIBUTE_NAME = "MIMEType";
private static final String REF_URI_ATTRIBUTE_NAME = "refUri";
private static final String MIME_TYPE_ATTRIBUTE_PATH = "AAS:File/MIMEType";
private static final String REF_URI_ATTRIBUTE_PATH = "AAS:File/refURI";

public FileMapper() {
super(PROPERTY_VALUE.getName(), PROPERTY_MIME_TYPE.getName());
Expand All @@ -56,11 +57,12 @@ protected void mapProperties(Object parent, AmlParser parser, MappingContext con
throw new MappingException(String.format("multiple external interfaces are found in file %s %s", parser.getCurrent().getID(), parser.getCurrent().getName()));

List<AttributeType> attributeTypes = externalInterfaces.get(0).getAttribute();

AttributeType mimeTypeAttribute = attributeTypes.stream()
.filter(x -> x.getName().equalsIgnoreCase(MIME_TYPE_ATTRIBUTE_NAME))
.filter(x -> x.getRefSemantic().get(0).getCorrespondingAttributePath().equalsIgnoreCase(MIME_TYPE_ATTRIBUTE_PATH))
.findFirst().orElse(null);
AttributeType refUriAttribute = attributeTypes.stream()
.filter(x -> x.getName().equalsIgnoreCase(REF_URI_ATTRIBUTE_NAME)).findFirst().orElse(null);
.filter(x -> x.getRefSemantic().get(0).getCorrespondingAttributePath().equalsIgnoreCase(REF_URI_ATTRIBUTE_PATH)).findFirst().orElse(null);

if (refUriAttribute != null)
((File) parent).setValue(refUriAttribute.getValue() == null ? null : refUriAttribute.getValue().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@
public class ViewMapper extends DefaultMapper<View> {

private static final String CONTAINED_ELEMENTS = "containedElements";
private static final PropertyDescriptor PROPERTY_VALUE_TYPE = AasUtils.getProperty(View.class, "idShort");

public ViewMapper() {
super(PROPERTY_VALUE_TYPE.getName());
}

@Override
protected void mapProperties(Object parent, AmlParser parser, MappingContext context) throws MappingException {
Expand All @@ -47,9 +42,6 @@ protected void mapProperties(Object parent, AmlParser parser, MappingContext con
if (!InternalElementType.class.isAssignableFrom(parser.getCurrent().getClass())) return;
InternalElementType internalElementType_View = (InternalElementType) parser.getCurrent();

//TODO remove after adjustment of serializer
((View) parent).setIdShort(internalElementType_View.getName());

List<InternalElementType> internalElementTypeList = internalElementType_View.getInternalElement();
internalElementTypeList.stream().forEach(x -> {
String idToReference = x.getRefBaseSystemUnitPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ private void swapSubmodelIdx(AssetAdministrationShellEnvironment env, int idxSrc
private void adaptSubmodels(AssetAdministrationShellEnvironment env) {
//non referenced submodels are not considered in AML
List<String> submodelIds = new ArrayList<>();
env.getAssetAdministrationShells().stream().forEach(x -> x.getSubmodels().stream().forEach(y -> y.getKeys().stream().forEach(z ->submodelIds.add(z.getValue()))));
env.getAssetAdministrationShells().stream().forEach(
x -> x.getSubmodels().stream()
.forEach(y -> y.getKeys().stream().forEach(z ->submodelIds.add(z.getValue()))));

List<Submodel> referencedSubmodels = env.getSubmodels().stream().filter(x -> submodelIds.contains(x.getIdentification().getIdentifier())).collect(Collectors.toList());
env.setSubmodels(referencedSubmodels);
Expand Down

0 comments on commit e798a87

Please sign in to comment.