org.eclipse.ditto.wot.model.Action Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ditto-wot-model Show documentation
Show all versions of ditto-wot-model Show documentation
Eclipse Ditto is a framework for creating and managing digital twins in the IoT.
The newest version!
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.wot.model;
import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull;
import java.util.Optional;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import org.eclipse.ditto.json.JsonFactory;
import org.eclipse.ditto.json.JsonFieldDefinition;
import org.eclipse.ditto.json.JsonObject;
/**
* An Action is an {@link Interaction} describing a function which can be invoked on a Thing.
*
* @see WoT TD ActionAffordance
* @since 2.4.0
*/
public interface Action extends Interaction {
static Action fromJson(final CharSequence actionName, final JsonObject jsonObject) {
return new ImmutableAction(checkNotNull(actionName, "actionName").toString(), jsonObject);
}
static Action.Builder newBuilder(final CharSequence actionName) {
return Action.Builder.newBuilder(actionName);
}
static Action.Builder newBuilder(final CharSequence actionName, final JsonObject jsonObject) {
return Action.Builder.newBuilder(actionName, jsonObject);
}
@Override
default Action.Builder toBuilder() {
return Builder.newBuilder(getActionName(), toJson());
}
String getActionName();
Optional getInput();
Optional getOutput();
boolean isSafe();
boolean isIdempotent();
Optional isSynchronous();
interface Builder extends Interaction.Builder {
static Builder newBuilder(final CharSequence actionName) {
return new MutableActionBuilder(checkNotNull(actionName, "actionName").toString(),
JsonObject.newBuilder());
}
static Builder newBuilder(final CharSequence actionName, final JsonObject jsonObject) {
return new MutableActionBuilder(checkNotNull(actionName, "actionName").toString(), jsonObject.toBuilder());
}
Builder setInput(@Nullable SingleDataSchema input);
Builder setOutput(@Nullable SingleDataSchema output);
Builder setSafe(@Nullable Boolean safe);
Builder setIdempotent(@Nullable Boolean idempotent);
Builder setSynchronous(@Nullable Boolean synchronous);
}
/**
* An enumeration of the known {@link JsonFieldDefinition}s of an Action.
*/
@Immutable
final class JsonFields {
public static final JsonFieldDefinition INPUT = JsonFactory.newJsonObjectFieldDefinition(
"input");
public static final JsonFieldDefinition OUTPUT = JsonFactory.newJsonObjectFieldDefinition(
"output");
public static final JsonFieldDefinition SAFE = JsonFactory.newBooleanFieldDefinition(
"safe");
public static final JsonFieldDefinition IDEMPOTENT = JsonFactory.newBooleanFieldDefinition(
"idempotent");
public static final JsonFieldDefinition SYNCHRONOUS = JsonFactory.newBooleanFieldDefinition(
"synchronous");
private JsonFields() {
throw new AssertionError();
}
}
}