-
Notifications
You must be signed in to change notification settings - Fork 2
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
Try to rework unique validator to make it possible to validate count … #39
base: master
Are you sure you want to change the base?
Conversation
|
||
groupedCommands.forEach((eIdentifier, entityChanges) -> | ||
entityChanges.stream() | ||
.skip(maxCount) |
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.
skip
is a clever idea :)
but lets not add errors yet because we also add them later, and we don't need to add the same error twice.
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 think we should delete it from list, like it was before. As i understand in existed logic on first stage we check duplicates in commands, remove it and that compare with db what's left
return; | ||
|
||
UniqueKey<E> pk = uniqueKey.getEntityType().getPrimaryKey(); | ||
EntityField<E, ?>[] uniqueKeyAndPK = ArrayUtils.addAll(uniqueKey.getFields(), pk.getFields()); | ||
|
||
Map<Identifier<E>, CurrentEntityState> duplicates = fetcher.fetch(uniqueKey.getEntityType(), commandsByIds.keySet(), condition, uniqueKeyAndPK) | ||
Map<Identifier<E>, List<CurrentEntityState>> duplicates = fetcher.fetch(uniqueKey.getEntityType(), groupedCommands.keySet(), condition, uniqueKeyAndPK) |
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.
"duplicates" is not a good name anymore.
we can call them "itemsInDB"
.collect(groupingBy(e -> createKeyValue(e, uniqueKey), toList())); | ||
|
||
duplicates.forEach((eIdentifier, currentEntityStates) -> { | ||
List<? extends EntityChange<E>> identifierCommands = groupedCommands.get(eIdentifier); |
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.
we can delete the "in same bulk" detection (line 57) and have a single check here:
groupedCommands.forEach( (group, cmds) -> {
int maxAllowedInBulk = maxCount - itemsFromDB.get(group).size() ;
// now do the "skip" trick with maxAllowedInBulk
};
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.
we'll get wrong error messages. I don't know is it critical, but when we have duplicate in db existed code should pass db id of duplicate. So here we should iterate over itemsFromDB
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.
One more interesting question - what should be in error message when we have 3 items in db, maxCount is 3 and few items in commands list?
…of entities