Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BI-2374 Add delete catch-all to deltabreed brapi controller #427

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private void batchProcessGermplasm(List<BrAPIGermplasm> germplasmList, String pr
Pattern programKeyPattern = Utilities.getRegexPatternMatchAllProgramKeysAnyAccession(programKey);
germplasmList.parallelStream().forEach(germplasm -> {
// Set dbId
germplasm.germplasmDbId(Utilities.getExternalReference(germplasm.getExternalReferences(), "breedinginsight.org")
germplasm.germplasmDbId(Utilities.getExternalReference(germplasm.getExternalReferences(), "breeding-insight.net")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the reason for this change? Should we be using the value defined in application.yml brapi.server.reference-source

.orElseThrow(() -> new IllegalStateException("No BI external reference found"))
.getReferenceId());
// Process synonyms
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/org/breedinginsight/brapi/v2/BrAPIV2Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.breedinginsight.brapi.v2;

import io.micronaut.context.annotation.Value;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.HttpStatus;
Expand Down Expand Up @@ -186,6 +187,15 @@ public HttpResponse<?> getCatchall(@PathVariable("path") String path, @PathVaria
return executeRequest(path, programId, request, "GET");
}

@Delete("/${micronaut.bi.api.version}/programs/{programId}" + BrapiVersion.BRAPI_V2 + "/{+path}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the delete pass through is overridden by specific implementations in future cards, is the plan to use the DeltaBreed external reference id rather than the DbId of the brapi service?

@Produces(MediaType.APPLICATION_JSON)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed in standup, this currently won't delete the associated dataset and that should be captured in the the experiment delete endpoint implementation.

@ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.PROGRAM_SCOPED_ROLES})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something only a program or system admin should be allowed to do? Wondering if we should make a new role group that is system admin and program admin without readonly.

public HttpResponse<?> deleteCatchall(@PathVariable("path") String path,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When testing I could do DELETE http://localhost:8081/v1/programs/9d4719fe-bd89-4d54-bbf6-e71f33f87b04/brapi/v2/trials/ with no trialDbId and get success. Seems like it should give an error in that case.

@PathVariable("programId") UUID programId,
HttpRequest<Void> request) {
return executeDeleteRequest(path, programId, request);
}

@Post("/${micronaut.bi.api.version}/programs/{programId}" + BrapiVersion.BRAPI_V2 + "/{+path}")
@Consumes(MediaType.ALL)
@Produces(MediaType.APPLICATION_JSON)
Expand Down Expand Up @@ -241,6 +251,22 @@ private HttpResponse<String> executeRequest(String path, UUID programId, HttpReq
throw new HttpStatusException(HttpStatus.UNAUTHORIZED, "Unauthorized BrAPI Request");
}

private HttpResponse<String> executeDeleteRequest(String path, UUID programId, HttpRequest<?> request) {
AuthenticatedUser actingUser = securityService.getUser();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actingUser isn't used


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe should add a logCall so behavior is consistent with executeByteRequest and executeRequest

if (programId != null) {
HttpUrl requestUrl = getUrl(programId, path, request);

var brapiRequest = new Request.Builder().url(requestUrl)
.method("DELETE", null)
.build();

return makeCall(brapiRequest);
}

throw new HttpStatusException(HttpStatus.UNAUTHORIZED, "Unauthorized BrAPI Request");
}

private HttpResponse<String> makeCall(Request brapiRequest) {
// TODO: use config parameter for timeout
OkHttpClient client = new OkHttpClient.Builder()
Expand Down
Loading