Example #1
0
 private void usersInGroups(Handler<Message<JsonObject>> handler) {
   final Neo4j neo4j = TransactionManager.getInstance().getNeo4j();
   final JsonObject params = new JsonObject().putString("id", id);
   String query =
       "MATCH (s:Structure {id : {id}})<-[:BELONGS]-(c:Class)"
           + "<-[:DEPENDS]-(cpg:Group) "
           + "OPTIONAL MATCH cpg<-[:IN]-(u:User) "
           + "RETURN cpg.id as group, cpg.name as groupName, collect(u.id) as users "
           + "UNION "
           + "MATCH (s:Structure {id : {id}})<-[r:DEPENDS]-(fg:FunctionalGroup) "
           + "OPTIONAL MATCH fg<-[:IN]-(u:User) "
           + "RETURN fg.id as group, fg.name as groupName, collect(u.id) as users ";
   neo4j.execute(query, params, handler);
 }
Example #2
0
 private void transitionClassGroup() {
   TransactionHelper tx = TransactionManager.getInstance().getTransaction("GraphDataUpdate");
   JsonObject params = new JsonObject().putString("id", id);
   String query =
       "MATCH (s:Structure {id : {id}})<-[r:BELONGS]-(c:Class)"
           + "<-[r1:DEPENDS]-(cpg:Group)-[r2]-() "
           + "DELETE r, r1, r2, c, cpg ";
   tx.add(query, params);
   query =
       "MATCH (s:Structure {id : {id}})<-[r:DEPENDS]-(fg:FunctionalGroup) "
           + "OPTIONAL MATCH fg-[r1]-() "
           + "DELETE r, r1, fg";
   tx.add(query, params);
 }
Example #3
0
  public void transition(final Handler<Message<JsonObject>> handler) {
    final TransactionHelper tx = TransactionManager.getInstance().getTransaction("GraphDataUpdate");
    String query =
        "MATCH (s:Structure {id : {id}})<-[:BELONGS]-(c:Class)"
            + "<-[:DEPENDS]-(cpg:Group)<-[:IN]-(u:User) "
            + "OPTIONAL MATCH s<-[:DEPENDS]-(fg:FunctionalGroup) "
            + "RETURN collect(distinct u.id) as users, collect(distinct cpg.id) as profileGroups, "
            + "collect(distinct fg.id) as functionalGroups";
    JsonObject params = new JsonObject().putString("id", id);
    tx.getNeo4j()
        .execute(
            query,
            params,
            new Handler<Message<JsonObject>>() {
              @Override
              public void handle(Message<JsonObject> event) {
                JsonArray r = event.body().getArray("result");
                if ("ok".equals(event.body().getString("status")) && r != null && r.size() == 1) {
                  final JsonObject res = r.get(0);
                  usersInGroups(
                      new Handler<Message<JsonObject>>() {

                        @Override
                        public void handle(Message<JsonObject> event) {
                          for (Object u : res.getArray("users")) {
                            User.backupRelationship(u.toString(), tx);
                            User.transition(u.toString(), tx);
                          }
                          transitionClassGroup();
                          handler.handle(event);
                        }
                      });
                } else {
                  log.error("Structure " + id + " transition error.");
                  log.error(event.body().encode());
                  handler.handle(event);
                }
              }
            });
  }