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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca327da8846362b8b4d42d7b790a1bbac50229d6
4
- data.tar.gz: b4135ce2daf5695c6343a2cf9b06e60767d2e539
3
+ metadata.gz: 0d660259bcadee0fabcc6f39060167d89080073e
4
+ data.tar.gz: 00915aa948657fac17f4f023ec677e72b7c067c9
5
5
  SHA512:
6
- metadata.gz: 17a9555a666ade062b8f6212b82d6c1e3c09fb1cb1861865deb64a9db5eeb12a9023179fdf36bc53b11516b11fc284c9a59feb022debcdaeb91d69edb0fc1ea6
7
- data.tar.gz: 168c8bfa214b379ded608250ea9bc676c19cc1e3749ec63851bc2b8f08e084e4be179089fa4c9eb80d3ef260a03ea39f67bf2de3d4207a1e602e76afe1a08295
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
- puts "Import results : #{result}"
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
- puts "Import results : #{result}"
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
- puts "skipping object deletion : #{id}"
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
- puts "Could not retrieve attached picture for object #{title} - Error is #{e.message}"
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
@@ -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
- removed.each do |o|
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)
@@ -1,14 +1,23 @@
1
1
  module Apidae
2
2
  class Town < ActiveRecord::Base
3
- def self.import(json_file)
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.each do |town_data|
8
- Town.create!(name: town_data[:nom], postal_code: town_data[:codePostal], insee_code: town_data[:code],
9
- country: 'fr', apidae_id: town_data[:id])
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
- result
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
@@ -0,0 +1,5 @@
1
+ class AddAttachmentsDataToApidaeObjects < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :apidae_objects, :attachments_data, :jsonb
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ class CreateApidaeReferences < ActiveRecord::Migration[5.1]
2
+ def change
3
+ create_table :apidae_references do |t|
4
+ t.integer :apidae_id
5
+ t.string :apidae_type
6
+ t.jsonb :label_data
7
+ t.index :apidae_id, unique: true
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module Apidae
2
- VERSION = "0.2.8"
2
+ VERSION = "0.2.9"
3
3
  end
@@ -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: 20180222105302) do
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
   (0.1ms) COMMIT
308
308
   (0.2ms) SELECT pg_advisory_unlock(6140174353533887940)
309
309
   (0.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
310
+  (6.6ms) SELECT pg_try_advisory_lock(6140174353533887940)
311
+  (2.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
312
+ Migrating to AddAttachmentsDataToApidaeObjects (20180307164936)
313
+  (0.2ms) BEGIN
314
+  (32.7ms) ALTER TABLE "apidae_objects" ADD "attachments_data" jsonb
315
+ SQL (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20180307164936"]]
316
+  (0.6ms) COMMIT
317
+ ActiveRecord::InternalMetadata Load (1.0ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
318
+  (0.1ms) BEGIN
319
+  (0.1ms) COMMIT
320
+  (0.2ms) SELECT pg_advisory_unlock(6140174353533887940)
321
+  (0.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
322
+  (0.2ms) SELECT pg_try_advisory_lock(6140174353533887940)
323
+  (0.5ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
324
+ Migrating to CreateApidaeReferences (20180307170349)
325
+  (0.1ms) BEGIN
326
+  (17.5ms) CREATE 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)
327
+  (0.8ms) CREATE UNIQUE INDEX "index_apidae_references_on_apidae_id" ON "apidae_references" ("apidae_id")
328
+ SQL (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20180307170349"]]
329
+  (1.2ms) COMMIT
330
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
331
+  (0.1ms) BEGIN
332
+  (0.1ms) COMMIT
333
+  (0.2ms) SELECT pg_advisory_unlock(6140174353533887940)
334
+  (0.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
@@ -0,0 +1,11 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ one:
4
+ apidae_id: 1
5
+ apidae_type: MyString
6
+ label_data:
7
+
8
+ two:
9
+ apidae_id: 1
10
+ apidae_type: MyString
11
+ label_data:
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ module Apidae
4
+ class ReferenceTest < ActiveSupport::TestCase
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ end
9
+ end
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.8
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-06 00:00:00.000000000 Z
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