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

Uniqueness of key for RelationshipAttributes #319

Merged
merged 110 commits into from
Dec 17, 2024

Conversation

britsta
Copy link
Contributor

@britsta britsta commented Nov 4, 2024

Readiness checklist

  • I added/updated tests.
  • I ensured that the PR title is good enough for the changelog.
  • I labeled the PR.

Description

In each Relationship, there should only be at most one RelationshipAttribute for each Relationship context for a given trio of value.@type, owner and key.

Validation To Be Added

It is probably only necessary to ensure the uniqueness of the key in those cases in which new RelationshipAttributes (ThirdPartyRelationshipAttributes explicitly excluded) are created. This means, validation needs to be added for the following cases:

  • ReadAttributeRequestItem with RelationshipAttributeQuery as query.
  • ProposeAttributeRequestItem with RelationshipAttributeQuery as query.
  • CreateAttributeRequestItem with RelationshipAttribute as attribute to be created.

To be sure, the validation is added on both sides when the Request is created and when the Request is received. Also note the following details:

  • If there are several RequestItems within a Request that would lead to the creation of RelationshipAttributes with the same key, the creation of such a Request is prevented by early iteration through the RequestItems. Additionally, an error would be thrown on the side of the Recipient of the Request in the unlikely event that it has received such a Request.
  • If the Recipient receives a Request that it cannot accept regardless of its specified parameters, an error is thrown. If parameters can be specified differently so that acceptance is possible, an ErrorValidationResult is returned instead.

Validation Not To Be Added

When it comes to existing RelationshipAttributes that are shared and lead to the creation of ThirdPartyRelationshipAttributes, no further validation needs to be added. There are three reasons for this:

  • The uniqueness of the key is already ensured when the initial RelationshipAttributes are created.
  • The re-sharing of the same RelationshipAttribute that has already been shared is already prohibited.
  • It makes sense to query a ThirdPartyRelationshipAttribute with the same key again, as it can happen during the succession of RelationshipAttributes that there is another existing RelationshipAttribute with the same key that is to be read.

Open Questions

  • We have to decide how to handle it when the two Identities involved in the Relationship send each other a Request to create a RelationshipAttribute with the same key and both accept it before they have received the response from their counterpart by synchronization. This can possibly be solved by forcing an early synchronization.
  • Requests should not become unacceptable just because it is not possible to accept a single RequestItem by creating another RelationshipAttribute with the same key. This can perhaps be solved by adding a new ResponseItem.

Further Notes

  • Note that it is a priori not possible to add validations in the applyIncomingResponseItem method of the various RequestItemProcessors that prevent the creation of a RelationshipAttribute with an already existing key, as this would lead to inconsistent data sets between the two Identities of the Relationship.
  • Nested RequestItemGroups are currently not fully supported, which is why some code had to be added in a simplified version.

@britsta britsta added wip Work in Progress (blocks mergify from auto update the branch) enhancement New feature or request labels Nov 4, 2024
Copy link

codecov bot commented Nov 4, 2024

Codecov Report

Attention: Patch coverage is 91.43646% with 31 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...teAttribute/CreateAttributeRequestItemProcessor.ts 59.67% 25 Missing ⚠️
...ity/validateRelationshipAttributesWithinRequest.ts 96.29% 6 Missing ⚠️
Files with missing lines Coverage Δ
...nsumption/src/consumption/ConsumptionCoreErrors.ts 80.69% <100.00%> (+0.20%) ⬆️
...ion/src/modules/attributes/AttributesController.ts 91.13% <100.00%> (+0.12%) ⬆️
...es/requests/incoming/IncomingRequestsController.ts 95.93% <100.00%> (+0.07%) ⬆️
...eAttribute/ProposeAttributeRequestItemProcessor.ts 91.76% <100.00%> (+1.05%) ⬆️
...readAttribute/ReadAttributeRequestItemProcessor.ts 91.74% <100.00%> (+1.02%) ⬆️
...es/requests/outgoing/OutgoingRequestsController.ts 82.31% <100.00%> (+0.20%) ⬆️
...ity/validateRelationshipAttributesWithinRequest.ts 96.29% <96.29%> (ø)
...teAttribute/CreateAttributeRequestItemProcessor.ts 70.51% <59.67%> (-25.98%) ⬇️

britsta and others added 24 commits November 4, 2024 15:08
@britsta
Copy link
Contributor Author

britsta commented Dec 16, 2024

The other RequestItemProcessor tests should move to the standard of the CreateAttributeProcessor test. Also in the controller tests there coud be more options tested, although I can't tell which extent is sensible - I'd definitely want some positive tests though

I wanted to avoid too much redundancy, but will add a few more tests. :)

@britsta
Copy link
Contributor Author

britsta commented Dec 16, 2024

@britsta Could you add the reason for why a failed validation is sometimes an error and sometimes just a negative ValidationResult to the description or somewhere? I can't find it 😃

Hahah sure, I wanted to at least subtly differentiate whether a Request is messed up and therefore cannot be accepted regardless of the user input (this is where the concept of unacceptable Requests comes into play), or whether the user has provided inappropriate input and can accept (or create) the Request by correcting their input.

With messed up Requests I throw an error, with inappropriate user input I return a negative ValidationResult.

Copy link
Contributor

@Milena-Czierlinski Milena-Czierlinski left a comment

Choose a reason for hiding this comment

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

I'll continue tomorrow. :)

@britsta britsta enabled auto-merge (squash) December 17, 2024 15:20
Copy link
Member

@jkoenig134 jkoenig134 left a comment

Choose a reason for hiding this comment

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

Blind Approval for @Milena-Czierlinski

@britsta britsta merged commit b44bcaf into main Dec 17, 2024
19 checks passed
@britsta britsta deleted the feature/uniqueness-of-key-for-relationshipattributes branch December 17, 2024 15:49
sebbi08 pushed a commit that referenced this pull request Dec 18, 2024
* refactor: preapare CreateAttributeRequestItemProcessor to add more validation

* feat: add validation for CreateAttributeRequestItemProcessor

* test: CreateAttributeRequestItemProcessor key validation

* fix: uniqueness for key only instead of pair of owner and key

* fix: failing test

* test: ensure key uniqueness in attributes.test

* test: ensure key uniqueness in CreateRelationshipAttributeRequestItemDVO.test

* feat: use database language every database understands

* test: ensure key uniqueness only for constant ownership

* fix: too late clean up of Attributes

* feat: ensure key uniqueness only for RelationshipAttributes that are not in deletion in any way

* refactor: extract function call as auxiliary function

* refactor: put afterEach block inside describe block

* feat: ensure key uniqueness for Recipient within CreateAttributeRequestItemProcessor

* refactor: auxiliary function can be applied to queries as well

* feat: ensure key uniqueness for Sender within ReadAttributeRequestItemProcessor

* feat: ensure key uniqueness only for constant value type

* fix: failing tests with async canCreateOutgoingRequestItem method

* feat: key uniqueness for Recipient within ReadAttributeRequestItemProcessor

* feat: ensure key uniquess for empty owner as placeholder as well

* refactor: simplify error message

* refactor: move validation to canAccept method

* refactor: standardize error messages

* test: ensure key uniqueness with empty owner

* test: move tests to canAccept block

* fix: call accept instead of canAccept

* test: refactor canAccept test with SuccessfulValidationResult

* test: make tests independent of each other

* feat: ensure key uniqueness for empty owner queried with ReadAttributeRequestItem

* feat: ensure key uniqueness on Sender site of ProposeAttributeRequestItemProcessor

* feat: ensure key uniqueness on Recipient site of ProposeAttributeRequestItemProcessor

* refactor: standardize error messages

* feat: prohibit Requests that create more than one RelationshipAttribute with same key

* fix: title type

* test: key uniqueness of incomingRequestsController

* test: key uniqueness of OutgoingRequestsController

* refactor: remove recursion of IncomingRequestsController

* refactor: keep RequestItemGroup in mind

* refactor: use auxiliary method for clearness

* feat: handle empty owner in IncomingRequestsController and OutgoingRequestsController

* test: ensure key uniqueness for empty owner

* refactor: move validation from canDecide to canAccept

* fix: failing IncomingRequestsController test

* test: ensure key uniqueness with RequestItemGroups

* fix: wrong DecideRequestParameters for RequestItemGroups

* feat: use already known separation sequence

* feat: give better validation function name

* refactor: do not break existing code blocks anymore

* fix: error due to incorrect merging

* test: ensure key uniqueness with ProposeAttributeRequestItem

* chore: descriptive values should not start with capital letter

* refactor: rename error code

* feat: distinguish between user mistake and deformed Request

* feat: throwing instead of returning error if Request is deformed

* feat: reuse key uniqueness error

* feat: distinguish between deformed Requests and wrong accept parameters

* test: RequestItem cannot be accepted due to incorrect params of User

* fix: failing test due to void return

* feat: self-explanatory variable names

* refactor: more renaming of variables

* refactor: unify renaming

* feat: simplify error message for unknown recipient of Request

* feat: incorporate some review comments

* fix: failing test due to wrong error format

* feat: incorporate review comment

* refactor: prepare reusability of code

* fix: error due to merge

* feat: use JSON.stringify() instead of own method for extracting identifiers

* refactor: reduce redundancy by move auxiliary functions to different file

* feat: inform user what key would be redundantly in use

* feat: incorporate some review comments

* feat: incoporate review comments

* refactor: change order of thrown errors

* test: can propose and query RelationshipAttribute with same key but different value type

* feat: incorporate review comments

* refactor: simplify extraction of fragments of mustBeAcceptedItems

* refactor: further simplification of extraction of fragments of mustBeAcceptedItems

* refactor: simplify extraction of fragments of accepte items

* fix: returned instead of continued

* test: RequestItem cannot be accepted if key uniqueness is violated regardless of value of mustBeAccepted

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Milena Czierlinski <milena.czierlinski@js-soft.com>
sebbi08 added a commit that referenced this pull request Dec 18, 2024
… that has passed (#369)

* chore: respect expireation date of request when creating request and sending message

* chore: white space

* Update packages/consumption/test/modules/requests/OutgoingRequestsController.test.ts

Co-authored-by: Julian König <33655937+jkoenig134@users.noreply.github.com>

* Update packages/consumption/src/consumption/ConsumptionCoreErrors.ts

Co-authored-by: Milena Czierlinski <146972016+Milena-Czierlinski@users.noreply.github.com>

* chore: fix test misstake

* chore: fix tests

* chore: PR comments

* chore: revert Date changes

* chore: pr comments

* chore: test

* chore: fix flaky test

* Update packages/consumption/test/modules/requests/OutgoingRequestsController.test.ts

Co-authored-by: Milena Czierlinski <146972016+Milena-Czierlinski@users.noreply.github.com>

* Update packages/consumption/test/modules/requests/OutgoingRequestsController.test.ts

Co-authored-by: Milena Czierlinski <146972016+Milena-Czierlinski@users.noreply.github.com>

* chore: improve test performance

* chore: improve test performance

* chore: PR comments

* refactor: add empty lines

* Uniqueness of `key` for RelationshipAttributes (#319)

* refactor: preapare CreateAttributeRequestItemProcessor to add more validation

* feat: add validation for CreateAttributeRequestItemProcessor

* test: CreateAttributeRequestItemProcessor key validation

* fix: uniqueness for key only instead of pair of owner and key

* fix: failing test

* test: ensure key uniqueness in attributes.test

* test: ensure key uniqueness in CreateRelationshipAttributeRequestItemDVO.test

* feat: use database language every database understands

* test: ensure key uniqueness only for constant ownership

* fix: too late clean up of Attributes

* feat: ensure key uniqueness only for RelationshipAttributes that are not in deletion in any way

* refactor: extract function call as auxiliary function

* refactor: put afterEach block inside describe block

* feat: ensure key uniqueness for Recipient within CreateAttributeRequestItemProcessor

* refactor: auxiliary function can be applied to queries as well

* feat: ensure key uniqueness for Sender within ReadAttributeRequestItemProcessor

* feat: ensure key uniqueness only for constant value type

* fix: failing tests with async canCreateOutgoingRequestItem method

* feat: key uniqueness for Recipient within ReadAttributeRequestItemProcessor

* feat: ensure key uniquess for empty owner as placeholder as well

* refactor: simplify error message

* refactor: move validation to canAccept method

* refactor: standardize error messages

* test: ensure key uniqueness with empty owner

* test: move tests to canAccept block

* fix: call accept instead of canAccept

* test: refactor canAccept test with SuccessfulValidationResult

* test: make tests independent of each other

* feat: ensure key uniqueness for empty owner queried with ReadAttributeRequestItem

* feat: ensure key uniqueness on Sender site of ProposeAttributeRequestItemProcessor

* feat: ensure key uniqueness on Recipient site of ProposeAttributeRequestItemProcessor

* refactor: standardize error messages

* feat: prohibit Requests that create more than one RelationshipAttribute with same key

* fix: title type

* test: key uniqueness of incomingRequestsController

* test: key uniqueness of OutgoingRequestsController

* refactor: remove recursion of IncomingRequestsController

* refactor: keep RequestItemGroup in mind

* refactor: use auxiliary method for clearness

* feat: handle empty owner in IncomingRequestsController and OutgoingRequestsController

* test: ensure key uniqueness for empty owner

* refactor: move validation from canDecide to canAccept

* fix: failing IncomingRequestsController test

* test: ensure key uniqueness with RequestItemGroups

* fix: wrong DecideRequestParameters for RequestItemGroups

* feat: use already known separation sequence

* feat: give better validation function name

* refactor: do not break existing code blocks anymore

* fix: error due to incorrect merging

* test: ensure key uniqueness with ProposeAttributeRequestItem

* chore: descriptive values should not start with capital letter

* refactor: rename error code

* feat: distinguish between user mistake and deformed Request

* feat: throwing instead of returning error if Request is deformed

* feat: reuse key uniqueness error

* feat: distinguish between deformed Requests and wrong accept parameters

* test: RequestItem cannot be accepted due to incorrect params of User

* fix: failing test due to void return

* feat: self-explanatory variable names

* refactor: more renaming of variables

* refactor: unify renaming

* feat: simplify error message for unknown recipient of Request

* feat: incorporate some review comments

* fix: failing test due to wrong error format

* feat: incorporate review comment

* refactor: prepare reusability of code

* fix: error due to merge

* feat: use JSON.stringify() instead of own method for extracting identifiers

* refactor: reduce redundancy by move auxiliary functions to different file

* feat: inform user what key would be redundantly in use

* feat: incorporate some review comments

* feat: incoporate review comments

* refactor: change order of thrown errors

* test: can propose and query RelationshipAttribute with same key but different value type

* feat: incorporate review comments

* refactor: simplify extraction of fragments of mustBeAcceptedItems

* refactor: further simplification of extraction of fragments of mustBeAcceptedItems

* refactor: simplify extraction of fragments of accepte items

* fix: returned instead of continued

* test: RequestItem cannot be accepted if key uniqueness is violated regardless of value of mustBeAccepted

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Milena Czierlinski <milena.czierlinski@js-soft.com>

* chore: prettier

* chore: pr comments

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Julian König <33655937+jkoenig134@users.noreply.github.com>
Co-authored-by: Milena Czierlinski <146972016+Milena-Czierlinski@users.noreply.github.com>
Co-authored-by: Milena Czierlinski <milena.czierlinski@js-soft.com>
Co-authored-by: Britta Stallknecht <146106656+britsta@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants