com.tinkerpop.blueprints.impls.orient.OrientVertex Java Examples

The following examples show how to use com.tinkerpop.blueprints.impls.orient.OrientVertex. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OrientGraphDatabase.java    From graphdb-benchmarks with Apache License 2.0 6 votes vote down vote up
@Override
public int reInitializeCommunities()
{
    Map<Integer, Integer> initCommunities = new HashMap<Integer, Integer>();
    int communityCounter = 0;
    for (Vertex v : graph.getVertices())
    {
        int communityId = v.getProperty(COMMUNITY);
        if (!initCommunities.containsKey(communityId))
        {
            initCommunities.put(communityId, communityCounter);
            communityCounter++;
        }
        int newCommunityId = initCommunities.get(communityId);
        ((OrientVertex) v).setProperties(COMMUNITY, newCommunityId, NODE_COMMUNITY, newCommunityId);
        ((OrientVertex) v).save();
    }
    return communityCounter;
}
 
Example #2
Source File: AbstractBfnRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void delPostDb(String bfnType, Map<String, Object> data) throws Exception {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try{
        graph.begin();
        OrientVertex post = (OrientVertex)graph.getVertexByKey("Post.entityId", data.get("entityId"));
        if(post != null) {
            // TODO cascade deleting all comments belong to the post.
            // Need to come up a query on that to get the entire tree.
            /*
            // https://github.com/orientechnologies/orientdb/issues/1108
            delete graph...
            */
            // TODO remove tags edge. Do I need to?
            graph.removeVertex(post);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example #3
Source File: OVertexTransformer.java    From orientdb-etl with Apache License 2.0 6 votes vote down vote up
@Override
public Object executeTransform(final Object input) {
  vertexClass = (String) resolve(vertexClass);
  if (vertexClass != null) {
    final OClass cls = pipeline.getGraphDatabase().getVertexType(vertexClass);
    if (cls == null)
      pipeline.getGraphDatabase().createVertexType(vertexClass);
  }

  final OrientVertex v = pipeline.getGraphDatabase().getVertex(input);
  if (v == null)
    return null;

  if (vertexClass != null && !vertexClass.equals(v.getRecord().getClassName()))
    try {
      v.setProperty("@class", vertexClass);
    } catch (ORecordDuplicatedException e) {
      if (skipDuplicates) {
        return null;
      } else {
        throw e;
      }
    }
  return v;
}
 
Example #4
Source File: AbstractProductRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void upVoteProduct(Map<String, Object> data) {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        OrientVertex updateUser = (OrientVertex) graph.getVertexByKey("User.userId", data.remove("updateUserId"));
        OrientVertex product = (OrientVertex) graph.getVertexByKey("Product.entityId", data.get("entityId"));
        if (product != null && updateUser != null) {
            // remove DownVote edge if there is.
            for (Edge edge : updateUser.getEdges(product, Direction.OUT, "DownVote")) {
                if (edge.getVertex(Direction.IN).equals(product)) graph.removeEdge(edge);
            }
            updateUser.addEdge("UpVote", product);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example #5
Source File: AbstractProductRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void downVoteProduct(Map<String, Object> data) {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        OrientVertex updateUser = (OrientVertex) graph.getVertexByKey("User.userId", data.remove("updateUserId"));
        OrientVertex product = (OrientVertex) graph.getVertexByKey("Product.entityId", data.get("entityId"));
        if (product != null && updateUser != null) {
            // remove UpVote edge if there is.
            for (Edge edge : updateUser.getEdges(product, Direction.OUT, "UpVote")) {
                if (edge.getVertex(Direction.IN).equals(product)) graph.removeEdge(edge);
            }
            updateUser.addEdge("DownVote", product);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example #6
Source File: AbstractRoleRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected String getRoleById(String roleId) {
    String json = null;
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        OrientVertex role = (OrientVertex)graph.getVertexByKey("Role.roleId", roleId);
        if(role != null) {
            json = role.getRecord().toJSON();
        }
    } catch (Exception e) {
        logger.error("Exception:", e);
        throw e;
    } finally {
        graph.shutdown();
    }
    return json;
}
 
Example #7
Source File: AbstractRoleRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void addRole(Map<String, Object> data) throws Exception {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        Vertex createUser = graph.getVertexByKey("User.userId", data.remove("createUserId"));
        OrientVertex role = graph.addVertex("class:Role", data);
        createUser.addEdge("Create", role);
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
}
 
Example #8
Source File: AbstractCatalogRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void delProductDb(Map<String, Object> data) throws Exception {
    String className = "Catalog";
    String id = "categoryId";
    String index = className + "." + id;
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try{
        graph.begin();
        OrientVertex product = (OrientVertex)graph.getVertexByKey("Product.entityId", data.get("entityId"));
        if(product != null) {
            // TODO cascade deleting all comments belong to the product.
            // Need to come up a query on that to get the entire tree.
            /*
            // https://github.com/orientechnologies/orientdb/issues/1108
            delete graph...
            */
            graph.removeVertex(product);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example #9
Source File: AbstractPostRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void upVotePost(Map<String, Object> data) {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        OrientVertex updateUser = (OrientVertex) graph.getVertexByKey("User.userId", data.remove("updateUserId"));
        OrientVertex post = (OrientVertex) graph.getVertexByKey("Post.entityId", data.get("entityId"));
        if (post != null && updateUser != null) {
            // remove DownVote edge if there is.
            for (Edge edge : updateUser.getEdges(post, Direction.OUT, "DownVote")) {
                if (edge.getVertex(Direction.IN).equals(post)) graph.removeEdge(edge);
            }
            updateUser.addEdge("UpVote", post);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example #10
Source File: AbstractPostRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void downVotePost(Map<String, Object> data) {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        OrientVertex updateUser = (OrientVertex) graph.getVertexByKey("User.userId", data.remove("updateUserId"));
        OrientVertex post = (OrientVertex) graph.getVertexByKey("Post.entityId", data.get("entityId"));
        if (post != null && updateUser != null) {
            // remove UpVote edge if there is.
            for (Edge edge : updateUser.getEdges(post, Direction.OUT, "UpVote")) {
                if (edge.getVertex(Direction.IN).equals(post)) graph.removeEdge(edge);
            }
            updateUser.addEdge("DownVote", post);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example #11
Source File: AbstractOrderRule.java    From light with Apache License 2.0 6 votes vote down vote up
/**
 * To save the order right before routing to payment gateway
 *
 * @param data
 * @throws Exception
 */
protected void addOrder(Map<String, Object> data) throws Exception {
    logger.entry(data);
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        Vertex user = graph.getVertexByKey("User.userId", data.remove("createUserId"));
        OrientVertex order = graph.addVertex("class:Order", data);
        user.addEdge("Create", order);
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
}
 
Example #12
Source File: AbstractUserRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void upVoteUser(Map<String, Object> data) {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        OrientVertex user = (OrientVertex)graph.getVertexByKey("User.userId", data.get("userId"));
        OrientVertex voteUser = (OrientVertex)graph.getVertexByKey("User.userId", data.get("voteUserId"));
        if(user != null && voteUser != null) {
            for (Edge edge : voteUser.getEdges(user, Direction.OUT, "DownVote")) {
                if(edge.getVertex(Direction.IN).equals(user)) graph.removeEdge(edge);
            }
            voteUser.addEdge("UpVote", user);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
}
 
Example #13
Source File: AbstractUserRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void downVoteUser(Map<String, Object> data) {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        OrientVertex user = (OrientVertex)graph.getVertexByKey("User.userId", data.get("userId"));
        OrientVertex voteUser = (OrientVertex)graph.getVertexByKey("User.userId", data.get("voteUserId"));
        if(user != null && voteUser != null) {
            for (Edge edge : voteUser.getEdges(user, Direction.OUT, "UpVote")) {
                if(edge.getVertex(Direction.IN).equals(user)) graph.removeEdge(edge);
            }
            voteUser.addEdge("DownVote", user);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
}
 
Example #14
Source File: BranchRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void downBranchDb(String branchType, Map<String, Object> data) throws Exception {
    String className = branchType.substring(0, 1).toUpperCase() + branchType.substring(1);
    String index = className + ".categoryId";
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try{
        graph.begin();
        OrientVertex updateUser = (OrientVertex)graph.getVertexByKey("User.userId", data.remove("updateUserId"));
        OrientVertex branch = (OrientVertex)graph.getVertexByKey(index, data.get("categoryId"));
        if(branch != null && updateUser != null) {
            // remove UpVote edge if there is.
            for (Edge edge : updateUser.getEdges(branch, Direction.OUT, "UpVote")) {
                if(edge.getVertex(Direction.IN).equals(branch)) graph.removeEdge(edge);
            }
            updateUser.addEdge("DownVote", branch);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example #15
Source File: BranchRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void upBranchDb(String branchType, Map<String, Object> data) throws Exception {
    String className = branchType.substring(0, 1).toUpperCase() + branchType.substring(1);
    String index = className + ".categoryId";
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try{
        graph.begin();
        OrientVertex updateUser = (OrientVertex)graph.getVertexByKey("User.userId", data.remove("updateUserId"));
        OrientVertex branch = (OrientVertex)graph.getVertexByKey(index, data.get("categoryId"));
        if(branch != null && updateUser != null) {
            // remove DownVote edge if there is.
            for (Edge edge : updateUser.getEdges(branch, Direction.OUT, "DownVote")) {
                if(edge.getVertex(Direction.IN).equals(branch)) graph.removeEdge(edge);
            }
            updateUser.addEdge("UpVote", branch);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example #16
Source File: AbstractPageRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void addPage(Map<String, Object> data) throws Exception {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        Vertex createUser = graph.getVertexByKey("User.userId", data.remove("createUserId"));
        OrientVertex page = graph.addVertex("class:Page", data);
        createUser.addEdge("Create", page);
        graph.commit();
        String json = page.getRecord().toJSON();
        Map<String, Object> pageMap = ServiceLocator.getInstance().getMemoryImage("pageMap");
        ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>)pageMap.get("cache");
        if(cache == null) {
            cache = new ConcurrentLinkedHashMap.Builder<Object, Object>()
                    .maximumWeightedCapacity(1000)
                    .build();
            pageMap.put("cache", cache);
        }
        cache.put(data.get("pageId"), new CacheObject(page.getProperty("@version").toString(), json));
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
}
 
Example #17
Source File: AbstractPageRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected CacheObject getPageById(OrientGraph graph, String pageId) {
    CacheObject co = null;
    Map<String, Object> pageMap = ServiceLocator.getInstance().getMemoryImage("pageMap");
    ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>)pageMap.get("cache");
    if(cache == null) {
        cache = new ConcurrentLinkedHashMap.Builder<Object, Object>()
                .maximumWeightedCapacity(1000)
                .build();
        pageMap.put("cache", cache);
    } else {
        co = (CacheObject)cache.get(pageId);
    }
    if(co == null) {
        OrientVertex page = (OrientVertex)graph.getVertexByKey("Page.pageId", pageId);
        if(page != null) {
            String json = page.getRecord().toJSON();
            co = new CacheObject(page.getProperty("@version").toString(), json);
            cache.put(pageId, co);
        }
    }
    return co;
}
 
Example #18
Source File: AbstractMenuRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected String getMenu(OrientGraph graph, String host) {
    String json = null;
    Map<String, Object> menuMap = (Map<String, Object>)ServiceLocator.getInstance().getMemoryImage("menuMap");
    ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>)menuMap.get("cache");
    if(cache != null) {
        json = (String)cache.get(host);
    }
    if(json == null) {
        Vertex menu = graph.getVertexByKey("Menu.host", host);
        if(menu != null) {
            json = ((OrientVertex)menu).getRecord().toJSON("rid,fetchPlan:[*]in_Create:-2 [*]out_Create:-2 [*]in_Update:-2 [*]out_Update:-2 [*]in_Own:-2 [*]out_Own:4");
        }
        if(json != null) {
            if(cache == null) {
                cache = new ConcurrentLinkedHashMap.Builder<Object, Object>()
                        .maximumWeightedCapacity(1000)
                        .build();
                menuMap.put("cache", cache);
            }
            cache.put(host, json);
        }
    }
    return json;
}
 
Example #19
Source File: AbstractMenuRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void addMenuItem(Map<String, Object> data) throws Exception {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        Vertex user = graph.getVertexByKey("User.userId", data.remove("createUserId"));
        List<String> addMenuItems = (List<String>)data.remove("addMenuItems");
        OrientVertex menuItem = graph.addVertex("class:MenuItem", data);
        if(addMenuItems != null && addMenuItems.size() > 0) {
            // find vertex for each menuItem id and create edge to it.
            for(String menuItemId: addMenuItems) {
                Vertex childMenuItem = graph.getVertexByKey("MenuItem.menuItemId", menuItemId);
                menuItem.addEdge("Own", childMenuItem);
            }
        }
        user.addEdge("Create", menuItem);
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
}
 
Example #20
Source File: AbstractConfigRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void delHostConfigDb(Map<String, Object> data) throws Exception {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try{
        graph.begin();
        OrientVertex config = getConfigByHostId(graph, (String)data.get("host"), (String)data.get("configId"));
        if(config != null) {
            graph.removeVertex(config);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example #21
Source File: AbstractRule.java    From light with Apache License 2.0 6 votes vote down vote up
public Map<String, Object> getAccessByRuleClass(OrientGraph graph, String ruleClass) throws Exception {
    Map<String, Object> access = null;
    Map<String, Object> accessMap = ServiceLocator.getInstance().getMemoryImage("accessMap");
    ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>)accessMap.get("cache");
    if(cache == null) {
        cache = new ConcurrentLinkedHashMap.Builder<Object, Object>()
                .maximumWeightedCapacity(1000)
                .build();
        accessMap.put("cache", cache);
    } else {
        access = (Map<String, Object>)cache.get(ruleClass);
    }
    if(access == null) {
        OrientVertex accessVertex = (OrientVertex)graph.getVertexByKey("Access.ruleClass", ruleClass);
        if(accessVertex != null) {
            String json = accessVertex.getRecord().toJSON();
            access = mapper.readValue(json,
                    new TypeReference<HashMap<String, Object>>() {
                    });
            cache.put(ruleClass, access);
        }
    }
    return access;
}
 
Example #22
Source File: AbstractCommentRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void updComment(Map<String, Object> data) throws Exception {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try{
        graph.begin();
        String commentId = (String)data.get("commentId");
        OrientVertex comment = (OrientVertex)graph.getVertexByKey("Comment.commentId", commentId);
        if(comment != null) {
            comment.setProperty("content", data.get("content"));
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example #23
Source File: AbstractCommentRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void delComment(Map<String, Object> data) throws Exception {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try{
        graph.begin();
        String commentId = (String)data.get("commentId");
        OrientVertex comment = (OrientVertex)graph.getVertexByKey("Comment.commentId", commentId);
        // remove the edge to this comment
        for (Edge edge : comment.getEdges(Direction.IN)) {
            graph.removeEdge(edge);
        }
        graph.removeVertex(comment);
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example #24
Source File: AbstractCommentRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void addComment(Map<String, Object> data) throws Exception {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try{
        graph.begin();
        Vertex createUser = graph.getVertexByKey("User.userId", data.remove("createUserId"));
        String parentId = (String)data.remove("parentId");
        String parentClassName = (String)data.remove("parentClassName");
        Vertex parent = null;
        if("Post".equals(parentClassName)) {
            parent = graph.getVertexByKey("Post.entityId", parentId);
        } else {
            parent = graph.getVertexByKey("Comment.commentId", parentId);
        }
        OrientVertex comment = graph.addVertex("class:Comment", data);
        createUser.addEdge("Create", comment);
        parent.addEdge("HasComment", comment);
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }

}
 
Example #25
Source File: OETLProcessor.java    From orientdb-etl with Apache License 2.0 6 votes vote down vote up
protected Class getClassByName(final OETLComponent iComponent, final String iClassName) {
  final Class inClass;
  if (iClassName.equals("ODocument"))
    inClass = ODocument.class;
  else if (iClassName.equals("String"))
    inClass = String.class;
  else if (iClassName.equals("Object"))
    inClass = Object.class;
  else if (iClassName.equals("OrientVertex"))
    inClass = OrientVertex.class;
  else if (iClassName.equals("OrientEdge"))
    inClass = OrientEdge.class;
  else
    try {
      inClass = Class.forName(iClassName);
    } catch (ClassNotFoundException e) {
      throw new OConfigurationException("Class '" + iClassName + "' declared as 'input' of ETL Component '"
          + iComponent.getName() + "' was not found.");
    }
  return inClass;
}
 
Example #26
Source File: BranchRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void delBranchDb(String branchType, Map<String, Object> data) throws Exception {
    String className = branchType.substring(0, 1).toUpperCase() + branchType.substring(1);
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try{
        graph.begin();
        OrientVertex branch = getBranchByHostId(graph, branchType, (String)data.get("host"), (String)data.get("categoryId"));
        if(branch != null) {
            graph.removeVertex(branch);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example #27
Source File: AbstractConfigRule.java    From light with Apache License 2.0 5 votes vote down vote up
public OrientVertex getConfigByHostId(OrientGraph graph, String host, String configId) {
    OrientVertex config = null;
    OIndex<?> hostIdIdx = graph.getRawGraph().getMetadata().getIndexManager().getIndex("configHostIdIdx");
    OCompositeKey key = new OCompositeKey(host, configId);
    OIdentifiable oid = (OIdentifiable) hostIdIdx.get(key);
    if (oid != null) {
        config = graph.getVertex(oid.getRecord());
    }
    return config;
}
 
Example #28
Source File: AbstractConfigRule.java    From light with Apache License 2.0 5 votes vote down vote up
protected void addHostConfigDb(Map<String, Object> data) throws Exception {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try{
        graph.begin();
        Vertex createUser = graph.getVertexByKey("User.userId", data.remove("createUserId"));
        OrientVertex hostConfig = graph.addVertex("class:HostConfig", data);
        createUser.addEdge("Create", hostConfig);
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example #29
Source File: UpCommentRule.java    From light with Apache License 2.0 5 votes vote down vote up
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> user = (Map<String, Object>) inputMap.get("user");
    String rid = (String)data.get("@rid");
    String entityRid = (String)data.get("entityRid");
    String error = null;
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        // check if the comment exists
        OrientVertex comment = (OrientVertex) DbService.getVertexByRid(graph, rid);
        if(comment == null ) {
            error = "Comment @rid " + rid + " cannot be found";
            inputMap.put("responseCode", 404);
        } else {
            Map eventMap = getEventMap(inputMap);
            Map<String, Object> eventData = (Map<String, Object>)eventMap.get("data");
            inputMap.put("eventMap", eventMap);
            eventData.put("commentId", comment.getProperty("commentId"));
            eventData.put("userId", user.get("userId"));
            clearCommentCache(entityRid);
        }
    } catch (Exception e) {
        logger.error("Exception:", e);
        throw e;
    } finally {
        graph.shutdown();
    }
    if(error != null) {
        inputMap.put("result", error);
        return false;
    } else {
        return true;
    }
}
 
Example #30
Source File: AbstractConfigRule.java    From light with Apache License 2.0 5 votes vote down vote up
protected void updHostConfigDb(Map<String, Object> data) throws Exception {
    String host = (String)data.get("host");
    String configId = (String)data.get("configId");
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try{
        graph.begin();
        Vertex updateUser = graph.getVertexByKey("User.userId", data.remove("updateUserId"));
        OrientVertex config = getConfigByHostId(graph, host, configId);
        if(config != null) {
            if(data.get("description") != null) {
                config.setProperty("description", data.get("description"));
            } else {
                config.removeProperty("description");
            }
            if(data.get("properties") != null) {
                config.setProperty("properties", data.get("properties"));
            } else {
                config.removeProperty("properties");
            }
            config.setProperty("updateDate", data.get("updateDate"));
            // updateUser
            updateUser.addEdge("Update", config);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}