@Test public void shouldRemoveDeeperRelationshipFromCollectionOfJavaObjects() { List<Factory> factories = car.getManufacturer().getFactories(); Object actual = displayUtil.breakDeepRelationChainForDisplay(factories, prepareFieldDefinitionsForFactory()); List<Factory> parsed = (List<Factory>) actual; assertEquals(factories.size(), parsed.size()); Factory parsed1 = parsed.get(0); Factory parsed2 = parsed.get(1); assertEquals(factories.get(0).getName(), parsed1.getName()); assertEquals(factories.get(1).getName(), parsed2.getName()); assertNull(parsed1.getLocation()); assertNull(parsed2.getLocation()); }
@Transactional(propagation = Propagation.NEVER) public Object breakDeepRelationChainForDisplay(Object value, List<FieldDto> fields) { boolean isCollection = value instanceof Collection; for (FieldDto fieldDto : fields) { if (fieldDto.getMetadata(Constants.MetadataKeys.RELATED_CLASS) != null && isCollection) { for (Object instance : (Collection) value) { PropertyUtil.safeSetProperty(instance, fieldDto.getBasic().getName(), null); } } else if (fieldDto.getMetadata(Constants.MetadataKeys.RELATED_CLASS) != null && !isCollection) { PropertyUtil.safeSetProperty(value, fieldDto.getBasic().getName(), null); } } return value; }
RelationshipDisplayUtil { @Transactional(propagation = Propagation.NEVER) public Object breakDeepRelationChainForDisplay(Object value, List<FieldDto> fields) { boolean isCollection = value instanceof Collection; for (FieldDto fieldDto : fields) { if (fieldDto.getMetadata(Constants.MetadataKeys.RELATED_CLASS) != null && isCollection) { for (Object instance : (Collection) value) { PropertyUtil.safeSetProperty(instance, fieldDto.getBasic().getName(), null); } } else if (fieldDto.getMetadata(Constants.MetadataKeys.RELATED_CLASS) != null && !isCollection) { PropertyUtil.safeSetProperty(value, fieldDto.getBasic().getName(), null); } } return value; } }
RelationshipDisplayUtil { @Transactional(propagation = Propagation.NEVER) public Object breakDeepRelationChainForDisplay(Object value, List<FieldDto> fields) { boolean isCollection = value instanceof Collection; for (FieldDto fieldDto : fields) { if (fieldDto.getMetadata(Constants.MetadataKeys.RELATED_CLASS) != null && isCollection) { for (Object instance : (Collection) value) { PropertyUtil.safeSetProperty(instance, fieldDto.getBasic().getName(), null); } } else if (fieldDto.getMetadata(Constants.MetadataKeys.RELATED_CLASS) != null && !isCollection) { PropertyUtil.safeSetProperty(value, fieldDto.getBasic().getName(), null); } } return value; }  }
RelationshipDisplayUtil { @Transactional(propagation = Propagation.NEVER) public Object breakDeepRelationChainForDisplay(Object value, List<FieldDto> fields) { boolean isCollection = value instanceof Collection; for (FieldDto fieldDto : fields) { if (fieldDto.getMetadata(Constants.MetadataKeys.RELATED_CLASS) != null && isCollection) { for (Object instance : (Collection) value) { PropertyUtil.safeSetProperty(instance, fieldDto.getBasic().getName(), null); } } else if (fieldDto.getMetadata(Constants.MetadataKeys.RELATED_CLASS) != null && !isCollection) { PropertyUtil.safeSetProperty(value, fieldDto.getBasic().getName(), null); } } return value; }  @Transactional(propagation = Propagation.NEVER) Object breakDeepRelationChainForDisplay(Object value, List<FieldDto> fields); }
RelationshipDisplayUtil { @Transactional(propagation = Propagation.NEVER) public Object breakDeepRelationChainForDisplay(Object value, List<FieldDto> fields) { boolean isCollection = value instanceof Collection; for (FieldDto fieldDto : fields) { if (fieldDto.getMetadata(Constants.MetadataKeys.RELATED_CLASS) != null && isCollection) { for (Object instance : (Collection) value) { PropertyUtil.safeSetProperty(instance, fieldDto.getBasic().getName(), null); } } else if (fieldDto.getMetadata(Constants.MetadataKeys.RELATED_CLASS) != null && !isCollection) { PropertyUtil.safeSetProperty(value, fieldDto.getBasic().getName(), null); } } return value; }  @Transactional(propagation = Propagation.NEVER) Object breakDeepRelationChainForDisplay(Object value, List<FieldDto> fields);  }