package com.xfestudio.xfeservermanager.api.operation;
import com.xfestudio.xfeservermanager.api.util.ApiChecks;
import java.time.Instant;
import java.util.Map;
import java.util.Objects;
/** Serializable state of a short or asynchronous management operation. */
public record OperationResult(
String operationId,
OperationStatus status,
String message,
Map<String, String> data,
ApiError error,
Instant startedAt,
Instant completedAt
) {
public OperationResult {
operationId = ApiChecks.notBlank(operationId, "operationId");
Objects.requireNonNull(status, "status");
message = ApiChecks.notBlank(message, "message");
data = ApiChecks.immutableMap(data, "data");
Objects.requireNonNull(startedAt, "startedAt");
if (status.isTerminal() != (completedAt != null)) {
throw new IllegalArgumentException("completedAt must be present exactly for terminal states");
}
if (status == OperationStatus.FAILED && error == null) {
throw new IllegalArgumentException("failed operations require an error");
}
if (status != OperationStatus.FAILED && error != null) {
throw new IllegalArgumentException("only failed operations may contain an error");
}
}
}
package com.xfestudio.xfeservermanager.api.operation;
import com.xfestudio.xfeservermanager.api.util.ApiChecks;
import java.time.Instant;
import java.util.Map;
import java.util.Objects;
/** Serializable state of a short or asynchronous management operation. */
public record OperationResult(
String operationId,
OperationStatus status,
String message,
Map<String, String> data,
ApiError error,
Instant startedAt,
Instant completedAt
) {
public OperationResult {
operationId = ApiChecks.notBlank(operationId, "operationId");
Objects.requireNonNull(status, "status");
message = ApiChecks.notBlank(message, "message");
data = ApiChecks.immutableMap(data, "data");
Objects.requireNonNull(startedAt, "startedAt");
if (status.isTerminal() != (completedAt != null)) {
throw new IllegalArgumentException("completedAt must be present exactly for terminal states");
}
if (status == OperationStatus.FAILED && error == null) {
throw new IllegalArgumentException("failed operations require an error");
}
if (status != OperationStatus.FAILED && error != null) {
throw new IllegalArgumentException("only failed operations may contain an error");
}
}
}