Exemple #1
0
  public boolean execute(Object... objects) throws Exception {
    Map<String, Object> inputMap = (Map<String, Object>) objects[0];
    Map<String, Object> data = (Map<String, Object>) inputMap.get("data");
    Map<String, Object> payload = (Map<String, Object>) inputMap.get("payload");
    Map<String, Object> user = (Map<String, Object>) payload.get("user");
    String rid = (String) data.get("@rid");
    String userId = (String) data.get("userId");
    String error = null;

    String host = (String) user.get("host");
    if (host != null && !host.equals(data.get("host"))) {
      error = "You can only delete user from host: " + host;
      inputMap.put("responseCode", 403);
    } else {
      if (rid == null && userId == null) {
        error = "rid or userId is required";
        inputMap.put("responseCode", 400);
      } else {
        OrientGraph graph = ServiceLocator.getInstance().getGraph();
        Vertex deleteUser = null;
        try {
          if (rid != null) {
            deleteUser = DbService.getVertexByRid(graph, rid);
            if (deleteUser == null) {
              error = "User with rid " + rid + " cannot be found.";
              inputMap.put("responseCode", 404);
            }
          } else {
            deleteUser = getUserByUserId(graph, userId);
            if (deleteUser == null) {
              error = "User with userId " + userId + " cannot be found.";
              inputMap.put("responseCode", 404);
            }
          }
          if (deleteUser != null) {
            Map eventMap = getEventMap(inputMap);
            Map<String, Object> eventData = (Map<String, Object>) eventMap.get("data");
            inputMap.put("eventMap", eventMap);
            eventData.put("userId", deleteUser.getProperty("userId").toString());
          }
        } catch (Exception e) {
          logger.error("Exception:", e);
          throw e;
        } finally {
          graph.shutdown();
        }
      }
    }
    if (error != null) {
      inputMap.put("result", error);
      return false;
    } else {
      return true;
    }
  }
Exemple #2
0
 public boolean execute(Object... objects) throws Exception {
   Map<String, Object> inputMap = (Map<String, Object>) objects[0];
   HttpServerExchange exchange = (HttpServerExchange) inputMap.get("exchange");
   Map<String, Object> data = (Map<String, Object>) inputMap.get("data");
   Map<String, Object> payload = (Map<String, Object>) inputMap.get("payload");
   Map<String, Object> user = (Map<String, Object>) payload.get("user");
   String rid = (String) data.get("@rid");
   String host = (String) data.get("host");
   String error = null;
   String userHost = (String) user.get("host");
   if (userHost != null && !userHost.equals(host)) {
     error = "You can only delete page from host: " + host;
     inputMap.put("responseCode", 403);
   } else {
     OrientGraph graph = ServiceLocator.getInstance().getGraph();
     try {
       Vertex page = DbService.getVertexByRid(graph, rid);
       if (page != null) {
         int inputVersion = (int) data.get("@version");
         int storedVersion = page.getProperty("@version");
         if (inputVersion != storedVersion) {
           inputMap.put("responseCode", 400);
           error =
               "Deleting version "
                   + inputVersion
                   + " doesn't match stored version "
                   + storedVersion;
         } else {
           Map eventMap = getEventMap(inputMap);
           Map<String, Object> eventData = (Map<String, Object>) eventMap.get("data");
           inputMap.put("eventMap", eventMap);
           eventData.put("pageId", page.getProperty("pageId"));
         }
       } else {
         error = "Page with @rid " + rid + " doesn't exist";
         inputMap.put("responseCode", 400);
       }
     } catch (Exception e) {
       logger.error("Exception:", e);
       throw e;
     } finally {
       graph.shutdown();
     }
   }
   if (error != null) {
     inputMap.put("result", error);
     return false;
   } else {
     return true;
   }
 }