Skip to content

Commit

Permalink
Merge pull request #22 from GenomicDataInfrastructure/issue-5/submit-…
Browse files Browse the repository at this point in the history
…application

feat: implement submit application endpoint
  • Loading branch information
brunopacheco1 authored Mar 21, 2024
2 parents de07e01 + 34a2f5a commit ec1e01c
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,6 +20,7 @@
public class ApplicationCommandApiImpl implements ApplicationCommandApi {

private final CreateApplicationService createApplicationService;
private final SubmitApplicationService submitApplicationService;

@Override
public Response acceptApplicationTermsV1(String id) {
Expand Down Expand Up @@ -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
Expand All @@ -95,4 +96,4 @@ public Response updateDatasetsOfApplicationV1(String id, List<UpdateDatasets> up
"Unimplemented method 'updateDatasetsOfApplicationV1'"
);
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
56 changes: 56 additions & 0 deletions src/main/openapi/rems.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
16 changes: 16 additions & 0 deletions src/test/resources/mappings/submit_application.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
3 changes: 3 additions & 0 deletions src/test/resources/mappings/submit_application.json.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2024 PNED G.I.E.

SPDX-License-Identifier: Apache-2.0

0 comments on commit ec1e01c

Please sign in to comment.