public static boolean returnsCollectionOfConfiguredObjects(ConfiguredObjectOperation operation) { return Collection.class.isAssignableFrom(operation.getReturnType()) && operation.getGenericReturnType() instanceof ParameterizedType && ConfiguredObject.class.isAssignableFrom(getCollectionMemberType((ParameterizedType) operation.getGenericReturnType())); }
private Object convertIntoLegacyIfRequired(final String name, final Object value) { if (value != null) { ConfiguredObjectAttribute<?, ?> attribute = getConfiguredObjectAttribute(name); final Class<?> type = attribute.getType(); final Type genericType = attribute.getGenericType(); if (ConfiguredObject.class.isAssignableFrom(type)) { return new LegacyConfiguredObjectObject((ConfiguredObject<?>) value); } else if (Collection.class.isAssignableFrom(type) && genericType instanceof ParameterizedType && ConfiguredObject.class.isAssignableFrom(getCollectionMemberType((ParameterizedType) genericType))) { Collection<?> collection = (Collection<?>) value; return collection.stream() .filter(o -> o instanceof LegacyConfiguredObjectObject) .map(LegacyConfiguredObjectObject.class::cast) .map(co -> new LegacyConfiguredObjectObject((ConfiguredObject<?>) co)) .collect(Collectors.toSet()); } } return value; }
public ConfiguredObjectFinder(final ConfiguredObject<?> root) { _root = root; _model = root.getModel(); final Class<? extends ConfiguredObject> managedCategory = root.getCategoryClass(); addManagedHierarchies(managedCategory, managedCategory); for (ConfiguredObjectOperation operation : _model.getTypeRegistry().getOperations(managedCategory).values()) { if (operation.isAssociateAsIfChildren() && returnsCollectionOfConfiguredObjects(operation)) { Class<? extends ConfiguredObject> associatedChildCategory = (getCollectionMemberType((ParameterizedType) operation.getGenericReturnType())); _associatedChildrenOperations.put(associatedChildCategory, operation); addManagedHierarchies(associatedChildCategory, associatedChildCategory); } } }