Skip to content

Commit

Permalink
Fixes SubmodelElements in JSON returned by /aas/submodels (#62)
Browse files Browse the repository at this point in the history
SubmodelElements in JSON response from /aas/submodels were represented as Map and not as List

Signed-off-by: Maximilian Conradi <[email protected]>
  • Loading branch information
mconradi-iese authored Mar 21, 2022
1 parent 843878f commit f63f35a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.basyx.submodel.aggregator.api.ISubmodelAggregator;
import org.eclipse.basyx.submodel.metamodel.api.ISubmodel;
import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
import org.eclipse.basyx.submodel.metamodel.facade.SubmodelElementMapCollectionConverter;
import org.eclipse.basyx.submodel.metamodel.map.Submodel;
import org.eclipse.basyx.submodel.restapi.SubmodelProvider;
import org.eclipse.basyx.submodel.restapi.api.ISubmodelAPI;
Expand Down Expand Up @@ -291,7 +292,7 @@ private Object retrieveSubmodels() throws ProviderException {
// Make a list and return all local submodels
Collection<ISubmodel> submodels = getSmAggregator().getSubmodelList();
addConnectedSubmodels(submodels);
return submodels;
return submodels.stream().map(sm -> SubmodelElementMapCollectionConverter.smToMap((Submodel) sm)).collect(Collectors.toList());
}

private void addConnectedSubmodels(Collection<ISubmodel> submodels) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.eclipse.basyx.aas.metamodel.api.parts.asset.AssetKind;
import org.eclipse.basyx.aas.metamodel.connected.ConnectedAssetAdministrationShell;
Expand All @@ -22,6 +25,8 @@
import org.eclipse.basyx.submodel.metamodel.api.reference.IReference;
import org.eclipse.basyx.submodel.metamodel.map.Submodel;
import org.eclipse.basyx.submodel.metamodel.map.identifier.Identifier;
import org.eclipse.basyx.submodel.metamodel.map.modeltype.ModelType;
import org.eclipse.basyx.submodel.metamodel.map.submodelelement.SubmodelElementCollection;
import org.eclipse.basyx.submodel.metamodel.map.submodelelement.dataelement.property.Property;
import org.eclipse.basyx.submodel.metamodel.map.submodelelement.dataelement.property.valuetype.ValueType;
import org.eclipse.basyx.submodel.metamodel.map.submodelelement.operation.Operation;
Expand Down Expand Up @@ -196,6 +201,22 @@ public void createDeleteSubmodelTest() {
}
}

/**
* Tests if SubmodelElements are returned as a List in Submodel and SubmodelElementCollection and not as Map
*/
@SuppressWarnings("unchecked")
@Test
public void submodelElementsAreContainedAsList() {
List<Map<String, Object>> submodels = (List<Map<String, Object>>) proxy.getValue("/aas/submodels");
Map<String, Object> submodel = submodels.get(0);
assertTrue(submodel.get(Submodel.SUBMODELELEMENT) instanceof List<?>);
List<Map<String, Object>> smCollections = ((List<Map<String, Object>>) submodel.get(Submodel.SUBMODELELEMENT))
.stream()
.filter(e -> ModelType.createAsFacade(e).getName().equals(SubmodelElementCollection.MODELTYPE))
.collect(Collectors.toList());
assertTrue(smCollections.get(0).get(Property.VALUE) instanceof List<?>);
}

@Test
public void invalidPathPrefixDeleteTest() {
Submodel sm = new SimpleAASSubmodel("TestSM");
Expand Down

0 comments on commit f63f35a

Please sign in to comment.