-
Notifications
You must be signed in to change notification settings - Fork 0
create assignSponsorToProject #113
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
Open
HMS-Victory
wants to merge
27
commits into
main
Choose a base branch
from
Talbot/add-assign-sponsor-command
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
487fd05
feat: create AssignSponsorToProject class
HMS-Victory bb1bb5a
feat: link AssignSponsorToProject to justServeCommand
HMS-Victory bb97bcb
feat(wip): add tests for AssignSponsorToProject
HMS-Victory 610a1b2
docs: add annotation for test failing from backend
HMS-Victory 7e33374
fix: correct AssignSponsorToProject command name
HMS-Victory a781ac0
feat: link new AssignSponsorToProject command to command base
HMS-Victory 4bd156d
feat: add support to find user by id
HMS-Victory 37db736
feat: add manual checks to ensure only valid projects, or ids send ap…
HMS-Victory 4c652a4
test: add basic testing for findUserById
HMS-Victory b835ed8
fix: repair rests for assignSponsorProject
HMS-Victory dc27448
refactor: place checks at the beginning of try catch for easier reada…
HMS-Victory 6e7c295
fix: remove unnecessary semicolon
HMS-Victory 4367438
Revert "feat: link AssignSponsorToProject to justServeCommand"
HMS-Victory 138362d
Update cli/src/main/java/org/justserve/command/AssignSponsorToProject…
HMS-Victory 689b0b6
Apply suggestions from code review - implement dynamic test title
HMS-Victory 4f57618
fix: change exception to specifically refer to invalid input
HMS-Victory 2ae36e3
fix: (wip) remove get api/v1/users/uid/limited
Jonathan-Zollinger 39da3da
test: (wip) add test for slim search
Jonathan-Zollinger f34c0d5
refactor(wip): adjust assignSponsorToProject command to use a differe…
HMS-Victory e513719
fix: make the sponsor ID available in the wider scope
HMS-Victory 7dbd214
refactor: clean up null checks to avoid using exceptions aside from f…
HMS-Victory 6948033
fix: assign sponsorId after ensuring a user exists
HMS-Victory ce0a432
docs: add sponsor email in addition to the sponsor id in all of the r…
HMS-Victory 5ec94e8
docs(fix): simplify into only one title to maintain.
HMS-Victory e5ddd8c
feat: if a createUser fails find and return a user instead
HMS-Victory 7462e68
test: restore basic testing for apiV1UsersUserIdLimitedGet
HMS-Victory be502bd
fix: AssignSponsorToProjectSpec sending in id parameter instead of email
HMS-Victory 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
90 changes: 90 additions & 0 deletions
90
cli/src/main/java/org/justserve/command/AssignSponsorToProject.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,90 @@ | ||
| package org.justserve.command; | ||
|
|
||
| import io.micronaut.http.client.exceptions.HttpClientResponseException; | ||
| import jakarta.inject.Inject; | ||
| import jakarta.inject.Provider; | ||
| import jakarta.validation.Valid; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.justserve.client.ProjectClient; | ||
| import org.justserve.client.UserClient; | ||
| import org.justserve.model.*; | ||
| import picocli.CommandLine.Command; | ||
| import picocli.CommandLine.Option; | ||
| import org.justserve.client.GraphQLClient; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| import static org.justserve.util.JustServePrinter.printError; | ||
| import static org.justserve.util.JustServePrinter.printNormal; | ||
|
|
||
|
|
||
| @Slf4j | ||
| @Command(name = "assignSponsorToProject", description = "Assigns an sponsor to a project", mixinStandardHelpOptions = true) | ||
| public class AssignSponsorToProject extends BaseCommand implements Runnable { | ||
|
|
||
| @Option(names = {"--project", "-p"}, description = "the project ID", required = true) | ||
| private UUID projectId; | ||
|
|
||
| @Option(names = {"--user", "-u"}, description = "the user ID", required = true) | ||
| private String sponsorEmail; | ||
|
|
||
| @Inject | ||
| Provider<GraphQLClient> graphQLClientProvider; | ||
|
|
||
| @Inject | ||
| Provider<UserClient> userClientProvider; | ||
|
|
||
| @Inject | ||
| Provider<ProjectClient> projectClientProvider; | ||
|
|
||
| @Override | ||
| public void run() { | ||
| if (isTokenInvalid()) { | ||
| return; | ||
| } | ||
|
|
||
| GraphQLClient client = graphQLClientProvider.get(); | ||
| UserClient userClient = userClientProvider.get(); | ||
| ProjectClient projectClient = projectClientProvider.get(); | ||
|
|
||
| // ensure the project id, and the sponsor id exist, since the backend does not throw an exception if they do not | ||
| UUID sponsorId; | ||
| try{ | ||
| @Valid UserSlimSearchResults userResults=userClient.userSearchSlim(new UserSearchRequest(sponsorEmail, 1, 1)).block(); | ||
| @Valid Project project = projectClient.getProject(projectId, " ", new GetProjectRequest()).block(); | ||
|
|
||
| if (userResults == null || userResults.getUsers() == null || userResults.getUsers().isEmpty()) { | ||
| printError("Could not find sponsor with email %s", sponsorEmail); | ||
| return; | ||
| }else if (project == null) { | ||
| printError("Could not find project %s", projectId); | ||
| return; | ||
| } | ||
| sponsorId=userResults.getUsers().getFirst().getId(); | ||
| }catch(HttpClientResponseException e){ | ||
| printError("User API returned null for sponsorId = %s projectId = %s", sponsorEmail, projectId); | ||
| log.atError().setCause(e).log("Error response from API: {}", e.getMessage()); | ||
| return; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| GraphQLCombinedMutationUpdateProjectAddProjectTagVariables tagVariables = new GraphQLCombinedMutationUpdateProjectAddProjectTagVariables() | ||
| .setProjectId(projectId) | ||
| .setModify(new GraphQLCombinedMutationUpdateProjectAddProjectTagVariablesModify() | ||
| .setSponsorUserId(sponsorId)); | ||
|
|
||
| try { | ||
| log.atTrace().log("Assigning sponsor ({}, {}) to project {}", sponsorId, sponsorEmail, projectId); | ||
|
|
||
| client.combinedMutationUpdateProjectAddProjectTag(tagVariables); | ||
|
|
||
| printNormal("Successfully assigned sponsor (%s, %s) to project %s", sponsorId, sponsorEmail, projectId); | ||
| log.atTrace().log("Assigning sponsor ({}, {}) to project {}", sponsorId, sponsorEmail, projectId); | ||
| } catch (HttpClientResponseException e) { | ||
| printError("Failed to assign sponsor (%s, %s) to project %s. %n%t Error Code %s: Error Message: %s", | ||
| sponsorId, sponsorEmail, projectId, e.getStatus().getCode(), e.getMessage()); | ||
| log.atError().setCause(e).log("Error response from API: {}", e.getResponse().body()); | ||
| } | ||
| } | ||
| } |
54 changes: 54 additions & 0 deletions
54
cli/src/test/groovy/org/justserve/cli/command/AssignSponsorToProjectSpec.groovy
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,54 @@ | ||
| package org.justserve.cli.command | ||
|
|
||
| import io.micronaut.test.extensions.spock.annotation.MicronautTest | ||
| import org.justserve.TestUser | ||
| import org.justserve.model.ProjectCard | ||
| import spock.lang.Execution | ||
| import spock.lang.Unroll | ||
|
|
||
| import static org.spockframework.runtime.model.parallel.ExecutionMode.SAME_THREAD | ||
|
|
||
| @Execution(SAME_THREAD) | ||
| @MicronautTest | ||
| class AssignSponsorToProjectSpec extends BaseCommandSpec { | ||
|
|
||
| def "can assign a sponsor to a project without errors"() { | ||
| given: | ||
| def newReadOnlyUser = new TestUser(faker) | ||
| newReadOnlyUser.id = createUser().id | ||
| ProjectCard project = searchResults.first() | ||
|
|
||
| def args = ["assignSponsorToProject", "-p", project.getId().toString(), "-u", newReadOnlyUser.id] | ||
|
|
||
| when: | ||
| def (outputStream, errorStream) = executeCommand(ctx, args as String[]) | ||
|
|
||
| then: | ||
| errorStream.matches(blankRegex) | ||
| outputStream.contains("Successfully assigned sponsor ${newReadOnlyUser.email} to project ${project.getId()}") | ||
| } | ||
|
|
||
| // things we need to test for, include when either the sponsor or the project do not exist | ||
|
|
||
| @Unroll | ||
| def "fails gracefully when #title"(){ | ||
| given: | ||
| def readOnlyUser = new TestUser(faker) | ||
| readOnlyUser.id = createUser().id | ||
| def args = ["assignSponsorToProject", "-p", projectId, "-u", sponsorEmail] | ||
|
|
||
| when: | ||
| def (outputStream, errorStream) = executeCommand(ctx, args as String[]) | ||
|
|
||
| then: | ||
| outputStream.matches(blankRegex) | ||
| errorStream.contains("Failed to assign sponsor ${sponsorEmail} to project ${projectId}. ${errorMessage}") | ||
|
|
||
| where: | ||
| title | projectId | sponsorId | errorMessage | ||
| "project does not exist" | UUID.randomUUID() | readOnlyUser.id | "(404: Client 'justserve': Not Found)" | ||
| "sponsor does not exist" | searchResults.first().getId() | UUID.randomUUID() | "(400: User Not Found)" | ||
| "project and sponsor do not exist" | UUID.randomUUID() | UUID.randomUUID() | "(400: User Not Found)" | ||
| } | ||
| } | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.