-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathSynchronousResponse.java
89 lines (73 loc) · 2.76 KB
/
SynchronousResponse.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
/*
* Copyright (c) 2022 Airbyte, Inc., all rights reserved.
*/
package io.airbyte.server.scheduler;
import io.airbyte.commons.temporal.TemporalResponse;
import io.airbyte.config.ConnectorJobOutput;
import io.airbyte.config.JobConfig.ConfigType;
import java.util.Objects;
import java.util.UUID;
import javax.annotation.Nullable;
public class SynchronousResponse<T> {
private final T output;
private final SynchronousJobMetadata metadata;
public static <T> SynchronousResponse<T> error(final SynchronousJobMetadata metadata) {
return new SynchronousResponse<>(null, metadata);
}
public static <T> SynchronousResponse<T> success(final T output, final SynchronousJobMetadata metadata) {
return new SynchronousResponse<>(output, metadata);
}
public static <T, U> SynchronousResponse<T> fromTemporalResponse(final TemporalResponse<U> temporalResponse,
@Nullable final ConnectorJobOutput jobOutput,
@Nullable final T responseOutput,
final UUID id,
final ConfigType configType,
final UUID configId,
final long createdAt,
final long endedAt) {
final SynchronousJobMetadata metadata = SynchronousJobMetadata.fromJobMetadata(
temporalResponse.getMetadata(),
id,
configType,
configId,
jobOutput != null ? jobOutput.getConnectorConfigurationUpdated() : false,
createdAt,
endedAt);
return new SynchronousResponse<>(responseOutput, metadata);
}
public SynchronousResponse(final T output, final SynchronousJobMetadata metadata) {
this.output = output;
this.metadata = metadata;
}
public boolean isSuccess() {
return metadata.isSucceeded();
}
public T getOutput() {
return output;
}
public SynchronousJobMetadata getMetadata() {
return metadata;
}
@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final SynchronousResponse<?> that = (SynchronousResponse<?>) o;
return Objects.equals(output, that.output) && Objects.equals(metadata, that.metadata);
}
@Override
public int hashCode() {
return Objects.hash(output, metadata);
}
@Override
public String toString() {
return "SynchronousResponse{" +
"output=" + output +
", metadata=" + metadata +
'}';
}
}