Commit 42e2685e authored by femiadeyemi's avatar femiadeyemi
Browse files

fix minor bug relating to entity update

Motivation:

Field inside cerebrum entity are private. Hence, one needs to
explicity set the accessibility of a private field if we need
to access it through  java reflection, else this will throw
IllegalAccessException error.

Modification:

Ensure that the private fields are accessible

Result:

Update of entity now works as expected

Target: master
Review-at: https://gitlab.hzdr.de/hifis-technical-platform/helmholtz-cerebrum/-/merge_requests/31
parent 52177ace
Pipeline #41752 failed with stages
in 60 minutes
......@@ -148,10 +148,16 @@ public abstract class CerebrumServiceBase<T, R> implements CerebrumService<T, R>
for (Field field : fields) {
if (field.getDeclaringClass() == this.entityClass
&& Modifier.toString(field.getModifiers()).contains("public")) {
&& Modifier.toString(field.getModifiers()).contains("private")) {
try {
field.set(retrievedEntity,
this.entityClass.getDeclaredField(field.getName()).get(submittedEntity));
field.setAccessible(true);
Field submittedEntityField = submittedEntity.getClass().getDeclaredField(field.getName());
submittedEntityField.setAccessible(true);
if (submittedEntityField.get(submittedEntity) != null) {
field.set(retrievedEntity, submittedEntityField.get(submittedEntity));
}
field.setAccessible(false);
submittedEntityField.setAccessible(false);
} catch (IllegalAccessException e) {
throw new ResponseStatusException(
HttpStatus.INTERNAL_SERVER_ERROR,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment