   (:import
    [org.apache.commons.configuration BaseConfiguration]
    [org.janusgraph.core JanusGraphFactory JanusGraph]
-   [org.apache.tinkerpop.gremlin.structure Vertex Edge]
+   [org.janusgraph.core.schema SchemaAction]
+   [org.apache.tinkerpop.gremlin.structure Vertex Edge Direction]
+   [org.apache.tinkerpop.gremlin.process.traversal P Order Traversal]
    [org.apache.tinkerpop.gremlin.tinkergraph.structure TinkerGraph]))
 
 (defn connect-tinkergraph

(defn -main
  [& args]
  (let [graph (connect-graph "config/ophion.clj")]
    (janus-make-index graph {:id String})
    (janus-make-index graph {:gid String})
    (janus-make-index graph {:type String})
    (janus-make-index graph {:label String})
    (janus-make-index graph {:symbol String})
    (janus-make-index graph {:featureId String})
    (janus-make-index graph {:chromosome String :start String :end String})))

    (.setProperty base "storage.cassandra.frame-size-mb" "60")
    (JanusGraphFactory/open base)))

(defn janus-get-property-key
  [manage [key type]]
  (or
   (.getPropertyKey manage)
   (.make
    (.dataType
     (.makePropertyKey manage (name key)) type))))

(defn janus-apply-index
  [manage db-index index]
  (let [db (reduce
            (fn [db-index [k v]]
              (let [property (janus-get-property-key manage k v)]
                (.addKey db-index property)))
            db-index index)]
    (.buildCompositeIndex db)))

(defn property-index-name
  [index]
  (string/join "-" (concat (keys index) ["index"])))

(defn janus-property-index
  [graph index]
  (try
    (let [index-name (property-index-name index)
          manage (.openManagement graph)]
      (janus-apply-index manage (.buildIndex manage (str index-name "-vertex") Vertex) index)
      (janus-apply-index manage (.buildIndex manage (str index-name "-edge") Edge) index)
      (.commit manage))
    (catch Exception e
      (.printStackTrace e))))

(defn edge-index-name
  [edge-label index]
  (string/join "-" (concat [edge-label] (keys index) ["vertex-centric-index"])))

(defn janus-edge-index
  [graph edge-label index]
  (try
    (let [index-name (edge-index-name edge-label index)
          manage (.openManagement graph)
          property-keys (into-array (mapv (partial janus-get-property-key index)))
          edge (.getEdgeLabel manage edge-label)
          index (.buildEdgeIndex manage edge index-name Direction/BOTH Order/incr property-keys)]
      (.commit manage))
    (catch Exception e
      (.printStackTrace e))))

(defn janus-edge-reindex
  [graph edge-label index]
  (try
    (let [index-name (edge-index-name edge-label index)
          manage (.openManagement graph)
          edge (.getEdgeLabel manage edge-label)
          index (.getRelationIndex manage edge index-name)]
      (.updateIndex index SchemaAction/REINDEX)
      (.commit manage))
    (catch Exception e
      (.printStackTrace e))))
