Skip to content

Instantly share code, notes, and snippets.

View dchandekstark's full-sized avatar

David Chandek-Stark dchandekstark

  • Duke University Libraries
  • Durham, North Carolina USA
View GitHub Profile
@dchandekstark
dchandekstark / add_duke_terms_to_desc_metadata.rb
Created June 17, 2014 14:31
Add Duke terms to descMetadata
ActiveFedora::Base.find_each({}, {cast: true}) do |obj|
unless obj.datastreams["descMetadata"].is_a? DulHydra::Datastreams::DescriptiveMetadataDatastream
puts "SKIPPED #{obj.pid} -- descMetadata is not a DulHydra::Datastreams::DescriptiveMetadataDatastream"
next
end
doc = obj.descMetadata.ng_xml
if doc.namespaces.include? "xmlns:#{DulHydra::Metadata::DukeTerms::NAMESPACE_PREFIX}"
puts "SKIPPED #{obj.pid} -- already has Duke terms namespace"
next
end
@dchandekstark
dchandekstark / preservation_event_type.rb
Created June 3, 2014 18:52
RDF Vocabulary: Preservation Event Types
require 'rdf'
class PreservationEventType < RDF::StrictVocabulary("http://id.loc.gov/vocabulary/preservation/eventType/")
property :cap, label: "capture"
property :com, label: "compression"
property :cre, label: "creation"
property :dea, label: "deaccession"
property :dec, label: "decompression"
property :der, label: "decryption"
property :del, label: "deletion"
@dchandekstark
dchandekstark / README.md
Last active August 29, 2015 14:01
UniquenessValidator for ActiveFedora

Notes

  • Modeled after ActiveRecord::Validations::UniquenessValidator
  • Only supports uniqueness for attributes, not associations.
  • Because indexing can vary, only supports one attribute at a time. Defaults to the :symbol indexer (*_ssim). Index field can be declared explicitly with :index_field option, or implicitly with :index_type and :data_type options.
  • Designed for single-valued attributes, i.e., :multiple => false. Should work for multi-valued attributes having single value; may work (perhaps not exactly as desired) for attributes having multiple values.
  • Does not support scoping or extra conditions.

Instructions

@dchandekstark
dchandekstark / dcterms.rdf
Last active August 29, 2015 14:01
RDF query
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rdf:RDF [
<!ENTITY rdfns 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
<!ENTITY rdfsns 'http://www.w3.org/2000/01/rdf-schema#'>
<!ENTITY dcns 'http://purl.org/dc/elements/1.1/'>
<!ENTITY dctermsns 'http://purl.org/dc/terms/'>
<!ENTITY dctypens 'http://purl.org/dc/dcmitype/'>
<!ENTITY dcamns 'http://purl.org/dc/dcam/'>
<!ENTITY skosns 'http://www.w3.org/2004/02/skos/core#'>
<!ENTITY owlns 'http://www.w3.org/2002/07/owl#'>
CHUNK = 1024**2
def add_file(file, dsid, file_name)
return add_external_file(file, file_name) if dsid == 'content'
super
end
def add_external_file(file, original_filename)
external_file_path = generate_external_file_path
@dchandekstark
dchandekstark / Roles.md
Last active August 29, 2015 14:00
Role Metadata

Manager

@dchandekstark
dchandekstark / example.rb
Created April 19, 2014 01:57
ActiveFedora / ActiveRecord
class Foo < ActiveRecord::Base
belongs_to_af :bar
end
class Bar < ActiveFedora::Base
has_many_ar :foos
end
@dchandekstark
dchandekstark / README.md
Last active August 29, 2015 14:00
Hydra Roles for Users and Groups

Hydra Roles for Users and Groups

Why

Hydra's current authorization model accounts for user- and group-based permissions (what I am calling groups are sometimes in Hydra called "roles", such as in the RoleMapper class or hydra-role-management). Authorization data is stored in the repository (as rightsMetadata or policy-based defaultRights) and provides a simple set of permissions ("discover", "read", and "edit") which are applied atomically at the object level. Adding other kinds of permissions (such as the ability to add child objects to a parent) or ones that don't depend on repository data (such as the ability to create new objects) involves custom coding using the current authorization library (CanCan, or CanCanCan in hydra-head 7).

It would seem beneficial to the Hydra community and/or individual adopters to explore the possibility of a common approach to extending Hydra's native authorization API.

What

class HasContentValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value.has_content?
record.errors[attribute] << "The \"#{value.dsid}\" datastream does not have content"
end
end
end
def get_objects_for_solr_field_values(solr_field, values, opts = {})
extra_solr_params = opts.delete(:extra_solr_params) || {}
documents = get_solr_response_for_field_values(solr_field, values, extra_solr_params)[1]
method = opts.delete(:lazy) ? :lazy_reify_solr_results : :reify_solr_results
ActiveFedora::SolrService.send(method, documents, opts)
end