Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add operation variables to self description #153

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
Loading