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

Bump aas4j-version from 1.0.2 to 1.0.3 #565

Merged
merged 6 commits into from
Dec 9, 2024
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 @@ -223,10 +223,7 @@ public void createSubmodelInAas(String aasIdentifier, Submodel submodel) {
throw new RegistryHttpRequestException(aasIdentifier, e);
}

Reference smRef = AasUtils.toReference(AasUtils.toReference(shell), submodel);

// TODO See https://github.com/eclipse-aas4j/aas4j/issues/308
smRef.setReferredSemanticId(submodel.getSemanticId());
Reference smRef = AasUtils.toReference(AasUtils.toReference(shell), submodel, true);

aasRepository.addSubmodelReference(aasIdentifier, smRef);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import org.eclipse.digitaltwin.basyx.http.pagination.Base64UrlEncodedCursor;
import org.eclipse.digitaltwin.basyx.http.pagination.PagedResult;
import org.eclipse.digitaltwin.basyx.http.pagination.PagedResultPagingMetadata;
import org.eclipse.digitaltwin.basyx.operation.OperationRequestExecutor;
import org.eclipse.digitaltwin.basyx.operation.OperationRequestExecutor.Invokable;
import org.eclipse.digitaltwin.basyx.pagination.GetSubmodelElementsResult;
import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepository;
import org.eclipse.digitaltwin.basyx.submodelrepository.http.pagination.GetSubmodelsResult;
Expand Down Expand Up @@ -283,28 +285,12 @@ private ResponseEntity<SubmodelElement> handleSubmodelElementValueNormalGetReque

@Override
public ResponseEntity<OperationResult> invokeOperationSubmodelRepo(Base64UrlEncodedIdentifier submodelIdentifier, String idShortPath, @Valid OperationRequest body, @Valid Boolean async) {
List<OperationVariable> inVars = new ArrayList<>();
inVars.addAll(body.getInputArguments());
inVars.addAll(body.getInoutputArguments());

List<OperationVariable> result = Arrays.asList(repository.invokeOperation(submodelIdentifier.getIdentifier(), idShortPath, inVars.toArray(new OperationVariable[0])));
// TODO: #566 Add async operation execution support to
// SubmodelRepositoryController

List<OperationVariable> outVars = new ArrayList<>(result);
List<OperationVariable> inoutputVars = new ArrayList<>();

if (!body.getInoutputArguments().isEmpty()) {
List<String> inoutputVarsIdShorts = body.getInoutputArguments().stream().map(OperationVariable::getValue).map(SubmodelElement::getIdShort).toList();

inoutputVars = result.stream().filter(opVar -> inoutputVarsIdShorts.contains(opVar.getValue().getIdShort())).toList();

outVars.removeAll(inoutputVars);
}

return ResponseEntity.ok(createOperationResult(outVars, inoutputVars));
}

private OperationResult createOperationResult(List<OperationVariable> outputVars, List<OperationVariable> inoutputVars) {
return new DefaultOperationResult.Builder().outputArguments(outputVars).inoutputArguments(inoutputVars).build();
Invokable invokable = inArgs -> repository.invokeOperation(submodelIdentifier.getIdentifier(), idShortPath, inArgs);
return ResponseEntity.ok(OperationRequestExecutor.executeOperationRequestSynchronously(invokable, body));
}

private String getEncodedCursorFromCursorResult(CursorResult<?> cursorResult) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*******************************************************************************
* Copyright (C) 2024 the Eclipse BaSyx Authors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* SPDX-License-Identifier: MIT
******************************************************************************/

package org.eclipse.digitaltwin.basyx.operation;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.eclipse.digitaltwin.aas4j.v3.model.OperationRequest;
import org.eclipse.digitaltwin.aas4j.v3.model.OperationResult;
import org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable;
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultOperationResult;

/**
* Executes an Operation Request
*
* @author mateusmolina
*/
public class OperationRequestExecutor {

private OperationRequestExecutor() {
}

public static OperationResult executeOperationRequestSynchronously(Invokable invokable, OperationRequest request) {
List<OperationVariable> inVars = new ArrayList<>();
inVars.addAll(request.getInputArguments());
inVars.addAll(request.getInoutputArguments());

List<OperationVariable> result = Arrays.asList(invokable.invoke(inVars.toArray(new OperationVariable[0])));

List<OperationVariable> outVars = new ArrayList<>(result);
List<OperationVariable> inoutputVars = new ArrayList<>();

if (!request.getInoutputArguments().isEmpty()) {
List<String> inoutputVarsIdShorts = request.getInoutputArguments().stream().map(OperationVariable::getValue).map(SubmodelElement::getIdShort).toList();

inoutputVars = result.stream().filter(opVar -> inoutputVarsIdShorts.contains(opVar.getValue().getIdShort())).toList();

outVars.removeAll(inoutputVars);
}

return createSuccessOperationResult(outVars, inoutputVars);
}

private static OperationResult createSuccessOperationResult(List<OperationVariable> outputVars, List<OperationVariable> inoutputVars) {
return new DefaultOperationResult.Builder().success(true).outputArguments(outputVars).inoutputArguments(inoutputVars).build();
}

@FunctionalInterface
public interface Invokable {
OperationVariable[] invoke(OperationVariable[] arguments);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,12 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.eclipse.digitaltwin.aas4j.v3.model.OperationRequest;
import org.eclipse.digitaltwin.aas4j.v3.model.OperationResult;
import org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable;
import org.eclipse.digitaltwin.aas4j.v3.model.Submodel;
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultOperationResult;
import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException;
import org.eclipse.digitaltwin.basyx.core.exceptions.ElementNotAFileException;
import org.eclipse.digitaltwin.basyx.core.exceptions.FileDoesNotExistException;
Expand All @@ -45,6 +41,8 @@
import org.eclipse.digitaltwin.basyx.http.pagination.Base64UrlEncodedCursor;
import org.eclipse.digitaltwin.basyx.http.pagination.PagedResult;
import org.eclipse.digitaltwin.basyx.http.pagination.PagedResultPagingMetadata;
import org.eclipse.digitaltwin.basyx.operation.OperationRequestExecutor;
import org.eclipse.digitaltwin.basyx.operation.OperationRequestExecutor.Invokable;
import org.eclipse.digitaltwin.basyx.pagination.GetSubmodelElementsResult;
import org.eclipse.digitaltwin.basyx.serialization.SubmodelMetadataUtil;
import org.eclipse.digitaltwin.basyx.submodelservice.SubmodelService;
Expand Down Expand Up @@ -236,30 +234,9 @@ public ResponseEntity<Void> patchSubmodelValueOnly(@Parameter(in = ParameterIn.D
public ResponseEntity<OperationResult> invokeOperation(
@Parameter(in = ParameterIn.PATH, description = "IdShort path to the submodel element (dot-separated)", required = true, schema = @Schema()) @PathVariable("idShortPath") String idShortPath,
@Parameter(in = ParameterIn.DEFAULT, description = "Operation request object", required = true, schema = @Schema()) @Valid @RequestBody OperationRequest body) {
List<OperationVariable> inVars = new ArrayList<>();
inVars.addAll(body.getInputArguments());
inVars.addAll(body.getInoutputArguments());

List<OperationVariable> result = Arrays.asList(service.invokeOperation(idShortPath, inVars.toArray(new OperationVariable[0])));

List<OperationVariable> outVars = new ArrayList<>(result);
List<OperationVariable> inoutputVars = new ArrayList<>();

if (!body.getInoutputArguments().isEmpty()) {
List<String> inoutputVarsIdShorts = body.getInoutputArguments().stream().map(OperationVariable::getValue).map(SubmodelElement::getIdShort).toList();

inoutputVars = result.stream().filter(opVar -> inoutputVarsIdShorts.contains(opVar.getValue().getIdShort())).toList();

outVars.removeAll(inoutputVars);
}

return ResponseEntity.ok(createOperationResult(outVars, inoutputVars));
}

private OperationResult createOperationResult(List<OperationVariable> outputVars, List<OperationVariable> inoutputVars) {
return new DefaultOperationResult.Builder()
.outputArguments(outputVars).inoutputArguments(inoutputVars)
.build();
Invokable invokable = inArgs -> service.invokeOperation(idShortPath, inArgs);
return ResponseEntity.ok(OperationRequestExecutor.executeOperationRequestSynchronously(invokable, body));
}

private String getEncodedCursorFromCursorResult(CursorResult<?> cursorResult) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"success": true,
"inoutputArguments": [
{
"value": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"success": true,
"outputArguments": [
{
"value": {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<docker.target.platforms>linux/amd64, linux/arm64, linux/arm/v7</docker.target.platforms>
<docker.host.port>8081</docker.host.port>
<docker.container.port>8081</docker.container.port>
<aas4j-version>1.0.2</aas4j-version>
<aas4j-version>1.0.3</aas4j-version>
</properties>

<pluginRepositories>
Expand Down
Loading