|
164 | 164 | (anti-value? value))) |
165 | 165 |
|
166 | 166 | (defn- parse-collection |
167 | | - "Parses collection into concepts. Returns nil on error." |
168 | | - [context collection] |
169 | | - (try |
170 | | - (cp/parse-concept context collection) |
171 | | - (catch Exception e |
172 | | - (error (format "An error occurred while parsing collection for autocomplete with concept-id [%s]: %s" |
173 | | - (:concept-id collection) |
174 | | - (.getMessage e)))))) |
| 167 | + "Parses collection into concepts. Returns a vector containing: |
| 168 | + 1. A list of successfully parsed collections |
| 169 | + 2. A list of concept IDs that failed to parse" |
| 170 | + [context collections] |
| 171 | + (let [results (map (fn [collection] |
| 172 | + (try |
| 173 | + [(cp/parse-concept context collection) nil] |
| 174 | + (catch Exception e |
| 175 | + (error (format "An error occurred while parsing collection for autocomplete with concept-id [%s]: %s" |
| 176 | + (:concept-id collection) |
| 177 | + (.getMessage e))) |
| 178 | + [nil (:concept-id collection)]))) |
| 179 | + collections) |
| 180 | + parsed-collections (keep first results) |
| 181 | + failed-concept-ids (keep second results)] |
| 182 | + [parsed-collections failed-concept-ids])) |
175 | 183 |
|
176 | 184 | (defn- get-humanized-collections |
177 | 185 | "Get the humanized fields for the passed in parsed-concept and remove the old flat platform |
|
187 | 195 | index (get-in index-names [:autocomplete :autocomplete]) |
188 | 196 | humanized-fields-fn (partial get-humanized-collections context) |
189 | 197 | existing-collections (remove :deleted collections) |
190 | | - parsed-concepts (->> existing-collections |
191 | | - (map #(parse-collection context %)) |
192 | | - (remove nil?)) |
| 198 | + [parsed-concepts failed-concept-ids] (parse-collection context existing-collections) |
| 199 | + valid-collections (remove #(contains? (set failed-concept-ids) (:concept-id %)) existing-collections) |
193 | 200 | collection-permissions (map (fn [collection] |
194 | 201 | (let [permissions (collection-util/get-coll-permitted-group-ids context provider-id collection)] |
195 | 202 | {:id (:concept-id collection) |
196 | 203 | :permissions permissions})) |
197 | | - existing-collections) |
| 204 | + valid-collections) |
198 | 205 | humanized-fields (map humanized-fields-fn parsed-concepts) |
199 | 206 | humanized-fields-with-permissions (map merge collection-permissions humanized-fields)] |
200 | 207 | (->> humanized-fields-with-permissions |
|
0 commit comments