Class: Opencdd::Parcel::EntityManifest

Inherits:
Object
  • Object
show all
Defined in:
lib/opencdd/parcel/entity_manifest.rb

Overview

Reads the harvester's _entity.json sidecar format and converts it into Opencdd::Entity::VersionHistory entries and stub entities for cross-reference resolution.

Extracted from ShardedDirReader so the JSON-shape concern has its own home and can be tested with a hash fixture instead of requiring a full directory tree on disk.

The sidecar schema (produced by harvest/download_versions.py):

{
"irdi": "0112/2///62656_1#AAA001",
"entity_type": "class",                 # Symbol
"current_version_dir": "ABC123...",     # UNID subfolder name
"versions": [
  { "version": 1, "revision": 0, "status": "Released",
    "timestamp": "2024-01-15T10:23:00Z", "user": "...",
    "change_request_id": "...", "unid": "...",
    "is_current": true }
]
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, path = nil) ⇒ EntityManifest

Returns a new instance of EntityManifest.



42
43
44
45
# File 'lib/opencdd/parcel/entity_manifest.rb', line 42

def initialize(data, path = nil)
  @data = data
  @path = path
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



29
30
31
# File 'lib/opencdd/parcel/entity_manifest.rb', line 29

def data
  @data
end

#pathObject (readonly)

Returns the value of attribute path.



29
30
31
# File 'lib/opencdd/parcel/entity_manifest.rb', line 29

def path
  @path
end

Class Method Details

.read(entity_dir) ⇒ Object

Returns a manifest for entity_dir, or nil when no _entity.json lives there or the file is unparseable.



33
34
35
36
37
38
39
40
# File 'lib/opencdd/parcel/entity_manifest.rb', line 33

def self.read(entity_dir)
  path = File.join(entity_dir, "_entity.json")
  return nil unless File.file?(path)
  data = JSON.parse(File.read(path))
  new(data, path)
rescue JSON::ParserError
  nil
end

Instance Method Details

#current_version_dirObject

Name of the per-version subfolder that holds the current version's XLS exports. nil for flat-layout manifests.



67
68
69
# File 'lib/opencdd/parcel/entity_manifest.rb', line 67

def current_version_dir
  @data["current_version_dir"]
end

#entity_typeObject

Symbol type (:class, :property, ...) or nil.



55
56
57
# File 'lib/opencdd/parcel/entity_manifest.rb', line 55

def entity_type
  @data["entity_type"]&.to_sym
end

#irdiObject

IRDI of the entity this manifest describes, or nil.



48
49
50
51
52
# File 'lib/opencdd/parcel/entity_manifest.rb', line 48

def irdi
  raw = @data["irdi"]
  return nil if raw.nil?
  Opencdd::IRDI.parse(raw.to_s)
end

#meta_class_codeObject

Meta-class IRDI code (e.g. "MDC_C002"), or nil if the type isn't registered.



61
62
63
# File 'lib/opencdd/parcel/entity_manifest.rb', line 61

def meta_class_code
  Opencdd::MetaClasses.meta_class_for_type(entity_type)
end

#to_stub_entityObject

Constructs a minimal stub entity from this manifest, so cross-references to entities that weren't loaded from a .xls still resolve. Returns nil if the manifest lacks an IRDI, type, or known meta-class.



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/opencdd/parcel/entity_manifest.rb', line 89

def to_stub_entity
  return nil unless irdi && meta_class_code
  meta_class = Opencdd::MetaClasses.for(meta_class_code)
  return nil unless meta_class&.entity_class

  code_property_id = Opencdd::MetaClasses.code_property_id_for(meta_class_code)
  props = code_property_id ? { code_property_id => @data["irdi"].to_s } : {}
  meta_class.entity_class.new(
    irdi: irdi,
    properties: props,
    meta_class_irdi: Opencdd::IRDI.parse(meta_class_code),
  )
end

#version_historyObject

Version history compiled from the versions array. Empty when no versions are listed.



73
74
75
76
77
78
79
# File 'lib/opencdd/parcel/entity_manifest.rb', line 73

def version_history
  vh = Opencdd::Entity::VersionHistory.new
  Array(@data["versions"]).each do |v|
    vh.attach(build_entry(v))
  end
  vh
end

#versions_empty?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/opencdd/parcel/entity_manifest.rb', line 81

def versions_empty?
  Array(@data["versions"]).empty?
end