Skip to content

Commit 89f18a1

Browse files
committed
fix(rest): update clearing request after editing in request tab
Signed-off-by: Nikesh Kumar <kumar.nikesh@siemens.com>
1 parent 34d1334 commit 89f18a1

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/clearingrequest/ClearingRequestController.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ public ResponseEntity<HalResource<ClearingRequest>> patchClearingRequest(
356356
schema = @Schema(implementation = ClearingRequest.class))
357357
@RequestBody Map<String, Object> reqBodyMap,
358358
HttpServletRequest request
359-
) {
360-
try{
359+
) throws TException {
360+
try {
361361
User sw360User = restControllerHelper.getSw360UserFromAuthentication();
362362

363363
ClearingRequest clearingRequest = sw360ClearingRequestService.getClearingRequestById(id, sw360User);
@@ -423,15 +423,23 @@ public ResponseEntity<HalResource<ClearingRequest>> patchClearingRequest(
423423
}
424424

425425
return new ResponseEntity<>(halClearingRequest, HttpStatus.OK);
426-
} catch (Exception e) {
426+
} catch (IllegalArgumentException e) {
427+
log.error("Invalid argument in clearing request update for id {}: {}", id, e.getMessage());
427428
throw new BadRequestClientException(e.getMessage(), e);
428429
}
429430
}
430431

431432
private ClearingRequest convertToClearingRequest(Map<String, Object> requestBody){
433+
Map<String, Object> sanitizedBody = new HashMap<>();
434+
requestBody.forEach((key, value) -> {
435+
if (value != null && !(value instanceof String && ((String) value).isEmpty())) {
436+
sanitizedBody.put(key, value);
437+
}
438+
});
439+
432440
ObjectMapper mapper = new ObjectMapper();
433441
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
434442
mapper.registerModule(sw360Module);
435-
return mapper.convertValue(requestBody, ClearingRequest.class);
443+
return mapper.convertValue(sanitizedBody, ClearingRequest.class);
436444
}
437445
}

0 commit comments

Comments
 (0)