apidae 0.9.35 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/app/models/apidae/file_import.rb +6 -16
- data/app/models/apidae/obj.rb +15 -19
- data/app/models/apidae/project.rb +0 -6
- data/app/models/apidae/selection.rb +4 -19
- data/config/initializers/constants.rb +1 -2
- data/config/locales/apidae.fr.yml +0 -1
- data/lib/apidae/version.rb +1 -1
- data/test/dummy/log/development.log +65 -4954
- data/test/models/apidae/file_import_test.rb +0 -23
- metadata +4 -7
- data/test/data/shared_selections.json +0 -15
- data/test/dummy/log/test.log +0 -5845
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1e5d13058f65857b20c5eb5ebcb31933047d458d
|
4
|
+
data.tar.gz: 57c158bf11ea28f28c25094e2e2b732289cd1b47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '039e3d10fa484d795ad731c1a178b567f7c793b2a339ea835370f0a3c59318734ecb5bc9cd818073da9d4c16cdaf03d9d833f83c507d8589f39fe41d56c32657'
|
7
|
+
data.tar.gz: 188194787706a94cf7b04854bdd92266095ee95607b24a764ad2ccadda0fec50f076bb9d0631b7bb3454c02c80c74334bb5f313832d10ac012b86ec4ad3c3e23
|
@@ -30,22 +30,18 @@ module Apidae
|
|
30
30
|
Town.import(zfile.read(TOWNS_FILE))
|
31
31
|
logger.info "Completed #{Town.count} towns update"
|
32
32
|
end
|
33
|
-
|
34
|
-
puts "processing #{file.name}"
|
33
|
+
zfile.each do |file|
|
35
34
|
if file.file? && file.name.end_with?('.json')
|
36
35
|
logger.info "Processing file : #{file.name}"
|
37
36
|
if file.name.include?(MODIFIED_DIR)
|
38
37
|
add_or_update_objects(zfile.read(file.name), result, project.locales, project.versions)
|
39
|
-
|
40
|
-
if file.name.include?(SELECTIONS_FILE)
|
41
|
-
add_or_update_selections(project, zfile.read(file.name), result)
|
42
|
-
end
|
43
|
-
if file.name.include?(DELETED_FILE)
|
38
|
+
elsif file.name.include?(DELETED_FILE)
|
44
39
|
delete_objects(zfile.read(file.name), result)
|
40
|
+
elsif file.name.include?(SELECTIONS_FILE)
|
41
|
+
add_or_update_selections(project, zfile.read(file.name), result)
|
45
42
|
end
|
46
43
|
end
|
47
44
|
end
|
48
|
-
project.cleanup_selections
|
49
45
|
create(result.except(:selections)
|
50
46
|
.merge({remote_file: (zip_file.is_a?(File) ? zip_file.path : zip_file), status: STATUS_COMPLETE, apidae_id: project_id}))
|
51
47
|
logger.info "Import results : #{result}"
|
@@ -108,16 +104,12 @@ module Apidae
|
|
108
104
|
end
|
109
105
|
end
|
110
106
|
|
111
|
-
def self.ordered_files(zfile)
|
112
|
-
zfile.sort_by {|f| f.name.include?(MODIFIED_DIR) ? 0 : (f.name.include?(SELECTIONS_FILE) ? 1 : 2)}
|
113
|
-
end
|
114
|
-
|
115
107
|
def self.delete_objects(deleted_json, result)
|
116
108
|
deleted_ids = JSON.parse(deleted_json)
|
117
109
|
deleted_ids.each do |id|
|
118
110
|
obj = Obj.find_by_apidae_id(id)
|
119
111
|
if obj
|
120
|
-
obj.destroy!
|
112
|
+
obj.destroy!
|
121
113
|
result[:deleted] += 1
|
122
114
|
else
|
123
115
|
logger.info "skipping object deletion : #{id}"
|
@@ -171,9 +163,7 @@ module Apidae
|
|
171
163
|
def self.add_or_update_selections(project, selections_json, result)
|
172
164
|
selections_hashes = JSON.parse(selections_json, symbolize_names: true)
|
173
165
|
deleted_ids = Selection.where(apidae_project_id: project.id).collect {|sel| sel.apidae_id}.uniq - selections_hashes.collect {|sel| sel[:id]}
|
174
|
-
|
175
|
-
SelectionObject.where(apidae_selection_id: apidae_selection_ids).delete_all
|
176
|
-
Selection.where(id: apidae_selection_ids).delete_all
|
166
|
+
Selection.where(apidae_id: deleted_ids).delete_all
|
177
167
|
selections_hashes.each do |selection_data|
|
178
168
|
logger.info "Updating selection #{selection_data[:id]}"
|
179
169
|
Selection.add_or_update(selection_data, project.id)
|
data/app/models/apidae/obj.rb
CHANGED
@@ -14,12 +14,12 @@ module Apidae
|
|
14
14
|
store_accessor :pictures_data, :pictures
|
15
15
|
store_accessor :attachments_data, :attachments
|
16
16
|
store_accessor :type_data, :categories, :themes, :capacity, :classification, :labels, :chains, :area, :track,
|
17
|
-
:products, :audience, :animals, :extra, :duration, :certifications, :business
|
17
|
+
:products, :audience, :animals, :extra, :duration, :certifications, :business
|
18
18
|
store_accessor :entity_data, :entity_id, :entity_name, :service_provider_id
|
19
19
|
store_accessor :contact, :telephone, :email, :website
|
20
20
|
store_accessor :location_data, :address, :place, :latitude, :longitude, :access, :territories, :environments
|
21
|
-
store_accessor :openings_data, :openings_desc, :openings_desc_mode, :openings, :time_periods
|
22
|
-
store_accessor :rates_data, :rates_desc, :rates_desc_mode, :rates, :payment_methods, :includes, :excludes
|
21
|
+
store_accessor :openings_data, :openings_desc, :openings_desc_mode, :openings, :time_periods
|
22
|
+
store_accessor :rates_data, :rates_desc, :rates_desc_mode, :rates, :payment_methods, :includes, :excludes
|
23
23
|
store_accessor :service_data, :services, :equipments, :comfort, :activities, :challenged, :languages
|
24
24
|
store_accessor :booking_data, :booking_desc, :booking_entities
|
25
25
|
store_accessor :tags_data, :promo, :internal, :linked
|
@@ -109,7 +109,11 @@ module Apidae
|
|
109
109
|
end
|
110
110
|
|
111
111
|
def in_version(v)
|
112
|
-
|
112
|
+
@cached_versions ||= {}
|
113
|
+
if @cached_versions[v].nil?
|
114
|
+
@cached_versions[v] = versions.where(version: v).first
|
115
|
+
end
|
116
|
+
@cached_versions[v]
|
113
117
|
end
|
114
118
|
|
115
119
|
def in_locale(l)
|
@@ -293,18 +297,12 @@ module Apidae
|
|
293
297
|
when PHONE
|
294
298
|
contact_details[:telephone] ||= []
|
295
299
|
contact_details[:telephone] << c[:coordonnees][:fr]
|
296
|
-
contact_details[:telephone_details] ||= []
|
297
|
-
contact_details[:telephone_details] << {value: c[:coordonnees][:fr], description: c.dig(:observation, :libelleFr)}
|
298
300
|
when EMAIL
|
299
301
|
contact_details[:email] ||= []
|
300
302
|
contact_details[:email] << c[:coordonnees][:fr]
|
301
|
-
contact_details[:email_details] ||= []
|
302
|
-
contact_details[:email_details] << {value: c[:coordonnees][:fr], description: c.dig(:observation, :libelleFr)}
|
303
303
|
when WEBSITE
|
304
304
|
contact_details[:website] ||= []
|
305
305
|
contact_details[:website] << c[:coordonnees][:fr]
|
306
|
-
contact_details[:website_details] ||= []
|
307
|
-
contact_details[:website_details] << {value: c[:coordonnees][:fr], description: c.dig(:observation, :libelleFr)}
|
308
306
|
else
|
309
307
|
end
|
310
308
|
end
|
@@ -345,14 +343,14 @@ module Apidae
|
|
345
343
|
end
|
346
344
|
end
|
347
345
|
|
346
|
+
# Note : use internal format for openings storage (ideally Apihours one, to merge data from both sources)
|
348
347
|
def self.parse_openings(openings_hash, *locales)
|
349
348
|
if openings_hash && openings_hash[:periodeEnClair]
|
350
349
|
{
|
351
350
|
openings_desc: node_value(openings_hash, :periodeEnClair, *locales),
|
352
351
|
openings_desc_mode: openings_hash[:periodeEnClairGenerationMode] == 'AUTOMATIQUE' ? MODE_AUTO : MODE_MANUAL,
|
353
352
|
openings: openings_hash[:periodesOuvertures],
|
354
|
-
time_periods: lists_ids(openings_hash[:indicationsPeriode])
|
355
|
-
openings_extra: lists_ids(openings_hash[:ouverturesComplementaires])
|
353
|
+
time_periods: lists_ids(openings_hash[:indicationsPeriode])
|
356
354
|
}
|
357
355
|
end
|
358
356
|
end
|
@@ -366,8 +364,7 @@ module Apidae
|
|
366
364
|
rates_desc: desc, rates: values, payment_methods: methods,
|
367
365
|
rates_desc_mode: rates_hash[:tarifsEnClairGenerationMode] == 'AUTOMATIQUE' ? MODE_AUTO : MODE_MANUAL,
|
368
366
|
includes: node_value(rates_hash, :leTarifComprend, *locales),
|
369
|
-
excludes: node_value(rates_hash, :leTarifNeComprendPas, *locales)
|
370
|
-
rates_complement: node_value(rates_hash, :complement, *locales)
|
367
|
+
excludes: node_value(rates_hash, :leTarifNeComprendPas, *locales)
|
371
368
|
}
|
372
369
|
end
|
373
370
|
end
|
@@ -382,7 +379,7 @@ module Apidae
|
|
382
379
|
categories: lists_ids(data_hash[:categories], data_hash[:typesDetailles], data_hash[:activiteCategories]),
|
383
380
|
themes: lists_ids(data_hash[:themes]),
|
384
381
|
capacity: (data_hash[:capacite] || {})
|
385
|
-
.merge(presta_hash ? {group_min:
|
382
|
+
.merge(presta_hash ? {group_min: presta_hash[:tailleGroupeMin], group_max: presta_hash[:tailleGroupeMax],
|
386
383
|
age_min: presta_hash[:ageMin], age_max: presta_hash[:ageMax]} : {}),
|
387
384
|
classification: nodes_ids(data_hash[:classement], data_hash[:classementPrefectoral], data_hash[:classification]) +
|
388
385
|
lists_ids(data_hash[:classementsGuides]) + lists_ids(data_hash[:classements]),
|
@@ -397,8 +394,7 @@ module Apidae
|
|
397
394
|
extra: apidae_obj.apidae_type == SPA ? node_value(data_hash, :formuleHebergement, *locales) : node_value(prestations_hash, :complementAccueil, *locales),
|
398
395
|
duration: apidae_obj.apidae_type == SPA ? {days: data_hash[:nombreJours], nights: data_hash[:nombreNuits]} : data_hash[:dureeSeance],
|
399
396
|
certifications: data_hash[:agrements].blank? ? [] : data_hash[:agrements].map {|a| {id: a[:type][:id], identifier: a[:numero]}},
|
400
|
-
business: business_hash
|
401
|
-
complement: apidae_obj.apidae_type == SPA ? node_value(prestations_hash, :complementAccueil, *locales) : {},
|
397
|
+
business: business_hash
|
402
398
|
}
|
403
399
|
end
|
404
400
|
|
@@ -427,7 +423,7 @@ module Apidae
|
|
427
423
|
end
|
428
424
|
unless linked_data_hash.blank? || linked_data_hash[:liensObjetsTouristiquesTypes].blank?
|
429
425
|
tags[:linked] = linked_data_hash[:liensObjetsTouristiquesTypes]
|
430
|
-
.map {|l| {apidae_id: l[:objetTouristique][:id], apidae_type: l[:objetTouristique][:type], category: l[:type]
|
426
|
+
.map {|l| {apidae_id: l[:objetTouristique][:id], apidae_type: l[:objetTouristique][:type], category: l[:type]}}
|
431
427
|
end
|
432
428
|
tags
|
433
429
|
end
|
@@ -461,7 +457,7 @@ module Apidae
|
|
461
457
|
|
462
458
|
def self.build_rate(rate_period)
|
463
459
|
{
|
464
|
-
id: rate_period[:identifiant],
|
460
|
+
id: rate_period[:identifiant], start_date: rate_period[:dateDebut], end_date: rate_period[:dateFin],
|
465
461
|
values: rate_period[:tarifs].blank? ? [] : rate_period[:tarifs].map {|t| {min: t[:minimum], max: t[:maximum], type: t[:type][:id], details: node_value(t, :precisionTarif)}}
|
466
462
|
}
|
467
463
|
end
|
@@ -42,20 +42,6 @@ module Apidae
|
|
42
42
|
SelectionObject.where(apidae_selection_id: apidae_sel.id, apidae_object_id: removed_ids).delete_all
|
43
43
|
end
|
44
44
|
|
45
|
-
def cleanup
|
46
|
-
obsolete_count = apidae_selection_objects
|
47
|
-
.joins("LEFT JOIN apidae_objs ON apidae_objs.id = apidae_selection_objects.apidae_object_id")
|
48
|
-
.where("apidae_objs.id IS NULL")
|
49
|
-
.delete_all
|
50
|
-
logger.info "Cleaned up #{obsolete_count} obsolete selection-objects associations for selection #{apidae_id}"
|
51
|
-
|
52
|
-
dups = apidae_selection_objects.reload.group(:apidae_object_id)
|
53
|
-
.select("COUNT(id), apidae_object_id, ARRAY_AGG(id) AS so_ids")
|
54
|
-
.having("COUNT(id) > ?", 1).map {|so| so.so_ids}
|
55
|
-
dups_count = apidae_selection_objects.where(id: dups.map {|d| d.sort[1..-1]}.flatten).delete_all
|
56
|
-
logger.info "Cleaned up #{dups_count} duplicate selection-objects associations for selection #{apidae_id}"
|
57
|
-
end
|
58
|
-
|
59
45
|
def results(where_clause, offset, size)
|
60
46
|
objects.includes(:town).limit(size).offset(offset).where(where_clause)
|
61
47
|
end
|
@@ -79,7 +65,7 @@ module Apidae
|
|
79
65
|
key = cache_key(:agenda, from, to)
|
80
66
|
res = $apidae_cache.read(key)
|
81
67
|
unless res
|
82
|
-
query_args = build_args(AGENDA_ENDPOINT, {selection_ids: [apidae_id], from: from, to: to
|
68
|
+
query_args = build_args(AGENDA_ENDPOINT, {selection_ids: [apidae_id], from: from, to: to})
|
83
69
|
res = query_api(query_args, true)
|
84
70
|
$apidae_cache.write(key, res)
|
85
71
|
end
|
@@ -130,7 +116,7 @@ module Apidae
|
|
130
116
|
obj = Obj.update_object(obj, obj_data, apidae_project.locales, apidae_project.versions)
|
131
117
|
else
|
132
118
|
obj = Obj.add_object(obj_data, apidae_project.locales, apidae_project.versions)
|
133
|
-
SelectionObject.create(apidae_selection_id: id, apidae_object_id:
|
119
|
+
SelectionObject.create(apidae_selection_id: id, apidae_object_id: added_obj.id)
|
134
120
|
end
|
135
121
|
if Rails.application.config.respond_to?(:apidae_obj_refresh_callback)
|
136
122
|
Rails.application.config.apidae_obj_refresh_callback.call(obj.apidae_id)
|
@@ -149,15 +135,14 @@ module Apidae
|
|
149
135
|
|
150
136
|
if all_results
|
151
137
|
loops = 0
|
152
|
-
max_loops = only_ids ? 50 : MAX_LOOPS
|
153
138
|
query_args[:first] = 0
|
154
|
-
query_args[:count]
|
139
|
+
query_args[:count] = MAX_COUNT
|
155
140
|
query_args[:locales] ||= apidae_project && !apidae_project.locales.blank? ? apidae_project.locales : [DEFAULT_LOCALE]
|
156
141
|
response = JSON.parse get_response(query_args), symbolize_names: false
|
157
142
|
total = response['numFound']
|
158
143
|
query_result[:results] = (only_ids ? response['objetTouristiqueIds'] : response['objetsTouristiques']) || {}
|
159
144
|
|
160
|
-
while total > results_count(query_result) && loops <
|
145
|
+
while total > results_count(query_result) && loops < MAX_LOOPS
|
161
146
|
loops += 1
|
162
147
|
query_args[:first] += MAX_COUNT
|
163
148
|
response = JSON.parse get_response(query_args), symbolize_names: false
|
@@ -8,10 +8,9 @@ module Apidae
|
|
8
8
|
LOCALE_ZH = 'zh'
|
9
9
|
LOCALE_ES = 'es'
|
10
10
|
LOCALE_PT_BR = 'pt-BR'
|
11
|
-
LOCALE_JP = 'jp'
|
12
11
|
|
13
12
|
DEFAULT_LOCALE = LOCALE_FR
|
14
|
-
ALL_LOCALES = [LOCALE_FR, LOCALE_EN, LOCALE_IT, LOCALE_DE, LOCALE_NL, LOCALE_RU, LOCALE_ZH, LOCALE_ES, LOCALE_PT_BR
|
13
|
+
ALL_LOCALES = [LOCALE_FR, LOCALE_EN, LOCALE_IT, LOCALE_DE, LOCALE_NL, LOCALE_RU, LOCALE_ZH, LOCALE_ES, LOCALE_PT_BR]
|
15
14
|
|
16
15
|
STANDARD_VERSION = 'STANDARD'
|
17
16
|
WINTER_VERSION = 'HIVER'
|
data/lib/apidae/version.rb
CHANGED