Skip to content

OBPIH-6271 Add an ability to delete existing default preference type …#4872

Merged
awalkowiak merged 3 commits intodevelopfrom
OBPIH-6271
Oct 8, 2024
Merged

OBPIH-6271 Add an ability to delete existing default preference type …#4872
awalkowiak merged 3 commits intodevelopfrom
OBPIH-6271

Conversation

@kchelstowski
Copy link
Collaborator

…via import

✨ Description of Change

A concise summary of what is being changed. Please provide enough context for reviewers to be able to understand the change and why it is necessary. If the issue/ticket already provides enough information, you can put "See ticket" as the description.

Link to GitHub issue or Jira ticket:

Description:


📷 Screenshots & Recordings (optional)

If this PR contains a UI change, consider adding one or more screenshots here or link to a screen recording to help reviewers visualize the change. Otherwise, you can remove this section.

@kchelstowski kchelstowski self-assigned this Oct 2, 2024
@github-actions github-actions bot added the domain: backend Changes or discussions relating to the backend server label Oct 2, 2024
ProductSupplierPreference productSupplierPreference = productSupplier.getGlobalProductSupplierPreference()
if (preferenceType) {
ProductSupplierPreference productSupplierPreference = productSupplier.getGlobalProductSupplierPreference()
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you replace the hardcoded date format with the one placed in Constants.groovy?

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can also use the SimpleDateFormat from this file, it's already declared here

Copy link
Member

Choose a reason for hiding this comment

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

Good point @alannadolny

Using SimpleDateFormat back in Grails 1.3.9 / Java 7 was a no-brainer since it was all we really had. I think we attempted to use Joda Time at some point to avoid some of the badness of the Java 7 date libraries. In Java 8 I think the datetime and formatting libraries are a bit better, so we could potentially use those. Wrapping whatever we do around a utility / service might be a good idea so we can codify our convention in one place.

So here are my recommendations.

  • Add Alan's recommendation to our current coding convention (using SimpleDateFormat, Constants, configuration) to make this clear to all developers.
  • If we're calling this assignDefaultPreferenceType() in a loop, we should try to find a way to share the date formatter across iterations of the loop (static variable, pass in as an argument) as this could be expensive.
  • Consider adding a wrapper (utility, service) to abstract these methods so we can update the implementation without having to refactor a lot of code.
  • I would also recommend using the interface / abstract class on the assignment side.
    DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy")
  • Create a discovery ticket to figure out best practices for date formatting in Java 8 and beyond.

None of these are urgent recommendations, so no need to do them here in this PR and I'll defer to @ewaterman @awalkowiak to decide whether any of these gets done at all.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@alannadolny @jmiranda It was only a copy-paste of already existing code, hence I didn't pay much attention to that, but obviously I can change it to the existing constant.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I think we'd benefit from a mini discovery to standardize how we format our dates and then create some kind of date util class as Justin mentioned that abstracts away the specific implementation in case we need to change it at some point.

For this ticket though since it's not new functionality, I think we stick with Alan's recommendation.

if (globalPreferenceTypeValidityEndDate) {
productSupplierPreference.validityEndDate = globalPreferenceTypeValidityEndDate
}
return
Copy link
Collaborator

Choose a reason for hiding this comment

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

won't it be cleaner to check if the preference type doesn't exist at the begging of the method? Doing this change you don't have to place so much logic in the if (preferenceType) so probably it should be easier to read. If you won't do this change it looks good to me.

Copy link
Collaborator Author

@kchelstowski kchelstowski Oct 2, 2024

Choose a reason for hiding this comment

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

could you elaborate on what would be cleaner? in my opinion doing if (!preferenceType) at the beginning wouldn't change much, because the logic of assigning preferences would have to stay the same, so the only change would be, that this logic wouldn't be nested inside the if statement, unless I miss something 🤔

productSupplierPreference.comments = comments

def globalPreferenceTypeValidityEndDate = params.globalPreferenceTypeValidityEndDate ? dateFormat.parse(params.globalPreferenceTypeValidityEndDate) : null
Date globalPreferenceTypeValidityStartDate = validityStartDate ? Constants.EXPIRATION_DATE_FORMATTER.parse(validityStartDate) : null
Copy link
Member

@ewaterman ewaterman Oct 4, 2024

Choose a reason for hiding this comment

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

this isn't an expiration date though, right? That constant just happens to have the same value that we want. You could create a new feature-specific constant (PREFERENCE_TYPE_VALIDITY_DATE_FORMAT) and use that but I think I'd instead create a new generic constant based on the format that you're using.

Maybe MONTH_DAY_YEAR_DATE_FORMAT = "MM/dd/yyyy"

Anyways, this is risking re-opening the date formatting discussion so I'll defer to whatever you think is best.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was supposed to use an existing constant. I would say technically it might be considered as the expiration date, as the validity date is somewhat a synonym, isn't it? 🤔

@awalkowiak awalkowiak merged commit 9f938f6 into develop Oct 8, 2024
@awalkowiak awalkowiak deleted the OBPIH-6271 branch October 8, 2024 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: backend Changes or discussions relating to the backend server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants