1
1
package life .qbic .projectmanagement .application .api ;
2
2
3
+ import static java .util .Objects .nonNull ;
4
+
5
+ import java .util .Optional ;
6
+ import java .util .UUID ;
3
7
import reactor .core .publisher .Mono ;
4
8
5
9
/**
@@ -62,6 +66,24 @@ sealed interface UpdateResponseBody permits ProjectDesign {
62
66
63
67
}
64
68
69
+ /**
70
+ * Cacheable requests provide a unique identifier so cache implementations can unambiguously
71
+ * manage the requests.
72
+ *
73
+ * @since 1.9.0
74
+ */
75
+ sealed interface CacheableRequest permits ProjectUpdateRequest {
76
+
77
+ /**
78
+ * Returns an ID that is unique to the request.
79
+ *
80
+ * @return the id
81
+ * @since 1.9.0
82
+ */
83
+ String requestId ();
84
+
85
+ }
86
+
65
87
/**
66
88
* Container for passing information in an {@link UpdateRequestBody} or
67
89
* {@link UpdateResponseBody}.
@@ -82,8 +104,17 @@ record ProjectDesign(String title, String objective) implements UpdateRequestBod
82
104
* @param requestBody the information to be updated.
83
105
* @since 1.9.0
84
106
*/
85
- record ProjectUpdateRequest (String projectId , UpdateRequestBody requestBody ) {
107
+ record ProjectUpdateRequest (String projectId , UpdateRequestBody requestBody , String id ) implements
108
+ CacheableRequest {
86
109
110
+ public ProjectUpdateRequest (String projectId , UpdateRequestBody requestBody ) {
111
+ this (projectId , requestBody , UUID .randomUUID ().toString ());
112
+ }
113
+
114
+ @ Override
115
+ public String requestId () {
116
+ return id ;
117
+ }
87
118
}
88
119
89
120
/**
@@ -93,8 +124,43 @@ record ProjectUpdateRequest(String projectId, UpdateRequestBody requestBody) {
93
124
* @param responseBody the information that was updated.
94
125
* @since 1.9.0
95
126
*/
96
- record ProjectUpdateResponse (String projectId , UpdateResponseBody responseBody ) {
127
+ record ProjectUpdateResponse (String projectId , UpdateResponseBody responseBody , String requestId ) {
128
+
129
+ public ProjectUpdateResponse {
130
+ if (projectId == null ) {
131
+ throw new IllegalArgumentException ("Project ID cannot be null" );
132
+ }
133
+ if (projectId .isBlank ()) {
134
+ throw new IllegalArgumentException ("Project ID cannot be blank" );
135
+ }
136
+ if (requestId != null && requestId .isBlank ()) {
137
+ requestId = null ;
138
+ }
139
+ }
97
140
141
+ /**
142
+ * Retrieves the request id associated with this response. May be {@link Optional#empty()} but
143
+ * never null.
144
+ *
145
+ * @return an Optional with the requestId; {@link Optional#empty()} otherwise.
146
+ */
147
+ public Optional <String > retrieveRequestId () {
148
+ return Optional .ofNullable (requestId );
149
+ }
150
+
151
+ /**
152
+ * Returns the requestId, can be null.
153
+ *
154
+ * @return Returns the requestId, if no requestId is set, returns null.
155
+ */
156
+ @ Override
157
+ public String requestId () {
158
+ return requestId ;
159
+ }
160
+
161
+ boolean hasRequestId () {
162
+ return nonNull (requestId );
163
+ }
98
164
}
99
165
100
166
/**
0 commit comments