Skip to content

Commit

Permalink
Refactor Invokable Interface and Improve Operation Handling Across Su…
Browse files Browse the repository at this point in the history
…bmodel Services (#567)

* refactor: move InvokableOperation

* refactor: extract Invokable interface

* refactor: InvokableOperation implements Invokable
  • Loading branch information
MateusMolina authored Dec 9, 2024
1 parent f3b586d commit 935edab
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
import java.util.Collection;

import org.eclipse.digitaltwin.aas4j.v3.model.Submodel;
import org.eclipse.digitaltwin.basyx.InvokableOperation;
import org.eclipse.digitaltwin.basyx.common.mongocore.BasyxMongoMappingContext;
import org.eclipse.digitaltwin.basyx.common.mongocore.MongoDBUtilities;
import org.eclipse.digitaltwin.basyx.core.exceptions.NotInvokableException;
import org.eclipse.digitaltwin.basyx.core.filerepository.FileRepository;
import org.eclipse.digitaltwin.basyx.core.filerepository.MongoDBFileRepository;
import org.eclipse.digitaltwin.basyx.operation.InvokableOperation;
import org.eclipse.digitaltwin.basyx.submodelrepository.backend.SimpleSubmodelRepositoryFactory;
import org.eclipse.digitaltwin.basyx.submodelrepository.backend.SubmodelBackendProvider;
import org.eclipse.digitaltwin.basyx.submodelrepository.core.SubmodelRepositorySuite;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultProperty;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultQualifier;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodel;
import org.eclipse.digitaltwin.basyx.InvokableOperation;
import org.eclipse.digitaltwin.basyx.core.exceptions.OperationDelegationException;
import org.eclipse.digitaltwin.basyx.core.filerepository.InMemoryFileRepository;
import org.eclipse.digitaltwin.basyx.core.pagination.PaginationInfo;
import org.eclipse.digitaltwin.basyx.http.Aas4JHTTPSerializationExtension;
import org.eclipse.digitaltwin.basyx.http.BaSyxHTTPConfiguration;
import org.eclipse.digitaltwin.basyx.http.SerializationExtension;
import org.eclipse.digitaltwin.basyx.operation.InvokableOperation;
import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelInMemoryBackendProvider;
import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepository;
import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepositoryFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
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.operation.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
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
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.basyx.InvokableOperation;
import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingIdentifierException;
import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException;
import org.eclipse.digitaltwin.basyx.core.exceptions.ElementNotAFileException;
Expand All @@ -52,6 +51,7 @@
import org.eclipse.digitaltwin.basyx.core.pagination.PaginationInfo;
import org.eclipse.digitaltwin.basyx.core.pagination.PaginationSupport;
import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier;
import org.eclipse.digitaltwin.basyx.operation.InvokableOperation;
import org.eclipse.digitaltwin.basyx.submodelservice.pathparsing.HierarchicalSubmodelElementParser;
import org.eclipse.digitaltwin.basyx.submodelservice.pathparsing.SubmodelElementIdShortHelper;
import org.eclipse.digitaltwin.basyx.submodelservice.value.FileBlobValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*******************************************************************************
* 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 org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable;

/**
* Interface for invokable operations
*
* @author mateusmolina
*/
@FunctionalInterface
public interface Invokable {
OperationVariable[] invoke(OperationVariable[] arguments);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (C) 2023 the Eclipse BaSyx Authors
* 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
Expand All @@ -24,9 +24,7 @@
******************************************************************************/


package org.eclipse.digitaltwin.basyx;

import java.util.function.Function;
package org.eclipse.digitaltwin.basyx.operation;

import org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable;
import org.eclipse.digitaltwin.aas4j.v3.model.builder.OperationBuilder;
Expand All @@ -38,25 +36,26 @@
* @author schnicke
*
*/
public class InvokableOperation extends DefaultOperation {
private Function<OperationVariable[], OperationVariable[]> invokable;
public class InvokableOperation extends DefaultOperation implements Invokable {
private Invokable invokable;

/**
* Invokes the operation with the passed arguments
*
* @param arguments
* @return
*/
@Override
public OperationVariable[] invoke(OperationVariable[] arguments) {
return invokable.apply(arguments);
return invokable.invoke(arguments);
}

/**
* Sets the function to call on operation invocation
*
* @param invokable
*/
public void setInvokable(Function<OperationVariable[], OperationVariable[]> invokable) {
public void setInvokable(Invokable invokable) {
this.invokable = invokable;
}

Expand All @@ -72,7 +71,7 @@ protected InvokableOperation newBuildingInstance() {
return new InvokableOperation();
}

public Builder invokable(Function<OperationVariable[], OperationVariable[]> invokable) {
public Builder invokable(Invokable invokable) {
getBuildingInstance().setInvokable(invokable);
return getSelf();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,4 @@ private static OperationResult createSuccessOperationResult(List<OperationVariab
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 @@ -67,7 +67,7 @@
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSpecificAssetId;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodelElementCollection;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodelElementList;
import org.eclipse.digitaltwin.basyx.InvokableOperation;
import org.eclipse.digitaltwin.basyx.operation.InvokableOperation;

import com.google.common.collect.Lists;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
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.operation.Invokable;
import org.eclipse.digitaltwin.basyx.pagination.GetSubmodelElementsResult;
import org.eclipse.digitaltwin.basyx.serialization.SubmodelMetadataUtil;
import org.eclipse.digitaltwin.basyx.submodelservice.SubmodelService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultProperty;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultReference;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodel;
import org.eclipse.digitaltwin.basyx.InvokableOperation;
import org.eclipse.digitaltwin.basyx.operation.InvokableOperation;

import com.google.common.collect.Lists;

Expand Down

0 comments on commit 935edab

Please sign in to comment.