apidae 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +4 -0
- data/app/assets/images/apidae/logo-apidae-grey.svg +84 -0
- data/app/controllers/apidae/dashboard_controller.rb +11 -0
- data/app/controllers/apidae/import_controller.rb +50 -0
- data/app/helpers/apidae/dashboard_helper.rb +4 -0
- data/app/helpers/apidae/import_helper.rb +4 -0
- data/app/models/apidae/export.rb +12 -0
- data/app/models/apidae/file_import.rb +66 -40
- data/app/models/apidae/selection.rb +7 -0
- data/app/views/apidae/dashboard/index.html.erb +39 -0
- data/app/views/apidae/import/callback.html.erb +2 -0
- data/app/views/apidae/objects/index.html.erb +29 -52
- data/app/views/apidae/selections/index.html.erb +29 -30
- data/config/routes.rb +8 -2
- data/db/migrate/20171025075304_create_apidae_exports.rb +15 -0
- data/lib/apidae/version.rb +1 -1
- data/test/controllers/apidae/dashboard_controller_test.rb +15 -0
- data/test/controllers/apidae/import_controller_test.rb +15 -0
- data/test/data/delete_selections.json +1 -0
- data/test/data/deletion.json +1 -0
- data/test/data/json_export.zip +0 -0
- data/test/data/selections.json +15 -0
- data/test/data/structure.json +65 -0
- data/test/data/update_selections.json +19 -0
- data/test/dummy/db/schema.rb +39 -2
- data/test/dummy/log/development.log +69 -0
- data/test/dummy/log/test.log +1808 -0
- data/test/fixtures/apidae/exports.yml +15 -0
- data/test/models/apidae/export_test.rb +9 -0
- data/test/models/apidae/file_import_test.rb +83 -4
- data/test/test_helper.rb +2 -1
- metadata +45 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd09605f8fc42cf6117c1339ec62cc76620b10bc
|
4
|
+
data.tar.gz: 072fd7a05baf4b878c76cca5baeeb8bc459352d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0acaaed45a9f86a98538808fba65872ec01d1fffbcd7dfe45118a0e83bdfa597172d39b5596ab7acfbee41633e42e95d691644527f698cbdb1a1275dcc83238
|
7
|
+
data.tar.gz: ceb438158398ade5e20dbcdf542c9430e8895b875adb9621d59d712f39d1386461c3b0c773315a39220f7f535883d926da392a1564cdeaf921120c08763c88e7
|
data/Rakefile
CHANGED
@@ -24,7 +24,11 @@ load 'rails/tasks/statistics.rake'
|
|
24
24
|
|
25
25
|
Bundler::GemHelper.install_tasks
|
26
26
|
|
27
|
+
# Note : where should engine-related test dependencies go ?
|
27
28
|
require 'rake/testtask'
|
29
|
+
require 'paperclip/schema'
|
30
|
+
|
31
|
+
include Paperclip::Schema
|
28
32
|
|
29
33
|
Rake::TestTask.new(:test) do |t|
|
30
34
|
t.libs << 'lib'
|
@@ -0,0 +1,84 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!-- Generator: Adobe Illustrator 21.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
3
|
+
<svg version="1.1" id="Calque_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
4
|
+
viewBox="0 0 3000 1335" style="enable-background:new 0 0 3000 1335;" xml:space="preserve">
|
5
|
+
<style type="text/css">
|
6
|
+
.st0{fill:none;}
|
7
|
+
.st1{fill:#D7D7D7;}
|
8
|
+
.st2{fill:#B2B2B2;}
|
9
|
+
.st3{fill:#999999;}
|
10
|
+
.st4{fill:#C2C2C2;}
|
11
|
+
.st5{fill:#8A8A8A;}
|
12
|
+
.st6{fill:#9A9A9A;}
|
13
|
+
.st7{fill:#9B9B9B;}
|
14
|
+
.st8{fill:#656565;}
|
15
|
+
.st9{fill:#FFFFFF;}
|
16
|
+
.st10{fill:#DDDDDD;}
|
17
|
+
.st11{fill:#A6A6A6;}
|
18
|
+
.st12{fill:#CCCCCC;}
|
19
|
+
.st13{fill:#C1C1C1;}
|
20
|
+
.st14{fill:#808080;}
|
21
|
+
.st15{fill:#777777;}
|
22
|
+
</style>
|
23
|
+
<title>Plan de travail 1</title>
|
24
|
+
<path class="st0" d="M2519,501.1c16.9-40.8,24.8-83.6,27.7-122.7c-17.1,27.5-39.4,69.4-54.1,118.4L2519,501.1z"/>
|
25
|
+
<path class="st0" d="M1973.6,424.3L1973.6,424.3c-1-1.3-2-2.5-3-3.8C1971.6,421.8,1972.6,423.1,1973.6,424.3z"/>
|
26
|
+
<path class="st1" d="M1688.9,441h103.8v101.7l27.2-33.3c-0.2-0.5-0.5-1.1-0.7-1.6c-1.4-3.4-2.7-6.9-4-10.3c-0.3-0.8-0.6-1.5-0.8-2.3
|
27
|
+
l-0.2-0.5c-22.4-63.1-19.3-130.1-9.4-184c-123-28.8-249.7,22-249.7,22s24.4,81.5,83.3,154.3v-46H1688.9z"/>
|
28
|
+
<path class="st2" d="M1837.6,201.4c0,0-21.1,45.6-32.8,109.2l0,0l0,0c19.4,4.6,39.2,10.8,57.9,19.9c44.6,21.7,80.2,55,107.9,90
|
29
|
+
c1,1.3,2,2.5,3,3.8l14.8,2.4c2-35.2,8.1-73.8,21.9-111.2C1936.8,237,1837.6,201.4,1837.6,201.4z"/>
|
30
|
+
<path class="st3" d="M1970.6,420.6c-27.7-35-63.3-68.2-107.9-90c-18.7-9.1-38.5-15.3-57.9-19.9l0,0l-0.1,0.5
|
31
|
+
c-10,54-12.8,120.5,9.5,183.5l0.2,0.5c0.3,0.8,0.6,1.5,0.8,2.3c1.3,3.6,2.7,7.1,4.2,10.6c0.2,0.4,0.4,0.8,0.5,1.2l70.7-86.6
|
32
|
+
l8.6-10.6l13.4,2.2l60.9,9.9C1972.6,423.1,1971.6,421.8,1970.6,420.6z"/>
|
33
|
+
<path class="st4" d="M2078.3,430.7L2187,298.5l8.6-10.5l13.4,2.2l98.1,16.3c24-103.5-0.2-203.8-0.2-203.8s-181.1,26.8-266.3,153.1
|
34
|
+
c-12.5,18.6-22.7,38.7-30.3,59.8c23.4,25,44.2,54.3,58.4,88.2C2072.4,412.6,2075.6,421.6,2078.3,430.7z"/>
|
35
|
+
<path class="st5" d="M2070.6,440.1l6.3-7.7l1.4-1.8c-2.7-9.1-5.9-18.1-9.6-26.9c-14.2-33.9-35-63.2-58.4-88.2
|
36
|
+
c-13.8,37.4-19.9,76-21.9,111.2L2070.6,440.1z"/>
|
37
|
+
<path class="st6" d="M2393.7,320.8l4.8,12.8l59.2,157.7l4.9,0.8l30.1,4.9c14.6-49,37-90.9,54.1-118.4c6.2-80.7-8.6-145.8-8.6-145.8
|
38
|
+
s-109,14.7-202.7,78.5l44.9,7.5L2393.7,320.8z"/>
|
39
|
+
<path class="st7" d="M2619,517.2c26.8-17.8,54.8-31.4,80.9-41.7c-53.3-82.1-129.3-132.1-129.3-132.1c-8.6,11.2-16.6,22.9-23.9,35
|
40
|
+
c-3,39.1-10.9,81.8-27.7,122.7L2619,517.2z"/>
|
41
|
+
<path class="st8" d="M2519,501.1c17.8-41.8,24.7-82.5,27.7-122.7c-17.1,27.5-39.4,69.4-54.1,118.4L2519,501.1L2519,501.1z"/>
|
42
|
+
<polygon class="st9" points="2492.6,496.8 2492.6,496.9 2492.6,496.8 "/>
|
43
|
+
<path class="st10" d="M2425.4,590l42.1-51.8l147,23.7l16.2,42.5c10.3,5.3,20.2,11.3,29.6,18l-30.4-79.6l-171.3-27.5l-77.3,95
|
44
|
+
l0.1-0.1C2395.5,602.1,2410.2,595.3,2425.4,590z"/>
|
45
|
+
<polygon class="st11" points="2119.4,451.5 2213.9,336.5 2360.8,360.8 2413.1,500.2 2318.6,615.2 2285.3,609.7 2285.3,631.3
|
46
|
+
2327.2,638.2 2437.4,504.2 2376.4,341.8 2205.3,313.5 2095.1,447.4 2147.4,586.8 2170.2,586.8 "/>
|
47
|
+
<path class="st12" d="M1849.2,644l-25.8-68l94.2-115.3l147,23.9l39.6,104.3c9.2,3.2,18.2,7,26.8,11.4v-0.5l-50.9-134.1l-171.2-27.9
|
48
|
+
l-109.7,134.3l33.7,89C1838.1,655.1,1843.5,649.4,1849.2,644z"/>
|
49
|
+
<path class="st13" d="M2740.3,719c3,6.5,5.7,13.1,8.2,19.9c2.1,5.9,4,11.8,5.7,17.8c1.9-2.5,3.7-5,5.5-7.5
|
50
|
+
c88-124.4,48.9-303.3,48.9-303.3s-49.2,6.2-108.8,29.7c22.3,34.4,40.7,74.5,47.8,119C2754.7,637.6,2750.2,680.2,2740.3,719z"/>
|
51
|
+
<path class="st14" d="M2747.8,594.5c-7.1-44.4-25.5-84.5-47.8-119c-26.1,10.3-54.1,23.9-80.9,41.7l14.8,2.4l13.4,2.2l4.9,12.7
|
52
|
+
l46.5,122c17,18.6,31.1,39.7,41.8,62.6C2750.2,680.2,2754.7,637.6,2747.8,594.5z"/>
|
53
|
+
<path class="st15" d="M151.6,1023.7l221.9-531.5H431l219.8,531.5H586l-61.7-148.3H276.8l-61,148.3H151.6z M294.6,825.6h211.8
|
54
|
+
L400.2,559.2L294.6,825.6z"/>
|
55
|
+
<path class="st15" d="M708,1214.1V637.3h50.5v81.2c16.1-28.9,38-51.5,65.7-67.8c27.7-16.2,59.7-24.4,95.9-24.3
|
56
|
+
c25.2,0,48.7,3.9,70.5,11.8c21.7,7.8,40.3,18.4,55.6,31.8c15.4,13.5,28.8,29.2,39.6,46.5c10.9,17.3,19.2,36.1,24.5,55.8
|
57
|
+
c5.3,19.5,7.9,39.7,7.9,59.9c0.1,52.2-19.2,102.7-54,141.6c-16.8,18.5-37.7,33.3-62.8,44.3c-25,11-52.1,16.4-81.3,16.4
|
58
|
+
c-19.6,0.1-39.2-2.7-58-8.2c-18.3-5.5-34-12.7-47-21.7c-12.1-8.3-23.2-17.9-33.1-28.7c-9.1-10.2-16-20.5-20.7-31v269.2L708,1214.1z
|
59
|
+
M757.8,831.6c0,43.3,14.8,79.8,44.5,109.5c29.2,29.2,65.5,43.7,109,43.7c43.7,0,80.2-14.6,109.6-43.9c29.3-29.3,44-65.9,44-110
|
60
|
+
v-0.7c0-18.7-3.3-37.2-9.8-54.7c-6.6-17.9-16.2-34.5-28.4-49.1c-12.4-14.9-28.7-27-48.9-36.2s-42.8-13.8-67.8-13.8
|
61
|
+
c-42.5,0-78.9,15-109,45.1C772.2,751.5,757.8,788.2,757.8,831.6L757.8,831.6z"/>
|
62
|
+
<path class="st15" d="M1198.8,566.2v-74h53.3v74H1198.8z M1198.8,1023.7V637.3h53.3v386.4L1198.8,1023.7z"/>
|
63
|
+
<path class="st15" d="M1331.7,830.2c0-37.9,8.5-72.4,25.5-103.4c16.6-30.6,41.2-56,71.3-73.4c30.5-17.9,64.8-26.9,102.8-26.9
|
64
|
+
c39,0,72.6,9.1,100.8,27.4s47.3,39,57.1,62.3V492.2h53.3v531.5h-51.2v-79.5c-14.5,27.1-35.9,49.7-62.2,65.7
|
65
|
+
c-26.7,16.5-59.1,24.7-97.2,24.7c-30,0-57.8-5.6-83.3-16.8c-25.5-11.2-46.7-26.2-63.5-45c-17.1-19.1-30.5-41.1-39.4-65.1
|
66
|
+
C1336.4,882.9,1331.6,856.6,1331.7,830.2z M1385,830.9c0.4,38.9,14.5,76.3,39.9,105.8c12.6,14.6,28.9,26.2,48.8,35
|
67
|
+
c19.9,8.8,42.1,13.1,66.4,13.1c20.7,0.1,41.3-3.9,60.4-11.9c18.5-7.6,35.3-18.9,49.2-33.2c28.7-29.4,43.1-64.5,43.1-105.3v-5.6
|
68
|
+
c0-43.1-14.8-79.2-44.5-108.1c-28.9-29.6-65.2-44.4-108.9-44.4c-44.4,0-81.2,14.8-110.5,44.3c-29.3,29.5-43.9,66.1-43.9,109.6
|
69
|
+
L1385,830.9z"/>
|
70
|
+
<path class="st15" d="M1822.5,830.9c0-37.7,8.4-72.1,25.3-103.1c16.9-31,40.8-55.7,71.7-73.9c30.9-18.2,65.5-27.4,104-27.4
|
71
|
+
c38.5,0,71.9,9.3,100.1,27.9c28.2,18.6,47.5,40.2,57.8,64.9v-81.9h53.3v386.4h-53.3v-79.5c-15,28.7-36.3,51-64.1,66.7
|
72
|
+
c-27.8,15.8-59.1,23.6-93.8,23.6c-24.7,0-47.7-3.7-69.2-11c-21.5-7.3-40.2-17.4-56.2-30.3c-15.9-12.8-29.8-27.9-41.2-44.8
|
73
|
+
c-11.5-17.1-20.3-35.8-25.9-55.7C1825.4,872.7,1822.5,851.8,1822.5,830.9z M1875.8,831.6c0.3,18.3,3.6,36.4,10,53.5
|
74
|
+
c6.5,17.7,15.9,34.3,27.8,49c12.2,15.2,28.4,27.4,48.7,36.7c20.3,9.3,43.2,14,68.6,14c33.2,0,61.9-8.6,86.3-25.7s42-39.8,52.7-68
|
75
|
+
c8.6-18.2,12.9-38.5,12.9-60.9v-4.9c0.2-19.6-4-38.9-12.2-56.7c-11-27.5-29-49.8-53.9-66.8c-25-17-54-25.5-87.2-25.5
|
76
|
+
c-44.1,0-80.8,14.9-110,44.8s-43.8,66.5-43.8,109.8L1875.8,831.6z"/>
|
77
|
+
<path class="st15" d="M2307.4,831.2c0-37.4,8.8-71.7,26.5-103.1c17.3-30.9,42.6-56.6,73.3-74.3c31.2-18.2,65.7-27.4,103.6-27.3
|
78
|
+
c26.5-0.1,52.9,4.7,77.7,14.2c23.8,9.1,45.6,22.8,64,40.5c21.8,20.9,38.5,46.6,48.7,75c8.2,22.4,12.4,46,12.6,69.8
|
79
|
+
c0,6.6-0.3,13.1-1,19.6h-352c0.7,23.2,5.9,44.2,15.4,63.1s21.8,34,36.6,45.5c14.5,11.3,30.6,20.2,47.9,26.4
|
80
|
+
c15.7,5.8,32.4,8.6,49.1,8.5h1.8c29.7,0,56.1-7,79.2-21.1c23.1-14.1,41-33.8,53.6-59.2h55.4c-17.5,41.1-43.7,72.6-78.5,94.3
|
81
|
+
c-32.7,21-69.3,31.6-109.7,31.6c-25.9,0-50.1-4-72.6-11.9c-22.5-7.9-41.6-18.6-57.3-32.1c-15.7-13.4-29.4-29-40.7-46.3
|
82
|
+
c-11.1-17-19.6-35.5-25.2-55C2310.2,870.4,2307.4,850.9,2307.4,831.2z M2361.4,803.2H2660c-1.9-34.7-17.4-65.5-46.6-92.3
|
83
|
+
c-28.3-25.9-61-38.9-98.1-38.9h-3.9c-40.9,0-75.5,12.9-103.8,38.7C2379.3,736.4,2363.9,767.3,2361.4,803.2L2361.4,803.2z"/>
|
84
|
+
</svg>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require_dependency "apidae/application_controller"
|
2
|
+
|
3
|
+
module Apidae
|
4
|
+
class DashboardController < ApplicationController
|
5
|
+
def index
|
6
|
+
@objects = Apidae::Object.count
|
7
|
+
@selections = Apidae::Selection.count
|
8
|
+
@last_imports = Apidae::FileImport.order(id: :desc).take(5)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require_dependency "apidae/application_controller"
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
module Apidae
|
5
|
+
class ImportController < ApplicationController
|
6
|
+
skip_before_action :verify_authenticity_token
|
7
|
+
|
8
|
+
# Callback endpoint for Apidae exports
|
9
|
+
#
|
10
|
+
# projetId : un entier. C’est l’identifiant du projet concerné.
|
11
|
+
# statut : une chaine de caractères, ‘SUCCESS’ ou ‘ERROR’. C’est l’issue de l’export.
|
12
|
+
# ponctuel : un booléen. Indique si l’export est ponctuel (true) ou périodique (false).
|
13
|
+
# reinitialisation : un booléen. Indique si l’export est une réinitialisation (true) ou différentiel (false).
|
14
|
+
# urlRecuperation : une chaine de caractères. L’URL de récupération du fichier d’export.
|
15
|
+
# urlConfirmation : une chaine de caractères. L’URL de confirmation.
|
16
|
+
def callback
|
17
|
+
project_id = params[:projetId]
|
18
|
+
if project_id == Rails.application.config.apidae_project_id
|
19
|
+
export = Export.new(project_id: project_id, remote_status: params[:status], oneshot: params[:ponctuel] == 'true',
|
20
|
+
reset: params[:reinitialisation] == 'true', file_url: params[:urlRecuperation],
|
21
|
+
confirm_url: params[:urlConfirmation], status: Export::PENDING)
|
22
|
+
if export.save
|
23
|
+
render nothing: true, status: :ok
|
24
|
+
else
|
25
|
+
render nothing: true, status: :internal_server_error
|
26
|
+
end
|
27
|
+
else
|
28
|
+
render nothing: true, status: :not_found
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def run
|
33
|
+
success = true
|
34
|
+
Export.pending.each do |e|
|
35
|
+
open(e.file_url) do |f|
|
36
|
+
begin
|
37
|
+
FileImport.import(f)
|
38
|
+
Net::HTTP.post(e.confirm_url, '')
|
39
|
+
e.update(status: Export::COMPLETE)
|
40
|
+
rescue Exception => ex
|
41
|
+
logger.error("Failed to retrieve export file : #{ex.file_url}")
|
42
|
+
logger.error("Error is : #{ex}")
|
43
|
+
success = false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
render nothing: true, status: (success ? :ok : :internal_server_error)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'zip'
|
2
|
+
|
1
3
|
module Apidae
|
2
4
|
class FileImport < ActiveRecord::Base
|
3
5
|
|
@@ -9,61 +11,78 @@ module Apidae
|
|
9
11
|
DELETED_FILE = 'objets_supprimes.json'
|
10
12
|
SELECTIONS_FILE = 'selections.json'
|
11
13
|
|
12
|
-
def self.import(
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
def self.import(zip_file)
|
15
|
+
Zip::File.open(zip_file) do |zfile|
|
16
|
+
result = {created: 0, updated: 0, deleted: 0, selections: []}
|
17
|
+
zfile.each do |file|
|
18
|
+
if file.file? && file.name.end_with?('.json')
|
19
|
+
if file.name.include?(MODIFIED_DIR)
|
20
|
+
add_or_update_objects(zfile.read(file.name), result)
|
21
|
+
elsif file.name.include?(DELETED_FILE)
|
22
|
+
delete_objects(zfile.read(file.name), result)
|
23
|
+
elsif file.name.include?(SELECTIONS_FILE)
|
24
|
+
add_or_update_selections(zfile.read(file.name), result)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
puts "Import results : #{result}"
|
29
|
+
result
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.import_dir(dir)
|
34
|
+
result = {created: 0, updated: 0, deleted: 0, selections: []}
|
35
|
+
import_updates(File.join(dir, MODIFIED_DIR), result)
|
36
|
+
import_deletions(File.join(dir, DELETED_FILE), result)
|
37
|
+
import_selections(File.join(dir,SELECTIONS_FILE), result)
|
38
|
+
puts "Import results : #{result}"
|
39
|
+
result
|
22
40
|
end
|
23
41
|
|
24
|
-
def self.import_updates(json_dir)
|
25
|
-
result = {success: false, created: 0, updated: 0}
|
42
|
+
def self.import_updates(json_dir, result)
|
26
43
|
if Dir.exist?(json_dir)
|
27
44
|
Dir.foreach(json_dir) do |f|
|
28
45
|
if f.end_with?('.json')
|
29
46
|
json_file = File.join(json_dir, f)
|
30
47
|
objects_json = File.read(json_file)
|
31
|
-
|
32
|
-
objects_hashes.each do |object_data|
|
33
|
-
existing = Apidae::Object.find_by_apidae_id(object_data[:id])
|
34
|
-
if existing
|
35
|
-
Apidae::Object.update_object(existing, object_data)
|
36
|
-
result[:updated] += 1
|
37
|
-
else
|
38
|
-
Apidae::Object.add_object(object_data)
|
39
|
-
result[:created] += 1
|
40
|
-
end
|
41
|
-
end
|
48
|
+
add_or_update_objects(objects_json, result)
|
42
49
|
end
|
43
|
-
result[:success] = true
|
44
50
|
end
|
45
51
|
end
|
46
|
-
result
|
47
52
|
end
|
48
53
|
|
54
|
+
def self.add_or_update_objects(objects_json, result)
|
55
|
+
objects_hashes = JSON.parse(objects_json, symbolize_names: true)
|
56
|
+
objects_hashes.each do |object_data|
|
57
|
+
existing = Apidae::Object.find_by_apidae_id(object_data[:id])
|
58
|
+
if existing
|
59
|
+
Apidae::Object.update_object(existing, object_data)
|
60
|
+
result[:updated] += 1
|
61
|
+
else
|
62
|
+
Apidae::Object.add_object(object_data)
|
63
|
+
result[:created] += 1
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
49
67
|
|
50
|
-
def self.import_deletions(json_file)
|
51
|
-
result = {success: false, deleted: 0}
|
68
|
+
def self.import_deletions(json_file, result)
|
52
69
|
if File.exist?(json_file)
|
53
70
|
deleted_json = File.read(json_file)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
71
|
+
delete_objects(deleted_json, result)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.delete_objects(deleted_json, result)
|
76
|
+
deleted_ids = JSON.parse(deleted_json)
|
77
|
+
deleted_ids.each do |id|
|
78
|
+
obj = Apidae::Object.find_by_apidae_id(id)
|
79
|
+
if obj
|
80
|
+
obj.destroy!
|
81
|
+
result[:deleted] += 1
|
82
|
+
else
|
83
|
+
puts "skipping object deletion : #{id}"
|
63
84
|
end
|
64
|
-
result[:success] = true
|
65
85
|
end
|
66
|
-
result
|
67
86
|
end
|
68
87
|
|
69
88
|
def self.update_fields(json_dir)
|
@@ -104,13 +123,20 @@ module Apidae
|
|
104
123
|
end
|
105
124
|
end
|
106
125
|
|
107
|
-
def self.import_selections(json_file)
|
126
|
+
def self.import_selections(json_file, result)
|
108
127
|
selections_json = File.read(json_file)
|
128
|
+
add_or_update_selections(selections_json, result)
|
129
|
+
end
|
130
|
+
|
131
|
+
def self.add_or_update_selections(selections_json, result)
|
109
132
|
selections_hashes = JSON.parse(selections_json, symbolize_names: true)
|
133
|
+
deleted_ids = Apidae::Selection.all.collect {|sel| sel.apidae_id}.uniq - selections_hashes.collect {|sel| sel[:id]}
|
134
|
+
Apidae::Selection.where(apidae_id: deleted_ids).delete_all
|
110
135
|
selections_hashes.each do |selection_data|
|
111
136
|
Apidae::Selection.add_or_update(selection_data)
|
112
137
|
end
|
113
|
-
Apidae::Selection.all
|
138
|
+
result[:selections] = Apidae::Selection.all
|
139
|
+
.collect {|sel| {apidae_id: sel.apidae_id, reference: sel.reference, objects: sel.objects.count}}
|
114
140
|
end
|
115
141
|
end
|
116
142
|
end
|
@@ -5,6 +5,10 @@ module Apidae
|
|
5
5
|
MAX_COUNT = 100
|
6
6
|
MAX_LOOPS = 10
|
7
7
|
|
8
|
+
validates_presence_of :apidae_id, :reference
|
9
|
+
|
10
|
+
before_validation :generate_reference, on: :create
|
11
|
+
|
8
12
|
def self.add_or_update(selection_data)
|
9
13
|
apidae_sel = Apidae::Selection.where(apidae_id: selection_data[:id]).first_or_initialize
|
10
14
|
apidae_sel.label = selection_data[:nom]
|
@@ -85,5 +89,8 @@ module Apidae
|
|
85
89
|
end
|
86
90
|
end
|
87
91
|
|
92
|
+
def generate_reference
|
93
|
+
self.reference ||= (self.label.parameterize || self.apidae_id)
|
94
|
+
end
|
88
95
|
end
|
89
96
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
<%= render layout: "/layouts/#{Rails.application.config.apidae_layout}" do |styles| %>
|
2
|
+
<div id="apidae_header" class="<%= styles[:header] %>">
|
3
|
+
<h1 class="<%= styles[:h1] %>">Apidae</h1>
|
4
|
+
</div>
|
5
|
+
<div id="apidae_dashboard" class="<%= styles[:wrapper] %>">
|
6
|
+
<div id="apidae_imports_panel" class="<%= styles[:body] %>">
|
7
|
+
<h2 class="<%= styles[:h2] %>">Derniers imports</h2>
|
8
|
+
<table id="apidae_imports" class="<%= styles[:table] %>">
|
9
|
+
<thead>
|
10
|
+
<tr>
|
11
|
+
<th>Date</th>
|
12
|
+
<th>Fichier</th>
|
13
|
+
<th>Statut</th>
|
14
|
+
</tr>
|
15
|
+
</thead>
|
16
|
+
|
17
|
+
<tbody>
|
18
|
+
<% @last_imports.each do |import| %>
|
19
|
+
<tr>
|
20
|
+
<td><%= import.updated_at.strftime('Le %d/%m/%Y à %H:%M') if import.updated_at %></td>
|
21
|
+
<td><%= import.remote_file %></td>
|
22
|
+
<td><%= import.status %></td>
|
23
|
+
</tr>
|
24
|
+
<% end %>
|
25
|
+
<% if @last_imports.empty? %>
|
26
|
+
<tr>
|
27
|
+
<td colspan="3">Aucun import pour le moment.</td>
|
28
|
+
</tr>
|
29
|
+
<% end %>
|
30
|
+
</tbody>
|
31
|
+
</table>
|
32
|
+
</div>
|
33
|
+
<div id="apidae_navigation_panel" class="<%= styles[:body] %>">
|
34
|
+
<h2 class="<%= styles[:h2] %>">Données issues d'Apidae</h2>
|
35
|
+
<h3 class="<%= styles[:h3] %>"><%= link_to pluralize(@selections, 'sélection'), apidae.selections_path %></h3>
|
36
|
+
<h3 class="<%= styles[:h3] %>"><%= link_to pluralize(@objects, 'objet touristique', 'objets touristiques'), apidae.objects_path %></h3>
|
37
|
+
</div>
|
38
|
+
</div>
|
39
|
+
<% end %>
|
@@ -1,53 +1,30 @@
|
|
1
|
-
|
1
|
+
<%= render layout: "/layouts/#{Rails.application.config.apidae_layout}" do |styles| %>
|
2
|
+
<div id="apidae_header" class="<%= styles[:header] %>">
|
3
|
+
<h1 class="<%= styles[:h1] %>">Apidae - Objets touristiques</h1>
|
4
|
+
</div>
|
5
|
+
<div id="apidae_dashboard" class="<%= styles[:wrapper] %>">
|
6
|
+
<div id="apidae_imports_panel" class="<%= styles[:body] %>">
|
7
|
+
<table id="apidae_objects" class="<%= styles[:table] %>">
|
8
|
+
<thead>
|
9
|
+
<tr>
|
10
|
+
<th>Titre</th>
|
11
|
+
<th>Identifiant</th>
|
12
|
+
<th>Type</th>
|
13
|
+
<th>Mise à jour</th>
|
14
|
+
</tr>
|
15
|
+
</thead>
|
2
16
|
|
3
|
-
<
|
4
|
-
|
5
|
-
<
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
<th>Latitude</th>
|
18
|
-
<th>Longitude</th>
|
19
|
-
<th>Openings</th>
|
20
|
-
<th>Rates</th>
|
21
|
-
<th>Reservation</th>
|
22
|
-
<th colspan="3"></th>
|
23
|
-
</tr>
|
24
|
-
</thead>
|
25
|
-
|
26
|
-
<tbody>
|
27
|
-
<% @objects.each do |object| %>
|
28
|
-
<tr>
|
29
|
-
<td><%= object.address %></td>
|
30
|
-
<td><%= object.apidae_id %></td>
|
31
|
-
<td><%= object.apidae_type %></td>
|
32
|
-
<td><%= object.apidae_subtype %></td>
|
33
|
-
<td><%= object.title %></td>
|
34
|
-
<td><%= object.short_desc %></td>
|
35
|
-
<td><%= object.contact %></td>
|
36
|
-
<td><%= object.long_desc %></td>
|
37
|
-
<td><%= object.type_data %></td>
|
38
|
-
<td><%= object.latitude %></td>
|
39
|
-
<td><%= object.longitude %></td>
|
40
|
-
<td><%= object.openings %></td>
|
41
|
-
<td><%= object.rates %></td>
|
42
|
-
<td><%= object.reservation %></td>
|
43
|
-
<td><%= link_to 'Show', object %></td>
|
44
|
-
<td><%= link_to 'Edit', edit_object_path(object) %></td>
|
45
|
-
<td><%= link_to 'Destroy', object, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
46
|
-
</tr>
|
47
|
-
<% end %>
|
48
|
-
</tbody>
|
49
|
-
</table>
|
50
|
-
|
51
|
-
<br>
|
52
|
-
|
53
|
-
<%= link_to 'New Object', new_object_path %>
|
17
|
+
<tbody>
|
18
|
+
<% @objects.each do |object| %>
|
19
|
+
<tr>
|
20
|
+
<td><%= object.title %></td>
|
21
|
+
<td><%= object.apidae_id %></td>
|
22
|
+
<td><%= object.apidae_type %></td>
|
23
|
+
<td><%= object.updated_at.strftime('Le %d/%m/%Y à %H:%M') if object.updated_at %></td>
|
24
|
+
</tr>
|
25
|
+
<% end %>
|
26
|
+
</tbody>
|
27
|
+
</table>
|
28
|
+
</div>
|
29
|
+
</div>
|
30
|
+
<% end %>
|