private void updateMatchedPaths(Connected newERBase) {
    Set<Path> newMatchedPaths = new HashSet<Path>();

    for (Path p : inputStream.getCurrentMatchedPaths()) {

      // if current level is optional -> move through current paths
      if (optional) newMatchedPaths.add(p);

      String lastId = p.getLast();
      Connected lastER = pipeNet.getById(lastId); // last er in the path can be virtual
      if (newERBase.isConnectedTo(lastId)
          || (lastER.isVirtual() && lastER.isConnectedTo(newERBase.getUuid()))) {
        if (!ALLOW_REENTRANCE) { // check for re-entrance
          if (p.contains(newERBase.getUuid())) continue;
        }

        p = p.clone();
        p.add(newERBase.getUuid());
        newMatchedPaths.add(p);
      }
    }

    for (Path p : newMatchedPaths) currentMatchedPaths.add(p);

    return;
  }
Beispiel #2
0
  @RequestMapping("/view-data")
  public void viewJSON(HttpServletRequest request, HttpServletResponse res) {

    String query = request.getParameter("q");
    if (null == query || query.trim().length() == 0) query = null;
    String depthStr = request.getParameter("d");
    int depth = 1;
    try {
      depth = Integer.parseInt(depthStr);
      // check boundaries [1, 5]
      if (depth < 1 || depth > 5) depth = 1;

    } catch (Exception ex) {

    }

    Set<Connected> eList = new HashSet<Connected>();
    Network net = new Network();
    if (null != query) {
      try {
        Storage storage = NMSServerConfig.getInstance().getStorage(request.getParameter("storage"));
        if (null == storage) {
          logger.error("storage is not defined");
          return;
        }

        net = (Network) request.getSession().getAttribute(query);
        if (null == net) {
          net = storage.query(query);
        } else {
          request.getSession().removeAttribute(query);
        }

        String[] entities = net.getIds();

        for (String eid : entities) {
          doDepthView(net.getById(eid), eList, depth);
        }
      } catch (NQLException e) {
        logger.error("Wrong NQL query " + query, e);
      } catch (StorageException e) {
        logger.error("Can't execute query " + query, e);
      }
    } else {
      logger.error("No NQL query");
    }

    List<Node> nodes = adaptNodes(eList, net);

    GsonBuilder gb = new GsonBuilder();
    Gson gson = gb.setPrettyPrinting().create();

    String jsonStr = gson.toJson(nodes);
    res.setContentType("application/json");

    logger.debug("JSON: " + jsonStr);
    //		System.out.println(jsonStr);
    try {
      res.getWriter().write(jsonStr);
    } catch (IOException e) {
      logger.error("Can't write JSON string to output stream", e);
    }
    return;
  }
Beispiel #3
0
  private List<Node> adaptNodes(Collection<Connected> eList, Network net) {
    List<Node> nodes = new ArrayList<Node>(eList.size());
    List<Connected> dependentEntities = new ArrayList<Connected>();
    for (Connected e : eList) {
      Node n = new Node();
      if (null != e.getUuid()) {
        n.id = e.getUuid();
      } else {
        n.id = e.getName();
      }
      n.name = e.getName();
      n.data.put("$color", "#83548B");
      String nodeType = getNodeType(e);
      if (null != nodeType) {
        n.data.put("$type", nodeType);
        //				n.data.put("$type", "circle");
      } else {
        n.data.put("$type", "circle");
      }
      n.data.put("$dim", 10);

      for (Connected r : e.getConnected()) {
        if (null == net.getById(r.getUuid())) // show relations in network only
        continue;

        //				for (ERBase rp : r.getAllConnectedFiltered(e.getUuid()))
        {
          Adjacency a = new Adjacency();
          a.nodeFrom = e.getUuid();
          a.nodeTo = r.getUuid();
          dependentEntities.add(r);
          //					a.nodeFrom = e.getName();
          //					a.nodeTo = rp.getEntity().getName();
          a.data.put("$name", r.getName());
          a.data.put("$color", "#557EAA");
          // TODO: how to add label to relation?
          //					a.data.put("$text", "test");
          //					a.data.put("$label", "test");
          n.adjacencies.add(a);
        }
      }
      nodes.add(n);
    }

    // update names for denepndent nodes (add depenent nodes without relations)
    for (Connected e : dependentEntities) {
      if (!eList.contains(e)) {
        Node n = new Node();
        if (null != e.getUuid()) {
          n.id = e.getUuid();
        } else {
          n.id = e.getName();
        }
        n.name = e.getName();
        n.data.put("$color", "#83548B");
        n.data.put("$type", "circle");
        n.data.put("$dim", 10);

        nodes.add(n);
      }
    }

    return nodes;
  }