Skip to content

Commit

Permalink
fix OperationResult to correctly inherit from BaseOperationResult (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjacoby authored Nov 19, 2024
1 parent e688926 commit 0b73774
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@KnownSubtypes({
@KnownSubtypes.Type(value = DefaultOperationResult.class)
})
public interface OperationResult {
public interface OperationResult extends BaseOperationResult {

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/*
* Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V.
* Copyright (c) 2023, SAP SE or an SAP affiliate company
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
Expand All @@ -19,14 +16,28 @@
import org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable;

import java.util.List;
import org.eclipse.digitaltwin.aas4j.v3.model.ExecutionState;
import org.eclipse.digitaltwin.aas4j.v3.model.Message;


public abstract class OperationResultBuilder<T extends OperationResult, B extends OperationResultBuilder<T, B>>
extends ExtendableBuilder<T, B> {
extends ExtendableBuilder<T, B> {

/**
* This function allows setting a value for executionState
*
* @param executionState desired value to be set
* @return Builder object with new value for executionState
*/
public B executionState(ExecutionState executionState) {
getBuildingInstance().setExecutionState(executionState);
return getSelf();
}


/**
* This function allows setting a value for inoutputArguments
*
*
* @param inoutputArguments desired value to be set
* @return Builder object with new value for inoutputArguments
*/
Expand All @@ -35,9 +46,10 @@ public B inoutputArguments(List<OperationVariable> inoutputArguments) {
return getSelf();
}


/**
* This function allows adding a value to the List inoutputArguments
*
*
* @param inoutputArguments desired value to be added
* @return Builder object with new value for inoutputArguments
*/
Expand All @@ -46,9 +58,34 @@ public B inoutputArguments(OperationVariable inoutputArguments) {
return getSelf();
}


/**
* This function allows setting a value for messages
*
* @param messages desired value to be set
* @return Builder object with new value for messages
*/
public B messages(List<Message> messages) {
getBuildingInstance().setMessages(messages);
return getSelf();
}


/**
* This function allows adding a value to the List messages
*
* @param messages desired value to be added
* @return Builder object with new value for messages
*/
public B messages(Message messages) {
getBuildingInstance().getMessages().add(messages);
return getSelf();
}


/**
* This function allows setting a value for outputArguments
*
*
* @param outputArguments desired value to be set
* @return Builder object with new value for outputArguments
*/
Expand All @@ -57,14 +94,28 @@ public B outputArguments(List<OperationVariable> outputArguments) {
return getSelf();
}


/**
* This function allows adding a value to the List outputArguments
*
*
* @param outputArguments desired value to be added
* @return Builder object with new value for outputArguments
*/
public B outputArguments(OperationVariable outputArguments) {
getBuildingInstance().getOutputArguments().add(outputArguments);
return getSelf();
}


/**
* This function allows setting a value for success
*
* @param success desired value to be set
* @return Builder object with new value for success
*/
public B success(boolean success) {
getBuildingInstance().setSuccess(success);
return getSelf();
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/*
* Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V.
* Copyright (c) 2023, SAP SE or an SAP affiliate company
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
Expand Down Expand Up @@ -73,37 +70,44 @@ public ExecutionState getExecutionState() {
return executionState;
}


@Override
public void setExecutionState(ExecutionState executionState) {
this.executionState = executionState;
}


@Override
public boolean getSuccess() {
return success;
}


@Override
public void setSuccess(boolean success) {
this.success = success;
}


@Override
public List<Message> getMessages() {
return messages;
}


@Override
public void setMessages(List<Message> messages) {
this.messages = messages;
}


public String toString() {
return String.format(
"DefaultBaseOperationResult (" + "executionState=%s,"
+ "success=%s,"
+ ")",
this.executionState, this.success);
"DefaultBaseOperationResult (" + "executionState=%s,"
+ "messages=%s,"
+ "success=%s,"
+ ")",
this.executionState, this.messages, this.success);
}

/**
Expand All @@ -116,6 +120,7 @@ protected Builder getSelf() {
return this;
}


@Override
protected DefaultBaseOperationResult newBuildingInstance() {
return new DefaultBaseOperationResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.eclipse.digitaltwin.aas4j.v3.model.ExecutionState;
import org.eclipse.digitaltwin.aas4j.v3.model.Message;


/**
Expand All @@ -33,6 +35,15 @@
@IRI("aas:OperationResult")
public class DefaultOperationResult implements OperationResult {

@IRI("https://admin-shell.io/aas/3/0/BaseOperationResult/executionState")
protected ExecutionState executionState;

@IRI("https://admin-shell.io/aas/3/0/BaseOperationResult/success")
protected boolean success;

@IRI("https://admin-shell.io/aas/3/0/Result/messages")
protected List<Message> messages = new ArrayList<>();

@IRI("https://admin-shell.io/aas/3/0/OperationResult/inoutputArguments")
protected List<OperationVariable> inoutputArguments = new ArrayList<>();

Expand All @@ -41,12 +52,17 @@ public class DefaultOperationResult implements OperationResult {

public DefaultOperationResult() {}


@Override
public int hashCode() {
return Objects.hash(this.inoutputArguments,
this.outputArguments);
return Objects.hash(this.executionState,
this.success,
this.messages,
this.inoutputArguments,
this.outputArguments);
}


@Override
public boolean equals(Object obj) {
if (this == obj) {
Expand All @@ -58,36 +74,83 @@ public boolean equals(Object obj) {
} else {
DefaultOperationResult other = (DefaultOperationResult) obj;
return Objects.equals(this.inoutputArguments, other.inoutputArguments) &&
Objects.equals(this.outputArguments, other.outputArguments);
Objects.equals(this.outputArguments, other.outputArguments) &&
Objects.equals(this.executionState, other.executionState) &&
Objects.equals(this.success, other.success) &&
Objects.equals(this.messages, other.messages);
}
}


@Override
public List<OperationVariable> getInoutputArguments() {
return inoutputArguments;
}


@Override
public void setInoutputArguments(List<OperationVariable> inoutputArguments) {
this.inoutputArguments = inoutputArguments;
}


@Override
public List<OperationVariable> getOutputArguments() {
return outputArguments;
}


@Override
public void setOutputArguments(List<OperationVariable> outputArguments) {
this.outputArguments = outputArguments;
}


@Override
public ExecutionState getExecutionState() {
return executionState;
}


@Override
public void setExecutionState(ExecutionState executionState) {
this.executionState = executionState;
}


@Override
public boolean getSuccess() {
return success;
}


@Override
public void setSuccess(boolean success) {
this.success = success;
}


@Override
public List<Message> getMessages() {
return messages;
}


@Override
public void setMessages(List<Message> messages) {
this.messages = messages;
}


public String toString() {
return String.format(
"DefaultOperationResult (" + "inoutputArguments=%s,"
+ "outputArguments=%s,"
+ ")",
this.inoutputArguments, this.outputArguments);
"DefaultOperationResult (" + "executionState=%s,"
+ "inoutputArguments=%s,"
+ "messages=%s,"
+ "outputArguments=%s,"
+ "success=%s,"
+ ")",
this.executionState, this.inoutputArguments, this.messages, this.outputArguments, this.success);
}

/**
Expand All @@ -100,6 +163,7 @@ protected Builder getSelf() {
return this;
}


@Override
protected DefaultOperationResult newBuildingInstance() {
return new DefaultOperationResult();
Expand Down

0 comments on commit 0b73774

Please sign in to comment.