|
29 | 29 | import java.io.InputStream; |
30 | 30 | import java.util.List; |
31 | 31 |
|
| 32 | +import com.fasterxml.jackson.databind.ObjectMapper; |
32 | 33 | import org.eclipse.digitaltwin.aas4j.v3.model.OperationRequest; |
33 | 34 | import org.eclipse.digitaltwin.aas4j.v3.model.OperationResult; |
34 | 35 | import org.eclipse.digitaltwin.aas4j.v3.model.Submodel; |
|
38 | 39 | import org.eclipse.digitaltwin.basyx.core.exceptions.FileDoesNotExistException; |
39 | 40 | import org.eclipse.digitaltwin.basyx.core.pagination.CursorResult; |
40 | 41 | import org.eclipse.digitaltwin.basyx.core.pagination.PaginationInfo; |
| 42 | +import org.eclipse.digitaltwin.basyx.http.CustomTypeCloneFactory; |
41 | 43 | import org.eclipse.digitaltwin.basyx.http.pagination.Base64UrlEncodedCursor; |
42 | 44 | import org.eclipse.digitaltwin.basyx.http.pagination.PagedResult; |
43 | 45 | import org.eclipse.digitaltwin.basyx.http.pagination.PagedResultPagingMetadata; |
|
69 | 71 | @RestController |
70 | 72 | public class SubmodelServiceHTTPApiController implements SubmodelServiceHTTPApi { |
71 | 73 |
|
72 | | - private SubmodelService service; |
| 74 | + private final SubmodelService service; |
| 75 | + private final ObjectMapper objectMapper; |
73 | 76 |
|
74 | 77 | @Autowired |
75 | | - public SubmodelServiceHTTPApiController(SubmodelService service) { |
| 78 | + public SubmodelServiceHTTPApiController(SubmodelService service, ObjectMapper objectMapper) { |
76 | 79 | this.service = service; |
77 | | - } |
| 80 | + this.objectMapper = objectMapper; |
| 81 | + } |
78 | 82 |
|
79 | 83 | @Override |
80 | 84 | public ResponseEntity<Void> deleteSubmodelElementByPath( |
@@ -196,16 +200,21 @@ public ResponseEntity<Void> patchSubmodelElementByPathValueOnly( |
196 | 200 | public ResponseEntity<SubmodelElement> postSubmodelElement(@Parameter(in = ParameterIn.DEFAULT, description = "Requested submodel element", required = true, schema = @Schema()) @Valid @RequestBody SubmodelElement body, |
197 | 201 | @Parameter(in = ParameterIn.QUERY, description = "Determines the structural depth of the respective resource content", schema = @Schema(allowableValues = { "deep", |
198 | 202 | "core" }, defaultValue = "deep")) @Valid @RequestParam(value = "level", required = false, defaultValue = "deep") String level) { |
199 | | - service.createSubmodelElement(body); |
200 | | - return new ResponseEntity<>(service.getSubmodelElement(body.getIdShort()), HttpStatus.CREATED); |
| 203 | + |
| 204 | + SubmodelElement validatedBody = new CustomTypeCloneFactory<>(SubmodelElement.class, objectMapper).create(body); |
| 205 | + service.createSubmodelElement(validatedBody); |
| 206 | + |
| 207 | + return new ResponseEntity<>(validatedBody, HttpStatus.CREATED); |
201 | 208 | } |
202 | 209 |
|
203 | 210 | @Override |
204 | 211 | public ResponseEntity<SubmodelElement> postSubmodelElementByPath( |
205 | 212 | @Parameter(in = ParameterIn.PATH, description = "IdShort path to the submodel element (dot-separated)", required = true, schema = @Schema()) @PathVariable("idShortPath") String idShortPath, |
206 | 213 | @Parameter(in = ParameterIn.DEFAULT, description = "Requested submodel element", required = true, schema = @Schema()) @Valid @RequestBody SubmodelElement body) { |
207 | | - service.createSubmodelElement(idShortPath, body); |
208 | | - return new ResponseEntity<>(service.getSubmodelElement(idShortPath), HttpStatus.CREATED); |
| 214 | + SubmodelElement validatedBody = new CustomTypeCloneFactory<>(SubmodelElement.class, objectMapper).create(body); |
| 215 | + service.createSubmodelElement(idShortPath, validatedBody); |
| 216 | + |
| 217 | + return new ResponseEntity<>(validatedBody, HttpStatus.CREATED); |
209 | 218 | } |
210 | 219 |
|
211 | 220 | @Override |
|
0 commit comments