Sha256: 2f90c279be31a50a9ce62184aa3f5d3193d74665b82490d907c4357d0b489d08

Contents?: true

Size: 1.14 KB

Versions: 8

Compression:

Stored size: 1.14 KB

Contents

module ActiveFedora
  class FixityService
    extend ActiveSupport::Concern

    attr_accessor :target, :response

    # Accepts an Fedora resource such as File.ldp_resource.subject
    def initialize target
      raise ArgumentError, 'You must provide a uri' unless target
      @target = target
    end

    # Executes a fixity check on Fedora and saves the Faraday::Response.
    # Returns true when the fixity check was successfully.
    def check
      @response = get_fixity_response_from_fedora
      status.match("SUCCESS") ? true : false
    end

    def status
      fixity_graph.query(predicate: status_url).map(&:object).first.to_s
    end

    private

    def get_fixity_response_from_fedora
      uri = target + "/fcr:fixity"
      ActiveFedora.fedora.connection.get(encoded_url(uri))
    end

    def fixity_graph
      ::RDF::Graph.new << ::RDF::Reader.for(:ttl).new(response.body)
    end

    def status_url
      ::RDF::URI("http://fedora.info/definitions/v4/repository#status")
    end

    def encoded_url uri
      if uri.match("fcr:versions")
        uri.gsub(/fcr:versions/,"fcr%3aversions")
      else
        uri
      end
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
active-fedora-9.0.0.rc2 lib/active_fedora/fixity_service.rb
active-fedora-9.0.0.rc1 lib/active_fedora/fixity_service.rb
active-fedora-9.0.0.beta8 lib/active_fedora/fixity_service.rb
active-fedora-9.0.0.beta7 lib/active_fedora/fixity_service.rb
active-fedora-9.0.0.beta6 lib/active_fedora/fixity_service.rb
active-fedora-9.0.0.beta5 lib/active_fedora/fixity_service.rb
active-fedora-9.0.0.beta4 lib/active_fedora/fixity_service.rb
active-fedora-9.0.0.beta3 lib/active_fedora/fixity_service.rb