ecoportal-api-v2 2.0.12 → 2.0.15
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/.gitignore +3 -0
- data/CHANGELOG.md +29 -3
- data/ecoportal-api-v2.gemspec +1 -1
- data/lib/ecoportal/api/common/content/array_model.rb +20 -3
- data/lib/ecoportal/api/common/content/class_helpers.rb +4 -2
- data/lib/ecoportal/api/common/content/client.rb +12 -6
- data/lib/ecoportal/api/common/content/collection_model/doc/items.rb +33 -0
- data/lib/ecoportal/api/common/content/collection_model/doc/rooted_key.rb +68 -0
- data/lib/ecoportal/api/common/content/collection_model/doc.rb +25 -0
- data/lib/ecoportal/api/common/content/collection_model/doc_mutation/delete.rb +33 -0
- data/lib/ecoportal/api/common/content/collection_model/doc_mutation/position.rb +42 -0
- data/lib/ecoportal/api/common/content/collection_model/doc_mutation/upsert.rb +45 -0
- data/lib/ecoportal/api/common/content/collection_model/doc_mutation.rb +27 -0
- data/lib/ecoportal/api/common/content/collection_model/model/cache.rb +44 -0
- data/lib/ecoportal/api/common/content/collection_model/model/items.rb +43 -0
- data/lib/ecoportal/api/common/content/collection_model/model/iterable.rb +44 -0
- data/lib/ecoportal/api/common/content/collection_model/model/lookup.rb +45 -0
- data/lib/ecoportal/api/common/content/collection_model/model/numeric_key.rb +40 -0
- data/lib/ecoportal/api/common/content/collection_model/model/var_tracking.rb +50 -0
- data/lib/ecoportal/api/common/content/collection_model/model.rb +33 -0
- data/lib/ecoportal/api/common/content/collection_model/modifiers/items_key.rb +57 -0
- data/lib/ecoportal/api/common/content/collection_model/modifiers/items_klass.rb +144 -0
- data/lib/ecoportal/api/common/content/collection_model/modifiers/items_order.rb +38 -0
- data/lib/ecoportal/api/common/content/collection_model/modifiers.rb +27 -0
- data/lib/ecoportal/api/common/content/collection_model/mutation/clear.rb +30 -0
- data/lib/ecoportal/api/common/content/collection_model/mutation/delete.rb +42 -0
- data/lib/ecoportal/api/common/content/collection_model/mutation/upsert.rb +56 -0
- data/lib/ecoportal/api/common/content/collection_model/mutation.rb +27 -0
- data/lib/ecoportal/api/common/content/collection_model.rb +19 -351
- data/lib/ecoportal/api/common/content/doc_helpers.rb +18 -16
- data/lib/ecoportal/api/common/content/double_model/attributable/base.rb +23 -0
- data/lib/ecoportal/api/common/content/double_model/attributable/enforce.rb +62 -0
- data/lib/ecoportal/api/common/content/double_model/attributable/nesting/cascaded_callback.rb +104 -0
- data/lib/ecoportal/api/common/content/double_model/attributable/nesting/embeddable.rb +76 -0
- data/lib/ecoportal/api/common/content/double_model/attributable/nesting/keyable.rb +119 -0
- data/lib/ecoportal/api/common/content/double_model/attributable/nesting.rb +136 -0
- data/lib/ecoportal/api/common/content/double_model/attributable/passthrough.rb +70 -0
- data/lib/ecoportal/api/common/content/double_model/attributable/simple.rb +48 -0
- data/lib/ecoportal/api/common/content/double_model/attributable.rb +30 -0
- data/lib/ecoportal/api/common/content/double_model/base.rb +29 -0
- data/lib/ecoportal/api/common/content/double_model/diffable_model.rb +43 -0
- data/lib/ecoportal/api/common/content/double_model/double_doc/base.rb +23 -0
- data/lib/ecoportal/api/common/content/double_model/double_doc/linkable_doc.rb +87 -0
- data/lib/ecoportal/api/common/content/double_model/double_doc/replaceable_doc.rb +61 -0
- data/lib/ecoportal/api/common/content/double_model/double_doc/reset_consolidate.rb +54 -0
- data/lib/ecoportal/api/common/content/double_model/double_doc/rooted_key.rb +49 -0
- data/lib/ecoportal/api/common/content/double_model/double_doc.rb +31 -0
- data/lib/ecoportal/api/common/content/double_model/hash_helpers.rb +40 -0
- data/lib/ecoportal/api/common/content/double_model/modifiers/read_only_able.rb +73 -0
- data/lib/ecoportal/api/common/content/double_model/modifiers/rootable.rb +64 -0
- data/lib/ecoportal/api/common/content/double_model/modifiers.rb +24 -0
- data/lib/ecoportal/api/common/content/double_model/parented.rb +22 -0
- data/lib/ecoportal/api/common/content/double_model/var_tracking.rb +45 -0
- data/lib/ecoportal/api/common/content/double_model.rb +28 -486
- data/lib/ecoportal/api/common/content/hash_diff_patch.rb +2 -1
- data/lib/ecoportal/api/common/content/includer.rb +16 -0
- data/lib/ecoportal/api/common/content/model_helpers.rb +14 -16
- data/lib/ecoportal/api/common/content.rb +1 -0
- data/lib/ecoportal/api/v2/page/component.rb +46 -46
- data/lib/ecoportal/api/v2/page/components.rb +2 -2
- data/lib/ecoportal/api/v2/page.rb +14 -14
- data/lib/ecoportal/api/v2/pages/page_stage/task.rb +2 -2
- data/lib/ecoportal/api/v2/pages/page_stage/tasks.rb +3 -3
- data/lib/ecoportal/api/v2/pages/page_stage.rb +8 -8
- data/lib/ecoportal/api/v2/pages/stages.rb +2 -2
- data/lib/ecoportal/api/v2/pages.rb +15 -15
- data/lib/ecoportal/api/v2/registers.rb +20 -19
- data/lib/ecoportal/api/v2/s3/files/batch_upload.rb +1 -0
- data/lib/ecoportal/api/v2/s3/files/poll.rb +5 -5
- data/lib/ecoportal/api/v2/s3/files/poll_status.rb +3 -3
- data/lib/ecoportal/api/v2/s3/files.rb +6 -6
- data/lib/ecoportal/api/v2/s3.rb +5 -5
- data/lib/ecoportal/api/v2.rb +18 -8
- data/lib/ecoportal/api/v2_version.rb +1 -1
- metadata +50 -4
@@ -5,35 +5,35 @@ module Ecoportal
|
|
5
5
|
class Component < Ecoportal::API::Common::Content::DoubleModel
|
6
6
|
extend Ecoportal::API::Common::Content::StringDigest
|
7
7
|
|
8
|
-
class_resolver :tag_field_class,
|
9
|
-
class_resolver :geo_field_class,
|
10
|
-
class_resolver :selection_field_class,
|
11
|
-
class_resolver :date_field_class,
|
12
|
-
class_resolver :number_field_class,
|
13
|
-
class_resolver :gauge_field_class,
|
14
|
-
class_resolver :plain_text_field_class,
|
15
|
-
class_resolver :rich_text_field_class,
|
16
|
-
class_resolver :people_field_class,
|
17
|
-
class_resolver :contractor_entities_field_class,
|
18
|
-
class_resolver :checklist_field_class,
|
19
|
-
class_resolver :action_field_class,
|
20
|
-
class_resolver :actions_field_class,
|
21
|
-
class_resolver :files_field_class,
|
22
|
-
class_resolver :images_field_class,
|
23
|
-
class_resolver :signature_field_class,
|
24
|
-
class_resolver :reference_field_class,
|
25
|
-
class_resolver :law_field_class,
|
26
|
-
class_resolver :mailbox_field_class,
|
27
|
-
class_resolver :chart_field_class,
|
28
|
-
class_resolver :chart_fr_field_class,
|
8
|
+
class_resolver :tag_field_class, 'Ecoportal::API::V2::Page::Component::TagField'
|
9
|
+
class_resolver :geo_field_class, 'Ecoportal::API::V2::Page::Component::GeoField'
|
10
|
+
class_resolver :selection_field_class, 'Ecoportal::API::V2::Page::Component::SelectionField'
|
11
|
+
class_resolver :date_field_class, 'Ecoportal::API::V2::Page::Component::DateField'
|
12
|
+
class_resolver :number_field_class, 'Ecoportal::API::V2::Page::Component::NumberField'
|
13
|
+
class_resolver :gauge_field_class, 'Ecoportal::API::V2::Page::Component::GaugeField'
|
14
|
+
class_resolver :plain_text_field_class, 'Ecoportal::API::V2::Page::Component::PlainTextField'
|
15
|
+
class_resolver :rich_text_field_class, 'Ecoportal::API::V2::Page::Component::RichTextField'
|
16
|
+
class_resolver :people_field_class, 'Ecoportal::API::V2::Page::Component::PeopleField'
|
17
|
+
class_resolver :contractor_entities_field_class, 'Ecoportal::API::V2::Page::Component::ContractorEntitiesField' # rubocop:disable Layout/LineLength
|
18
|
+
class_resolver :checklist_field_class, 'Ecoportal::API::V2::Page::Component::ChecklistField'
|
19
|
+
class_resolver :action_field_class, 'Ecoportal::API::V2::Page::Component::ActionField'
|
20
|
+
class_resolver :actions_field_class, 'Ecoportal::API::V2::Page::Component::ActionsField'
|
21
|
+
class_resolver :files_field_class, 'Ecoportal::API::V2::Page::Component::FilesField'
|
22
|
+
class_resolver :images_field_class, 'Ecoportal::API::V2::Page::Component::ImagesField'
|
23
|
+
class_resolver :signature_field_class, 'Ecoportal::API::V2::Page::Component::SignatureField'
|
24
|
+
class_resolver :reference_field_class, 'Ecoportal::API::V2::Page::Component::ReferenceField'
|
25
|
+
class_resolver :law_field_class, 'Ecoportal::API::V2::Page::Component::LawField'
|
26
|
+
class_resolver :mailbox_field_class, 'Ecoportal::API::V2::Page::Component::MailboxField'
|
27
|
+
class_resolver :chart_field_class, 'Ecoportal::API::V2::Page::Component::ChartField'
|
28
|
+
class_resolver :chart_fr_field_class, 'Ecoportal::API::V2::Page::Component::ChartFrField'
|
29
29
|
|
30
30
|
class << self
|
31
31
|
def new_doc(type: nil)
|
32
32
|
{
|
33
|
-
|
33
|
+
'id' => new_uuid
|
34
34
|
}.tap do |base_doc|
|
35
35
|
if type
|
36
|
-
base_doc.merge!({
|
36
|
+
base_doc.merge!({'type' => type})
|
37
37
|
if (klass = get_class(base_doc))
|
38
38
|
base_doc.merge!(klass.new_doc || {})
|
39
39
|
end
|
@@ -43,48 +43,48 @@ module Ecoportal
|
|
43
43
|
|
44
44
|
def get_class(doc) # rubocop:disable Metrics/AbcSize
|
45
45
|
return nil unless doc.is_a?(Hash)
|
46
|
-
case doc[
|
47
|
-
when
|
46
|
+
case doc['type']
|
47
|
+
when 'tag_field'
|
48
48
|
tag_field_class
|
49
|
-
when
|
49
|
+
when 'geo'
|
50
50
|
geo_field_class
|
51
|
-
when
|
51
|
+
when 'select'
|
52
52
|
selection_field_class
|
53
|
-
when
|
53
|
+
when 'date'
|
54
54
|
date_field_class
|
55
|
-
when
|
55
|
+
when 'number'
|
56
56
|
number_field_class
|
57
|
-
when
|
57
|
+
when 'gauge'
|
58
58
|
gauge_field_class
|
59
|
-
when
|
59
|
+
when 'plain_text'
|
60
60
|
plain_text_field_class
|
61
|
-
when
|
61
|
+
when 'rich_text'
|
62
62
|
rich_text_field_class
|
63
|
-
when
|
63
|
+
when 'people'
|
64
64
|
people_field_class
|
65
|
-
when
|
65
|
+
when 'contractor_entities'
|
66
66
|
contractor_entities_field_class
|
67
|
-
when
|
67
|
+
when 'checklist'
|
68
68
|
checklist_field_class
|
69
|
-
when
|
69
|
+
when 'page_action', 'checklist_task'
|
70
70
|
action_field_class
|
71
|
-
when
|
71
|
+
when 'actions_list'
|
72
72
|
actions_field_class
|
73
|
-
when
|
73
|
+
when 'file'
|
74
74
|
files_field_class
|
75
|
-
when
|
75
|
+
when 'image_gallery'
|
76
76
|
images_field_class
|
77
|
-
when
|
77
|
+
when 'signature'
|
78
78
|
signature_field_class
|
79
|
-
when
|
79
|
+
when 'cross_reference'
|
80
80
|
reference_field_class
|
81
|
-
when
|
81
|
+
when 'law'
|
82
82
|
law_field_class
|
83
|
-
when
|
83
|
+
when 'mailbox'
|
84
84
|
mailbox_field_class
|
85
|
-
when
|
85
|
+
when 'chart'
|
86
86
|
chart_field_class
|
87
|
-
when
|
87
|
+
when 'frequency_rate_chart'
|
88
88
|
chart_fr_field_class
|
89
89
|
else
|
90
90
|
self
|
@@ -113,7 +113,7 @@ module Ecoportal
|
|
113
113
|
digest = self.class.hash_label(label, any_length: any_length)
|
114
114
|
return unless digest
|
115
115
|
|
116
|
-
[type, digest].join(
|
116
|
+
[type, digest].join('.')
|
117
117
|
end
|
118
118
|
|
119
119
|
# Looks up the section that this component belongs to.
|
@@ -3,7 +3,7 @@ module Ecoportal
|
|
3
3
|
class V2
|
4
4
|
class Page
|
5
5
|
class Components < Ecoportal::API::Common::Content::CollectionModel
|
6
|
-
class_resolver :component_class,
|
6
|
+
class_resolver :component_class, 'Ecoportal::API::V2::Page::Component'
|
7
7
|
|
8
8
|
klass do |doc|
|
9
9
|
component_class.get_class(doc).tap do |klass|
|
@@ -50,7 +50,7 @@ module Ecoportal
|
|
50
50
|
# @yield [field] do some stuff with field
|
51
51
|
# @yieldparam [Ecoportal::API::V2::Page::Component] the created field
|
52
52
|
# @return [Ecoportal::API::V2::Page::Component] the created field.
|
53
|
-
def add(doc: nil, label: doc && doc[
|
53
|
+
def add(doc: nil, label: doc && doc['label'], type: doc && doc['type'])
|
54
54
|
fld_doc = doc ? JSON.parse(doc.to_json) : component_class.new_doc(type: type)
|
55
55
|
upsert!(fld_doc) do |fld|
|
56
56
|
fld.label = label unless doc
|
@@ -23,10 +23,10 @@ module Ecoportal
|
|
23
23
|
passdate :created_at, :updated_at, read_only: true
|
24
24
|
passthrough :can
|
25
25
|
|
26
|
-
class_resolver :components_class,
|
27
|
-
class_resolver :sections_class,
|
28
|
-
class_resolver :stages_class,
|
29
|
-
class_resolver :forces_class,
|
26
|
+
class_resolver :components_class, 'Ecoportal::API::V2::Page::Components'
|
27
|
+
class_resolver :sections_class, 'Ecoportal::API::V2::Page::Sections'
|
28
|
+
class_resolver :stages_class, 'Ecoportal::API::V2::Page::Stages'
|
29
|
+
class_resolver :forces_class, 'Ecoportal::API::V2::Page::Forces'
|
30
30
|
|
31
31
|
embeds_many :components, enum_class: :components_class
|
32
32
|
embeds_many :sections, enum_class: :sections_class
|
@@ -45,16 +45,16 @@ module Ecoportal
|
|
45
45
|
super.tap do |hash|
|
46
46
|
next unless hash
|
47
47
|
|
48
|
-
hash[
|
48
|
+
hash['data'].select! do |key, _value|
|
49
49
|
ALLOWED_KEYS.include?(key)
|
50
50
|
end
|
51
51
|
|
52
|
-
return nil if (hash[
|
52
|
+
return nil if (hash['data'].keys - ['patch_ver']).empty?
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
56
|
def stages?
|
57
|
-
doc[
|
57
|
+
doc['stages'] && stages.count.positive?
|
58
58
|
end
|
59
59
|
|
60
60
|
# @return [String] with feedback, if for this page instance, there are any of:
|
@@ -63,8 +63,8 @@ module Ecoportal
|
|
63
63
|
multi = components.multi_section
|
64
64
|
return true unless multi.length.positive?
|
65
65
|
|
66
|
-
msg =
|
67
|
-
msg <<
|
66
|
+
msg = ''
|
67
|
+
msg << 'There are fields attached to more than one section:'
|
68
68
|
msg << "\n • "
|
69
69
|
msg << multi.map(&:label).join("\n • ")
|
70
70
|
msg << "\n"
|
@@ -75,13 +75,13 @@ module Ecoportal
|
|
75
75
|
|
76
76
|
def _doc_bug_fix(hash)
|
77
77
|
hash.tap do
|
78
|
-
_fix_doc(hash[
|
78
|
+
_fix_doc(hash['stages'], 'flow_node_ids', 'section_ids') if hash.key?('stages')
|
79
79
|
|
80
|
-
next unless hash.key?(
|
80
|
+
next unless hash.key?('sections')
|
81
81
|
|
82
|
-
_fix_doc(hash[
|
83
|
-
_fix_doc(hash[
|
84
|
-
_fix_doc(hash[
|
82
|
+
_fix_doc(hash['sections'], 'membrane_ids', 'component_ids')
|
83
|
+
_fix_doc(hash['sections'], 'left_membrane_ids', 'left_component_ids')
|
84
|
+
_fix_doc(hash['sections'], 'right_membrane_ids', 'right_component_ids')
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
@@ -30,7 +30,7 @@ module Ecoportal
|
|
30
30
|
passthrough :view_type
|
31
31
|
|
32
32
|
def ooze
|
33
|
-
|
33
|
+
_parent.ooze
|
34
34
|
end
|
35
35
|
|
36
36
|
def fill_in?
|
@@ -43,7 +43,7 @@ module Ecoportal
|
|
43
43
|
|
44
44
|
def complete!(force: false)
|
45
45
|
return mark_as_submit(force: force) if fill_in?
|
46
|
-
|
46
|
+
mark_as_sign_off(force: force) if review?
|
47
47
|
end
|
48
48
|
|
49
49
|
private
|
@@ -4,17 +4,17 @@ module Ecoportal
|
|
4
4
|
class Pages
|
5
5
|
class PageStage
|
6
6
|
class Tasks < Ecoportal::API::Common::Content::CollectionModel
|
7
|
-
class_resolver :task_class,
|
7
|
+
class_resolver :task_class, 'Ecoportal::API::V2::Pages::PageStage::Task'
|
8
8
|
|
9
9
|
self.klass = :task_class
|
10
10
|
|
11
11
|
def ooze
|
12
|
-
|
12
|
+
_parent.ooze
|
13
13
|
end
|
14
14
|
|
15
15
|
# @return [Ecoportal::API::V2::Pages::PageStage::Task]
|
16
16
|
def get_by_id(id)
|
17
|
-
|
17
|
+
find do |task|
|
18
18
|
task.id == id
|
19
19
|
end
|
20
20
|
end
|
@@ -4,19 +4,19 @@ module Ecoportal
|
|
4
4
|
class Pages
|
5
5
|
class PageStage < V2::Page
|
6
6
|
passthrough :archive
|
7
|
-
embeds_one :mould_counter, klass:
|
7
|
+
embeds_one :mould_counter, klass: 'Ecoportal::API::V2::Page::MouldCounter'
|
8
8
|
passthrough :task_priority, :state, :status
|
9
9
|
passthrough :votes_enabled, :upvotes, :downvotes
|
10
10
|
|
11
|
-
class_resolver :tasks_class,
|
11
|
+
class_resolver :tasks_class, 'Ecoportal::API::V2::Pages::PageStage::Tasks'
|
12
12
|
embeds_many :tasks, enum_class: :tasks_class
|
13
13
|
|
14
|
-
#embeds_many :permits, klass:
|
14
|
+
#embeds_many :permits, klass: 'Ecoportal::API::V2::Page::Permit'
|
15
15
|
passarray :force_errors, :subtags, order_matters: false
|
16
16
|
|
17
17
|
# @return [Boolean] whether or not this entry has mould counter
|
18
18
|
def mould_counter?
|
19
|
-
!!doc[
|
19
|
+
!!doc['moult_counter']
|
20
20
|
end
|
21
21
|
|
22
22
|
# @return [String] unique id
|
@@ -29,7 +29,7 @@ module Ecoportal
|
|
29
29
|
|
30
30
|
# @return [String] `id` of the stage we got the data of.
|
31
31
|
def current_stage_id
|
32
|
-
doc.dig(
|
32
|
+
doc.dig('active_stage', 'id') || doc['current_stage_id']
|
33
33
|
end
|
34
34
|
|
35
35
|
# @return [Ecoportal::API::V2::Page::Stage]
|
@@ -44,18 +44,18 @@ module Ecoportal
|
|
44
44
|
# 2. orphaned sections (sections not belonging to any stage)
|
45
45
|
def validate # rubocop:disable Metrics/AbcSize
|
46
46
|
msg = super
|
47
|
-
msg =
|
47
|
+
msg = '' unless msg.is_a?(String)
|
48
48
|
|
49
49
|
orphans = components.unattached.select {|comp| comp.global_binding.to_s.strip.empty?}
|
50
50
|
if orphans.length.positive?
|
51
|
-
msg <<
|
51
|
+
msg << 'There are fields not attached to any sections:'
|
52
52
|
msg << "\n • "
|
53
53
|
msg << orphans.map(&:label).join("\n • ")
|
54
54
|
msg << "\n"
|
55
55
|
end
|
56
56
|
|
57
57
|
if (orphans = sections.unattached).length.positive?
|
58
|
-
msg <<
|
58
|
+
msg << 'There are sections not attached to any stage:'
|
59
59
|
msg << "\n • "
|
60
60
|
msg << orphans.map do |sec|
|
61
61
|
"'#{sec.heading}' (#{sec.id})"
|
@@ -10,7 +10,7 @@ module Ecoportal
|
|
10
10
|
extend Ecoportal::API::Common::BaseClass
|
11
11
|
include Ecoportal::API::Common::Content::DocHelpers
|
12
12
|
|
13
|
-
class_resolver :page_stage_class,
|
13
|
+
class_resolver :page_stage_class, 'Ecoportal::API::V2::Pages::PageStage'
|
14
14
|
|
15
15
|
attr_reader :client
|
16
16
|
|
@@ -39,7 +39,7 @@ module Ecoportal
|
|
39
39
|
# @param id [String, nil] the `id` of the target **page**.
|
40
40
|
# @param stage_id [String] the `id` of the target **stage**.
|
41
41
|
# @return [Response] an object with the api response.
|
42
|
-
def update(doc, id: nil
|
42
|
+
def update(doc, stage_id:, id: nil)
|
43
43
|
body = get_body(doc)
|
44
44
|
id ||= get_id(doc)
|
45
45
|
path = "/pages/#{CGI.escape(id)}/stages/#{CGI.escape(stage_id)}/"
|
@@ -4,14 +4,14 @@ module Ecoportal
|
|
4
4
|
# @attr_reader client [Ecoportal::API::Common::Client] a `Ecoportal::API::Common::Client`
|
5
5
|
# object that holds the configuration of the api connection.
|
6
6
|
class Pages
|
7
|
-
STAGE_REX = /stages\/(?<sid>.*)
|
7
|
+
STAGE_REX = /stages\/(?<sid>.*)/
|
8
8
|
extend Ecoportal::API::Common::BaseClass
|
9
9
|
include Ecoportal::API::Common::Content::DocHelpers
|
10
10
|
|
11
|
-
class_resolver :stages_class,
|
12
|
-
class_resolver :page_class,
|
13
|
-
class_resolver :page_stage_class,
|
14
|
-
class_resolver :create_page_response_class,
|
11
|
+
class_resolver :stages_class, 'Ecoportal::API::V2::Pages::Stages'
|
12
|
+
class_resolver :page_class, 'Ecoportal::API::V2::Page'
|
13
|
+
class_resolver :page_stage_class, 'Ecoportal::API::V2::Pages::PageStage'
|
14
|
+
class_resolver :create_page_response_class, 'Ecoportal::API::V2::Pages::PageCreateResponse'
|
15
15
|
|
16
16
|
attr_reader :client
|
17
17
|
|
@@ -45,7 +45,7 @@ module Ecoportal
|
|
45
45
|
return wrapped.result if wrapped.success?
|
46
46
|
|
47
47
|
url = nil
|
48
|
-
url = response.body[
|
48
|
+
url = response.body['data'] if response.status == 302
|
49
49
|
stage_id = url_to_stage_id(url) unless url.nil?
|
50
50
|
|
51
51
|
return stages.get(id: id, stage_id: stage_id) if stage_id
|
@@ -63,9 +63,9 @@ module Ecoportal
|
|
63
63
|
return stages.update(doc, stage_id: stage_id)
|
64
64
|
end
|
65
65
|
|
66
|
-
body = get_body(doc) # , level:
|
66
|
+
body = get_body(doc) # , level: 'page'
|
67
67
|
# Launch only if there are changes
|
68
|
-
raise
|
68
|
+
raise 'Missing page object' unless body && body['page']
|
69
69
|
|
70
70
|
id = get_id(doc)
|
71
71
|
|
@@ -77,7 +77,7 @@ module Ecoportal
|
|
77
77
|
# @return [Ecoportal::API::V2::Page] the new page object.
|
78
78
|
def get_new(from)
|
79
79
|
id = get_id(from)
|
80
|
-
response = client.get(
|
80
|
+
response = client.get('/pages/new', params: {template_id: id})
|
81
81
|
wrapped = Ecoportal::API::Common::Content::WrappedResponse.new(
|
82
82
|
response,
|
83
83
|
page_stage_class
|
@@ -94,15 +94,15 @@ module Ecoportal
|
|
94
94
|
def create(doc, from:)
|
95
95
|
id = get_id(from)
|
96
96
|
body = get_body(doc).tap do |hash|
|
97
|
-
unless hash[
|
98
|
-
hash[
|
99
|
-
|
100
|
-
|
101
|
-
|
97
|
+
unless hash['page']
|
98
|
+
hash['page'] = {
|
99
|
+
'id' => '111111111111111111111111',
|
100
|
+
'operation' => 'changed',
|
101
|
+
'data' => {'patch_ver' => 0}
|
102
102
|
}
|
103
103
|
end
|
104
104
|
end
|
105
|
-
response = client.post(
|
105
|
+
response = client.post('/pages', data: body, params: {template_id: id})
|
106
106
|
wrapped = Ecoportal::API::Common::Content::WrappedResponse.new(
|
107
107
|
response,
|
108
108
|
create_page_response_class
|
@@ -9,9 +9,9 @@ module Ecoportal
|
|
9
9
|
include Ecoportal::API::Common::Content::DocHelpers
|
10
10
|
include Enumerable
|
11
11
|
|
12
|
-
class_resolver :register_class,
|
13
|
-
class_resolver :register_search_result_class,
|
14
|
-
class_resolver :register_search_results,
|
12
|
+
class_resolver :register_class, 'Ecoportal::API::V2::Registers::Register'
|
13
|
+
class_resolver :register_search_result_class, 'Ecoportal::API::V2::Registers::PageResult'
|
14
|
+
class_resolver :register_search_results, 'Ecoportal::API::V2::Registers::SearchResults'
|
15
15
|
|
16
16
|
attr_reader :client
|
17
17
|
|
@@ -31,11 +31,11 @@ module Ecoportal
|
|
31
31
|
# Gets all the registers via api request.
|
32
32
|
# @return [Enumerable<Register>] an `Enumerable` with all schemas already wrapped as `Register` objects.
|
33
33
|
def get
|
34
|
-
response = client.get(
|
34
|
+
response = client.get('/templates')
|
35
35
|
Ecoportal::API::Common::Content::WrappedResponse.new(
|
36
36
|
response,
|
37
37
|
register_class,
|
38
|
-
key:
|
38
|
+
key: 'registers'
|
39
39
|
)
|
40
40
|
end
|
41
41
|
|
@@ -44,7 +44,8 @@ module Ecoportal
|
|
44
44
|
# @param options [Hash] the search options
|
45
45
|
# @option options [Hash<Symbol, String>] :query plain search (like the search box in register).
|
46
46
|
# @option options [Hash<Symbol, Array<Object>>] :filters the set of filters.
|
47
|
-
# @option options [Boolean] if `true`, it only performs the first search and
|
47
|
+
# @option options [Boolean] if `true`, it only performs the first search and
|
48
|
+
# results `Ecoportal::API::V2::Registers::SearchResults`.
|
48
49
|
# @yield [result] something to do with search page-result.
|
49
50
|
# @yieldparam result [Ecoportal::V2::Registers::PageResult] a page result.
|
50
51
|
# @return [Ecoportal::API::V2::Registers, Ecoportal::API::V2::Registers::SearchResults]
|
@@ -56,7 +57,7 @@ module Ecoportal
|
|
56
57
|
response = client.get("/registers/#{register_id}/search", params: options)
|
57
58
|
raise "Request failed - Status #{response.status}: #{response.body}" unless response.success?
|
58
59
|
|
59
|
-
return register_search_results.new(response.body[
|
60
|
+
return register_search_results.new(response.body['data'])
|
60
61
|
end
|
61
62
|
|
62
63
|
cursor_id = nil
|
@@ -68,34 +69,34 @@ module Ecoportal
|
|
68
69
|
response = client.get("/registers/#{register_id}/search", params: options)
|
69
70
|
raise "Request failed - Status #{response.status}: #{response.body}" unless response.success?
|
70
71
|
|
71
|
-
data = response.body[
|
72
|
-
total ||= data[
|
73
|
-
if total != data[
|
74
|
-
msg =
|
75
|
-
msg <<
|
72
|
+
data = response.body['data']
|
73
|
+
total ||= data['total']
|
74
|
+
if total != data['total']
|
75
|
+
msg = 'Change of total in search results. '
|
76
|
+
msg << 'Probably due to changes that affect the filter'
|
76
77
|
msg << "(register: #{register_id}):"
|
77
78
|
print_search_status(msg, total, results, cursor_id, data, options)
|
78
|
-
#total = data[
|
79
|
+
#total = data['total']
|
79
80
|
end
|
80
81
|
|
81
82
|
unless total&.zero?
|
82
|
-
results += data[
|
83
|
+
results += data['results'].length
|
83
84
|
print_progress(results, total)
|
84
85
|
end
|
85
86
|
|
86
|
-
data[
|
87
|
+
data['results'].each do |result|
|
87
88
|
object = register_search_result_class.new(result)
|
88
89
|
yield object
|
89
90
|
end
|
90
91
|
|
91
92
|
break if total <= results
|
92
93
|
|
93
|
-
unless data[
|
94
|
-
msg =
|
94
|
+
unless data['cursor_id']
|
95
|
+
msg = 'Possible error... finishing search for lack of cursor_id in response:'
|
95
96
|
print_search_status(msg, total, results, cursor_id, data, options)
|
96
97
|
end
|
97
98
|
|
98
|
-
break unless (cursor_id = data[
|
99
|
+
break unless (cursor_id = data['cursor_id'])
|
99
100
|
end
|
100
101
|
|
101
102
|
self
|
@@ -133,7 +134,7 @@ module Ecoportal
|
|
133
134
|
|
134
135
|
def print_progress(results, total)
|
135
136
|
percent = results * 100 / total
|
136
|
-
msg =
|
137
|
+
msg = 'Registers SEARCH'
|
137
138
|
print "#{msg}: #{percent.round}% (of #{total})\r"
|
138
139
|
$stdout.flush
|
139
140
|
end
|
@@ -42,6 +42,7 @@ module Ecoportal
|
|
42
42
|
bench = benchmarking && benchmark_enabled?
|
43
43
|
bench_mth = "#{self.class}##{__method__}"
|
44
44
|
thr_children = []
|
45
|
+
|
45
46
|
benchmarking("#{bench_mth}.#{files.count}_files", print: bench) do
|
46
47
|
with_preserved_thread_globals(report: false) do
|
47
48
|
files.each do |file|
|
@@ -5,7 +5,7 @@ module Ecoportal
|
|
5
5
|
class Files
|
6
6
|
class Poll < Ecoportal::API::Common::Content::DoubleModel
|
7
7
|
passthrough :poll_url
|
8
|
-
embeds_one :status, nullable: true, klass:
|
8
|
+
embeds_one :status, nullable: true, klass: 'Ecoportal::API::V2::S3::Files::PollStatus'
|
9
9
|
|
10
10
|
def poll_id
|
11
11
|
return @poll_id if instance_variable_defined?(:@poll_id)
|
@@ -29,17 +29,17 @@ module Ecoportal
|
|
29
29
|
def status=(value)
|
30
30
|
case value
|
31
31
|
when NilClass
|
32
|
-
doc[
|
32
|
+
doc['status'] = nil
|
33
33
|
when Ecoportal::API::V2::S3::Files::PollStatus
|
34
|
-
doc[
|
34
|
+
doc['status'] = JSON.parse(value.to_json)
|
35
35
|
when Hash
|
36
|
-
doc[
|
36
|
+
doc['status'] = value
|
37
37
|
else
|
38
38
|
# TODO
|
39
39
|
raise "Invalid set on status: Need nil, PollStatus or Hash; got #{value.class}"
|
40
40
|
end
|
41
41
|
|
42
|
-
remove_instance_variable(
|
42
|
+
remove_instance_variable('@status') if defined?(@status)
|
43
43
|
end
|
44
44
|
|
45
45
|
def pending?
|
@@ -34,15 +34,15 @@ module Ecoportal
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def pending?
|
37
|
-
status ==
|
37
|
+
status == 'pending'
|
38
38
|
end
|
39
39
|
|
40
40
|
def success?
|
41
|
-
status ==
|
41
|
+
status == 'success'
|
42
42
|
end
|
43
43
|
|
44
44
|
def failed?
|
45
|
-
status ==
|
45
|
+
status == 'failed'
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -13,8 +13,8 @@ module Ecoportal
|
|
13
13
|
POLL_TIMEOUT = 240
|
14
14
|
DELAY_STATUS_CHECK = 5
|
15
15
|
|
16
|
-
class_resolver :poll_class,
|
17
|
-
class_resolver :poll_status_class,
|
16
|
+
class_resolver :poll_class, 'Ecoportal::API::V2::S3::Files::Poll'
|
17
|
+
class_resolver :poll_status_class, 'Ecoportal::API::V2::S3::Files::PollStatus'
|
18
18
|
|
19
19
|
attr_reader :client, :s3_api
|
20
20
|
|
@@ -48,7 +48,7 @@ module Ecoportal
|
|
48
48
|
check_delay: DELAY_STATUS_CHECK,
|
49
49
|
raise_timeout: false
|
50
50
|
)
|
51
|
-
raise ArgumentError,
|
51
|
+
raise ArgumentError, 'Block required. None given' unless block_given?
|
52
52
|
|
53
53
|
poll = create_poll(s3_file_reference)
|
54
54
|
yield(poll) if block_given?
|
@@ -72,7 +72,7 @@ module Ecoportal
|
|
72
72
|
# @param s3_file_reference [Hash]
|
73
73
|
# @return [Ecoportal::API::V2::S3::Files::Poll, NilClass]
|
74
74
|
def create_poll(s3_file_reference)
|
75
|
-
response = client.post(
|
75
|
+
response = client.post('/s3/files', data: s3_file_reference)
|
76
76
|
body = body_data(response.body)
|
77
77
|
|
78
78
|
return poll_class.new(body) if response.success?
|
@@ -100,9 +100,9 @@ module Ecoportal
|
|
100
100
|
|
101
101
|
def body_data(body)
|
102
102
|
return body unless body.is_a?(Hash)
|
103
|
-
return body unless body.key?(
|
103
|
+
return body unless body.key?('data')
|
104
104
|
|
105
|
-
body[
|
105
|
+
body['data']
|
106
106
|
end
|
107
107
|
|
108
108
|
# @note timeout library is evil. So we make poor-man timeout.
|
data/lib/ecoportal/api/v2/s3.rb
CHANGED
@@ -8,8 +8,8 @@ module Ecoportal
|
|
8
8
|
|
9
9
|
extend Ecoportal::API::Common::BaseClass
|
10
10
|
|
11
|
-
class_resolver :data_class,
|
12
|
-
class_resolver :files_class,
|
11
|
+
class_resolver :data_class, 'Ecoportal::API::V2::S3::Data'
|
12
|
+
class_resolver :files_class, 'Ecoportal::API::V2::S3::Files'
|
13
13
|
|
14
14
|
attr_reader :client
|
15
15
|
|
@@ -23,7 +23,7 @@ module Ecoportal
|
|
23
23
|
# Gets the S3 credentials to upload files
|
24
24
|
# @return [Ecoportal::API::V2::S3::Data]
|
25
25
|
def data
|
26
|
-
response = client.get(
|
26
|
+
response = client.get('/s3/data')
|
27
27
|
body = body_data(response.body)
|
28
28
|
|
29
29
|
return data_class.new(body) if response.success?
|
@@ -53,9 +53,9 @@ module Ecoportal
|
|
53
53
|
|
54
54
|
def body_data(body)
|
55
55
|
return body unless body.is_a?(Hash)
|
56
|
-
return body unless body.key?(
|
56
|
+
return body unless body.key?('data')
|
57
57
|
|
58
|
-
body[
|
58
|
+
body['data']
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|