caruby-tissue 1.5.6 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +17 -0
- data/History.md +5 -1
- data/README.md +2 -2
- data/bin/crtdump +2 -8
- data/bin/crtexample +2 -5
- data/bin/crtmigrate +3 -6
- data/bin/crtsmoke +3 -8
- data/conf/wustl/{log4j.properties → linux/log4j.properties} +3 -3
- data/conf/wustl/windows/log4j.properties +40 -0
- data/examples/galena/Gemfile +16 -0
- data/examples/galena/Gemfile.lock +88 -0
- data/examples/galena/README.md +16 -16
- data/examples/galena/Rakefile +30 -0
- data/examples/galena/bin/seed +5 -11
- data/examples/galena/conf/annotation/defaults.yaml +2 -0
- data/examples/galena/conf/{migration/annotation_fields.yaml → annotation/fields.yaml} +2 -4
- data/examples/galena/conf/defaults.yaml +9 -0
- data/examples/galena/conf/{migration/filter_fields.yaml → filter/fields.yaml} +0 -1
- data/examples/galena/conf/filter/values.yaml +8 -0
- data/examples/galena/conf/{migration/frozen_defaults.yaml → frozen/defaults.yaml} +0 -0
- data/examples/galena/conf/{migration/frozen_fields.yaml → frozen/fields.yaml} +0 -2
- data/examples/galena/conf/{migration/general_fields.yaml → general/fields.yaml} +0 -24
- data/examples/galena/conf/registration/fields.yaml +6 -0
- data/examples/galena/conf/{migration/simple_fields.yaml → simple/fields.yaml} +1 -6
- data/examples/galena/data/annotation.csv +1 -1
- data/examples/galena/data/filter.csv +1 -1
- data/examples/galena/data/frozen.csv +1 -1
- data/examples/galena/data/general.csv +1 -1
- data/examples/galena/data/registration.csv +1 -1
- data/examples/galena/data/simple.csv +1 -1
- data/examples/galena/galena.gemspec +24 -0
- data/examples/galena/lib/galena/filter.rb +25 -0
- data/examples/galena/lib/galena/{tissue/migration/frozen_shims.rb → frozen.rb} +6 -10
- data/examples/galena/lib/galena/seed.rb +126 -0
- data/examples/galena/lib/galena/version.rb +3 -0
- data/examples/galena/lib/galena.rb +18 -7
- data/examples/galena/log/galena.log +37351 -0
- data/examples/galena/log/galena.log.0 +147830 -0
- data/examples/galena/spec/annotation_spec.rb +46 -0
- data/examples/galena/spec/filter_spec.rb +94 -0
- data/examples/galena/spec/frozen_spec.rb +39 -0
- data/examples/galena/spec/general_spec.rb +62 -0
- data/examples/galena/spec/registration_spec.rb +37 -0
- data/examples/galena/spec/seed.rb +107 -0
- data/examples/galena/spec/simple_spec.rb +58 -0
- data/examples/galena/spec/spec_helper.rb +11 -0
- data/examples/galena/spec/support/migration.rb +70 -0
- data/lib/catissue/annotation/annotatable.rb +10 -8
- data/lib/catissue/annotation/annotation.rb +7 -7
- data/lib/catissue/annotation/de_integration.rb +9 -20
- data/lib/catissue/annotation/importer.rb +148 -0
- data/lib/catissue/annotation/introspector.rb +32 -0
- data/lib/catissue/annotation/metadata.rb +422 -0
- data/lib/catissue/annotation/proxy.rb +2 -2
- data/lib/catissue/annotation/proxy_class.rb +45 -30
- data/lib/catissue/annotation/record_entry_proxy.rb +2 -2
- data/lib/catissue/cli/command.rb +14 -24
- data/lib/catissue/cli/example.rb +5 -3
- data/lib/catissue/cli/migrate.rb +45 -37
- data/lib/catissue/cli/smoke.rb +2 -3
- data/lib/catissue/database/annotation/annotation_service.rb +8 -17
- data/lib/catissue/database/annotation/entity_facade.rb +33 -30
- data/lib/catissue/database/annotation/id_generator.rb +1 -1
- data/lib/catissue/database/annotation/integration_service.rb +11 -4
- data/lib/catissue/database/annotation/reference_writer.rb +38 -38
- data/lib/catissue/database/controlled_value_finder.rb +13 -28
- data/lib/catissue/database/controlled_values.rb +73 -45
- data/lib/catissue/database.rb +637 -277
- data/lib/catissue/domain/abstract_domain_object.rb +5 -0
- data/lib/catissue/domain/abstract_position.rb +3 -5
- data/lib/catissue/domain/abstract_specimen.rb +79 -65
- data/lib/catissue/domain/abstract_specimen_collection_group.rb +3 -6
- data/lib/catissue/domain/address.rb +0 -2
- data/lib/catissue/domain/cancer_research_group.rb +0 -3
- data/lib/catissue/domain/capacity.rb +2 -4
- data/lib/catissue/domain/check_in_check_out_event_parameter.rb +0 -3
- data/lib/catissue/domain/collection_event_parameters.rb +2 -7
- data/lib/catissue/domain/collection_protocol.rb +11 -16
- data/lib/catissue/domain/collection_protocol_event.rb +19 -12
- data/lib/catissue/domain/collection_protocol_registration.rb +8 -12
- data/lib/catissue/domain/consent_tier_response.rb +0 -4
- data/lib/catissue/domain/consent_tier_status.rb +1 -4
- data/lib/catissue/domain/container.rb +10 -10
- data/lib/catissue/domain/container_position.rb +4 -7
- data/lib/catissue/domain/container_type.rb +4 -7
- data/lib/catissue/domain/department.rb +0 -3
- data/lib/catissue/domain/disposal_event_parameters.rb +5 -5
- data/lib/catissue/domain/embedded_event_parameters.rb +1 -4
- data/lib/catissue/domain/external_identifier.rb +0 -12
- data/lib/catissue/domain/frozen_event_parameters.rb +1 -4
- data/lib/catissue/domain/institution.rb +0 -3
- data/lib/catissue/domain/new_specimen_array_order_item.rb +0 -5
- data/lib/catissue/domain/order_details.rb +0 -2
- data/lib/catissue/domain/participant/clinical/chemotherapy.rb +1 -3
- data/lib/catissue/domain/participant/clinical/duration.rb +2 -4
- data/lib/catissue/domain/participant/clinical/radiation_therapy.rb +2 -4
- data/lib/catissue/domain/participant.rb +22 -24
- data/lib/catissue/domain/participant_medical_identifier.rb +0 -4
- data/lib/catissue/domain/password.rb +0 -4
- data/lib/catissue/domain/race.rb +0 -3
- data/lib/catissue/domain/received_event_parameters.rb +3 -6
- data/lib/catissue/domain/site.rb +1 -4
- data/lib/catissue/domain/specimen/pathology/additional_finding.rb +12 -0
- data/lib/catissue/domain/specimen/pathology/details.rb +12 -0
- data/lib/catissue/domain/specimen/pathology/gleason_score.rb +12 -0
- data/lib/catissue/domain/specimen/pathology/histologic_grade.rb +12 -0
- data/lib/catissue/domain/specimen/pathology/histologic_type.rb +19 -0
- data/lib/catissue/domain/specimen/pathology/histologic_variant_type.rb +12 -0
- data/lib/catissue/domain/specimen/pathology/invasion.rb +12 -0
- data/lib/catissue/domain/specimen/pathology/prostate_specimen_gleason_score.rb +5 -11
- data/lib/catissue/domain/specimen/pathology/prostate_specimen_pathology_annotation.rb +12 -12
- data/lib/catissue/domain/specimen/pathology/specimen_additional_finding.rb +5 -14
- data/lib/catissue/domain/specimen/pathology/specimen_base_solid_tissue_pathology_annotation.rb +6 -21
- data/lib/catissue/domain/specimen/pathology/specimen_details.rb +4 -10
- data/lib/catissue/domain/specimen/pathology/specimen_histologic_grade.rb +4 -10
- data/lib/catissue/domain/specimen/pathology/specimen_histologic_type.rb +6 -14
- data/lib/catissue/domain/specimen/pathology/specimen_histologic_variant_type.rb +5 -11
- data/lib/catissue/domain/specimen/pathology/specimen_invasion.rb +5 -11
- data/lib/catissue/domain/specimen.rb +113 -76
- data/lib/catissue/domain/specimen_array.rb +0 -3
- data/lib/catissue/domain/specimen_array_content.rb +1 -4
- data/lib/catissue/domain/specimen_array_type.rb +1 -4
- data/lib/catissue/domain/specimen_characteristics.rb +0 -3
- data/lib/catissue/domain/specimen_collection_group/pathology/base_pathology_annotation.rb +2 -4
- data/lib/catissue/domain/specimen_collection_group/pathology/base_solid_tissue_pathology_annotation.rb +2 -4
- data/lib/catissue/domain/specimen_collection_group.rb +43 -53
- data/lib/catissue/domain/specimen_event_parameters.rb +24 -32
- data/lib/catissue/domain/specimen_position.rb +8 -5
- data/lib/catissue/domain/specimen_protocol.rb +3 -6
- data/lib/catissue/domain/specimen_requirement.rb +22 -20
- data/lib/catissue/domain/storage_container.rb +9 -12
- data/lib/catissue/domain/storage_type.rb +6 -10
- data/lib/catissue/domain/transfer_event_parameters.rb +3 -6
- data/lib/catissue/domain/user.rb +22 -29
- data/lib/catissue/{util → helpers}/collectible.rb +23 -18
- data/lib/catissue/helpers/collectible_event_parameters.rb +68 -0
- data/lib/catissue/helpers/controlled_value.rb +35 -0
- data/lib/catissue/{domain → helpers}/hash_code.rb +0 -0
- data/lib/catissue/{util → helpers}/location.rb +6 -5
- data/lib/catissue/helpers/log.rb +4 -0
- data/lib/catissue/{util → helpers}/person.rb +1 -1
- data/lib/catissue/{util → helpers}/position.rb +10 -8
- data/lib/catissue/helpers/properties_loader.rb +143 -0
- data/lib/catissue/{util → helpers}/storable.rb +2 -1
- data/lib/catissue/{util → helpers}/storage_type_holder.rb +9 -3
- data/lib/catissue/{annotation/annotatable_class.rb → metadata.rb} +73 -95
- data/lib/catissue/migration/migratable.rb +93 -44
- data/lib/catissue/migration/migrator.rb +26 -42
- data/lib/catissue/migration/shims.rb +1 -1
- data/lib/catissue/migration/unique.rb +76 -0
- data/lib/catissue/resource.rb +16 -20
- data/lib/catissue/version.rb +1 -1
- data/lib/catissue/wustl/logger.rb +52 -32
- data/lib/catissue.rb +38 -20
- data/test/lib/catissue/database/controlled_values_test.rb +22 -27
- data/test/lib/catissue/database/database_test.rb +18 -0
- data/test/lib/catissue/domain/address_test.rb +9 -11
- data/test/lib/catissue/domain/ca_tissue_test_defaults_test.rb +5 -16
- data/test/lib/catissue/domain/capacity_test.rb +2 -2
- data/test/lib/catissue/domain/collection_event_parameters_test.rb +16 -8
- data/test/lib/catissue/domain/collection_protocol_event_test.rb +1 -1
- data/test/lib/catissue/domain/collection_protocol_registration_test.rb +26 -16
- data/test/lib/catissue/domain/collection_protocol_test.rb +2 -2
- data/test/lib/catissue/domain/container_position_test.rb +7 -4
- data/test/lib/catissue/domain/department_test.rb +3 -3
- data/test/lib/catissue/domain/disposal_event_parameters_test.rb +1 -1
- data/test/lib/catissue/domain/external_identifier_test.rb +5 -1
- data/test/lib/catissue/domain/location_test.rb +4 -4
- data/test/lib/catissue/domain/participant_medical_identifier_test.rb +3 -3
- data/test/lib/catissue/domain/participant_test.rb +33 -20
- data/test/lib/catissue/domain/received_event_parameters_test.rb +19 -0
- data/test/lib/catissue/domain/site_test.rb +2 -2
- data/test/lib/catissue/domain/specimen_array_test.rb +3 -3
- data/test/lib/catissue/domain/specimen_array_type_test.rb +6 -6
- data/test/lib/catissue/domain/specimen_characteristics_test.rb +1 -1
- data/test/lib/catissue/domain/specimen_collection_group_test.rb +49 -13
- data/test/lib/catissue/domain/specimen_event_parameters_test.rb +4 -4
- data/test/lib/catissue/domain/specimen_position_test.rb +1 -1
- data/test/lib/catissue/domain/specimen_requirement_test.rb +2 -2
- data/test/lib/catissue/domain/specimen_test.rb +58 -24
- data/test/lib/catissue/domain/storage_container_test.rb +3 -16
- data/test/lib/catissue/domain/storage_type_test.rb +3 -3
- data/test/lib/catissue/domain/transfer_event_parameters_test.rb +17 -17
- data/test/lib/catissue/domain/user_test.rb +32 -34
- data/test/lib/catissue/helpers/properties_loader_test.rb +19 -0
- data/test/lib/catissue/migration/{test_case.rb → helpers/test_case.rb} +30 -20
- data/test/lib/examples/galena/tissue/domain/examples_test.rb +28 -38
- data/test/lib/examples/galena/tissue/helpers/test_case.rb +24 -0
- metadata +175 -99
- data/bin/crtextract +0 -47
- data/examples/galena/conf/extract/simple_fields.yaml +0 -4
- data/examples/galena/conf/migration/annotation_defaults.yaml +0 -2
- data/examples/galena/conf/migration/filter_defaults.yaml +0 -1
- data/examples/galena/conf/migration/filter_values.yaml +0 -13
- data/examples/galena/conf/migration/participant_fields.yaml +0 -4
- data/examples/galena/conf/migration/registration_fields.yaml +0 -5
- data/examples/galena/data/participant.csv +0 -1
- data/examples/galena/lib/galena/tissue/migration/filter_shims.rb +0 -41
- data/examples/galena/lib/galena/tissue/seed/defaults.rb +0 -127
- data/examples/psbin/README.md +0 -45
- data/examples/psbin/conf/adjuvant_hormone_defaults.yaml +0 -2
- data/examples/psbin/conf/adjuvant_radiation_defaults.yaml +0 -3
- data/examples/psbin/conf/biopsy_defaults.yaml +0 -3
- data/examples/psbin/conf/biopsy_fields.yaml +0 -9
- data/examples/psbin/conf/neoadjuvant_hormone_defaults.yaml +0 -2
- data/examples/psbin/conf/neoadjuvant_radiation_defaults.yaml +0 -3
- data/examples/psbin/conf/patient_defaults.yaml +0 -3
- data/examples/psbin/conf/patient_fields.yaml +0 -5
- data/examples/psbin/conf/surgery_defaults.yaml +0 -4
- data/examples/psbin/conf/surgery_fields.yaml +0 -15
- data/examples/psbin/conf/t_stage_defaults.yaml +0 -1
- data/examples/psbin/conf/t_stage_fields.yaml +0 -4
- data/examples/psbin/conf/therapy_fields.yaml +0 -5
- data/examples/psbin/data/adjuvant_hormone.csv +0 -1
- data/examples/psbin/data/adjuvant_radiation.csv +0 -1
- data/examples/psbin/data/biopsy.csv +0 -1
- data/examples/psbin/data/neoadjuvant_hormone.csv +0 -1
- data/examples/psbin/data/neoadjuvant_radiation.csv +0 -1
- data/examples/psbin/data/patient.csv +0 -1
- data/examples/psbin/data/surgery.csv +0 -1
- data/examples/psbin/data/t_stage.csv +0 -1
- data/examples/psbin/lib/psbin/biopsy_shims.rb +0 -15
- data/examples/psbin/lib/psbin/surgery_shims.rb +0 -15
- data/lib/catissue/annotation/annotation_class.rb +0 -406
- data/lib/catissue/annotation/annotation_module.rb +0 -106
- data/lib/catissue/domain.rb +0 -26
- data/lib/catissue/extract/command.rb +0 -31
- data/lib/catissue/extract/delta.rb +0 -58
- data/lib/catissue/extract/extractor.rb +0 -99
- data/lib/catissue/migration/uniquify.rb +0 -2
- data/lib/catissue/util/collectible_event_parameters.rb +0 -71
- data/lib/catissue/util/controlled_value.rb +0 -29
- data/lib/catissue/util/uniquify.rb +0 -86
- data/test/fixtures/catissue/domain/conf/catissue_override.yaml +0 -9
- data/test/fixtures/catissue/extract/conf/scg_extract.yaml +0 -3
- data/test/fixtures/catissue/extract/conf/scg_fields.yaml +0 -3
- data/test/fixtures/catissue/extract/conf/spc_extract.yaml +0 -3
- data/test/fixtures/catissue/extract/conf/spc_fields.yaml +0 -4
- data/test/fixtures/lib/catissue/defaults_test_fixture.rb +0 -206
- data/test/fixtures/lib/examples/galena/migration/alt_key_shims.rb +0 -7
- data/test/lib/catissue/domain/base_haemotology_pathology_test.rb +0 -24
- data/test/lib/catissue/extract/delta_test.rb +0 -25
- data/test/lib/catissue/extract/extractor_test.rb +0 -43
- data/test/lib/catissue/import/importable_module_test.rb +0 -14
- data/test/lib/catissue/test_case.rb +0 -247
- data/test/lib/examples/galena/tissue/migration/annotation_test.rb +0 -29
- data/test/lib/examples/galena/tissue/migration/filter_test.rb +0 -29
- data/test/lib/examples/galena/tissue/migration/frozen_test.rb +0 -36
- data/test/lib/examples/galena/tissue/migration/general_test.rb +0 -56
- data/test/lib/examples/galena/tissue/migration/participant_test.rb +0 -61
- data/test/lib/examples/galena/tissue/migration/registration_test.rb +0 -17
- data/test/lib/examples/galena/tissue/migration/seedify.rb +0 -119
- data/test/lib/examples/galena/tissue/migration/simple_test.rb +0 -30
- data/test/lib/examples/galena/tissue/migration/test_case.rb +0 -72
- data/test/lib/examples/psbin/migration_test.rb +0 -153
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
Bundler.require(:test, :development)
|
4
|
+
|
5
|
+
require 'galena'
|
6
|
+
|
7
|
+
# Open the logger.
|
8
|
+
Jinx::Log.instance.open(File.expand_path(Galena::LOG), :debug => true)
|
9
|
+
|
10
|
+
# Include the test utility classes.
|
11
|
+
Dir.glob(File.dirname(__FILE__) + '/support/**/*.rb').each { |f| require f }
|
@@ -0,0 +1,70 @@
|
|
1
|
+
shared_context 'a migration' do
|
2
|
+
# Builds a migrator for the given test fixture with the given options.
|
3
|
+
# The options must include at least the migration target.
|
4
|
+
# The mapping, defaults, filter and shims options are inferred from the fixture
|
5
|
+
# name, and should not be specified in the options argument.
|
6
|
+
#
|
7
|
+
# @param [Symbol] fixture the input test data fixture
|
8
|
+
# @param [{Symbol => Object}] opts the migration options
|
9
|
+
# @return [CaTissue::Migrator] the migrator
|
10
|
+
def migrator(fixture, opts)
|
11
|
+
# the input file
|
12
|
+
input = File.expand_path("#{fixture}.csv", Galena::DATA)
|
13
|
+
# the fixture configurations
|
14
|
+
fxt_conf = File.expand_path(fixture.to_s, Galena::CONFIGS)
|
15
|
+
# the fixture mapping
|
16
|
+
mapping = File.expand_path('fields.yaml', fxt_conf)
|
17
|
+
mopts = opts.merge(:input => input, :mapping => mapping, :debug => true)
|
18
|
+
unless mopts.has_key?(:defaults) then
|
19
|
+
# the standard defaults file
|
20
|
+
defs = mopts[:defaults] = [File.expand_path('defaults.yaml', Galena::CONFIGS)]
|
21
|
+
# the fixture defaults, if any
|
22
|
+
fxt_defs = File.expand_path('defaults.yaml', fxt_conf)
|
23
|
+
defs << fxt_defs if File.exists?(fxt_defs)
|
24
|
+
end
|
25
|
+
unless mopts.has_key?(:filters) then
|
26
|
+
# the fixture filter, if any
|
27
|
+
filter = File.expand_path('values.yaml', fxt_conf)
|
28
|
+
mopts[:filters] = filter if File.exists?(filter)
|
29
|
+
end
|
30
|
+
# the test seed shim
|
31
|
+
shims = [File.expand_path('seed.rb', File.dirname(__FILE__) + '/..')]
|
32
|
+
# the fixture shims, if any
|
33
|
+
fxt_shims = File.expand_path("#{fixture}.rb", Galena::SHIMS)
|
34
|
+
shims << fxt_shims if File.exists?(fxt_shims)
|
35
|
+
mopts[:shims] = shims
|
36
|
+
CaTissue::Migrator.new(mopts)
|
37
|
+
end
|
38
|
+
|
39
|
+
# @param [Symbol] fixture the input test data fixture
|
40
|
+
# @param [{Symbol => Object}] opts the migration options
|
41
|
+
# @return [<CaTissue::Resource>] the migrated targets
|
42
|
+
# @yield [target] an optional block to process the migration result
|
43
|
+
# @yieldparam [CaTissue::Resource] target the migrated target object
|
44
|
+
# @see #migrator
|
45
|
+
def migrate(fixture, opts, &block)
|
46
|
+
mgtr = migrator(fixture, opts)
|
47
|
+
mgtr.map do |tgt|
|
48
|
+
yield tgt if block_given?
|
49
|
+
tgt
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# @param [Symbol] fixture the input test data fixture
|
54
|
+
# @param [{Symbol => Object}] opts the migration options
|
55
|
+
# @return [<CaTissue::Resource>] the migrated targets
|
56
|
+
# @yield [target] an optional block to process the migration result
|
57
|
+
# @yieldparam [CaTissue::Resource] target the migrated target object
|
58
|
+
# @see #migrator
|
59
|
+
def migrate_to_database(fixture, opts, &block)
|
60
|
+
tgts = []
|
61
|
+
db_opts = opts.merge(:database => CaTissue::Database.instance)
|
62
|
+
db_opts[:unique] = true unless db_opts.has_key?(:unique)
|
63
|
+
mgtr = migrator(fixture, db_opts)
|
64
|
+
mgtr.migrate_to_database do |tgt, rec|
|
65
|
+
yield tgt if block_given?
|
66
|
+
tgts << tgt
|
67
|
+
end
|
68
|
+
tgts
|
69
|
+
end
|
70
|
+
end
|
@@ -1,18 +1,20 @@
|
|
1
|
-
require 'catissue/
|
1
|
+
require 'catissue/resource'
|
2
2
|
|
3
3
|
module CaTissue
|
4
|
-
# {CaTissue::Resource} annotation
|
4
|
+
# Annotatable extends {CaTissue::Resource} with annotation capability.
|
5
5
|
module Annotatable
|
6
|
+
include Resource
|
7
|
+
|
6
8
|
def method_missing(mth, *args)
|
7
9
|
name = mth.to_s
|
8
10
|
# remove trailing assignment '=' character if present
|
9
|
-
|
11
|
+
pa = name =~ /=$/ ? name.chop.to_sym : mth
|
10
12
|
# If an annotation can be generated on demand, then resend the method.
|
11
13
|
# Otherwise, delegate to super for the standard error.
|
12
14
|
begin
|
13
|
-
self.class.annotation_attribute?(
|
14
|
-
rescue AnnotationError
|
15
|
-
raise
|
15
|
+
self.class.annotation_attribute?(pa) ? send(mth, *args) : super
|
16
|
+
rescue AnnotationError => e
|
17
|
+
raise e
|
16
18
|
rescue NoMethodError
|
17
19
|
super
|
18
20
|
end
|
@@ -22,8 +24,8 @@ module CaTissue
|
|
22
24
|
# @param [Annotation] the annotation
|
23
25
|
# @return [Proxy] the hook proxy for the given annotation
|
24
26
|
def proxy_for(attribute, annotation)
|
25
|
-
@ann_pxy_hash ||= LazyHash.new do |ann|
|
26
|
-
pxy = self.class.
|
27
|
+
@ann_pxy_hash ||= Jinx::LazyHash.new do |ann|
|
28
|
+
pxy = self.class.property(attribute).type.new
|
27
29
|
pxy.hook = self
|
28
30
|
send(attribute) << pxy
|
29
31
|
pxy
|
@@ -1,23 +1,23 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require 'catissue/
|
1
|
+
require 'jinx/metadata/id_alias'
|
2
|
+
require 'catissue/resource'
|
3
|
+
require 'catissue/helpers/hash_code'
|
4
4
|
|
5
5
|
module CaTissue
|
6
|
-
#
|
6
|
+
# The annotation error class.
|
7
7
|
class AnnotationError < StandardError; end
|
8
8
|
|
9
|
-
#
|
9
|
+
# The caTissue dynamic extension class mix-in.
|
10
10
|
#
|
11
11
|
# @quirk caTissue Annotation RecordEntry proxy classes implements hashCode with the identifier.
|
12
12
|
# Consequently, a set member is not found after identifier assignment.
|
13
13
|
# The work-around is to include the HashCode mixin, which reimplements the hash and equality
|
14
14
|
# test methods to be invariant with respect to identifier assignment.
|
15
15
|
module Annotation
|
16
|
-
include
|
16
|
+
include Resource, HashCode
|
17
17
|
|
18
18
|
# @return [Database] the database which stores this object
|
19
19
|
def database
|
20
|
-
|
20
|
+
Database.instance
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -1,32 +1,21 @@
|
|
1
|
-
require '
|
1
|
+
require 'jinx/resource'
|
2
2
|
|
3
3
|
module CaTissue
|
4
4
|
module Annotation
|
5
|
-
# DEIntegration encapsulates the
|
5
|
+
# DEIntegration encapsulates the auxiliary DE integration package in caTissue 1.2 and higher.
|
6
6
|
module DEIntegration
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
begin
|
14
|
-
java_import name
|
15
|
-
rescue NameError
|
16
|
-
super
|
17
|
-
end
|
18
|
-
end
|
7
|
+
include Jinx::Resource
|
8
|
+
|
9
|
+
extend Jinx::Importer
|
10
|
+
|
11
|
+
# The caTissue Java package name.
|
12
|
+
packages 'edu.wustl.catissuecore.domain.deintegration'
|
19
13
|
|
20
14
|
# @param [String] name the annotated hook class name
|
21
15
|
# @return [Class, nil] the hook proxy class, or nil if none defined
|
22
16
|
def self.proxy(name)
|
23
|
-
const_get(name
|
17
|
+
const_get(name) rescue nil
|
24
18
|
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
# The auxiliary record entry class Java package name.
|
29
|
-
PKG = 'edu.wustl.catissuecore.domain.deintegration'
|
30
19
|
end
|
31
20
|
end
|
32
21
|
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'catissue/annotation/annotation'
|
2
|
+
require 'catissue/annotation/metadata'
|
3
|
+
require 'catissue/annotation/importer'
|
4
|
+
require 'catissue/annotation/proxy'
|
5
|
+
require 'catissue/annotation/proxy_class'
|
6
|
+
require 'catissue/annotation/de_integration'
|
7
|
+
|
8
|
+
module CaTissue
|
9
|
+
module Annotation
|
10
|
+
module Importer
|
11
|
+
include Jinx::Importer
|
12
|
+
|
13
|
+
# @return [<Metadata>] this module's annotation classes
|
14
|
+
attr_reader :annotation_classes
|
15
|
+
|
16
|
+
# @return [ProxyClass] the annotation proxy class
|
17
|
+
attr_reader :proxy
|
18
|
+
|
19
|
+
# @return [String] the group short name
|
20
|
+
attr_reader :group
|
21
|
+
|
22
|
+
# @return [ProxyClass] the hook-annotation association class, or nil for 1.1.x caTissue
|
23
|
+
attr_reader :record_entry_class
|
24
|
+
|
25
|
+
# @return [Symbol] the {#record_entry_class} hook writer method, or nil for 1.1.x caTissue
|
26
|
+
attr_reader :record_entry_hook_writer
|
27
|
+
|
28
|
+
# Builds this annotation module.
|
29
|
+
# This method intended to be called only by {Metadata}.
|
30
|
+
#
|
31
|
+
# @param [Class] hook the static hook class
|
32
|
+
# @param [{Symbol => Object}] the options
|
33
|
+
# @option opts [String] :package the DE package name
|
34
|
+
# @option opts [String] :service the DE service name
|
35
|
+
# @option opts [String] :group the DE group short name
|
36
|
+
# @option opts [String] :record_entry the record entry name class for post-1.1.x caTissue
|
37
|
+
# @yield [proxy] makes the hook => proxy reference attribute
|
38
|
+
# @yieldparam [ProxyClass] proxy the proxy class
|
39
|
+
# @yield [proxy] makes the hook => proxy reference attribute
|
40
|
+
# @yieldparam [ProxyClass] proxy the proxy class
|
41
|
+
def initialize_annotation(hook, opts)
|
42
|
+
logger.debug { "Building #{hook.qp} annotation #{qp}..." }
|
43
|
+
# Make this module an annotation-enabled Jinx::Importer
|
44
|
+
enable_metadata(hook, opts)
|
45
|
+
@svc_nm = opts[:service]
|
46
|
+
@group = opts[:group]
|
47
|
+
@annotation_classes = []
|
48
|
+
dei = hook.de_integration_proxy_class
|
49
|
+
if dei then
|
50
|
+
import_record_entry_class(dei, hook)
|
51
|
+
pxy_nm = dei.name.demodulize
|
52
|
+
end
|
53
|
+
@proxy = import_proxy(hook, pxy_nm)
|
54
|
+
# Make the hook => proxy reference
|
55
|
+
yield @proxy
|
56
|
+
# Fill out the dependency hierarchy.
|
57
|
+
@proxy.build_annotation_dependency_hierarchy
|
58
|
+
# Print all known annotation classes.
|
59
|
+
@annotation_classes.each { |klass| logger.info(klass.pp_s) }
|
60
|
+
logger.debug { "Built #{hook.qp} annotation #{qp}." }
|
61
|
+
end
|
62
|
+
|
63
|
+
# @return (ProxyClass#hook)
|
64
|
+
def hook
|
65
|
+
@proxy.hook
|
66
|
+
end
|
67
|
+
|
68
|
+
# @return [CaRuby::PersistenceService] this module's application service
|
69
|
+
def persistence_service
|
70
|
+
@ann_svc ||= Database.instance.annotator.create_annotation_service(self, @svc_nm)
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
# The location of the domain class definitions.
|
76
|
+
DOMAIN_DIR = File.dirname(__FILE__) + '/../domain'
|
77
|
+
|
78
|
+
# @param (see #initialize_annotation)
|
79
|
+
def enable_metadata(hook, opts)
|
80
|
+
# Add introspection and annotation capability.
|
81
|
+
include Annotation
|
82
|
+
# Make this module an annotation importer.
|
83
|
+
extend Jinx::Importer
|
84
|
+
# Each annotation class extends Annotation::Metadata.
|
85
|
+
@metadata_module = Metadata
|
86
|
+
# The annotation parent module is the hook domain module.
|
87
|
+
@parent_importer = hook.domain_module
|
88
|
+
# the package name
|
89
|
+
package(opts[:package])
|
90
|
+
# the annotation Ruby source files
|
91
|
+
dir = File.join(DOMAIN_DIR, hook.name.demodulize.underscore, name.demodulize.underscore)
|
92
|
+
definitions(dir) if File.directory?(dir)
|
93
|
+
end
|
94
|
+
|
95
|
+
# Augments +Jinx::Importer.add_metadata+ to add annotation meta-data to the introspected class.
|
96
|
+
#
|
97
|
+
# @param [Metadata] klass the domain class
|
98
|
+
def add_metadata(klass)
|
99
|
+
super
|
100
|
+
# Build the annotation metadata.
|
101
|
+
klass.add_annotation_metadata(self)
|
102
|
+
# Register the annotation class.
|
103
|
+
annotation_classes << klass
|
104
|
+
|
105
|
+
# # Annotation classes are introspected, but the annotation constant is not set properly
|
106
|
+
# # in the annotation module. This occurs sporadically, e.g. in the PSBIN migration_test
|
107
|
+
# # test_biopsy_target test case the NewDiagnosisHealthAnnotation class is introspected
|
108
|
+
# # but when subsequently referenced by the migrator, the NewDiagnosisHealthAnnotation
|
109
|
+
# # class is not introspected and the class object id differs from the original class
|
110
|
+
# # object id. However, the analogous test_surgery_target does not exhibit this defect.
|
111
|
+
# #
|
112
|
+
# # The cause of this bug is a complete mystery. The work-around is to get the constant.
|
113
|
+
# # below. This is a seemingly unnecessary action to take, but was the most reasonable
|
114
|
+
# # remedy. The const_get can only be done with annotation classes, and breaks
|
115
|
+
# # non-annotation classes.
|
116
|
+
# const_get(klass.name.demodulize)
|
117
|
+
end
|
118
|
+
|
119
|
+
# Sets the record entry instance variables for the given class name, if it exists
|
120
|
+
# as a {Annotation::DEIntegration} proxy class. caTissue v1.1.x does not have
|
121
|
+
# a record entry class.
|
122
|
+
#
|
123
|
+
# @param [String] the record entry class name specified in the
|
124
|
+
# {CaTissue::Metadata#add_annotation} +:record_entry+ option
|
125
|
+
def import_record_entry_class(klass, hook)
|
126
|
+
@record_entry_class = const_get(klass.name.demodulize.to_sym)
|
127
|
+
@record_entry_hook_writer = "#{hook.name.demodulize.underscore}=".to_sym
|
128
|
+
end
|
129
|
+
|
130
|
+
# @param hook (see #initialize_annotation)
|
131
|
+
# @param [String] name the demodulized name of the proxy class
|
132
|
+
# (default is the demodulized hook class name)
|
133
|
+
def import_proxy(hook, name=nil)
|
134
|
+
name ||= hook.name.demodulize
|
135
|
+
logger.debug { "Importing the #{qp} #{hook.qp} annotation proxy..." }
|
136
|
+
begin
|
137
|
+
klass = const_get(name.to_sym)
|
138
|
+
rescue NameError => e
|
139
|
+
Jinx.fail(AnnotationError, "#{hook.qp} annotation #{qp} does not have a hook proxy class", e)
|
140
|
+
end
|
141
|
+
klass.extend(Annotation::ProxyClass)
|
142
|
+
klass.hook = hook
|
143
|
+
logger.debug { "Built the #{name} #{hook.qp} annotation proxy #{klass}." }
|
144
|
+
klass
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module CaTissue
|
2
|
+
module Annotation
|
3
|
+
module Introspector
|
4
|
+
private
|
5
|
+
|
6
|
+
# Augments +Jinx::Introspector.create_java_attribute+ to accomodate the
|
7
|
+
# following caTissue anomaly:
|
8
|
+
#
|
9
|
+
# @quirk caTissue DE annotation collection attributes are often misnamed,
|
10
|
+
# e.g. +histologic_grade+ for a +HistologicGrade+ collection attribute.
|
11
|
+
# This is fixed by adding a pluralized alias, e.g. +histologic_grades+.
|
12
|
+
#
|
13
|
+
# @return [Symbol] the new attribute symbol
|
14
|
+
def create_java_property(pd)
|
15
|
+
# the new property
|
16
|
+
prop = super
|
17
|
+
# alias a misnamed collection attribute, if necessary
|
18
|
+
if prop.collection? then
|
19
|
+
name = prop.attribute.to_s
|
20
|
+
if name.singularize == name then
|
21
|
+
aliaz = name.pluralize.to_sym
|
22
|
+
if aliaz != name then
|
23
|
+
logger.debug { "Adding annotation #{qp} alias #{aliaz} to the misnamed collection property #{prop}..." }
|
24
|
+
delegate_to_attribute(aliaz, prop.attribute)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
prop
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,422 @@
|
|
1
|
+
require 'catissue/annotation/annotation'
|
2
|
+
require 'catissue/annotation/introspector'
|
3
|
+
require 'catissue/database/annotation/reference_writer'
|
4
|
+
|
5
|
+
module CaTissue
|
6
|
+
module Annotation
|
7
|
+
module Metadata
|
8
|
+
include CaRuby::Metadata
|
9
|
+
|
10
|
+
# @return [Integer, nil] the annotation class designator that is used by caTissue to persist primary
|
11
|
+
# annotation objects, or nil if this is not a primary annotation
|
12
|
+
attr_reader :entity_id
|
13
|
+
|
14
|
+
# @return [Intger, nil] the container id, or nil if this is not a primary annotation
|
15
|
+
attr_reader :container_id
|
16
|
+
|
17
|
+
# @return [Module] the module which imported this annotation class
|
18
|
+
attr_reader :annotation_module
|
19
|
+
|
20
|
+
# @return [<Class>] the annotation class hierarchy, including this class
|
21
|
+
def annotation_hierarchy
|
22
|
+
class_hierarchy.filter { |klass| klass < Annotation }
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [Boolean] whether this annotation class references a hook proxy
|
26
|
+
def primary?
|
27
|
+
@is_primary
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [Boolean] whether this annotation refers to a {#primary?} annotation
|
31
|
+
def secondary?
|
32
|
+
ref = domain_attributes.detect_with_metadata { |prop| prop.type < Annotation and prop.type.primary? }
|
33
|
+
not ref.nil?
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [Boolean] whether this annotation is neither a {#primary?} nor a {#secondary?} annotation
|
37
|
+
def tertiary?
|
38
|
+
not (primary? or secondary?)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Adds metadata to this annotation class.
|
42
|
+
# This method is intended for the sole use of {Metadata}.
|
43
|
+
#
|
44
|
+
# @param [Module] mod (see AnnotationModule.extend_class)
|
45
|
+
def add_annotation_metadata(mod)
|
46
|
+
# Set the primary key.
|
47
|
+
property :identifier, :primary_key
|
48
|
+
# The entity facade determines various caTissue DE arcana.
|
49
|
+
efcd = Annotation::EntityFacade.instance
|
50
|
+
@annotation_module = mod
|
51
|
+
logger.debug { "Annotatable #{qp} annotation module is set to #{mod}." }
|
52
|
+
@entity_id = efcd.annotation_entity_id(self, false)
|
53
|
+
@is_primary = efcd.primary?(@entity_id) if @entity_id
|
54
|
+
# A primary entity has a container id.
|
55
|
+
if primary? then
|
56
|
+
@container_id = efcd.container_id(@entity_id)
|
57
|
+
if @container_id.nil? then
|
58
|
+
raise AnnotationError.new("Primary annotation #{self} is missing a container id")
|
59
|
+
end
|
60
|
+
logger.debug { "Primary annotation #{self} has container id #{@container_id}." }
|
61
|
+
pxy = @annotation_module.proxy
|
62
|
+
if pxy then pxy.ensure_primary_references_proxy(self) end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# @return [Symbol] the domain attributes which include {Annotation}
|
67
|
+
def annotation_attributes
|
68
|
+
@ann_attrs ||= domain_attributes.compose { |prop| prop.type < Annotation }
|
69
|
+
end
|
70
|
+
|
71
|
+
# Filters +CaRuby::Propertied.loadable_attributes+ to exclude all references,
|
72
|
+
# since annotation lazy-loading is not supported.
|
73
|
+
#
|
74
|
+
# @return [Array] an empty array
|
75
|
+
def loadable_attributes
|
76
|
+
Array::EMPTY_ARRAY
|
77
|
+
end
|
78
|
+
|
79
|
+
# Saves the annotations referenced by the given annotation.
|
80
|
+
#
|
81
|
+
# @param [Annotation] annotation the subject annotation
|
82
|
+
def save_dependent_attributes(annotation)
|
83
|
+
dependent_attributes.each { |pa| save_dependent_attribute(annotation, pa) }
|
84
|
+
end
|
85
|
+
|
86
|
+
# @return [ProxyClass] the annotation proxy class
|
87
|
+
def proxy_class
|
88
|
+
annotation_module.proxy
|
89
|
+
end
|
90
|
+
|
91
|
+
alias :proxy :proxy_class
|
92
|
+
|
93
|
+
# @return [Metadata] the annotated domain object class
|
94
|
+
def hook_class
|
95
|
+
proxy.hook
|
96
|
+
end
|
97
|
+
|
98
|
+
alias :hook :hook_class
|
99
|
+
|
100
|
+
# @return [Jinx::Property, nil] the attribute metadata which references
|
101
|
+
# the hook proxy, or nil if this is not a primary annotation class
|
102
|
+
def proxy_property
|
103
|
+
@pxy_prop
|
104
|
+
end
|
105
|
+
|
106
|
+
# @return [Symbol, nil] the attribute symbol which references the hook proxy,
|
107
|
+
# or nil if this is not a primary annotation class
|
108
|
+
def proxy_attribute
|
109
|
+
@pxy_prop.to_sym if @pxy_prop
|
110
|
+
end
|
111
|
+
|
112
|
+
# @return [Symbol, nil] the hook proxy class attribute which references this annotation class,
|
113
|
+
# or nil if this is not a primary annotation class
|
114
|
+
def hook_proxy_attribute
|
115
|
+
# The hook => primary attribute symbol is the same as the proxy => primary attribute symbol.
|
116
|
+
@pxy_prop.inverse if @pxy_prop
|
117
|
+
end
|
118
|
+
|
119
|
+
# @return [Array] an empty array, since no annotation reference is lazy-loaded by caTissue.
|
120
|
+
def toxic_attributes
|
121
|
+
Array::EMPTY_ARRAY
|
122
|
+
end
|
123
|
+
|
124
|
+
protected
|
125
|
+
|
126
|
+
# @return [Symbol => ReferenceWriter] this class's attribute => writer hash
|
127
|
+
def attribute_writer_hash
|
128
|
+
@attr_writer_hash ||= map_writers
|
129
|
+
end
|
130
|
+
|
131
|
+
# Marks each of this annotation class's non-owner domain attributes as a dependent.
|
132
|
+
def add_dependent_attributes
|
133
|
+
# First infer the attribute inverses.
|
134
|
+
infer_inverses
|
135
|
+
# Select the annotation attributes to make dependent.
|
136
|
+
pa = domain_attributes.compose do |prop|
|
137
|
+
prop != @pxy_prop and prop.type < Annotation and not (prop.dependent? or prop.owner?) and prop.declarer == self
|
138
|
+
end
|
139
|
+
# Copy the attributes to an array before iteration, since adding a dependent attribute
|
140
|
+
# might also add another attribute in the case of a proxy.
|
141
|
+
pa.to_a.each do |pa|
|
142
|
+
logger.debug { "Adding annotation #{qp} #{pa} attribute as a logical dependent..." }
|
143
|
+
add_dependent_attribute(pa, :logical, :unsaved)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# Infers this annotation class inverses attribute.
|
148
|
+
# This method is called by the annotation module on each imported annotated class.
|
149
|
+
def infer_inverses
|
150
|
+
annotation_attributes.each_property do |prop|
|
151
|
+
if prop.inverse.nil? and prop.declarer == self then
|
152
|
+
prop.declarer.infer_property_inverse(prop)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
# Recurses the dependency hierarchy to this annotation class's dependents in a
|
158
|
+
# breadth-first manner.
|
159
|
+
#
|
160
|
+
# @param [<Jinx::Property>] path the visited attributes
|
161
|
+
def add_dependent_attribute_closure(path=[])
|
162
|
+
return if path.include?(self)
|
163
|
+
|
164
|
+
# add breadth-first dependencies
|
165
|
+
deps = dependent_attributes(false)
|
166
|
+
return if deps.empty?
|
167
|
+
logger.debug { "Adding #{qp} annotation dependents #{deps.qp}..." }
|
168
|
+
deps.each_property { |prop| prop.type.add_dependent_attributes }
|
169
|
+
logger.debug { "Added #{qp} dependents #{deps.qp}." }
|
170
|
+
|
171
|
+
# recurse to dependents
|
172
|
+
path.push(self)
|
173
|
+
dependent_attributes(false).each_property do |prop|
|
174
|
+
klass = prop.type
|
175
|
+
klass.add_dependent_attribute_closure(path)
|
176
|
+
end
|
177
|
+
path.pop
|
178
|
+
end
|
179
|
+
|
180
|
+
# Creates the proxy attribute that references the given proxy class, if it is not
|
181
|
+
# already defined.
|
182
|
+
#
|
183
|
+
# @param [Annotation::ProxyClass] klass the annotation module proxy class
|
184
|
+
# @raise [AnnotationError] if this annotation is not {#primary?}
|
185
|
+
# @raise [AnnotationError] if the proxy attribute is already set and references a
|
186
|
+
# different proxy class
|
187
|
+
def define_proxy_attribute(klass)
|
188
|
+
# Only a primary annotation class can have a proxy.
|
189
|
+
unless primary? then
|
190
|
+
raise AnnotationError.new("Can't set proxy for non-primary annotation class #{qp}")
|
191
|
+
end
|
192
|
+
# If the proxy is already set, then confirm that this call is redundant, which is tolerated
|
193
|
+
# as a no-op, as opposed to conflicting, which is not allowed.
|
194
|
+
if @pxy_prop then
|
195
|
+
return if @pxy_prop.type == klass
|
196
|
+
raise AnnotationError.new("Can't reset #{self} proxy from #{@pxy_prop.type} to #{klass}")
|
197
|
+
end
|
198
|
+
logger.debug { "Setting annotation #{qp} proxy to #{klass}..." }
|
199
|
+
# the annotation => proxy reference attribute
|
200
|
+
prop = obtain_proxy_property(klass)
|
201
|
+
# The canonical proxy attribute is named after the annotation module, e.g. clinical.
|
202
|
+
# caTissue 1.1.x confusingly names the proxy the same as the hook. Correct this by repurposing
|
203
|
+
# the proxy as the hook attribute and making a separate proxy attribute named by the annotation
|
204
|
+
# module.
|
205
|
+
hook_attr = klass.hook.name.demodulize.underscore.to_sym
|
206
|
+
if prop.to_sym == hook_attr then
|
207
|
+
wrap_1_1_proxy_attribute(prop)
|
208
|
+
else
|
209
|
+
set_proxy_property(prop, hook_attr)
|
210
|
+
end
|
211
|
+
logger.debug { "Annotation #{qp} proxy reference attribute is #{@pxy_prop}." }
|
212
|
+
|
213
|
+
# Alias 'proxy' to the proxy attribute.
|
214
|
+
logger.debug { "Aliased annotation #{qp} :proxy to #{@pxy_prop}." }
|
215
|
+
alias_attribute(:proxy, @pxy_prop.to_sym)
|
216
|
+
# Alias 'hook' to the hook attribute.
|
217
|
+
logger.debug { "Aliased annotation #{qp} :hook to #{hook_attr}." }
|
218
|
+
alias_attribute(:hook, hook_attr)
|
219
|
+
end
|
220
|
+
|
221
|
+
private
|
222
|
+
|
223
|
+
# Augments +Jinx::Introspector.add_java_attribute+ to accomodate the
|
224
|
+
# following caTissue anomaly:
|
225
|
+
#
|
226
|
+
# @quirk caTissue DE annotation collection attributes are often misnamed,
|
227
|
+
# e.g. +histologic_grade+ for a +HistologicGrade+ collection attribute.
|
228
|
+
# This is fixed by adding a pluralized alias, e.g. +histologic_grades+.
|
229
|
+
#
|
230
|
+
# @return [Symbol] the new attribute symbol
|
231
|
+
def add_java_property(pd)
|
232
|
+
# the new property
|
233
|
+
prop = super
|
234
|
+
# alias a misnamed collection attribute, if necessary
|
235
|
+
if prop.collection? then
|
236
|
+
name = prop.attribute.to_s
|
237
|
+
if name.singularize == name then
|
238
|
+
aliaz = name.pluralize.to_sym
|
239
|
+
if aliaz != name then
|
240
|
+
logger.debug { "Adding annotation #{qp} alias #{aliaz} to the misnamed collection property #{prop}..." }
|
241
|
+
delegate_to_attribute(aliaz, prop.attribute)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
prop
|
246
|
+
end
|
247
|
+
|
248
|
+
# Sets the caTissue 1.2 and higher proxy attribute. The attribute is aliased
|
249
|
+
# to the demodulized annotation module name, e.g. +clinical+. A hook attribute
|
250
|
+
# is created that is a shortcut for the annotation => proxy => hook reference.
|
251
|
+
#
|
252
|
+
# @param [Jinx::Property] prop the proxy attribute
|
253
|
+
# @param [Symbol, nil] the proxy => hook attribute (default is the underscore demodulized hook class name)
|
254
|
+
def set_proxy_property(prop, hook_attr=nil)
|
255
|
+
hook_attr ||= prop.type.hook.name.demodulize.underscore.to_sym
|
256
|
+
@pxy_prop = prop
|
257
|
+
|
258
|
+
# Alias the attribute with the proxy hook name, e.g. the
|
259
|
+
# Participant::Clinical::AlcoholAnnotation -> Participant::Clinical::ParticipantRecordEntry
|
260
|
+
# proxy reference attribute participant_record_entry is aliased by clinical.
|
261
|
+
aliaz = annotation_module.name.demodulize.underscore.to_sym
|
262
|
+
if aliaz != prop.to_sym then
|
263
|
+
alias_attribute(aliaz, prop.to_sym)
|
264
|
+
logger.debug { "Aliased #{qp} #{aliaz} to #{prop}." }
|
265
|
+
end
|
266
|
+
|
267
|
+
# Make the hook attribute.
|
268
|
+
define_method(hook_attr) { pxy = send(aliaz); pxy.hook if pxy }
|
269
|
+
define_method("#{hook_attr}=".to_sym) { |obj| pxy = obj.proxy_for(aliaz, self) if obj; send(prop.writer, pxy) }
|
270
|
+
add_attribute(hook_attr, prop.type.hook)
|
271
|
+
logger.debug { "Defined #{qp} => #{prop.type.hook.qp} hook attribute #{hook_attr}." }
|
272
|
+
end
|
273
|
+
|
274
|
+
# Wraps the caTissue 1.1.x proxy attribute with a hook argument and return value.
|
275
|
+
# If the superclass is a primary annotation, then this method delegates
|
276
|
+
# to the superclass to set the proxy attribute. Otherwise, the proxy accessor
|
277
|
+
# methods are modified as follows:
|
278
|
+
# * the proxy writer converts a hook argument to its proxy
|
279
|
+
# * the proxy reader converts a proxy to its hook
|
280
|
+
# * the proxy is aliased as a hook attribute, if necessary, e.g. +participant+
|
281
|
+
# is aliased to +participant_record_entry+
|
282
|
+
#
|
283
|
+
# @param [Jinx::Property] prop the proxy attribute
|
284
|
+
def wrap_1_1_proxy_attribute(prop)
|
285
|
+
if prop.nil? then
|
286
|
+
raise AnnotationError.new("Cannot convert #{qp} => #{klass.qp} argument to a proxy since no proxy attribute is defined.")
|
287
|
+
end
|
288
|
+
logger.debug { "Adding #{qp} #{prop} attribute to wrap the proxy Java accessor methods with the hook JRuby accessor methods..." }
|
289
|
+
# Wrap the proxy reader with a proxy => hook converter.
|
290
|
+
convert_proxy_reader_result_to_hook(prop.reader)
|
291
|
+
# the proxy => hook attribute metadata
|
292
|
+
pxy_hook_prop = annotation_module.proxy.hook_property
|
293
|
+
# the hook => proxy attribute
|
294
|
+
hook_pxy_attr = pxy_hook_prop.inverse
|
295
|
+
# Wrap the proxy writer with a hook -> proxy converter.
|
296
|
+
convert_proxy_writer_hook_argument_to_proxy(prop.writer, hook_pxy_attr)
|
297
|
+
# Reset the attribute type.
|
298
|
+
hook = pxy_hook_prop.type
|
299
|
+
set_attribute_type(prop.to_sym, hook)
|
300
|
+
logger.debug { "Reset #{qp} #{prop} type to the hook class #{hook}." }
|
301
|
+
# Mark the hook attribute as unsaved. This is necessary because as a uni-directional
|
302
|
+
# Java independent reference, the default is to save this attribute. Since we save the
|
303
|
+
# proxy reference instead, the convenience hook reference is unsaved.
|
304
|
+
prop.qualify(:unsaved)
|
305
|
+
|
306
|
+
# Add the proxy reference attribute.
|
307
|
+
pxy_attr = annotation_module.name.demodulize.underscore.to_sym
|
308
|
+
@pxy_prop = add_attribute(pxy_attr, annotation_module.proxy, :saved)
|
309
|
+
logger.debug { "Added #{qp} => #{@pxy_prop.type} proxy attribute #{@pxy_prop}." }
|
310
|
+
end
|
311
|
+
|
312
|
+
# @param [ProxyClass] klass the proxy class
|
313
|
+
# @return [Jinx::Property] the annotation -> proxy attribute
|
314
|
+
def obtain_proxy_property(klass)
|
315
|
+
prop = infer_proxy_property(klass) || create_proxy_property(klass)
|
316
|
+
if prop.nil? then raise AnnotationError.new("Annotation #{qp} proxy attribute could not be found or created") end
|
317
|
+
logger.debug { "Annotation class #{qp} has proxy reference attribute #{prop}." }
|
318
|
+
prop
|
319
|
+
end
|
320
|
+
|
321
|
+
# @param [ProxyClass] klass the proxy class
|
322
|
+
# @return [Jinx::Property] the existing annotation -> proxy attribute
|
323
|
+
def infer_proxy_property(klass)
|
324
|
+
domain_attributes.each_property { |prop| return prop if prop.type == klass and prop.declarer == self }
|
325
|
+
nil
|
326
|
+
end
|
327
|
+
|
328
|
+
# @param [ProxyClass] klass the proxy class
|
329
|
+
# @return [Jinx::Property] the new annotation -> proxy attribute
|
330
|
+
def create_proxy_property(klass)
|
331
|
+
# the proxy attribute symbol
|
332
|
+
pa = annotation_module.name.demodulize.underscore.to_sym
|
333
|
+
logger.debug { "Creating primary annotation #{qp} => proxy #{klass} attribute #{pa}..." }
|
334
|
+
# make the attribute
|
335
|
+
attr_accessor(pa)
|
336
|
+
|
337
|
+
# Add the attribute. Setting the saved flag ensures that the save template passed to
|
338
|
+
# the annotation service includes a reference to the hook object. This in turn allows
|
339
|
+
# the annotation service to call the integration service to associate the annotation
|
340
|
+
# to the hook object.
|
341
|
+
prop = add_attribute(pa, proxy, :saved)
|
342
|
+
# make the inverse proxy -> annotation dependent attribute
|
343
|
+
inverse = klass.create_annotation_attribute(self)
|
344
|
+
logger.debug { "Created primary annotation #{qp} proxy #{klass} attribute #{pa} with inverse #{inverse}." }
|
345
|
+
|
346
|
+
prop
|
347
|
+
end
|
348
|
+
|
349
|
+
# Recursively saves the annotation dependency hierarchy rooted at the given annotation attribute.
|
350
|
+
#
|
351
|
+
# @param annotation (see #save_annotation)
|
352
|
+
# @param [Symbol] attribute the attribute to save
|
353
|
+
def save_dependent_attribute(annotation, attribute)
|
354
|
+
annotation.send(attribute).enumerate do |ref|
|
355
|
+
logger.debug { "Saving annotation #{annotation} #{attribute} dependent #{ref.qp}..." }
|
356
|
+
wtr = writer(attribute)
|
357
|
+
if wtr.nil? then raise AnnotationError.new("Annotation reference writer not found for #{qp} #{attribute}") end
|
358
|
+
wtr.save(ref)
|
359
|
+
ref.class.save_dependent_attributes(ref)
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
# @param [Symbol] attribute the annotation attribute
|
364
|
+
# @return [AnnotationWriter] the attribute writer for instances of this class
|
365
|
+
def writer(attribute)
|
366
|
+
attribute_writer_hash[attribute]
|
367
|
+
end
|
368
|
+
|
369
|
+
# @return [{Symbol => Annotation::ReferenceWriter}] the annotation attribute => writer hash
|
370
|
+
def map_writers
|
371
|
+
awh = {}
|
372
|
+
dependent_attributes.each_pair do |pa, prop|
|
373
|
+
# skip attributes defined in a superclass
|
374
|
+
next unless prop.declarer == self
|
375
|
+
if @entity_id.nil? then
|
376
|
+
raise AnnotationError.new("Cannot define reference writers for #{qp} since it does not have an entity id.")
|
377
|
+
end
|
378
|
+
awh[pa] = Annotation::ReferenceWriter.new(@entity_id, prop)
|
379
|
+
end
|
380
|
+
# If the superclass is also an annotation, then form the union of its writers with the local writers.
|
381
|
+
superclass < Annotation && superclass.primary? ? awh + superclass.attribute_writer_hash : awh
|
382
|
+
end
|
383
|
+
|
384
|
+
# Wraps the proxy reader method to convert a proxy to its hook.
|
385
|
+
#
|
386
|
+
# @param [Symbol] reader the proxy reader method
|
387
|
+
def convert_proxy_reader_result_to_hook(reader)
|
388
|
+
redefine_method(reader) do |old_mth|
|
389
|
+
# Alias the annotation module attribute name to the old method.
|
390
|
+
aliaz = annotation_module.name.demodulize.underscore.to_sym
|
391
|
+
alias_method(aliaz, old_mth)
|
392
|
+
# Convert the proxy to the hook.
|
393
|
+
lambda do
|
394
|
+
pxy = send(old_mth)
|
395
|
+
pxy.hook if pxy
|
396
|
+
end
|
397
|
+
end
|
398
|
+
logger.debug { "Redefined the #{qp} #{reader} reader method to convert a proxy parameter to its hook object." }
|
399
|
+
end
|
400
|
+
|
401
|
+
# Wraps the proxy writer method to convert a hook argument to its proxy.
|
402
|
+
#
|
403
|
+
# @param [Symbol] writer the proxy writer method
|
404
|
+
# @param [Symbol] inverse the hook => proxy attribute
|
405
|
+
def convert_proxy_writer_hook_argument_to_proxy(writer, inverse)
|
406
|
+
klass = annotation_module.hook
|
407
|
+
redefine_method(writer) do |old_mth|
|
408
|
+
# Alias the annotation module attribute name to the old method.
|
409
|
+
aliaz = "#{annotation_module.name.demodulize.underscore}=".to_sym
|
410
|
+
alias_method(aliaz, old_mth)
|
411
|
+
lambda do |value|
|
412
|
+
# Convert the parameter from a hook to a proxy, if necessary.
|
413
|
+
pxy = klass === value ? value.proxy_for(inverse, self) : value
|
414
|
+
unless pxy == value then logger.debug { "Converted #{qp} #{writer} argument from hook #{value.qp} to proxy #{pxy.qp}" } end
|
415
|
+
send(self.class.proxy_property.writer, pxy)
|
416
|
+
end
|
417
|
+
end
|
418
|
+
logger.debug { "Redefined the #{klass.qp} #{inverse} proxy writer #{writer} to convert a hook #{klass.qp} parameter to the hook proxy." }
|
419
|
+
end
|
420
|
+
end
|
421
|
+
end
|
422
|
+
end
|