Skip to content

Commit

Permalink
chores: #72 use checkIfApplicationIsEditableByUser and fix naming con…
Browse files Browse the repository at this point in the history
…flicts
  • Loading branch information
emilianapali committed Aug 1, 2024
1 parent 6087e1e commit 07fe1dd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,12 @@ private String userId() {
}

@Override
public Response acceptApplicationTermsV1(Long id, AcceptLicensesCommand acceptLicensesCommand) {
public Response acceptApplicationTermsV1(Long id, AcceptTermsCommand acceptTermsCommand) {
String userId = userId();

io.github.genomicdatainfrastructure.daam.remote.rems.model.AcceptLicensesCommand remoteAcceptLicensesCommand = new io.github.genomicdatainfrastructure.daam.remote.rems.model.AcceptLicensesCommand();
remoteAcceptLicensesCommand.setApplicationId(acceptLicensesCommand.getApplicationId());
remoteAcceptLicensesCommand.setAcceptedLicenses(acceptLicensesCommand
.getAcceptedLicenses());
remoteAcceptLicensesCommand.setApplicationId(acceptTermsCommand.getApplicationId());
remoteAcceptLicensesCommand.setAcceptedLicenses(acceptTermsCommand.getAcceptedLicenses());

acceptTermsService.acceptTerms(id, userId, remoteAcceptLicensesCommand);
return Response.noContent().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@

package io.github.genomicdatainfrastructure.daam.services;

import io.github.genomicdatainfrastructure.daam.exceptions.ApplicationNotInCorrectStateException;
import io.github.genomicdatainfrastructure.daam.exceptions.UserNotApplicantException;
import io.github.genomicdatainfrastructure.daam.exceptions.ApplicationNotFoundException;
import io.github.genomicdatainfrastructure.daam.gateways.RemsApiQueryGateway;
import io.github.genomicdatainfrastructure.daam.remote.rems.api.RemsApplicationCommandApi;
import io.github.genomicdatainfrastructure.daam.remote.rems.model.AcceptLicensesCommand;
import io.github.genomicdatainfrastructure.daam.remote.rems.model.Application;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.eclipse.microprofile.config.inject.ConfigProperty;
Expand All @@ -37,10 +34,7 @@ public AcceptTermsService(
}

public void acceptTerms(Long id, String userId, AcceptLicensesCommand acceptLicensesCommand) {
Application application = remsApiQueryGateway.retrieveApplication(id, userId);
if (!application.getApplicationApplicant().getUserid().equals(userId)) {
throw new UserNotApplicantException(id, userId);
}
remsApiQueryGateway.checkIfApplicationIsEditableByUser(id, userId);

try {
remsApplicationCommandApi.apiApplicationsAcceptLicensesPost(remsApiKey, userId,
Expand All @@ -49,13 +43,6 @@ public void acceptTerms(Long id, String userId, AcceptLicensesCommand acceptLice
if (e.getResponse().getStatus() == Status.NOT_FOUND.getStatusCode()) {
throw new ApplicationNotFoundException(id);
}
if (e.getResponse().getStatus() == Status.FORBIDDEN.getStatusCode()) {
throw new UserNotApplicantException(id, userId);
}
if (e.getResponse().getStatus() == Status.PRECONDITION_REQUIRED.getStatusCode()) {
throw new ApplicationNotInCorrectStateException(id,
"Application not in submittable state");
}
throw e;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/openapi/daam.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ paths:
content:
application/json:
schema:
$ref: "#/components/schemas/AcceptLicensesCommand"
$ref: "#/components/schemas/AcceptTermsCommand"
responses:
"204":
description: Successful Response (no content)
Expand Down Expand Up @@ -1066,7 +1066,7 @@ components:
format: date-time
required:
- entitlements
AcceptLicensesCommand:
AcceptTermsCommand:
type: object
required:
- application-id
Expand Down

0 comments on commit 07fe1dd

Please sign in to comment.