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

Try to rework unique validator to make it possible to validate count … #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AUsachov
Copy link

…of entities


groupedCommands.forEach((eIdentifier, entityChanges) ->
entityChanges.stream()
.skip(maxCount)
Copy link
Contributor

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.

Copy link
Author

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)
Copy link
Contributor

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);
Copy link
Contributor

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
};

Copy link
Author

@AUsachov AUsachov Jun 23, 2021

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

Copy link
Author

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?

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