apidae 1.2.27 → 1.3.0
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 +5 -5
- data/app/controllers/apidae/import_controller.rb +2 -40
- data/app/helpers/apidae/application_helper.rb +1 -1
- data/app/models/apidae/apidae_data_parser.rb +13 -42
- data/app/models/apidae/export.rb +41 -0
- data/app/models/apidae/file_import.rb +6 -15
- data/app/models/apidae/obj.rb +13 -21
- data/app/models/apidae/project.rb +0 -6
- data/app/models/apidae/reference.rb +1 -1
- data/app/models/apidae/selection.rb +0 -16
- data/config/initializers/constants.rb +5 -9
- data/config/locales/apidae.fr.yml +0 -1
- data/lib/apidae/version.rb +1 -1
- data/test/dummy/db/schema.rb +1 -3
- data/test/dummy/log/development.log +67 -24
- data/test/dummy/log/test.log +3398 -0
- data/test/models/apidae/file_import_test.rb +0 -23
- metadata +16 -9
- data/test/data/shared_selections.json +0 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 11f5031e46f8bfa23ce228c242e023c4ebe10e0e
|
|
4
|
+
data.tar.gz: '0083f65ff4cfbd3f53c5a13126ca940c4be696ae'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0a6544dae89ca3cee7525b37433fc6941b5ae76d720f2adce045d3357fd65efca3150885b0cb9da8234a5324218448e57545897865a77896e1bdfe7a462ab31b
|
|
7
|
+
data.tar.gz: 9c51ebdb6c1d9d671499fd60f086a8c43feb94a9c77d06108aa030b73d5bce00ad4fd5b58e0f5467d21a509bcc1594c2c59f6d19e4be2f61a78d76fc04037b3b
|
|
@@ -37,7 +37,7 @@ module Apidae
|
|
|
37
37
|
def run
|
|
38
38
|
success = true
|
|
39
39
|
Export.pending.each do |e|
|
|
40
|
-
success &&= import_data
|
|
40
|
+
success &&= e.import_data
|
|
41
41
|
end
|
|
42
42
|
success ? head(:ok) : head(:internal_server_error)
|
|
43
43
|
end
|
|
@@ -48,7 +48,7 @@ module Apidae
|
|
|
48
48
|
|
|
49
49
|
def create
|
|
50
50
|
@export = Export.new(export_params)
|
|
51
|
-
if @export.save &&
|
|
51
|
+
if @export.save && @export.import_data
|
|
52
52
|
redirect_to apidae.root_url, notice: 'Le fichier a bien été importé.'
|
|
53
53
|
else
|
|
54
54
|
flash.now[:alert] = "Une erreur s'est produite lors de l'import du fichier."
|
|
@@ -61,43 +61,5 @@ module Apidae
|
|
|
61
61
|
def export_params
|
|
62
62
|
params.require(:export).permit(:project_id, :file_url, :status)
|
|
63
63
|
end
|
|
64
|
-
|
|
65
|
-
def import_data(e)
|
|
66
|
-
success = true
|
|
67
|
-
begin
|
|
68
|
-
open(e.file_url) do |f|
|
|
69
|
-
begin
|
|
70
|
-
FileImport.import(f, e.project_id)
|
|
71
|
-
unless e.confirm_url.blank?
|
|
72
|
-
uri = URI(e.confirm_url)
|
|
73
|
-
req = Net::HTTP::Post.new(uri)
|
|
74
|
-
Net::HTTP.start(uri.hostname, uri.port) do |http|
|
|
75
|
-
http.request(req)
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
e.update(status: Export::COMPLETE)
|
|
79
|
-
if Rails.application.config.respond_to?(:apidae_import_callback)
|
|
80
|
-
Rails.application.config.apidae_import_callback.call(e)
|
|
81
|
-
end
|
|
82
|
-
rescue Exception => ex
|
|
83
|
-
logger.error("Failed to import export file : #{e.file_url}")
|
|
84
|
-
logger.error("Error is : #{ex} \n#{ex.backtrace.join("\n") unless ex.backtrace.blank?}")
|
|
85
|
-
success = false
|
|
86
|
-
e.update(status: Export::CANCELLED)
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
rescue OpenURI::HTTPError => err
|
|
90
|
-
logger.error("Failed to download export file : #{e.file_url}")
|
|
91
|
-
logger.error("Error is : #{err}")
|
|
92
|
-
success = false
|
|
93
|
-
e.update(status: Export::CANCELLED)
|
|
94
|
-
rescue Exception => e
|
|
95
|
-
logger.error "Failed to import file : #{e.file_url}"
|
|
96
|
-
logger.error("Error is : #{err}")
|
|
97
|
-
success = false
|
|
98
|
-
e.update(status: Export::CANCELLED)
|
|
99
|
-
end
|
|
100
|
-
success
|
|
101
|
-
end
|
|
102
64
|
end
|
|
103
65
|
end
|
|
@@ -44,7 +44,7 @@ module Apidae
|
|
|
44
44
|
'LUNDI' => MONDAY,
|
|
45
45
|
'MARDI' => TUESDAY,
|
|
46
46
|
'MERCREDI' => WEDNESDAY,
|
|
47
|
-
'
|
|
47
|
+
'JEUD' => THURSDAY,
|
|
48
48
|
'VENDREDI' => FRIDAY,
|
|
49
49
|
'SAMEDI' => SATURDAY,
|
|
50
50
|
'DIMANCHE' => SUNDAY
|
|
@@ -113,7 +113,7 @@ module Apidae
|
|
|
113
113
|
short_desc: node_value(data_hash, :descriptifCourt, *locales),
|
|
114
114
|
long_desc: node_value(data_hash, :descriptifDetaille, *locales),
|
|
115
115
|
theme_desc: data_hash[:descriptifsThematises].blank? ? {} : Hash[data_hash[:descriptifsThematises].map {|th| [node_id(th, :theme), node_value(th, :description, *locales)]}],
|
|
116
|
-
private_desc: private_data.blank? ? {} : Hash[private_data.map {|d| [d[:nomTechnique],
|
|
116
|
+
private_desc: private_data.blank? ? {} : Hash[private_data.map {|d| [d[:nomTechnique], node_value(d, :descriptif, *locales)]}]
|
|
117
117
|
}
|
|
118
118
|
end
|
|
119
119
|
end
|
|
@@ -151,7 +151,6 @@ module Apidae
|
|
|
151
151
|
name: localized_value(att, :nom, locale),
|
|
152
152
|
url: att[:traductionFichiers][0][:url].gsub('http:', 'https:'),
|
|
153
153
|
type: att[:type],
|
|
154
|
-
link: att[:link],
|
|
155
154
|
description: localized_value(att, :legende, locale)
|
|
156
155
|
}
|
|
157
156
|
end
|
|
@@ -223,8 +222,6 @@ module Apidae
|
|
|
223
222
|
loc_data[:latitude] = geoloc_details[:geoJson][:coordinates][1]
|
|
224
223
|
loc_data[:longitude] = geoloc_details[:geoJson][:coordinates][0]
|
|
225
224
|
end
|
|
226
|
-
loc_data[:map_reference] = geoloc_details[:reperePlan]
|
|
227
|
-
loc_data[:altitude] = geoloc_details[:altitude] if geoloc_details
|
|
228
225
|
loc_data[:access] = node_value(geoloc_details, :complement) if geoloc_details
|
|
229
226
|
loc_data[:environments] = location_hash[:environnements].map {|e| e[:id]} if location_hash[:environnements]
|
|
230
227
|
end
|
|
@@ -239,7 +236,6 @@ module Apidae
|
|
|
239
236
|
openings_desc: node_value(openings_hash, :periodeEnClair, *locales),
|
|
240
237
|
openings_desc_mode: openings_hash[:periodeEnClairGenerationMode] == 'AUTOMATIQUE' ? MODE_AUTO : MODE_MANUAL,
|
|
241
238
|
openings: build_openings(openings_hash, *locales),
|
|
242
|
-
all_year_long: openings_hash[:ouvertTouteLAnnee] == 'OUVERT_TOUTE_L_ANNEE' ? 'true' : 'false',
|
|
243
239
|
time_periods: lists_ids(openings_hash[:indicationsPeriode]),
|
|
244
240
|
openings_extra: lists_ids(openings_hash[:ouverturesComplementaires])
|
|
245
241
|
}
|
|
@@ -251,10 +247,8 @@ module Apidae
|
|
|
251
247
|
desc = rates_hash[:gratuit] ? {DEFAULT_LOCALE => 'gratuit'} : node_value(rates_hash, :tarifsEnClair, *locales)
|
|
252
248
|
values = rates_hash[:periodes].blank? ? [] : rates_hash[:periodes].map {|p| build_rate(p, *locales)}
|
|
253
249
|
methods = rates_hash[:modesPaiement].blank? ? [] : rates_hash[:modesPaiement].map {|p| p[:id]}
|
|
254
|
-
|
|
255
250
|
{
|
|
256
251
|
rates_desc: desc, rates: values, payment_methods: methods,
|
|
257
|
-
tax_included: rates_hash[:taxeDeSejourIncluse].blank? ? nil : (rates_hash[:taxeDeSejourIncluse] == 'OUI'),
|
|
258
252
|
rates_desc_mode: rates_hash[:tarifsEnClairGenerationMode] == 'AUTOMATIQUE' ? MODE_AUTO : MODE_MANUAL,
|
|
259
253
|
includes: node_value(rates_hash, :leTarifComprend, *locales),
|
|
260
254
|
excludes: node_value(rates_hash, :leTarifNeComprendPas, *locales),
|
|
@@ -270,21 +264,18 @@ module Apidae
|
|
|
270
264
|
apidae_obj.apidae_subtype = node_id(data_hash, :rubrique) if apidae_obj.apidae_type == Obj::EQU
|
|
271
265
|
apidae_obj.apidae_subtype = lists_ids(data_hash[:typesHebergement]).first if apidae_obj.apidae_type == Obj::SPA
|
|
272
266
|
{
|
|
273
|
-
categories: lists_ids(data_hash[:categories], data_hash[:typesDetailles], data_hash[:activiteCategories]
|
|
267
|
+
categories: lists_ids(data_hash[:categories], data_hash[:typesDetailles], data_hash[:activiteCategories]),
|
|
274
268
|
themes: lists_ids(data_hash[:themes]),
|
|
275
269
|
capacity: (data_hash[:capacite] || {})
|
|
276
270
|
.merge(presta_hash ? {group_min: presta_hash[:tailleGroupeMin], group_max: presta_hash[:tailleGroupeMax],
|
|
277
271
|
age_min: presta_hash[:ageMin], age_max: presta_hash[:ageMax]} : {}),
|
|
278
272
|
classification: nodes_ids(data_hash[:classement], data_hash[:classementPrefectoral], data_hash[:classification]) +
|
|
279
273
|
lists_ids(data_hash[:classementsGuides]) + lists_ids(data_hash[:classements]),
|
|
280
|
-
classification_date: data_hash[:dateClassement],
|
|
281
|
-
classification_ref: data_hash[:numeroClassement],
|
|
282
274
|
labels: lists_ids(data_hash[:labels], data_hash[:labelsChartesQualite], prestations_hash[:labelsTourismeHandicap]) +
|
|
283
275
|
(node_id(data_hash, :typeLabel) ? [node_id(data_hash, :typeLabel)] : []),
|
|
284
276
|
chains: lists_ids(data_hash[:chaines]) + nodes_ids(data_hash[:chaineEtLabel]),
|
|
285
277
|
area: apidae_obj.apidae_type == Obj::DOS ? data_hash.except(:classification) : node_value(data_hash, :lieuDePratique),
|
|
286
|
-
track: apidae_obj.apidae_type == Obj::EQU ?
|
|
287
|
-
tricky_sections: apidae_obj.apidae_type == Obj::EQU ? node_value(data_hash[:itineraire], :passagesDelicats, *locales) : nil,
|
|
278
|
+
track: apidae_obj.apidae_type == Obj::EQU ? data_hash[:itineraire] : nil,
|
|
288
279
|
products: lists_ids(data_hash[:typesProduit], data_hash[:aopAocIgps], data_hash[:specialites]),
|
|
289
280
|
audience: lists_ids(prestations_hash[:typesClientele]),
|
|
290
281
|
animals: {allowed: prestations_hash[:animauxAcceptes] == 'ACCEPTES', desc: node_value(prestations_hash, :descriptifAnimauxAcceptes, *locales),
|
|
@@ -292,10 +283,7 @@ module Apidae
|
|
|
292
283
|
extra: apidae_obj.apidae_type == Obj::SPA ? node_value(data_hash, :formuleHebergement, *locales) : node_value(prestations_hash, :complementAccueil, *locales),
|
|
293
284
|
duration: apidae_obj.apidae_type == Obj::SPA ? {days: data_hash[:nombreJours], nights: data_hash[:nombreNuits]} : data_hash[:dureeSeance],
|
|
294
285
|
certifications: data_hash[:agrements].blank? ? [] : data_hash[:agrements].map {|a| {id: a[:type][:id], identifier: a[:numero]}},
|
|
295
|
-
business:
|
|
296
|
-
business_equipments: lists_ids((business_hash || {})[:sallesEquipeesPour], (business_hash || {})[:sallesEquipement],
|
|
297
|
-
(business_hash || {})[:sallesRestauration], (business_hash || {})[:sallesHebergement]),
|
|
298
|
-
business_rooms: (business_hash || {})[:sallesReunion]
|
|
286
|
+
business: business_hash
|
|
299
287
|
}
|
|
300
288
|
end
|
|
301
289
|
|
|
@@ -329,19 +317,13 @@ module Apidae
|
|
|
329
317
|
tags
|
|
330
318
|
end
|
|
331
319
|
|
|
332
|
-
def self.parse_booking(reservation_hash,
|
|
333
|
-
booking_hash = {}
|
|
320
|
+
def self.parse_booking(reservation_hash, *locales)
|
|
334
321
|
if reservation_hash
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
booking_hash[:visits_allowed] = visits_hash[:visitable] == true
|
|
340
|
-
booking_hash[:visits_desc] = node_value(visits_hash, :complementVisite, *locales)
|
|
341
|
-
booking_hash[:visits_duration] = visits_hash[:dureeMoyenneVisiteIndividuelle]
|
|
342
|
-
booking_hash[:visits_services] = lists_ids(visits_hash[:prestationsVisitesGroupees]) + lists_ids(visits_hash[:prestationsVisitesIndividuelles])
|
|
322
|
+
{
|
|
323
|
+
booking_desc: node_value(reservation_hash, :complement, *locales),
|
|
324
|
+
booking_entities: reservation_hash[:organismes]
|
|
325
|
+
}
|
|
343
326
|
end
|
|
344
|
-
booking_hash
|
|
345
327
|
end
|
|
346
328
|
|
|
347
329
|
def self.parse_town(location_hash)
|
|
@@ -353,21 +335,10 @@ module Apidae
|
|
|
353
335
|
end
|
|
354
336
|
end
|
|
355
337
|
|
|
356
|
-
def self.parse_entity_fields(information_hash, type_data_hash
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
if information_hash[:structureGestion]
|
|
360
|
-
entity_hash.merge!({entity_id: information_hash[:structureGestion][:id], service_provider_id: node_id(type_data_hash, :prestataireActivites)})
|
|
361
|
-
end
|
|
362
|
-
|
|
363
|
-
if information_hash[:informationsLegales]
|
|
364
|
-
entity_hash.merge!({legal: information_hash[:informationsLegales]})
|
|
365
|
-
end
|
|
366
|
-
end
|
|
367
|
-
if sp_hash && sp_hash[:prestataireActivites]
|
|
368
|
-
entity_hash[:is_service_provider] = true
|
|
338
|
+
def self.parse_entity_fields(information_hash, type_data_hash)
|
|
339
|
+
if information_hash && information_hash[:structureGestion]
|
|
340
|
+
{entity_id: information_hash[:structureGestion][:id], service_provider_id: node_id(type_data_hash, :prestataireActivites)}
|
|
369
341
|
end
|
|
370
|
-
entity_hash
|
|
371
342
|
end
|
|
372
343
|
|
|
373
344
|
def self.node_id(node, key)
|
data/app/models/apidae/export.rb
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
require 'uri'
|
|
2
|
+
require 'net/http'
|
|
3
|
+
|
|
1
4
|
module Apidae
|
|
2
5
|
class Export < ActiveRecord::Base
|
|
3
6
|
|
|
@@ -20,5 +23,43 @@ module Apidae
|
|
|
20
23
|
def self.pending
|
|
21
24
|
where(remote_status: 'SUCCESS', status: PENDING).order(:id)
|
|
22
25
|
end
|
|
26
|
+
|
|
27
|
+
def import_data
|
|
28
|
+
success = true
|
|
29
|
+
begin
|
|
30
|
+
open(file_url) do |f|
|
|
31
|
+
begin
|
|
32
|
+
FileImport.import(f, project_id)
|
|
33
|
+
unless confirm_url.blank?
|
|
34
|
+
uri = URI(confirm_url)
|
|
35
|
+
req = Net::HTTP::Post.new(uri)
|
|
36
|
+
Net::HTTP.start(uri.hostname, uri.port) do |http|
|
|
37
|
+
http.request(req)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
update(status: Export::COMPLETE)
|
|
41
|
+
if Rails.application.config.respond_to?(:apidae_import_callback)
|
|
42
|
+
Rails.application.config.apidae_import_callback.call(self)
|
|
43
|
+
end
|
|
44
|
+
rescue Exception => ex
|
|
45
|
+
logger.error("Failed to import export file : #{file_url}")
|
|
46
|
+
logger.error("Error is : #{ex} \n#{ex.backtrace.join("\n") unless ex.backtrace.blank?}")
|
|
47
|
+
success = false
|
|
48
|
+
update(status: Export::CANCELLED)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
rescue OpenURI::HTTPError => err
|
|
52
|
+
logger.error("Failed to download export file : #{file_url}")
|
|
53
|
+
logger.error("Error is : #{err}")
|
|
54
|
+
success = false
|
|
55
|
+
update(status: Export::CANCELLED)
|
|
56
|
+
rescue Exception => e
|
|
57
|
+
logger.error "Failed to import file : #{e.file_url}"
|
|
58
|
+
logger.error("Error is : #{err}")
|
|
59
|
+
success = false
|
|
60
|
+
e.update(status: Export::CANCELLED)
|
|
61
|
+
end
|
|
62
|
+
success
|
|
63
|
+
end
|
|
23
64
|
end
|
|
24
65
|
end
|
|
@@ -30,21 +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
|
-
|
|
33
|
+
zfile.each do |file|
|
|
34
34
|
if file.file? && file.name.end_with?('.json')
|
|
35
35
|
logger.info "Processing file : #{file.name}"
|
|
36
36
|
if file.name.include?(MODIFIED_DIR)
|
|
37
37
|
add_or_update_objects(zfile.read(file.name), result, project.locales, project.versions)
|
|
38
|
-
|
|
39
|
-
if file.name.include?(SELECTIONS_FILE)
|
|
40
|
-
add_or_update_selections(project, zfile.read(file.name), result)
|
|
41
|
-
end
|
|
42
|
-
if file.name.include?(DELETED_FILE)
|
|
38
|
+
elsif file.name.include?(DELETED_FILE)
|
|
43
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)
|
|
44
42
|
end
|
|
45
43
|
end
|
|
46
44
|
end
|
|
47
|
-
project.cleanup_selections
|
|
48
45
|
create(result.except(:selections)
|
|
49
46
|
.merge({remote_file: (zip_file.is_a?(File) ? zip_file.path : zip_file), status: STATUS_COMPLETE, apidae_id: project_id}))
|
|
50
47
|
logger.info "Import results : #{result}"
|
|
@@ -107,16 +104,12 @@ module Apidae
|
|
|
107
104
|
end
|
|
108
105
|
end
|
|
109
106
|
|
|
110
|
-
def self.ordered_files(zfile)
|
|
111
|
-
zfile.sort_by {|f| f.name.include?(MODIFIED_DIR) ? 0 : (f.name.include?(SELECTIONS_FILE) ? 1 : 2)}
|
|
112
|
-
end
|
|
113
|
-
|
|
114
107
|
def self.delete_objects(deleted_json, result)
|
|
115
108
|
deleted_ids = JSON.parse(deleted_json)
|
|
116
109
|
deleted_ids.each do |id|
|
|
117
110
|
obj = Obj.find_by_apidae_id(id)
|
|
118
111
|
if obj
|
|
119
|
-
obj.destroy!
|
|
112
|
+
obj.destroy!
|
|
120
113
|
result[:deleted] += 1
|
|
121
114
|
else
|
|
122
115
|
logger.info "skipping object deletion : #{id}"
|
|
@@ -170,9 +163,7 @@ module Apidae
|
|
|
170
163
|
def self.add_or_update_selections(project, selections_json, result)
|
|
171
164
|
selections_hashes = JSON.parse(selections_json, symbolize_names: true)
|
|
172
165
|
deleted_ids = Selection.where(apidae_project_id: project.id).collect {|sel| sel.apidae_id}.uniq - selections_hashes.collect {|sel| sel[:id]}
|
|
173
|
-
|
|
174
|
-
SelectionObject.where(apidae_selection_id: apidae_selection_ids).delete_all
|
|
175
|
-
Selection.where(id: apidae_selection_ids).delete_all
|
|
166
|
+
Selection.where(apidae_id: deleted_ids).delete_all
|
|
176
167
|
selections_hashes.each do |selection_data|
|
|
177
168
|
logger.info "Updating selection #{selection_data[:id]}"
|
|
178
169
|
Selection.add_or_update(selection_data, project.id)
|
data/app/models/apidae/obj.rb
CHANGED
|
@@ -7,24 +7,22 @@ module Apidae
|
|
|
7
7
|
|
|
8
8
|
attr_accessor :locale
|
|
9
9
|
attr_accessor :obj_version
|
|
10
|
-
attr_accessor :obj_versions
|
|
11
10
|
|
|
12
11
|
store_accessor :title_data, :title
|
|
13
12
|
store_accessor :owner_data, :owner_name, :owner_id
|
|
14
13
|
store_accessor :description_data, :short_desc, :long_desc, :theme_desc, :private_desc
|
|
15
14
|
store_accessor :pictures_data, :pictures
|
|
16
15
|
store_accessor :attachments_data, :attachments
|
|
17
|
-
store_accessor :type_data, :categories, :themes, :capacity, :classification, :
|
|
18
|
-
:
|
|
19
|
-
|
|
20
|
-
store_accessor :entity_data, :entity_id, :entity_name, :service_provider_id, :is_service_provider, :legal
|
|
16
|
+
store_accessor :type_data, :categories, :themes, :capacity, :classification, :labels, :chains, :area, :track,
|
|
17
|
+
:products, :audience, :animals, :animals_desc, :extra, :duration, :certifications, :business
|
|
18
|
+
store_accessor :entity_data, :entity_id, :entity_name, :service_provider_id
|
|
21
19
|
store_accessor :contact_data, :telephone, :email, :website, :google, :facebook, :twitter, :yelp, :trip_advisor, :fax,
|
|
22
20
|
:mobile_website, :shorty_url, :contacts
|
|
23
|
-
store_accessor :location_data, :address, :place, :latitude, :longitude, :access, :territories, :environments
|
|
21
|
+
store_accessor :location_data, :address, :place, :latitude, :longitude, :access, :territories, :environments
|
|
24
22
|
store_accessor :openings_data, :openings_desc, :openings_desc_mode, :openings, :time_periods, :openings_extra
|
|
25
|
-
store_accessor :rates_data, :rates_desc, :rates_desc_mode, :rates, :payment_methods, :includes, :excludes, :rates_extra
|
|
23
|
+
store_accessor :rates_data, :rates_desc, :rates_desc_mode, :rates, :payment_methods, :includes, :excludes, :rates_extra
|
|
26
24
|
store_accessor :service_data, :services, :equipments, :comfort, :activities, :challenged, :languages
|
|
27
|
-
store_accessor :booking_data, :booking_desc, :booking_entities
|
|
25
|
+
store_accessor :booking_data, :booking_desc, :booking_entities
|
|
28
26
|
store_accessor :tags_data, :promo, :internal, :linked
|
|
29
27
|
store_accessor :version_data, :versioned_fields
|
|
30
28
|
|
|
@@ -85,7 +83,7 @@ module Apidae
|
|
|
85
83
|
COS => {node: :informationsCommerceEtService, subtype: :commerceEtServiceType},
|
|
86
84
|
DEG => {node: :informationsDegustation, subtype: :degustationType},
|
|
87
85
|
DOS => {node: :informationsDomaineSkiable, subtype: :domaineSkiableType},
|
|
88
|
-
EQU => {node: :informationsEquipement, subtype: :
|
|
86
|
+
EQU => {node: :informationsEquipement, subtype: :equipementType},
|
|
89
87
|
FEM => {node: :informationsFeteEtManifestation, subtype: :feteEtManifestationType},
|
|
90
88
|
HCO => {node: :informationsHebergementCollectif, subtype: :hebergementCollectifType},
|
|
91
89
|
HLO => {node: :informationsHebergementLocatif, subtype: :hebergementLocatifType},
|
|
@@ -102,7 +100,6 @@ module Apidae
|
|
|
102
100
|
after_initialize do
|
|
103
101
|
@locale = DEFAULT_LOCALE
|
|
104
102
|
@obj_version = DEFAULT_VERSION
|
|
105
|
-
@obj_versions = {}
|
|
106
103
|
end
|
|
107
104
|
|
|
108
105
|
def root_obj
|
|
@@ -114,15 +111,11 @@ module Apidae
|
|
|
114
111
|
end
|
|
115
112
|
|
|
116
113
|
def in_version(v)
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
else
|
|
121
|
-
if @obj_versions[v].nil?
|
|
122
|
-
@obj_versions[v] = versions.where(version: v).first
|
|
123
|
-
end
|
|
124
|
-
@obj_versions[v]
|
|
114
|
+
@cached_versions ||= {}
|
|
115
|
+
if @cached_versions[v].nil?
|
|
116
|
+
@cached_versions[v] = versions.where(version: v).first
|
|
125
117
|
end
|
|
118
|
+
@cached_versions[v]
|
|
126
119
|
end
|
|
127
120
|
|
|
128
121
|
def in_locale(l)
|
|
@@ -171,7 +164,6 @@ module Apidae
|
|
|
171
164
|
apidae_obj
|
|
172
165
|
end
|
|
173
166
|
|
|
174
|
-
# Note : overrides existing fields (not a merge)
|
|
175
167
|
def self.populate_fields(apidae_obj, object_data, locales)
|
|
176
168
|
type_fields = TYPES_DATA[object_data[:type]]
|
|
177
169
|
apidae_obj.last_update = DateTime.parse(object_data[:gestion][:dateModification]) unless object_data[:gestion].blank?
|
|
@@ -186,12 +178,12 @@ module Apidae
|
|
|
186
178
|
apidae_obj.town = ApidaeDataParser.parse_town(object_data[:localisation])
|
|
187
179
|
apidae_obj.openings_data = ApidaeDataParser.parse_openings(object_data[:ouverture], *locales)
|
|
188
180
|
apidae_obj.rates_data = ApidaeDataParser.parse_rates(object_data[:descriptionTarif], *locales)
|
|
189
|
-
apidae_obj.booking_data = ApidaeDataParser.parse_booking(object_data[:reservation],
|
|
181
|
+
apidae_obj.booking_data = ApidaeDataParser.parse_booking(object_data[:reservation], *locales)
|
|
190
182
|
apidae_obj.type_data = ApidaeDataParser.parse_type_data(apidae_obj, object_data[type_fields[:node]], object_data[:prestations],
|
|
191
183
|
object_data[:tourismeAffaires], *locales)
|
|
192
184
|
apidae_obj.pictures_data = ApidaeDataParser.parse_pictures_data(object_data[:illustrations], *locales)
|
|
193
185
|
apidae_obj.attachments_data = ApidaeDataParser.parse_attachments_data(object_data[:multimedias], *locales)
|
|
194
|
-
apidae_obj.entity_data = ApidaeDataParser.parse_entity_fields(object_data[:informations], object_data[type_fields[:node]]
|
|
186
|
+
apidae_obj.entity_data = ApidaeDataParser.parse_entity_fields(object_data[:informations], object_data[type_fields[:node]])
|
|
195
187
|
apidae_obj.service_data = ApidaeDataParser.parse_service_data(object_data[:prestations], object_data[type_fields[:node]])
|
|
196
188
|
apidae_obj.tags_data = ApidaeDataParser.parse_tags_data(object_data[:presentation], object_data[:criteresInternes], object_data[:liens])
|
|
197
189
|
apidae_obj.meta_data = object_data[:metadonnees]
|
|
@@ -10,7 +10,7 @@ module Apidae
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def self.import(refs_json)
|
|
13
|
-
|
|
13
|
+
locales = Rails.application.config.respond_to?(:apidae_locales) ? Rails.application.config.apidae_locales : [DEFAULT_LOCALE]
|
|
14
14
|
locales_map = Hash[locales.map {|loc| ["libelle#{loc.camelize.gsub('-', '')}".to_sym, loc]}]
|
|
15
15
|
refs_hashes = JSON.parse(refs_json, symbolize_names: true)
|
|
16
16
|
if refs_hashes.length != where("apidae_type != ?", INTERNAL).count
|
|
@@ -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
|
|
@@ -106,7 +92,6 @@ module Apidae
|
|
|
106
92
|
query_api(query_args, true, false)
|
|
107
93
|
end
|
|
108
94
|
|
|
109
|
-
# Note : WARNING - updated obj will only contain the provided fields
|
|
110
95
|
def add_or_refresh_obj(apidae_obj_id, fields = ["@all"])
|
|
111
96
|
if valid_api?
|
|
112
97
|
res = api_object(apidae_obj_id, fields)
|
|
@@ -117,7 +102,6 @@ module Apidae
|
|
|
117
102
|
end
|
|
118
103
|
end
|
|
119
104
|
|
|
120
|
-
# Note : WARNING - updated objs will only contain the provided fields
|
|
121
105
|
def add_or_refresh_objs(fields = ["@all"])
|
|
122
106
|
if valid_api?
|
|
123
107
|
res = api_objects({fields: fields})
|
|
@@ -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'
|
|
@@ -25,11 +24,8 @@ module Apidae
|
|
|
25
24
|
ALL_VERSIONS = [STANDARD_VERSION, WINTER_VERSION, SUMMER_VERSION, CHALLENGED_VERSION, BUSINESS_VERSION,
|
|
26
25
|
GROUPS_VERSION, ACTIVITIES_VERSION]
|
|
27
26
|
|
|
28
|
-
LOCALIZED_FIELDS = [:title, :short_desc, :long_desc, :pictures, :attachments,
|
|
29
|
-
:
|
|
30
|
-
ALL_FIELDS = LOCALIZED_FIELDS + [:theme_desc, :private_desc, :capacity, :telephone, :email, :website,
|
|
31
|
-
:
|
|
32
|
-
:openings, :openings_extra, :rates, :services, :payment_methods, :categories, :themes,
|
|
33
|
-
:labels, :chains, :classification, :challenged, :environments, :languages, :products,
|
|
34
|
-
:animals, :equipments, :comfort, :activities, :promo, :internal, :linked]
|
|
27
|
+
LOCALIZED_FIELDS = [:title, :short_desc, :long_desc, :pictures, :attachments, :openings_desc, :rates_desc,
|
|
28
|
+
:includes, :excludes, :extra, :booking_desc]
|
|
29
|
+
ALL_FIELDS = LOCALIZED_FIELDS + [:theme_desc, :private_desc, :capacity, :telephone, :email, :website, :services,
|
|
30
|
+
:equipments, :comfort, :activities, :promo, :internal, :linked]
|
|
35
31
|
end
|
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: 2020_05_22_124205) do
|
|
14
14
|
|
|
15
15
|
# These are extensions that must be enabled in order to support this database
|
|
16
16
|
enable_extension "plpgsql"
|
|
@@ -92,10 +92,8 @@ ActiveRecord::Schema.define(version: 2020_05_28_101957) do
|
|
|
92
92
|
t.datetime "created_at", null: false
|
|
93
93
|
t.datetime "updated_at", null: false
|
|
94
94
|
t.jsonb "meta_data"
|
|
95
|
-
t.boolean "is_active"
|
|
96
95
|
t.index ["apidae_id"], name: "index_apidae_references_on_apidae_id"
|
|
97
96
|
t.index ["apidae_type"], name: "index_apidae_references_on_apidae_type"
|
|
98
|
-
t.index ["is_active"], name: "index_apidae_references_on_is_active"
|
|
99
97
|
end
|
|
100
98
|
|
|
101
99
|
create_table "apidae_selection_objects", force: :cascade do |t|
|
|
@@ -1,24 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
to
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
(
|
|
1
|
+
[1m[36mApidae::Obj Load (1.5ms)[0m [1m[34mSELECT "apidae_objs".* FROM "apidae_objs" ORDER BY "apidae_objs"."id" ASC LIMIT $1[0m [["LIMIT", 1]]
|
|
2
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT pg_try_advisory_lock(6140174353533887940)[0m
|
|
3
|
+
[1m[35m (1.7ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
|
4
|
+
Migrating to AddProjectIdToSelections (20181024072424)
|
|
5
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
|
6
|
+
[1m[35m (39.2ms)[0m [1m[35mALTER TABLE "apidae_selections" ADD "apidae_project_id" integer[0m
|
|
7
|
+
[1m[36mActiveRecord::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181024072424"]]
|
|
8
|
+
[1m[35m (0.8ms)[0m [1m[35mCOMMIT[0m
|
|
9
|
+
Migrating to CreateApidaeProjects (20181024072843)
|
|
10
|
+
[1m[35m (0.1ms)[0m [1m[35mBEGIN[0m
|
|
11
|
+
[1m[35m (56.9ms)[0m [1m[35mCREATE TABLE "apidae_projects" ("id" bigserial primary key, "name" character varying, "apidae_id" integer, "api_key" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)[0m
|
|
12
|
+
[1m[36mActiveRecord::SchemaMigration Create (0.2ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20181024072843"]]
|
|
13
|
+
[1m[35m (2.1ms)[0m [1m[35mCOMMIT[0m
|
|
14
|
+
Migrating to AddApidaeIdToApidaeFileImports (20190111162443)
|
|
15
|
+
[1m[35m (40.0ms)[0m [1m[35mBEGIN[0m
|
|
16
|
+
[1m[35m (0.6ms)[0m [1m[35mALTER TABLE "apidae_file_imports" ADD "apidae_id" integer[0m
|
|
17
|
+
[1m[36mActiveRecord::SchemaMigration Create (0.4ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190111162443"]]
|
|
18
|
+
[1m[35m (0.6ms)[0m [1m[35mCOMMIT[0m
|
|
19
|
+
Migrating to UpgradeApidaeObjsTitleDataType (20190123142628)
|
|
20
|
+
[1m[35m (0.1ms)[0m [1m[35mBEGIN[0m
|
|
21
|
+
[1m[35m (0.4ms)[0m [1m[35mALTER TABLE "apidae_objs" ADD "title_data" jsonb[0m
|
|
22
|
+
[1m[36mApidae::Obj Load (0.5ms)[0m [1m[34mSELECT "apidae_objs".* FROM "apidae_objs"[0m
|
|
23
|
+
[1m[35m (1.4ms)[0m [1m[35mALTER TABLE "apidae_objs" DROP COLUMN "title"[0m
|
|
24
|
+
[1m[36mActiveRecord::SchemaMigration Create (0.2ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190123142628"]]
|
|
25
|
+
[1m[35m (0.4ms)[0m [1m[35mCOMMIT[0m
|
|
26
|
+
[1m[36mActiveRecord::InternalMetadata Load (1.9ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
|
27
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
|
28
|
+
[1m[35m (0.1ms)[0m [1m[35mCOMMIT[0m
|
|
29
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT pg_advisory_unlock(6140174353533887940)[0m
|
|
30
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
|
31
|
+
[1m[35m (0.3ms)[0m [1m[34mSELECT pg_try_advisory_lock(6140174353533887940)[0m
|
|
32
|
+
[1m[35m (3.6ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
|
33
|
+
Migrating to AddBookingDataToApidaeObjs (20190123160046)
|
|
34
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
|
35
|
+
[1m[35m (0.7ms)[0m [1m[35mALTER TABLE "apidae_objs" ADD "booking_data" jsonb[0m
|
|
36
|
+
[1m[36mApidae::Obj Load (1.0ms)[0m [1m[34mSELECT "apidae_objs".* FROM "apidae_objs"[0m
|
|
37
|
+
[1m[35m (0.5ms)[0m [1m[35mALTER TABLE "apidae_objs" DROP COLUMN "reservation"[0m
|
|
38
|
+
[1m[36mActiveRecord::SchemaMigration Create (0.3ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190123160046"]]
|
|
39
|
+
[1m[35m (0.6ms)[0m [1m[35mCOMMIT[0m
|
|
40
|
+
[1m[36mActiveRecord::InternalMetadata Load (0.7ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
|
41
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
|
42
|
+
[1m[35m (0.1ms)[0m [1m[35mCOMMIT[0m
|
|
43
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT pg_advisory_unlock(6140174353533887940)[0m
|
|
44
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
|
45
|
+
[1m[35m (4.5ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
|
46
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT pg_try_advisory_lock(6140174353533887940)[0m
|
|
47
|
+
[1m[35m (0.6ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
|
48
|
+
Migrating to AddLocalesDataToApidaeProjects (20190123214635)
|
|
49
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
|
50
|
+
[1m[35m (3.2ms)[0m [1m[35mALTER TABLE "apidae_projects" ADD "locales_data" character varying[0m
|
|
51
|
+
[1m[36mActiveRecord::SchemaMigration Create (0.3ms)[0m [1m[32mINSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version"[0m [["version", "20190123214635"]]
|
|
52
|
+
[1m[35m (0.5ms)[0m [1m[35mCOMMIT[0m
|
|
53
|
+
[1m[36mActiveRecord::InternalMetadata Load (42.2ms)[0m [1m[34mSELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m [["key", "environment"], ["LIMIT", 1]]
|
|
54
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
|
55
|
+
[1m[35m (0.1ms)[0m [1m[35mCOMMIT[0m
|
|
56
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT pg_advisory_unlock(6140174353533887940)[0m
|
|
57
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
|
58
|
+
[1m[35m (0.5ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
|
59
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT pg_try_advisory_lock(6140174353533887940)[0m
|
|
60
|
+
[1m[35m (0.5ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
|
61
|
+
[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]]
|
|
62
|
+
[1m[35m (0.2ms)[0m [1m[35mBEGIN[0m
|
|
63
|
+
[1m[35m (0.2ms)[0m [1m[35mCOMMIT[0m
|
|
64
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT pg_advisory_unlock(6140174353533887940)[0m
|
|
65
|
+
[1m[35m (0.2ms)[0m [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
|
|
66
|
+
[1m[36mApidae::Obj Load (26.8ms)[0m [1m[34mSELECT apidae_id, COUNT(id) FROM "apidae_objs" WHERE "apidae_objs"."root_obj_id" IS NULL GROUP BY "apidae_objs"."apidae_id" HAVING (COUNT(id) > 1)[0m
|
|
67
|
+
[1m[36mApidae::Obj Load (2.4ms)[0m [1m[34mSELECT apidae_id, COUNT(id) FROM "apidae_objs" WHERE "apidae_objs"."root_obj_id" IS NULL GROUP BY "apidae_objs"."apidae_id" HAVING (COUNT(id) > 1)[0m
|