diff --git a/src/main/java/io/github/genomicdatainfrastructure/daam/api/ApplicationCommandApiImpl.java b/src/main/java/io/github/genomicdatainfrastructure/daam/api/ApplicationCommandApiImpl.java index 70d6093..effbf13 100644 --- a/src/main/java/io/github/genomicdatainfrastructure/daam/api/ApplicationCommandApiImpl.java +++ b/src/main/java/io/github/genomicdatainfrastructure/daam/api/ApplicationCommandApiImpl.java @@ -6,6 +6,7 @@ import java.util.List; import io.github.genomicdatainfrastructure.daam.services.CreateApplicationService; +import io.github.genomicdatainfrastructure.daam.services.SubmitApplicationService; import io.github.genomicdatainfrastructure.daam.model.AddApplicationEvent; import io.github.genomicdatainfrastructure.daam.model.AddedAttachments; import io.github.genomicdatainfrastructure.daam.model.CreateApplication; @@ -19,6 +20,7 @@ public class ApplicationCommandApiImpl implements ApplicationCommandApi { private final CreateApplicationService createApplicationService; + private final SubmitApplicationService submitApplicationService; @Override public Response acceptApplicationTermsV1(String id) { @@ -84,9 +86,8 @@ public Response saveApplicationFormsAndDuosV1(String id, SaveFormsAndDuos saveFo @Override public Response submitApplicationV1(String id) { - throw new UnsupportedOperationException( - "Unimplemented method 'submitApplicationV1'" - ); + submitApplicationService.submitApplication(id); + return Response.noContent().build(); } @Override @@ -95,4 +96,4 @@ public Response updateDatasetsOfApplicationV1(String id, List up "Unimplemented method 'updateDatasetsOfApplicationV1'" ); } -} \ No newline at end of file +} diff --git a/src/main/java/io/github/genomicdatainfrastructure/daam/services/SubmitApplicationService.java b/src/main/java/io/github/genomicdatainfrastructure/daam/services/SubmitApplicationService.java new file mode 100644 index 0000000..d1e2565 --- /dev/null +++ b/src/main/java/io/github/genomicdatainfrastructure/daam/services/SubmitApplicationService.java @@ -0,0 +1,46 @@ +// SPDX-FileCopyrightText: 2024 PNED G.I.E. +// +// SPDX-License-Identifier: Apache-2.0 + +package io.github.genomicdatainfrastructure.daam.services; + +import static io.github.genomicdatainfrastructure.daam.security.PostAuthenticationFilter.USER_ID_CLAIM; +import io.github.genomicdatainfrastructure.daam.remote.rems.api.RemsApplicationCommandApi; +import io.github.genomicdatainfrastructure.daam.remote.rems.model.SubmitApplicationCommand; +import io.quarkus.oidc.runtime.OidcJwtCallerPrincipal; +import io.quarkus.security.identity.SecurityIdentity; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import org.eclipse.microprofile.config.inject.ConfigProperty; +import org.eclipse.microprofile.rest.client.inject.RestClient; + + +@ApplicationScoped +public class SubmitApplicationService { + + private final SecurityIdentity identity; + private final String remsApiKey; + private final RemsApplicationCommandApi remsApplicationCommandApi; + + @Inject + public SubmitApplicationService( + @ConfigProperty(name = "quarkus.rest-client.rems_yaml.api-key") String remsApiKey, + SecurityIdentity identity, + @RestClient RemsApplicationCommandApi applicationsApi + ) { + this.remsApiKey = remsApiKey; + this.identity = identity; + this.remsApplicationCommandApi = applicationsApi; + } + + public void submitApplication(String id) { + var principal = (OidcJwtCallerPrincipal) identity.getPrincipal(); + String userId = principal.getClaim(USER_ID_CLAIM); + + SubmitApplicationCommand command = SubmitApplicationCommand.builder() + .applicationId(Long.valueOf(id)) + .build(); + + remsApplicationCommandApi.apiApplicationsSubmitPost(command, remsApiKey, userId); + } +} diff --git a/src/main/openapi/rems.yaml b/src/main/openapi/rems.yaml index c16c791..62577f0 100644 --- a/src/main/openapi/rems.yaml +++ b/src/main/openapi/rems.yaml @@ -102,6 +102,38 @@ paths: application/json: schema: $ref: '#/components/schemas/CreateApplicationResponse' + /api/applications/submit: + post: + tags: + - rems-application-command + summary: 'Submits a submit command for an application (roles: logged-in)' + parameters: + - in: header + name: x-rems-api-key + description: REMS API-Key (optional for UI, required for API) + required: false + schema: + type: string + - in: header + name: x-rems-user-id + description: User (optional for UI, required for API). This can be a REMS internal or an external user identity attribute (specified in config.edn). + required: false + schema: + type: string + requestBody: + description: Application submission data + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/SubmitApplicationCommand' + responses: + '200': + description: Application submission successful + content: + application/json: + schema: + $ref: '#/components/schemas/SubmitApplicationResponse' components: schemas: ApplicationOverview: @@ -602,6 +634,30 @@ components: required: - catalogue-item-ids CreateApplicationResponse: + type: object + properties: + success: + type: boolean + errors: + type: array + items: {} + warnings: + type: array + items: {} + application-id: + type: integer + format: int64 + required: + - success + SubmitApplicationCommand: + type: object + properties: + application-id: + type: integer + format: int64 + required: + - application-id + SubmitApplicationResponse: type: object properties: success: diff --git a/src/test/java/io/github/genomicdatainfrastructure/daam/api/ApplicationCommandApiImplTest.java b/src/test/java/io/github/genomicdatainfrastructure/daam/api/ApplicationCommandApiImplTest.java index 7afabf0..682de1d 100644 --- a/src/test/java/io/github/genomicdatainfrastructure/daam/api/ApplicationCommandApiImplTest.java +++ b/src/test/java/io/github/genomicdatainfrastructure/daam/api/ApplicationCommandApiImplTest.java @@ -41,6 +41,17 @@ void createApplication_when_authenticated() { .statusCode(204); } + @Test + void submitApplication_when_authenticated() { + given() + .auth() + .oauth2(getAccessToken("alice")) + .when() + .post("/api/v1/applications/1/submit") + .then() + .statusCode(204); + } + private String getAccessToken(String userName) { return keycloakClient.getAccessToken(userName); } diff --git a/src/test/resources/mappings/submit_application.json b/src/test/resources/mappings/submit_application.json new file mode 100644 index 0000000..c1596e4 --- /dev/null +++ b/src/test/resources/mappings/submit_application.json @@ -0,0 +1,16 @@ +{ + "request": { + "method": "POST", + "url": "/api/applications/submit" + }, + "response": { + "status": 200, + "headers": { + "Content-Type": "application/json" + }, + "jsonBody": { + "success": true, + "application-id": 12345 + } + } +} \ No newline at end of file diff --git a/src/test/resources/mappings/submit_application.json.license b/src/test/resources/mappings/submit_application.json.license new file mode 100644 index 0000000..c8d4da6 --- /dev/null +++ b/src/test/resources/mappings/submit_application.json.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2024 PNED G.I.E. + +SPDX-License-Identifier: Apache-2.0 \ No newline at end of file