-
Notifications
You must be signed in to change notification settings - Fork 215
/
Action.java
110 lines (80 loc) · 3.61 KB
/
Action.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* 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 <a href="https://www.w3.org/TR/wot-thing-description11/#actionaffordance">WoT TD ActionAffordance</a>
* @since 2.4.0
*/
public interface Action extends Interaction<Action, ActionFormElement, ActionForms> {
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<SingleDataSchema> getInput();
Optional<SingleDataSchema> getOutput();
boolean isSafe();
boolean isIdempotent();
Optional<Boolean> isSynchronous();
interface Builder extends Interaction.Builder<Builder, Action, ActionFormElement, ActionForms> {
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<JsonObject> INPUT = JsonFactory.newJsonObjectFieldDefinition(
"input");
public static final JsonFieldDefinition<JsonObject> OUTPUT = JsonFactory.newJsonObjectFieldDefinition(
"output");
public static final JsonFieldDefinition<Boolean> SAFE = JsonFactory.newBooleanFieldDefinition(
"safe");
public static final JsonFieldDefinition<Boolean> IDEMPOTENT = JsonFactory.newBooleanFieldDefinition(
"idempotent");
public static final JsonFieldDefinition<Boolean> SYNCHRONOUS = JsonFactory.newBooleanFieldDefinition(
"synchronous");
private JsonFields() {
throw new AssertionError();
}
}
}