Sha256: 0ad9a68ee00ee69590f430402b24657c6677d6d3da6e36232eb4aee1c36b9393

Contents?: true

Size: 1.18 KB

Versions: 4

Compression:

Stored size: 1.18 KB

Contents

module ActiveFedora
  class FixityService
    extend ActiveSupport::Concern

    attr_accessor :target, :response

    # @param [String, RDF::URI] target url for a Fedora resource
    def initialize target
      raise ArgumentError, 'You must provide a uri' unless target
      @target = target.to_s
    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: ActiveFedora::RDF::Fcrepo4.status).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

      # See https://jira.duraspace.org/browse/FCREPO-1247
      # @param [String] uri
      def encoded_url uri
        if uri.match("fcr:versions")
          uri.gsub(/fcr:versions/,"fcr%3aversions")
        else
          uri
        end
      end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
active-fedora-9.3.0 lib/active_fedora/fixity_service.rb
active-fedora-9.2.1 lib/active_fedora/fixity_service.rb
active-fedora-9.2.0 lib/active_fedora/fixity_service.rb
active-fedora-9.2.0.rc2 lib/active_fedora/fixity_service.rb