|
| 1 | +package life.qbic.projectmanagement.application.api; |
| 2 | + |
| 3 | +import reactor.core.publisher.Mono; |
| 4 | + |
| 5 | +/** |
| 6 | + * Service API layer the user interface code shall interact with in the application. |
| 7 | + * <p> |
| 8 | + * The API uses a straight-forward request-response pattern and promotes a reactive service |
| 9 | + * interaction. |
| 10 | + * <p> |
| 11 | + * The interface definition also contains the request and response object records and their body |
| 12 | + * interfaces. |
| 13 | + * <p> |
| 14 | + * Implementing classes must ensure to throw the proper exceptions expected by the client based on |
| 15 | + * the service methods exposed in this interface. |
| 16 | + * |
| 17 | + * @since 1.9.0 |
| 18 | + */ |
| 19 | +public interface AsyncProjectService { |
| 20 | + |
| 21 | + /** |
| 22 | + * Submits a project update request and returns a reactive {@link Mono<ProjectUpdateResponse>} |
| 23 | + * object immediately. |
| 24 | + * <p> |
| 25 | + * The method is non-blocking. |
| 26 | + * <p> |
| 27 | + * The implementing class must ensure to be able to process all implementing classes of the |
| 28 | + * {@link UpdateRequestBody} interface contained in the request. |
| 29 | + * <p> |
| 30 | + * The implementing class must also ensure to only return responses with classes implementing the |
| 31 | + * {@link UpdateResponseBody} interface. |
| 32 | + * |
| 33 | + * @param request the request to update a project |
| 34 | + * @return a {@link Mono<ProjectUpdateResponse>} object publishing an |
| 35 | + * {@link ProjectUpdateResponse} on success. |
| 36 | + * @throws UnknownRequestException if an unknown request has been used in the service call |
| 37 | + * @throws RequestFailedException if the request was not successfully executed |
| 38 | + * @throws AccessDeniedException if the user has insufficient rights |
| 39 | + * @since 1.9.0 |
| 40 | + */ |
| 41 | + Mono<ProjectUpdateResponse> update( |
| 42 | + ProjectUpdateRequest request) |
| 43 | + throws UnknownRequestException, RequestFailedException, AccessDeniedException; |
| 44 | + |
| 45 | + /** |
| 46 | + * Container of an update request for a service call and part of the |
| 47 | + * {@link ProjectUpdateRequest}. |
| 48 | + * |
| 49 | + * @since 1.9.0 |
| 50 | + */ |
| 51 | + sealed interface UpdateRequestBody permits ProjectDesign { |
| 52 | + |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Container of an update response from a service call and part of the |
| 57 | + * {@link ProjectUpdateResponse}. |
| 58 | + * |
| 59 | + * @since 1.9.0 |
| 60 | + */ |
| 61 | + sealed interface UpdateResponseBody permits ProjectDesign { |
| 62 | + |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Container for passing information in an {@link UpdateRequestBody} or |
| 67 | + * {@link UpdateResponseBody}. |
| 68 | + * |
| 69 | + * @param title the title of the project |
| 70 | + * @param objective the objective of the project |
| 71 | + * @since 1.9.0 |
| 72 | + */ |
| 73 | + record ProjectDesign(String title, String objective) implements UpdateRequestBody, |
| 74 | + UpdateResponseBody { |
| 75 | + |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * A service request to update project information. |
| 80 | + * |
| 81 | + * @param projectId the project's id |
| 82 | + * @param requestBody the information to be updated. |
| 83 | + * @since 1.9.0 |
| 84 | + */ |
| 85 | + record ProjectUpdateRequest(String projectId, UpdateRequestBody requestBody) { |
| 86 | + |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * A service response from an update project information request. |
| 91 | + * |
| 92 | + * @param projectId the project's id |
| 93 | + * @param responseBody the information that was updated. |
| 94 | + * @since 1.9.0 |
| 95 | + */ |
| 96 | + record ProjectUpdateResponse(String projectId, UpdateResponseBody responseBody) { |
| 97 | + |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * Exception to indicate that the service did not recognise the request. |
| 102 | + * |
| 103 | + * @since 1.9.0 |
| 104 | + */ |
| 105 | + class UnknownRequestException extends RuntimeException { |
| 106 | + |
| 107 | + public UnknownRequestException(String message) { |
| 108 | + super(message); |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + /** |
| 113 | + * Exception to indicate that the service tried to execute the request, but it failed. |
| 114 | + * |
| 115 | + * @since 1.9.0 |
| 116 | + */ |
| 117 | + class RequestFailedException extends RuntimeException { |
| 118 | + |
| 119 | + public RequestFailedException(String message) { |
| 120 | + super(message); |
| 121 | + } |
| 122 | + |
| 123 | + public RequestFailedException(String message, Throwable cause) { |
| 124 | + super(message, cause); |
| 125 | + } |
| 126 | + } |
| 127 | + |
| 128 | + /** |
| 129 | + * Exception to indicate that the service tried to execute the request, but the user had |
| 130 | + * insufficient rights and thus the request failed. |
| 131 | + * |
| 132 | + * @since 1.9.0 |
| 133 | + */ |
| 134 | + class AccessDeniedException extends RuntimeException { |
| 135 | + |
| 136 | + public AccessDeniedException(String message) { |
| 137 | + super(message); |
| 138 | + } |
| 139 | + |
| 140 | + public AccessDeniedException(String message, Throwable cause) { |
| 141 | + super(message, cause); |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | +} |
0 commit comments