labimotion 2.3.4 → 2.4.0.rc1
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/CHANGELOG.md +0 -39
- data/lib/labimotion/apis/element_variation_api.rb +3 -58
- data/lib/labimotion/apis/exporter_api.rb +19 -2
- data/lib/labimotion/apis/generic_dataset_api.rb +1 -3
- data/lib/labimotion/apis/generic_element_api.rb +38 -14
- data/lib/labimotion/apis/segment_api.rb +1 -5
- data/lib/labimotion/collection/import.rb +3 -36
- data/lib/labimotion/constants.rb +0 -6
- data/lib/labimotion/entities/application_entity.rb +1 -5
- data/lib/labimotion/entities/generic_klass_entity.rb +0 -11
- data/lib/labimotion/entities/properties_entity.rb +28 -0
- data/lib/labimotion/helpers/element_helpers.rb +9 -37
- data/lib/labimotion/helpers/generic_helpers.rb +4 -9
- data/lib/labimotion/helpers/param_helpers.rb +1 -0
- data/lib/labimotion/libs/converter.rb +23 -100
- data/lib/labimotion/libs/dataset_builder.rb +1 -1
- data/lib/labimotion/libs/linked_element.rb +193 -0
- data/lib/labimotion/libs/nmr_mapper.rb +4 -34
- data/lib/labimotion/models/concerns/attachment_converter.rb +0 -24
- data/lib/labimotion/models/concerns/datasetable.rb +5 -16
- data/lib/labimotion/models/concerns/element_fetchable.rb +2 -3
- data/lib/labimotion/models/concerns/segmentable.rb +5 -24
- data/lib/labimotion/models/element.rb +2 -3
- data/lib/labimotion/utils/mapper_utils.rb +5 -30
- data/lib/labimotion/utils/prop.rb +0 -8
- data/lib/labimotion/utils/units.rb +32 -67
- data/lib/labimotion/version.rb +1 -1
- data/lib/labimotion.rb +1 -13
- metadata +5 -26
- data/lib/labimotion/helpers/export_authorization_helpers.rb +0 -39
- data/lib/labimotion/libs/element_variation_column_set.rb +0 -426
- data/lib/labimotion/libs/element_variation_header.rb +0 -119
- data/lib/labimotion/libs/export_element_variations.rb +0 -245
- data/lib/labimotion/libs/export_tpa_segments.rb +0 -53
- data/lib/labimotion/libs/import_element_variations.rb +0 -411
- data/lib/labimotion/libs/klass_version.rb +0 -66
- data/lib/labimotion/libs/release_metadata.rb +0 -64
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'active_support/core_ext/object/blank'
|
|
4
|
-
|
|
5
|
-
module Labimotion
|
|
6
|
-
# Resolves which release of a template a saved element, segment or dataset follows, as
|
|
7
|
-
# the pair [klass_uuid, properties_release]. The submitted properties carry the klass_uuid
|
|
8
|
-
# they were built on; it counts when it is the klass's current release or one of its
|
|
9
|
-
# revisions, so a copy of an older record keeps that release instead of being relabelled.
|
|
10
|
-
module KlassVersion
|
|
11
|
-
# A new record without a known release, such as a new empty one, follows the current release.
|
|
12
|
-
# A copy of a record from an instance with releases of its own names a klass_uuid this one
|
|
13
|
-
# cannot resolve; it keeps the release the client sent only when that release names the same uuid.
|
|
14
|
-
def self.for_create(klass, revisions, submitted_uuid, client_release: nil)
|
|
15
|
-
uuid = string_uuid(submitted_uuid)
|
|
16
|
-
release = release_of(klass, revisions, uuid)
|
|
17
|
-
return [uuid, release] if release
|
|
18
|
-
return [uuid, client_release] if uuid.present? && release_uuid(client_release) == uuid
|
|
19
|
-
|
|
20
|
-
[klass.uuid, klass.properties_release]
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# An existing record keeps its stored klass_uuid when none is submitted, then the uuid its
|
|
24
|
-
# stored release names, and follows the current release only when it has neither. A klass_uuid
|
|
25
|
-
# this instance cannot resolve (a record imported from elsewhere) keeps the release stored with it.
|
|
26
|
-
def self.for_update(klass, revisions, submitted_uuid, record)
|
|
27
|
-
uuid = string_uuid(submitted_uuid).presence || record.klass_uuid.presence
|
|
28
|
-
if uuid.nil?
|
|
29
|
-
stored_uuid = release_uuid(record.properties_release)
|
|
30
|
-
return [stored_uuid, record.properties_release] if stored_uuid
|
|
31
|
-
|
|
32
|
-
return [klass.uuid, klass.properties_release]
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
release = release_of(klass, revisions, uuid) || record.properties_release.presence
|
|
36
|
-
[uuid, release || klass.properties_release]
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
# for_update when the record exists, for_create when it is nil.
|
|
40
|
-
def self.for_record(klass, revisions, submitted_uuid, record, client_release: nil)
|
|
41
|
-
return for_create(klass, revisions, submitted_uuid, client_release: client_release) if record.nil?
|
|
42
|
-
|
|
43
|
-
for_update(klass, revisions, submitted_uuid, record)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# Revisions are soft-deleted, and deleting one does not change which release the records
|
|
47
|
-
# built on it follow, so a deleted revision still answers here.
|
|
48
|
-
def self.release_of(klass, revisions, uuid)
|
|
49
|
-
return if uuid.blank?
|
|
50
|
-
return klass.properties_release if uuid == klass.uuid
|
|
51
|
-
|
|
52
|
-
revisions.with_deleted.where(uuid: uuid).order(id: :desc).pick(:properties_release)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
# Every release hash carries the uuid of the release it describes; nil when it names none.
|
|
56
|
-
def self.release_uuid(release)
|
|
57
|
-
release.is_a?(Hash) ? string_uuid(release['uuid']).presence : nil
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
# properties is a free-form hash, so klass_uuid can arrive as an array or a number; either
|
|
61
|
-
# would turn the revision lookup into a query matching more than the record's own release.
|
|
62
|
-
def self.string_uuid(submitted_uuid)
|
|
63
|
-
submitted_uuid.is_a?(String) ? submitted_uuid : nil
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# `underscore`, `constantize` and `index_by` are ActiveSupport core extensions, not plain
|
|
4
|
-
# Ruby. A booted host always has them; declaring them here keeps this file from depending on
|
|
5
|
-
# load order.
|
|
6
|
-
require 'active_support/core_ext/enumerable'
|
|
7
|
-
require 'active_support/core_ext/string/inflections'
|
|
8
|
-
|
|
9
|
-
module Labimotion
|
|
10
|
-
## ReleaseMetadata
|
|
11
|
-
# Each klass's metadata as of its active release, for the `metadata_releases:` option the
|
|
12
|
-
# klass entities read and for records the gem builds itself. The klass row's own `metadata`
|
|
13
|
-
# follows every save, drafts included, so a record built from `properties_release` needs the
|
|
14
|
-
# copy kept on the revision.
|
|
15
|
-
# The active revision is the one whose uuid equals the klass's, which changes only on release.
|
|
16
|
-
class ReleaseMetadata
|
|
17
|
-
# A klass with no revision matching its uuid (never released, or imported without one)
|
|
18
|
-
# is left out of the map, and the entity reads it as nil.
|
|
19
|
-
def self.map_for(klasses)
|
|
20
|
-
Array(klasses).compact.group_by(&:class).each_with_object({}) do |(model, group), map|
|
|
21
|
-
map.merge!(map_for_family(model, group))
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# The metadata a record built from the klass's `properties_release` stores: the active
|
|
26
|
-
# release's, or the klass's own when no revision matches its uuid. A failed lookup also
|
|
27
|
-
# falls back to the klass's own, so building the record never fails on it.
|
|
28
|
-
def self.for_klass(klass)
|
|
29
|
-
map_for([klass])[key_of(klass)] || klass.metadata || {}
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# Family as well as id: a segment klass payload nests its element klass, and ids repeat
|
|
33
|
-
# across the klass tables.
|
|
34
|
-
def self.key_of(klass)
|
|
35
|
-
"#{klass.class.name.split('::').last}:#{klass.id}"
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def self.map_for_family(model, klasses)
|
|
39
|
-
by_pair = klasses.reject { |klass| klass.uuid.nil? }.index_by { |klass| [klass.id, klass.uuid] }
|
|
40
|
-
return {} if by_pair.empty?
|
|
41
|
-
|
|
42
|
-
revisions_for(model, by_pair.keys).each_with_object({}) do |(klass_id, uuid, metadata), map|
|
|
43
|
-
# The IN lists cross-match: a revision of one listed klass can carry the uuid of
|
|
44
|
-
# another. Only the exact pair is that klass's active release.
|
|
45
|
-
klass = by_pair[[klass_id, uuid]]
|
|
46
|
-
map[key_of(klass)] = metadata unless klass.nil?
|
|
47
|
-
end
|
|
48
|
-
rescue StandardError => e
|
|
49
|
-
# The release metadata is an addition to a list that must still render, and a failing
|
|
50
|
-
# family must not blank the families that resolved. A record builder falls back too.
|
|
51
|
-
Labimotion.log_exception(e)
|
|
52
|
-
{}
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
# The revision model and its foreign key are named after the klass model.
|
|
56
|
-
def self.revisions_for(model, pairs)
|
|
57
|
-
foreign_key = "#{model.name.underscore.split('/').last}_id"
|
|
58
|
-
"#{model.name}esRevision".constantize
|
|
59
|
-
.where(foreign_key => pairs.map(&:first), uuid: pairs.map(&:last))
|
|
60
|
-
.pluck(foreign_key, :uuid, :metadata)
|
|
61
|
-
end
|
|
62
|
-
private_class_method :map_for_family, :revisions_for
|
|
63
|
-
end
|
|
64
|
-
end
|