<commit_before>(ns oc.storage.util.import
  "
  Commandline client to import data into OpenCompany.

  Usage:

  lein run -m oc.storage.util.import -- -d ./opt/samples/buff.edn

  lein run -m oc.storage.util.import -- -d ./opt/samples/
  "
  (:require [clojure.string :as s]
            [clojure.tools.cli :refer (parse-opts)]
            [clojure.walk :refer (keywordize-keys)]
            [oc.lib.db.pool :as db]
            [oc.lib.db.common :as db-common]
            [oc.storage.resources.org :as org]
            [oc.storage.resources.board :as board]
            [oc.storage.resources.entry :as entry]
            [oc.storage.config :as c])
  (:gen-class))

(defn exit [status msg]
  (println msg)
  (System/exit status))

;; ----- Resource import -----

(defn- import-entry [conn org board entry-props author]
  (let [board-uuid (:uuid board)
        timestamp (:created-at entry-props)
        entry-authors (or (:author entry-props) [(assoc (dissoc author :teams) :updated-at timestamp)])
        authors (map #(assoc % :teams [(:team-id org)]) entry-authors)
        entry (entry/->entry conn board-uuid entry-props (first authors))
        fixed-entry (-> entry
                      (assoc :author entry-authors)
                      (assoc :publisher (first entry-authors))
                      (assoc :published-at timestamp)
                      (assoc :status "published"))]
    (println (str "Creating entry at " timestamp " on board '" (:name board) "'"))
    (db-common/create-resource conn entry/table-name fixed-entry timestamp)))

(defn- import-board [conn org board author]
  (println (str "Creating board '" (:name board) "'."))
  (let [empty-board (dissoc board :entries)
        board-props (board/->board (:uuid org) empty-board author)]
    (if-let [new-board (board/create-board! conn board-props)]
      
      ;; Create the entries
      (do
        (println (str "Creating " (count (:entries board)) " entries."))
        (doseq [entry (:entries board)]<commit_msg>Fix import, no :updated-at for publisher.<commit_after>(ns oc.storage.util.import
  "
  Commandline client to import data into OpenCompany.

  Usage:

  lein run -m oc.storage.util.import -- -d ./opt/samples/buff.edn

  lein run -m oc.storage.util.import -- -d ./opt/samples/
  "
  (:require [clojure.string :as s]
            [clojure.tools.cli :refer (parse-opts)]
            [clojure.walk :refer (keywordize-keys)]
            [oc.lib.db.pool :as db]
            [oc.lib.db.common :as db-common]
            [oc.storage.resources.org :as org]
            [oc.storage.resources.board :as board]
            [oc.storage.resources.entry :as entry]
            [oc.storage.config :as c])
  (:gen-class))

(defn exit [status msg]
  (println msg)
  (System/exit status))

;; ----- Resource import -----

(defn- import-entry [conn org board entry-props author]
  (let [board-uuid (:uuid board)
        timestamp (:created-at entry-props)
        entry-authors (or (:author entry-props) [(assoc (dissoc author :teams) :updated-at timestamp)])
        authors (map #(assoc % :teams [(:team-id org)]) entry-authors)
        entry (entry/->entry conn board-uuid entry-props (first authors))
        fixed-entry (-> entry
                      (assoc :author entry-authors)
                      (assoc :publisher (dissoc (first entry-authors) :updated-at))
                      (assoc :published-at timestamp)
                      (assoc :status "published"))]
    (println (str "Creating entry at " timestamp " on board '" (:name board) "'"))
    (db-common/create-resource conn entry/table-name fixed-entry timestamp)))

(defn- import-board [conn org board author]
  (println (str "Creating board '" (:name board) "'."))
  (let [empty-board (dissoc board :entries)
        board-props (board/->board (:uuid org) empty-board author)]
    (if-let [new-board (board/create-board! conn board-props)]
      
      ;; Create the entries
      (do
        (println (str "Creating " (count (:entries board)) " entries."))
        (doseq [entry (:entries board)]
{'fraction_non_alphanumeric': 0.1471241668723772, 'fraction_numerical': 0.0, 'mean_word_length': 2.324036095159967, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2738271', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1215, 'n_words': 350}