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

feat(DataManagementApi): returns id in Assest, Policy and Contract de… #2012

Conversation

git-masoud
Copy link
Contributor

What this PR changes/adds

Made all the DataManagementApi POST resource return id of the created resource

  • Added wrapper class for PolicyDefinition#getId, ContractDefinition#getId and AssetIdPolicyDefinition#getId.
  • Modified Asset, PolicyDefinition and ContractDefinition classes to return their wrapperId in the POST functions
  • Modified and added the unit tests and integration tests

Why it does that

Improving the DataManagementApi

Linked Issue(s)

Closes #1984

Checklist

  • added appropriate tests?
  • performed checkstyle check locally?
  • added/updated copyright headers?
  • documented public classes/methods?
  • added/updated relevant documentation?
  • assigned appropriate label? (exclude from changelog with label no-changelog)
  • formatted title correctly? (take a look at the CONTRIBUTING and styleguide for details)

…finition Post calls. Modify and added the unit tests and integration tests
@git-masoud git-masoud temporarily deployed to Azure-dev September 25, 2022 15:43 Inactive
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

We are always happy to welcome new contributors ❤️ To make things easier for everyone, please make sure to follow our contribution guidelines, check if you have already signed the ECA, and relate this pull request to an existing issue or discussion.

@git-masoud git-masoud requested a review from ndr-brt September 25, 2022 15:44
@codecov-commenter
Copy link

codecov-commenter commented Sep 25, 2022

Codecov Report

Base: 63.64% // Head: 5.39% // Decreases project coverage by -58.24% ⚠️

Coverage data is based on head (5eb5003) compared to base (740c100).
Patch coverage: 0.00% of modified lines in pull request are covered.

❗ Current head 5eb5003 differs from pull request most recent head 75d5a32. Consider uploading reports for the commit 75d5a32 to get more accurate results

Additional details and impacted files
@@             Coverage Diff              @@
##               main   #2012       +/-   ##
============================================
- Coverage     63.64%   5.39%   -58.25%     
- Complexity        0     166      +166     
============================================
  Files           772     780        +8     
  Lines         16370   16521      +151     
  Branches       1055    1074       +19     
============================================
- Hits          10418     892     -9526     
- Misses         5508   15563    +10055     
+ Partials        444      66      -378     
Impacted Files Coverage Δ
...se/dataspaceconnector/api/model/IdResponseDto.java 0.00% <0.00%> (ø)
...r/api/datamanagement/asset/AssetApiController.java 0.00% <0.00%> (-97.73%) ⬇️
...actdefinition/ContractDefinitionApiController.java 0.00% <0.00%> (-95.24%) ⬇️
...tnegotiation/ContractNegotiationApiController.java 0.00% <0.00%> (-96.37%) ⬇️
...nagement/policy/PolicyDefinitionApiController.java 0.00% <0.00%> (-95.00%) ⬇️
.../transferprocess/TransferProcessApiController.java 0.00% <0.00%> (-95.92%) ⬇️
...eclipse/dataspaceconnector/spi/result/Failure.java 0.00% <0.00%> (-100.00%) ⬇️
...clipse/dataspaceconnector/spi/query/SortOrder.java 0.00% <0.00%> (-100.00%) ⬇️
.../eclipse/dataspaceconnector/policy/model/Rule.java 0.00% <0.00%> (-100.00%) ⬇️
...pse/dataspaceconnector/spi/event/EventPayload.java 0.00% <0.00%> (-100.00%) ⬇️
... and 548 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@git-masoud git-masoud temporarily deployed to Azure-dev September 25, 2022 16:46 Inactive
@git-masoud git-masoud temporarily deployed to Azure-dev September 25, 2022 17:03 Inactive
@git-masoud git-masoud temporarily deployed to Azure-dev September 25, 2022 17:10 Inactive
@git-masoud git-masoud added enhancement New feature or request api Feature related to the (REST) api labels Sep 25, 2022
@ApiResponse(responseCode = "400", description = "Request body was malformed",
content = @Content(array = @ArraySchema(schema = @Schema(implementation = ApiErrorDetail.class)))),
@ApiResponse(responseCode = "409", description = "Could not create asset, because an asset with that ID already exists",
content = @Content(array = @ArraySchema(schema = @Schema(implementation = ApiErrorDetail.class)))) }
)
void createAsset(@Valid AssetEntryDto assetEntryDto);
AssetId createAsset(@Valid AssetEntryDto assetEntryDto);
Copy link
Member

Choose a reason for hiding this comment

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

Please do not use these unnecessary wrappers. Just return a String.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I agree. I just tried to implement the same thing as contractnegotiation-api ,
org.eclipse.dataspaceconnector.api.datamanagement.contractnegotiation.model.NegotiationId

Copy link
Contributor Author

Choose a reason for hiding this comment

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

looking at the other endpoints responses, using String will breaks the consistency of the api responses, since all the other endpoints either return nothing or a json. Furthermore, as I mentioned contractnegotiation-api and transferprocess-api are already implemented with the same approach(Using a wrapper for Id).
if this argument is convincing, then I can use the subclasses of BaseResponseDto not instead of wrappers. However my question is, if I should use the ones which are already implemented such as AssetResponseDto or ContractDefinitionResponseDto, which returns the whole object or a new one to return only the Id?

@paullatzelsperger
Copy link
Member

paullatzelsperger commented Sep 26, 2022

There is really no point in wrapping a String in an object, much less in different objects that do the same thing. Please don't do that.
If the response absolutely cannot be a String for some reason (which you would have to argue well), you could look at the BaseResponseDto and subclass it.

Copy link
Contributor

@juliapampus juliapampus left a comment

Choose a reason for hiding this comment

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

@git-masoud You need to create an Eclipse account and sign the ECA.

@ndr-brt
Copy link
Member

ndr-brt commented Sep 26, 2022

There is really no point in wrapping a String in an object, much less in different objects that do the same thing. Please don't do that. If the response absolutely cannot be a String for some reason (which you would have to argue well), you could look at the BaseResponseDto and subclass it.

@paullatzelsperger if I remember correctly we decided for the wrapping (in the TransferProcess and in the ContractNegotiation controllers) to always have a json object as response type. I would keep this convention.

@paullatzelsperger
Copy link
Member

paullatzelsperger commented Sep 26, 2022

@paullatzelsperger if I remember correctly we decided for the wrapping (in the TransferProcess and in the ContractNegotiation controllers) to always have a json object as response type. I would keep this convention.

That is the reason I suggested the use of the BaseResponseDto (e.g. could be something like a StringResponseDto), in case we absolutely want the wrapping. That could even contain the creation timestamp. We do absolutely not need three different classes for wrapping a single String, all of which circumvent our DTO hierarchy.

Copy link
Member

@ndr-brt ndr-brt left a comment

Choose a reason for hiding this comment

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

Looks neat, apart from some duplicated contentType(JSON) for me it's good to go

@ndr-brt
Copy link
Member

ndr-brt commented Sep 26, 2022

@paullatzelsperger if I remember correctly we decided for the wrapping (in the TransferProcess and in the ContractNegotiation controllers) to always have a json object as response type. I would keep this convention.

That is the reason I suggested the use of the BaseResponseDto, in case we absolutely want the wrapping. We do absolutely not need three different classes for wrapping a single String, all of which circumvent our DTO hierarchy.

Oh, yeah, you're right, for some reasons I lost that part :D
Anyway it could be a subsequent refactoring.

@paullatzelsperger
Copy link
Member

paullatzelsperger commented Sep 26, 2022

@paullatzelsperger if I remember correctly we decided for the wrapping (in the TransferProcess and in the ContractNegotiation controllers) to always have a json object as response type. I would keep this convention.

That is the reason I suggested the use of the BaseResponseDto, in case we absolutely want the wrapping. We do absolutely not need three different classes for wrapping a single String, all of which circumvent our DTO hierarchy.

Oh, yeah, you're right, for some reasons I lost that part :D

@ndr_brt no worries :) However, this seems like an easy-enough thing to do, so I'd rather have this done properly now instead of introducing technical debt on purpose. I mean, we're talking about a trivial change, that would even reduce the surface of the current PR.

…StringResponseDto to be used instead of the object's wrappers. Remove extra contentType tests in the integration tests. Change all the Data Management Api post return to StringResponseDto. Change openapi.yaml
@git-masoud git-masoud temporarily deployed to Azure-dev September 27, 2022 06:55 Inactive
@git-masoud
Copy link
Contributor Author

Thanks for the tips. I implemented StringResponseDto to be used instead of the object's wrappers, although I am not sure about it's location(currently in extensions/common/api/api-core/src/main/java/org/eclipse/dataspaceconnector/api/model/StringResponseDto.java).

return new AssetId(result.getContent().getId());
return StringResponseDto.Builder.newInstance()
.id(result.getContent().getId())
.createdAt(result.getContent().getCreatedAt())
Copy link
Member

Choose a reason for hiding this comment

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

Please extract the "content" in a variable

@@ -111,7 +111,10 @@ public ContractDefinitionId createContractDefinition(@Valid ContractDefinitionRe
var result = service.create(contractDefinition);
if (result.succeeded()) {
monitor.debug(format("Contract definition created %s", result.getContent().getId()));
return new ContractDefinitionId(result.getContent().getId());
return StringResponseDto.Builder.newInstance()
.id(result.getContent().getId())
Copy link
Member

Choose a reason for hiding this comment

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

Please extract the "content" in a variable

return new PolicyDefinitionId(result.getContent().getId());
return StringResponseDto.Builder.newInstance()
.id(result.getContent().getId())
.createdAt(result.getContent().getCreatedAt())
Copy link
Member

Choose a reason for hiding this comment

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

Please extract the "content" in a variable

…to. Refactor and optimise the related classes
@git-masoud git-masoud temporarily deployed to Azure-dev September 27, 2022 08:41 Inactive
@paullatzelsperger
Copy link
Member

re-requesting my own review, so that I have it in my to-review list.

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;

@JsonDeserialize(builder = String.class)
Copy link
Member

Choose a reason for hiding this comment

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

that seems incorrect. should be IdResponseDto.Builder. Also, there is no test for this class. There should at least be a test to verify correct serialization and deserialization, which would have surfaced the incorrect builder.

@paullatzelsperger
Copy link
Member

@git-masoud the Openapi test is failing. don't forget to regenerate the open api spec and the swagger ui:

./gradlew resolve
./gradlew mergeOpenApiFiles
./gradlew generateSwaggerUI

Execute these three tasks in separate gradle calls (=do NOT join them together) and also commit that changeset.

@git-masoud git-masoud temporarily deployed to Azure-dev September 28, 2022 06:23 Inactive
@git-masoud git-masoud temporarily deployed to Azure-dev September 28, 2022 06:33 Inactive
@paullatzelsperger paullatzelsperger merged commit 5bc741c into eclipse-edc:main Sep 29, 2022
@paullatzelsperger
Copy link
Member

@git-masoud please note that I updated the PR title for merging so that it complies with our standards regarding conventional commits and contributing guidelines, specifically regarding the imperative mood.

@git-masoud git-masoud deleted the feature/1984_DataManagement_CreateController_Return_IdWrapper branch September 29, 2022 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Feature related to the (REST) api enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: make all the DataManagementApi POST resource return id of the created resource
5 participants