Skip to content

Commit

Permalink
example middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
rshewitt committed Aug 23, 2024
1 parent dffa052 commit ab2011a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ gem 'psych', '< 4.0.0'

gem 'adiwg-mdtranslator',
git: 'https://github.com/GSA/mdTranslator.git',
branch: 'datagov'
# branch: 'feature/iso19115_3-reader'
branch: 'cleanup'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GIT
remote: https://github.com/GSA/mdTranslator.git
revision: fe10f1d66171757f87be54e3053e0c09821500b4
branch: datagov
revision: 4a0bbb7ee5043ec4c6a9c2ef7e8d52af534de197
branch: cleanup
specs:
adiwg-mdtranslator (2.20.0.pre.beta.5)
adiwg-mdcodes (= 2.10.0)
Expand Down
5 changes: 5 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# require "sprockets/railtie"
require 'rails/test_unit/railtie'

require_relative '../lib/middleware/md_transformer'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
Expand All @@ -26,6 +28,9 @@ class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 6.0

# intermediate transformation middleware
config.middleware.use MetadataTransformer

# Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers
# -- all .rb files in that directory are automatically loaded after loading
Expand Down
38 changes: 38 additions & 0 deletions lib/middleware/md_transformer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'nokogiri'

class MetadataTransformer
def initialize(app)
@app = app
end

def determine_fgdc(xfgdc)
# FGDC CSDGM Version 2.0, 1998 ( FGDC-STD-001-1998)
# FGDC CSDGM Biological Data Profile (FGDC-STD-001.1-1999)
# FGDC CSDGM Metadata Profile for Shoreline Data (FGDC-STD-001.2-2001)
# FGDC Extension for Remote Sensing (FGDC-STD-012-2002)
# fgdc_standards = { 'FGDC-STD-001-1998' => 'version 2.0', 'FGDC-STD-001.1-1999' }
fgdc_standard_xpath = 'metainfo//metstdv'

standard = xfgdc.xpath(fgdc_standard_xpath)[0]
end

def determine_iso(x); end

def determine_schema(xml_str)
fgdc_root = 'metadata'
begin
xDoc = Nokogiri::XML(xml_str, &:strict)
rescue Nokogiri::XML::SyntaxError => e
'ERROR: XML file is not well formed'
end
end

def call(env)
request = Rack::Request.new(env)
file_param = request.params['file']
# transform
# request.update_param('file', transformed_file)

@app.call(env)
end
end

0 comments on commit ab2011a

Please sign in to comment.