Skip to content

Commit 0eb8b49

Browse files
committed
Check valid response construction
1 parent 1556faf commit 0eb8b49

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

project-management/src/main/java/life/qbic/projectmanagement/application/api/AsyncProjectService.java

+38
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package life.qbic.projectmanagement.application.api;
22

3+
import static java.util.Objects.isNull;
4+
5+
import java.util.Optional;
36
import java.util.UUID;
47
import reactor.core.publisher.Mono;
58

@@ -123,6 +126,41 @@ public String requestId() {
123126
*/
124127
record ProjectUpdateResponse(String projectId, UpdateResponseBody responseBody, String requestId) {
125128

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+
}
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, if no requestId is set, returns an empty String.
153+
*
154+
* @return Returns the requestId, if no requestId is set, returns an empty String.
155+
*/
156+
@Override
157+
public String requestId() {
158+
return isNull(requestId) ? "" : requestId;
159+
}
160+
161+
boolean hasRequestId() {
162+
return isNull(requestId);
163+
}
126164
}
127165

128166
/**

0 commit comments

Comments
 (0)