Module: ExportHelpers
- Defined in:
- backend/app/lib/export.rb
Instance Method Summary collapse
-
#generate_dc(id) ⇒ Object
-
#generate_eac(id, type) ⇒ Object
-
#generate_ead(id, include_unpublished, include_daos, include_uris, use_numbered_c_tags, ead3) ⇒ Object
-
#generate_labels(id) ⇒ Object
-
#generate_marc(id, include_unpublished = false) ⇒ Object
-
#generate_marc_auth(id, type) ⇒ Object
-
#generate_mets(id, dmd = "mods") ⇒ Object
-
#generate_mods(id) ⇒ Object
-
#generate_pdf_from_ead(ead, image_for_pdf) ⇒ Object
-
#pdf_response(pdf) ⇒ Object
-
#safe_filename(id, suffix = "") ⇒ Object
this takes identifiers and makes sure there’s no ‘funny’ characters.
-
#stream_response(streamer, content_type = "application/xml") ⇒ Object
-
#tsv_response(tsv) ⇒ Object
-
#xml_response(xml) ⇒ Object
Instance Method Details
#generate_dc(id) ⇒ Object
43 44 45 46 47 |
# File 'backend/app/lib/export.rb', line 43 def generate_dc(id) obj = resolve_references(DigitalObject.to_jsonmodel(id), ['repository', 'linked_agents', 'subjects']) dc = ASpaceExport.model(:dc).from_digital_object(JSONModel(:digital_object).new(obj)) ASpaceExport::serialize(dc) end |
#generate_eac(id, type) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'backend/app/lib/export.rb', line 113 def generate_eac(id, type) klass = Kernel.const_get(type.camelize) events = [] agent = klass.get_or_die(id) relationship_defn = klass.find_relationship(:linked_agents) = relationship_defn.find_by_participant(agent).map {|relation| = relation.other_referent_than(agent) next unless [Resource, ArchivalObject, DigitalObject, DigitalObjectComponent].include?(.class) RequestContext.open(:repo_id => .repo_id) do { :role => BackendEnumSource.values_for_ids(relation[:role_id])[relation[:role_id]], :record => .class.to_jsonmodel(, :skip_relationships => true) } end }.compact obj = resolve_references(klass.to_jsonmodel(agent), ['related_agents']) repo_json = Repository.to_jsonmodel(RequestContext.get(:repo_id)) repo = JSONModel(:repository).new(repo_json) eac = ASpaceExport.model(:eac).from_agent(JSONModel(type.intern).new(obj), events, , repo) ASpaceExport::serialize(eac) end |
#generate_ead(id, include_unpublished, include_daos, include_uris, use_numbered_c_tags, ead3) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'backend/app/lib/export.rb', line 87 def generate_ead(id, include_unpublished, include_daos, include_uris, , ead3) resolve = ['repository', 'linked_agents', 'subjects', 'digital_object', 'top_container', 'top_container::container_profile'] resource = Resource.get_or_die(id) jsonmodel = JSONModel(:resource).new(resolve_references(Resource.to_jsonmodel(resource), resolve)) opts = { :include_unpublished => include_unpublished, :include_daos => include_daos, :include_uris => include_uris, :use_numbered_c_tags => , :ead3 => ead3 } if ead3 opts[:serializer] = :ead3 end # SPECIFY SERIALIZER HERE ead = ASpaceExport.model(:ead).from_resource(jsonmodel, resource.tree(:all, mode = :sparse), opts) ASpaceExport::stream(ead, opts) end |
#generate_labels(id) ⇒ Object
34 35 36 37 38 39 40 |
# File 'backend/app/lib/export.rb', line 34 def generate_labels(id) resource = Resource.get_or_die(id) obj = resolve_references(Resource.to_jsonmodel(resource), ['repository']) labels = ASpaceExport.model(:labels).from_resource(JSONModel(:resource).new(obj), resource.tree(:all, mode = :sparse)) labels end |
#generate_marc(id, include_unpublished = false) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'backend/app/lib/export.rb', line 74 def generate_marc(id, include_unpublished = false) obj = resolve_references(Resource.to_jsonmodel(id), ['repository', 'linked_agents', 'subjects']) opts = {:include_unpublished => include_unpublished} resource = JSONModel(:resource).new(obj) JSONModel::set_publish_flags!(resource) marc = ASpaceExport.model(:marc21).from_resource(resource, opts) ASpaceExport::serialize(marc) end |
#generate_marc_auth(id, type) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'backend/app/lib/export.rb', line 142 def generate_marc_auth(id, type) klass = Kernel.const_get(type.camelize) events = [] agent = klass.get_or_die(id) relationship_defn = klass.find_relationship(:linked_agents) = relationship_defn.find_by_participant(agent).map {|relation| = relation.other_referent_than(agent) next unless [Resource, ArchivalObject, DigitalObject, DigitalObjectComponent].include?(.class) RequestContext.open(:repo_id => .repo_id) do { :role => BackendEnumSource.values_for_ids(relation[:role_id])[relation[:role_id]], :record => .class.to_jsonmodel(, :skip_relationships => true) } end }.compact obj = resolve_references(klass.to_jsonmodel(agent), ['related_agents']) repo_json = Repository.to_jsonmodel(RequestContext.get(:repo_id)) repo = JSONModel(:repository).new(repo_json) ma = ASpaceExport.model(:marc_auth).from_agent(JSONModel(type.intern).new(obj), events, , repo) ASpaceExport::serialize(ma) end |
#generate_mets(id, dmd = "mods") ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'backend/app/lib/export.rb', line 50 def generate_mets(id, dmd = "mods") digital_object = DigitalObject.get_or_die(id) obj = resolve_references(DigitalObject.to_jsonmodel(digital_object), ['repository::agent_representation', 'linked_agents', 'subjects']) # FIXME: This currently still uses the full digital object tree because it # needs access to all file versions. Maybe there's some other way we could # get this data out? mets = ASpaceExport.model(:mets).from_digital_object(JSONModel(:digital_object).new(obj), digital_object.tree(:all)) ASpaceExport::serialize(mets, {:dmd => dmd}) end |
#generate_mods(id) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'backend/app/lib/export.rb', line 64 def generate_mods(id) digital_object = DigitalObject.get_or_die(id) obj = resolve_references(DigitalObject.to_jsonmodel(digital_object), ['repository::agent_representation', 'linked_agents', 'subjects']) mods = ASpaceExport.model(:mods).from_digital_object(JSONModel(:digital_object).new(obj), digital_object.tree(:all, mode = :sparse)) ASpaceExport::serialize(mods) end |
#generate_pdf_from_ead(ead, image_for_pdf) ⇒ Object
13 14 15 16 17 |
# File 'backend/app/lib/export.rb', line 13 def generate_pdf_from_ead(ead, image_for_pdf) xml = "" ead.each { |e| xml << e } ASFop.new(xml, image_for_pdf).to_pdf end |
#pdf_response(pdf) ⇒ Object
9 10 11 |
# File 'backend/app/lib/export.rb', line 9 def pdf_response(pdf) [status, {"Content-Type" => "application/pdf"}, pdf ] end |
#safe_filename(id, suffix = "") ⇒ Object
this takes identifiers and makes sure there’s no ‘funny’ characters. usefuly for filenaming on exports.
173 174 175 176 |
# File 'backend/app/lib/export.rb', line 173 def safe_filename(id, suffix = "") filename = "#{id}_#{Time.now.getutc}_#{suffix}" filename.gsub(/\s+/, '_').gsub(/[^0-9A-Za-z_\.]/, '') end |
#stream_response(streamer, content_type = "application/xml") ⇒ Object
24 25 26 |
# File 'backend/app/lib/export.rb', line 24 def stream_response(streamer, content_type = "application/xml") [status, {"Content-Type" => content_type}, streamer] end |
#tsv_response(tsv) ⇒ Object
29 30 31 |
# File 'backend/app/lib/export.rb', line 29 def tsv_response(tsv) [status, {"Content-Type" => "text/tab-separated-values"}, tsv.stream] end |
#xml_response(xml) ⇒ Object
19 20 21 |
# File 'backend/app/lib/export.rb', line 19 def xml_response(xml) [status, {"Content-Type" => "application/xml"}, [xml + "\n"]] end |