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

OBPIH-5972 trim white space from firstname and last name when binding user to recipient on PO items import #4384

Conversation

drodzewicz
Copy link
Collaborator

The issue is that somehow in the database there was a user which had an extra space in it's firstname column value like

firstname: "name ",
lastname: "lastname"

I don't know how that extra space appeared there, because I tested creating Person/User in the UI and via import and in both cases it clears the extra white space, the only way I was able to reproduce it is updating the value directly in the database.

When exporting the PO items excel it exports the users value with that extra space "name lastname" (there are two spaces in between) and trying to re-import the same file causes the system to not find the set user because when we do split(" ") it splits by the first space and now we are looking for users with a combo firstname and last name
[ firstname: "name", lastname: " lastname" ]

adding *.trim() does solve the problem in a way, but I am not sure if it is necessary because the simplest solution would be to just fix the data and I am not sure if we want to dive that deep into parsing/transforming potentially incorrect data.

I pushed this PR as an example and to give you guys a better context to what is happening, but if you think that we should not go this direction and just fix the data then we can close this PR.

@drodzewicz drodzewicz added the status: needs discussion An issue that needs further discussion before it can proceed. label Nov 17, 2023
@drodzewicz drodzewicz self-assigned this Nov 17, 2023
@@ -71,7 +71,7 @@ class PersonDataService {
}

String[] extractNames(String combinedNames) {
String[] names = combinedNames.split(" ", 2)
String[] names = combinedNames.split(" ", 2)*.trim()
Copy link
Member

Choose a reason for hiding this comment

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

I like the spread operator, but feel a little weird using it when we're mutating the results. It's probably better to use a collect to be more readable and explicit.

String[] names = combinedNames.split(" ", 2).collect { name?.trim() }

With that said, the official Groovy docs seem to imply (using the phrase "invoke an action on all items") so I'm okay with using it this way as long as everyone else is okay with it. Since @awalkowiak is the only other reviewer, I'll let him voice his opinion.

The Spread-dot Operator (*.), often abbreviated to just Spread Operator, is used to invoke an action on all items of an aggregate object.

Source: https://groovy-lang.org/operators.html#_spread_operator

@drodzewicz drodzewicz removed the status: needs discussion An issue that needs further discussion before it can proceed. label Nov 30, 2023
@awalkowiak awalkowiak merged commit 6b6869e into feature/upgrade-to-grails-3.3.10 Nov 30, 2023
1 check passed
@awalkowiak awalkowiak deleted the OBPIH-5972-recipient-exports-with-two-spaces-in-po-items-export branch November 30, 2023 19:36
awalkowiak added a commit that referenced this pull request Dec 11, 2023
… binding user to recipient on PO items import (#4384)"

This reverts commit 6b6869e.
@awalkowiak awalkowiak restored the OBPIH-5972-recipient-exports-with-two-spaces-in-po-items-export branch December 11, 2023 15:39
awalkowiak added a commit that referenced this pull request Dec 12, 2023
… binding user to recipient on PO items import (#4384)" (#4412)

This reverts commit 6b6869e.
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.

None yet

3 participants