-
Notifications
You must be signed in to change notification settings - Fork 1
[BI-1366] Subscribe Ontology #175
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f329cf6
shared ontology subscribe: subscribe and unsubscribe from ontology
4744f4b
subscribe ontology: change unsubscribe to DELETE call
bcc8ee7
subscribe ontology: change permissions to breeder
0ffd4ba
subscribe ontology: endpoints and fixes
697649e
subscribe ontology: add editable trait to subscribe options endpoint
ddfa722
subscribe ontology: rename models
10cba57
subscribe ontology: PR changes
dae5604
subscribe ontology: add error to logging
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,12 +4,9 @@ | |
| import io.micronaut.http.HttpStatus; | ||
| import io.micronaut.http.MediaType; | ||
| import io.micronaut.http.annotation.*; | ||
| import io.micronaut.security.annotation.Secured; | ||
| import io.micronaut.security.rules.SecurityRule; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.breedinginsight.api.auth.ProgramSecured; | ||
| import org.breedinginsight.api.auth.ProgramSecuredRole; | ||
| import org.breedinginsight.api.auth.ProgramSecuredRoleGroup; | ||
| import org.breedinginsight.api.auth.SecurityService; | ||
| import org.breedinginsight.api.model.v1.request.SharedOntologyProgramRequest; | ||
| import org.breedinginsight.api.model.v1.response.DataResponse; | ||
|
|
@@ -19,8 +16,8 @@ | |
| import org.breedinginsight.api.model.v1.response.metadata.Status; | ||
| import org.breedinginsight.api.model.v1.response.metadata.StatusCode; | ||
| import org.breedinginsight.api.v1.controller.metadata.AddMetadata; | ||
| import org.breedinginsight.model.SharedProgram; | ||
| import org.breedinginsight.model.Trait; | ||
| import org.breedinginsight.model.SharedOntology; | ||
| import org.breedinginsight.model.SubscribedOntology; | ||
| import org.breedinginsight.services.OntologyService; | ||
| import org.breedinginsight.services.exceptions.DoesNotExistException; | ||
| import org.breedinginsight.services.exceptions.UnprocessableEntityException; | ||
|
|
@@ -67,15 +64,20 @@ public OntologyController(SecurityService securityService, OntologyService ontol | |
| @Produces(MediaType.APPLICATION_JSON) | ||
| @AddMetadata | ||
| @ProgramSecured(roles = {ProgramSecuredRole.BREEDER}) | ||
| public HttpResponse<Response<DataResponse<SharedProgram>>> getAvailablePrograms( | ||
| public HttpResponse<Response<DataResponse<SharedOntology>>> getAvailablePrograms( | ||
| @PathVariable UUID programId, @QueryValue(defaultValue = "false") Boolean shared) { | ||
| List<SharedProgram> sharedPrograms = ontologyService.getSharedOntology(programId, shared); | ||
| List<org.breedinginsight.api.model.v1.response.metadata.Status> metadataStatus = new ArrayList<>(); | ||
| metadataStatus.add(new Status(StatusCode.INFO, "Successful Query")); | ||
| Pagination pagination = new Pagination(sharedPrograms.size(), 1, 1, 0); | ||
| Metadata metadata = new Metadata(pagination, metadataStatus); | ||
| Response<DataResponse<SharedProgram>> response = new Response(metadata, new DataResponse<>(sharedPrograms)); | ||
| return HttpResponse.ok(response); | ||
| try { | ||
| List<SharedOntology> sharedOntologies = ontologyService.getSharedOntology(programId, shared); | ||
| List<Status> metadataStatus = new ArrayList<>(); | ||
| metadataStatus.add(new Status(StatusCode.INFO, "Successful Query")); | ||
| Pagination pagination = new Pagination(sharedOntologies.size(), 1, 1, 0); | ||
| Metadata metadata = new Metadata(pagination, metadataStatus); | ||
| Response<DataResponse<SharedOntology>> response = new Response(metadata, new DataResponse<>(sharedOntologies)); | ||
| return HttpResponse.ok(response); | ||
| } catch (DoesNotExistException e) { | ||
| log.error(e.getMessage(), e); | ||
| return HttpResponse.status(HttpStatus.NOT_FOUND, e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -94,22 +96,26 @@ public HttpResponse<Response<DataResponse<SharedProgram>>> getAvailablePrograms( | |
| @Post("/programs/{programId}/ontology/shared/programs") | ||
| @Produces(MediaType.APPLICATION_JSON) | ||
| @ProgramSecured(roles = {ProgramSecuredRole.BREEDER}) | ||
| public HttpResponse<Response<DataResponse<SharedProgram>>> shareOntology( | ||
| public HttpResponse<Response<DataResponse<SharedOntology>>> shareOntology( | ||
| @PathVariable UUID programId, @Body List<SharedOntologyProgramRequest> request) { | ||
| try { | ||
| List<SharedProgram> sharedPrograms = ontologyService.shareOntology(programId, securityService.getUser(), request); | ||
| List<org.breedinginsight.api.model.v1.response.metadata.Status> metadataStatus = new ArrayList<>(); | ||
| List<SharedOntology> sharedOntologies = ontologyService.shareOntology(programId, securityService.getUser(), request); | ||
| List<Status> metadataStatus = new ArrayList<>(); | ||
| metadataStatus.add(new Status(StatusCode.INFO, "Successful Creation")); | ||
| Pagination pagination = new Pagination(sharedPrograms.size(), 1, 1, 0); | ||
| Pagination pagination = new Pagination(sharedOntologies.size(), 1, 1, 0); | ||
| Metadata metadata = new Metadata(pagination, metadataStatus); | ||
| Response<DataResponse<SharedProgram>> response = new Response(metadata, new DataResponse<>(sharedPrograms)); | ||
| Response<DataResponse<SharedOntology>> response = new Response(metadata, new DataResponse<>(sharedOntologies)); | ||
| return HttpResponse.ok(response); | ||
| } catch (ValidatorException e) { | ||
| log.error("Validation errors", e); | ||
| HttpResponse response = HttpResponse.status(HttpStatus.UNPROCESSABLE_ENTITY).body(e.getErrors()); | ||
| return response; | ||
| } catch (UnprocessableEntityException e) { | ||
| log.error(e.getMessage(), e); | ||
| return HttpResponse.status(HttpStatus.UNPROCESSABLE_ENTITY, e.getMessage()); | ||
| } catch (DoesNotExistException e) { | ||
| log.error(e.getMessage(), e); | ||
| return HttpResponse.status(HttpStatus.NOT_FOUND, e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -124,14 +130,99 @@ public HttpResponse<Response<DataResponse<SharedProgram>>> shareOntology( | |
| @Delete("/programs/{programId}/ontology/shared/programs/{sharedProgramId}") | ||
| @Produces(MediaType.APPLICATION_JSON) | ||
| @ProgramSecured(roles = {ProgramSecuredRole.BREEDER}) | ||
| public HttpResponse<Response<DataResponse<Trait>>> revokeOntology( | ||
| public HttpResponse revokeOntology( | ||
| @PathVariable UUID programId, @PathVariable UUID sharedProgramId) { | ||
| try { | ||
| ontologyService.revokeOntology(programId, sharedProgramId); | ||
| return HttpResponse.ok(); | ||
| } catch (UnprocessableEntityException e) { | ||
| log.error(e.getMessage(), e); | ||
| return HttpResponse.status(HttpStatus.UNPROCESSABLE_ENTITY, e.getMessage()); | ||
| } catch (DoesNotExistException e) { | ||
| log.error(e.getMessage(), e); | ||
| return HttpResponse.status(HttpStatus.NOT_FOUND, e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Scoped under the program that is subscribing. Accept a shared ontology. | ||
| * | ||
| * @param programId -- Program that is subscribing to an ontology | ||
| * @param sharingProgramId -- Program that has shared its ontology. | ||
| * @return | ||
| */ | ||
| @Put("/programs/{programId}/ontology/subscribe/{sharingProgramId}") | ||
| @Produces(MediaType.APPLICATION_JSON) | ||
| @AddMetadata | ||
| @ProgramSecured(roles = {ProgramSecuredRole.BREEDER}) | ||
| public HttpResponse<Response<SubscribedOntology>> subscribeOntology( | ||
| @PathVariable UUID programId, @PathVariable UUID sharingProgramId) { | ||
| try { | ||
| SubscribedOntology shareRequest = ontologyService.subscribeOntology(programId, sharingProgramId); | ||
| Response<SubscribedOntology> response = new Response(shareRequest); | ||
| return HttpResponse.ok(response); | ||
| } catch (UnprocessableEntityException e) { | ||
| log.error(e.getMessage(), e); | ||
| return HttpResponse.status(HttpStatus.UNPROCESSABLE_ENTITY, e.getMessage()); | ||
| } catch (DoesNotExistException e) { | ||
| log.error(e.getMessage(), e); | ||
| return HttpResponse.status(HttpStatus.NOT_FOUND, e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Scoped under the program that is subscribing. Unsubscribe from a shared ontology. | ||
| * | ||
| * @param programId -- Program that is unsubscribing from an ontology | ||
| * @param sharingProgramId -- Program that has shared its ontology. | ||
| * @return | ||
| */ | ||
| @Delete("/programs/{programId}/ontology/subscribe/{sharingProgramId}") | ||
| @Produces(MediaType.APPLICATION_JSON) | ||
| @ProgramSecured(roles = {ProgramSecuredRole.BREEDER}) | ||
| public HttpResponse unsubscribeOntology( | ||
| @PathVariable UUID programId, @PathVariable UUID sharingProgramId) { | ||
| try { | ||
| ontologyService.unsubscribeOntology(programId, sharingProgramId); | ||
| return HttpResponse.ok(); | ||
| } catch (UnprocessableEntityException e) { | ||
| log.error(e.getMessage(), e); | ||
| return HttpResponse.status(HttpStatus.UNPROCESSABLE_ENTITY, e.getMessage()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add an error log statement, please?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
| } catch (DoesNotExistException e) { | ||
| log.error(e.getMessage(), e); | ||
| return HttpResponse.status(HttpStatus.NOT_FOUND, e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves subscription options for programs that have shared their ontology with the requesting program. | ||
| * Will indicate whether the program has subscribed to a given ontology or not. | ||
| * | ||
| * @param programId -- Program request information | ||
| * @return | ||
| * { | ||
| * programId, -- Program that owns the ontology the request program is subscribed to. | ||
| * programName, | ||
| * subscribed, -- boolean. Whether the requesting program is subscribed to this ontology or not. | ||
| * editable -- boolean || null. Indicates whether this program can unsubscribe from this ontology or not. Null if not subscribed to this ontology. | ||
| * } | ||
| */ | ||
| @Get("/programs/{programId}/ontology/subscribe") | ||
| @Produces(MediaType.APPLICATION_JSON) | ||
| @AddMetadata | ||
| @ProgramSecured(roles = {ProgramSecuredRole.BREEDER}) | ||
| public HttpResponse<Response<DataResponse<SubscribedOntology>>> getSubscribedOntology( | ||
| @PathVariable UUID programId) { | ||
| try { | ||
| List<SubscribedOntology> shareRequests = ontologyService.getSubscribeOntologyOptions(programId); | ||
| List<Status> metadataStatus = new ArrayList<>(); | ||
| metadataStatus.add(new Status(StatusCode.INFO, "Successful Creation")); | ||
| Pagination pagination = new Pagination(shareRequests.size(), 1, 1, 0); | ||
| Metadata metadata = new Metadata(pagination, metadataStatus); | ||
| Response<DataResponse<SubscribedOntology>> response = new Response(metadata, new DataResponse<>(shareRequests)); | ||
| return HttpResponse.ok(response); | ||
| } catch (DoesNotExistException e) { | ||
| log.error(e.getMessage(), e); | ||
| return HttpResponse.status(HttpStatus.NOT_FOUND, e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/org/breedinginsight/model/SubscribedOntology.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package org.breedinginsight.model; | ||
|
|
||
| import lombok.*; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Builder | ||
| public class SubscribedOntology { | ||
| private UUID programId; | ||
| private String programName; | ||
| private Boolean subscribed; | ||
| private Boolean editable; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add an error log statement, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added