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

TSPS-136 Require a JobControl object containing a job id when creating a new job #52

Merged
merged 12 commits into from
Jan 31, 2024

Conversation

mmorgantaylor
Copy link
Collaborator

@mmorgantaylor mmorgantaylor commented Jan 30, 2024

Description

Per DSP's Async API best practices, the caller must provide a job id contained in a JobControl object. This PR implements that requirement and validates that the string the user has provided is a uuid.

Some other minor edits:

  • removed our MissingRequiredFieldsException class and use TCL's MissingRequiredFieldException instead
  • removed the user's email address (PII) from the log message
  • changed the base class for StairwayDatabaseConfigurationTest from BaseTest to BaseEmbeddedDbTest, which allows that test to pass for me locally.

Jira Ticket

https://broadworkbench.atlassian.net/browse/TSPS-136

Copy link
Collaborator

@jsotobroad jsotobroad left a comment

Choose a reason for hiding this comment

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

curiosities and some questions

properties:
description:
description: >-
User-provided description of the job request.
type: string
jobControl:
Copy link
Collaborator

Choose a reason for hiding this comment

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

just curious, what is the benefit of this schema being an object vs a string like pipelineVersion?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it's the spec. it's an object that contains currently just the "id" field, but in future it could additionally contain things like notification preferences. does this answer your question?

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

String errorMessage = error.getDefaultMessage();
errors.put(fieldName, errorMessage);
});
String validationErrorMessage = "Request could not be parsed or was invalid: " + errors;
Copy link
Collaborator

Choose a reason for hiding this comment

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

i would probaby put at least a \n between each error so it can be a bit easier to read (if only slightly)

.getAllErrors()
.forEach(
error -> {
String fieldName = ((FieldError) error).getField();
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we have to do the cast here? surprised thats necessary if we know what the exception we're starting with is.

Copy link
Collaborator Author

@mmorgantaylor mmorgantaylor Jan 31, 2024

Choose a reason for hiding this comment

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

we seemingly do... .getAllErrors returns a List, and ObjectError doesn't have a .getField method. let me know if I'm missing something though!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nevermind! there's a .getFieldErrors method!

Copy link
Collaborator

Choose a reason for hiding this comment

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

woohoo

@@ -119,17 +120,20 @@ public ResponseEntity<ApiCreateJobResponse> createJob(
@PathVariable("pipelineId") String pipelineId, @RequestBody ApiCreateJobRequestBody body) {
final SamUser userRequest = getAuthenticatedInfo();
String userId = userRequest.getSubjectId();
String jobIdString = body.getJobControl().getId();
UUID jobId = validateJobId(jobIdString);
Copy link
Collaborator

Choose a reason for hiding this comment

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

what do we think abotu using the openapi yaml to validate this for us. something like what is found in https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.1.md#support-for-x-www-form-urlencoded-request-bodies

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nice, I didn't see the "format: uuid" option. that throws a different error that we have to handle differently in the GlobalExceptionHandler. I've implemented it... see what you think.

logger.info("Create new imputation version {} job for user {}", pipelineVersion, userId);

JobBuilder jobBuilder =
jobService
.newJob()
.jobId(createJobId())
.jobId(jobId)
Copy link
Collaborator

Choose a reason for hiding this comment

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

woooo! things are comin together

Copy link

@mmorgantaylor mmorgantaylor merged commit d64fb72 into main Jan 31, 2024
13 checks passed
@mmorgantaylor mmorgantaylor deleted the TSPS-136_mma_require_jobid branch January 31, 2024 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants