コード例 #1
0
  private Map<String, FilteringPropertyFilter> createSubfilters(
      final Class<?> entityClass, final Map<String, ObjectGraph> entitySubgraphs) {
    final Set<String> processed = Sets.newHashSet();
    final Map<String, FilteringPropertyFilter> subfilters = Maps.newHashMap();

    for (final Map.Entry<String, ObjectGraph> entry : entitySubgraphs.entrySet()) {
      final String fieldName = entry.getKey();

      if (fieldName.startsWith("_")) continue;

      final ObjectGraph graph = entry.getValue();

      // Subgraph Fields.
      final Map<String, ObjectGraph> subgraphs = graph.getSubgraphs(fieldName);

      Map<String, FilteringPropertyFilter> subSubfilters = Maps.newHashMap();
      if (!subgraphs.isEmpty()) {
        final Class<?> subEntityClass = graph.getEntityClass();

        processed.add(getProcessedSubgraph(entityClass, fieldName, subEntityClass));
        subSubfilters = createSubfilters(fieldName, subEntityClass, subgraphs, processed);
      }

      final FilteringPropertyFilter filter =
          new FilteringPropertyFilter(
              graph.getEntityClass(), graph.getFields(fieldName), subSubfilters);

      subfilters.put(fieldName, filter);
    }

    return subfilters;
  }
コード例 #2
0
  /** {@inheritDoc} */
  @Override
  public FilterProvider transform(final ObjectGraph graph) {
    // Root entity.
    final FilteringPropertyFilter root =
        new FilteringPropertyFilter(
            graph.getEntityClass(),
            graph.getFields(),
            createSubfilters(graph.getEntityClass(), graph.getSubgraphs()));

    return new FilteringFilterProvider(root);
  }
コード例 #3
0
  private Map<String, FilteringPropertyFilter> createSubfilters(
      final String parent,
      final Class<?> entityClass,
      final Map<String, ObjectGraph> entitySubgraphs,
      final Set<String> processed) {
    final Map<String, FilteringPropertyFilter> subfilters = Maps.newHashMap();

    for (final Map.Entry<String, ObjectGraph> entry : entitySubgraphs.entrySet()) {
      final String fieldName = entry.getKey();

      if (fieldName.startsWith("_")) continue;

      final ObjectGraph graph = entry.getValue();

      final String path = parent + "." + fieldName;

      // Subgraph Fields.
      final Map<String, ObjectGraph> subgraphs = graph.getSubgraphs(path);

      final Class<?> subEntityClass = graph.getEntityClass();
      final String processedSubgraph = getProcessedSubgraph(entityClass, fieldName, subEntityClass);

      Map<String, FilteringPropertyFilter> subSubfilters = Maps.newHashMap();
      if (!subgraphs.isEmpty() && !processed.contains(processedSubgraph)) {
        processed.add(processedSubgraph);
        subSubfilters = createSubfilters(path, subEntityClass, subgraphs, processed);
      }

      subfilters.put(
          fieldName,
          new FilteringPropertyFilter(
              graph.getEntityClass(), graph.getFields(path), subSubfilters));
    }

    return subfilters;
  }