Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade da progetto padre #1

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
release 3.1.1 rev 20210716
  • Loading branch information
agiove committed Jul 16, 2021
commit 28a5719fb53ed7322bccb89501f5c80eff0e03f1
13 changes: 11 additions & 2 deletions app/helpers/imports_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ def import_caption(import)
elsif (import.is_institution_importable_type?)
caption = import.importable.name
elsif (import.is_creator_importable_type? || import.is_custodian_importable_type?)
caption = import.importable.preferred_name.name
caption = import.importable.try(:preferred_name).try(:name).to_s
#if (caption.empty?)
# caption = import.importable.try(:display_name).to_s
#end
if (caption.empty?)
caption = import.importable.try(:name).to_s
end
if (caption.empty?)
caption = "(Denominazione non trovata)"
end
elsif (import.is_anagraphic_importable_type?)
caption = import.importable.name
if !import.importable.surname.nil? && !import.importable.surname.empty?
Expand All @@ -35,4 +44,4 @@ def import_caption(import)
end
return caption
end
end
end
11 changes: 8 additions & 3 deletions app/models/export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,9 @@ def stream_icar_import()
xml_formatted = ''
require "rexml/document"
doc = REXML::Document.new(xml.to_s)
formatter = REXML::Formatters::Pretty.new
formatter.compact = true
#formatter = REXML::Formatters::Pretty.new # Rimuove CR/LF
#formatter.compact = true # dai testi nelle Text Area
formatter = REXML::Formatters::Default.new
formatter.write(doc, xml_formatted)

File.open(file_dest, 'w+') { |f| f.write(xml_formatted) }
Expand All @@ -801,7 +802,7 @@ def stream_icar_import()
file_dest.close
File.delete(data_file_name) if File.exist?(data_file_name)
rescue Exception => e
puts "ECCEZIONE export.rb > stream_icar_import: #{e.message}"
Rails.logger.info "ECCEZIONE export.rb > stream_icar_import: #{e.message}"
end

#oggetti digitali
Expand All @@ -819,10 +820,14 @@ def stream_icar_import()
if !digital_objects.empty?
Zip::File.open(zip_file_name, false) do |zipfile|
digital_objects.each do |digital_object|
begin
dob_files = Dir.entries("#{Rails.root}/public/digital_objects/#{digital_object.access_token}").select {|f| !File.directory? f}
dob_files.each do |dob_file_name|
dob_file_path = "#{Rails.root}/public/digital_objects/#{digital_object.access_token}/#{dob_file_name}"
zipfile.add("#{digital_object.access_token}/#{dob_file_name}", dob_file_path)
end
rescue Exception => e
Rails.logger.info "ERRORE export.rb > stream_icar_import > oggetti digitali: #{e.message}"
end
end
end
Expand Down
66 changes: 24 additions & 42 deletions app/models/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,12 @@ class Import < ActiveRecord::Base
require File.join(File.dirname(__FILE__), ".", "fe_identification.rb")
# FINE - require richiesti per l'import batch

# Upgrade 2.1.0 inizio
extend Sc2Restore
# Upgrade 2.1.0 fine

attr_accessor :imported_file_version, :does_source_have_fonds
# Upgrade 2.2.0 inizio
attr_accessor :ref_fond_id, :ref_root_fond_id, :is_icar_import, :is_batch_import, :batch_import_filename
# Upgrade 2.2.0 fine

TMP_IMPORTS = "#{Rails.root}/tmp/imports"
# Upgrade 3.0.0 inizio
PUBLIC_IMPORTS = "#{Rails.root}/public/imports"
# Upgrade 3.0.0 fine
DIGITAL_FOLDER_PATH = "#{Rails.root}/public/digital_objects"

belongs_to :user
Expand Down Expand Up @@ -340,7 +333,7 @@ def import_unit_from_path document, user_id, group_id

if unit_component.xpath("../../accessrestrict/p").present?
terms = Term.where(vocabulary_id: Vocabulary.where(name: "units.access_condition").first.id).select(:term_key)
condition = unit_component.xpath("../../accessrestrict/p").text.squish
condition = unit_component.xpath("../../accessrestrict/p").text
if terms.include? condition.downcase
unit.access_condition = condition.downcase
else
Expand All @@ -349,7 +342,7 @@ def import_unit_from_path document, user_id, group_id
end
if unit_component.xpath("../../userestrict/p").present?
terms = Term.where(vocabulary_id: Vocabulary.where(name: "units.use_condition").first.id).select(:term_key)
condition = unit_component.xpath("../../userestrict/p").text.squish
condition = unit_component.xpath("../../userestrict/p").text
if terms.include? condition.downcase
unit.use_condition = condition.downcase
else
Expand All @@ -362,8 +355,8 @@ def import_unit_from_path document, user_id, group_id
if (unit.ancestry.present?)
unit.ancestry_depth = Unit.find(unit.ancestry).ancestry_depth + 1
end
unit.arrangement_note = unit_component.xpath("../processinfo[@localtype='noteDellArchivista']/p").text.squish
unit.content = unit_component.xpath("../../scopecontent/p").text.squish
unit.arrangement_note = unit_component.xpath("../processinfo[@localtype='noteDellArchivista']/p").text
unit.content = unit_component.xpath("../../scopecontent/p").text
unit.extent = unit_component.xpath("../physdescstructured/quantity").text
unit.physical_type = unit_component.xpath("../physdescstructured/unittype").text
unit.file_number = unit_component.xpath("../unitid[@localtype='numFascicolo']").text
Expand All @@ -372,11 +365,11 @@ def import_unit_from_path document, user_id, group_id
unit.physical_container_number = unit_component.xpath("../container/@containerid").text
unit.physical_container_title = unit_component.xpath("../container").text
unit.physical_container_type = unit_component.xpath("../container/@localtype").text
unit.physical_description = unit_component.xpath("../physdescstructured/descriptivenote").text.squish
unit.preservation_note = unit_component.xpath("../physdescstructured/phystech").text.squish
unit.physical_description = unit_component.xpath("../physdescstructured/descriptivenote").text
unit.preservation_note = unit_component.xpath("../physdescstructured/phystech").text
unit.reference_number = unit_component.xpath("../unitid[@localtype='segnaturaAttuale']").text
unit.title = unit_component.xpath("../unittitle[@localtype='denominazione']").text.squish
unit.given_title = unit_component.xpath("../unittitle[@localtype='titoloAttribuito']").text.squish
unit.title = unit_component.xpath("../unittitle[@localtype='denominazione']").text
unit.given_title = unit_component.xpath("../unittitle[@localtype='titoloAttribuito']").text
unit.tmp_reference_number = unit_component.xpath("../unitid[@localtype='segnaturaProvvisoriaNumero']").text
unit.tmp_reference_string = unit_component.xpath("../unitid[@localtype='segnaturaProvvisoriaTesto']").text

Expand Down Expand Up @@ -454,14 +447,14 @@ def import_unit_from_path document, user_id, group_id
if unit_component.xpath("../../odd[@localtype='ElementiTestuali']/p").present?
sc2_textual_element = Sc2TextualElement.new
sc2_textual_element.unit_id = unit.id
sc2_textual_element.isri = unit_component.xpath("../../odd[@localtype='ElementiTestuali']/p").text.squish
sc2_textual_element.isri = unit_component.xpath("../../odd[@localtype='ElementiTestuali']/p").text
sc2_textual_element.save!
end

if unit_component.xpath("../../odd[@localtype='ElementiFigurati']/p").present?
sc2_visual_elements = Sc2VisualElement.new
sc2_visual_elements.unit_id = unit.id
sc2_visual_elements.stmd = unit_component.xpath("../../odd[@localtype='ElementiFigurati']/p").text.squish
sc2_visual_elements.stmd = unit_component.xpath("../../odd[@localtype='ElementiFigurati']/p").text
sc2_visual_elements.save!
end

Expand Down Expand Up @@ -823,7 +816,7 @@ def import_fond_from_path path, user_id, group_id

if path.xpath("accessrestrict/p").present?
terms = Term.where(vocabulary_id: Vocabulary.where(name: "fonds.access_condition").first.id).select(:term_key)
condition = path.xpath("accessrestrict/p").first.text.squish
condition = path.xpath("accessrestrict/p").first.text
if terms.include? condition.downcase
fond.access_condition = condition.downcase
else
Expand All @@ -836,9 +829,9 @@ def import_fond_from_path path, user_id, group_id
fond.published = true
end

fond.history = path.xpath("custodhist/p").text.squish
fond.history = path.xpath("custodhist/p").text

fond.extent = path.xpath("did/physdesc").text.squish
fond.extent = path.xpath("did/physdesc").text

path.xpath("did/physdescstructured").each do |pd|
quantity = pd.xpath("quantity").text.squish
Expand Down Expand Up @@ -878,11 +871,11 @@ def import_fond_from_path path, user_id, group_id
Rails.logger.info "Fondo: #{fond.name.squish} - Trovato ma non importato il tag 'ead/bibliography': #{path.xpath("bibliography").text.squish}"
end

fond.description = path.xpath("scopecontent/p").text.squish
fond.description = path.xpath("scopecontent/p").text

fond.arrangement_note = ""
if path.xpath("arrangement/p").present?
fond.arrangement_note += "Criteri di ordinamento: " + path.xpath("arrangement/p").text.squish + "\n"
fond.arrangement_note += "Criteri di ordinamento: " + path.xpath("arrangement/p").text + "\n"
end

fond.sneaky_save!
Expand Down Expand Up @@ -927,8 +920,8 @@ def import_fond_from_path path, user_id, group_id
path.xpath("controlaccess/genreform").each do |fond_document|
rel__f_d = RelFondDocumentForm.new
rel__f_d.name = fond_document.xpath("part[@localtype='denominazione']").text.squish
rel__f_d.description = fond_document.xpath("part[@localtype='descrizione']").text.squish
rel__f_d.note = fond_document.xpath("part[@localtype='note']").text.squish
rel__f_d.description = fond_document.xpath("part[@localtype='descrizione']").text
rel__f_d.note = fond_document.xpath("part[@localtype='note']").text
if DocumentForm.where("document_forms.name = ?", rel__f_d.name).first.present?
rel__f_d.document_form_id = DocumentForm.where("document_forms.name = ?", rel__f_d.name).first[:id]
rel__f_d.fond_id = fond.id
Expand Down Expand Up @@ -992,7 +985,7 @@ def import_fond_from_path path, user_id, group_id
if !fond.related_materials.present?
fond.related_materials = ""
end
fond.related_materials += path.xpath("relatedmaterials/archref/ref").text.squish
fond.related_materials += path.xpath("relatedmaterials/archref/ref").text
end

source = path.xpath("did/unitid")
Expand Down Expand Up @@ -3525,8 +3518,6 @@ def import_xml_file(user, ability)
# def import_aef_file(user)
def import_aef_file(user, ability)

# Upgrade 2.2.0 fine

#File.open(data_file) do |file|
# begin
# ActiveRecord::Base.transaction do
Expand Down Expand Up @@ -3556,35 +3547,32 @@ def import_aef_file(user, ability)

begin
lines = File.readlines(data_file)
# Upgrade 2.2.0 inizio
unit_aef_import_units_count = 0
# Upgrade 2.2.0 fine
ActiveRecord::Base.transaction do
# Upgrade 2.0.0 inizio
model = nil
prev_model = nil
object = nil
# Upgrade 2.0.0 fine
lines.each do |line|
if line.include? "custodian_name"
line = line.gsub('"qualifier":"AU"', '"qualifier":"OT"')
line = line.gsub('"qualifier":"[\"OT\", \"AU\"]"', '"qualifier":"OT"')
line = line.gsub('"qualifier":"[\'OT\', \'AU\']"', '"qualifier":"OT"')
end

next if line.blank?
data = ActiveSupport::JSON.decode(line.strip)
key = data.keys.first
# Upgrade 2.1.0 inizio
ipdata = data[key]
if imported_file_version < "2.1.0"
key = prv_adjust_ante_210_project(key, ipdata)
key = prv_adjust_ante_210_project_credits(key, ipdata)
end
# Upgrade 2.1.0 fine
model = key.camelize.constantize
# Upgrade 2.1.0 inizio
#data[key].delete_if{|k, v| not model.column_names.include? k}
#object = model.new(data[key])
ipdata.delete_if { |k, v| not model.column_names.include? k }
object = model.new(ipdata)
# Upgrade 2.1.0 fine
object.db_source = self.identifier
# Upgrade 2.2.0 inizio
#object.group_id = user.group_id if object.has_attribute? 'group_id'
if object.has_attribute? 'group_id'
object.group_id = if user.is_multi_group_user?() then
Expand All @@ -3601,11 +3589,9 @@ def import_aef_file(user, ability)
unit_aef_import_units_count += 1
end
end
# Upgrade 2.2.0 fine
object.created_by = user.id if object.has_attribute? 'created_by'
object.updated_by = user.id if object.has_attribute? 'updated_by'

# Upgrade 2.0.0 inizio
#object.send(:create_without_callbacks)
object.sneaky_save!
if model != prev_model && !prev_model.nil?
Expand All @@ -3617,12 +3603,8 @@ def import_aef_file(user, ability)
if !object.nil?
set_lacking_field_values(object)
end
# Upgrade 2.0.0 fine
end
# Upgrade 2.2.0 inizio
#update_statements
update_statements(unit_aef_import_units_count)
# Upgrade 2.2.0 fine
return true
rescue Exception => e
Rails.logger.info "import_aef_file Errore=" + e.message.to_s
Expand Down
4 changes: 2 additions & 2 deletions app/views/site/about.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<strong>Informazioni</strong>
<ul>
<li>
<%= link_to_unless(APP_EDITION == "standalone", "www.archimista.it", "http://www.archimista.it", { target: "_blank" }) %>
<%= link_to_unless(APP_EDITION == "standalone", "www.icar.beniculturali.it/attivita-e-progetti/progetti-icar-1/software-open-source-archimista-versione-311", "https://www.icar.beniculturali.it/attivita-e-progetti/progetti-icar-1/software-open-source-archimista-versione-311", { target: "_blank" }) %>
</li>
<li>
<%= link_to_unless(APP_EDITION == "standalone", "archimista@polimi.it", "mailto:archimista@polimi.it") %>
Expand All @@ -68,7 +68,7 @@
<br/>
Sino alla versione 1.2.1: <%= link_to_unless(APP_EDITION == "standalone", raw("Codex Societ&agrave; Cooperativa"), "http://www.codexcoop.it/", { target: "_blank" }) %>, Pavia
<br/>
Per la storia del progetto Archimista consultare il sito ufficiale <%= link_to_unless(APP_EDITION == "standalone", "www.archimista.it", "http://www.archimista.it", { target: "_blank" }) %>
Per la storia del progetto Archimista consultare il sito ufficiale <%= link_to_unless(APP_EDITION == "standalone", "www.icar.beniculturali.it/attivita-e-progetti/progetti-icar-1/software-open-source-archimista-versione-311", "https://www.icar.beniculturali.it/attivita-e-progetti/progetti-icar-1/software-open-source-archimista-versione-311", { target: "_blank" }) %>
<br/>
</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/site/dashboard.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<p>
Applicazione web multipiattaforma gratuita ed open source per la descrizione di archivi storici e la realizzazione di inventari, censimenti e guide.
<br />
Sito ufficiale:&nbsp;<%= link_to_unless(APP_EDITION == "standalone", "www.archimista.it", "http://www.archimista.it", { target: "_blank" } ) %>
Sito ufficiale:&nbsp;<%= link_to_unless(APP_EDITION == "standalone", "www.icar.beniculturali.it/attivita-e-progetti/progetti-icar-1/software-open-source-archimista-versione-311", "https://www.icar.beniculturali.it/attivita-e-progetti/progetti-icar-1/software-open-source-archimista-versione-311", { target: "_blank" } ) %>
<br />
Contatti:&nbsp;<%= link_to_unless(APP_EDITION == "standalone", "archimista@polimi.it", "mailto:archimista@polimi.it" ) %>
<br />
Expand Down
5 changes: 3 additions & 2 deletions lib/tasks/archimista_ead.rake
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ namespace :ead do
xml_formatted = ''
require "rexml/document"
doc = REXML::Document.new(xml.to_s)
formatter = REXML::Formatters::Pretty.new
formatter.compact = true
#formatter = REXML::Formatters::Pretty.new # Rimuove CR/LF
#formatter.compact = true # dai testi nelle Text Area
formatter = REXML::Formatters::Default.new
formatter.write(doc, xml_formatted)

File.open(file_dest, 'w+') { |f| f.write(xml_formatted) }
Expand Down