Skip to content

Commit

Permalink
Fix for subject source not migrating correctly with faceted subject t…
Browse files Browse the repository at this point in the history
…erms
  • Loading branch information
Nathan Stevens committed Mar 6, 2015
1 parent 047560d commit cce29cc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
22 changes: 21 additions & 1 deletion app/models/archon_digitalfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,27 @@ def self.unique_filename(basename, id)
else
"#{basename}.#{i}"
end
newname

# need to remove special characters from filename
sanitize_filename(newname)
end


# http://stackoverflow.com/questions/1939333/how-to-make-a-ruby-string-safe-for-a-filesystem
def self.sanitize_filename(filename)
# Split the name when finding a period which is preceded by some
# character, and is followed by some character other than a period,
# if there is no following period that is followed by something
# other than a period (yeah, confusing, I know)
fn = filename.split /(?<=.)\.(?=[^.])(?!.*\.[^.])/m

# We now have one or two parts (depending on whether we could find
# a suitable period). For each of these parts, replace any unwanted
# sequence of characters with an underscore
fn.map! { |s| s.gsub /[^a-z0-9\-]+/i, '_' }

# Finally, join the parts with a period and return the result
return fn.join '.'
end


Expand Down
11 changes: 9 additions & 2 deletions app/models/archon_subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def self.transform(rec)
obj.terms = terms
obj.external_ids = [{:external_id => rec["ID"], :source => "Archon"}]
obj.vocabulary = '/vocabularies/1'
obj.source = get_source(rec["SubjectSourceID"])
obj.source = get_source(get_source_id(rec))
end

obj.uri = obj.class.uri_for(rec.import_id)
Expand All @@ -24,6 +24,13 @@ def self.transform(rec)
yield obj
end

def self.get_source_id(rec)
if rec['SubjectSourceID'] && rec['ParentID'] == '0'
return rec['SubjectSourceID']
else
get_source_id(rec['Parent'])
end
end

def self.get_source(id)
rec = Archon.record_type(:subjectsource).find(id)
Expand Down Expand Up @@ -85,7 +92,7 @@ def self.transform_to_agent(rec)

def self.name_template(rec)
hsh = super
hsh.merge({:source => get_source(rec['SubjectSourceID'])})
hsh.merge({:source => get_source(get_source_id(rec))})
end

end
2 changes: 1 addition & 1 deletion app/views/index.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1>Archon Migration Service 1.0.2 (10-23-2014)</h1>
<h1>Archon Migration Service 1.0.3B1 (03-06-2015)</h1>
<div class="pure-g">
<div id="form-wrapper" class="pure-u-1-2">
<%= ERB.new(File.read(File.dirname(__FILE__)+'/jobs/new.erb')).result(binding) %>
Expand Down
2 changes: 1 addition & 1 deletion config/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def config(&block)
# Collection, divided by 100. So, e.g., if you have a Collection
# with 50,000 Content records, set this to 500 if your server
# has sufficient memory
Appdata.archon_page_cache_size 400
Appdata.archon_page_cache_size 600

Appdata.use_dbcache false

Expand Down

0 comments on commit cce29cc

Please sign in to comment.