Last active
January 9, 2019 17:29
-
-
Save carolyncole/77760544865ed32c435b0be327b95ae4 to your computer and use it in GitHub Desktop.
replacing mimeType in fedora
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ids = ActiveFedora::SolrService.query('*:*',fq: 'has_model_ssim:"ActiveFedora::DirectContainer"', fl: 'id', rows: ActiveFedora::DirectContainer.count).map{|resp| resp["id"]} | |
ids.each do |id| | |
container = ActiveFedora::DirectContainer.find(id) rescue next | |
if container.has_member_relation.first.id == "http://pcdm.org/models#hasFile" | |
container.contained.map(&:id).each do |uri| | |
id = ActiveFedora::Base.uri_to_id(uri) | |
file = Hydra::PCDM::File.find(id) | |
has_mime_type = file.metadata.attributes["http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#hasMimeType"].first | |
puts has_mime_type | |
new_has_mime_type = has_mime_type.gsub('scholarsphere.psu.edu','scholarsphere-stage.libraries.psu.edu').gsub('"','\\\\\\\\\"') | |
curl_command = "curl -u #{ActiveFedora.config.credentials[:user]}:#{ActiveFedora.config.credentials[:password]} -i -XPATCH -H\"Content-type:application/sparql-update\" -d \"PREFIX ebucore: <http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#> DELETE {<> ebucore:hasMimeType \\\"#{has_mime_type}\\\"} INSERT {<> ebucore:hasMimeType \\\"#{new_has_mime_type}\\\"} WHERE {}\" #{uri}/fcr:metadata" | |
insert_curl_command = "curl -u #{ActiveFedora.config.credentials[:user]}:#{ActiveFedora.config.credentials[:password]} -i -XPATCH -H\"Content-type:application/sparql-update\" -d \"PREFIX ebucore: <http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#> DELETE {} INSERT {<> ebucore:hasMimeType \\\"#{new_has_mime_type}\\\" .} WHERE {}\" #{uri}/fcr:metadata" | |
response = `#{insert_curl_command}` | |
if response.include?("HTTP/1.1 204 No Content") | |
puts "converted #{uri} correctly" | |
else | |
logger.error "could not convert #{uri} #{response}" | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment