0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenclass Ontology
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen # An ontology being imported into is in this context not only a Mapping with
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen # kind 'import' but any kind of mapping. Otherwise the target ontology's view,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen # alignment, etc. is invalid.
1171f0abf442638bac1827bb24a0b6b8eb682a82Timo Sirainen module ImportMappings
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen extend ActiveSupport::Concern
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen included do
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen def mapping_targets
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen source_mappings.map(&:target)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
a40d26f83af808a0ea1e212c001d682a96d870b0Timo Sirainen def imported_ontologies
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen fetch_mappings_by_kind(self, 'import')
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen def direct_imported_ontologies
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen ontology_ids = Mapping.where(target_id: self, kind: 'import').
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen pluck(:source_id)
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen Ontology.where(id: ontology_ids)
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen def source_mappings_from_other_files
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen source_mappings.reject do |l|
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen l.target.repository == repository && l.target.path == path
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen def source_mappings_from_other_repositories
a40d26f83af808a0ea1e212c001d682a96d870b0Timo Sirainen source_mappings.select { |l| l.target.repository != repository }
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
a40d26f83af808a0ea1e212c001d682a96d870b0Timo Sirainenend
a40d26f83af808a0ea1e212c001d682a96d870b0Timo Sirainen