Exemple #1
0
  public JSONObject addPrimaryNode(PrimaryNode t) {
    System.out.println("start creating a a primary node");
    JSONObject json = new JSONObject();

    Transaction tx = db.beginTx();
    System.out.println("test1111");
    try {
      Node primarynode = createAndIndexNode(id, t.getPostalcode());
      // System.out.println("xxxxxxxxxxxxxxhere");
      primarynode.setProperty("postalcode", t.getPostalcode());
      primarynode.setProperty("name", t.getName());
      primarynode.setProperty("lat", t.getlat());
      primarynode.setProperty("lon", t.getLon());
      primarynode.setProperty("province", t.getProvince());
      primarynode.setProperty("district", t.getDistrict());
      primarynode.setProperty("description", t.getDescription());
      primarynode.setProperty("node_type", t.getNodeType());

      Node parent = indexToNode(District, t.getDistrict());
      if (parent != null) {
        parent.createRelationshipTo(primarynode, geo_rel.PRIMARY_NODE);
      } else {
        json.put("status", "fail");
        json.put("desc", "Cannot find the parent node of this Primary Node");
      }
      GeoOperations op = new GeoOperations();
      json = op.convertPrimaryNodetoJSON(primarynode);

      /*if(json.get("status").equals("fail")){
      	return json;
      }*/

      json.put("status", "success");
      json.put("desc", "Town created sucessfully");
      tx.success();
    } catch (Exception e) {

      json.put("status", "fail");
      json.put("desc", "exception occurs while creating a user" + e.getMessage());

    } finally {
      tx.finish();
    }

    return json;
  }
Exemple #2
0
  public JSONObject addSecondaryNode(SecondaryNode n) {
    System.out.println("start creating a secondary node");
    JSONObject json = new JSONObject();

    Transaction tx2 = db.beginTx();
    Node n2;
    try {
      n2 = indexToNode("id", id_for_secondarynodes);
      int val = 0;
      if (n2 != null) {
        val = Integer.parseInt(n2.getProperty("val").toString());
        val++;

      } else {
        json.put("status", "fail");
        json.put("desc", "Id generation error");
        return json;
      }

      Node town = createAndIndexNode(snid, Integer.toString(val));
      n2.setProperty("val", Integer.toString(val)); // store the current issued number in the node
      town.setProperty(snid, Integer.toString(val));

      town.setProperty("name", n.getName());
      town.setProperty("postalcode", n.getPostalCode());
      town.setProperty("type", n.getType());
      town.setProperty("lat", n.getLat());
      town.setProperty("lon", n.getLon());

      // System.out.println("s111");

      town.setProperty("address", n.getAddress());
      town.setProperty("phone", n.getphone());
      town.setProperty("email", n.getEmail());
      town.setProperty("image", n.getImage());

      // System.out.println("s22");

      town.setProperty("website", n.getWebsite());
      town.setProperty("description", n.getDescription());
      town.setProperty("is_government", n.IsGovernment());
      town.setProperty("node_type", n.getNodeType());

      // System.out.println("s333");

      Node parent = indexToNode(id, n.getPostalCode());
      // System.out.println("s4444");
      parent.createRelationshipTo(town, geo_rel.SECONDARY_NODE);
      // System.out.println("s55");
      System.out.println(town + "secondary node created");
      // System.out.println("1111");

      GeoOperations op1 = new GeoOperations();

      // System.out.println("2222");
      json = op1.convertSecondaryNodetoJSON(town);

      // System.out.println("3333");

      json.put("status", "success");
      json.put("desc", "Secondary Node added sucessfully");

      // System.out.println("4444");
      tx2.success();

    } catch (Exception e) {
      // System.out.println("55");
      json.put("status", "fail");
      json.put("desc", "exception occurs while creating a Secondary Node:" + e.getMessage());

    } finally {
      tx2.finish();
    }

    return json;
  }