Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebase Fedora 6 work on ActiveFedora 15 #1504

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9eaa76b
Types should be in headers.
tpendragon Oct 17, 2019
70ad520
Fix direct containers.
tpendragon Oct 17, 2019
0a5467f
Fix containers.
tpendragon Oct 18, 2019
3ec5f9e
Set FCRepo version.
tpendragon Oct 18, 2019
21d9b27
Set FCRepo version.
tpendragon Oct 18, 2019
f1f9b37
Update for versionable resources, no API for restoring versions
stkenny Nov 4, 2020
23ae08d
External binaries specified with Link header
stkenny Nov 12, 2020
89c0304
Retrieve value for external binary handling
stkenny Nov 13, 2020
2b5595e
Update fcrepo_wrapper config for v6
stkenny Mar 16, 2021
3ec4125
Fix for clean connection spec
stkenny Mar 16, 2021
b091b47
WIP: Fedora has to be able to resolve the external uri so it needs th…
cjcolvar Nov 3, 2021
4903f1f
fcr:fixity cannot be called on a memento version but a digest can be …
cjcolvar Nov 5, 2021
7b5a12c
Specify custom docker executor instead of one coming from the orb
cjcolvar Nov 5, 2021
258531d
Remove unneeded prereq environment task since it doesn't get loaded b…
cjcolvar Mar 23, 2023
7d9ea66
Appease rubocop
cjcolvar Mar 23, 2023
4fc0c64
Use latest fcrepo jar
cjcolvar Mar 23, 2023
6952f26
Use Array#join instead Rails.root.join since it is no longer available
cjcolvar Mar 24, 2023
af0e9a5
Fix call to graph.query for new method signature
cjcolvar Mar 24, 2023
486b888
Rewrite file streaming to use faraday instead of Net::HTTP; require f…
cjcolvar Apr 3, 2023
f112394
Test with fedora 6.4.0 image
cjcolvar Apr 4, 2023
777b3b0
Use non-ntriples connection when making head requests during descenda…
cjcolvar Apr 4, 2023
0f5ccb1
Test on fcrepo 6.5
cjcolvar Oct 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ orbs:
jobs:
bundle_lint_test:
parameters:
ruby_type:
type: string
default: 'ruby'
ruby_version:
type: string
bundler_version:
Expand All @@ -14,23 +17,22 @@ jobs:
solr_config_path:
type: string
default: lib/generators/active_fedora/config/solr/templates/solr/conf
ruby_type:
type: string
default: 'ruby'
solr_port:
type: string
default: '8985'
fcrepo_version:
type: string
default: "4.7.5"
default: "5.1.0"
solr_version:
type: string
default: "9"
docker:
- image: cimg/<< parameters.ruby_type >>:<< parameters.ruby_version >>-browsers
- image: samvera/fcrepo4:<< parameters.fcrepo_version >>
- image: fcrepo/fcrepo:6.5-tomcat9
environment:
CATALINA_OPTS: "-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms512m -Xmx1024m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m -XX:MaxPermSize=256m -XX:+DisableExplicitGC"
JAVA_OPTS: -Dfcrepo.autoversioning.enabled=false -Dfcrepo.external.content.allowed=/fcrepo_allow.txt
command: |
/bin/bash -c "echo 'http://fedoraAdmin:fedoraAdmin@localhost:8080/' > /fcrepo_allow.txt && catalina.sh run"
- image: zookeeper:3.9
environment:
ZOO_ADMINSERVER_ENABLED: false
Expand All @@ -48,6 +50,8 @@ jobs:
FCREPO_TEST_PORT: 8080
SPEC_OPTS: --profile 10 --format RspecJunitFormatter --out /tmp/test-results/rspec.xml --format progress
RAILS_VERSION: << parameters.rails_version >>
FCREPO_PORT: 8080
FCREPO_REST_PATH: fcrepo/rest
steps:
- samvera/cached_checkout
- checkout
Expand Down
10 changes: 10 additions & 0 deletions .fcrepo_wrapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Place any default configuration for solr_wrapper here
port: 8986
version: 6.4.0
enable_jms: false
java_options: ['-Dfcrepo.log.http.api=DEBUG','-Dfcrepo.log.kernel=ERROR','-Xmx512m',
'-Dfcrepo.external.content.allowed=config/fcrepo_allow.txt', '-Dfcrepo.autoversioning.enabled=false']
#managed: true
#fcrepo_home_dir: tmp/fcrepo-development-data
url: https://github.com/fcrepo/fcrepo/releases/download/fcrepo-6.4.0/fcrepo-webapp-6.4.0-jetty-console.jar
ignore_md5sum: true
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ Rails/FilePath:
Rails/ActiveRecordAliases:
Enabled: false

Rails/RakeEnvironment:
Enabled: false

Rails/SkipsModelValidations:
Enabled: false

Expand Down
2 changes: 1 addition & 1 deletion .solr_wrapper
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Place any default configuration for solr_wrapper here
# version: 6.1.0
version: 7.7.3
port: 8985
collection:
dir: lib/generators/active_fedora/config/solr/templates/solr/conf/
Expand Down
3 changes: 2 additions & 1 deletion active-fedora.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ Gem::Specification.new do |s|
s.add_dependency "activesupport", '>= 6.1'
s.add_dependency "active-triples", '>= 0.11.0', '< 2.0.0'
s.add_dependency "deprecation"
s.add_dependency 'faraday', '>= 1.0'
s.add_dependency 'faraday', '>= 2.0'
s.add_dependency 'faraday-encoding', '>= 0.0.5'
s.add_dependency 'faraday-follow_redirects'
s.add_dependency "ldp", '>= 0.7.0', '< 2'
s.add_dependency "mutex_m"
s.add_dependency 'rsolr', '>= 1.1.2', '< 3'
Expand Down
3 changes: 3 additions & 0 deletions config/fcrepo_allow.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://example.com/
http://example.com/
http://localhost:8986/
2 changes: 2 additions & 0 deletions lib/active_fedora/attached_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def add_file(file, opts)
node.content = file
node.mime_type = opts[:mime_type]
node.original_name = opts[:original_name]
node.external_uri = opts[:external_uri]
node.external_handling = opts[:external_handling]
end
end

Expand Down
4 changes: 3 additions & 1 deletion lib/active_fedora/change_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def changes
elsif key == 'type'.freeze
# working around https://github.com/ActiveTriples/ActiveTriples/issues/122
predicate = ::RDF.type
result[predicate] = graph.query({ subject: object.rdf_subject, predicate: predicate })
result[predicate] = graph.query({ subject: object.rdf_subject, predicate: predicate }).select do |statement|
!statement.object.to_s.start_with?("http://fedora.info/definitions/v4/repository#", "http://www.w3.org/ns/ldp#")
end
elsif object.local_attributes.include?(key)
raise "Unable to find a graph predicate corresponding to the attribute: \"#{key}\""
end
Expand Down
1 change: 1 addition & 0 deletions lib/active_fedora/clean_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def get(*args)

def omit_uris
[
"http://fedora.info/definitions/fcrepo#ServerManaged",
::RDF::Vocab::Fcrepo4.ServerManaged,
::RDF::Vocab::LDP.PreferContainment,
::RDF::Vocab::LDP.PreferEmptyContainer,
Expand Down
1 change: 0 additions & 1 deletion lib/active_fedora/containers/direct_container.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module ActiveFedora
class DirectContainer < Container
type ::RDF::Vocab::LDP.DirectContainer
end
end
2 changes: 0 additions & 2 deletions lib/active_fedora/containers/indirect_container.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module ActiveFedora
class IndirectContainer < Container
type ::RDF::Vocab::LDP.IndirectContainer

property :inserted_content_relation, predicate: ::RDF::Vocab::LDP.insertedContentRelation
end
end
3 changes: 3 additions & 0 deletions lib/active_fedora/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ class File

autoload :Streaming
autoload :Attributes
autoload :External

include Common
include ActiveFedora::File::Attributes
include ActiveFedora::File::Streaming
include ActiveFedora::File::External
include ActiveFedora::FilePersistence
include ActiveFedora::Versionable
include ActiveModel::Dirty
Expand Down Expand Up @@ -175,6 +177,7 @@ def retrieve_content
def ldp_headers
headers = { 'Content-Type'.freeze => mime_type, 'Content-Length'.freeze => content.size.to_s }
headers['Content-Disposition'.freeze] = "attachment; filename=\"#{URI::DEFAULT_PARSER.escape(@original_name)}\"" if @original_name
headers["Link"] = "<#{@external_uri}>; rel=\"http://fedora.info/definitions/fcrepo#ExternalContent\"; handling=\"#{@external_handling}\"; type=\"#{mime_type}\"" if @external_uri
headers
end

Expand Down
39 changes: 39 additions & 0 deletions lib/active_fedora/file/external.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module ActiveFedora::File::External
HANDLING_TYPES = ['redirect', 'proxy', 'copy'].freeze

def external_uri
@external_uri ||= fetch_external_uri
end

def external_uri=(uri)
@external_uri = uri
end

def external_handling=(handling)
@external_handling = handling
end

def external_handling
@external_handling ||= fetch_external_handling
end

private

def fetch_external_uri
return if new_record?
ldp_source.head.response.headers['Content-Location']
end

def fetch_external_handling
return if new_record?
response = ldp_source.head.response
return unless response.headers.key?('Content-Location')

case response.status
when Net::HTTPRedirection
'redirect'
when Net::HTTPSuccess
'proxy'
end
end
end
57 changes: 30 additions & 27 deletions lib/active_fedora/file/streaming.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
require 'faraday/follow_redirects'

module ActiveFedora::File::Streaming
# @param range [String] the Range HTTP header
# @return [Stream] an object that responds to each
def stream(range = nil)
uri = URI.parse(self.uri)
FileBody.new(uri, headers(range, authorization_key))
FileBody.new(uri, headers(range, nil))
end

# @param range [String] from #stream
# @param key [String] from #authorization_key
# @return [Hash]
def headers(range, key, result = {})
def headers(range, _key, result = {})
result["Range"] = range if range
result["Authorization"] = key if key
result
end

Expand All @@ -22,32 +22,35 @@ def initialize(uri, headers)
@headers = headers
end

def each(no_of_requests_limit = 3, &block)
raise ArgumentError, 'HTTP redirect too deep' if no_of_requests_limit.zero?
Net::HTTP.start(uri.host, uri.port, use_ssl: (uri.scheme == 'https')) do |http|
request = Net::HTTP::Get.new uri, headers
http.request request do |response|
case response
when Net::HTTPSuccess
response.read_body do |chunk|
yield chunk
end
when Net::HTTPRedirection
no_of_requests_limit -= 1
@uri = URI(response["location"])
each(no_of_requests_limit, &block)
else
raise "Couldn't get data from Fedora (#{uri}). Response: #{response.code}"
end
def each(no_of_requests_limit = 3)
redirecting_connection(no_of_requests_limit).get(uri.to_s, nil, headers) do |req|
req.options.on_data = proc do |chunk, overall_received_bytes, _env|
yield chunk unless overall_received_bytes.zero? # Don't yield when redirecting
end
end
rescue Faraday::FollowRedirects::RedirectLimitReached
raise ArgumentError, 'HTTP redirect too deep'
rescue Faraday::Error => ex
raise "Couldn't get data from Fedora (#{uri}). Response: #{ex.response_status}"
end
end

private
private

# @return [String] current authorization token from Ldp::Client
def authorization_key
ldp_source.client.http.headers.fetch("Authorization", nil)
end
# Create a new faraday connection with follow_redirects enabled and configured using passed value
def redirecting_connection(redirection_limit)
options = {}
options[:ssl] = ActiveFedora.fedora.ssl_options if ActiveFedora.fedora.ssl_options
options[:request] = ActiveFedora.fedora.request_options if ActiveFedora.fedora.request_options
Faraday.new(ActiveFedora.fedora.host, options) do |conn|
conn.response :encoding # use Faraday::Encoding middleware
conn.adapter Faraday.default_adapter # net/http
if Gem::Version.new(Faraday::VERSION) < Gem::Version.new('2')
conn.request :basic_auth, ActiveFedora.fedora.user, ActiveFedora.fedora.password
else
conn.request :authorization, :basic, ActiveFedora.fedora.user, ActiveFedora.fedora.password
conn.response :follow_redirects, limit: redirection_limit - 1 # Need to reduce by one to retain same behavior as before
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/active_fedora/file_configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def config_path(config_type)
end

if defined?(Rails.root)
config_path = "#{Rails.root}/config/#{config_type}.yml"
config_path = [Rails.root, "config/#{config_type}.yml"].join('/')
return config_path if ::File.file? config_path
end

Expand Down
8 changes: 7 additions & 1 deletion lib/active_fedora/indexing/descendant_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def descendant_and_self_uris_partitioned
def descendant_and_self_uris_partitioned_by_model
# GET could be slow if it's a big resource, we're using HEAD to avoid this problem,
# but this causes more requests to Fedora.
return partitioned_uris unless rdf_resource.head.rdf_source?
return partitioned_uris unless rdf_source?

add_self_to_partitioned_uris unless @exclude_self

Expand All @@ -76,6 +76,12 @@ def descendant_and_self_uris_partitioned_by_model

protected

# Fcrepo 6.4 returns a 406 for file objects when returning ntriples
# so use the standard connection just for the head request
def rdf_source?
Ldp::Resource.new(ActiveFedora.fedora.connection, uri).head.rdf_source?
end

def rdf_resource
@rdf_resource ||= Ldp::Resource::RdfSource.new(ActiveFedora.fedora.build_ntriples_connection, uri)
end
Expand Down
25 changes: 20 additions & 5 deletions lib/active_fedora/ldp_resource.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
module ActiveFedora
class LdpResource < Ldp::Resource::RdfSource
def build_empty_graph
graph_class.new(subject_uri)
module LdpResourceAddons
extend ActiveSupport::Concern
module ClassMethods
def graph_class
ActiveTriples::Resource
end
end

def self.graph_class
ActiveTriples::Resource
def build_empty_graph
graph_class.new(subject_uri)
end

def graph_class
Expand All @@ -27,4 +30,16 @@ def response_as_graph(resp)
graph_class.new(subject_uri, data: resp.graph.data)
end
end

class LdpResource < Ldp::Resource::RdfSource
include LdpResourceAddons
end

class IndirectContainerResource < Ldp::Container::Indirect
include LdpResourceAddons
end

class DirectContainerResource < Ldp::Container::Direct
include LdpResourceAddons
end
end
15 changes: 13 additions & 2 deletions lib/active_fedora/ldp_resource_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@ def initialize(conn)
end

def build(klass, id)
resource_klass = resource_klass(klass)
if id
LdpResource.new(connection, to_uri(klass, id))
resource_klass.new(connection, to_uri(klass, id))
else
parent_uri = ActiveFedora.fedora.host + ActiveFedora.fedora.base_path
LdpResource.new(connection, nil, nil, parent_uri)
resource_klass.new(connection, nil, nil, parent_uri)
end
end

def resource_klass(klass)
if klass <= ActiveFedora::IndirectContainer
IndirectContainerResource
elsif klass <= ActiveFedora::DirectContainer
DirectContainerResource
else
LdpResource
end
end

Expand Down
5 changes: 3 additions & 2 deletions lib/active_fedora/persistence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,11 @@ def identifier_service
# and assign_id can mint an id for the object, then assign it to the resource.
# Otherwise the resource will have the id assigned by the LDP server
def assign_rdf_subject
ldp_resource_klass = ActiveFedora.fedora.ldp_resource_service.resource_klass(self.class)
@ldp_source = if !id && new_id = assign_id
LdpResource.new(ActiveFedora.fedora.connection, self.class.id_to_uri(new_id), @resource)
ldp_resource_klass.new(ActiveFedora.fedora.connection, self.class.id_to_uri(new_id), @resource)
else
LdpResource.new(ActiveFedora.fedora.connection, @ldp_source.subject, @resource, base_path_for_resource)
ldp_resource_klass.new(ActiveFedora.fedora.connection, @ldp_source.subject, @resource, base_path_for_resource)
end
end

Expand Down
Loading