-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/bi 1459 #185
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
Feature/bi 1459 #185
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ae7d5c5
[BI-1459] - Add endpoint to fetch all jobs in a program
timparsons 21464e9
[BI-1459] - Creating Job data model
timparsons 2305b35
[BI-1459] - Updating response model to use DataResponse
timparsons ae02f01
[BI-1459] - Adding tests for jobs endpoint
timparsons 302ca8e
[BI-1459] - Changing error severity to be in line with other log mess…
timparsons e0a8c76
[BI-1459] - Adding documentation on JobDetail
timparsons 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
79 changes: 79 additions & 0 deletions
79
src/main/java/org/breedinginsight/api/v1/controller/JobController.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,79 @@ | ||
| /* | ||
| * See the NOTICE file distributed with this work for additional information | ||
| * regarding copyright ownership. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.breedinginsight.api.v1.controller; | ||
|
|
||
| import io.micronaut.http.HttpResponse; | ||
| import io.micronaut.http.MediaType; | ||
| import io.micronaut.http.annotation.Controller; | ||
| import io.micronaut.http.annotation.Get; | ||
| import io.micronaut.http.annotation.PathVariable; | ||
| import io.micronaut.http.annotation.Produces; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.breedinginsight.api.auth.AuthenticatedUser; | ||
| import org.breedinginsight.api.auth.ProgramSecured; | ||
| import org.breedinginsight.api.auth.ProgramSecuredRoleGroup; | ||
| import org.breedinginsight.api.auth.SecurityService; | ||
| import org.breedinginsight.api.model.v1.response.DataResponse; | ||
| import org.breedinginsight.api.model.v1.response.Response; | ||
| import org.breedinginsight.api.model.v1.response.metadata.Metadata; | ||
| import org.breedinginsight.api.model.v1.response.metadata.Pagination; | ||
| 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.job.Job; | ||
| import org.breedinginsight.services.exceptions.DoesNotExistException; | ||
| import org.breedinginsight.services.job.JobService; | ||
|
|
||
| import javax.inject.Inject; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| @Slf4j | ||
| @Controller("/${micronaut.bi.api.version}") | ||
| public class JobController { | ||
| private SecurityService securityService; | ||
| private JobService jobService; | ||
|
|
||
| @Inject | ||
| public JobController(SecurityService securityService, JobService jobService) { | ||
| this.securityService = securityService; | ||
| this.jobService = jobService; | ||
| } | ||
|
|
||
| @Get("programs/{programId}/jobs") | ||
| @Produces(MediaType.APPLICATION_JSON) | ||
| @AddMetadata | ||
| @ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.ALL}) | ||
| public HttpResponse<Response<DataResponse<Job>>> getProgramJobs(@PathVariable UUID programId) { | ||
| log.debug(String.format("fetching jobs for program: %s", programId)); | ||
| try { | ||
| AuthenticatedUser actingUser = securityService.getUser(); | ||
| var programJobs = jobService.getProgramJobs(programId); | ||
| List<Status> metadataStatus = new ArrayList<>(); | ||
| metadataStatus.add(new Status(StatusCode.INFO, "Successful Query")); | ||
| Pagination pagination = new Pagination(programJobs.size(), programJobs.size(), 1, 0); | ||
| Metadata metadata = new Metadata(pagination, metadataStatus); | ||
| Response<DataResponse<Job>> response = new Response<>(metadata, new DataResponse<>(programJobs)); | ||
| return HttpResponse.ok(response); | ||
| } catch (DoesNotExistException e) { | ||
| log.info(e.getMessage(), e); | ||
| return HttpResponse.notFound(); | ||
| } | ||
| } | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * See the NOTICE file distributed with this work for additional information | ||
| * regarding copyright ownership. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.breedinginsight.model.job; | ||
|
|
||
| import lombok.*; | ||
| import lombok.experimental.Accessors; | ||
| import org.breedinginsight.model.User; | ||
|
|
||
| import java.time.OffsetDateTime; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| @Accessors(chain=true) | ||
| @ToString | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class Job { | ||
| private int statuscode; | ||
| private String statusMessage; | ||
| private String jobType; | ||
| private OffsetDateTime createdAt; | ||
| private OffsetDateTime updatedAt; | ||
| private User createdByUser; | ||
| private JobDetail jobDetail; | ||
| } |
25 changes: 25 additions & 0 deletions
25
src/main/java/org/breedinginsight/model/job/JobDetail.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,25 @@ | ||
| /* | ||
| * See the NOTICE file distributed with this work for additional information | ||
| * regarding copyright ownership. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.breedinginsight.model.job; | ||
|
|
||
| /** | ||
| * Represents an object that contains the details about a specific asynchronous job. | ||
| */ | ||
| public interface JobDetail { | ||
| String getJobType(); | ||
| } |
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.
I'm confused about the need for the JobDetail interface. I only see it implemented once (here), and then it is only used to return a hardcoded value. Is there a more direct way to code this? If not, maybe a comment would be valuable.
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.
@davedrp Added some javadoc to the
JobDetailinterface.Essentially, the
JobDetailinterface is to allow aJobto hold additional information about a specific task, but not have to know exactly what that information is (the UI cares more about this hence why there is agetTypemethod in theJobDetail).