Skip to content

Commit

Permalink
Merge pull request #153 from carlos-schmidt/feat/operation-variables-…
Browse files Browse the repository at this point in the history
…to-self-description

Add operation variables to self description
  • Loading branch information
carlos-schmidt authored Oct 26, 2024
2 parents ec4ef73 + 36e8653 commit fd48f52
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,18 @@
package de.fraunhofer.iosb.app.aas.mapper;

import de.fraunhofer.iosb.model.aas.AasProvider;
import org.eclipse.digitaltwin.aas4j.v3.model.Operation;
import org.eclipse.digitaltwin.aas4j.v3.model.Reference;
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement;
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementCollection;
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementList;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultEmbeddedDataSpecification;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultReference;
import org.eclipse.edc.connector.controlplane.asset.spi.domain.Asset;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
* Not an ElementMapper since we have a different method signature.
Expand Down Expand Up @@ -59,18 +57,28 @@ <E extends SubmodelElement> Asset map(Reference parent, E submodelElement, AasPr
.map(Class::getSimpleName)
.orElse("SubmodelElement");

var additionalProperties = new HashMap<>(Map.of(
"modelingType", modelingType,
"value", children));

if (submodelElement.getEmbeddedDataSpecifications() != null) {
additionalProperties.put("embeddedDataSpecifications", submodelElement.getEmbeddedDataSpecifications());
}

if (submodelElement.getSemanticId() != null) {
additionalProperties.put("semanticId", submodelElement.getSemanticId());
}

if (submodelElement instanceof Operation operation) {
additionalProperties.put("inputVariables", operation.getInputVariables());
additionalProperties.put("inoutputVariables", operation.getInoutputVariables());
additionalProperties.put("outputVariables", operation.getOutputVariables());
}

return elementMapper.mapReferableToAssetBuilder(submodelElement)
.id(elementMapper.getId(dataAddress))
.contentType("application/json")
.properties(Map.of(
"embeddedDataSpecifications",
Optional.ofNullable(submodelElement.getEmbeddedDataSpecifications())
.orElse(List.of(new DefaultEmbeddedDataSpecification())),
"semanticId",
Optional.ofNullable(submodelElement.getSemanticId())
.orElse(new DefaultReference()),
"modelingType", modelingType,
"value", children))
.properties(additionalProperties)
.dataAddress(dataAddress)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package de.fraunhofer.iosb.app.aas.mapper;

import de.fraunhofer.iosb.model.aas.service.Service;
import org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes;
import org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultKey;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultOperation;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultOperationVariable;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultReference;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import static de.fraunhofer.iosb.app.testutils.AasCreator.getProperty;
import static org.junit.jupiter.api.Assertions.assertEquals;

class SubmodelElementMapperTest {

private SubmodelElementMapper testSubject;

@BeforeEach
void setUp() {
testSubject = new SubmodelElementMapper();
}


@Test
void test_map_operation() {
var mockParent = new DefaultReference.Builder()
.keys(new DefaultKey.Builder()
.type(KeyTypes.SUBMODEL)
.value("sm-id")
.build())
.build();
List<OperationVariable> mockInputVariables = List.of(
new DefaultOperationVariable.Builder()
.value(getProperty("input1"))
.build(),
new DefaultOperationVariable.Builder()
.value(getProperty("input2"))
.build());
List<OperationVariable> mockInoutputVariables = List.of(
new DefaultOperationVariable.Builder()
.value(getProperty("inout1")).build(),
new DefaultOperationVariable.Builder()
.value(getProperty("inout2")).build());

List<OperationVariable> mockOutputVariables = List.of(
new DefaultOperationVariable.Builder()
.value(getProperty("out1")).build(),
new DefaultOperationVariable.Builder()
.value(getProperty("out2")).build());

var mockOperation = new DefaultOperation.Builder()
.idShort("test-operation-id-short")
.inputVariables(mockInputVariables)
.inoutputVariables(mockInoutputVariables)
.outputVariables(mockOutputVariables)
.build();

var resultAsset = testSubject.map(mockParent, mockOperation, mockService());

assertEquals(mockInputVariables, resultAsset.getProperty("inputVariables"));
assertEquals(mockInoutputVariables, resultAsset.getProperty("inoutputVariables"));
assertEquals(mockOutputVariables, resultAsset.getProperty("outputVariables"));
}

private Service mockService() {
try {
return new Service(new URL("https://test-url:1234/api/v3.0"));
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit fd48f52

Please sign in to comment.