-
Notifications
You must be signed in to change notification settings - Fork 48
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
fix: Response body for post #484
base: main
Are you sure you want to change the base?
Conversation
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.
Hi @VivekHub97 ,
Thanks a lot for the implementation.
Actually, this should be fixed in core [1] and [2] first and then at the Controller side, the return type here in [1] and [2] is void but it should be SubmodelElement, and then at the HttpController [3] and [4] respectively for Repo and Service, it should be like below:
@Override
public ResponseEntity<SubmodelElement> postSubmodelElementSubmodelRepo(Base64UrlEncodedIdentifier submodelIdentifier, @Valid SubmodelElement body) {
SubmodelElement createdSME = repository.createSubmodelElement(submodelIdentifier.getIdentifier(), body);
return new ResponseEntity<SubmodelElement>(createdSME, HttpStatus.CREATED);
}
Inside SubmodelRepoHttpController [3] the method postSubmodelElementByPathSubmodelRepo is not fixed.
Following is the summary:
- Update interfaces of SubmodelRepository [1] and SubmodelService [2] for createSubmodelElement methods (there are multiple overloaded methods) such that the return type is SME instead of void.
- Then handle this appropriately wherever these interfaces are implemented possibly in all implementations (Crud*Repo) and all features.
- Update HTTP controllers for SMRepo [3] and SMService [4] like I defined above
- Update the test cases to additionally check the creation response wherever required. (Maybe do this first to achieve Test Driven Development).
[1] basyx-java-server-sdk/basyx.submodelrepository/basyx.submodelrepository-core/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/SubmodelRepository.java at main · eclipse-basyx/basyx-java-server-sdk (github.com)
[2] basyx-java-server-sdk/basyx.submodelservice/basyx.submodelservice-core/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/SubmodelService.java at main · eclipse-basyx/basyx-java-server-sdk (github.com)
[3] basyx-java-server-sdk/basyx.submodelrepository/basyx.submodelrepository-http/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/http/SubmodelRepositoryApiHTTPController.java at main · eclipse-basyx/basyx-java-server-sdk (github.com)
[4] basyx-java-server-sdk/basyx.submodelservice/basyx.submodelservice-http/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/http/SubmodelServiceHTTPApiController.java at main · eclipse-basyx/basyx-java-server-sdk (github.com)
e7d1b97
to
52e3ab5
Compare
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.
There are no tests in the SubmodelServiceSuite. Please add them as well.
public SubmodelElement createSubmodelElement(String submodelId, SubmodelElement smElement) { | ||
SubmodelService submodelService = getSubmodelServiceOrThrow(submodelId); | ||
|
||
submodelService.createSubmodelElement(smElement); | ||
|
||
updateSubmodel(submodelId, submodelService.getSubmodel()); | ||
return smElement; | ||
} |
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.
public SubmodelElement createSubmodelElement(String submodelId, SubmodelElement smElement) { | |
SubmodelService submodelService = getSubmodelServiceOrThrow(submodelId); | |
submodelService.createSubmodelElement(smElement); | |
updateSubmodel(submodelId, submodelService.getSubmodel()); | |
return smElement; | |
} | |
public SubmodelElement createSubmodelElement(String submodelId, SubmodelElement smElement) { | |
SubmodelService submodelService = getSubmodelServiceOrThrow(submodelId); | |
SubmodelElement createdSME = submodelService.createSubmodelElement(smElement); | |
updateSubmodel(submodelId, submodelService.getSubmodel()); | |
return createdSME; | |
} |
public SubmodelElement createSubmodelElement(String submodelId, String idShortPath, SubmodelElement smElement) throws ElementDoesNotExistException { | ||
SubmodelService submodelService = getSubmodelServiceOrThrow(submodelId); | ||
|
||
submodelService.createSubmodelElement(idShortPath, smElement); | ||
|
||
updateSubmodel(submodelId, submodelService.getSubmodel()); | ||
return smElement; | ||
} |
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.
public SubmodelElement createSubmodelElement(String submodelId, String idShortPath, SubmodelElement smElement) throws ElementDoesNotExistException { | |
SubmodelService submodelService = getSubmodelServiceOrThrow(submodelId); | |
submodelService.createSubmodelElement(idShortPath, smElement); | |
updateSubmodel(submodelId, submodelService.getSubmodel()); | |
return smElement; | |
} | |
public SubmodelElement createSubmodelElement(String submodelId, String idShortPath, SubmodelElement smElement) throws ElementDoesNotExistException { | |
SubmodelService submodelService = getSubmodelServiceOrThrow(submodelId); | |
SubmodelElement createdSME = submodelService.createSubmodelElement(idShortPath, smElement); | |
updateSubmodel(submodelId, submodelService.getSubmodel()); | |
return createdSME; | |
} |
@@ -99,17 +99,19 @@ public void setSubmodelElementValue(String submodelId, String idShortPath, Submo | |||
} | |||
|
|||
@Override | |||
public void createSubmodelElement(String submodelId, SubmodelElement smElement) { | |||
public SubmodelElement createSubmodelElement(String submodelId, SubmodelElement smElement) { | |||
decorated.createSubmodelElement(submodelId, smElement); | |||
SubmodelElement submodelElement = decorated.getSubmodelElement(submodelId, smElement.getIdShort()); |
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.
Ideally, we can get rid of this getSME operation and use the createSME return.
SubmodelElement submodelElement = decorated.getSubmodelElement(submodelId, smElement.getIdShort()); | |
SubmodelElement submodelElement = decorated.createSubmodelElement(submodelId, smElement); |
} | ||
|
||
@Override | ||
public void createSubmodelElement(String submodelId, String idShortPath, SubmodelElement smElement) throws ElementDoesNotExistException { | ||
public SubmodelElement createSubmodelElement(String submodelId, String idShortPath, SubmodelElement smElement) throws ElementDoesNotExistException { | ||
decorated.createSubmodelElement(submodelId, idShortPath, smElement); | ||
SubmodelElement submodelElement = decorated.getSubmodelElement(submodelId, idShortPath); |
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.
Same as above
|
||
assertEquals(responseSubmodelElement, submodelElement); |
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.
Expected should be first parameter.
assertEquals(responseSubmodelElement, submodelElement); | |
assertEquals(submodelElement, responseSubmodelElement); |
InMemorySubmodelService inMemorySubmodelService = getInMemorySubmodelService(); | ||
inMemorySubmodelService.createSubmodelElement(submodelElement); | ||
Submodel submodel = inMemorySubmodelService.getSubmodel(); | ||
crudRepository.save(submodel); | ||
return submodelElement; |
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.
Use the returned SME from line 108 and not return the SME received as a parameter.
InMemorySubmodelService inMemorySubmodelService = getInMemorySubmodelService(); | ||
inMemorySubmodelService.createSubmodelElement(idShortPath, submodelElement); | ||
Submodel submodel = inMemorySubmodelService.getSubmodel(); | ||
crudRepository.save(submodel); | ||
return submodelElement; |
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.
Same as above.
@@ -718,6 +718,10 @@ private DefaultEntity createDummyEntityWithStatement(SubmodelElement submodelEle | |||
private DefaultProperty createDummyProperty(String idShort) { | |||
return new DefaultProperty.Builder().idShort(idShort).category("cat1").value("123").valueType(DataTypeDefXsd.INTEGER).build(); | |||
} | |||
|
|||
private SubmodelElement createDummySME(String idShort) { |
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.
Could you please explain the need of this? Because I can't find any reference to this private method in this class.
@@ -93,19 +93,21 @@ public void setSubmodelElementValue(String idShortPath, SubmodelElementValue val | |||
} | |||
|
|||
@Override | |||
public void createSubmodelElement(SubmodelElement submodelElement) { | |||
public SubmodelElement createSubmodelElement(SubmodelElement submodelElement) { | |||
decorated.createSubmodelElement(submodelElement); | |||
SubmodelElement smElement = decorated.getSubmodelElement(submodelElement.getIdShort()); |
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 get rid of this method and use the returned SME from line 97
} | ||
|
||
@Override | ||
public void createSubmodelElement(String idShortPath, SubmodelElement submodelElement) throws ElementDoesNotExistException { | ||
public SubmodelElement createSubmodelElement(String idShortPath, SubmodelElement submodelElement) throws ElementDoesNotExistException { | ||
|
||
decorated.createSubmodelElement(idShortPath, submodelElement); | ||
|
||
SubmodelElement smElement = decorated.getSubmodelElement(submodelElement.getIdShort()); |
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.
Same comment as above.
fix: Response body for posting in submodel repository and submodel service
Closes #398
Closes #457