Package org.structr.core.graph.search

Examples of org.structr.core.graph.search.SourceSearchAttribute


  @Override
  public SearchAttribute getSearchAttribute(SecurityContext securityContext, Occur occur, T searchValue, boolean exactMatch, final Query query) {

    final Predicate<GraphObject> predicate    = query != null ? query.toPredicate() : null;
    final SourceSearchAttribute attr          = new SourceSearchAttribute(occur);
    final Set<GraphObject> intersectionResult = new LinkedHashSet<>();
    boolean alreadyAdded                      = false;

    try {

      if (searchValue != null && !StringUtils.isBlank(searchValue.toString())) {

        final App app                          = StructrApp.getInstance(securityContext);
        final PropertyKey key                  = notion.getPrimaryPropertyKey();
        final PropertyConverter inputConverter = key.inputConverter(securityContext);

        // transform search values using input convert of notion property
        final Object transformedValue          = inputConverter != null ? inputConverter.convert(searchValue) : searchValue;

        if (exactMatch) {

          Result<AbstractNode> result = app.nodeQuery(entityProperty.relatedType()).and(key, transformedValue).getResult();

          for (AbstractNode node : result.getResults()) {

            switch (occur) {

              case MUST:

                if (!alreadyAdded) {

                  // the first result is the basis of all subsequent intersections
                  intersectionResult.addAll(entityProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));

                  // the next additions are intersected with this one
                  alreadyAdded = true;

                } else {

                  intersectionResult.retainAll(entityProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
                }

                break;

              case SHOULD:
                intersectionResult.addAll(entityProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
                break;

              case MUST_NOT:
                break;
            }
          }

        } else {

          Result<AbstractNode> result = app.nodeQuery(entityProperty.relatedType(), false).and(key, transformedValue, false).getResult();

          // loose search behaves differently, all results must be combined
          for (AbstractNode node : result.getResults()) {

            intersectionResult.addAll(entityProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
          }
        }

        attr.setResult(intersectionResult);

      } else {

        // experimental filter attribute that
        // removes entities with a non-empty
View Full Code Here


  @Override
  public SearchAttribute getSearchAttribute(SecurityContext securityContext, BooleanClause.Occur occur, List<T> searchValue, boolean exactMatch, final Query query) {

    final Predicate<GraphObject> predicate    = query != null ? query.toPredicate() : null;
    final SourceSearchAttribute attr          = new SourceSearchAttribute(occur);
    final Set<GraphObject> intersectionResult = new LinkedHashSet<>();
    boolean alreadyAdded                      = false;

    if (searchValue != null && !StringUtils.isBlank(searchValue.toString())) {

      final App app = StructrApp.getInstance(securityContext);

      if (exactMatch) {

        for (NodeInterface node : searchValue) {

          switch (occur) {

            case MUST:

              if (!alreadyAdded) {

                // the first result is the basis of all subsequent intersections
                intersectionResult.addAll(getRelatedNodesReverse(securityContext, node, declaringClass, predicate));

                // the next additions are intersected with this one
                alreadyAdded = true;

              } else {

                intersectionResult.retainAll(getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
              }

              break;

            case SHOULD:
              intersectionResult.addAll(getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
              break;

            case MUST_NOT:
              break;
          }
        }

      } else {

        // loose search behaves differently, all results must be combined
        for (NodeInterface node : searchValue) {

          intersectionResult.addAll(getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
        }
      }

      attr.setResult(intersectionResult);

    } else {

      // experimental filter attribute that
      // removes entities with a non-empty
View Full Code Here

  @Override
  public SearchAttribute getSearchAttribute(SecurityContext securityContext, BooleanClause.Occur occur, List<S> searchValue, boolean exactMatch, final Query query) {

    final Predicate<GraphObject> predicate    = query != null ? query.toPredicate() : null;
    final SourceSearchAttribute attr          = new SourceSearchAttribute(occur);
    final Set<GraphObject> intersectionResult = new LinkedHashSet<>();
    boolean alreadyAdded                      = false;

    if (searchValue != null && !StringUtils.isBlank(searchValue.toString())) {

      final App app = StructrApp.getInstance(securityContext);

      if (exactMatch) {

        for (NodeInterface node : searchValue) {

          switch (occur) {

            case MUST:

              if (!alreadyAdded) {

                // the first result is the basis of all subsequent intersections
                intersectionResult.addAll(getRelatedNodesReverse(securityContext, node, declaringClass, predicate));

                // the next additions are intersected with this one
                alreadyAdded = true;

              } else {

                intersectionResult.retainAll(getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
              }

              break;

            case SHOULD:
              intersectionResult.addAll(getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
              break;

            case MUST_NOT:
              break;
          }
        }

      } else {

        // loose search behaves differently, all results must be combined
        for (NodeInterface node : searchValue) {

          intersectionResult.addAll(getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
        }
      }

      attr.setResult(intersectionResult);

    } else {

      // experimental filter attribute that
      // removes entities with a non-empty
View Full Code Here

  @Override
  public SearchAttribute getSearchAttribute(SecurityContext securityContext, BooleanClause.Occur occur, T searchValue, boolean exactMatch, final Query query) {

    final Predicate<GraphObject> predicate    = query != null ? query.toPredicate() : null;
    final SourceSearchAttribute attr          = new SourceSearchAttribute(occur);
    final Set<GraphObject> intersectionResult = new LinkedHashSet<>();
    boolean alreadyAdded                      = false;

    if (searchValue != null && !StringUtils.isBlank(searchValue.toString())) {

      final App app = StructrApp.getInstance(securityContext);

      if (exactMatch) {

        switch (occur) {

          case MUST:

            if (!alreadyAdded) {

              // the first result is the basis of all subsequent intersections
              intersectionResult.addAll(getRelatedNodesReverse(securityContext, searchValue, declaringClass, predicate));

              // the next additions are intersected with this one
              alreadyAdded = true;

            } else {

              intersectionResult.retainAll(getRelatedNodesReverse(securityContext, searchValue, declaringClass, predicate));
            }

            break;

          case SHOULD:
            intersectionResult.addAll(getRelatedNodesReverse(securityContext, searchValue, declaringClass, predicate));
            break;

          case MUST_NOT:
            break;
        }

      } else {

        intersectionResult.addAll(getRelatedNodesReverse(securityContext, searchValue, declaringClass, predicate));
      }

      attr.setResult(intersectionResult);

    } else {

      // experimental filter attribute that
      // removes entities with a non-empty
View Full Code Here

  @Override
  public SearchAttribute getSearchAttribute(SecurityContext securityContext, BooleanClause.Occur occur, List<T> searchValues, boolean exactMatch, final Query query) {

    final Predicate<GraphObject> predicate    = query != null ? query.toPredicate() : null;
    final SourceSearchAttribute attr          = new SourceSearchAttribute(occur);
    final Set<GraphObject> intersectionResult = new LinkedHashSet<>();
    boolean alreadyAdded                      = false;

    try {

      if (searchValues != null && !searchValues.isEmpty()) {

        final PropertyKey key                  = notion.getPrimaryPropertyKey();
        final PropertyConverter inputConverter = key.inputConverter(securityContext);
        final List<Object> transformedValues   = new LinkedList<>();
        boolean allBlank                       = true;

        // transform search values using input convert of notion property
        for (T searchValue : searchValues) {

          if (inputConverter != null) {

            transformedValues.add(inputConverter.convert(searchValue));
          } else {

            transformedValues.add(searchValue);
          }
        }

        // iterate over transformed values
        for (Object searchValue : transformedValues) {

          // check if the list contains non-empty search values
          if (StringUtils.isBlank(searchValue.toString())) {

            continue;

          } else {

            allBlank = false;
          }

          final App app = StructrApp.getInstance(securityContext);


          if (exactMatch) {

            Result<AbstractNode> result = app.nodeQuery(collectionProperty.relatedType()).and(notion.getPrimaryPropertyKey(), searchValue).getResult();

            for (AbstractNode node : result.getResults()) {

              switch (occur) {

                case MUST:

                  if (!alreadyAdded) {

                    // the first result is the basis of all subsequent intersections
                    intersectionResult.addAll(collectionProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));

                    // the next additions are intersected with this one
                    alreadyAdded = true;

                  } else {

                    intersectionResult.retainAll(collectionProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
                  }

                  break;

                case SHOULD:
                  intersectionResult.addAll(collectionProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
                  break;

                case MUST_NOT:
                  break;
              }
            }

          } else {

            Result<AbstractNode> result = app.nodeQuery(collectionProperty.relatedType(), false).and(notion.getPrimaryPropertyKey(), searchValue, false).getResult();

            // loose search behaves differently, all results must be combined
            for (AbstractNode node : result.getResults()) {

              intersectionResult.addAll(collectionProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
            }

          }
        }

        if (allBlank) {

          // experimental filter attribute that
          // removes entities with a non-empty
          // value in the given field
          return new EmptySearchAttribute(this, Collections.emptyList());

        } else {

          attr.setResult(intersectionResult);
        }

      } else {

        // experimental filter attribute that
View Full Code Here

  @Override
  public SearchAttribute getSearchAttribute(SecurityContext securityContext, BooleanClause.Occur occur, S searchValue, boolean exactMatch, final Query query) {

    final Predicate<GraphObject> predicate    = query != null ? query.toPredicate() : null;
    final SourceSearchAttribute attr          = new SourceSearchAttribute(occur);
    final Set<GraphObject> intersectionResult = new LinkedHashSet<>();
    boolean alreadyAdded                      = false;

    if (searchValue != null && !StringUtils.isBlank(searchValue.toString())) {

      final App app = StructrApp.getInstance(securityContext);

      if (exactMatch) {

        switch (occur) {

          case MUST:

            if (!alreadyAdded) {

              // the first result is the basis of all subsequent intersections
              intersectionResult.addAll(getRelatedNodesReverse(securityContext, searchValue, declaringClass, predicate));

              // the next additions are intersected with this one
              alreadyAdded = true;

            } else {

              intersectionResult.retainAll(getRelatedNodesReverse(securityContext, searchValue, declaringClass, predicate));
            }

            break;

          case SHOULD:
            intersectionResult.addAll(getRelatedNodesReverse(securityContext, searchValue, declaringClass, predicate));
            break;

          case MUST_NOT:
            break;
        }

      } else {

        intersectionResult.addAll(getRelatedNodesReverse(securityContext, searchValue, declaringClass, predicate));
      }

      attr.setResult(intersectionResult);

    } else {

      // experimental filter attribute that
      // removes entities with a non-empty
View Full Code Here

TOP

Related Classes of org.structr.core.graph.search.SourceSearchAttribute

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.