From 7a0b4d285062037040906053af1f85f26ebc77b5 Mon Sep 17 00:00:00 2001 From: Agarwal Date: Sun, 6 Oct 2024 15:38:38 +0200 Subject: [PATCH 1/7] fix: Response body for posting in submodel repository and submodel service --- .../http/SubmodelRepositoryApiHTTPController.java | 2 +- .../http/SubmodelServiceHTTPApiController.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/basyx.submodelrepository/basyx.submodelrepository-http/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/http/SubmodelRepositoryApiHTTPController.java b/basyx.submodelrepository/basyx.submodelrepository-http/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/http/SubmodelRepositoryApiHTTPController.java index 645486669..4f8eb4c7b 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-http/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/http/SubmodelRepositoryApiHTTPController.java +++ b/basyx.submodelrepository/basyx.submodelrepository-http/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/http/SubmodelRepositoryApiHTTPController.java @@ -182,7 +182,7 @@ public ResponseEntity postSubmodelElementByPathSubmodelRepo(Bas @Override public ResponseEntity postSubmodelElementSubmodelRepo(Base64UrlEncodedIdentifier submodelIdentifier, @Valid SubmodelElement body) { repository.createSubmodelElement(submodelIdentifier.getIdentifier(), body); - return new ResponseEntity(HttpStatus.CREATED); + return new ResponseEntity(body, HttpStatus.CREATED); } @Override diff --git a/basyx.submodelservice/basyx.submodelservice-http/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/http/SubmodelServiceHTTPApiController.java b/basyx.submodelservice/basyx.submodelservice-http/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/http/SubmodelServiceHTTPApiController.java index 66498d924..e2587d33b 100644 --- a/basyx.submodelservice/basyx.submodelservice-http/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/http/SubmodelServiceHTTPApiController.java +++ b/basyx.submodelservice/basyx.submodelservice-http/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/http/SubmodelServiceHTTPApiController.java @@ -199,7 +199,7 @@ public ResponseEntity postSubmodelElement(@Parameter(in = Param @Parameter(in = ParameterIn.QUERY, description = "Determines the structural depth of the respective resource content", schema = @Schema(allowableValues = { "deep", "core" }, defaultValue = "deep")) @Valid @RequestParam(value = "level", required = false, defaultValue = "deep") String level) { service.createSubmodelElement(body); - return new ResponseEntity(HttpStatus.CREATED); + return new ResponseEntity(body, HttpStatus.CREATED); } @Override @@ -207,7 +207,7 @@ public ResponseEntity postSubmodelElementByPath( @Parameter(in = ParameterIn.PATH, description = "IdShort path to the submodel element (dot-separated)", required = true, schema = @Schema()) @PathVariable("idShortPath") String idShortPath, @Parameter(in = ParameterIn.DEFAULT, description = "Requested submodel element", required = true, schema = @Schema()) @Valid @RequestBody SubmodelElement body) { service.createSubmodelElement(idShortPath, body); - return new ResponseEntity(HttpStatus.CREATED); + return new ResponseEntity(body, HttpStatus.CREATED); } @Override From 52e3ab5562854c6ffd459d158922f0b8174d75ff Mon Sep 17 00:00:00 2001 From: Agarwal Date: Tue, 29 Oct 2024 14:10:31 +0100 Subject: [PATCH 2/7] Changes return type for createSubmodelElement --- .../backend/CrudSubmodelRepository.java | 6 ++++-- .../client/ConnectedSubmodelRepository.java | 8 ++++---- .../basyx/submodelrepository/SubmodelRepository.java | 4 ++-- .../core/SubmodelRepositorySubmodelServiceWrapper.java | 8 ++++---- .../authorization/AuthorizedSubmodelRepository.java | 8 ++++---- .../feature/mqtt/MqttSubmodelRepository.java | 6 ++++-- .../delegation/OperationDelegationSubmodelRepository.java | 8 ++++---- .../RegistryIntegrationSubmodelRepository.java | 8 ++++---- .../http/SubmodelRepositoryApiHTTPController.java | 8 ++++---- .../basyx/submodelservice/InMemorySubmodelService.java | 8 ++++---- .../basyx/submodelservice/MongoDBSubmodelService.java | 6 ++++-- .../submodelservice/client/ConnectedSubmodelService.java | 8 ++++---- .../basyx/submodelservice/SubmodelService.java | 6 ++++-- .../submodelservice/feature/mqtt/MqttSubmodelService.java | 6 ++++-- .../http/SubmodelServiceHTTPApiController.java | 8 ++++---- 15 files changed, 58 insertions(+), 48 deletions(-) diff --git a/basyx.submodelrepository/basyx.submodelrepository-backend/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/backend/CrudSubmodelRepository.java b/basyx.submodelrepository/basyx.submodelrepository-backend/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/backend/CrudSubmodelRepository.java index 5f6f91ed8..bd8c0e202 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-backend/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/backend/CrudSubmodelRepository.java +++ b/basyx.submodelrepository/basyx.submodelrepository-backend/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/backend/CrudSubmodelRepository.java @@ -197,21 +197,23 @@ public void setSubmodelElementValue(String submodelId, String smeIdShort, Submod } @Override - public void createSubmodelElement(String submodelId, SubmodelElement smElement) { + public SubmodelElement createSubmodelElement(String submodelId, SubmodelElement smElement) { SubmodelService submodelService = getSubmodelServiceOrThrow(submodelId); submodelService.createSubmodelElement(smElement); updateSubmodel(submodelId, submodelService.getSubmodel()); + return smElement; } @Override - public void createSubmodelElement(String submodelId, String idShortPath, SubmodelElement smElement) throws ElementDoesNotExistException { + 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; } @Override diff --git a/basyx.submodelrepository/basyx.submodelrepository-client/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/client/ConnectedSubmodelRepository.java b/basyx.submodelrepository/basyx.submodelrepository-client/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/client/ConnectedSubmodelRepository.java index 397767fa6..58d9a65cc 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-client/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/client/ConnectedSubmodelRepository.java +++ b/basyx.submodelrepository/basyx.submodelrepository-client/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/client/ConnectedSubmodelRepository.java @@ -196,13 +196,13 @@ public void setSubmodelElementValue(String submodelId, String smeIdShort, Submod } @Override - public void createSubmodelElement(String submodelId, SubmodelElement smElement) { - getConnectedSubmodelService(submodelId).createSubmodelElement(smElement); + public SubmodelElement createSubmodelElement(String submodelId, SubmodelElement smElement) { + return getConnectedSubmodelService(submodelId).createSubmodelElement(smElement); } @Override - public void createSubmodelElement(String submodelId, String idShortPath, SubmodelElement smElement) throws ElementDoesNotExistException { - getConnectedSubmodelService(submodelId).createSubmodelElement(idShortPath, smElement); + public SubmodelElement createSubmodelElement(String submodelId, String idShortPath, SubmodelElement smElement) throws ElementDoesNotExistException { + return getConnectedSubmodelService(submodelId).createSubmodelElement(idShortPath, smElement); } @Override diff --git a/basyx.submodelrepository/basyx.submodelrepository-core/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/SubmodelRepository.java b/basyx.submodelrepository/basyx.submodelrepository-core/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/SubmodelRepository.java index 0a5df3ec7..2314db4ea 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-core/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/SubmodelRepository.java +++ b/basyx.submodelrepository/basyx.submodelrepository-core/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/SubmodelRepository.java @@ -164,7 +164,7 @@ public interface SubmodelRepository { * @param smElement * the SubmodelElement */ - public void createSubmodelElement(String submodelId, SubmodelElement smElement); + public SubmodelElement createSubmodelElement(String submodelId, SubmodelElement smElement); /** * Creates a nested SubmodelElement @@ -176,7 +176,7 @@ public interface SubmodelRepository { * @param smElement * the SubmodelElement */ - public void createSubmodelElement(String submodelId, String idShortPath, SubmodelElement smElement) throws ElementDoesNotExistException; + public SubmodelElement createSubmodelElement(String submodelId, String idShortPath, SubmodelElement smElement) throws ElementDoesNotExistException; /** * Deletes a SubmodelElement diff --git a/basyx.submodelrepository/basyx.submodelrepository-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/core/SubmodelRepositorySubmodelServiceWrapper.java b/basyx.submodelrepository/basyx.submodelrepository-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/core/SubmodelRepositorySubmodelServiceWrapper.java index 4716e9e8c..8adc2e87d 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/core/SubmodelRepositorySubmodelServiceWrapper.java +++ b/basyx.submodelrepository/basyx.submodelrepository-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/core/SubmodelRepositorySubmodelServiceWrapper.java @@ -86,14 +86,14 @@ public void setSubmodelElementValue(String idShortPath, SubmodelElementValue val } @Override - public void createSubmodelElement(SubmodelElement submodelElement) { - repoApi.createSubmodelElement(submodelId, submodelElement); + public SubmodelElement createSubmodelElement(SubmodelElement submodelElement) { + return repoApi.createSubmodelElement(submodelId, submodelElement); } @Override - public void createSubmodelElement(String idShortPath, SubmodelElement submodelElement) + public SubmodelElement createSubmodelElement(String idShortPath, SubmodelElement submodelElement) throws ElementDoesNotExistException { - repoApi.createSubmodelElement(submodelId, idShortPath, submodelElement); + return repoApi.createSubmodelElement(submodelId, idShortPath, submodelElement); } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/AuthorizedSubmodelRepository.java b/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/AuthorizedSubmodelRepository.java index 2b94ecaac..696abe657 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/AuthorizedSubmodelRepository.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/AuthorizedSubmodelRepository.java @@ -155,21 +155,21 @@ public void setSubmodelElementValue(String submodelId, String smeIdShortPath, Su } @Override - public void createSubmodelElement(String submodelId, SubmodelElement smElement) { + public SubmodelElement createSubmodelElement(String submodelId, SubmodelElement smElement) { boolean isAuthorized = permissionResolver.hasPermission(Action.UPDATE, new SubmodelTargetInformation(getIdAsList(submodelId), getIdAsList(ALL_ALLOWED_WILDCARD))); throwExceptionIfInsufficientPermission(isAuthorized); - decorated.createSubmodelElement(submodelId, smElement); + return 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 { boolean isAuthorized = permissionResolver.hasPermission(Action.UPDATE, new SubmodelTargetInformation(getIdAsList(submodelId), getIdAsList(idShortPath))); throwExceptionIfInsufficientPermission(isAuthorized); - decorated.createSubmodelElement(submodelId, idShortPath, smElement); + return decorated.createSubmodelElement(submodelId, idShortPath, smElement); } @Override diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-mqtt/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/mqtt/MqttSubmodelRepository.java b/basyx.submodelrepository/basyx.submodelrepository-feature-mqtt/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/mqtt/MqttSubmodelRepository.java index 86d11bc29..742492c93 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-mqtt/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/mqtt/MqttSubmodelRepository.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-mqtt/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/mqtt/MqttSubmodelRepository.java @@ -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()); submodelElementCreated(submodelElement, getName(), submodelId, smElement.getIdShort()); + return submodelElement; } @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); submodelElementCreated(submodelElement, getName(), submodelId, idShortPath); + return submodelElement; } @Override diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-operation-delegation/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/operation/delegation/OperationDelegationSubmodelRepository.java b/basyx.submodelrepository/basyx.submodelrepository-feature-operation-delegation/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/operation/delegation/OperationDelegationSubmodelRepository.java index 457fa6c19..a672c4b1c 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-operation-delegation/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/operation/delegation/OperationDelegationSubmodelRepository.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-operation-delegation/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/operation/delegation/OperationDelegationSubmodelRepository.java @@ -117,13 +117,13 @@ public void setSubmodelElementValue(String submodelId, String smeIdShort, Submod } @Override - public void createSubmodelElement(String submodelId, SubmodelElement smElement) { - decorated.createSubmodelElement(submodelId, smElement); + public SubmodelElement createSubmodelElement(String submodelId, SubmodelElement smElement) { + return decorated.createSubmodelElement(submodelId, smElement); } @Override - public void createSubmodelElement(String submodelId, String idShortPath, SubmodelElement smElement) throws ElementDoesNotExistException { - decorated.createSubmodelElement(submodelId, idShortPath, smElement); + public SubmodelElement createSubmodelElement(String submodelId, String idShortPath, SubmodelElement smElement) throws ElementDoesNotExistException { + return decorated.createSubmodelElement(submodelId, idShortPath, smElement); } @Override diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepository.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepository.java index 3b9638aed..34532daf3 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepository.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/RegistryIntegrationSubmodelRepository.java @@ -134,13 +134,13 @@ public void setSubmodelElementValue(String submodelId, String idShortPath, Submo } @Override - public void createSubmodelElement(String submodelId, SubmodelElement submodelElement) { - decorated.createSubmodelElement(submodelId, submodelElement); + public SubmodelElement createSubmodelElement(String submodelId, SubmodelElement submodelElement) { + return decorated.createSubmodelElement(submodelId, submodelElement); } @Override - public void createSubmodelElement(String submodelId, String idShortPath, SubmodelElement submodelElement) throws ElementDoesNotExistException { - decorated.createSubmodelElement(submodelId, idShortPath, submodelElement); + public SubmodelElement createSubmodelElement(String submodelId, String idShortPath, SubmodelElement submodelElement) throws ElementDoesNotExistException { + return decorated.createSubmodelElement(submodelId, idShortPath, submodelElement); } @Override diff --git a/basyx.submodelrepository/basyx.submodelrepository-http/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/http/SubmodelRepositoryApiHTTPController.java b/basyx.submodelrepository/basyx.submodelrepository-http/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/http/SubmodelRepositoryApiHTTPController.java index 4f8eb4c7b..a1ca90fba 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-http/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/http/SubmodelRepositoryApiHTTPController.java +++ b/basyx.submodelrepository/basyx.submodelrepository-http/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/http/SubmodelRepositoryApiHTTPController.java @@ -175,14 +175,14 @@ public ResponseEntity getSubmodelElementByPathSubmodelRepo(Base @Override public ResponseEntity postSubmodelElementByPathSubmodelRepo(Base64UrlEncodedIdentifier submodelIdentifier, String idShortPath, @Valid SubmodelElement body, @Valid String level, @Valid String extent) { - repository.createSubmodelElement(submodelIdentifier.getIdentifier(), idShortPath, body); - return new ResponseEntity(HttpStatus.CREATED); + SubmodelElement createdSME = repository.createSubmodelElement(submodelIdentifier.getIdentifier(), idShortPath, body); + return new ResponseEntity(createdSME, HttpStatus.CREATED); } @Override public ResponseEntity postSubmodelElementSubmodelRepo(Base64UrlEncodedIdentifier submodelIdentifier, @Valid SubmodelElement body) { - repository.createSubmodelElement(submodelIdentifier.getIdentifier(), body); - return new ResponseEntity(body, HttpStatus.CREATED); + SubmodelElement createdSME = repository.createSubmodelElement(submodelIdentifier.getIdentifier(), body); + return new ResponseEntity(createdSME, HttpStatus.CREATED); } @Override diff --git a/basyx.submodelservice/basyx.submodelservice-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/InMemorySubmodelService.java b/basyx.submodelservice/basyx.submodelservice-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/InMemorySubmodelService.java index ab232f2ab..94148626f 100644 --- a/basyx.submodelservice/basyx.submodelservice-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/InMemorySubmodelService.java +++ b/basyx.submodelservice/basyx.submodelservice-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/InMemorySubmodelService.java @@ -123,12 +123,13 @@ public void setSubmodelElementValue(String idShort, SubmodelElementValue value) } @Override - public void createSubmodelElement(SubmodelElement submodelElement) throws CollidingIdentifierException { + public SubmodelElement createSubmodelElement(SubmodelElement submodelElement) throws CollidingIdentifierException { throwIfSubmodelElementExists(submodelElement.getIdShort()); List smElements = submodel.getSubmodelElements(); smElements.add(submodelElement); submodel.setSubmodelElements(smElements); + return submodelElement; } private void throwIfSubmodelElementExists(String submodelElementId) { @@ -141,7 +142,7 @@ private void throwIfSubmodelElementExists(String submodelElementId) { } @Override - public void createSubmodelElement(String idShortPath, SubmodelElement submodelElement) throws ElementDoesNotExistException, CollidingIdentifierException { + public SubmodelElement createSubmodelElement(String idShortPath, SubmodelElement submodelElement) throws ElementDoesNotExistException, CollidingIdentifierException { throwIfSubmodelElementExists(getFullIdShortPath(idShortPath, submodelElement.getIdShort())); SubmodelElement parentSme = parser.getSubmodelElementFromIdShortPath(idShortPath); @@ -150,15 +151,14 @@ public void createSubmodelElement(String idShortPath, SubmodelElement submodelEl List submodelElements = list.getValue(); submodelElements.add(submodelElement); list.setValue(submodelElements); - return; } if (parentSme instanceof SubmodelElementCollection) { SubmodelElementCollection collection = (SubmodelElementCollection) parentSme; List submodelElements = collection.getValue(); submodelElements.add(submodelElement); collection.setValue(submodelElements); - return; } + return submodelElement; } @Override diff --git a/basyx.submodelservice/basyx.submodelservice-backend-mongodb/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/MongoDBSubmodelService.java b/basyx.submodelservice/basyx.submodelservice-backend-mongodb/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/MongoDBSubmodelService.java index 182add728..3ee433acf 100644 --- a/basyx.submodelservice/basyx.submodelservice-backend-mongodb/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/MongoDBSubmodelService.java +++ b/basyx.submodelservice/basyx.submodelservice-backend-mongodb/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/MongoDBSubmodelService.java @@ -103,19 +103,21 @@ public void setSubmodelElementValue(String idShortPath, SubmodelElementValue val } @Override - public void createSubmodelElement(SubmodelElement submodelElement) { + public SubmodelElement createSubmodelElement(SubmodelElement submodelElement) { InMemorySubmodelService inMemorySubmodelService = getInMemorySubmodelService(); inMemorySubmodelService.createSubmodelElement(submodelElement); Submodel submodel = inMemorySubmodelService.getSubmodel(); crudRepository.save(submodel); + return submodelElement; } @Override - public void createSubmodelElement(String idShortPath, SubmodelElement submodelElement) throws ElementDoesNotExistException { + public SubmodelElement createSubmodelElement(String idShortPath, SubmodelElement submodelElement) throws ElementDoesNotExistException { InMemorySubmodelService inMemorySubmodelService = getInMemorySubmodelService(); inMemorySubmodelService.createSubmodelElement(idShortPath, submodelElement); Submodel submodel = inMemorySubmodelService.getSubmodel(); crudRepository.save(submodel); + return submodelElement; } diff --git a/basyx.submodelservice/basyx.submodelservice-client/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/client/ConnectedSubmodelService.java b/basyx.submodelservice/basyx.submodelservice-client/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/client/ConnectedSubmodelService.java index 78556c15c..16441611c 100644 --- a/basyx.submodelservice/basyx.submodelservice-client/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/client/ConnectedSubmodelService.java +++ b/basyx.submodelservice/basyx.submodelservice-client/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/client/ConnectedSubmodelService.java @@ -113,14 +113,14 @@ public void setSubmodelElementValue(String idShortPath, SubmodelElementValue val } @Override - public void createSubmodelElement(SubmodelElement submodelElement) { - serviceApi.postSubmodelElement(submodelElement); + public SubmodelElement createSubmodelElement(SubmodelElement submodelElement) { + return serviceApi.postSubmodelElement(submodelElement); } @Override - public void createSubmodelElement(String idShortPath, SubmodelElement submodelElement) throws ElementDoesNotExistException { + public SubmodelElement createSubmodelElement(String idShortPath, SubmodelElement submodelElement) throws ElementDoesNotExistException { try { - serviceApi.postSubmodelElementByPath(idShortPath, submodelElement); + return serviceApi.postSubmodelElementByPath(idShortPath, submodelElement); } catch (ApiException e) { throw mapExceptionSubmodelElementAccess(idShortPath, e); } diff --git a/basyx.submodelservice/basyx.submodelservice-core/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/SubmodelService.java b/basyx.submodelservice/basyx.submodelservice-core/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/SubmodelService.java index 90381c531..a9e713572 100644 --- a/basyx.submodelservice/basyx.submodelservice-core/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/SubmodelService.java +++ b/basyx.submodelservice/basyx.submodelservice-core/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/SubmodelService.java @@ -90,9 +90,10 @@ public interface SubmodelService { /** * Creates a Submodel Element + * @return * */ - public void createSubmodelElement(SubmodelElement submodelElement); + public SubmodelElement createSubmodelElement(SubmodelElement submodelElement); /** * Create a nested submodel element @@ -101,10 +102,11 @@ public interface SubmodelService { * the SubmodelElement IdShortPath * @param submodelElement * the submodel element to be created + * @return * @throws ElementDoesNotExistException * If the submodel element defined in the path does not exist */ - public void createSubmodelElement(String idShortPath, SubmodelElement submodelElement) throws ElementDoesNotExistException; + public SubmodelElement createSubmodelElement(String idShortPath, SubmodelElement submodelElement) throws ElementDoesNotExistException; /** * Updates a submodel element diff --git a/basyx.submodelservice/basyx.submodelservice-feature-mqtt/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/feature/mqtt/MqttSubmodelService.java b/basyx.submodelservice/basyx.submodelservice-feature-mqtt/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/feature/mqtt/MqttSubmodelService.java index 3d8beed4c..5bd4b48be 100644 --- a/basyx.submodelservice/basyx.submodelservice-feature-mqtt/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/feature/mqtt/MqttSubmodelService.java +++ b/basyx.submodelservice/basyx.submodelservice-feature-mqtt/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/feature/mqtt/MqttSubmodelService.java @@ -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()); submodelElementCreated(submodelElement, smElement.getIdShort()); + return smElement; } @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()); submodelElementCreated(smElement, idShortPath); + return smElement; } @Override diff --git a/basyx.submodelservice/basyx.submodelservice-http/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/http/SubmodelServiceHTTPApiController.java b/basyx.submodelservice/basyx.submodelservice-http/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/http/SubmodelServiceHTTPApiController.java index e2587d33b..ac9ee1c98 100644 --- a/basyx.submodelservice/basyx.submodelservice-http/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/http/SubmodelServiceHTTPApiController.java +++ b/basyx.submodelservice/basyx.submodelservice-http/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/http/SubmodelServiceHTTPApiController.java @@ -198,16 +198,16 @@ public ResponseEntity patchSubmodelElementByPathValueOnly( public ResponseEntity postSubmodelElement(@Parameter(in = ParameterIn.DEFAULT, description = "Requested submodel element", required = true, schema = @Schema()) @Valid @RequestBody SubmodelElement body, @Parameter(in = ParameterIn.QUERY, description = "Determines the structural depth of the respective resource content", schema = @Schema(allowableValues = { "deep", "core" }, defaultValue = "deep")) @Valid @RequestParam(value = "level", required = false, defaultValue = "deep") String level) { - service.createSubmodelElement(body); - return new ResponseEntity(body, HttpStatus.CREATED); + SubmodelElement createdSME = service.createSubmodelElement(body); + return new ResponseEntity(createdSME, HttpStatus.CREATED); } @Override public ResponseEntity postSubmodelElementByPath( @Parameter(in = ParameterIn.PATH, description = "IdShort path to the submodel element (dot-separated)", required = true, schema = @Schema()) @PathVariable("idShortPath") String idShortPath, @Parameter(in = ParameterIn.DEFAULT, description = "Requested submodel element", required = true, schema = @Schema()) @Valid @RequestBody SubmodelElement body) { - service.createSubmodelElement(idShortPath, body); - return new ResponseEntity(body, HttpStatus.CREATED); + SubmodelElement createdSME = service.createSubmodelElement(idShortPath, body); + return new ResponseEntity(createdSME, HttpStatus.CREATED); } @Override From 28160cab83baa683f841b88ec086f67bd325eb8d Mon Sep 17 00:00:00 2001 From: Agarwal Date: Tue, 29 Oct 2024 18:26:09 +0100 Subject: [PATCH 3/7] testcases for response of createSubmodelElement in submodelrepository --- .../feature/mqtt/TestMqttSubmodelObserver.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-mqtt/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/mqtt/TestMqttSubmodelObserver.java b/basyx.submodelrepository/basyx.submodelrepository-feature-mqtt/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/mqtt/TestMqttSubmodelObserver.java index 1198e9ab1..20a79b2af 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-mqtt/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/mqtt/TestMqttSubmodelObserver.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-mqtt/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/mqtt/TestMqttSubmodelObserver.java @@ -127,8 +127,9 @@ public void createSubmodelElementEvent() throws DeserializationException { Submodel submodel = createSubmodelDummy("createSubmodelForElementEventId"); submodelRepository.createSubmodel(submodel); SubmodelElement submodelElement = createSubmodelElementDummy("createSubmodelElementEventId"); - submodelRepository.createSubmodelElement(submodel.getId(), submodelElement); + SubmodelElement responseSubmodelElement = submodelRepository.createSubmodelElement(submodel.getId(), submodelElement); + assertEquals(responseSubmodelElement, submodelElement); assertEquals(topicFactory.createCreateSubmodelElementTopic(submodelRepository.getName(), submodel.getId(), submodelElement.getIdShort()), listener.lastTopic); assertEquals(submodelElement, deserializeSubmodelElementPayload(listener.lastPayload)); } @@ -138,10 +139,11 @@ public void updateSubmodelElementEvent() throws DeserializationException { Submodel submodel = createSubmodelDummy("updateSubmodelForElementEventId"); submodelRepository.createSubmodel(submodel); SubmodelElement submodelElement = createSubmodelElementDummy("updateSubmodelElementEventId"); - submodelRepository.createSubmodelElement(submodel.getId(), submodelElement); + SubmodelElement responseSubmodelElement = submodelRepository.createSubmodelElement(submodel.getId(), submodelElement); SubmodelElementValue value = new PropertyValue("updatedValue"); submodelRepository.setSubmodelElementValue(submodel.getId(), submodelElement.getIdShort(), value); + assertEquals(responseSubmodelElement, submodelElement); assertEquals(topicFactory.createUpdateSubmodelElementTopic(submodelRepository.getName(), submodel.getId(), submodelElement.getIdShort()), listener.lastTopic); assertEquals(submodelElement, deserializeSubmodelElementPayload(listener.lastPayload)); } @@ -151,9 +153,10 @@ public void deleteSubmodelElementEvent() throws DeserializationException { Submodel submodel = createSubmodelDummy("deleteSubmodelForElementEventId"); submodelRepository.createSubmodel(submodel); SubmodelElement submodelElement = createSubmodelElementDummy("deleteSubmodelElementEventId"); - submodelRepository.createSubmodelElement(submodel.getId(), submodelElement); + SubmodelElement responseSubmodelElement = submodelRepository.createSubmodelElement(submodel.getId(), submodelElement); submodelRepository.deleteSubmodelElement(submodel.getId(), submodelElement.getIdShort()); + assertEquals(responseSubmodelElement, submodelElement); assertEquals(topicFactory.createDeleteSubmodelElementTopic(submodelRepository.getName(), submodel.getId(), submodelElement.getIdShort()), listener.lastTopic); assertEquals(submodelElement, deserializeSubmodelElementPayload(listener.lastPayload)); } @@ -165,8 +168,9 @@ public void createSubmodelElementWithoutValueEvent() throws DeserializationExcep SubmodelElement submodelElement = createSubmodelElementDummy("noValueSubmodelElementEventId"); List qualifierList = createNoValueQualifierList(); submodelElement.setQualifiers(qualifierList); - submodelRepository.createSubmodelElement(submodel.getId(), submodelElement); + SubmodelElement responseSubmodelElement = submodelRepository.createSubmodelElement(submodel.getId(), submodelElement); + assertEquals(responseSubmodelElement, submodelElement); assertEquals(topicFactory.createCreateSubmodelElementTopic(submodelRepository.getName(), submodel.getId(), submodelElement.getIdShort()), listener.lastTopic); assertNotEquals(submodelElement, deserializeSubmodelElementPayload(listener.lastPayload)); From 33cf443ca60d35aeedcce55ad0091bfdb7adda31 Mon Sep 17 00:00:00 2001 From: Agarwal Date: Tue, 29 Oct 2024 19:13:29 +0100 Subject: [PATCH 4/7] testcases for response of createSubmodelElement in submodelservice --- .../basyx/submodelservice/SubmodelServiceSuite.java | 13 +++++++++---- .../feature/mqtt/TestMqttSubmodelObserver.java | 12 ++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/basyx.submodelservice/basyx.submodelservice-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelservice/SubmodelServiceSuite.java b/basyx.submodelservice/basyx.submodelservice-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelservice/SubmodelServiceSuite.java index 94820e893..df0da52b5 100644 --- a/basyx.submodelservice/basyx.submodelservice-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelservice/SubmodelServiceSuite.java +++ b/basyx.submodelservice/basyx.submodelservice-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelservice/SubmodelServiceSuite.java @@ -305,9 +305,11 @@ public void createSubmodelElement() { property.setValue("205"); SubmodelService submodelService = getSubmodelService(technicalData); - submodelService.createSubmodelElement(property); + SubmodelElement responseSubmodelElement = submodelService.createSubmodelElement(property); SubmodelElement submodelEl = submodelService.getSubmodelElement("test123"); + + assertEquals(submodelEl, responseSubmodelElement); assertEquals("test123", submodelEl.getIdShort()); } @@ -334,18 +336,20 @@ public void createNestedSubmodelElement() { Property propertyInSmeList = new DefaultProperty.Builder().idShort("test456").category("cat1").value("305").valueType(DataTypeDefXsd.INTEGER).build(); String idShortPathPropertyInSmeCol = DummySubmodelFactory.SUBMODEL_OPERATIONAL_DATA_ELEMENT_COLLECTION_ID_SHORT; - submodelService.createSubmodelElement(idShortPathPropertyInSmeCol, propertyInSmeCol); + SubmodelElement responseSubmodelElementCol = submodelService.createSubmodelElement(idShortPathPropertyInSmeCol, propertyInSmeCol); String idShortPathPropertyInSmeList = DummySubmodelFactory.SUBMODEL_OPERATIONAL_DATA_ELEMENT_COLLECTION_ID_SHORT + "." + DummySubmodelFactory.SUBMODEL_OPERATIONAL_DATA_ELEMENT_LIST_ID_SHORT; - submodelService.createSubmodelElement(idShortPathPropertyInSmeList, propertyInSmeList); + SubmodelElement responseSubmodelElementList = submodelService.createSubmodelElement(idShortPathPropertyInSmeList, propertyInSmeList); idShortPathPropertyInSmeCol = idShortPathPropertyInSmeCol.concat(".test123"); SubmodelElement propertyInCollectionCreated = submodelService.getSubmodelElement(idShortPathPropertyInSmeCol); assertEquals("test123", propertyInCollectionCreated.getIdShort()); + assertEquals(propertyInCollectionCreated, responseSubmodelElementCol); idShortPathPropertyInSmeList = idShortPathPropertyInSmeList.concat("[1]"); SubmodelElement propertyInSmeListCreated = submodelService.getSubmodelElement(idShortPathPropertyInSmeList); assertEquals("test456", propertyInSmeListCreated.getIdShort()); + assertEquals(propertyInSmeListCreated, responseSubmodelElementList); } @Test @@ -372,13 +376,14 @@ public void updateNonNestedSME() { String idShortPath = "dummyProperty"; Property property = createDummyProperty(idShortPath); - submodelService.createSubmodelElement(property); + SubmodelElement responseSubmodelElement = submodelService.createSubmodelElement(property); Property expectedUpdatedProperty = SubmodelServiceHelper.createDummyProperty(idShortPath, "arbitraryValue", DataTypeDefXsd.STRING); submodelService.updateSubmodelElement(idShortPath, expectedUpdatedProperty); Property actualUpdatedProperty = (Property) submodelService.getSubmodelElement(idShortPath); assertEquals(expectedUpdatedProperty, actualUpdatedProperty); + assertEquals(submodelService.getSubmodelElement(idShortPath), responseSubmodelElement); } @Test diff --git a/basyx.submodelservice/basyx.submodelservice-feature-mqtt/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/mqtt/TestMqttSubmodelObserver.java b/basyx.submodelservice/basyx.submodelservice-feature-mqtt/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/mqtt/TestMqttSubmodelObserver.java index 75eab2b75..1e6293dca 100644 --- a/basyx.submodelservice/basyx.submodelservice-feature-mqtt/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/mqtt/TestMqttSubmodelObserver.java +++ b/basyx.submodelservice/basyx.submodelservice-feature-mqtt/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/mqtt/TestMqttSubmodelObserver.java @@ -97,34 +97,37 @@ public static void tearDownClass() { public void createSubmodelElementEvent() throws DeserializationException { SubmodelElement submodelElement = createSubmodelElementDummy("createSubmodelElementEventId"); - submodelService.createSubmodelElement(submodelElement); + SubmodelElement responseSubmodelElement = submodelService.createSubmodelElement(submodelElement); assertEquals(topicFactory.createCreateSubmodelElementTopic(submodelElement.getIdShort()), listener.lastTopic); assertEquals(submodelElement, deserializeSubmodelElementPayload(listener.lastPayload)); + assertEquals(submodelElement, responseSubmodelElement); } @Test public void updateSubmodelElementEvent() throws DeserializationException { SubmodelElement submodelElement = createSubmodelElementDummy("updateSubmodelElementEventId"); - submodelService.createSubmodelElement(submodelElement); + SubmodelElement responseSubmodelElement = submodelService.createSubmodelElement(submodelElement); SubmodelElementValue value = new PropertyValue("updatedValue"); submodelService.setSubmodelElementValue(submodelElement.getIdShort(), value); assertEquals(topicFactory.createUpdateSubmodelElementTopic(submodelElement.getIdShort()), listener.lastTopic); assertEquals(submodelElement, deserializeSubmodelElementPayload(listener.lastPayload)); + assertEquals(submodelElement, responseSubmodelElement); } @Test public void deleteSubmodelElementEvent() throws DeserializationException { SubmodelElement submodelElement = createSubmodelElementDummy("deleteSubmodelElementEventId"); - submodelService.createSubmodelElement(submodelElement); + SubmodelElement responseSubmodelElement = submodelService.createSubmodelElement(submodelElement); submodelService.deleteSubmodelElement(submodelElement.getIdShort()); assertEquals(topicFactory.createDeleteSubmodelElementTopic(submodelElement.getIdShort()), listener.lastTopic); assertEquals(submodelElement, deserializeSubmodelElementPayload(listener.lastPayload)); + assertEquals(submodelElement, responseSubmodelElement); } @Test @@ -133,13 +136,14 @@ public void createSubmodelElementWithoutValueEvent() throws DeserializationExcep SubmodelElement submodelElement = createSubmodelElementDummy("noValueSubmodelElementEventId"); List qualifierList = createNoValueQualifierList(); submodelElement.setQualifiers(qualifierList); - submodelService.createSubmodelElement(submodelElement); + SubmodelElement responseSubmodelElement = submodelService.createSubmodelElement(submodelElement); assertEquals(topicFactory.createCreateSubmodelElementTopic(submodelElement.getIdShort()), listener.lastTopic); assertNotEquals(submodelElement, deserializeSubmodelElementPayload(listener.lastPayload)); ((Property) submodelElement).setValue(null); assertEquals(submodelElement, deserializeSubmodelElementPayload(listener.lastPayload)); + assertEquals(submodelElement, responseSubmodelElement); } private List createNoValueQualifierList() { From b160d852202197ed730d092c30ef6cc7d06e0144 Mon Sep 17 00:00:00 2001 From: Agarwal Date: Tue, 29 Oct 2024 22:16:39 +0100 Subject: [PATCH 5/7] some fixes and testcase updates --- .../basyx/submodelservice/SubmodelService.java | 4 ++-- .../submodelservice/SubmodelServiceHelper.java | 8 ++++++++ .../submodelservice/SubmodelServiceSuite.java | 17 ++++++++--------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/basyx.submodelservice/basyx.submodelservice-core/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/SubmodelService.java b/basyx.submodelservice/basyx.submodelservice-core/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/SubmodelService.java index a9e713572..bb372047c 100644 --- a/basyx.submodelservice/basyx.submodelservice-core/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/SubmodelService.java +++ b/basyx.submodelservice/basyx.submodelservice-core/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/SubmodelService.java @@ -90,7 +90,6 @@ public interface SubmodelService { /** * Creates a Submodel Element - * @return * */ public SubmodelElement createSubmodelElement(SubmodelElement submodelElement); @@ -102,7 +101,7 @@ public interface SubmodelService { * the SubmodelElement IdShortPath * @param submodelElement * the submodel element to be created - * @return + * @return the SubmodelElement * @throws ElementDoesNotExistException * If the submodel element defined in the path does not exist */ @@ -113,6 +112,7 @@ public interface SubmodelService { * * @param idShortPath * @param submodelElement + * @return the SubmodelElement * @throws ElementDoesNotExistException * If the submodel element defined in the path does not exist */ diff --git a/basyx.submodelservice/basyx.submodelservice-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelservice/SubmodelServiceHelper.java b/basyx.submodelservice/basyx.submodelservice-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelservice/SubmodelServiceHelper.java index 8c6ef3f31..542f85816 100644 --- a/basyx.submodelservice/basyx.submodelservice-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelservice/SubmodelServiceHelper.java +++ b/basyx.submodelservice/basyx.submodelservice-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelservice/SubmodelServiceHelper.java @@ -358,6 +358,14 @@ public static Property createDummyProperty(String idShort, String value, DataTyp .build(); } + public static SubmodelElement createDummySME(String idShort, String value, DataTypeDefXsd dataType) { + return new DefaultProperty.Builder().idShort(idShort) + .category("cat1") + .value(value) + .valueType(dataType) + .build(); + } + public static File createDummyFile(String idShort, String contentType, String value) { return new DefaultFile.Builder().idShort(idShort) .category("file") diff --git a/basyx.submodelservice/basyx.submodelservice-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelservice/SubmodelServiceSuite.java b/basyx.submodelservice/basyx.submodelservice-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelservice/SubmodelServiceSuite.java index df0da52b5..8a2d9c878 100644 --- a/basyx.submodelservice/basyx.submodelservice-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelservice/SubmodelServiceSuite.java +++ b/basyx.submodelservice/basyx.submodelservice-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelservice/SubmodelServiceSuite.java @@ -305,11 +305,9 @@ public void createSubmodelElement() { property.setValue("205"); SubmodelService submodelService = getSubmodelService(technicalData); - SubmodelElement responseSubmodelElement = submodelService.createSubmodelElement(property); + submodelService.createSubmodelElement(property); SubmodelElement submodelEl = submodelService.getSubmodelElement("test123"); - - assertEquals(submodelEl, responseSubmodelElement); assertEquals("test123", submodelEl.getIdShort()); } @@ -336,20 +334,18 @@ public void createNestedSubmodelElement() { Property propertyInSmeList = new DefaultProperty.Builder().idShort("test456").category("cat1").value("305").valueType(DataTypeDefXsd.INTEGER).build(); String idShortPathPropertyInSmeCol = DummySubmodelFactory.SUBMODEL_OPERATIONAL_DATA_ELEMENT_COLLECTION_ID_SHORT; - SubmodelElement responseSubmodelElementCol = submodelService.createSubmodelElement(idShortPathPropertyInSmeCol, propertyInSmeCol); + submodelService.createSubmodelElement(idShortPathPropertyInSmeCol, propertyInSmeCol); String idShortPathPropertyInSmeList = DummySubmodelFactory.SUBMODEL_OPERATIONAL_DATA_ELEMENT_COLLECTION_ID_SHORT + "." + DummySubmodelFactory.SUBMODEL_OPERATIONAL_DATA_ELEMENT_LIST_ID_SHORT; - SubmodelElement responseSubmodelElementList = submodelService.createSubmodelElement(idShortPathPropertyInSmeList, propertyInSmeList); + submodelService.createSubmodelElement(idShortPathPropertyInSmeList, propertyInSmeList); idShortPathPropertyInSmeCol = idShortPathPropertyInSmeCol.concat(".test123"); SubmodelElement propertyInCollectionCreated = submodelService.getSubmodelElement(idShortPathPropertyInSmeCol); assertEquals("test123", propertyInCollectionCreated.getIdShort()); - assertEquals(propertyInCollectionCreated, responseSubmodelElementCol); idShortPathPropertyInSmeList = idShortPathPropertyInSmeList.concat("[1]"); SubmodelElement propertyInSmeListCreated = submodelService.getSubmodelElement(idShortPathPropertyInSmeList); assertEquals("test456", propertyInSmeListCreated.getIdShort()); - assertEquals(propertyInSmeListCreated, responseSubmodelElementList); } @Test @@ -376,14 +372,13 @@ public void updateNonNestedSME() { String idShortPath = "dummyProperty"; Property property = createDummyProperty(idShortPath); - SubmodelElement responseSubmodelElement = submodelService.createSubmodelElement(property); + submodelService.createSubmodelElement(property); Property expectedUpdatedProperty = SubmodelServiceHelper.createDummyProperty(idShortPath, "arbitraryValue", DataTypeDefXsd.STRING); submodelService.updateSubmodelElement(idShortPath, expectedUpdatedProperty); Property actualUpdatedProperty = (Property) submodelService.getSubmodelElement(idShortPath); assertEquals(expectedUpdatedProperty, actualUpdatedProperty); - assertEquals(submodelService.getSubmodelElement(idShortPath), responseSubmodelElement); } @Test @@ -723,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) { + return new DefaultProperty.Builder().idShort(idShort).value("123").build(); + } private InputStream getInputStreamOfDummyFile(String fileContent) throws FileNotFoundException, IOException { return new ByteArrayInputStream(fileContent.getBytes()); From 3ba2774c5ad96a218b4282442fa645ef9823a131 Mon Sep 17 00:00:00 2001 From: Vivek Agarwal Date: Sun, 17 Nov 2024 08:54:12 +0100 Subject: [PATCH 6/7] resolved review remarks --- .../backend/CrudSubmodelRepository.java | 8 ++++---- .../feature/mqtt/MqttSubmodelRepository.java | 4 ++-- .../feature/mqtt/TestMqttSubmodelObserver.java | 12 ++++++++---- .../submodelservice/MongoDBSubmodelService.java | 8 ++++---- .../feature/mqtt/MqttSubmodelService.java | 15 ++++++--------- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/basyx.submodelrepository/basyx.submodelrepository-backend/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/backend/CrudSubmodelRepository.java b/basyx.submodelrepository/basyx.submodelrepository-backend/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/backend/CrudSubmodelRepository.java index bd8c0e202..9cba64c59 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-backend/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/backend/CrudSubmodelRepository.java +++ b/basyx.submodelrepository/basyx.submodelrepository-backend/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/backend/CrudSubmodelRepository.java @@ -200,20 +200,20 @@ public void setSubmodelElementValue(String submodelId, String smeIdShort, Submod public SubmodelElement createSubmodelElement(String submodelId, SubmodelElement smElement) { SubmodelService submodelService = getSubmodelServiceOrThrow(submodelId); - submodelService.createSubmodelElement(smElement); + SubmodelElement createdSME = submodelService.createSubmodelElement(smElement); updateSubmodel(submodelId, submodelService.getSubmodel()); - return smElement; + return createdSME; } @Override public SubmodelElement createSubmodelElement(String submodelId, String idShortPath, SubmodelElement smElement) throws ElementDoesNotExistException { SubmodelService submodelService = getSubmodelServiceOrThrow(submodelId); - submodelService.createSubmodelElement(idShortPath, smElement); + SubmodelElement createdSME = submodelService.createSubmodelElement(idShortPath, smElement); updateSubmodel(submodelId, submodelService.getSubmodel()); - return smElement; + return createdSME; } @Override diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-mqtt/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/mqtt/MqttSubmodelRepository.java b/basyx.submodelrepository/basyx.submodelrepository-feature-mqtt/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/mqtt/MqttSubmodelRepository.java index 742492c93..9891285ad 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-mqtt/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/mqtt/MqttSubmodelRepository.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-mqtt/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/mqtt/MqttSubmodelRepository.java @@ -101,7 +101,7 @@ public void setSubmodelElementValue(String submodelId, String idShortPath, Submo @Override public SubmodelElement createSubmodelElement(String submodelId, SubmodelElement smElement) { decorated.createSubmodelElement(submodelId, smElement); - SubmodelElement submodelElement = decorated.getSubmodelElement(submodelId, smElement.getIdShort()); + SubmodelElement submodelElement = decorated.createSubmodelElement(submodelId, smElement); submodelElementCreated(submodelElement, getName(), submodelId, smElement.getIdShort()); return submodelElement; } @@ -109,7 +109,7 @@ public SubmodelElement createSubmodelElement(String submodelId, SubmodelElement @Override public SubmodelElement createSubmodelElement(String submodelId, String idShortPath, SubmodelElement smElement) throws ElementDoesNotExistException { decorated.createSubmodelElement(submodelId, idShortPath, smElement); - SubmodelElement submodelElement = decorated.getSubmodelElement(submodelId, idShortPath); + SubmodelElement submodelElement = decorated.createSubmodelElement(submodelId, smElement); submodelElementCreated(submodelElement, getName(), submodelId, idShortPath); return submodelElement; } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-mqtt/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/mqtt/TestMqttSubmodelObserver.java b/basyx.submodelrepository/basyx.submodelrepository-feature-mqtt/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/mqtt/TestMqttSubmodelObserver.java index 20a79b2af..8d14f3518 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-mqtt/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/mqtt/TestMqttSubmodelObserver.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-mqtt/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/mqtt/TestMqttSubmodelObserver.java @@ -129,7 +129,7 @@ public void createSubmodelElementEvent() throws DeserializationException { SubmodelElement submodelElement = createSubmodelElementDummy("createSubmodelElementEventId"); SubmodelElement responseSubmodelElement = submodelRepository.createSubmodelElement(submodel.getId(), submodelElement); - assertEquals(responseSubmodelElement, submodelElement); + assertEquals(submodelElement, responseSubmodelElement); assertEquals(topicFactory.createCreateSubmodelElementTopic(submodelRepository.getName(), submodel.getId(), submodelElement.getIdShort()), listener.lastTopic); assertEquals(submodelElement, deserializeSubmodelElementPayload(listener.lastPayload)); } @@ -140,10 +140,12 @@ public void updateSubmodelElementEvent() throws DeserializationException { submodelRepository.createSubmodel(submodel); SubmodelElement submodelElement = createSubmodelElementDummy("updateSubmodelElementEventId"); SubmodelElement responseSubmodelElement = submodelRepository.createSubmodelElement(submodel.getId(), submodelElement); + + assertEquals(submodelElement, responseSubmodelElement); + SubmodelElementValue value = new PropertyValue("updatedValue"); submodelRepository.setSubmodelElementValue(submodel.getId(), submodelElement.getIdShort(), value); - assertEquals(responseSubmodelElement, submodelElement); assertEquals(topicFactory.createUpdateSubmodelElementTopic(submodelRepository.getName(), submodel.getId(), submodelElement.getIdShort()), listener.lastTopic); assertEquals(submodelElement, deserializeSubmodelElementPayload(listener.lastPayload)); } @@ -154,9 +156,11 @@ public void deleteSubmodelElementEvent() throws DeserializationException { submodelRepository.createSubmodel(submodel); SubmodelElement submodelElement = createSubmodelElementDummy("deleteSubmodelElementEventId"); SubmodelElement responseSubmodelElement = submodelRepository.createSubmodelElement(submodel.getId(), submodelElement); + + assertEquals(submodelElement, responseSubmodelElement); + submodelRepository.deleteSubmodelElement(submodel.getId(), submodelElement.getIdShort()); - assertEquals(responseSubmodelElement, submodelElement); assertEquals(topicFactory.createDeleteSubmodelElementTopic(submodelRepository.getName(), submodel.getId(), submodelElement.getIdShort()), listener.lastTopic); assertEquals(submodelElement, deserializeSubmodelElementPayload(listener.lastPayload)); } @@ -170,7 +174,7 @@ public void createSubmodelElementWithoutValueEvent() throws DeserializationExcep submodelElement.setQualifiers(qualifierList); SubmodelElement responseSubmodelElement = submodelRepository.createSubmodelElement(submodel.getId(), submodelElement); - assertEquals(responseSubmodelElement, submodelElement); + assertEquals(submodelElement, responseSubmodelElement); assertEquals(topicFactory.createCreateSubmodelElementTopic(submodelRepository.getName(), submodel.getId(), submodelElement.getIdShort()), listener.lastTopic); assertNotEquals(submodelElement, deserializeSubmodelElementPayload(listener.lastPayload)); diff --git a/basyx.submodelservice/basyx.submodelservice-backend-mongodb/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/MongoDBSubmodelService.java b/basyx.submodelservice/basyx.submodelservice-backend-mongodb/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/MongoDBSubmodelService.java index 3ee433acf..6dce92cf5 100644 --- a/basyx.submodelservice/basyx.submodelservice-backend-mongodb/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/MongoDBSubmodelService.java +++ b/basyx.submodelservice/basyx.submodelservice-backend-mongodb/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/MongoDBSubmodelService.java @@ -105,19 +105,19 @@ public void setSubmodelElementValue(String idShortPath, SubmodelElementValue val @Override public SubmodelElement createSubmodelElement(SubmodelElement submodelElement) { InMemorySubmodelService inMemorySubmodelService = getInMemorySubmodelService(); - inMemorySubmodelService.createSubmodelElement(submodelElement); + SubmodelElement createdSME = inMemorySubmodelService.createSubmodelElement(submodelElement); Submodel submodel = inMemorySubmodelService.getSubmodel(); crudRepository.save(submodel); - return submodelElement; + return createdSME; } @Override public SubmodelElement createSubmodelElement(String idShortPath, SubmodelElement submodelElement) throws ElementDoesNotExistException { InMemorySubmodelService inMemorySubmodelService = getInMemorySubmodelService(); - inMemorySubmodelService.createSubmodelElement(idShortPath, submodelElement); + SubmodelElement createdSME = inMemorySubmodelService.createSubmodelElement(idShortPath, submodelElement); Submodel submodel = inMemorySubmodelService.getSubmodel(); crudRepository.save(submodel); - return submodelElement; + return createdSME; } diff --git a/basyx.submodelservice/basyx.submodelservice-feature-mqtt/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/feature/mqtt/MqttSubmodelService.java b/basyx.submodelservice/basyx.submodelservice-feature-mqtt/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/feature/mqtt/MqttSubmodelService.java index 5bd4b48be..c9a7cab84 100644 --- a/basyx.submodelservice/basyx.submodelservice-feature-mqtt/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/feature/mqtt/MqttSubmodelService.java +++ b/basyx.submodelservice/basyx.submodelservice-feature-mqtt/src/main/java/org/eclipse/digitaltwin/basyx/submodelservice/feature/mqtt/MqttSubmodelService.java @@ -94,20 +94,17 @@ public void setSubmodelElementValue(String idShortPath, SubmodelElementValue val @Override public SubmodelElement createSubmodelElement(SubmodelElement submodelElement) { - decorated.createSubmodelElement(submodelElement); - SubmodelElement smElement = decorated.getSubmodelElement(submodelElement.getIdShort()); - submodelElementCreated(submodelElement, smElement.getIdShort()); - return smElement; + SubmodelElement createdSME = decorated.createSubmodelElement(submodelElement); + submodelElementCreated(submodelElement, createdSME.getIdShort()); + return createdSME; } @Override public SubmodelElement createSubmodelElement(String idShortPath, SubmodelElement submodelElement) throws ElementDoesNotExistException { - decorated.createSubmodelElement(idShortPath, submodelElement); - - SubmodelElement smElement = decorated.getSubmodelElement(submodelElement.getIdShort()); - submodelElementCreated(smElement, idShortPath); - return smElement; + SubmodelElement createdSME = decorated.createSubmodelElement(idShortPath, submodelElement); + submodelElementCreated(createdSME, idShortPath); + return createdSME; } @Override From b08c21b2a751fdba8b533f7559e7ad1d771f3207 Mon Sep 17 00:00:00 2001 From: Vivek Agarwal Date: Sun, 17 Nov 2024 09:20:23 +0100 Subject: [PATCH 7/7] fix issues --- .../submodelrepository/feature/mqtt/MqttSubmodelRepository.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-mqtt/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/mqtt/MqttSubmodelRepository.java b/basyx.submodelrepository/basyx.submodelrepository-feature-mqtt/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/mqtt/MqttSubmodelRepository.java index 9891285ad..40e5e7dce 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-mqtt/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/mqtt/MqttSubmodelRepository.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-mqtt/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/mqtt/MqttSubmodelRepository.java @@ -100,7 +100,6 @@ public void setSubmodelElementValue(String submodelId, String idShortPath, Submo @Override public SubmodelElement createSubmodelElement(String submodelId, SubmodelElement smElement) { - decorated.createSubmodelElement(submodelId, smElement); SubmodelElement submodelElement = decorated.createSubmodelElement(submodelId, smElement); submodelElementCreated(submodelElement, getName(), submodelId, smElement.getIdShort()); return submodelElement; @@ -108,7 +107,6 @@ public SubmodelElement createSubmodelElement(String submodelId, SubmodelElement @Override public SubmodelElement createSubmodelElement(String submodelId, String idShortPath, SubmodelElement smElement) throws ElementDoesNotExistException { - decorated.createSubmodelElement(submodelId, idShortPath, smElement); SubmodelElement submodelElement = decorated.createSubmodelElement(submodelId, smElement); submodelElementCreated(submodelElement, getName(), submodelId, idShortPath); return submodelElement;