private void addQueryFilters(final ContentQuery.Builder builder) {
   if (contentQueryJson.getQueryFilters() != null) {
     for (final FilterJson queryFilterJson : contentQueryJson.getQueryFilters()) {
       builder.queryFilter(queryFilterJson.getFilter());
     }
   }
 }
  public ContentQuery createQuery() {
    final ContentQuery.Builder builder =
        ContentQuery.create()
            .from(contentQueryJson.getFrom())
            .size(contentQueryJson.getSize())
            .queryExpr(QueryParser.parse(contentQueryJson.getQueryExprString()))
            .addContentTypeNames(contentQueryJson.getContentTypeNames());

    addAggregationQueries(builder);

    addQueryFilters(builder);

    addOutboundContentIdsToFilter(builder);

    return builder.build();
  }
 private void addAggregationQueries(final ContentQuery.Builder builder) {
   if (contentQueryJson.getAggregationQueries() != null) {
     for (final AggregationQueryJson aggregationQueryJson :
         contentQueryJson.getAggregationQueries()) {
       builder.aggregationQuery(aggregationQueryJson.getAggregationQuery());
     }
   }
 }
  private void addOutboundContentIdsToFilter(final ContentQuery.Builder builder) {
    if (contentQueryJson.getMustBeReferencedById() != null) {

      final ContentIds ids =
          this.contentService.getOutboundDependencies(contentQueryJson.getMustBeReferencedById());

      // TODO: no need to filter when we fix that removed content will be removed from references
      builder.filterContentIds(getExistingContentIds(ids));
    }
  }