Skip to content

Commit

Permalink
chore(merge): release-10.2.0 into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
bonita-ci committed Jul 9, 2024
2 parents 4d36906 + 07fadc8 commit 6afa209
Showing 1 changed file with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
**/
package org.bonitasoft.engine.business.data.proxy;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
Expand All @@ -25,14 +26,17 @@

import org.bonitasoft.engine.bdm.Entity;
import org.bonitasoft.engine.bdm.lazy.LazyLoaded;
import org.springframework.beans.PropertyAccessorFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* @author Colin Puy
* @author Laurent Leseigneur
*/
public class ServerProxyfier {

private static final Logger LOGGER = LoggerFactory.getLogger(ServerProxyfier.class);

private final ServerLazyLoader lazyLoader;

public ServerProxyfier(final ServerLazyLoader lazyLoader) {
Expand Down Expand Up @@ -170,23 +174,27 @@ private static Entity unProxifyIfNeeded(Entity entity, Set<Entity> alreadyUnprox
boolean wasNotAlreadyUnproxified = alreadyUnproxyfiedEntities.add(detachedEntity);
// If we just unproxified this entity, we must also unproxify its related Entity fields:
if (wasNotAlreadyUnproxified) {
var propertyAccessor = PropertyAccessorFactory.forBeanPropertyAccess(detachedEntity);
for (var property : propertyAccessor.getPropertyDescriptors()) {
var propertyType = property.getPropertyType();
if (Entity.class.isAssignableFrom(propertyType)) {
propertyAccessor.setPropertyValue(property.getName(),
unProxifyIfNeeded((Entity) propertyAccessor.getPropertyValue(property.getName()),
alreadyUnproxyfiedEntities));
} else if (List.class.isAssignableFrom(propertyType)) {
final List list = (List) propertyAccessor.getPropertyValue(property.getName());
if (list != null && !list.isEmpty() && isThereAnyNonNullEntityInTheList(list)) {
final List<Entity> realEntities = ((List<Entity>) list).stream()
.map(element -> unProxifyIfNeeded(element, alreadyUnproxyfiedEntities))
.collect(Collectors.toList());
list.clear();
list.addAll(realEntities);
propertyAccessor.setPropertyValue(property.getName(), list);
final Field[] declaredFields = detachedEntity.getClass().getDeclaredFields();
for (final Field field : declaredFields) {
try {
if (Entity.class.isAssignableFrom(field.getType())) {
field.setAccessible(true);
field.set(detachedEntity,
unProxifyIfNeeded((Entity) field.get(detachedEntity), alreadyUnproxyfiedEntities));
} else if (List.class.isAssignableFrom(field.getType())) {
field.setAccessible(true);
final List list = (List) field.get(detachedEntity);
if (list != null && !list.isEmpty() && isThereAnyNonNullEntityInTheList(list)) {
final List<Entity> realEntities = ((List<Entity>) list).stream()
.map(element -> unProxifyIfNeeded(element, alreadyUnproxyfiedEntities))
.collect(Collectors.toList());
list.clear();
list.addAll(realEntities);
field.set(detachedEntity, list);
}
}
} catch (IllegalAccessException e) {
LOGGER.error(String.format("Illegal access to field '%s' of Entity '%s'", field, detachedEntity));
}
}
}
Expand Down

0 comments on commit 6afa209

Please sign in to comment.