apidae 0.2.8 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/models/apidae/file_import.rb +12 -4
- data/app/models/apidae/object.rb +15 -0
- data/app/models/apidae/reference.rb +24 -0
- data/app/models/apidae/selection.rb +1 -4
- data/app/models/apidae/town.rb +16 -7
- data/db/migrate/20180307164936_add_attachments_data_to_apidae_objects.rb +5 -0
- data/db/migrate/20180307170349_create_apidae_references.rb +12 -0
- data/lib/apidae/version.rb +1 -1
- data/test/dummy/db/schema.rb +11 -1
- data/test/dummy/log/development.log +25 -0
- data/test/fixtures/apidae/references.yml +11 -0
- data/test/models/apidae/reference_test.rb +9 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d660259bcadee0fabcc6f39060167d89080073e
|
4
|
+
data.tar.gz: 00915aa948657fac17f4f023ec677e72b7c067c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b26d1d9e7012f9f1e6c04227b1be4c8fd15b7170562b628149615f78d238fee03429676cce28d1c9a75c2917e935d951f5fcca0a806ae43b7463b5f67481931
|
7
|
+
data.tar.gz: a80d476fe8b5be391448e3f4c033f694f51feb8bfd290bc9dec67c077d333ea2f45ef8042603f38388c204561959055358ed99a3bfc6bfe16a1ef2985ff17760
|
@@ -7,6 +7,8 @@ module Apidae
|
|
7
7
|
STATUS_COMPLETE = 'complete'
|
8
8
|
STATUS_CANCELLED = 'cancelled'
|
9
9
|
|
10
|
+
TOWNS_FILE = 'communes.json'
|
11
|
+
REFERENCES_FILE = 'elements_reference.json'
|
10
12
|
MODIFIED_DIR = 'objets_modifies'
|
11
13
|
DELETED_FILE = 'objets_supprimes.json'
|
12
14
|
SELECTIONS_FILE = 'selections.json'
|
@@ -14,8 +16,13 @@ module Apidae
|
|
14
16
|
def self.import(zip_file)
|
15
17
|
Zip::File.open(zip_file) do |zfile|
|
16
18
|
result = {created: 0, updated: 0, deleted: 0, selections: []}
|
19
|
+
Reference.import(zfile.read(REFERENCES_FILE))
|
20
|
+
logger.info "Completed #{Reference.count} references update"
|
21
|
+
Town.import(zfile.read(TOWNS_FILE))
|
22
|
+
logger.info "Completed #{Town.count} towns update"
|
17
23
|
zfile.each do |file|
|
18
24
|
if file.file? && file.name.end_with?('.json')
|
25
|
+
logger.info "Processing file : #{file.name}"
|
19
26
|
if file.name.include?(MODIFIED_DIR)
|
20
27
|
add_or_update_objects(zfile.read(file.name), result)
|
21
28
|
elsif file.name.include?(DELETED_FILE)
|
@@ -25,7 +32,7 @@ module Apidae
|
|
25
32
|
end
|
26
33
|
end
|
27
34
|
end
|
28
|
-
|
35
|
+
logger.info "Import results : #{result}"
|
29
36
|
result
|
30
37
|
end
|
31
38
|
end
|
@@ -35,7 +42,7 @@ module Apidae
|
|
35
42
|
import_updates(File.join(dir, MODIFIED_DIR), result)
|
36
43
|
import_deletions(File.join(dir, DELETED_FILE), result)
|
37
44
|
import_selections(File.join(dir,SELECTIONS_FILE), result)
|
38
|
-
|
45
|
+
logger.info "Import results : #{result}"
|
39
46
|
result
|
40
47
|
end
|
41
48
|
|
@@ -80,7 +87,7 @@ module Apidae
|
|
80
87
|
obj.destroy!
|
81
88
|
result[:deleted] += 1
|
82
89
|
else
|
83
|
-
|
90
|
+
logger.info "skipping object deletion : #{id}"
|
84
91
|
end
|
85
92
|
end
|
86
93
|
end
|
@@ -116,7 +123,7 @@ module Apidae
|
|
116
123
|
description: pic[:description], credits: pic[:credits])
|
117
124
|
attached.save
|
118
125
|
rescue OpenURI::HTTPError => e
|
119
|
-
|
126
|
+
logger.error "Could not retrieve attached picture for object #{title} - Error is #{e.message}"
|
120
127
|
end
|
121
128
|
end
|
122
129
|
end
|
@@ -133,6 +140,7 @@ module Apidae
|
|
133
140
|
deleted_ids = Apidae::Selection.all.collect {|sel| sel.apidae_id}.uniq - selections_hashes.collect {|sel| sel[:id]}
|
134
141
|
Apidae::Selection.where(apidae_id: deleted_ids).delete_all
|
135
142
|
selections_hashes.each do |selection_data|
|
143
|
+
logger.info "Updating selection #{selection_data[:id]}"
|
136
144
|
Apidae::Selection.add_or_update(selection_data)
|
137
145
|
end
|
138
146
|
result[:selections] = Apidae::Selection.all
|
data/app/models/apidae/object.rb
CHANGED
@@ -7,6 +7,7 @@ module Apidae
|
|
7
7
|
has_many :selections, class_name: 'Apidae::Selection', source: :apidae_selection, through: :apidae_selection_objects
|
8
8
|
|
9
9
|
store_accessor :pictures_data, :pictures
|
10
|
+
store_accessor :attachments_data, :attachments
|
10
11
|
store_accessor :type_data, :categories, :themes, :capacite, :classement, :classementPrefectoral, :labels
|
11
12
|
store_accessor :entity_data, :entity_id, :entity_name
|
12
13
|
store_accessor :contact, :telephone, :email, :website
|
@@ -77,6 +78,7 @@ module Apidae
|
|
77
78
|
apidae_obj.reservation = parse_reservation(object_data[:reservation])
|
78
79
|
apidae_obj.type_data = object_data[type_fields[:node]]
|
79
80
|
apidae_obj.pictures_data = pictures_urls(object_data[:illustrations])
|
81
|
+
apidae_obj.attachments_data = attachments_urls(object_data[:illustrations])
|
80
82
|
apidae_obj.entity_data = entity_fields(object_data[:informations])
|
81
83
|
apidae_obj.service_data = object_data[:prestations]
|
82
84
|
apidae_obj.save!
|
@@ -97,6 +99,19 @@ module Apidae
|
|
97
99
|
{pictures: pics_data}
|
98
100
|
end
|
99
101
|
|
102
|
+
def self.attachments_urls(attachments_array)
|
103
|
+
atts_data = []
|
104
|
+
unless attachments_array.blank?
|
105
|
+
attachments_array.select { |att| att.is_a?(Hash) && !att[:traductionFichiers].blank? }.each do |att|
|
106
|
+
atts_data << {
|
107
|
+
name: node_value(att, :nom),
|
108
|
+
url: att[:traductionFichiers][0][:url]
|
109
|
+
}
|
110
|
+
end
|
111
|
+
end
|
112
|
+
{attachments: atts_data}
|
113
|
+
end
|
114
|
+
|
100
115
|
def self.contact(information_hash)
|
101
116
|
contact_details = {}
|
102
117
|
contact_entries = information_hash[:moyensCommunication].nil? ? [] : information_hash[:moyensCommunication]
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Apidae
|
2
|
+
class Reference < ApplicationRecord
|
3
|
+
def self.import(refs_json)
|
4
|
+
refs_hashes = JSON.parse(refs_json, symbolize_names: true)
|
5
|
+
if refs_hashes.length != count
|
6
|
+
refs_hashes.each do |ref_data|
|
7
|
+
ref = Reference.find_or_initialize_by(apidae_id: ref_data[:id])
|
8
|
+
ref.apidae_type = ref_data[:elementReferenceType]
|
9
|
+
ref.label_data = ref_data.slice(:libelleFr, :libelleEn)
|
10
|
+
ref.save!
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.import_file(json_file)
|
16
|
+
refs_json = File.read(json_file)
|
17
|
+
import(refs_json)
|
18
|
+
end
|
19
|
+
|
20
|
+
def label(language)
|
21
|
+
label_data["libelle#{language.to_s.upcase_first}"]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -28,10 +28,7 @@ module Apidae
|
|
28
28
|
Apidae::SelectionObject.create(apidae_selection_id: apidae_sel.id, apidae_object_id: obj.id)
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
|
-
obj = Apidae::Object.find_by_apidae_id(o)
|
33
|
-
Apidae::SelectionObject.destroy(apidae_selection_id: apidae_sel.id, apidae_object_id: obj.id)
|
34
|
-
end
|
31
|
+
Apidae::SelectionObject.where(apidae_selection_id: apidae_sel.id, apidae_object_id: removed).delete_all
|
35
32
|
end
|
36
33
|
|
37
34
|
def results(where_clause, offset, size)
|
data/app/models/apidae/town.rb
CHANGED
@@ -1,14 +1,23 @@
|
|
1
1
|
module Apidae
|
2
2
|
class Town < ActiveRecord::Base
|
3
|
-
def self.import(
|
4
|
-
result = true
|
5
|
-
towns_json = File.read(json_file)
|
3
|
+
def self.import(towns_json)
|
6
4
|
towns_hashes = JSON.parse(towns_json, symbolize_names: true)
|
7
|
-
towns_hashes.
|
8
|
-
|
9
|
-
|
5
|
+
if towns_hashes.length != count
|
6
|
+
countries = Hash[Reference.where(apidae_type: "Pays").map {|ref| [ref.id, ref.label(:fr)]}]
|
7
|
+
towns_hashes.each do |town_data|
|
8
|
+
town = Town.find_or_initialize_by(apidae_id: town_data[:id])
|
9
|
+
town.name = town_data[:nom]
|
10
|
+
town.postal_code = town_data[:codePostal]
|
11
|
+
town.insee_code = town_data[:code]
|
12
|
+
town.country = countries[town_data[:pays][:id]]
|
13
|
+
town.save!
|
14
|
+
end
|
10
15
|
end
|
11
|
-
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.import_file(json_file)
|
19
|
+
towns_json = File.read(json_file)
|
20
|
+
import(towns_json)
|
12
21
|
end
|
13
22
|
|
14
23
|
def label
|
data/lib/apidae/version.rb
CHANGED
data/test/dummy/db/schema.rb
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
#
|
11
11
|
# It's strongly recommended that you check this file into your version control system.
|
12
12
|
|
13
|
-
ActiveRecord::Schema.define(version:
|
13
|
+
ActiveRecord::Schema.define(version: 20180307170349) do
|
14
14
|
|
15
15
|
# These are extensions that must be enabled in order to support this database
|
16
16
|
enable_extension "plpgsql"
|
@@ -71,6 +71,7 @@ ActiveRecord::Schema.define(version: 20180222105302) do
|
|
71
71
|
t.jsonb "entity_data"
|
72
72
|
t.jsonb "service_data"
|
73
73
|
t.jsonb "rates_data"
|
74
|
+
t.jsonb "attachments_data"
|
74
75
|
end
|
75
76
|
|
76
77
|
create_table "apidae_objects_selections", id: :serial, force: :cascade do |t|
|
@@ -78,6 +79,15 @@ ActiveRecord::Schema.define(version: 20180222105302) do
|
|
78
79
|
t.integer "selection_id"
|
79
80
|
end
|
80
81
|
|
82
|
+
create_table "apidae_references", force: :cascade do |t|
|
83
|
+
t.integer "apidae_id"
|
84
|
+
t.string "apidae_type"
|
85
|
+
t.jsonb "label_data"
|
86
|
+
t.datetime "created_at", null: false
|
87
|
+
t.datetime "updated_at", null: false
|
88
|
+
t.index ["apidae_id"], name: "index_apidae_references_on_apidae_id", unique: true
|
89
|
+
end
|
90
|
+
|
81
91
|
create_table "apidae_selection_objects", force: :cascade do |t|
|
82
92
|
t.integer "apidae_selection_id"
|
83
93
|
t.integer "apidae_object_id"
|
@@ -307,3 +307,28 @@ Migrating to RenameOpeningsToOpeningsData (20180222105302)
|
|
307
307
|
[1m[35m (0.1ms)[0m [1m[35mCOMMIT[0m
|
308
308
|
[1m[35m (0.2ms)[0m [1m[34mSELECT pg_advisory_unlock(6140174353533887940)[0m
|
309
309
|
[1m[35m (0.2ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
310
|
+
[1m[35m (6.6ms)[0m [1m[34mSELECT pg_try_advisory_lock(6140174353533887940)[0m
|
311
|
+
[1m[35m (2.1ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
312
|
+
Migrating to AddAttachmentsDataToApidaeObjects (20180307164936)
|
313
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
314
|
+
[1m[35m (32.7ms)[0m [1m[35mALTER TABLE "apidae_objects" ADD "attachments_data" jsonb[0m
|
315
|
+
[1m[35mSQL (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20180307164936"]]
|
316
|
+
[1m[35m (0.6ms)[0m [1m[35mCOMMIT[0m
|
317
|
+
[1m[36mActiveRecord::InternalMetadata Load (1.0ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
318
|
+
[1m[35m (0.1ms)[0m [1m[35mBEGIN[0m
|
319
|
+
[1m[35m (0.1ms)[0m [1m[35mCOMMIT[0m
|
320
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT pg_advisory_unlock(6140174353533887940)[0m
|
321
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
322
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT pg_try_advisory_lock(6140174353533887940)[0m
|
323
|
+
[1m[35m (0.5ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
324
|
+
Migrating to CreateApidaeReferences (20180307170349)
|
325
|
+
[1m[35m (0.1ms)[0m [1m[35mBEGIN[0m
|
326
|
+
[1m[35m (17.5ms)[0m [1m[35mCREATE TABLE "apidae_references" ("id" bigserial primary key, "apidae_id" integer, "apidae_type" character varying, "label_data" jsonb, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)[0m
|
327
|
+
[1m[35m (0.8ms)[0m [1m[35mCREATE UNIQUE INDEX "index_apidae_references_on_apidae_id" ON "apidae_references" ("apidae_id")[0m
|
328
|
+
[1m[35mSQL (0.3ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20180307170349"]]
|
329
|
+
[1m[35m (1.2ms)[0m [1m[35mCOMMIT[0m
|
330
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.4ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
331
|
+
[1m[35m (0.1ms)[0m [1m[35mBEGIN[0m
|
332
|
+
[1m[35m (0.1ms)[0m [1m[35mCOMMIT[0m
|
333
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT pg_advisory_unlock(6140174353533887940)[0m
|
334
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apidae
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean-Baptiste Vilain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- app/models/apidae/export.rb
|
97
97
|
- app/models/apidae/file_import.rb
|
98
98
|
- app/models/apidae/object.rb
|
99
|
+
- app/models/apidae/reference.rb
|
99
100
|
- app/models/apidae/selection.rb
|
100
101
|
- app/models/apidae/selection_object.rb
|
101
102
|
- app/models/apidae/town.rb
|
@@ -129,6 +130,8 @@ files:
|
|
129
130
|
- db/migrate/20180218231319_add_service_data_to_apidae_objects.rb
|
130
131
|
- db/migrate/20180222104915_add_rates_data_to_apidae_objects.rb
|
131
132
|
- db/migrate/20180222105302_rename_openings_to_openings_data.rb
|
133
|
+
- db/migrate/20180307164936_add_attachments_data_to_apidae_objects.rb
|
134
|
+
- db/migrate/20180307170349_create_apidae_references.rb
|
132
135
|
- lib/apidae.rb
|
133
136
|
- lib/apidae/engine.rb
|
134
137
|
- lib/apidae/version.rb
|
@@ -186,6 +189,7 @@ files:
|
|
186
189
|
- test/fixtures/apidae/attached_files.yml
|
187
190
|
- test/fixtures/apidae/exports.yml
|
188
191
|
- test/fixtures/apidae/objects.yml
|
192
|
+
- test/fixtures/apidae/references.yml
|
189
193
|
- test/fixtures/apidae/selection_objects.yml
|
190
194
|
- test/fixtures/apidae/selections.yml
|
191
195
|
- test/fixtures/apidae/towns.yml
|
@@ -194,6 +198,7 @@ files:
|
|
194
198
|
- test/models/apidae/export_test.rb
|
195
199
|
- test/models/apidae/file_import_test.rb
|
196
200
|
- test/models/apidae/object_test.rb
|
201
|
+
- test/models/apidae/reference_test.rb
|
197
202
|
- test/models/apidae/selection_object_test.rb
|
198
203
|
- test/models/apidae/selection_test.rb
|
199
204
|
- test/models/apidae/town_test.rb
|
@@ -267,10 +272,12 @@ test_files:
|
|
267
272
|
- test/models/apidae/selection_test.rb
|
268
273
|
- test/models/apidae/file_import_test.rb
|
269
274
|
- test/models/apidae/export_test.rb
|
275
|
+
- test/models/apidae/reference_test.rb
|
270
276
|
- test/models/apidae/attached_file_test.rb
|
271
277
|
- test/models/apidae/town_test.rb
|
272
278
|
- test/fixtures/apidae/selection_objects.yml
|
273
279
|
- test/fixtures/apidae/towns.yml
|
280
|
+
- test/fixtures/apidae/references.yml
|
274
281
|
- test/fixtures/apidae/objects.yml
|
275
282
|
- test/fixtures/apidae/selections.yml
|
276
283
|
- test/fixtures/apidae/attached_files.yml
|