Package org.structr.common

Examples of org.structr.common.StructrAndSpatialPredicate


    final List<AbstractNode> nodes = new LinkedList<>();

    // instantiate all nodes in a single list
    try (final Tx tx = StructrApp.getInstance().tx()) {

      final Result<AbstractNode> result = nodeFactory.instantiateAll(Iterables.filter(new StructrAndSpatialPredicate(true, false, false), GlobalGraphOperations.at(graphDb).getAllNodes()));
      for (AbstractNode node : result.getResults()) {

        if (type == null || node.getClass().equals(type)) {

          nodes.add(node);
View Full Code Here


      final List<AbstractNode> nodes = new LinkedList<>();

      // instantiate all nodes in a single list
      try (final Tx tx = StructrApp.getInstance().tx()) {

        final Result<AbstractNode> result = nodeFactory.instantiateAll(Iterables.filter(new StructrAndSpatialPredicate(true, false, false), GlobalGraphOperations.at(graphDb).getAllNodes()));
        for (AbstractNode node : result.getResults()) {

          if (type == null || node.getClass().equals(type)) {

            nodes.add(node);
          }

        }

        tx.success();
      }

      if (type == null) {

        logger.log(Level.INFO, "Node type not set or no entity class found. Starting (re-)indexing all nodes");

      } else {

        logger.log(Level.INFO, "Starting (re-)indexing all nodes of type {0}", new Object[]{type.getSimpleName()});
      }

      long count = bulkGraphOperation(securityContext, nodes, 100, "RebuildNodeIndex", new BulkGraphOperation<AbstractNode>() {

        @Override
        public void handleGraphObject(SecurityContext securityContext, AbstractNode node) {

          try {
            // Set type to update labels
            final String type = node.getProperty(NodeInterface.type);
            node.setProperty(NodeInterface.type, null);
            node.setProperty(NodeInterface.type, type);
          } catch (FrameworkException ex) {
            ex.printStackTrace();
          }
          node.updateInIndex();

        }

        @Override
        public void handleThrowable(SecurityContext securityContext, Throwable t, AbstractNode node) {

          logger.log(Level.WARNING, "Unable to index node {0}: {1}", new Object[]{node, t.getMessage()});

        }

        @Override
        public void handleTransactionFailure(SecurityContext securityContext, Throwable t) {

          logger.log(Level.WARNING, "Unable to index node: {0}", t.getMessage());

        }

      });

      logger.log(Level.INFO, "Done with (re-)indexing {0} nodes", count);
    }

    if (mode == null || "relsOnly".equals(mode)) {

      final List<AbstractRelationship> rels = new LinkedList<>();
      long count                            = 0;

      // instantiate all relationships in a single list
      try (final Tx tx = StructrApp.getInstance().tx()) {

          final List<AbstractRelationship> unfilteredRels = relFactory.instantiate(Iterables.filter(new StructrAndSpatialPredicate(true, false, false), GlobalGraphOperations.at(graphDb).getAllRelationships()));
        for (AbstractRelationship rel : unfilteredRels) {

          if (relType == null || rel.getType().equals(relType)) {

            rels.add(rel);
View Full Code Here

      // register transaction post process that rebuilds the index after successful creation
      TransactionCommand.postProcess("reloadschema", new ReloadSchema());

      // analyze nodes
      for (final Node node : Iterables.filter(new StructrAndSpatialPredicate(false, false, true), GlobalGraphOperations.at(graphDb).getAllNodes())) {

        final NodeInfo nodeInfo = new NodeInfo(node);

        // extract node info and set UUID
        nodeTypes.add(nodeInfo);

        List<Node> nodes = nodeMap.get(nodeInfo);
        if (nodes == null) {
          nodes = new LinkedList<>();
          nodeMap.put(nodeInfo, nodes);
        }

        nodes.add(node);
      }

      // nodeTypes now contains all existing node types and their property sets
      identifyCommonBaseClasses(nodeTypes, nodeMap, typeInfos);

      // group type infos by type
      collectTypeInfos(typeInfos, typeInfoTypeMap);

      // reduce type infos with more than one type
      reduceTypeInfos(typeInfoTypeMap, reducedTypeInfos);

      // intersect property sets of type infos
      intersectPropertySets(reducedTypeInfos);

      // sort type infos
      Collections.sort(reducedTypeInfos, new HierarchyComparator(false));

      // set type and ID on newly created nodes
      final Map<String, TypeInfo> reducedTypeInfoMap = new LinkedHashMap<>();
      for (final TypeInfo info : reducedTypeInfos) {

        final String type = info.getPrimaryType();

        // map TypeInfo to type for later use
        reducedTypeInfoMap.put(type, info);

        for (final Node node : info.getNodes()) {

          node.setProperty(GraphObject.id.dbName(), NodeServiceCommand.getNextUuid());
          node.setProperty(GraphObject.type.dbName(), type);

          // store type info for imported node
          nodeTypeInfoMap.put(node.getId(), info);
        }
      }

      // analyze relationships
      for (final Relationship rel : Iterables.filter(new StructrAndSpatialPredicate(false, false, true), GlobalGraphOperations.at(graphDb).getAllRelationships())) {

        final Node startNode          = rel.getStartNode();
        final Node endNode            = rel.getEndNode();

        // make sure node has been successfully identified above
View Full Code Here

TOP

Related Classes of org.structr.common.StructrAndSpatialPredicate

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.