apidae 1.2.34 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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 +20 -57
- data/app/models/apidae/export.rb +41 -0
- data/app/models/apidae/file_import.rb +6 -15
- data/app/models/apidae/obj.rb +15 -23
- data/app/models/apidae/project.rb +0 -6
- data/app/models/apidae/reference.rb +1 -1
- data/app/models/apidae/selection.rb +1 -17
- 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 -58
- data/test/dummy/log/test.log +3324 -5771
- data/test/models/apidae/file_import_test.rb +0 -23
- metadata +14 -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
|
@@ -101,15 +101,10 @@ module Apidae
|
|
101
101
|
{title: node_value(data_hash, :nom, *locales)}
|
102
102
|
end
|
103
103
|
|
104
|
-
def self.parse_owner_data(data_hash
|
105
|
-
owner_data = {}
|
104
|
+
def self.parse_owner_data(data_hash)
|
106
105
|
unless data_hash.blank?
|
107
|
-
|
106
|
+
{owner_name: data_hash[:nom], owner_id: data_hash[:id]}
|
108
107
|
end
|
109
|
-
unless polls_data.blank?
|
110
|
-
owner_data.merge!({polls: polls_data[:enquetes] || []})
|
111
|
-
end
|
112
|
-
owner_data
|
113
108
|
end
|
114
109
|
|
115
110
|
def self.parse_desc_data(data_hash, private_data, *locales)
|
@@ -118,7 +113,7 @@ module Apidae
|
|
118
113
|
short_desc: node_value(data_hash, :descriptifCourt, *locales),
|
119
114
|
long_desc: node_value(data_hash, :descriptifDetaille, *locales),
|
120
115
|
theme_desc: data_hash[:descriptifsThematises].blank? ? {} : Hash[data_hash[:descriptifsThematises].map {|th| [node_id(th, :theme), node_value(th, :description, *locales)]}],
|
121
|
-
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)]}]
|
122
117
|
}
|
123
118
|
end
|
124
119
|
end
|
@@ -156,7 +151,6 @@ module Apidae
|
|
156
151
|
name: localized_value(att, :nom, locale),
|
157
152
|
url: att[:traductionFichiers][0][:url].gsub('http:', 'https:'),
|
158
153
|
type: att[:type],
|
159
|
-
link: att[:link],
|
160
154
|
description: localized_value(att, :legende, locale)
|
161
155
|
}
|
162
156
|
end
|
@@ -214,22 +208,20 @@ module Apidae
|
|
214
208
|
def self.parse_location_data(location_hash, type_data_hash, territories)
|
215
209
|
loc_data = {}
|
216
210
|
unless location_hash.blank?
|
217
|
-
address_hash = location_hash[:adresse]
|
211
|
+
address_hash = location_hash[:adresse]
|
218
212
|
computed_address = []
|
219
213
|
unless address_hash.blank?
|
220
|
-
computed_address << address_hash[:adresse1]
|
221
|
-
computed_address << address_hash[:adresse2]
|
222
|
-
computed_address << address_hash[:adresse3]
|
214
|
+
computed_address << address_hash[:adresse1] unless address_hash[:adresse1].blank?
|
215
|
+
computed_address << address_hash[:adresse2] unless address_hash[:adresse2].blank?
|
216
|
+
computed_address << address_hash[:adresse3] unless address_hash[:adresse3].blank?
|
223
217
|
end
|
224
218
|
loc_data.merge!({address: computed_address})
|
225
|
-
loc_data.merge!({place:
|
219
|
+
loc_data.merge!({place: type_data_hash[:nomLieu]}) if type_data_hash
|
226
220
|
geoloc_details = location_hash[:geolocalisation]
|
227
221
|
if geoloc_details && geoloc_details[:valide] && geoloc_details[:geoJson]
|
228
222
|
loc_data[:latitude] = geoloc_details[:geoJson][:coordinates][1]
|
229
223
|
loc_data[:longitude] = geoloc_details[:geoJson][:coordinates][0]
|
230
224
|
end
|
231
|
-
loc_data[:map_reference] = geoloc_details[:reperePlan]
|
232
|
-
loc_data[:altitude] = geoloc_details[:altitude] if geoloc_details
|
233
225
|
loc_data[:access] = node_value(geoloc_details, :complement) if geoloc_details
|
234
226
|
loc_data[:environments] = location_hash[:environnements].map {|e| e[:id]} if location_hash[:environnements]
|
235
227
|
end
|
@@ -244,7 +236,6 @@ module Apidae
|
|
244
236
|
openings_desc: node_value(openings_hash, :periodeEnClair, *locales),
|
245
237
|
openings_desc_mode: openings_hash[:periodeEnClairGenerationMode] == 'AUTOMATIQUE' ? MODE_AUTO : MODE_MANUAL,
|
246
238
|
openings: build_openings(openings_hash, *locales),
|
247
|
-
all_year_long: openings_hash[:ouvertTouteLAnnee] == 'OUVERT_TOUTE_L_ANNEE' ? 'true' : 'false',
|
248
239
|
time_periods: lists_ids(openings_hash[:indicationsPeriode]),
|
249
240
|
openings_extra: lists_ids(openings_hash[:ouverturesComplementaires])
|
250
241
|
}
|
@@ -256,10 +247,8 @@ module Apidae
|
|
256
247
|
desc = rates_hash[:gratuit] ? {DEFAULT_LOCALE => 'gratuit'} : node_value(rates_hash, :tarifsEnClair, *locales)
|
257
248
|
values = rates_hash[:periodes].blank? ? [] : rates_hash[:periodes].map {|p| build_rate(p, *locales)}
|
258
249
|
methods = rates_hash[:modesPaiement].blank? ? [] : rates_hash[:modesPaiement].map {|p| p[:id]}
|
259
|
-
|
260
250
|
{
|
261
251
|
rates_desc: desc, rates: values, payment_methods: methods,
|
262
|
-
tax_included: rates_hash[:taxeDeSejourIncluse].blank? ? nil : (rates_hash[:taxeDeSejourIncluse] == 'OUI'),
|
263
252
|
rates_desc_mode: rates_hash[:tarifsEnClairGenerationMode] == 'AUTOMATIQUE' ? MODE_AUTO : MODE_MANUAL,
|
264
253
|
includes: node_value(rates_hash, :leTarifComprend, *locales),
|
265
254
|
excludes: node_value(rates_hash, :leTarifNeComprendPas, *locales),
|
@@ -275,21 +264,18 @@ module Apidae
|
|
275
264
|
apidae_obj.apidae_subtype = node_id(data_hash, :rubrique) if apidae_obj.apidae_type == Obj::EQU
|
276
265
|
apidae_obj.apidae_subtype = lists_ids(data_hash[:typesHebergement]).first if apidae_obj.apidae_type == Obj::SPA
|
277
266
|
{
|
278
|
-
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]),
|
279
268
|
themes: lists_ids(data_hash[:themes]),
|
280
269
|
capacity: (data_hash[:capacite] || {})
|
281
270
|
.merge(presta_hash ? {group_min: presta_hash[:tailleGroupeMin], group_max: presta_hash[:tailleGroupeMax],
|
282
271
|
age_min: presta_hash[:ageMin], age_max: presta_hash[:ageMax]} : {}),
|
283
272
|
classification: nodes_ids(data_hash[:classement], data_hash[:classementPrefectoral], data_hash[:classification]) +
|
284
273
|
lists_ids(data_hash[:classementsGuides]) + lists_ids(data_hash[:classements]),
|
285
|
-
classification_date: data_hash[:dateClassement],
|
286
|
-
classification_ref: data_hash[:numeroClassement],
|
287
274
|
labels: lists_ids(data_hash[:labels], data_hash[:labelsChartesQualite], prestations_hash[:labelsTourismeHandicap]) +
|
288
275
|
(node_id(data_hash, :typeLabel) ? [node_id(data_hash, :typeLabel)] : []),
|
289
276
|
chains: lists_ids(data_hash[:chaines]) + nodes_ids(data_hash[:chaineEtLabel]),
|
290
277
|
area: apidae_obj.apidae_type == Obj::DOS ? data_hash.except(:classification) : node_value(data_hash, :lieuDePratique),
|
291
|
-
track: apidae_obj.apidae_type == Obj::EQU ?
|
292
|
-
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,
|
293
279
|
products: lists_ids(data_hash[:typesProduit], data_hash[:aopAocIgps], data_hash[:specialites]),
|
294
280
|
audience: lists_ids(prestations_hash[:typesClientele]),
|
295
281
|
animals: {allowed: prestations_hash[:animauxAcceptes] == 'ACCEPTES', desc: node_value(prestations_hash, :descriptifAnimauxAcceptes, *locales),
|
@@ -297,10 +283,7 @@ module Apidae
|
|
297
283
|
extra: apidae_obj.apidae_type == Obj::SPA ? node_value(data_hash, :formuleHebergement, *locales) : node_value(prestations_hash, :complementAccueil, *locales),
|
298
284
|
duration: apidae_obj.apidae_type == Obj::SPA ? {days: data_hash[:nombreJours], nights: data_hash[:nombreNuits]} : data_hash[:dureeSeance],
|
299
285
|
certifications: data_hash[:agrements].blank? ? [] : data_hash[:agrements].map {|a| {id: a[:type][:id], identifier: a[:numero]}},
|
300
|
-
business:
|
301
|
-
business_equipments: lists_ids((business_hash || {})[:sallesEquipeesPour], (business_hash || {})[:sallesEquipement],
|
302
|
-
(business_hash || {})[:sallesRestauration], (business_hash || {})[:sallesHebergement]),
|
303
|
-
business_rooms: (business_hash || {})[:sallesReunion]
|
286
|
+
business: business_hash
|
304
287
|
}
|
305
288
|
end
|
306
289
|
|
@@ -334,19 +317,13 @@ module Apidae
|
|
334
317
|
tags
|
335
318
|
end
|
336
319
|
|
337
|
-
def self.parse_booking(reservation_hash,
|
338
|
-
booking_hash = {}
|
320
|
+
def self.parse_booking(reservation_hash, *locales)
|
339
321
|
if reservation_hash
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
booking_hash[:visits_allowed] = visits_hash[:visitable] == true
|
345
|
-
booking_hash[:visits_desc] = node_value(visits_hash, :complementVisite, *locales)
|
346
|
-
booking_hash[:visits_duration] = visits_hash[:dureeMoyenneVisiteIndividuelle]
|
347
|
-
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
|
+
}
|
348
326
|
end
|
349
|
-
booking_hash
|
350
327
|
end
|
351
328
|
|
352
329
|
def self.parse_town(location_hash)
|
@@ -358,24 +335,10 @@ module Apidae
|
|
358
335
|
end
|
359
336
|
end
|
360
337
|
|
361
|
-
def self.parse_entity_fields(information_hash, type_data_hash
|
362
|
-
|
363
|
-
|
364
|
-
if information_hash[:structureGestion]
|
365
|
-
entity_hash.merge!({entity_id: information_hash[:structureGestion][:id], entity_name: information_hash[:structureGestion].dig(:nom, :libelleFr),
|
366
|
-
info_entity_id: (information_hash[:structureInformation] || information_hash[:structureGestion])[:id],
|
367
|
-
info_entity_name: (information_hash[:structureInformation] || information_hash[:structureGestion]).dig(:nom, :libelleFr),
|
368
|
-
service_provider_id: node_id(type_data_hash, :prestataireActivites)})
|
369
|
-
end
|
370
|
-
|
371
|
-
if information_hash[:informationsLegales]
|
372
|
-
entity_hash.merge!({legal: information_hash[:informationsLegales]})
|
373
|
-
end
|
374
|
-
end
|
375
|
-
if sp_hash && sp_hash[:prestataireActivites]
|
376
|
-
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)}
|
377
341
|
end
|
378
|
-
entity_hash
|
379
342
|
end
|
380
343
|
|
381
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
|
-
store_accessor :owner_data, :owner_name, :owner_id
|
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, :info_entity_id, :info_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,11 +164,10 @@ 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?
|
178
|
-
apidae_obj.owner_data = ApidaeDataParser.parse_owner_data(object_data[:gestion][:membreProprietaire]
|
170
|
+
apidae_obj.owner_data = ApidaeDataParser.parse_owner_data(object_data[:gestion][:membreProprietaire]) unless object_data[:gestion].blank?
|
179
171
|
apidae_obj.apidae_type = object_data[:type]
|
180
172
|
apidae_obj.apidae_subtype = ApidaeDataParser.node_id(object_data[type_fields[:node]], type_fields[:subtype])
|
181
173
|
apidae_obj.title_data = ApidaeDataParser.parse_title(object_data, *locales)
|
@@ -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})
|
@@ -219,7 +203,7 @@ module Apidae
|
|
219
203
|
def get_response(args)
|
220
204
|
response = ''
|
221
205
|
query = JSON.generate args.except(:url)
|
222
|
-
logger.
|
206
|
+
logger.info "Apidae API query : #{args[:url]}?query=#{query}"
|
223
207
|
open("#{args[:url]}?query=#{CGI.escape query}") { |f|
|
224
208
|
f.each_line {|line| response += line if line}
|
225
209
|
}
|
@@ -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|
|