Skip to content

Commit

Permalink
CMR-5500: Make Parinfer happy.
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-durbin committed Feb 9, 2019
1 parent c218711 commit 7218589
Show file tree
Hide file tree
Showing 87 changed files with 1,086 additions and 1,117 deletions.
51 changes: 25 additions & 26 deletions access-control-app/src/cmr/access_control/services/acl_service.clj
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
(ns cmr.access-control.services.acl-service
(:require
[clojure.edn :as edn]
[clojure.set :as set]
[clojure.string :as str]
[cmr.access-control.data.access-control-index :as index]
[cmr.access-control.data.acl-json-results-handler :as result-handler]
[cmr.access-control.data.acl-schema :as schema]
[cmr.access-control.services.acl-authorization :as acl-auth]
[cmr.access-control.services.acl-service-messages :as acl-msg]
[cmr.access-control.services.acl-util :as acl-util]
[cmr.access-control.services.acl-validation :as v]
[cmr.access-control.services.auth-util :as auth-util]
[cmr.access-control.services.messages :as msg]
[cmr.access-control.services.parameter-validation :as pv]
[cmr.acl.core :as acl]
[cmr.common-app.api.enabled :as common-enabled]
[cmr.common-app.services.search.params :as cp]
[cmr.common.concepts :as concepts]
[cmr.common.log :refer [info debug]]
[cmr.common.services.errors :as errors]
[cmr.common.util :as util]
[cmr.transmit.echo.tokens :as tokens]
[cmr.transmit.metadata-db :as mdb1]
[cmr.transmit.metadata-db2 :as mdb]
[cmr.umm-spec.acl-matchers :as acl-matchers]))

[clojure.edn :as edn]
[clojure.set :as set]
[clojure.string :as str]
[cmr.access-control.data.access-control-index :as index]
[cmr.access-control.data.acl-json-results-handler :as result-handler]
[cmr.access-control.data.acl-schema :as schema]
[cmr.access-control.services.acl-authorization :as acl-auth]
[cmr.access-control.services.acl-service-messages :as acl-msg]
[cmr.access-control.services.acl-util :as acl-util]
[cmr.access-control.services.acl-validation :as v]
[cmr.access-control.services.auth-util :as auth-util]
[cmr.access-control.services.messages :as msg]
[cmr.access-control.services.parameter-validation :as pv]
[cmr.acl.core :as acl]
[cmr.common-app.api.enabled :as common-enabled]
[cmr.common-app.services.search.params :as cp]
[cmr.common.concepts :as concepts]
[cmr.common.log :refer [info debug]]
[cmr.common.services.errors :as errors]
[cmr.common.util :as util]
[cmr.transmit.echo.tokens :as tokens]
[cmr.transmit.metadata-db :as mdb1]
[cmr.transmit.metadata-db2 :as mdb]
[cmr.umm-spec.acl-matchers :as acl-matchers]))

(defn- context->user-id
"Returns user id of the token in the context. Throws an error if no token is provided"
Expand Down Expand Up @@ -74,7 +73,7 @@
(errors/throw-service-error
:invalid-data
(msg/invalid-revision-id revision-id)))
concept))
concept))

(defn update-acl
"Update the ACL with the given concept-id and revision-id in Metadata DB.
Expand Down
4 changes: 2 additions & 2 deletions access-control-app/src/cmr/access_control/site/routes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"Defines the HTTP URL routes for the access-control web site."
(:require
[cmr.access-control.site.pages :as pages]
[cmr.common-app.static :as static]
[cmr.common-app.site.data :as common-data]
[cmr.common-app.site.pages :as common-pages]
[cmr.common-app.static :as static]
[cmr.transmit.config :as config]
[compojure.core :refer [GET context routes]]
[ring.util.response :refer [redirect]]))
Expand Down Expand Up @@ -34,7 +34,7 @@
(redirect
(str (config/application-public-root-url ctx)
"site/docs/access-control/api.html")
307))
307))
(GET "/usage"
{ctx :request-context}
(redirect
Expand Down
11 changes: 6 additions & 5 deletions access-control-app/test/cmr/access_control/test/site/routes.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
(ns cmr.access-control.test.site.routes
(:require [clojure.string :as string]
[clojure.test :refer :all]
[cmr.access-control.site.routes :as r]
[ring.mock.request :refer [request]]))
(:require
[clojure.string :as string]
[clojure.test :refer :all]
[cmr.access-control.site.routes :as r]
[ring.mock.request :refer [request]]))

(def ^:private scheme "https")
(def ^:private host "cmr.example.com")
Expand All @@ -18,7 +19,7 @@
(testing "visited on a path without a trailing slash"
(let [response (site (request :get base-url))]
(testing "produces a HTTP 200 success response"
(is (= 200 (:status response) )))
(is (= 200 (:status response))))
(testing "returns the welcome page HTML"
(is (string/includes?
(:body response)
Expand Down
3 changes: 1 addition & 2 deletions bootstrap-app/src/cmr/bootstrap/data/bulk_migration.clj
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,4 @@
(get-provider-collection-list-sql "FIX_PROV1")
(copy-granule-data-for-provider (oc/create-db (mdb-config/db-spec)) "FIX_PROV1")
(delete-collection-granules-sql "FIX_PROV1" "C1000000073-FIX_PROV1")
(mu/full-metadata-db-concept-table "FIX_PROV1" :collection)
)
(mu/full-metadata-db-concept-table "FIX_PROV1" :collection))
13 changes: 7 additions & 6 deletions bootstrap-app/src/cmr/bootstrap/runner.clj
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
(ns cmr.bootstrap.runner
"Entry point for the application. Defines a main method that accepts arguments."
(:require [cmr.bootstrap.system :as system]
[clojure.string :as string]
[cmr.common.log :refer (debug info warn error)]
[cmr.common.api.web-server :as web]
[cmr.bootstrap.api.routes :as routes]
[cmr.common.config :as cfg])
(:require
[clojure.string :as string]
[cmr.bootstrap.api.routes :as routes]
[cmr.bootstrap.system :as system]
[cmr.common.api.web-server :as web]
[cmr.common.config :as cfg]
[cmr.common.log :refer (debug info warn error)])
(:gen-class))

(defn -main
Expand Down
3 changes: 1 addition & 2 deletions bootstrap-app/src/cmr/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,4 @@
;; integration tests
(let [db (oracle-config/sys-dba-db-spec)]
(o/create-user db "DEV_52_CATALOG_REST" "DEV_52_CATALOG_REST")
(o/grant-select-privileges db "DEV_52_CATALOG_REST" "METADATA_DB"))
)
(o/grant-select-privileges db "DEV_52_CATALOG_REST" "METADATA_DB")))
8 changes: 4 additions & 4 deletions common-lib/src/cmr/common/api/context.clj
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
"Returns user id of the token in the context. Throws an error if no token is
provided."
([context]
(context->user-id context "Valid user token required."))
(context->user-id context "Valid user token required."))
([context msg]
(if-let [token (:token context)]
(util/lazy-get context :user-id)
(errors/throw-service-error :unauthorized msg))))
(if-let [token (:token context)]
(util/lazy-get context :user-id)
(errors/throw-service-error :unauthorized msg))))
17 changes: 8 additions & 9 deletions common-lib/src/cmr/common/cache/fallback_cache_spec.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
(ns cmr.common.cache.fallback-cache-spec
"Defines a common set of tests for a fallback cache."
(:require [clojure.test :refer :all]
[cmr.common.cache :as c]
[cmr.common.cache.spec-util :as su]))
(:require
[clojure.test :refer :all]
[cmr.common.cache :as c]
[cmr.common.cache.spec-util :as su]))

(defn- basic-fallback-test
"Tests the fallback cache works as expected with regards to the primary and backup store."
Expand Down Expand Up @@ -86,14 +87,14 @@
(testing "Lookup function is used if value is not in either cache"
(is (= "lookup function value" (c/get-value fallback-cache :alpha lookup-fn))))

(testing "Value added by lookup function is in primary cache"
(is (= "lookup function value" (c/get-value primary-cache :alpha))))
(testing "Value added by lookup function is in primary cache"
(is (= "lookup function value" (c/get-value primary-cache :alpha))))

(testing "Value added by lookup function is in backup cache"
(is (= "lookup function value" (c/get-value backup-cache :alpha)))))

(testing "Get keys returns all of the keys"
(su/assert-cache-keys [:foo :bar :alpha] fallback-cache true)))
(testing "Get keys returns all of the keys"
(su/assert-cache-keys [:foo :bar :alpha] fallback-cache true)))

(def ^:private cache-test-fns
"Defines the set of test functions that check a cache implementation"
Expand All @@ -110,5 +111,3 @@
(c/reset fallback-cache)
(testing (:name (meta test-fn-var))
((var-get test-fn-var) fallback-cache primary-cache backup-cache))))


9 changes: 4 additions & 5 deletions common-lib/src/cmr/common/dev/repeat_last_request.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
[]
(let [system (var-get (find-var 'user/system))
routes-fn (get-in system [:web :routes-fn])]
(if @last-request-atom
(let [api-fn (routes-fn system)]
(api-fn @last-request-atom))
(println "No last request captured to repeat"))))

(if @last-request-atom
(let [api-fn (routes-fn system)]
(api-fn @last-request-atom))
(println "No last request captured to repeat"))))
32 changes: 17 additions & 15 deletions common-lib/src/cmr/common/jobs.clj
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
(ns cmr.common.jobs
"Defines a job scheduler that wraps quartz for defining a job."
(:require [cmr.common.log :as log :refer (debug info warn error)]
[cmr.common.lifecycle :as l]
[cmr.common.services.errors :as errors]
[clj-time.core :as t]
[cmr.common.config :as config :refer [defconfig]]
;; quartzite dependencies
[clojurewerkz.quartzite.scheduler :as qs]
[clojurewerkz.quartzite.triggers :as qt]
[clojurewerkz.quartzite.jobs :as qj]
[clojurewerkz.quartzite.stateful :as qst]
[clojurewerkz.quartzite.schedule.calendar-interval :as qcal]
[clojurewerkz.quartzite.schedule.cron :as qcron]
[clojurewerkz.quartzite.conversion :as qc])
(:import org.quartz.impl.StdScheduler))
(:require
[clj-time.core :as t]
[cmr.common.config :as config :refer [defconfig]]
[cmr.common.lifecycle :as l]
[cmr.common.log :as log :refer (debug info warn error)]
[cmr.common.services.errors :as errors]
;; quartzite dependencies
[clojurewerkz.quartzite.conversion :as qc]
[clojurewerkz.quartzite.jobs :as qj]
[clojurewerkz.quartzite.schedule.calendar-interval :as qcal]
[clojurewerkz.quartzite.schedule.cron :as qcron]
[clojurewerkz.quartzite.scheduler :as qs]
[clojurewerkz.quartzite.stateful :as qst]
[clojurewerkz.quartzite.triggers :as qt])
(:import
(org.quartz.impl StdScheduler)))

(defn defjob*
"The function that does the bulk of the work for the def job macros."
Expand Down Expand Up @@ -255,7 +257,7 @@
(assoc this
:running? true
:qz-scheduler scheduler)))
(errors/internal-error! "No jobs to schedule.")))
(errors/internal-error! "No jobs to schedule.")))

(stop
[this system]
Expand Down
9 changes: 5 additions & 4 deletions common-lib/src/cmr/common/regex_builder.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
"Provides functions for programmatically building a regular expression. All of the regular
expression functions work by joining strings together. Call compile-regex to create the final
regular expression"
(:require [clojure.string :as str]))
(:require
[clojure.string :as str]))

(defn group
"Groups together items in a sequence."
[& parts]
(if (= (count parts) 1)
(first parts)
(str "(?:" (str/join "" parts) ")" )))
(str "(?:" (str/join "" parts) ")")))

(defn capture
"Groups together items in a sequence that will be captured"
[& parts]
(if (= (count parts) 1)
(str "(" (first parts) ")")
(str "(" (str/join "" parts) ")" )))
(str "(" (str/join "" parts) ")")))

(defn- build-postfix-op
"Helper for building a postfix operation that can also group items"
Expand Down Expand Up @@ -67,4 +68,4 @@
(let [sign "[+\\-]"]
(group (optional sign)
(one-or-more digit)
(optional "\\." (one-or-more digit)))))
(optional "\\." (one-or-more digit)))))
12 changes: 6 additions & 6 deletions common-lib/src/cmr/common/test/runners/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@
of all namepsace objects whose namepsace names beginn with 'cmr' will be
used instead."
([]
(get-all-tests (-all-cmr-namespaces)))
(get-all-tests (-all-cmr-namespaces)))
([nss]
(->> nss
(map #(vals (ns-interns %)))
(flatten)
(map #(-> % meta :test))
(remove nil?))))
(->> nss
(map #(vals (ns-interns %)))
(flatten)
(map #(-> % meta :test))
(remove nil?))))
24 changes: 12 additions & 12 deletions common-lib/src/cmr/common/validations/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
value. It returns either nil or a map of field paths to a list of errors.
Maps and lists will automatically be converted into record-validation or
seq-of-validations."
(:require
(:require
[camel-snake-kebab.core :as csk]
[clojure.string :as str]
[cmr.common.date-time-parser :as date-time-parser]
Expand Down Expand Up @@ -71,21 +71,21 @@
(defn validate
"Returns a map of fields to error messages."
([validation value]
(validate validation [] value))
(validate validation [] value))
([validation key-path value]
(cond
(sequential? validation)
(reduce
(fn [error-map v]
(merge-with concat error-map (validate v key-path value)))
{}
validation)
(reduce
(fn [error-map v]
(merge-with concat error-map (validate v key-path value)))
{}
validation)
(map? validation)
(reduce
(fn [error-map [k v]]
(merge error-map (validate v (conj key-path k) (get value k))))
{}
validation)
(reduce
(fn [error-map [k v]]
(merge error-map (validate v (conj key-path k) (get value k))))
{}
validation)
(fn? validation) (validation key-path value))))

(defn validate!
Expand Down
12 changes: 6 additions & 6 deletions common-lib/src/cmr/common/xml/simple_xpath.clj
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,9 @@
(try
(let [source-elements (cond
(= source :from-root)
[(:root xpath-context)]
[(:root xpath-context)]
(= source :from-context)
(:context xpath-context)
(:context xpath-context)
:else
(throw
(Exception.
Expand Down Expand Up @@ -565,13 +565,13 @@
[context-or-node]
(cond
(string? context-or-node)
context-or-node
context-or-node
(xpath-context? context-or-node)
(str/join (map text (:context context-or-node)))
(str/join (map text (:context context-or-node)))
(seq? context-or-node)
(str/join (map text context-or-node))
(str/join (map text context-or-node))
(:content context-or-node)
(str/join (map text (:content context-or-node)))))
(str/join (map text (:content context-or-node)))))

(defn select*
"Returns all elements matching the XPath expression."
Expand Down
5 changes: 2 additions & 3 deletions common-lib/test/cmr/common/test/id_generator.clj
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
(with-curr-times
[5 6]
(is (= {:worker 1 :sequence 255 :time 5}
(id-generator/next-id-state id-state)))
(id-generator/next-id-state id-state)))
(is (= {:worker 1 :sequence 0 :time 6}
(id-generator/next-id-state id-state)))))))

(id-generator/next-id-state id-state)))))))
4 changes: 2 additions & 2 deletions common-lib/test/cmr/common/test/regex_builder.clj
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@
:non-matches ["Abz1" "Abzbz1" "Abbb1"]}

{:regex (group "A" (n-to-m-times 2 3 "b" "z") "1")
:matches ["Abzbz1" "Abzbzbz1" ]
:non-matches ["Abz1" "Abzbzbzbz1" "Abbb1"]}])
:matches ["Abzbz1" "Abzbzbz1"]
:non-matches ["Abz1" "Abzbzbzbz1" "Abbb1"]}])
Loading

0 comments on commit 7218589

Please sign in to comment.