From 52e3ab5562854c6ffd459d158922f0b8174d75ff Mon Sep 17 00:00:00 2001 From: Agarwal Date: Tue, 29 Oct 2024 14:10:31 +0100 Subject: [PATCH] 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