Skip to content

Commit

Permalink
Changes return type for createSubmodelElement
Browse files Browse the repository at this point in the history
  • Loading branch information
VivekHub97 committed Oct 29, 2024
1 parent 7a0b4d2 commit 52e3ab5
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ public ResponseEntity<SubmodelElement> getSubmodelElementByPathSubmodelRepo(Base

@Override
public ResponseEntity<SubmodelElement> postSubmodelElementByPathSubmodelRepo(Base64UrlEncodedIdentifier submodelIdentifier, String idShortPath, @Valid SubmodelElement body, @Valid String level, @Valid String extent) {
repository.createSubmodelElement(submodelIdentifier.getIdentifier(), idShortPath, body);
return new ResponseEntity<SubmodelElement>(HttpStatus.CREATED);
SubmodelElement createdSME = repository.createSubmodelElement(submodelIdentifier.getIdentifier(), idShortPath, body);
return new ResponseEntity<SubmodelElement>(createdSME, HttpStatus.CREATED);
}

@Override
public ResponseEntity<SubmodelElement> postSubmodelElementSubmodelRepo(Base64UrlEncodedIdentifier submodelIdentifier, @Valid SubmodelElement body) {
repository.createSubmodelElement(submodelIdentifier.getIdentifier(), body);
return new ResponseEntity<SubmodelElement>(body, HttpStatus.CREATED);
SubmodelElement createdSME = repository.createSubmodelElement(submodelIdentifier.getIdentifier(), body);
return new ResponseEntity<SubmodelElement>(createdSME, HttpStatus.CREATED);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SubmodelElement> smElements = submodel.getSubmodelElements();
smElements.add(submodelElement);
submodel.setSubmodelElements(smElements);
return submodelElement;
}

private void throwIfSubmodelElementExists(String submodelElementId) {
Expand All @@ -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);
Expand All @@ -150,15 +151,14 @@ public void createSubmodelElement(String idShortPath, SubmodelElement submodelEl
List<SubmodelElement> submodelElements = list.getValue();
submodelElements.add(submodelElement);
list.setValue(submodelElements);
return;
}
if (parentSme instanceof SubmodelElementCollection) {
SubmodelElementCollection collection = (SubmodelElementCollection) parentSme;
List<SubmodelElement> submodelElements = collection.getValue();
submodelElements.add(submodelElement);
collection.setValue(submodelElements);
return;
}
return submodelElement;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,16 @@ public ResponseEntity<Void> patchSubmodelElementByPathValueOnly(
public ResponseEntity<SubmodelElement> 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<SubmodelElement>(body, HttpStatus.CREATED);
SubmodelElement createdSME = service.createSubmodelElement(body);
return new ResponseEntity<SubmodelElement>(createdSME, HttpStatus.CREATED);
}

@Override
public ResponseEntity<SubmodelElement> 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<SubmodelElement>(body, HttpStatus.CREATED);
SubmodelElement createdSME = service.createSubmodelElement(idShortPath, body);
return new ResponseEntity<SubmodelElement>(createdSME, HttpStatus.CREATED);
}

@Override
Expand Down

0 comments on commit 52e3ab5

Please sign in to comment.