diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dfa7ad8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/config/database.yml +/config/secrets.yml +/Gemfile.lock diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e08b9c..3fb77d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,23 @@ -## Archimista 3.0 e 3.1 versione server e stand alone – gennaio 2019 +## Archimista 3.1.1 +* Il ruolo admin può ora gestire le schede anagrafiche all'interno del suo gruppo. +* Ripristinata l'anteprima delle text area nelle unità archivistiche. +* Modificati i loghi sulla home page. +* Correzione codifica caratteri accentati su alcune pagine. +* Modificata pagina di Informazioni e Copyright. +* Aumentata la dimensione di diversi campi testuali a 16777215 caratteri. +* Corretto il caricamento dei CSV in maniera tale da poter inserire nei campi testuali le virgole. +* Modificato il modo in cui sono conteggiate le unità archivistiche. +* Aggiunto filtro per complesso archivistico sulla pagina degli oggetti digitali. +* Corretta la tipologia fascicolo nella versione standalone. +* Corretta la segnatura provvisoria - numero delle unità: accetta solo caratteri numerici. +* Rese utilizzabili tutte le lingue nel relativo vocabolario. +* Modificato l'export XML (SCONS2, EAC-CPF, EAD3) in maniera tale da essere conforme al relativo tracciato. +* Tracciato EAC-CPF: modificato import dei soggetti produttori. +* Tracciato EAC-CPF: implementato import dei profili istituzionali. +* Tracciato EAC-CPF: implementato import delle schede anagrafiche. +* Tracciato SCONS2: modificato import dei soggetti conservatori. + +## Archimista 3.0 e 3.1 – gennaio 2019 * Sviluppo del fascicolo edilizio secondo il modello presentato e dopo analisi con l’ICAR; * Integrazione con la procedura di esportazione/importazione aef; * Integrazione con la procedura di esportazione/importazione EAD3/EAC; diff --git a/FAQ.md b/FAQ.md index a1d25c8..4e1292f 100644 --- a/FAQ.md +++ b/FAQ.md @@ -1,4 +1,4 @@ -## Archimista FAQ 3.1.0 +## Archimista FAQ 3.1.1 **È possibile estrarre un complesso o un’unità includendo tutta la gerarchia (ascendenza e discendenza)?** Sì. Il tracciato relativo ad un complesso ora contiene: tutta l’ascendenza (se presente) a partire dal complesso radice secondo una struttura breve contenente solo *unitid* e *unittitle*; il complesso oggetto di esportazione; tutta la discendenza (se presente); le unità archivistiche associate al complesso oggetto di esportazione ed ai complessi figli. Il tracciato relativo ad una unità ora contiene: tutta l’ascendenza sia in termini di complessi che di unità a partire dal complesso radice secondo una struttura breve contenente solo *unitid* e *unittitle*; l’unità oggetto di esportazione; tutta la discendenza (se presente). @@ -15,6 +15,9 @@ Il tracciato ICAR-IMPORT è costruito a partire da un complesso archivistico (ra * le schede anagrafiche collegate alle unità incluse secondo il tracciato EAC-CPF; * le fonti archivistiche collegate al complesso oggetto di esportazione o ai complessi figli secondo il tracciato EAD3. +**Tentando di estrarre mediante unzip un archivio generato dall'export in formato ICAR-IMPORT si ottiene un errore del tipo "error: invalid zip file with overlapped components (possible zip bomb)"; come risolvere?** +Per archivi di dimensioni superiori a 4GB potrebbe verificarsi un errore in fase di estrazione mediante unzip. Per ovviare al problema è possibile utilizzare in alernativa il software "7zip" o il comando "jar xf ". + **È possibile creare una scheda sottofascicolo?** Sì. È possibile crearla, dalla schermata in cui compare la lista delle unità relative ad un determinato complesso archivistico, è sufficiente cliccare sul bottone “crea sottofascicolo”. E’ anche possibile reiterare l’operazione su più livelli. @@ -59,3 +62,4 @@ Per dettagli consulta la pagina [Note di rilascio](http://www.archimista.it/?pag * produzione di report per Complesso archivistico, Progetto o Soggetto conservatore * upload multiplo di oggetti digitali * creazione sotto-unità e sotto-sotto-unità e possibilità di modificarne il livello + diff --git a/README.md b/README.md index 37f69fc..d18935b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## Archimista Archimista è un'applicazione web open source per la descrizione di archivi storici. È disponibile in due versioni: standalone e server. -La versione corrente è la **3.1.0**. +La versione corrente è la **3.1.1**. ## Requisiti Archimista funziona sui sistemi operativi GNU/Linux, Mac OS X, Windows Vista e superiori. Per Windows XP è necessario utilizzare una versione apposita che viene compilata allo scopo. @@ -47,3 +47,4 @@ Lo sviluppo attuale è curato da INGLOBA360 s.r.l. ([http://www.ingloba360.it](h ## Licenza Archimista è rilasciato sotto licenza GNU General Public License v2.0 o successive. + diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index eea8843..4ad33be 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -67,7 +67,7 @@ def sc2_terms def langs # Upgrade 2.0.0 inizio # @langs = Lang.find(:all, :conditions => {:active => true}) - @langs = Lang.where(active: true) + @langs = Lang.where(active: true).order("active DESC, it_name ASC") # Upgrade 2.0.0 fine end @@ -147,3 +147,4 @@ def after_sign_out_path_for(resource_or_scope) end + diff --git a/app/controllers/digital_objects_controller.rb b/app/controllers/digital_objects_controller.rb index f9e470d..429e1f1 100644 --- a/app/controllers/digital_objects_controller.rb +++ b/app/controllers/digital_objects_controller.rb @@ -47,6 +47,12 @@ def current_ability # Upgrade 2.2.0 fine def all + #if params[:type].present? + # @selected_attachable = {:type => params[:type]} + #else + # @selected_attachable = {:type => "Fond"} + #end + # Upgrade 2.0.0 inizio =begin @digital_objects = DigitalObject.accessible_by(current_ability, :read). @@ -62,14 +68,89 @@ def all to_a. delete_if {|o| o.attachable.nil? || (o.attachable.has_attribute?("sequence_number") && o.attachable.sequence_number.nil?) } =end - @digital_objects = DigitalObject.accessible_by(current_ability, :read). - joins(:group). - includes(:attachable). - order(sort_column + ' ' + sort_direction).page(params[:page]). - to_a. - delete_if {|o| o.attachable.nil? || (o.attachable.has_attribute?("sequence_number") && o.attachable.sequence_number.nil?) } -# Upgrade 2.2.0 fine -# Upgrade 2.0.0 fine +=begin + #Ricerca degli oggetti digitali appartenenti a fondi che hanno come ROOT un fondo con il nome ricercato (like) + + @digital_objects = DigitalObject.accessible_by(current_ability, :read). + joins(:group). + includes(:attachable). + where(attachable: Fond.roots.where("fonds.name LIKE ?", "%" + params[:q] + "%"). + joins("INNER JOIN fonds f_child ON f_child.ancestry LIKE CONCAT(fonds.id, '/%') OR f_child.ancestry_depth = 0")). + order(sort_column + ' ' + sort_direction). + page(params[:page]). + to_a. + delete_if { + |o| o.attachable.nil? || + (o.attachable.has_attribute?("sequence_number") && o.attachable.sequence_number.nil?)} +=end + if params[:q].present? or params[:unit].present? + if params[:unit] != "" && params[:q] != "" + @digital_objects = DigitalObject.accessible_by(current_ability, :read). + joins(:group). + includes(:attachable). + where(attachable: Unit.joins("INNER JOIN fonds ON units.root_fond_id = fonds.id"). + where("fonds.name LIKE ? AND units.title LIKE ?", + "%" + params[:q] + "%", + "%" + params[:unit] + "%")). + order(sort_column + ' ' + sort_direction).page(params[:page]). + to_a. + delete_if { + |o| o.attachable.nil? || + (o.attachable.has_attribute?("sequence_number") && o.attachable.sequence_number.nil?) + } + elsif params[:unit] != "" + @digital_objects = DigitalObject.accessible_by(current_ability, :read). + joins(:group). + includes(:attachable). + where(attachable: Unit.joins("INNER JOIN fonds ON units.root_fond_id = fonds.id"). + where("units.title LIKE ?", + "%" + params[:unit] + "%")). + order(sort_column + ' ' + sort_direction).page(params[:page]). + to_a. + delete_if { + |o| o.attachable.nil? || + (o.attachable.has_attribute?("sequence_number") && o.attachable.sequence_number.nil?) + } + + elsif params[:q] != "" + @digital_objects = DigitalObject.accessible_by(current_ability, :read). + joins(:group). + includes(:attachable). + where(attachable: Unit.joins("INNER JOIN fonds ON units.root_fond_id = fonds.id"). + where("fonds.name LIKE ?", "%" + params[:q] + "%")). + order(sort_column + ' ' + sort_direction).page(params[:page]). + to_a. + delete_if { + |o| o.attachable.nil? || + (o.attachable.has_attribute?("sequence_number") && o.attachable.sequence_number.nil?) + } + end + + @fond_ids_AEF = Array.new + @fond_ids_EAD = Array.new + @unit_ids = Array.new + + @digital_objects.each do |dig_obj| + if dig_obj.attachable_type == "Unit" + @fond_ids_AEF.push Unit.find(dig_obj.attachable_id).root_fond_id + @unit_ids.push dig_obj.attachable_id + end + if dig_obj.attachable_type == "Fond" + @fond_ids_AEF.push dig_obj.attachable_id + @fond_ids_EAD.push dig_obj.attachable_id + end + end + else + @digital_objects = DigitalObject.accessible_by(current_ability, :read). + joins(:group). + includes(:attachable). + order(sort_column + ' ' + sort_direction).page(params[:page]). + to_a. + delete_if {|o| o.attachable.nil? || (o.attachable.has_attribute?("sequence_number") && o.attachable.sequence_number.nil?) } + end + + #Upgrade 2.2.0 fine + #Upgrade 2.0.0 fine # FIXME: retrieving del path di fonds/units è query intensive. Ma per ora teniamocelo... end diff --git a/app/controllers/exports_batch_controller.rb b/app/controllers/exports_batch_controller.rb new file mode 100644 index 0000000..07839a9 --- /dev/null +++ b/app/controllers/exports_batch_controller.rb @@ -0,0 +1,312 @@ +class ExportsBatchController < ApplicationController + + OK_EXPORT_MESSAGE = "Esportazione batch avviata." + KO_EXPORT_MESSAGE = "Errore nell'avvio dell'esportazione batch." + + def index + @export_folder = "#{Rails.root}/public/exports" + + @fonds = Fond.list. + roots. + accessible_by(current_ability, :read). + active. + default_order + + @custodians = Custodian.export_list.accessible_by(current_ability, :read) + @projects = Project.export_list.accessible_by(current_ability, :read) + @creators = Creator.export_list.accessible_by(current_ability, :read) + @sources = Source.export_list.accessible_by(current_ability, :read) + + @project_select_options = [] + @projects.each do |project| + @project_select_options.append([project.name, project.id]) + end + + @fonds_select_options = [] + @fonds.each do |fond| + @fonds_select_options.append([fond.name, fond.id]) + end + + @custodians_select_options = [] + @custodians.each do |custodian| + @custodians_select_options.append([custodian.name, custodian.id]) + end + + @sources_select_options = [] + @sources.each do |source| + @sources_select_options.append([source.short_title, source.id]) + end + end + + def icarimport + begin + fond_id = params[:fond_id] + if fond_id.nil? + add_message = " Selezionare un Complesso." + redirect_to({ :action=>'index' }, :alert => KO_EXPORT_MESSAGE + add_message) + return + end + + rake_req = 'rake ead:build_xml[icar-import,"' + fond_id + '"]' + + Rails.logger.info "Esecuzione rake task: " + rake_req + system rake_req + redirect_to({ :action=>'index' }, :notice => OK_EXPORT_MESSAGE) + rescue Exception => e + Rails.logger.warn "ECCEZIONE in exports_batch_controller: #{e.message}" + redirect_to({ :action=>'index' }, :alert => KO_EXPORT_MESSAGE) + end + end + + def aefallfonds + begin + project_id = params[:project_id] + if project_id.nil? + add_message = " Selezionare un Progetto." + redirect_to({ :action=>'index' }, :alert => KO_EXPORT_MESSAGE + add_message) + return + end + + rake_req = 'rake aef:build_data[fonds,"SELECT DISTINCT f.* from fonds f\, rel_project_fonds r\, projects p where p.id=r.project_id and f.id=r.fond_id and f.published is true and p.id=' + project_id + ' and trashed is false and f.ancestry_depth=0 and p.published is true"]' + + Rails.logger.info "Esecuzione rake task: " + rake_req + system rake_req + redirect_to({ :action=>'index' }, :notice => OK_EXPORT_MESSAGE) + rescue Exception => e + Rails.logger.warn "ECCEZIONE in exports_batch_controller: #{e.message}" + redirect_to({ :action=>'index' }, :alert => KO_EXPORT_MESSAGE) + end + end + + def aeffondsnoancestry + begin + fond_ids = params[:fond_id] + if fond_ids.nil? + add_message = " Selezionare almeno un Fondo." + redirect_to({ :action=>'index' }, :alert => KO_EXPORT_MESSAGE + add_message) + return + end + + fond_ids_list = fond_ids.to_s.gsub("[", "(").gsub("]", ")").gsub("\"", "").gsub(" ", "").gsub(",", "\\,") + + rake_req = 'rake aef:build_data[fonds,"SELECT DISTINCT * from fonds where id IN ' + fond_ids_list + ' and ancestry_depth=0"]' + + Rails.logger.info "Esecuzione rake task: " + rake_req + system rake_req + redirect_to({ :action=>'index' }, :notice => OK_EXPORT_MESSAGE) + rescue Exception => e + Rails.logger.warn "ECCEZIONE in exports_batch_controller: #{e.message}" + redirect_to({ :action=>'index' }, :alert => KO_EXPORT_MESSAGE) + end + end + + def aefallfondsnoancestry + begin + rake_req = 'rake aef:build_data[fonds,"SELECT DISTINCT * from fonds where ancestry_depth=0"]' + Rails.logger.info "Esecuzione rake task: " + rake_req + system rake_req + redirect_to({ :action=>'index' }, :notice => OK_EXPORT_MESSAGE) + rescue Exception => e + Rails.logger.warn "ECCEZIONE in exports_batch_controller: #{e.message}" + redirect_to({ :action=>'index' }, :alert => KO_EXPORT_MESSAGE) + end + end + + def aefprojects + begin + project_ids = params[:project_id] + if project_ids.nil? + add_message = " Selezionare almeno un Progetto." + redirect_to({ :action=>'index' }, :alert => KO_EXPORT_MESSAGE + add_message) + return + end + + project_ids_list = project_ids.to_s.gsub("[", "(").gsub("]", ")").gsub("\"", "").gsub(" ", "").gsub(",", "\\,") + + rake_req = 'rake aef:build_data[projects,"SELECT DISTINCT * from projects where id IN ' + project_ids_list + ' and published is true"]' + + Rails.logger.info "Esecuzione rake task: " + rake_req + system rake_req + redirect_to({ :action=>'index' }, :notice => OK_EXPORT_MESSAGE) + rescue Exception => e + Rails.logger.warn "ECCEZIONE in exports_batch_controller: #{e.message}" + redirect_to({ :action=>'index' }, :alert => KO_EXPORT_MESSAGE) + end + end + + def aefallprojects + begin + rake_req = 'rake aef:build_data[projects,"SELECT DISTINCT * from projects where published is true"]' + Rails.logger.info "Esecuzione rake task: " + rake_req + system rake_req + redirect_to({ :action=>'index' }, :notice => OK_EXPORT_MESSAGE) + rescue Exception => e + Rails.logger.warn "ECCEZIONE in exports_batch_controller: #{e.message}" + redirect_to({ :action=>'index' }, :alert => KO_EXPORT_MESSAGE) + end + end + + def aefcustodiansproject + begin + project_id = params[:project_id] + if project_id.nil? + add_message = " Selezionare un Progetto." + redirect_to({ :action=>'index' }, :alert => KO_EXPORT_MESSAGE + add_message) + return + end + + rake_req = 'rake aef:build_data[custodians,"SELECT * from custodians where id IN (SELECT DISTINCT custodian_id FROM rel_custodian_fonds WHERE fond_id IN (SELECT DISTINCT f.id from rel_project_fonds r\, fonds f\, projects p where p.id=r.project_id and f.id=r.fond_id and f.published is true and p.id=' + project_id + ' and trashed is false and f.ancestry_depth=0 and p.published is true))"]' + + Rails.logger.info "Esecuzione rake task: " + rake_req + system rake_req + redirect_to({ :action=>'index' }, :notice => OK_EXPORT_MESSAGE) + rescue Exception => e + Rails.logger.warn "ECCEZIONE in exports_batch_controller: #{e.message}" + redirect_to({ :action=>'index' }, :alert => KO_EXPORT_MESSAGE) + end + end + + def aefcustodians + begin + custodian_ids = params[:custodian_id] + if custodian_ids.nil? + add_message = " Selezionare almeno un Conservatore." + redirect_to({ :action=>'index' }, :alert => KO_EXPORT_MESSAGE + add_message) + return + end + + custodian_ids_list = custodian_ids.to_s.gsub("[", "(").gsub("]", ")").gsub("\"", "").gsub(" ", "").gsub(",", "\\,") + + rake_req = 'rake aef:build_data[custodians,"SELECT DISTINCT * from custodians where id IN ' + custodian_ids_list + '"]' + + Rails.logger.info "Esecuzione rake task: " + rake_req + system rake_req + redirect_to({ :action=>'index' }, :notice => OK_EXPORT_MESSAGE) + rescue Exception => e + Rails.logger.warn "ECCEZIONE in exports_batch_controller: #{e.message}" + redirect_to({ :action=>'index' }, :alert => KO_EXPORT_MESSAGE) + end + end + + def aefallcustodians + begin + rake_req = 'rake aef:build_data[custodians,"SELECT DISTINCT * from custodians"]' + Rails.logger.info "Esecuzione rake task: " + rake_req + system rake_req + redirect_to({ :action=>'index' }, :notice => OK_EXPORT_MESSAGE) + rescue Exception => e + Rails.logger.warn "ECCEZIONE in exports_batch_controller: #{e.message}" + redirect_to({ :action=>'index' }, :alert => KO_EXPORT_MESSAGE) + end + end + + def xmlallfonds + begin + project_id = params[:project_id] + if project_id.nil? + add_message = " Selezionare un Progetto." + redirect_to({ :action=>'index' }, :alert => KO_EXPORT_MESSAGE + add_message) + return + end + + rake_req = 'rake ead:build_xml[fonds,"SELECT DISTINCT f.* from rel_project_fonds r\, fonds f\, projects p where p.id=r.project_id and f.id=r.fond_id and f.published is true and p.id=' + project_id + ' and trashed is false and f.ancestry_depth=0"]' + + Rails.logger.info "Esecuzione rake task: " + rake_req + system rake_req + redirect_to({ :action=>'index' }, :notice => OK_EXPORT_MESSAGE) + rescue Exception => e + Rails.logger.warn "ECCEZIONE in exports_batch_controller: #{e.message}" + redirect_to({ :action=>'index' }, :alert => KO_EXPORT_MESSAGE) + end + end + + def xmlfondsnoancestry + begin + fond_ids = params[:fond_id] + if fond_ids.nil? + add_message = " Selezionare almeno un Fondo." + redirect_to({ :action=>'index' }, :alert => KO_EXPORT_MESSAGE + add_message) + return + end + + fond_ids_list = fond_ids.to_s.gsub("[", "(").gsub("]", ")").gsub("\"", "").gsub(" ", "").gsub(",", "\\,") + + rake_req = 'rake ead:build_xml[fonds,"SELECT DISTINCT * from fonds where id IN ' + fond_ids_list + ' and ancestry_depth=0"]' + + Rails.logger.info "Esecuzione rake task: " + rake_req + system rake_req + redirect_to({ :action=>'index' }, :notice => OK_EXPORT_MESSAGE) + rescue Exception => e + Rails.logger.warn "ECCEZIONE in exports_batch_controller: #{e.message}" + redirect_to({ :action=>'index' }, :alert => KO_EXPORT_MESSAGE) + end + end + + def xmlallfondsnoancestry + begin + rake_req = 'rake ead:build_xml[fonds,"SELECT DISTINCT * from fonds where ancestry_depth=0"]' + Rails.logger.info "Esecuzione rake task: " + rake_req + system rake_req + redirect_to({ :action=>'index' }, :notice => OK_EXPORT_MESSAGE) + rescue Exception => e + Rails.logger.warn "ECCEZIONE in exports_batch_controller: #{e.message}" + redirect_to({ :action=>'index' }, :alert => KO_EXPORT_MESSAGE) + end + end + + def xmlsourcesproject + begin + project_id = params[:project_id] + if project_id.nil? + add_message = " Selezionare un Progetto." + redirect_to({ :action=>'index' }, :alert => KO_EXPORT_MESSAGE + add_message) + return + end + + rake_req = 'rake ead:build_xml[sources,"SELECT * from sources where id IN (SELECT DISTINCT source_id FROM rel_fond_sources WHERE fond_id IN (SELECT DISTINCT f.id from rel_project_fonds r\, fonds f\, projects p where p.id=r.project_id and f.id=r.fond_id and f.published is true and p.id=' + project_id + ' and trashed is false and f.ancestry_depth=0))"]' + # cambiato: rel_source_fonds -> rel_fond_sources + + Rails.logger.info "Esecuzione rake task: " + rake_req + system rake_req + redirect_to({ :action=>'index' }, :notice => OK_EXPORT_MESSAGE) + rescue Exception => e + Rails.logger.warn "ECCEZIONE in exports_batch_controller: #{e.message}" + redirect_to({ :action=>'index' }, :alert => KO_EXPORT_MESSAGE) + end + end + + def xmlsources + begin + source_ids = params[:source_id] + if source_ids.nil? + add_message = " Selezionare almeno una Fonte o Strumento." + redirect_to({ :action=>'index' }, :alert => KO_EXPORT_MESSAGE + add_message) + return + end + + source_ids_list = source_ids.to_s.gsub("[", "(").gsub("]", ")").gsub("\"", "").gsub(" ", "").gsub(",", "\\,") + + rake_req = 'rake ead:build_xml[sources,"SELECT DISTINCT * from sources where id IN ' + source_ids_list + '"]' + + Rails.logger.info "Esecuzione rake task: " + rake_req + system rake_req + redirect_to({ :action=>'index' }, :notice => OK_EXPORT_MESSAGE) + rescue Exception => e + Rails.logger.warn "ECCEZIONE in exports_batch_controller: #{e.message}" + redirect_to({ :action=>'index' }, :alert => KO_EXPORT_MESSAGE) + end + end + + def xmlallsources + begin + rake_req = 'rake ead:build_xml[sources,"SELECT DISTINCT * from sources"]' + Rails.logger.info "Esecuzione rake task: " + rake_req + system rake_req + redirect_to({ :action=>'index' }, :notice => OK_EXPORT_MESSAGE) + rescue Exception => e + Rails.logger.warn "ECCEZIONE in exports_batch_controller: #{e.message}" + redirect_to({ :action=>'index' }, :alert => KO_EXPORT_MESSAGE) + end + end + +end diff --git a/app/controllers/exports_controller.rb b/app/controllers/exports_controller.rb index 6ae0098..95834c1 100644 --- a/app/controllers/exports_controller.rb +++ b/app/controllers/exports_controller.rb @@ -4,6 +4,9 @@ class ExportsController < ApplicationController require 'builder' # Upgrade 2.0.0 fine + @@is_icar_file = false + @@icar_download_file = "" + def index @fonds = Fond.list. roots. @@ -77,9 +80,12 @@ def xml @export.group_id = entity.group_id target_xml = params[:target_xml] if target_xml.include? "san" + @@is_icar_file = false @export.create_export_xml_san_file else - @export.create_export_xml_ead_file + @@is_icar_file = true + @export.stream_icar_import + @@icar_download_file = @export.get_icarimportfile end @@ -97,7 +103,11 @@ def xml def download #File.delete("#{Export::TMP_EXPORTS}/#{params[:data]}") #File.delete("#{Export::TMP_EXPORTS}/#{params[:meta]}") - file = "#{Rails.root}/public/downloads/#{params[:file]}" + if @@is_icar_file + file = @@icar_download_file + else + file = "#{Rails.root}/public/downloads/#{params[:file]}" + end send_file(file) end @@ -160,5 +170,46 @@ def get_target_class_caption(target_class) end # Upgrade 2.2.0 fine + def units_ead + if params[:units].present? + ids = String.new + params[:units].each do |unit| + ids += unit.to_s + "\\," + end + ids = ids[0...-2] + rake_req = "rake ead:build_xml[units,\"SELECT DISTINCT * from units where id IN (" + ids + ")\"]" + puts rake_req + system rake_req + end +=begin +# Al momento solo le unita' vengono ricercate e quindi esportate in EAD + if(params[:fonds].present?) + ids = String.new + params[:units].each do |fond| + ids += fond.to_s + "\\," + end + ids = ids[0...-2] + rake_req = "rake ead:build_xml[fonds,\"SELECT DISTINCT * from fonds where id IN (" + ids + ")\"]" + puts rake_req + system rake_req + end +=end + head :ok + end + + def fonds_aef + if params[:fonds].present? + ids = String.new + params[:fonds].each do |fond| + ids += fond.to_s + "\\," + end + ids = ids[0...-2] + rake_req = "rake aef:build_data[fonds,\"SELECT DISTINCT * from fonds where id IN (" + ids + ")\"]" + puts rake_req + system rake_req + end + head :ok + end + end diff --git a/app/controllers/fonds_controller.rb b/app/controllers/fonds_controller.rb index d00128c..b9bc9d4 100644 --- a/app/controllers/fonds_controller.rb +++ b/app/controllers/fonds_controller.rb @@ -227,7 +227,7 @@ def index # Upgrade 2.2.0 fine if @fonds.size > 0 @units_counts = Unit.joins(:fond). - where({:root_fond_id => @fonds.map(&:id), :fonds => {:trashed => false}}). + where({:root_fond_id => @fonds.map(&:id), :fonds => {:trashed => false}, :ancestry => nil}). group(:root_fond_id).count("id") end # Upgrade 2.0.0 fine @@ -442,15 +442,15 @@ def merge_with def merge @fond = Fond.find(params[:id]) - if params[:new_root_id].present? - if params[:id] == params[:new_root_id] + if params[:choosen_root_id].present? + if params[:id] == params[:choosen_root_id] flash[:alert] = 'Impossibile unire un complesso archivistico con se stesso.' redirect_to fonds_url return end @choosen_root = Fond.find(params[:choosen_root_id]) - new_root_id = params[:new_root_id].to_i + new_root_id = params[:choosen_root_id].to_i if @fond.move_with_external_sequence(:new_parent_id => @choosen_root.id, :new_position => 1) # Upgrade 3.0.0 inizio # Unit.update_all("root_fond_id = #{@new_root.id}", ["root_fond_id = ?", @fond.id]) diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb index 6fa3385..dd8243d 100644 --- a/app/controllers/imports_controller.rb +++ b/app/controllers/imports_controller.rb @@ -1,11 +1,21 @@ class ImportsController < ApplicationController load_and_authorize_resource -# Upgrade 2.2.0 inizio + # Upgrade 2.2.0 inizio skip_load_and_authorize_resource :only => [ :new ] -# Upgrade 2.2.0 fine + # Upgrade 2.2.0 fine -# Upgrade 2.2.0 inizio + attr_accessor :is_batch_import, :batch_import_user, :batch_import_filename + + # Upgrade 2.2.0 inizio def current_ability + current_user_tmp = NIL + if !@is_batch_import + current_user_tmp = current_user + else + current_user_tmp = @batch_import_user + end + current_user = current_user_tmp + if @current_ability.nil? if (current_user.is_multi_group_user?()) if (["destroy"].include?(params[:action])) @@ -19,65 +29,76 @@ def current_ability end end end - if @current_ability.nil? - @current_ability = super + if !@is_batch_import + if @current_ability.nil? + @current_ability = super + end end return @current_ability end -# Upgrade 2.2.0 fine + # Upgrade 2.2.0 fine def index -# Upgrade 2.0.0 inizio -# @imports = Import.accessible_by(current_ability, :read).all(:include => [:importable], :conditions => {:deletable => true}, :order => "created_at DESC") + # Upgrade 2.0.0 inizio + #@imports = Import.accessible_by(current_ability, :read).all(:include => [:importable], :conditions => {:deletable => true}, :order => "created_at DESC") @imports = Import.accessible_by(current_ability, :read).includes([:importable]).where({:deletable => true}).order("created_at DESC") -# Upgrade 2.0.0 fine + # Upgrade 2.0.0 fine end def new @import = Import.new + @is_icar_import = false end def create -# Upgrade 2.0.0 inizio Strong parameters -# if params[:import].present? -# @import = Import.new(params[:import]) if import_params.present? - @import = Import.new(import_params) -# Upgrade 2.0.0 fine + current_user_tmp = NIL + if !@is_batch_import + @import = Import.new(import_params) + current_user_tmp = current_user + else + current_user_tmp = @batch_import_user + @import = Import.new({"group_id"=>"1"}) + @import.is_batch_import = true + @import.batch_import_filename = @batch_import_filename + end + current_user = current_user_tmp + @import.user_id = current_user.id -# Upgrade 2.2.0 inizio -# @import.group_id = current_user.group_id if current_user.is_multi_group_user?() @import.group_id = current_ability.target_group_id else @import.group_id = current_user.rel_user_groups[0].group_id end - if (params[:context].present? && params[:context] == "units_import") - is_units_import = true - if (params[:ref_fond_id].present?) - @import.ref_fond_id = params[:ref_fond_id] - end - if (params[:ref_root_fond_id].present?) - @import.ref_root_fond_id = params[:ref_root_fond_id] - end - if (params[:ref_fond_id].present?) - redirect_url = fond_units_path(params[:ref_fond_id]) - redirect_url_new = redirect_url + + if !@is_batch_import + if (params[:context].present? && params[:context] == "units_import") + is_units_import = true + if (params[:ref_fond_id].present?) + @import.ref_fond_id = params[:ref_fond_id] + end + if (params[:ref_root_fond_id].present?) + @import.ref_root_fond_id = params[:ref_root_fond_id] + end + if (params[:ref_fond_id].present?) + redirect_url = fond_units_path(params[:ref_fond_id]) + redirect_url_new = redirect_url + else + redirect_url = imports_url + redirect_url_new = new_import_url + end else + is_units_import = false redirect_url = imports_url redirect_url_new = new_import_url end - else - is_units_import = false - redirect_url = imports_url - redirect_url_new = new_import_url end -# Upgrade 2.2.0 fine + @import.identifier = Digest::SHA1.hexdigest("#{Time.now}") if @import.save begin @import.is_valid_file? -# Upgrade 2.2.0 inizio + # Upgrade 2.2.0 inizio if is_units_import if !@import.is_unit_aef_file? raise "Il file aef selezionato non è stato creato esportando unità e non può quindi essere utilizzato con questa funzionalità dell'applicazione.
Per importarlo è necessario utilizzare le funzioni di importazione di file aef disponibili all'interno della relativa sezione dell'applicazione." @@ -87,68 +108,122 @@ def create raise "Il file aef selezionato è stato creato esportando unità e non può quindi essere utilizzato con questa funzionalità dell'applicazione.
Per importarlo è necessario utilizzare la funzionità di importazione di file aef contenenti unità disponibile nella pagina di visualizzazione delle unità di un complesso." end end -# Upgrade 2.2.0 fine + # Upgrade 2.2.0 fine rescue Exception => e Rails.logger.info("eccezione: #{e.message}") @import.delete_tmp_files @import.delete -# Upgrade 2.2.0 inizio -# redirect_to new_import_url, :alert => e.message - redirect_to redirect_url_new, :alert => e.message -# Upgrade 2.2.0 fine + if !@is_batch_import + redirect_to redirect_url_new, :alert => e.message + else + Rails.logger.warn e.message + puts "\n>>> #{e.message}" + end return end -# Upgrade 2.2.0 inizio -# if @import.import_aef_file(current_user) + # Upgrade 2.2.0 inizio + #if @import.import_aef_file(current_user) extens = File.extname(@import.data_file_name).downcase.gsub('.', '') if ['aef'].include? extens if @import.import_aef_file(current_user, current_ability) -# Upgrade 2.2.0 fine + # Upgrade 2.2.0 fine @import.delete_tmp_files @import.update_attributes :importable_id => @import.importable_id, :importable_type => @import.importable_type -# Upgrade 2.2.0 inizio -# redirect_to imports_url, :notice => "File importato correttamente." - redirect_to redirect_url, :notice => "File importato correttamente." -# Upgrade 2.2.0 fine + msg = "File importato correttamente." + if !@is_batch_import + redirect_to redirect_url, :notice => msg + else + Rails.logger.info msg + puts "\n> #{msg}" + end else @import.delete_tmp_files @import.delete -# Upgrade 2.2.0 inizio -# redirect_to imports_url, :alert => "Si è verificato un errore durante l'importazione del file aef." - redirect_to redirect_url, :alert => "Si è verificato un errore durante l'importazione del file aef." -# Upgrade 2.2.0 fine + msg = "Si è verificato un errore durante l'importazione del file aef." + if !@is_batch_import + redirect_to redirect_url, :alert => msg + else + Rails.logger.warn msg + puts "\n>>> #{msg}" + end end - elsif ['zip'].include? extens - - if @import.import_zip_file(current_user, current_ability) - - @import.delete_tmp_files + elsif ['xml'].include? extens + result = @import.import_xml_file(current_user, current_ability) + if result == 1 @import.update_attributes :importable_id => @import.importable_id, :importable_type => @import.importable_type - @import.delete_tmp_zip_files - - redirect_to redirect_url, :notice => "File importato correttamente." - + if @import.does_source_have_fonds + msg_notice = "File importato correttamente." + msg_alert = "Fonte importata collegata a dei complessi.\n I complessi collegati devono essere riassociati manualmente" + if !@is_batch_import + redirect_to redirect_url, :notice => msg_notice, :alert => msg_alert + else + Rails.logger.info msg_notice + Rails.logger.warn msg_alert + puts "\n> #{msg_notice}" + puts ">>> #{msg_alert}" + end + else + msg = "File importato correttamente." + if !@is_batch_import + redirect_to redirect_url, :notice => msg + else + Rails.logger.info msg + puts "\n> #{msg}" + end + end else - @import.delete_tmp_files - @import.delete_tmp_zip_files @import.delete + + if result == 2 + alert = "Si è verificato un errore nella validazione del file xml." + else + alert = "Si è verificato un errore durante l'importazione del file xml." + end - redirect_to redirect_url, :alert => "Si è verificato un errore durante l'importazione del file zip." + if !@is_batch_import + redirect_to redirect_url, :alert => alert + else + Rails.logger.warn alert + puts "\n>>> #{alert}" + end end - else + elsif ['csv'].include? extens if @import.import_csv_file(current_user, current_ability) - redirect_to redirect_url, :notice => "File importato correttamente." + msg = "File importato correttamente." + if !@is_batch_import + redirect_to redirect_url, :notice => msg + else + Rails.logger.info msg + puts "\n> #{msg}" + end else @import.delete - redirect_to redirect_url, :alert => "Si è verificato un errore durante l'importazione del file csv." + msg = "Si è verificato un errore durante l'importazione del file csv." + if !@is_batch_import + redirect_to redirect_url, :alert => msg + else + Rails.logger.warn msg + puts "\n>>> #{msg}" + end + end + else + @import.delete + msg = "Formato file non supportato." + if !@is_batch_import + redirect_to redirect_url, :alert => msg + else + Rails.logger.warn msg + puts "\n>>> #{msg}" end end - else -# Upgrade 2.2.0 inizio -# redirect_to imports_url, :alert => "Si è verificato un errore durante il salvataggio del file aef." - redirect_to redirect_url, :alert => "Si è verificato un errore durante il salvataggio del file aef." -# Upgrade 2.2.0 fine + msg = "Si è verificato un errore durante il salvataggio del file aef." + if !@is_batch_import + redirect_to redirect_url, :alert => msg + else + Rails.logger.warn msg + puts "\n>>> #{msg}" + end end else render :action => "new" @@ -167,10 +242,13 @@ def destroy end end -# Upgrade 2.0.0 inizio Strong parameters def import_params - params.require(:import).permit! + if !@is_batch_import + imp_pars = params.require(:import).permit! + else + imp_pars = {"is_import_batch" => true} + end + return imp_pars end -# Upgrade 2.0.0 fine end diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 9dd726e..4f57b77 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -564,7 +564,9 @@ def pdf_init(action) html = render_to_string(:action => action, :layout => false) kit = PDFKitWrapper.new(html, options) kit.stylesheets << "#{Rails.root}/public/stylesheets/reports-print.css" + Rails.logger.info(kit.command("#{Rails.root}/public/downloads/#{filename}.pdf")) kit.to_file("#{Rails.root}/public/downloads/#{filename}.pdf") + filename # Upgrade 2.0.0 fine end diff --git a/app/controllers/units_controller.rb b/app/controllers/units_controller.rb index dcf74e2..7472171 100644 --- a/app/controllers/units_controller.rb +++ b/app/controllers/units_controller.rb @@ -337,7 +337,7 @@ def index @units = @fond.descendant_units end else - @units = @fond.units + @units = Unit.where(Unit.arel_table[:fond_id].in(@fond.subtree_ids)) end select_clause = "units.id, units.fond_id, units.position, units.sequence_number, units.ancestry, units.ancestry_depth, units.published, units.tsk, diff --git a/app/helpers/imports_helper.rb b/app/helpers/imports_helper.rb index 0374ba0..e0e7dda 100644 --- a/app/helpers/imports_helper.rb +++ b/app/helpers/imports_helper.rb @@ -1,24 +1,38 @@ -# Upgrade 2.2.0 inizio module ImportsHelper def importable_type_caption(import) - if (import.is_unit_importable_type?) - caption = "Unità archivistiche" - else - caption = t(import.importable_type.downcase) - end - return caption + if (import.is_unit_importable_type?) + caption = "Unità archivistiche" + elsif (import.is_institution_importable_type?) + caption = "Profilo istituzionale" + elsif (import.is_anagraphic_importable_type?) + caption = "Scheda anagrafica" + elsif (import.is_source_importable_type?) + caption = "Strumento di ricerca" + else + caption = t(import.importable_type.downcase) + end + return caption end def import_caption(import) - if (import.is_unit_importable_type?) - units_count = Unit.where({:db_source => import.identifier}).count("id") - caption = "(#{units_count.to_s}) importate in: \"#{Fond.find(import.importable.fond_id).display_name}\"" - else - caption = import.importable.display_name - end - return caption + if (import.is_unit_importable_type?) + units_count = Unit.where({:db_source => import.identifier}).count("id") + caption = "(#{units_count.to_s}) importate in: \"#{Fond.find(import.importable.fond_id).display_name}\"" + 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 + elsif (import.is_anagraphic_importable_type?) + caption = import.importable.name + if !import.importable.surname.nil? && !import.importable.surname.empty? + caption += " " + import.importable.surname + end + elsif (import.is_source_importable_type?) + caption = import.importable.short_title + else + caption = import.importable.display_name + end + return caption end - -end -# Upgrade 2.2.0 fine \ No newline at end of file +end \ No newline at end of file diff --git a/app/models/ability.rb b/app/models/ability.rb index 7aced88..a65d5c6 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -5,7 +5,7 @@ class Ability # Upgrade 2.2.0 inizio # Upgrade 3.0.0 inizio attr_accessor :target_group_id - @target_group_id = -1 + @c = -1 def initialize(user, targetGroupId) @target_group_id = targetGroupId @@ -67,7 +67,7 @@ def prv_initialize(user_id, role, group_id, userRelatedGroupIds) when "admin" if (group_id == -1) - can :manage, [Fond, Creator, Custodian, Source, DigitalObject, Institution, DocumentForm, Project, Editor, Heading, Import, Unit], :group_id => userRelatedGroupIds + can :manage, [Anagraphic, Fond, Creator, Custodian, Source, DigitalObject, Institution, DocumentForm, Project, Editor, Heading, Import, Unit], :group_id => userRelatedGroupIds can :manage, User, :rel_user_groups => { :group_id => userRelatedGroupIds } can :manage, RelUserGroup, :group_id => userRelatedGroupIds @@ -76,7 +76,7 @@ def prv_initialize(user_id, role, group_id, userRelatedGroupIds) cannot :create, Group can :manage, GroupImage, :group_id => userRelatedGroupIds else - can :manage, [Fond, Creator, Custodian, Source, DigitalObject, Project, Editor, Heading, Import, Institution, DocumentForm, Unit], :group_id => group_id + can :manage, [Anagraphic, Fond, Creator, Custodian, Source, DigitalObject, Project, Editor, Heading, Import, Institution, DocumentForm, Unit], :group_id => group_id can :manage, User, :rel_user_groups => { :group_id => group_id } cannot [:update, :destroy], User, :rel_user_groups => { :role => 'superadmin' } @@ -118,7 +118,7 @@ def initialize_210(user) cannot [:destroy], Group, :name => 'default' when "admin" - can :manage, [Fond, Creator, Custodian, Source, DigitalObject, Institution, DocumentForm, Project, Editor, Heading, Import], :group_id => user.group_id + can :manage, [Anagraphic, Fond, Creator, Custodian, Source, DigitalObject, Institution, DocumentForm, Project, Editor, Heading, Import], :group_id => user.group_id can :manage, User, :group_id => user.group_id cannot [:update, :destroy], User, :role => 'superadmin' can :manage, Group, :id => user.group_id @@ -136,4 +136,5 @@ def initialize_210(user) end # Upgrade 2.1.0 fine -end \ No newline at end of file +end + diff --git a/app/models/anagraphic.rb b/app/models/anagraphic.rb index f437567..29f0bc2 100644 --- a/app/models/anagraphic.rb +++ b/app/models/anagraphic.rb @@ -7,8 +7,10 @@ class Anagraphic < ActiveRecord::Base belongs_to :updater, :class_name => "User", :foreign_key => "updated_by" - # Many-to-many associations (rel) + # One-to-many associations (rel) + has_one :import, :as => :importable, :dependent => :destroy + # Many-to-many associations (rel) has_many :rel_unit_anagraphics, :autosave => true, :dependent => :destroy has_many :anag_identifiers, :dependent => :destroy has_many :units, :through => :rel_unit_anagraphics @@ -68,3 +70,4 @@ def self.find_or_initialize(params) end end + diff --git a/app/models/creator.rb b/app/models/creator.rb index 2be0668..3cc15c8 100644 --- a/app/models/creator.rb +++ b/app/models/creator.rb @@ -48,6 +48,8 @@ def is_corporate? has_many :digital_objects, :as => :attachable, :dependent => :destroy + has_one :import, :as => :importable, :dependent => :destroy + # Many-to-many associations (rel) has_many :rel_creator_creators, :dependent => :destroy, :autosave => true @@ -232,7 +234,7 @@ def reset_associated_records_by_creator_type preferred_name.first_name = nil preferred_name.last_name = nil preferred_name.note_p = nil - preferred_name.note = preferred_name.note_cf + #preferred_name.note = preferred_name.note_cf # causa note NULL in produttore corporate end end @@ -275,3 +277,4 @@ def sorted_rel_creator_sources end + diff --git a/app/models/custodian.rb b/app/models/custodian.rb index 05371f3..4368ddd 100644 --- a/app/models/custodian.rb +++ b/app/models/custodian.rb @@ -16,7 +16,7 @@ class Custodian < ActiveRecord::Base has_one :preferred_name, :class_name => 'CustodianName', :conditions => {:qualifier => 'AU', :preferred => true} has_many :other_names, :class_name => 'CustodianName', :conditions => {:preferred => false} =end - has_one :preferred_name, -> { where({:qualifier => 'AU', :preferred => true}) }, :class_name => 'CustodianName' + has_one :preferred_name, -> { where({:qualifier => ['OT', 'AU'], :preferred => true}) }, :class_name => 'CustodianName' has_many :other_names, -> { where({:preferred => false}) }, :class_name => 'CustodianName' # Upgrade 2.0.0 fine @@ -150,14 +150,14 @@ class Custodian < ActiveRecord::Base scope :export_list, -> { select("custodians.id, custodian_names.name, custodians.updated_at, custodians.db_source, count(custodians.id) AS num").joins([:fonds, :preferred_name]).group("custodians.id, custodian_names.name").order("custodian_names.name") } scope :search, ->(q) { - conditions = ["custodian_names.qualifier = 'AU' AND LOWER(custodian_names.name) LIKE :q", {:q => "%#{q.downcase.squish}%"}] if q.present? + conditions = ["custodian_names.qualifier = 'OT' AND LOWER(custodian_names.name) LIKE :q", {:q => "%#{q.downcase.squish}%"}] if q.present? where(conditions) } scope :autocomplete_list, ->(term) { select("custodians.id AS id, custodian_names.name AS value, custodian_names.name AS name"). joins(:custodian_names). - where(["custodian_names.preferred = ? AND custodian_names.qualifier = ? AND LOWER(custodian_names.name) LIKE ?", true, 'AU', "%#{term}%"]). + where(["custodian_names.preferred = ? AND custodian_names.qualifier = ? AND LOWER(custodian_names.name) LIKE ?", true, 'OT', "%#{term}%"]). order("custodian_names.name ASC"). limit(10) } diff --git a/app/models/digital_object.rb b/app/models/digital_object.rb index 124f94e..13716fb 100644 --- a/app/models/digital_object.rb +++ b/app/models/digital_object.rb @@ -23,19 +23,24 @@ def scope_condition before_create :generate_access_token # Paperclip - has_attached_file :asset, - :styles => { :large => "1280x1280>", :medium => "210x210>", :thumb => "130x130>" }, - :url => "/digital_objects/:access_token/:style.:extension", - :default_url => "/images/missing-:style.jpg" + begin + has_attached_file :asset, + :styles => { :large => "1280x1280>", :medium => "210x210>", :thumb => "130x130>" }, + :url => "/digital_objects/:access_token/:style.:extension", + :default_url => "/images/missing-:style.jpg" - validates_attachment_presence :asset + validates_attachment_presence :asset - validates_attachment_content_type :asset, - :content_type => ["image/jpeg", "image/jpg", "image/pjpeg", "application/pdf", "video/mp4", "application/mp4", "video/mpeg4"] + validates_attachment_content_type :asset, + :content_type => ["image/jpeg", "image/jpg", "image/pjpeg", "application/pdf", "video/mp4", "application/mp4", "video/mpeg4"] - validates_attachment_size :asset, :less_than => 8.megabytes + validates_attachment_size :asset, :less_than => 8.megabytes - before_post_process :is_image? + before_post_process :is_image? + rescue + # caso del batch import + # do_nothing + end # Scopes # Upgrade 2.0.0 inizio @@ -87,7 +92,10 @@ def to_jq_upload private def generate_access_token - self.access_token = Digest::SHA1.hexdigest("#{asset_file_name}#{Time.now.to_i}") + if self.access_token.nil? + self.access_token = Digest::SHA1.hexdigest("#{asset_file_name}#{Time.now.to_i}") + end + return self.access_token end Paperclip.interpolates :access_token do |attachment, style| diff --git a/app/models/export.rb b/app/models/export.rb index 1600f79..f908e96 100644 --- a/app/models/export.rb +++ b/app/models/export.rb @@ -9,6 +9,13 @@ class Export < ActiveRecord::Base # Upgrade 2.0.0 fine TMP_EXPORTS = "#{Rails.root}/tmp/exports" + PUBLIC_DOWNLOADS = "#{Rails.root}/public/downloads" + + @@icarimportfile = "" + + def get_icarimportfile + @@icarimportfile + end def self.columns() @columns ||= []; end @@ -761,6 +768,67 @@ def selected_fond_ids fond_ids = @fonds.map(&:id) end + def stream_icar_import() + set_fonds(self.target_id) + fond = @fonds.first + + prefix = Time.now.strftime("%Y-%m-%d-%H-%M-%S-") + zip_file_name = PUBLIC_DOWNLOADS + "/#{prefix}icar-import-#{fond.id}.zip" + @@icarimportfile = zip_file_name + File.delete(zip_file_name) if File.exist?(zip_file_name) + + file_name = "#{prefix}icar-import-#{fond.id}.xml" + data_file_name = PUBLIC_DOWNLOADS + "/" + file_name + file_dest = File.new(data_file_name, 'w+') + view = ActionView::Base.new(views_path("icar-import")) + xml = ::Builder::XmlMarkup.new(target: file_dest, :indent => 2) + digital_objects = Array.new + xml = view.render(:file => "icar-import.xml.builder", :locals => {:fond => fond}) + + xml_formatted = '' + require "rexml/document" + doc = REXML::Document.new(xml.to_s) + formatter = REXML::Formatters::Pretty.new + formatter.compact = true + formatter.write(doc, xml_formatted) + + File.open(file_dest, 'w+') { |f| f.write(xml_formatted) } + Zip::File.open(zip_file_name, Zip::File::CREATE) do |zipfile| + zipfile.add(file_name, file_dest.path) + end + + begin + 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}" + end + + #oggetti digitali + fonds_id = Array.new + fonds_id.push(fond.id) + if fond.ancestry.nil? + query = "ancestry LIKE '#{fond.id}/%' OR ancestry = '#{fond.id}'" + else + query = "ancestry LIKE '#{fond.ancestry}/%' OR ancestry = '#{fond.ancestry}'" + end + children_ids = Fond.where(query).pluck(:id) + fonds_id = fonds_id + children_ids + unit_ids = Unit.where(fond_id: fonds_id).pluck(:id) + digital_objects = DigitalObject.where(attachable_id: unit_ids) + if !digital_objects.empty? + Zip::File.open(zip_file_name, false) do |zipfile| + digital_objects.each do |digital_object| + 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 + end + end + end + end + def stream_ead(records, ids = []) if records.present? @@ -1082,7 +1150,7 @@ def create_units_data_file_csv(unit_ids, fond_id) end end - def create_csv(ids, sequence_numbers, options = {}) + def create_csv(ids, sequence_numbers) conditionParam = "#{:id} IN (#{ids.join(',')})" ucsv = Unit.where(conditionParam).order("sequence_number") attributes_all = Unit.column_names @@ -1090,20 +1158,22 @@ def create_csv(ids, sequence_numbers, options = {}) attributes = attributes_all - attributes_except attr_names = attributes.collect { |x| "units_" + x } - CSV.generate(options) do |new_csv| + CSV.generate(:force_quotes => true) do |new_csv| new_csv << attr_names ucsv.each_with_index do |csv_unit, index| csv_data = [] attributes.each do |attribute| + value = nil if attribute == "legacy_id" - csv_data << csv_unit.id + value = csv_unit.id elsif attribute == "legacy_parent_unit_id" - csv_data << csv_unit.is_root? ? nil : csv_unit.parent_id.to_s + value = csv_unit.is_root? ? nil : csv_unit.parent_id elsif attribute == "sequence_number" - csv_data << csv_unit.display_sequence_number_from_hash(sequence_numbers) + value = csv_unit.display_sequence_number_from_hash(sequence_numbers) else - csv_data << csv_unit.try(attribute.to_sym).to_s + value = csv_unit.try(attribute.to_sym) end + csv_data << value end new_csv << csv_data end @@ -1111,13 +1181,13 @@ def create_csv(ids, sequence_numbers, options = {}) end end - def create_related_csv(table, set_element, options = {}) + def create_related_csv(table, set_element) related_attributes_all = table.singularize.camelize.constantize.column_names related_attributes_except = ["id", "db_source", "created_at", "updated_at"] related_attributes = related_attributes_all - related_attributes_except related_attr_names = related_attributes.collect { |j| table + "_" + j } - CSV.generate(options) do |new_related_csv| + CSV.generate(:force_quotes => true) do |new_related_csv| new_related_csv << related_attr_names set_element.each_with_index do |csv_related_unit, index| csv_related_data = [] @@ -1127,17 +1197,19 @@ def create_related_csv(table, set_element, options = {}) if (table == "sc2_commissions") then @sc2_commission_names_ids.push(csv_related_unit.id) end end related_attributes.each do |attribute| + value = nil if attribute == "legacy_id" if table == "sc2_attribution_reasons" - csv_related_data << csv_related_unit.sc2_author_id + value = csv_related_unit.sc2_author_id elsif table == "sc2_commission_names" - csv_related_data << csv_related_unit.sc2_commission_id + value = csv_related_unit.sc2_commission_id else - csv_related_data << csv_related_unit.unit_id + value = csv_related_unit.unit_id end else - csv_related_data << csv_related_unit.try(attribute.to_sym).to_s + value = csv_related_unit.try(attribute.to_sym) end + csv_related_data << value end new_related_csv << csv_related_data end @@ -1324,4 +1396,4 @@ def create_data_file end end -end \ No newline at end of file +end diff --git a/app/models/fond.rb b/app/models/fond.rb index 5995be4..41ee9d0 100644 --- a/app/models/fond.rb +++ b/app/models/fond.rb @@ -1,5 +1,13 @@ class Fond < ActiveRecord::Base + # INIZIO - require richiesti per l'import batch + require File.join(File.dirname(__FILE__), ".", "fond_event.rb") + require File.join(File.dirname(__FILE__), ".", "unit.rb") + require File.join(File.dirname(__FILE__), ".", "fond_editor.rb") + require File.join(File.dirname(__FILE__), ".", "fond_name.rb") + require File.join(File.dirname(__FILE__), ".", "fond_identifier.rb") + # FINE - require richiesti per l'import batch + # Modules extend Cleaner @@ -64,7 +72,15 @@ class Fond < ActiveRecord::Base def active_descendant_units_count # Upgrade 2.0.0 inizio # Unit.count("id", :joins => :fond, :conditions => {:fond_id => subtree_ids, :fonds => {:trashed => false}}) - Unit.joins(:fond).where({:fond_id => subtree_ids, :fonds => {:trashed => false}}).count("id") + Unit.joins(:fond).where({:fond_id => subtree_ids, :fonds => {:trashed => false}, :ancestry => nil}).count("id") +# Upgrade 2.0.0 fine + end + + def active_descendant_units_count_children +# Upgrade 2.0.0 inizio +# Unit.count("id", :joins => :fond, :conditions => {:fond_id => subtree_ids, :fonds => {:trashed => false}}) +# Unit.joins(:fond).where({:fond_id => id, :fonds => {:trashed => false}, :ancestry => #nil}).count("id") + Unit.joins(:fond).where({:fond_id => subtree_ids, :ancestry_depth =>0, :fonds => {:trashed => false}, :ancestry => nil}).count("id") # Upgrade 2.0.0 fine end diff --git a/app/models/import.rb b/app/models/import.rb index 206e279..7276366 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -1,59 +1,126 @@ class Import < ActiveRecord::Base require 'csv' - -# Upgrade 2.0.0 inizio -# require 'zip/zip' -# nella versione rubyzip-1.1.6 zip.rb non è nella sottocartella zip dive invece era nella rubyzip-0.9.9 usata prima + require 'nokogiri' + require 'open-uri' require 'zip' -# Upgrade 2.0.0 fine - -# Upgrade 2.1.0 inizio + require 'active_support' + + # INIZIO - require richiesti per l'import batch + require File.join(File.dirname(__FILE__), ".", "fond.rb") + require File.join(File.dirname(__FILE__), ".", "creator_event.rb") + require File.join(File.dirname(__FILE__), ".", "creator.rb") + require File.join(File.dirname(__FILE__), ".", "fond_lang.rb") + require File.join(File.dirname(__FILE__), ".", "rel_custodian_fond.rb") + require File.join(File.dirname(__FILE__), ".", "rel_fond_source.rb") + require File.join(File.dirname(__FILE__), ".", "digital_object.rb") + require File.join(File.dirname(__FILE__), ".", "source.rb") + require File.join(File.dirname(__FILE__), ".", "source_url.rb") + require File.join(File.dirname(__FILE__), ".", "creator_corporate_type.rb") + require File.join(File.dirname(__FILE__), ".", "rel_creator_fond.rb") + require File.join(File.dirname(__FILE__), ".", "creator_url.rb") + require File.join(File.dirname(__FILE__), ".", "creator_editor.rb") + require File.join(File.dirname(__FILE__), ".", "creator_name.rb") + require File.join(File.dirname(__FILE__), ".", "creator_legal_status.rb") + require File.join(File.dirname(__FILE__), ".", "rel_creator_source.rb") + require File.join(File.dirname(__FILE__), ".", "rel_creator_institution.rb") + require File.join(File.dirname(__FILE__), ".", "institution.rb") + require File.join(File.dirname(__FILE__), ".", "institution_editor.rb") + require File.join(File.dirname(__FILE__), ".", "custodian.rb") + require File.join(File.dirname(__FILE__), ".", "custodian_type.rb") + require File.join(File.dirname(__FILE__), ".", "custodian_name.rb") + require File.join(File.dirname(__FILE__), ".", "custodian_url.rb") + require File.join(File.dirname(__FILE__), ".", "rel_custodian_source.rb") + require File.join(File.dirname(__FILE__), ".", "custodian_identifier.rb") + require File.join(File.dirname(__FILE__), ".", "custodian_building.rb") + require File.join(File.dirname(__FILE__), ".", "custodian_contact.rb") + require File.join(File.dirname(__FILE__), ".", "custodian_editor.rb") + require File.join(File.dirname(__FILE__), ".", "source_type.rb") + require File.join(File.dirname(__FILE__), ".", "unit_identifier.rb") + require File.join(File.dirname(__FILE__), ".", "sc2.rb") + require File.join(File.dirname(__FILE__), ".", "unit_editor.rb") + require File.join(File.dirname(__FILE__), ".", "heading.rb") + require File.join(File.dirname(__FILE__), ".", "rel_unit_heading.rb") + + require File.join(File.dirname(__FILE__), ".", "unit_url.rb") + require File.join(File.dirname(__FILE__), ".", "unit_event.rb") + require File.join(File.dirname(__FILE__), ".", "anagraphic.rb") + require File.join(File.dirname(__FILE__), ".", "rel_unit_anagraphic.rb") + require File.join(File.dirname(__FILE__), ".", "anag_identifier.rb") + require File.join(File.dirname(__FILE__), ".", "fond_editor.rb") + require File.join(File.dirname(__FILE__), ".", "fond_name.rb") + require File.join(File.dirname(__FILE__), ".", "fond_event.rb") + require File.join(File.dirname(__FILE__), ".", "fond_identifier.rb") + require File.join(File.dirname(__FILE__), ".", "creator_identifier.rb") + require File.join(File.dirname(__FILE__), ".", "document_form.rb") + require File.join(File.dirname(__FILE__), ".", "rel_fond_document_form.rb") + require File.join(File.dirname(__FILE__), ".", "term.rb") + require File.join(File.dirname(__FILE__), ".", "vocabulary.rb") + require File.join(File.dirname(__FILE__), ".", "sc2_scale.rb") + require File.join(File.dirname(__FILE__), ".", "sc2_technique.rb") + require File.join(File.dirname(__FILE__), ".", "sc2_textual_element.rb") + require File.join(File.dirname(__FILE__), ".", "sc2_visual_element.rb") + require File.join(File.dirname(__FILE__), ".", "sc2_author.rb") + require File.join(File.dirname(__FILE__), ".", "sc2_attribution_reason.rb") + require File.join(File.dirname(__FILE__), ".", "fe_context.rb") + 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 + # Upgrade 2.1.0 fine - attr_accessor :imported_file_version -# Upgrade 2.2.0 inizio - attr_accessor :ref_fond_id, :ref_root_fond_id -# Upgrade 2.2.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 + # Upgrade 3.0.0 inizio PUBLIC_IMPORTS = "#{Rails.root}/public/imports" -# Upgrade 3.0.0 fine + # Upgrade 3.0.0 fine DIGITAL_FOLDER_PATH = "#{Rails.root}/public/digital_objects" belongs_to :user belongs_to :importable, :polymorphic => true - has_attached_file :data, :path => ":rails_root/public/imports/:id/:basename.:extension" + @is_batch_import = false - before_create :sanitize_file_name - validates_attachment_presence :data -# Upgrade 2.0.0 inizio - do_not_validate_attachment_file_type :data -# Upgrade 2.0.0 fine + begin + has_attached_file :data, :path => ":rails_root/public/imports/:id/:basename.:extension" + rescue + @is_batch_import = true + end + before_create :sanitize_file_name + + begin + validates_attachment_presence :data + do_not_validate_attachment_file_type :data + rescue + # caso del batch import + # do_nothing + end + def ar_connection -# Upgrade 2.0.0 inizio -# ActiveRecord::Base.connection + # Upgrade 2.0.0 inizio + #ActiveRecord::Base.connection self.class.connection -# Upgrade 2.0.0 fine + # Upgrade 2.0.0 fine end def adapter ar_connection.adapter_name.downcase end - def zip_data_file - filename = self.importable_type.downcase - TMP_IMPORTS + "/#{self.id}_data-#{filename}.xml" + def xml_data_file + PUBLIC_IMPORTS + "/#{self.id}/#{self.data_file_name}" end -# Upgrade 3.0.0 inizio + # Upgrade 3.0.0 inizio def csv_data_file - PUBLIC_IMPORTS + "/#{self.id}/#{self.data_file_name}" + PUBLIC_IMPORTS + "/#{self.id}/#{self.data_file_name}" end -# Upgrade 3.0.0 fine + # Upgrade 3.0.0 fine def data_file TMP_IMPORTS + "/#{self.id}_data.json" @@ -64,15 +131,15 @@ def metadata_file end def delete_tmp_files - File.delete(data_file) if File.exists?(data_file) - File.delete(metadata_file) if File.exists?(metadata_file) + File.delete(data_file) if File.exists?(data_file) + File.delete(metadata_file) if File.exists?(metadata_file) end def delete_tmp_zip_files @extracted_files.each do |efd| File.delete(efd) if File.exists?(efd) end - File.delete(TMP_IMPORTS + "/data.json") if File.exists?(TMP_IMPORTS + "/data.json") + File.delete(TMP_IMPORTS + "/data.json") if File.exists?(TMP_IMPORTS + "/data.json") end def delete_digital_folder(folder) @@ -89,7 +156,27 @@ def db_has_digital_objects? DigitalObject.exists?(["db_source = ?", self.identifier]) end -# Upgrade 2.2.0 inizio + def is_institution_importable_type? + return (importable_type == "Institution") + end + + def is_creator_importable_type? + return (importable_type == "Creator") + end + + def is_anagraphic_importable_type? + return (importable_type == "Anagraphic") + end + + def is_custodian_importable_type? + return (importable_type == "Custodian") + end + + def is_source_importable_type? + return (importable_type == "Source") + end + + # Upgrade 2.2.0 inizio def is_unit_importable_type? return (importable_type == "Unit") end @@ -98,72 +185,88 @@ def is_unit_aef_file? return is_unit_importable_type? end -# Upgrade 3.0.0 inizio -# modificata nella 3.1.1 con l'utilizzo della gemma csv + # Upgrade 3.0.0 inizio + # modificata nella 3.1.1 con l'utilizzo della gemma csv def import_csv_file(user, ability) begin - csv_file = CSV.read(csv_data_file) - lines = File.readlines(csv_data_file) unit_aef_import_units_count = 0 - + rebuild_sequence = false + ActiveRecord::Base.transaction do model = nil prev_model = nil object = nil prev_line = "" - headers = "" + headers = nil elem_count = 0 separator = "" - lines.each_with_index do |line, i| - line = line.delete("\r") - line = line.delete("\a") - line = line.delete("\b") - line = line.delete("\t") - line = line.delete("\f") - if prev_line.blank? - elements = line.delete("\n").split(',') - elem_count > elements.count - 1 ? elem_count = elem_count : elem_count = elements.count - 1 - separator = "," * elem_count - elem = elements[1].split('_') + date_time = DateTime.now + sequence_number = nil + + CSV.foreach(csv_data_file) do |row| + if prev_line.blank? and (!row.blank? or !row.all?(&:blank?)) pos_last = -1 + elem = row[0].split('_') elem.each do |e| if e.last == "s" pos_last += 1 break else pos_last += 1 - end + end end key = (elem[0..pos_last].join('_'))[0..-2] key = key.to_s model = key.camelize.constantize - headers = elements.map!{ |element| element.gsub(key + 's_', '') } + headers = [] + row.each do |elem| + if !elem.nil? + headers.push(elem.gsub!(key + 's_', '')) + end + end prev_line = "not_blank" else - line = line.delete("\n") - if (line.include? separator) || (line.blank?) + if row.all?(&:blank?) prev_line = "" - next else - values = csv_file[i] - values = values.map!{ |value| value.nil? ? '' : value } + values = row.map! { |value| value.nil? ? '' : value } zipped = headers.zip(values) ipdata = Hash[zipped] object = model.new(ipdata) object.db_source = self.identifier if object.has_attribute? 'group_id' - object.group_id = if user.is_multi_group_user?() then ability.target_group_id else user.rel_user_groups[0].group_id end + object.group_id = if user.is_multi_group_user?() then + ability.target_group_id + else + user.rel_user_groups[0].group_id + end end if (self.is_unit_aef_file?) if (model.to_s == "Unit") object.fond_id = self.ref_fond_id object.root_fond_id = prv_get_ref_root_fond_id + rebuild_sequence = true + + if sequence_number.nil? + sequence_number = Unit.where(:root_fond_id => object.root_fond_id).maximum(:sequence_number) + end + sequence_number = sequence_number + 1 + object.sequence_number = sequence_number + unit_aef_import_units_count += 1 end end object.created_by = user.id if object.has_attribute? 'created_by' object.updated_by = user.id if object.has_attribute? 'updated_by' + if object.created_at.nil? + object.created_at = date_time + end + if object.updated_at.nil? + object.updated_at = date_time + end + object.sneaky_save! + if model != prev_model && !prev_model.nil? prev_object = prev_model.new set_lacking_field_values(prev_object) @@ -174,839 +277,3298 @@ def import_csv_file(user, ability) end end update_statements(unit_aef_import_units_count) + + if rebuild_sequence + Fond.find(prv_get_ref_root_fond_id).rebuild_external_sequence + end rescue Exception => e Rails.logger.info "import_csv_file errore: " + e.message.to_s return false ensure end end -# Upgrade 3.0.0 fine + # Upgrade 3.0.0 fine - def fond_creator_relation(creator_id) - rel_creator_fond = {'rel_creator_fond' => { - 'legacy_creator_id'=> creator_id, - 'legacy_fond_id'=> @fond_leg_id - } - } - File.open(TMP_IMPORTS + "/data.json","a") do |f| - f.write(rel_creator_fond.to_json) - f.write("\r\n") - end + def import_unit_from_path document, user_id, group_id + Rails.logger.info "Import unita' INIZIATO da import.rb" + + datetime = Time.now.strftime("%Y-%m-%d %H:%M:%S") + unit_component = document.xpath("did/unitid") + + unit = Unit.new + + unit.db_source = self.identifier + unit.created_by = user_id + unit.updated_by = user_id + unit.created_at = datetime + unit.updated_at = datetime + + case document.xpath("@level").text + when "list" + unit.unit_type = "registro o altra unità rilegata" + when "file" + unit.unit_type = "fascicolo o altra unità complessa" + when "item" + unit.unit_type = "unità documentaria" + end + + + unit.legacy_id = unit_component.xpath("@identifier").text + + 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 + if terms.include? condition.downcase + unit.access_condition = condition.downcase + else + unit.access_condition_note = condition.gsub(/\t/, '') + end + 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 + if terms.include? condition.downcase + unit.use_condition = condition.downcase + else + unit.use_condition_note = condition.gsub(/\t/, '') + end + end + + unit.ancestry = nil + unit.ancestry_depth = 0 + 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.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 + unit.folder_number = unit_component.xpath("../unitid[@localtype='busta']").text + unit.medium = unit_component.xpath("../physdescstructured/physfacet[@localtype='Supporto']").text + 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.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.tmp_reference_number = unit_component.xpath("../unitid[@localtype='segnaturaProvvisoriaNumero']").text + unit.tmp_reference_string = unit_component.xpath("../unitid[@localtype='segnaturaProvvisoriaTesto']").text + + unit.fond_id = nil + if (unit.fond_id.present?) + unit.root_fond_id = Fond.find(unit.fond_id).root.id + end + Rails.logger.info "Salvataggio unita'" + unit.sneaky_save + + unit_component.xpath("../unitid").each do |unitid| + if unitid.xpath("@identifier").present? + unit_identifier = UnitIdentifier.new + unit_identifier.unit_id = unit.id + unit_identifier.identifier = unitid.text + unit_identifier.note = "Identificativo di sistema" + unit_identifier.db_source = self.identifier + unit_identifier.save! + end + end + + if unit_component.xpath("../unitid[@localtype='classificazione']").present? || + unit_component.xpath("../unitid[@localtype='fascicolo']").present? || + unit_component.xpath("../unitid[@localtype='subfascicolo']").present? + fe_context = FeContext.new + fe_context.unit_id = unit.id + fe_context.classification = unit_component.xpath("../unitid[@localtype='classificazione']").text + fe_context.number = unit_component.xpath("../unitid[@localtype='fascicolo']").text + fe_context.sub_number = unit_component.xpath("../unitid[@localtype='subfascicolo']").text + fe_context.save! + end + + if unit_component.xpath("../unitid[@localtype='classe']").present? || + unit_component.xpath("../unitid[@localtype='codice']").present? || + unit_component.xpath("../unitid[@localtype='categoria']").present? || + unit_component.xpath("../unitid[@localtype='anno']").present? + fe_identifications = FeIdentification.new + fe_identifications.unit_id = unit.id + fe_identifications.identification_class = unit_component.xpath("../unitid[@localtype='classe']").text + fe_identifications.code = unit_component.xpath("../unitid[@localtype='codice']").text + fe_identifications.category = unit_component.xpath("../unitid[@localtype='categoria']").text + fe_identifications.file_year = unit_component.xpath("../unitid[@localtype='anno']").text + fe_identifications.save! + end + + if unit_component.xpath("../physdescstructured").present? || + unit_component.xpath("../../odd[@localtype='NumeroTavola']/p").present? || + unit_component.xpath("../../controlaccess/subject[@localtype='Soggetto']").present? + sc2 = Sc2.new + sc2.unit_id = unit.id + sc2.mtce = unit_component.xpath("../physdescstructured/physfacet[@localtype='Esecuzione']").text + sc2.sdtt = unit_component.xpath("../physdescstructured/physfacet[@localtype='Tiporappresentazione']").text + sc2.misa = unit_component.xpath("../physdescstructured/physfacet[@localtype='altezza']").text + sc2.misl = unit_component.xpath("../physdescstructured/physfacet[@localtype='larghezza']").text + sc2.lrc = unit_component.xpath("../physdescstructured/descriptivenote/p/geoname[@localtype='Luogorappresentazione']/part").text + sc2.dpgf = unit_component.xpath("../../odd[@localtype='NumeroTavola']/p").text + sc2.sgti = unit_component.xpath("../../controlaccess/subject[@localtype='Soggetto']/part").text + sc2.save! + end + + if unit_component.xpath("../physdescstructured/physfacet[@localtype='Scala']").present? + sc2_scales = Sc2Scale.new + sc2_scales.unit_id = unit.id + sc2_scales.sca = unit_component.xpath("../physdescstructured/physfacet[@localtype='Scala']").text + sc2_scales.save! + end + + if unit_component.xpath("../physdescstructured/physfacet[@localtype='Tecnica']").present? + sc2_techniques = Sc2Technique.new + sc2_techniques.unit_id = unit.id + sc2_techniques.mtct = unit_component.xpath("../physdescstructured/physfacet[@localtype='Tecnica']").text + sc2_techniques.save! + end + + 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.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.save! + end + + if unit_component.xpath("../../controlaccess/name[@localtype='Autore']").present? + sc2_authors = Sc2Author.new + sc2_authors.autr = unit_component.xpath("../../controlaccess/name[@localtype='Autore']/part[@localtype='Ruolo']").text + sc2_authors.autn = unit_component.xpath("../../controlaccess/name[@localtype='Autore']/part[@localtype='Autore']").text + sc2_authors.auta = unit_component.xpath("../../controlaccess/name[@localtype='Autore']/part[@localtype='DatiAnagrafici']").text + sc2_authors.save! + + if unit_component.xpath("../../controlaccess/name[@localtype='Autore']/part[@localtype='Attribuzione']").present? + sc2_attribution_reasons = Sc2AttributionReason.new + sc2_attribution_reasons.sc2_author_id = sc2_authors.id + sc2_attribution_reasons.autm = unit_component.xpath("../../controlaccess/name[@localtype='Autore']/part[@localtype='Attribuzione']").text + sc2_attribution_reasons.save! + end + end + + #if unit_component.xpath("../../controlaccess/name[@localtype='Committente']").present? + # sc2_commission = Sc2Commission.new + # sc2_commission.unit_id = unit.id + # sc2_commission.cmmc + #end + if unit_component.xpath("../../processinfo[@localtype='compilatori']/processinfo").present? + unit_component.xpath("../../processinfo[@localtype='compilatori']/processinfo").each do |pi| + editor = UnitEditor.new + editor.unit_id = unit.id + editor.name = pi.xpath("p/persname/part[@localtype='compilatore']").text + tipo_intervento = pi.xpath("p/persname/part[@localtype='tipoIntervento']").text + if tipo_intervento == "inserimento" || tipo_intervento == "created" + editor.editing_type = "inserimento dati" + elsif tipo_intervento == "modifica" || tipo_intervento == "updated" + editor.editing_type = "aggiornamento scheda" + end + editor.qualifier = pi.xpath("p/persname/part[@localtype='qualifica']").text + editor.edited_at = pi.xpath("p/date[@localtype='dataIntervento']").text + editor.save! + end + else + if unit_component.xpath("/ead/control/maintenancehistory/maintenanceevent").present? + unit_component.xpath("/ead/control/maintenancehistory/maintenanceevent").each do |maintenance_event| + editor = UnitEditor.new + editor.unit_id = unit.id + editor.name = maintenance_event.xpath("agent").text.squish + editor.editing_type = import_editing_type(maintenance_event.xpath("eventtype/@value").text) + if maintenance_event.xpath("eventdatetime").present? + editor.edited_at = maintenance_event.xpath("eventdatetime").text.squish + end + editor.qualifier = import_agent_type(maintenance_event.xpath("agenttype/@value").text) + editor.save + end + end + end + + if unit_component.xpath("../../controlaccess/persname").present? + unit_component.xpath("../../controlaccess/persname").each do |heading| + headingObj = get_heading_obj(heading, 'Persona') + save_heading(headingObj, unit.id) + end + end + + if unit_component.xpath("../../controlaccess/famname").present? + unit_component.xpath("../../controlaccess/famname").each do |heading| + headingObj = get_heading_obj(heading, 'Famiglia') + save_heading(headingObj, unit.id) + end + end + + if unit_component.xpath("../../controlaccess/corpname").present? + unit_component.xpath("../../controlaccess/corpname").each do |heading| + headingObj = get_heading_obj(heading, 'Ente') + save_heading(headingObj, unit.id) + end + end + + if unit_component.xpath("../../controlaccess/geogname").present? + unit_component.xpath("../../controlaccess/geogname").each do |heading| + headingObj = get_heading_obj(heading, 'Toponimo') + save_heading(headingObj, unit.id) + end + end + + if unit_component.xpath("../../controlaccess/subject").present? + unit_component.xpath("../../controlaccess/subject").each do |heading| + headingObj = get_heading_obj(heading, 'Altro') + save_heading(headingObj, unit.id) + end + end + + if unit_component.xpath("../../controlaccess/genreform").present? + unit_component.xpath("../../controlaccess/genreform").each do |heading| + headingObj = get_heading_obj(heading, 'Tipologia documentaria') + save_heading(headingObj, unit.id) + end + end + + if unit_component.xpath("../../relations/relation[@otherrelationtype='URL']").present? + unit_component.xpath("../../relation/relationtype[@otherrelationtype='URL']").each do |url| + unit_url = UnitUrl.new + unit_url.id = unit.id + unit_url.url = url.xpath('@href').text + unit_url.note = url.xpath('relationentry').text + unit_url.save! + end + end + + if unit_component.xpath("../unitdatestructured").present? + date = unit_component.xpath("../unitdatestructured") + unit_event = UnitEvent.new + unit_event.unit_id = unit.id + if date.xpath("dateset").present? + import_dateset date.xpath("dateset").first, unit_event, datetime + else + import_dateset date, unit_event, datetime + end + end + + if unit_component.xpath("../../relations/relation[@otherrelationtype='INDICE']/relationentry[@localtype='identificativo']").present? + unit_component.xpath("../../relations/relation[@otherrelationtype='INDICE']/relationentry[@localtype='identificativo']").each do |anagraphic_id| + anagraphic = Anagraphic.where(db_source: self.identifier, legacy_id: anagraphic_id.text[3..10].to_i.to_s) + if anagraphic.present? + rel_unit_anag = RelUnitAnagraphic.new + rel_unit_anag.db_source = self.identifier + rel_unit_anag.unit_id = unit.id + rel_unit_anag.anagraphic_id = anagraphic.first.id + rel_unit_anag.legacy_unit_id = unit.legacy_id + rel_unit_anag.legacy_anagraphic_id = anagraphic.first.legacy_id + rel_unit_anag.save + end + end + end + if unit_component.xpath("../../did/dao").present? + unit_component.xpath("../../did/dao").each do |digital_obj| + digital_object = DigitalObject.new + digital_object.attachable_type = 'Unit' + digital_object.attachable_id = unit.id + digital_object.db_source = self.identifier + digital_object.legacy_id = digital_obj.xpath('@id').text + href = digital_obj.xpath('@href').text.split('/') + + #if href.last == "" + # href.pop + #end + #digital_object.asset_file_name = href.pop #esclude il nome del file .jpg dopo aver eliminato la stringa vuota dovuta all'eventuale fine dell'url con uno slash + #digital_object.access_token = href.last + digital_object.access_token = href.first + digital_object.asset_file_name = href.last + + digital_object.asset_content_type = digital_obj.xpath("@linkrole").text + digital_object.title = "importato senza titolo" + digital_object.created_by = user_id + digital_object.updated_by = user_id + digital_object.group_id = group_id + digital_object.asset_updated_at = datetime + digital_object.save! + Rails.logger.info "Oggetto digitale #{digital_object.id} aggiunto all'unità #{digital_object.attachable_id}" + end + end + + + Rails.logger.info "Unita' salvata, id: #{unit.id}" + self.importable_id = unit.id + return unit end - def extract_creator(zip_data_file) - xml = File.open(zip_data_file).read - json = Hash.from_xml(xml).to_json - parsed_xml_to_json = ActiveSupport::JSON.decode(json).symbolize_keys - if parsed_xml_to_json[:eac_cpf]["cpfDescription"].kind_of?(Array) - creator_size = parsed_xml_to_json[:eac_cpf]["cpfDescription"].length - creator_num = 0 - begin - creator_leg_id = rand(1..1000) - fond_creator_relation(creator_leg_id) - entityType = parsed_xml_to_json[:eac_cpf]["cpfDescription"][creator_num]["identity"]["entityType"] - if entityType == "corporateBody" - creator_type = "C" - event_start = parsed_xml_to_json[:eac_cpf]["cpfDescription"][creator_num]["description"]["existDates"]["dateRange"] - event_end = parsed_xml_to_json[:eac_cpf]["cpfDescription"][creator_num]["description"]["existDates"]["dateRange"] - residence = parsed_xml_to_json[:eac_cpf]["cpfDescription"][creator_num]["description"]["place"]["placeEntry"] - elsif entityType == "person" - creator_type = "P" - event_start = parsed_xml_to_json[:eac_cpf]["cpfDescription"][creator_num]["description"]["existDates"][0] - event_end = parsed_xml_to_json[:eac_cpf]["cpfDescription"][creator_num]["description"]["existDates"][1] - residence = nil - elsif entityType == "family" - creator_type = "F" - event_start = parsed_xml_to_json[:eac_cpf]["cpfDescription"][creator_num]["description"]["existDates"][0] - event_end = parsed_xml_to_json[:eac_cpf]["cpfDescription"][creator_num]["description"]["existDates"][1] - residence = nil - end - history = parsed_xml_to_json[:eac_cpf]["cpfDescription"][creator_num]["description"]["biogHist"].present? ? parsed_xml_to_json[:eac_cpf]["cpfDescription"][creator_num]["description"]["biogHist"]["abstract"] : nil - creator = {'creator' => { - 'creator_type'=> creator_type, - 'creator_corporate_type_id'=> nil, - 'residence'=> residence, - 'abstract'=> '', - 'history'=> history, - 'legal_status'=> nil, - 'note'=> '', - 'legacy_id'=> creator_leg_id, - 'published'=> true - } - } - File.open(TMP_IMPORTS + "/data.json","a") do |f| - f.write(creator.to_json) - f.write("\r\n") - end - - rel_creator_event(event_start, event_end, creator_leg_id) - - if parsed_xml_to_json[:eac_cpf]["cpfDescription"][creator_num]["identity"]["nameEntry"].present? - if parsed_xml_to_json[:eac_cpf]["cpfDescription"][creator_num]["identity"]["nameEntry"].kind_of?(Array) - size = parsed_xml_to_json[:eac_cpf]["cpfDescription"][creator_num]["identity"]["nameEntry"].length - nums = 0 - begin - creator_name = parsed_xml_to_json[:eac_cpf]["cpfDescription"][creator_num]["identity"]["nameEntry"][nums]["part"] - preferred = true - qualifier = "A" - if nums > 0 - preferred = false - qualifier = "OT" - end - rel_creator_name(creator_name, creator_leg_id, preferred, qualifier) - nums += 1 - end while size > nums + def save_heading (headingObj, unit_id) + rel_unit_heading = RelUnitHeading.new + unless headingObj.id? + headingObj.save! + end + rel_unit_heading.heading_id = headingObj.id + rel_unit_heading.unit_id = unit_id + rel_unit_heading.save! + end + + def get_heading_obj (heading_xml, heading_type) + heading_name = [] + heading_name.push(heading_xml.xpath('part[@localtype="cognome"]').text) + heading_name.push(heading_xml.xpath('part[@localtype="nome"]').text) + heading_name.push(heading_xml.xpath('part[not(@*)]').text) + name = heading_name.join(' ').squish + + headingObj = Heading.find_by(name: name) #il nome deve essere unico + if headingObj.nil? + headingObj = Heading.new + headingObj.heading_type = heading_type + headingObj.name = name + headingObj.dates = heading_xml.xpath("part[@localtype='estremiCronologici']").text + headingObj.qualifier = heading_xml.xpath("part[@localtype='qualifica']").text + end + + headingObj + end + + def import_unit_hierarchy (unit_xpath, root_fond_id, fond_id, user_id, group_id, ancestry) + fond = Fond.find(fond_id) + unit_just_saved = Unit.find (import_unit_from_path unit_xpath, user_id, group_id).id + unit_just_saved.ancestry = ancestry + unit_just_saved.fond_id = fond_id + unit_just_saved.root_fond_id = root_fond_id + Rails.logger.info "unita' #{unit_just_saved.id} del complesso #{fond_id} con root: #{root_fond_id}" + unit_just_saved.ancestry_depth = 0 + if ancestry != nil + unit_just_saved.ancestry_depth = ancestry.split('/').size + end + fond.units_count = fond.units.count + unit_just_saved.sequence_number = fond.units.count + 1 + unit_just_saved.sneaky_update + fond.sneaky_update + if unit_xpath.xpath('c').present? + unit_xpath.xpath('c').each do |subunit| + if ancestry != nil + import_unit_hierarchy subunit, root_fond_id, fond_id, user_id, group_id, (ancestry + '/' + unit_just_saved.id.to_s) else - creator_name = parsed_xml_to_json[:eac_cpf]["cpfDescription"][creator_num]["identity"]["nameEntry"]["part"] - preferred = true - qualifier = "A" - rel_creator_name(creator_name, creator_leg_id, preferred, qualifier) + import_unit_hierarchy subunit, root_fond_id, fond_id, user_id, group_id, unit_just_saved.id.to_s end - end + end + end + Rails.logger.info "Unita` #{unit_xpath.xpath('did/unitid/@identifier').text} salvata." + return + end - if parsed_xml_to_json[:eac_cpf]["control"][creator_num]["maintenanceHistory"]["maintenanceEvent"].kind_of?(Array) - length_editor = parsed_xml_to_json[:eac_cpf]["control"][creator_num]["maintenanceHistory"]["maintenanceEvent"].length - num = 0 - begin - creator_editor = parsed_xml_to_json[:eac_cpf]["control"][creator_num]["maintenanceHistory"]["maintenanceEvent"][num] - rel_creator_editor(creator_editor, creator_leg_id) - num +=1 - end while length_editor > num - else - creator_editor = parsed_xml_to_json[:eac_cpf]["control"][creator_num]["maintenanceHistory"]["maintenanceEvent"] - rel_creator_editor(creator_editor, creator_leg_id) + #fond_root: ead/archdesc o ..dsc/c + #ancestry: rappresenta una stringa contenente tutti i parent dell'entita` in considerazione + def import_fond_hierarchy (fond_root, user_id, group_id, ancestry) + #TODO da rendere una costante globale. + fond_types = [ + "fonds", + "recordgrp", + "subfonds", + "series", + "subseries", + "subsubseries", + "otherlevel" + ] + #otherlevels = Term.where(id: Vocabulary.find_by(name: "fonds.fond_type").id).select(:term_value) + + def eredita_compilatori (fond_id, ancestry) + if ancestry != "" + + fond_editor = FondEditor.find_by_fond_id(fond_id) + + if fond_editor.nil? + parent_fond_id = ancestry.split("/")[-1].to_i + + FondEditor.where(fond_id: parent_fond_id).find_each do |parent_fond_editor| + new_fond_editor = FondEditor.new + new_fond_editor.fond_id = fond_id + new_fond_editor.name = parent_fond_editor.name + new_fond_editor.qualifier = parent_fond_editor.qualifier + new_fond_editor.editing_type = parent_fond_editor.editing_type + new_fond_editor.edited_at = parent_fond_editor.edited_at + new_fond_editor.db_source = parent_fond_editor.db_source + new_fond_editor.legacy_id = parent_fond_editor.legacy_id + new_fond_editor.created_at = parent_fond_editor.created_at + new_fond_editor.updated_at = parent_fond_editor.updated_at + new_fond_editor.save! + end end - creator_num += 1 - end while creator_size > creator_num + end + end + + if ancestry == '' + fond_just_saved = import_fond_from_path fond_root, user_id, group_id + root_fond_id = fond_just_saved.id + + eredita_compilatori(fond_just_saved.id, ancestry) + + ancestry = fond_just_saved.id.to_s + import_fond_control_field fond_root.xpath("../control"), root_fond_id + + if fond_root.xpath('dsc/c').present? + Rails.logger.info "Importazione figli di primo livello del fondo." + fond_root.xpath('dsc/c').each do |subfond| + if fond_types.include? subfond.xpath("@level").text + fond_just_saved = Fond.find (import_fond_from_path subfond, user_id, group_id).id + fond_just_saved.ancestry = ancestry + fond_just_saved.ancestry_depth = 1 + fond_just_saved.sneaky_update + + eredita_compilatori(fond_just_saved.id, ancestry) + + import_fond_hierarchy subfond, user_id, group_id, (ancestry + '/' + fond_just_saved.id.to_s) + else + import_unit_hierarchy subfond, ancestry.split('/').first.to_i, ancestry.split('/').last.to_i, user_id, group_id, nil + end + end + end + return root_fond_id else - creator_leg_id = rand(1..1000) - fond_creator_relation(creator_leg_id) - entityType = parsed_xml_to_json[:eac_cpf]["cpfDescription"]["identity"]["entityType"] - if entityType == "corporateBody" - creator_type = "C" - event_start = parsed_xml_to_json[:eac_cpf]["cpfDescription"]["description"]["existDates"]["dateRange"] - event_end = parsed_xml_to_json[:eac_cpf]["cpfDescription"]["description"]["existDates"]["dateRange"] - residence = parsed_xml_to_json[:eac_cpf]["cpfDescription"]["description"]["place"]["placeEntry"] - elsif entityType == "person" - creator_type = "P" - event_start = parsed_xml_to_json[:eac_cpf]["cpfDescription"]["description"]["existDates"][0] - event_end = parsed_xml_to_json[:eac_cpf]["cpfDescription"]["description"]["existDates"][1] - residence = nil - elsif entityType == "family" - creator_type = "F" - event_start = parsed_xml_to_json[:eac_cpf]["cpfDescription"]["description"]["existDates"][0] - event_end = parsed_xml_to_json[:eac_cpf]["cpfDescription"]["description"]["existDates"][1] - residence = nil - end - history = parsed_xml_to_json[:eac_cpf]["cpfDescription"]["description"]["biogHist"].present? ? parsed_xml_to_json[:eac_cpf]["cpfDescription"]["description"]["biogHist"]["abstract"] : nil - - creator = {'creator' => { - 'creator_type'=> creator_type, - 'creator_corporate_type_id'=> nil, - 'residence'=> residence, - 'abstract'=> '', - 'history'=> history, - 'legal_status'=> nil, - 'note'=> '', - 'legacy_id'=> creator_leg_id, - 'published'=> true - } - } - File.open(TMP_IMPORTS + "/data.json","a") do |f| - f.write(creator.to_json) - f.write("\r\n") - end - - rel_creator_event(event_start, event_end, creator_leg_id) - - if parsed_xml_to_json[:eac_cpf]["cpfDescription"]["identity"]["nameEntry"].present? - if parsed_xml_to_json[:eac_cpf]["cpfDescription"]["identity"]["nameEntry"].kind_of?(Array) - size = parsed_xml_to_json[:eac_cpf]["cpfDescription"]["identity"]["nameEntry"].length - nums = 0 - begin - creator_name = parsed_xml_to_json[:eac_cpf]["cpfDescription"]["identity"]["nameEntry"][nums]["part"] - preferred = true - qualifier = "A" - if nums > 0 - preferred = false - qualifier = "OT" - end - rel_creator_name(creator_name, creator_leg_id, preferred, qualifier) - nums += 1 - end while size > nums + if fond_root.xpath('c').present? + Rails.logger.info "Importazione figli del fondo di livelli successivi al primo." + fond_root.xpath('c').each do |subfond| + if fond_types.include? subfond.xpath("@level").text + fond_just_saved = Fond.find (import_fond_from_path subfond, user_id, group_id).id + fond_just_saved.ancestry = ancestry + fond_just_saved.ancestry_depth = ancestry.split('/').size + fond_just_saved.sneaky_update + + eredita_compilatori(fond_just_saved.id, ancestry) + + import_fond_hierarchy subfond, user_id, group_id, (ancestry + '/' + fond_just_saved.id.to_s) else - creator_name = parsed_xml_to_json[:eac_cpf]["cpfDescription"]["identity"]["nameEntry"]["part"] - preferred = true - qualifier = "A" - rel_creator_name(creator_name, creator_leg_id, preferred,qualifier) + import_unit_hierarchy subfond, ancestry.split('/').first.to_i, ancestry.split('/').last.to_i, user_id, group_id, nil end - end - - if parsed_xml_to_json[:eac_cpf]["control"]["maintenanceHistory"]["maintenanceEvent"].kind_of?(Array) - length_editor = parsed_xml_to_json[:eac_cpf]["control"]["maintenanceHistory"]["maintenanceEvent"].length - num = 0 - begin - creator_editor = parsed_xml_to_json[:eac_cpf]["control"]["maintenanceHistory"]["maintenanceEvent"][num] - rel_creator_editor(creator_editor, creator_leg_id) - num +=1 - end while length_editor > num - else - creator_editor = parsed_xml_to_json[:eac_cpf]["control"]["maintenanceHistory"]["maintenanceEvent"] - rel_creator_editor(creator_editor, creator_leg_id) end + end end end - def rel_creator_editor(rel_c, creator_id) + # dato un generico path xml importa i dati del complesso: + # sara' /archdesc per il complesso principale e /c per tutti i figli. + def import_fond_from_path path, user_id, group_id + Rails.logger.info "import_fond_from_path" + datetime = Time.now.strftime("%Y-%m-%d %H:%M:%S") + + fond = Fond.new + otherlevel_from_path = "" + level_from_path = path.xpath("@level").text + level = level_from_path + if level_from_path == "otherlevel" + otherlevel_from_path = path.xpath("@otherlevel").text + level = otherlevel_from_path + end + fond.fond_type = import_level_type(level) - creator_editor = {'creator_editor' => { - 'creator_id'=> creator_id, - 'name'=> rel_c["agent"], - 'qualifier'=> nil, - 'editing_type'=> rel_c["eventType"], - 'edited_at'=> rel_c["eventDateTime"], - 'legacy_id'=> creator_id - } - } + if level_from_path == "otherlevel" + if otherlevel_from_path == "" + Rails.logger.warn "Fondo con @level = otherlevel, descrizione @otherlevel non indicata (campo obbligatorio)" + else + Rails.logger.info "Fondo con @level = #{level_from_path}, @otherlevel = #{otherlevel_from_path}, fond_type: #{fond.fond_type}" + end + else + if level_from_path == "" + Rails.logger.warn "Livello di descrizione del fondo non indicato (campo obbligatorio)" + else + Rails.logger.info "Fondo con @level = #{level_from_path}, fond_type: #{fond.fond_type}" + end + end - File.open(TMP_IMPORTS + "/data.json","a") do |f| - f.write(creator_editor.to_json) - f.write("\r\n") - end + path.xpath("did/unittitle").each do |title| + if title.xpath('@localtype').text.downcase == "denominazione" + fond.name = title.text + end + end - end + # verra' utilizzato per ricostruire le relazioni presenti nel file icar-import se non presente dovra` + # dare un'eccezione - def rel_creator_name(rel_c, creator_id, preferred, qualifier) - creator_name = {'creator_name' => { - 'creator_id'=> creator_id, - 'preferred'=> preferred, - 'name'=> rel_c, - 'first_name'=> nil, - 'last_name'=> nil, - 'qualifier'=> qualifier, - 'patronymic'=> nil, - 'nickname'=> nil, - 'legacy_id'=> creator_id - } - } - File.open(TMP_IMPORTS + "/data.json","a") do |f| - f.write(creator_name.to_json) - f.write("\r\n") - end - end + fond.legacy_id = path.xpath("did/unitid").text.squish - def rel_creator_event(event_start, event_end, creator_id) - - if(event_start["fromDate"] != nil) - st_date = event_start["fromDate"] - start_date_from = st_date + '-01-01' - start_date_to = st_date + '-12-31' - start_date_display = st_date - start_date_format = 'Y' - elsif(event_start["date"] != nil) - st_date = event_start["date"] - start_date_from = nil - start_date_to = nil - start_date_display = st_date - start_date_format = 'YMD' - elsif(event_start["dateRange"]["fromDate"] != nil) - st_date = event_start["dateRange"]["fromDate"] - start_date_from = nil - start_date_to = nil - start_date_display = st_date - start_date_format = 'C' + fond.db_source = self.identifier + fond.created_by = user_id + fond.updated_by = user_id + fond.group_id = group_id + fond.created_at = datetime + fond.updated_at = datetime + + 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 + if terms.include? condition.downcase + fond.access_condition = condition.downcase + else + fond.access_condition_note = condition.downcase + end end - - if(event_end["fromDate"] != nil) - end_date = event_start["fromDate"] - end_date_from = end_date + '-01-01' - end_date_to = end_date + '-12-31' - end_date_display = end_date - end_date_format = 'Y' - elsif(event_end["date"] != nil) - end_date = event_start["date"] - end_date_from = nil - end_date_to = nil - end_date_display = end_date - end_date_format = 'YMD' - elsif(event_end["dateRange"]["fromDate"] != nil) - end_date = event_start["dateRange"]["fromDate"] - end_date_from = nil - end_date_to = nil - end_date_display = end_date - end_date_format = 'C' - end - - creator_event = {'creator_event' => { - 'creator_id'=> creator_id, - 'preferred'=> true, - 'is_valid'=> true, - 'start_date_place'=> nil, - 'start_date_spec'=> 'idem', - 'start_date_from'=> start_date_from, - 'start_date_to'=> start_date_to, - 'start_date_valid'=> 'C', - 'start_date_format'=> start_date_format, - 'start_date_display'=> start_date_display, - 'end_date_place'=> nil, - 'end_date_spec'=> 'idem', - 'end_date_from'=> end_date_from, - 'end_date_to'=> end_date_to, - 'end_date_valid'=> 'C', - 'end_date_format'=> end_date_format, - 'end_date_display'=> end_date_display, - 'legacy_display_date'=> nil, - 'order_date'=> nil, - 'note'=> '', - 'legacy_id'=> creator_id - } - } - File.open(TMP_IMPORTS + "/data.json","a") do |file| - file.write(creator_event.to_json) - file.write("\r\n") - end - end - def fond_custodian_relation(custodian_id) - rel_custodian_fond = {'rel_custodian_fond' => { - 'legacy_custodian_id'=> custodian_id, - 'legacy_fond_id'=> @fond_leg_id - } - } - File.open(TMP_IMPORTS + "/data.json","a") do |f| - f.write(rel_custodian_fond.to_json) - f.write("\r\n") - end - end + fond.published = false + if path.xpath("processinfo/p").text.downcase == "pubblicata" + fond.published = true + end - def extract_custodian(zip_data_file) - xml = File.open(zip_data_file).read - json = Hash.from_xml(xml).to_json - parsed_xml_to_json = ActiveSupport::JSON.decode(json) - custodian_leg_id = rand(1..1000) - fond_custodian_relation(custodian_leg_id) - c_id = CustodianType.where("custodian_type like (?)", parsed_xml_to_json["scons"]["tipologia"]).first.id - - custodian = {'custodian' => { - 'custodian_type_id'=> c_id, - 'legal_status'=> nil, - 'owner'=> nil, - 'contact_person'=> '', - 'history'=> parsed_xml_to_json["scons"]["descrizione"], - 'administrative_structure'=> nil, - 'collecting_policies'=> nil, - 'holdings'=> nil, - 'accessibility'=> nil, - 'services'=> nil, - 'legacy_id'=> custodian_leg_id, - 'published'=> true - } - } - File.open(TMP_IMPORTS + "/data.json","a") do |f| - f.write(custodian.to_json) - f.write("\r\n") - end - - custodian_name = parsed_xml_to_json["scons"]["formaautorizzata"] - rel_custodian_name(custodian_name, custodian_leg_id) - - if parsed_xml_to_json["scons"]["info"]["evento"].kind_of?(Array) - length_editor = parsed_xml_to_json["scons"]["info"]["evento"].length - num = 0 - begin - custodian_editor = parsed_xml_to_json["scons"]["info"]["evento"][num] - rel_custodian_editor(custodian_editor, custodian_leg_id) - num +=1 - end while length_editor > num + fond.history = path.xpath("custodhist/p").text.squish + + fond.extent = path.xpath("did/physdesc").text.squish + + path.xpath("did/physdescstructured").each do |pd| + quantity = pd.xpath("quantity").text.squish + unit_type = pd.xpath("unittype").text.squish + + if unit_type == "metri lineari" + begin + fond.length = Float(quantity) + rescue + Rails.logger.info "ead/did/physdescstructured/quantity NON numerico" + end + else + if fond.extent != "" + fond.extent += "\n" + end + fond.extent += quantity + " " + unit_type + end + end + + if path.xpath("did/physloc").present? + Rails.logger.info "Fondo: #{fond.name.squish} - Trovato ma non importato il tag 'ead/did/physloc': #{path.xpath("did/physloc").text.squish}" + end + + if path.xpath("did/didnote").present? + Rails.logger.info "Fondo: #{fond.name.squish} - Trovato ma non importato il tag 'ead/did/didnote': #{path.xpath("did/didnote").text.squish}" + end + + if path.xpath("acqinfo").present? + Rails.logger.info "Fondo: #{fond.name.squish} - Trovato ma non importato il tag 'ead/acqinfo': #{path.xpath("acqinfo").text.squish}" + end + + if path.xpath("separatedmaterial").present? + Rails.logger.info "Fondo: #{fond.name.squish} - Trovato ma non importato il tag 'ead/separatedmaterial': #{path.xpath("separatedmaterial").text.squish}" + end + + if path.xpath("bibliography").present? + 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.arrangement_note = "" + if path.xpath("arrangement/p").present? + fond.arrangement_note += "Criteri di ordinamento: " + path.xpath("arrangement/p").text.squish + "\n" + end + + fond.sneaky_save! + + self.importable_id = fond.id + + if path.xpath("processinfo/processinfo/p").present? + path.xpath("processinfo[@localtype='compilatori']/processinfo[@localtype='compilatore']").each do |pi| + editor = FondEditor.new + editor.fond_id = fond.id + editor.name = pi.xpath("p/persname/part[@localtype='compilatore']").text + editor.qualifier = pi.xpath("p/persname/part[@localtype='qualifica']").text + tipo_intervento = pi.xpath("p/persname/part[@localtype='tipoIntervento']").text + if tipo_intervento == "inserimento" || tipo_intervento == "created" + editor.editing_type = "inserimento dati" + elsif tipo_intervento == "modifica" || tipo_intervento == "updated" + editor.editing_type = "aggiornamento scheda" + end + if pi.xpath("p/date").text.present? + editor.edited_at = Date.parse pi.xpath("p/date").text + end + editor.save! + end else - custodian_editor = parsed_xml_to_json["scons"]["info"]["evento"] - rel_custodian_editor(custodian_editor, custodian_leg_id) + if path.xpath("../control/maintenancehistory/maintenanceevent").present? + path.xpath("../control/maintenancehistory/maintenanceevent").each do |maintenance_event| + editor = FondEditor.new + editor.fond_id = fond.id + editor.name = maintenance_event.xpath("agent").text.squish + editor.editing_type = import_editing_type(maintenance_event.xpath("eventtype/@value").text) + if maintenance_event.xpath("eventdatetime").present? + editor.edited_at = maintenance_event.xpath("eventdatetime").text.squish + end + editor.qualifier = import_agent_type(maintenance_event.xpath("agenttype/@value").text) + editor.db_source = self.identifier + editor.save + end + end end - - end - def rel_custodian_editor(rel_c, cust_id) + if path.xpath("controlaccess/genreform").present? + 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 + 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 + rel__f_d.save! + else + puts("Nessun DocumentForm trovato con il nome inserito. Non e' stato aggiunto alcun record del tipo 'RelFondDocumentForm'") + end + end + end + + #altre denominazioni + path.xpath("did/unittitle").each do |unittitle| + if (unittitle.text != fond.name) + fond_name = FondName.new + fond_name.fond_id = fond.id + fond_name.name = unittitle.text + fond_name.created_at = datetime + fond_name.updated_at = datetime + fond_name.qualifier = "O" + if unittitle.xpath("@localtype").text == "denominazioneParallela" + fond_name.note = "Denominazione parallela;" + end + if unittitle.xpath("@lang").text.present? + fond_name.note += " Codice lingua: " + unittitle.xpath("@lang").text + end + + fond_name.save! + end + end + + if path.xpath("did/unitdatestructured/dateset").present? + event = FondEvent.new + event.fond_id = fond.id + import_dateset(path.xpath("did/unitdatestructured/dateset").first, event, datetime) + end + + if path.xpath("did/unitdatestructured/daterange").present? + event = FondEvent.new + event.fond_id = fond.id + import_dateset(path.xpath("did/unitdatestructured").first, event, datetime) + end + + # Salvataggio delle informazioni riguardanti le relazioni in campi "di fortuna". + #if path.xpath("relations/relation").present? && !@is_icar_import + # if !fond.related_materials.present? + # fond.related_materials = "" + # end + # path.xpath("relations/relation").each do |relation| + # fond.related_materials += + # "relation: {\n + # @relationtype: #{relation.xpath("@relationtype").text};\n + # @href: #{relation.xpath("@href").text};\n + # relationentry: #{relation.xpath("relationentry").text};\n + # relationentry/@localtype: #{relation.xpath("relationentry/@localtype").text}; + # \n}\n" + # end + #end + + # Import per il campo Archimista: Fondo > Altre informazioni > Documentazione collegata + if path.xpath("relatedmaterials/archref/ref").present? + if !fond.related_materials.present? + fond.related_materials = "" + end + fond.related_materials += path.xpath("relatedmaterials/archref/ref").text.squish + end + + source = path.xpath("did/unitid") + if source.xpath("@identifier").present? + fond_identifier = FondIdentifier.new + fond_identifier.fond_id = fond.id + fond_identifier.identifier = source.xpath("@identifier").text + #fond_identifier.identifier_source = source.xpath("@localtype").text + fond_identifier.db_source = self.identifier + fond_identifier.note = "Identificativo di sistema" + fond_identifier.save + end + + # Produttori: + #if path.xpath("did/origination/corpname").present? + # path.xpath("did/origination/corpname").each do |source| + # fond_identifier = FondIdentifier.new + # fond_identifier.fond_id = fond.id + # fond_identifier.identifier = source.xpath("@identifier").text + # fond_identifier.identifier_source = "" + # fond_identifier.db_source = self.identifier + # fond_identifier.note = source.xpath("part").text + # fond_identifier.save + # end + #end + #if path.xpath("did/origination/persname").present? + # path.xpath("did/origination/persname").each do |source| + # fond_identifier = FondIdentifier.new + # fond_identifier.fond_id = fond.id + # fond_identifier.identifier = source.xpath("@identifier").text + # fond_identifier.identifier_source = "" + # fond_identifier.db_source = self.identifier + # fond_identifier.note = source.xpath("part").text + # fond_identifier.save + # end + #end + #if path.xpath("did/origination/famname").present? + # path.xpath("did/origination/famname").each do |source| + # fond_identifier = FondIdentifier.new + # fond_identifier.fond_id = fond.id + # fond_identifier.identifier = source.xpath("@identifier").text + # fond_identifier.identifier_source = "" + # fond_identifier.db_source = self.identifier + # fond_identifier.note = source.xpath("part").text + # fond_identifier.save + # end + #end + + def create_rel_creator_fond_from_origination(path, fond_id, fond_legacy_id, datetime) + if path.xpath("@identifier").present? + creator_legacy_id = path.xpath("@identifier").text + creator_ids = Creator.where(legacy_id: creator_legacy_id).ids + if creator_ids.present? + rel_creator_fond = RelCreatorFond.new + rel_creator_fond.creator_id = creator_ids.first + rel_creator_fond.fond_id = fond_id + rel_creator_fond.db_source = self.identifier + rel_creator_fond.legacy_creator_id = creator_legacy_id + rel_creator_fond.legacy_fond_id = fond_legacy_id + rel_creator_fond.created_at = datetime + rel_creator_fond.updated_at = datetime + rel_creator_fond.save! + end + end + end + + if path.xpath("did/origination").present? + path.xpath("did/origination/persname").each do |creator_name| + create_rel_creator_fond_from_origination(creator_name, fond.id, fond.legacy_id, datetime) + end + path.xpath("did/origination/corpname").each do |creator_name| + create_rel_creator_fond_from_origination(creator_name, fond.id, fond.legacy_id, datetime) + end + path.xpath("did/origination/famname").each do |creator_name| + create_rel_creator_fond_from_origination(creator_name, fond.id, fond.legacy_id, datetime) + end + end + + if path.xpath("relations/relation").present? + path.xpath("relations/relation").each do |relation| + if relation.xpath("@relationtype").text == "resourcerelation" + rel_fond_source = RelFondSource.new + source = Source.find_by(db_source: self.identifier, legacy_id: relation.xpath("@href").text) + if source.present? + Rails.logger.info "Risorsa fonte trovata '#{source.short_title}'" + rel_fond_source.fond_id = fond.id + rel_fond_source.source_id = source.id + rel_fond_source.db_source = self.identifier + rel_fond_source.legacy_source_id = source.legacy_id + rel_fond_source.legacy_fond_id = fond.legacy_id + rel_fond_source.save + + source_id = source.id + source_legacy_id = source.legacy_id + + Rails.logger.info "Relazione (legacy) Fonte #{rel_fond_source.legacy_source_id} -> Complesso #{rel_fond_source.legacy_fond_id} ricostruita." + else + Rails.logger.info "Risorsa fonte NON trovata '#{relation.xpath("@href").text}'" + source_new = Source.new + source_new.created_by = user_id + source_new.updated_by = user_id + source_new.group_id = group_id + source_new.created_at = datetime + source_new.updated_at = datetime + source_new.db_source = self.identifier + source_new.legacy_id = fond.legacy_id + if relation.xpath("relationentry/@localtype").text == "strumentoRicercaInterno" + source_new.source_type_code = 2 # strumento di corredo + else + source_new.source_type_code = 3 # fonte archivistica + end + title = relation.xpath("relationentry").text.squish + source_new.title = title + source_new.short_title = title.truncate(50, separator: /\s/) + if Source.where("short_title = '#{source_new.short_title.gsub(/'/, "''")}'").present? + source_new.sneaky_save + source_new.short_title << " - #{source_new.id.to_s}" + end + source_new.save! + + source_id = source_new.id + source_legacy_id = source_new.legacy_id + + fonte_url = relation.xpath("@href").text + if fonte_url.present? && fonte_url != "" + source_url = SourceUrl.new + source_url.url = fonte_url + source_url.source_id = source_new.id + source_url.save! + end + + Rails.logger.info "Risorsa fonte creata '#{source_new.title}'" + end + + rel_fond_source.fond_id = fond.id + rel_fond_source.source_id = source_id + rel_fond_source.db_source = self.identifier + rel_fond_source.legacy_source_id = source_legacy_id + rel_fond_source.legacy_fond_id = fond.legacy_id + rel_fond_source.save + + Rails.logger.info "Relazione (legacy) Fonte #{rel_fond_source.legacy_source_id} -> Complesso #{rel_fond_source.legacy_fond_id} ricostruita." + end + + if relation.xpath("@relationtype").text == "otherrelationtype" + tipo = relation.xpath("@otherrelationtype").text + title = relation.xpath("relationentry").text.squish + + if tipo == "BIBTEXT" || tipo == "BIBSBN" || tipo == "FONTETEXT" || tipo == "FONTEURI" + if tipo == "BIBSBN" || tipo == "FONTEURI" + fonte_url = relation.xpath("@href").text + if fonte_url.present? && fonte_url != "" + link = FondUrl .new + link.db_source = self.identifier + link.fond_id = fond.id + link.url = fonte_url + link.save + end + end + + if title.present? && title != "" + source_by_title = Source.find_by_title(title) + if source_by_title.nil? + source = Source.new + source.created_by = user_id + source.updated_by = user_id + source.group_id = group_id + source.created_at = datetime + source.updated_at = datetime + source.db_source = self.identifier + source.legacy_id = fond.legacy_id + if tipo == "BIBTEXT" || tipo == "BIBSBN" + source.source_type_code = 1 # bibliografia + elsif tipo == "FONTETEXT" || tipo == "FONTEURI" + source.source_type_code = 3 # fonte archivistica + end + source.title = title + source.short_title = title.truncate(50, separator: /\s/) + if Source.where("short_title = '#{source.short_title.gsub(/'/, "''")}'").present? + source.sneaky_save + source.short_title << " - #{source.id.to_s}" + end + source.save! + if tipo == "BIBSBN" || tipo == "FONTEURI" + fonte_url = relation.xpath("@href").text + if fonte_url.present? && fonte_url != "" + source_url = SourceUrl.new + source_url.url = fonte_url + source_url.source_id = source.id + source_url.save! + end + end + source_id = source.id + else + source_id = source_by_title.id + end + rel_fond_source = RelFondSource.new + rel_fond_source.fond_id = fond.id + rel_fond_source.source_id = source_id + rel_fond_source.save! + end + end + end + end + end + + + Rails.logger.info "Salvataggio complesso importato da import.rb > import_fond_from_path" + fond.save + Rails.logger.info "Salvataggio complesso COMPLETATO da import.rb > import_fond_from_path" + return fond + end + + #Per importare le informazioni presenti nella sezione "control" presente solo per il fondo di root + #path: xpath("ead/control") + def import_fond_control_field(path, fond_id) + if path.xpath("sources").present? + path.xpath("sources/source").each do |source| + fond_identifier = FondIdentifier.new + fond_identifier.fond_id = fond_id + fond_identifier.identifier = source.xpath("@id").text + fond_identifier.identifier_source = source.xpath("@href").text + fond_identifier.note = source.xpath("sourceentry").text + fond_identifier.save + end + end + end + + def import_icar_import(document, user_id, group_id) + @is_icar_import = true + + # 0) import schede anagrafiche: + document.xpath("//icar-import/listRecords/record/recordBody/eac-cpf").each do |anagraphic_root| + if anagraphic_root.xpath("cpfDescription/identity/entityType").present? + if anagraphic_root.xpath("cpfDescription/identity/entityType").text == "person" && + anagraphic_root.xpath("cpfDescription/identity/entityId/@localType").present? + returned_bundle = import_anagraphic anagraphic_root.xpath(".."), user_id, group_id + end + end + end + + # 5) import fonti relative ai vari complessi: + document.xpath("//icar-import/listRecords/record/recordBody/ead").each do |document_source_root| + if ((document_source_root.xpath("archdesc/did/*").size == 1) && + (document_source_root.xpath("archdesc/did/unittitle").text == "") && + !document_source_root.xpath("boolean(archdesc/dsc)")) + returned_bundle = import_source document_source_root.xpath(".."), user_id, group_id + + #returned_bundle[:legacy_fond_ids].each do |legacy_fond_id| + # rel_fond_source = RelFondSource.new + # fond = Fond.where(db_source: self.identifier, legacy_id: legacy_fond_id) + # if fond.present? + # rel_fond_source.fond_id = fond.first.id + # rel_fond_source.source_id = returned_bundle[:source_id] + # rel_fond_source.db_source = self.identifier + # rel_fond_source.legacy_source_id = Source.find(rel_fond_source.source_id).legacy_id + # rel_fond_source.legacy_fond_id = legacy_fond_id + # rel_fond_source.save + # Rails.logger.info "Relazione (legacy) Fonte #{rel_fond_source.legacy_source_id} -> Complesso #{rel_fond_source.legacy_fond_id} ricostruita." + # end + #end + + end + end + + # import produttori e creazione relaazioni con i complessi/fondi + document.xpath("//icar-import/listRecords/record/recordBody/eac-cpf").each do |creator_root| + if creator_root.xpath('cpfDescription/identity/@localType').text == 'soggettoProduttore' + returned_bundle = import_creator creator_root.xpath(".."), user_id, group_id + returned_bundle[:legacy_fond_ids].each do |legacy_fond_id| + rel_creator_fond = RelCreatorFond.new + rel_creator_fond.creator_id = returned_bundle[:creator_id] + fond = Fond.where(db_source: self.identifier, legacy_id: legacy_fond_id) + if fond.present? + rel_creator_fond.fond_id = fond.first.id + rel_creator_fond.db_source = self.identifier + rel_creator_fond.legacy_creator_id = Creator.find(rel_creator_fond.creator_id).legacy_id + rel_creator_fond.legacy_fond_id = legacy_fond_id + rel_creator_fond.save + Rails.logger.info "Relazione (legacy) Produttore #{rel_creator_fond.legacy_creator_id} -> Fondo #{legacy_fond_id} ricostruita." + end + end + end + end + + # 1.a) import complesso principale e relativi figli + # 1.b) import unita' relative ai complessi e relazione unita`-scheda anagrafica: + root_fond_id = nil + _document_fond_root = document.xpath("//icar-import/listRecords/record/recordBody/ead/archdesc") + _document_fond_root.each do |document_fond_root| + if ((document_fond_root.xpath("did/*").size == 1) && (document_fond_root.xpath("did/unittitle").text == "") && + !document_fond_root.xpath("boolean(dsc)")) + Rails.logger.info "Trovata fonte anziche` complesso" + else + root_fond_id = import_fond_hierarchy document_fond_root, user_id, group_id, "" + fonds_to_upload = Fond.where(db_source: self.identifier) + fonds_to_upload.each do |fond| + fond.units_count = fond.units.count + fond.sneaky_update + end + end + end + + # 1.c) import oggetti digitali relativi alle unita': + + # 2) import conservatori relativi al SOLO complesso principale: + document.xpath("//icar-import/listRecords/record/recordBody/scons").each do |custodian_root| + rel_custodian_fond = RelCustodianFond.new + rel_custodian_fond.custodian_id = (import_custodian custodian_root.xpath(".."), user_id, group_id)[:custodian_id] + rel_custodian_fond.fond_id = root_fond_id + rel_custodian_fond.db_source = self.identifier + rel_custodian_fond.legacy_custodian_id = Custodian.find(rel_custodian_fond.custodian_id).legacy_id + rel_custodian_fond.legacy_fond_id = Fond.find(root_fond_id).legacy_id + rel_custodian_fond.save + Rails.logger.info "Relazione (legacy) Conservatore #{rel_custodian_fond.legacy_custodian_id} -> Fondo #{rel_custodian_fond.legacy_fond_id} ricostruita." + end + + # 4) import profili istituzionali relativi ai produttori: + document.xpath("//icar-import/listRecords/record/recordBody/eac-cpf").each do |institution_root| + if institution_root.xpath('cpfDescription/identity/@localType') && institution_root.xpath('cpfDescription/identity/@localType').text == 'profiloIstituzionale' + returned_bundle = import_institution institution_root.xpath(".."), user_id, group_id + returned_bundle[:legacy_creator_ids].each do |legacy_creator_id| + rel_creator_institution = RelCreatorInstitution.new + creator = Creator.where(db_source: self.identifier, legacy_id: legacy_creator_id) + if creator.present? + rel_creator_institution.institution_id = returned_bundle[:institution_id] + rel_creator_institution.creator_id = creator.first.id + rel_creator_institution.db_source = self.identifier + rel_creator_institution.legacy_creator_id = legacy_creator_id + rel_creator_institution.legacy_institution_id = Institution.find(rel_creator_institution.institution_id).legacy_id + rel_creator_institution.save + Rails.logger.info "Relazione (legacy) Produttore #{rel_creator_institution.legacy_creator_id} -> Profilo istituzionale #{rel_creator_institution.legacy_institution_id} ricostruita." + end + end + end + end + + self.importable_id = root_fond_id + Rails.logger.info "ICAR-IMPORT relativo al complesso #{root_fond_id} completato -> Inizio salvataggio import " + end + + #import profilo istituzionale + #document Nokogiri::XML + #user_id utente che effettua l'import + #group_id gruppo dell'utente che effettua l'import + def import_institution(document, user_id, group_id) + institution = Institution.new + if document.xpath("eac-cpf/cpfDescription/identity/nameEntry/part").present? + institution.name = document.xpath("eac-cpf/cpfDescription/identity/nameEntry/part").first.text #denominazione + elsif document.xpath("eac-cpf/cpfDescription/identity/nameEntryParallel/nameEntry/part").present? + institution.name = document.xpath("eac-cpf/cpfDescription/identity/nameEntryParallel/nameEntry/part").first.text #denominazione + end + if document.xpath("eac-cpf/cpfDescription/description/biogHist/p").present? + institution.description = document.xpath("eac-cpf/cpfDescription/description/biogHist/p").first.text.squish #descrizione + end + + document.xpath("eac-cpf/cpfDescription/identity/nameEntryParallel/nameEntry").each do |nameEntry| + attr_name = nameEntry.xpath("name(@*)").squish + attr_value = nameEntry.xpath("@*").text.squish + if (attr_name.include? "lang") && (attr_value != "ita") + institution_description = institution.description.nil? ? "" : (institution.description + "\n") + institution.description = institution_description + "Denominazione parallela: " + nameEntry.xpath("part").text.squish + " [codice lingua: #{attr_value}]" + end + end + + document.xpath("eac-cpf/cpfDescription/description/localDescription").each do |localDescription| + if localDescription.xpath("@localType").text == "tipologiaEnte" + term = localDescription.xpath("term") + if term.present? && term.xpath("@vocabularySource").text == "http://dati.san.beniculturali.it/SAN/TesauroSAN/sottotipologia_ente" + institution_description = institution.description.nil? ? "" : (institution.description + "\n") + institution.description = institution_description + "Tipologia ente: " + term.text.squish + end + end + end + + document.xpath("eac-cpf/cpfDescription/description/legalStatuses").each do |legalStatuses| + term = legalStatuses.xpath("legalStatus/term") + if term.present? + institution_description = institution.description.nil? ? "" : (institution.description + "\n") + institution.description = institution_description + "Condizione giuridica: " + term.text.squish + end + end + + date_range = document.xpath("eac-cpf/cpfDescription/description/existDates/dateRange") + if date_range.present? && date_range.xpath("@localType").text == "data di esistenza" + exist_date = "-" + from_Date = date_range.xpath("fromDate") + to_Date = date_range.xpath("toDate") + if from_Date.present? + exist_date = from_Date.text.squish + exist_date + end + if to_Date.present? + exist_date = exist_date + to_Date.text.squish + end + if exist_date != "-" + institution_description = institution.description.nil? ? "" : (institution.description + "\n") + institution.description = institution_description + "Date di esistenza: " + exist_date + end + end + + # vale per: Sede, Giurisdizione, Ambito territoriale e altri tag place con figli placeRole e placeEntry presenti + document.xpath("eac-cpf/cpfDescription/description/place").each do |place| + placeRole = place.xpath("placeRole") + placeEntry = place.xpath("placeEntry") + if placeRole.present? && placeEntry.present? + institution_description = institution.description.nil? ? "" : (institution.description + "\n") + institution.description = institution_description + placeRole.text.squish.capitalize + ": " + placeEntry.text.squish + end + end + + document.xpath("eac-cpf/cpfDescription/relations").each do |relations| + # Profilo istituzionale associato + cpf_relation = relations.xpath("cpfRelation") + if cpf_relation.present? && cpf_relation.xpath("@cpfRelationType").text == "associative" + relation_entry = cpf_relation.xpath("relationEntry") + if relation_entry.present? && relation_entry.xpath("@localType").text == "profiloIstituzionale" + institution_description = institution.description.nil? ? "" : (institution.description + "\n") + institution.description = institution_description + "Profilo istituzionale associato: " + relation_entry.text.squish + end + end + + # Contesto Storico istituzionale e Ambito territoriale + relations.xpath("resourceRelation").each do |resourceRelation| + if resourceRelation.xpath("@resourceRelationType").text == "other" + relation_entry = resourceRelation.xpath("relationEntry") + if relation_entry.present? + case relation_entry.xpath("@localType").text + when "ambitoTerritoriale" + label = "Ambito territoriale: " + value = relation_entry.text.squish + institution_description = institution.description.nil? ? "" : (institution.description + "\n") + institution.description = institution_description + label + value + when "contestoStoricoIstituzionale" + label = "Contesto storico istituzionale: " + value = relation_entry.text.squish + institution_description = institution.description.nil? ? "" : (institution.description + "\n") + institution.description = institution_description + label + value + end + end + end + end + end + + institution.legacy_id = document.xpath("eac-cpf/control/recordId").text + institution.note = "" + institution.created_by = user_id + institution.updated_by = user_id + institution.group_id = group_id + institution.db_source = self.identifier + institution.save! + + self.importable_id = institution.id + + #compilatori + datetime = Time.now.strftime("%Y-%m-%d %H:%M:%S") + document.xpath("eac-cpf/control/maintenanceHistory/maintenanceEvent").each do |editor| + event_type = editor.xpath("eventType").first.text + event_datetime = "" + if editor.xpath("eventDateTime").present? + if editor.xpath("eventDateTime/@standardDateTime").present? + event_datetime = editor.xpath("eventDateTime/@standardDateTime").first.text + else + event_datetime = editor.xpath("eventDateTime").first.text + end + + end + agent_type = import_agent_type(editor.xpath("agentType").first.text) + agent = editor.xpath("agent").first.text + event_description_present = editor.xpath("boolean(eventDescription)") + + if ((event_type == "created") && (event_datetime == "") && (agent_type == "human") && (agent == "") && !event_description_present) + #ogni entità ha un evento di compilazione di default di questo tipo + # + # created + # + # human + # + # + #nell'import è ignorato + next + else + institution_editor = InstitutionEditor.new + institution_editor.institution_id = institution.id + institution_editor.name = agent + institution_editor.editing_type = import_editing_type(event_type) + institution_editor.qualifier = agent_type + if !event_datetime.empty? + institution_editor.edited_at = Date.parse(event_datetime) + end + institution_editor.created_at = datetime + institution_editor.updated_at = datetime + if event_description_present + institution_editor.qualifier = editor.xpath("eventDescription").first.text + end + institution_editor.save! + end + end + return_bundle = {institution_id: institution.id, legacy_creator_ids: Array.new} + # ripristina eventuali relazioni con dei produttori + if document.xpath("eac-cpf/cpfDescription/relations/cpfRelation/relationEntry[@localType='soggettoProduttore']").present? + Rails.logger.info "Associazione profilo istituzionale #{institution.id} al produttore" + document.xpath("eac-cpf/cpfDescription/relations/cpfRelation/relationEntry[@localType='soggettoProduttore']").each do |related_creator| + return_bundle[:legacy_creator_ids].push related_creator.text + Rails.logger.info "Associazione produttore con legacy_id #{related_creator.text}" + end + end + return return_bundle + end + + #import soggetto produttore + #document Nokogiri::XML + #user_id utente che effettua l'import + #group_id gruppo dell'utente che effettua l'import + def import_creator(document, user_id, group_id) + datetime = Time.now.strftime("%Y-%m-%d %H:%M:%S") + + creator = Creator.new + + localType = document.xpath("eac-cpf/cpfDescription/identity/entityType").first.text + if (localType == "corporateBody") + creator.creator_type = "C" #tipologia + + corporate_type = "" + if document.xpath("eac-cpf/cpfDescription/description/localDescription/term").present? + description = document.xpath("eac-cpf/cpfDescription/description/localDescription/term").first.text + case description + when "TesauroSAN/opera_pia-istituzione_ed_ente_assistenza_e_beneficenza_ospedale" + corporate_type = "ente di assistenza e beneficenza" + when "TesauroSAN/banca-istituto_di_credito-ente_assicurativo-ente_previdenziale" + corporate_type = "ente di credito, assicurativo, previdenziale" + when "TesauroSAN/accademia_ente_di_cultura" + corporate_type = "ente di cultura, ricreativo, sportivo, turistico" + when "TesauroSAN/ente_ricreativo-sportivo-turistico_sp" + corporate_type = "ente di cultura, ricreativo, sportivo, turistico" + when "TesauroSAN/scuola-ente_di_istruzione" + corporate_type = "ente di istruzione e ricerca" + when "TesauroSAN/universita-ente_di_ricerca" + corporate_type = "ente di istruzione e ricerca" + when "TesauroSAN/ente_culto_cattolico-associazione_cattolica" + corporate_type = "ente e associazione della chiesa cattolica" + when "TesauroSAN/ente_di_culto_acattolico-associazione_acattolica" + corporate_type = "ente e associazione di culto acattolico" + when "TesauroSAN/corporazione_religiosa" + corporate_type = "ente ecclesiastico" + when "TesauroSAN/ente_economico-impresa-studio_professionale_sp" + corporate_type = "ente economico / impresa" + #when "TesauroSAN/ente_territoriale_minore" + #corporate_type = "ente funzionale territoriale" + when "TesauroSAN/ente_territoriale_minore" + corporate_type = "ente pubblico territoriale" + when "TesauroSAN/ente_sanitario-ente_servizi_alla_persona" + corporate_type = "ente sanitario" + when "TesauroSAN/arte_ordine_collegio_associazione_di_categoria" + corporate_type = "ordine professionale, associazione di categoria" + when "TesauroSAN/organo_e_ufficio_statale_periferico_di_periodo_postunitario" + corporate_type = "organo periferico dello stato" + when "TesauroSAN/partito_e_movimento_politico-associazione_politica" + corporate_type = "partito politico, organizzazione sindacale" + when "TesauroSAN/organo_e_ufficio_statale_centrale_del_periodo_preunitario" + corporate_type = "preunitario" + when "TesauroSAN/regione-regione_a_statuto_speciale_sp" + corporate_type = "regione" + #when "TesauroSAN/statali" + #corporate_type = "organo giudiziario" + when "TesauroSAN/statali" + corporate_type = "stato" + + when "opera_pia-istituzione_ed_ente_assistenza_e_beneficenza_ospedale" + corporate_type = "ente di assistenza e beneficenza" + when "banca-istituto_di_credito-ente_assicurativo-ente_previdenziale" + corporate_type = "ente di credito, assicurativo, previdenziale" + when "accademia_ente_di_cultura" + corporate_type = "ente di cultura, ricreativo, sportivo, turistico" + when "ente_ricreativo-sportivo-turistico_sp" + corporate_type = "ente di cultura, ricreativo, sportivo, turistico" + when "scuola-ente_di_istruzione" + corporate_type = "ente di istruzione e ricerca" + when "universita-ente_di_ricerca" + corporate_type = "ente di istruzione e ricerca" + when "ente_culto_cattolico-associazione_cattolica" + corporate_type = "ente e associazione della chiesa cattolica" + when "ente_di_culto_acattolico-associazione_acattolica" + corporate_type = "ente e associazione di culto acattolico" + when "corporazione_religiosa" + corporate_type = "ente ecclesiastico" + when "ente_economico-impresa-studio_professionale_sp" + corporate_type = "ente economico / impresa" + #when "ente_territoriale_minore" + #corporate_type = "ente funzionale territoriale" + when "ente_territoriale_minore" + corporate_type = "ente pubblico territoriale" + when "ente_sanitario-ente_servizi_alla_persona" + corporate_type = "ente sanitario" + when "arte_ordine_collegio_associazione_di_categoria" + corporate_type = "ordine professionale, associazione di categoria" + when "organo_e_ufficio_statale_periferico_di_periodo_postunitario" + corporate_type = "organo periferico dello stato" + when "partito_e_movimento_politico-associazione_politica" + corporate_type = "partito politico, organizzazione sindacale" + when "organo_e_ufficio_statale_centrale_del_periodo_preunitario" + corporate_type = "preunitario" + when "regione-regione_a_statuto_speciale_sp" + corporate_type = "regione" + #when "statali" + #corporate_type = "organo giudiziario" + when "statali" + corporate_type = "stato" + end + + corporate_type_from_db = CreatorCorporateType.select(:id).where(:corporate_type => corporate_type) + if !corporate_type_from_db.empty? + creator.creator_corporate_type_id = corporate_type_from_db.first.id + end + end + elsif (localType == "person") + creator.creator_type = "P" + elsif (localType == "family") + creator.creator_type = "F" + end + + if document.xpath("eac-cpf/cpfDescription/description/biogHist/abstract").present? + creator.abstract = document.xpath("eac-cpf/cpfDescription/description/biogHist/abstract").first.text.squish + end + + if document.xpath("eac-cpf/cpfDescription/description/biogHist/p").present? + creator.history = document.xpath("eac-cpf/cpfDescription/description/biogHist/p").first.text.squish + end + + creator.legacy_id = document.xpath("eac-cpf/control/recordId").text + creator.db_source = self.identifier + creator.created_by = user_id + creator.updated_by = user_id + creator.group_id = group_id + creator.created_at = datetime + creator.updated_at = datetime + creator.sneaky_save! + self.importable_id = creator.id + + document.xpath("eac-cpf/cpfDescription/relations/resourceRelation").each do |resourceRelation| + if resourceRelation.xpath("relationEntry/@localType").text == "URI" + creator_url = CreatorUrl.new + creator_url.creator_id = creator.id + creator_url.url = resourceRelation.xpath("@href").text + creator_url.note = resourceRelation.xpath("relationEntry").text + creator_url.created_at = datetime + creator_url.updated_at = datetime + creator_url.save! + end + + if resourceRelation.xpath("@resourceRelationType").text == "creatorOf" && resourceRelation.xpath("relationEntry/@localType").text == "complesso" + creator_of_complesso = resourceRelation.xpath("relationEntry").text.squish + if creator_of_complesso[0..3] != "http" + fond_by_legacy_id = Fond.find_by_legacy_id(creator_of_complesso) + if !fond_by_legacy_id.nil? + rel_creator_fond = RelCreatorFond.new + rel_creator_fond.legacy_creator_id = creator.legacy_id + rel_creator_fond.legacy_fond_id = fond_by_legacy_id.legacy_id + rel_creator_fond.creator_id = creator.id + rel_creator_fond.fond_id = fond_by_legacy_id.id + rel_creator_fond.created_at = datetime + rel_creator_fond.updated_at = datetime + rel_creator_fond.save! + end + end + end + + if resourceRelation.xpath("relationEntry/@localType").text == "contestoStoricoIstituzionale" + if resourceRelation.xpath("relationEntry").text[0..3] != "http" + contesto_storico_istituzionale = "Contesto storico istituzionale: " + resourceRelation.xpath("relationEntry").text.squish + if creator.history.nil? + creator.history = contesto_storico_istituzionale + else + creator.history += ("\n" + contesto_storico_istituzionale) + end + else + creator_url = CreatorUrl.new + creator_url.creator_id = creator.id + creator_url.url = resourceRelation.xpath("relationEntry").text.squish + creator_url.note = "Contesto storico istituzionale" + creator_url.created_at = datetime + creator_url.updated_at = datetime + creator_url.save! + end + end + + if resourceRelation.xpath("relationEntry/@localType").text == "ambitoTerritoriale" + if resourceRelation.xpath("relationEntry").text[0..3] != "http" + ambito_territoriale = "Ambito territoriale: " + resourceRelation.xpath("relationEntry").text.squish + if creator.history.nil? + creator.history = ambito_territoriale + else + creator.history += ("\n" + ambito_territoriale) + end + else + creator_url = CreatorUrl.new + creator_url.creator_id = creator.id + creator_url.url = resourceRelation.xpath("relationEntry").text.squish + creator_url.note = "Ambito territoriale" + creator_url.created_at = datetime + creator_url.updated_at = datetime + creator_url.save! + end + end + end + + if document.xpath("eac-cpf/control/recordId").present? + creator_identifier = CreatorIdentifier.new + creator_identifier.creator_id = creator.id + creator_identifier.identifier = document.xpath("eac-cpf/control/recordId").text + creator_identifier.identifier_source = CGI.unescape(document.xpath("eac-cpf/control/recordId/@localType").text) + creator_identifier.note = "Identificativo di sistema" + creator_identifier.created_at = datetime + creator_identifier.updated_at = datetime + creator_identifier.save! + end + + document.xpath("eac-cpf/control/otherRecordId").each do |otherRecordId| + creator_identifier = CreatorIdentifier.new + creator_identifier.creator_id = creator.id + creator_identifier.identifier = otherRecordId.text + creator_identifier.identifier_source = CGI.unescape(otherRecordId.xpath("@localType").text) + creator_identifier.created_at = datetime + creator_identifier.updated_at = datetime + creator_identifier.save! + end + + document.xpath("eac-cpf/control/maintenanceHistory/maintenanceEvent").each do |editor| + event_type = editor.xpath("eventType").first.text + if editor.xpath("eventDateTime/@standardDateTime").present? + date_format = 'YMD' + event_datetime = editor.xpath("eventDateTime/@standardDateTime").first.text + if event_datetime.size == 4 + dateFormat = 'Y' + event_datetime << "-01-01" + elsif event_datetime.size == 7 + date_format = 'YM' + event_datetime << "-01" + end + else + event_datetime = editor.xpath("eventDateTime").first.text + end + agent_type = import_agent_type(editor.xpath("agentType").first.text) + agent = editor.xpath("agent").first.text + event_description_present = editor.xpath("boolean(eventDescription)") + + if ((event_type == "created") && (event_datetime == "") && (agent_type == "human") && (agent == "") && !event_description_present) + #ogni entità ha un evento di compilazione di default di questo tipo + # + # created + # + # human + # + # + #nell'import è ignorato + next + else + editor_model = CreatorEditor.new + editor_model.creator_id = creator.id + editor_model.name = agent + editor_model.editing_type = import_editing_type(event_type) + if !event_datetime.empty? + editor_model.edited_at = Date.parse(event_datetime) + end + editor_model.created_at = datetime + editor_model.updated_at = datetime + editor_model.qualifier = agent_type + #TODO creazione attributo per date_format. + editor_model.save! + end + end + + if creator.is_corporate? + if document.xpath("eac-cpf/cpfDescription/identity/nameEntryParallel").present? + #denominazione principale e denominazioni parallele + document.xpath("eac-cpf/cpfDescription/identity/nameEntryParallel/nameEntry").each do |nameEntry| + nameEntry_part = nameEntry.xpath("part").first + + creator_name = CreatorName.new + creator_name.creator_id = creator.id + creator_name.name = nameEntry_part.text + + if CreatorName.where(creator_id: creator.id).present? + #denominazione parallela + creator_name.preferred = false + creator_name.qualifier = "PA" + else + #denominazione principale (se e` la prima denominazione salvata). + creator_name.preferred = true + creator_name.qualifier = "A" + end + + begin + if nameEntry.xpath("@lang").present? + lang = nameEntry.xpath("@lang").text + elsif nameEntry.xpath("@xml:lang").present? + lang = nameEntry.xpath("@xml:lang").text + end + if lang.present? + creator_name.note = "codice lingua: " + lang + end + rescue + Rails.logger.info "sigla della lingua non trovata" + creator_name.note = "codice lingua: " + lang + end + + creator_name.created_at = datetime + creator_name.updated_at = datetime + creator_name.save! + end + + # altre denominazioni + #document.xpath("eac-cpf/cpfDescription/identity/nameEntry/part").each do |nameEntry| + # creator_name = CreatorName.new + # creator_name.creator_id = creator.id + # creator_name.name = nameEntry.text + # creator_name.preferred = false + # creator_name.qualifier = import_qualifer_type(nameEntry.xpath("@localType").text) + # creator_name.note = "" + # creator_name.created_at = datetime + # creator_name.updated_at = datetime + # creator_name.save! + #end + + else + #non sono presenti denominazioni parallele + preferred_name_already_set = false + document.xpath("eac-cpf/cpfDescription/identity/nameEntry/part").each do |nameEntry| + creator_name = CreatorName.new + creator_name.creator_id = creator.id + creator_name.name = nameEntry.text + if (nameEntry.xpath("boolean(@localType)") || preferred_name_already_set) + #altra denominazione + creator_name.preferred = false + creator_name.qualifier = import_qualifer_type(nameEntry.xpath("@localType").text) + else + #denominazione principale + creator_name.preferred = true + creator_name.qualifier = "A" + preferred_name_already_set = true + end + + creator_name.note = "" + + if nameEntry.xpath("../useDates/date").present? + creator_name_date = nameEntry.xpath("../useDates/date").text.squish + + if creator_name_date != "" + if !creator_name.name.nil? + if creator_name.name != "" + creator_name.name += " " + end + creator_name.name += "(" + creator_name_date + ")" + else + creator_name.name = "(" + creator_name_date + ")" + end + end + end + + creator_name.created_at = datetime + creator_name.updated_at = datetime + creator_name.save! + end + end + + document.xpath("eac-cpf/cpfDescription/description/legalStatuses/legalStatus").each do |legalStatus| + legalStatus_text = legalStatus.xpath("term").text + if legalStatus_text == "Pubblico" + legalStatus_id = "PU" + elsif legalStatus_text == "Privato" + legalStatus_id = "PR" + elsif legalStatus_text == "Ecclesiastico" + legalStatus_id = "EC" + else + legalStatus_id = "NA" + end + + creator_legal_status = CreatorLegalStatus.new + creator_legal_status.creator_id = creator.id + creator_legal_status.legal_status = legalStatus_id + creator_legal_status.created_at = datetime + creator_legal_status.updated_at = datetime + creator_legal_status.save! + end + + if document.xpath("eac-cpf/cpfDescription/description/existDates").present? + event = CreatorEvent.new + event.creator_id = creator.id + import_dateset(document.xpath("eac-cpf/cpfDescription/description/existDates").first, event, datetime) + + event.save! + end + + document.xpath("eac-cpf/cpfDescription/description/place").each do |place| + placerole_voc_src = place.xpath("placeRole/@vocabularySource").text + tipo_luogo_CPF_URL = "http://dati.san.beniculturali.it/SAN/TesauroSAN/Tipo_luogo_CPF" + placerole_tag = place.xpath("placeRole").text + if (placerole_voc_src != tipo_luogo_CPF_URL && placerole_tag == "Sede") || + (placerole_voc_src == tipo_luogo_CPF_URL && placerole_tag == "TesauroSAN/sede") + creator.residence = place.xpath("placeEntry").text.squish + end + end + elsif creator.is_person? + firstnameFound = false + lastnameFound = false + + creator_name = CreatorName.new + creator_name.creator_id = creator.id + if document.xpath("eac-cpf/cpfDescription/identity/nameEntry/part[@localType='nome']").present? + creator_name.first_name = document.xpath("eac-cpf/cpfDescription/identity/nameEntry/part[@localType='nome']").first.text + firstnameFound = true + end + + if document.xpath("eac-cpf/cpfDescription/identity/nameEntry/part[@localType='cognome']").present? + creator_name.last_name = document.xpath("eac-cpf/cpfDescription/identity/nameEntry/part[@localType='cognome']").first.text + lastnameFound = true + end + + if document.xpath("eac-cpf/cpfDescription/identity/nameEntry/part[@localType='denominazione']").present? || + document.xpath("eac-cpf/cpfDescription/identity/nameEntry/part[@localType='intestazione']").present? + #denominazione principale + if document.xpath("eac-cpf/cpfDescription/identity/nameEntry/part[@localType='denominazione']").present? + name = document.xpath("eac-cpf/cpfDescription/identity/nameEntry/part[@localType='denominazione']").first.text + else + name = document.xpath("eac-cpf/cpfDescription/identity/nameEntry/part[@localType='intestazione']").first.text + end + + creator_name.name = name + if name.include?(",") + name_parts = name.split(",") + if (!lastnameFound) + creator_name.last_name = name_parts[0].strip + end + if (!firstnameFound) + creator_name.first_name = name_parts[1].strip + end + else + if (!lastnameFound) + creator_name.last_name = name + end + if (!firstnameFound) + creator_name.first_name = "" + end + end + end + + if (!creator_name.name.empty?) + creator_name.preferred = true + creator_name.qualifier = "A" + creator_name.note = "" + creator_name.created_at = datetime + creator_name.updated_at = datetime + creator_name.save! + end + + document.xpath("eac-cpf/cpfDescription/identity/nameEntry/part").each do |nameEntry| + if (nameEntry.xpath("boolean(@localType)")) + if (nameEntry.xpath("@localType").text == "denominazione" || + #nameEntry.xpath("@localType").text == "intestazione" || + nameEntry.xpath("@localType").text == "cognome" || + nameEntry.xpath("@localType").text == "nome") + next + end + + creator_name = CreatorName.new + creator_name.creator_id = creator.id + + name = nameEntry.text + creator_name.name = name + #altra denominazione + creator_name.preferred = false + creator_name.qualifier = "OT" + + case nameEntry.xpath("@localType").text.downcase + when "intestazione" + creator_name.qualifier = "IN" + when "patronimico" + creator_name.qualifier = "PT" + when "soprannome" + creator_name.qualifier = "SN" + when "pseudonimo" + creator_name.qualifier = "AL" + when "alias" + creator_name.qualifier = "AL" + else + creator_name.note = nameEntry.xpath("@localType").text.downcase + end + + creator_name.created_at = datetime + creator_name.updated_at = datetime + creator_name.save! + end + end + + if (document.xpath("eac-cpf/cpfDescription/description/existDates").present? || document.xpath("eac-cpf/cpfDescription/description/place").present?) + event = CreatorEvent.new + event.creator_id = creator.id + + if document.xpath("eac-cpf/cpfDescription/description/existDates").present? + import_dateset(document.xpath("eac-cpf/cpfDescription/description/existDates").first, event, datetime) + end + + document.xpath("eac-cpf/cpfDescription/description/place").each do |place| + if (place.xpath("placeRole").text == "TesauroSAN/luogo di nascita") + event.start_date_place = place.xpath("placeEntry").text + elsif (place.xpath("placeRole").text == "TesauroSAN/luogo di morte") + event.end_date_place = place.xpath("placeEntry").text + end + end + + event.save! + end + elsif creator.is_family? + document.xpath("eac-cpf/cpfDescription/identity/nameEntry/part").each do |nameEntry| + creator_name = CreatorName.new + creator_name.creator_id = creator.id + creator_name.name = nameEntry.text + creator_name.note = "" + if (nameEntry.xpath("boolean(@localType)")) + #altra denominazione + creator_name.preferred = false + creator_name.qualifier = "OT" + + case nameEntry.xpath("@localType").text.downcase + when "intestazione" + creator_name.qualifier = "IN" + when "patronimico" + creator_name.qualifier = "PT" + when "soprannome" + creator_name.qualifier = "SN" + when "pseudonimo" + creator_name.qualifier = "AL" + when "alias" + creator_name.qualifier = "AL" + else + creator_name.note = nameEntry.xpath("@localType").text.downcase + end + else + #denominazione principale + creator_name.preferred = true + creator_name.qualifier = "A" + end + creator_name.created_at = datetime + creator_name.updated_at = datetime + creator_name.save! + end + + if document.xpath("eac-cpf/cpfDescription/description/existDates").present? + event = CreatorEvent.new + event.creator_id = creator.id + import_dateset(document.xpath("eac-cpf/cpfDescription/description/existDates").first, event, datetime) + + event.save! + end + end + + # Extra "Tipo_luogo" per tutti i tipi di produttore + document.xpath("eac-cpf/cpfDescription/description/place").each do |place| + if place.xpath("placeRole/@vocabularySource").text == "http://dati.san.beniculturali.it/SAN/TesauroSAN/Tipo_luogo_CPF" + creator_history = creator.history.nil? ? "" : (creator.history + "\n") + placeRole_text = place.xpath("placeRole").text + placEntry_label = placeRole_text.squish.capitalize + ": " + if (placeRole_text != "sede" && placeRole_text != "TesauroSAN/sede") || creator.residence.nil? + creator.history = creator_history + placEntry_label + place.xpath("placeEntry[count(@*)=0]").text.squish + end + end + end + + if document.xpath("eac-cpf/cpfDescription/relations/cpfRelation").present? && !@is_icar_import + Rails.logger.info "Sono presenti relazioni non ricostruibili per il produttore #{creator.id}" + if !creator.note.present? + #creator.note = "" + end + document.xpath("eac-cpf/cpfDescription/relations/cpfRelation").each do |relation| + if relation.xpath("relationEntry").text[0..3] == "http" + link = CreatorUrl.new + link.db_source = self.identifier + link.creator_id = creator.id + link.url = relation.xpath("relationEntry").text + link.note = relation.xpath("relationEntry/@localType").text + link.save + else + #creator.note += "#{relation.xpath("relationEntry/@localType").text}: #{relation.xpath("relationEntry").text}\n;" + end + end + end + + if document.xpath("eac-cpf/cpfDescription/relations/resourceRelation").present? && !@is_icar_import + Rails.logger.info "Sono presenti relazioni non ricostruibili per il produttore #{creator.id}" + + document.xpath("eac-cpf/cpfDescription/relations/resourceRelation").each do |relation| + if relation.xpath("relationEntry").text[0..3] == "http" + note = relation.xpath("relationEntry/@localType").text + if (note != "contestoStoricoIstituzionale" && note != "ambitoTerritoriale") + link = CreatorUrl.new + link.db_source = self.identifier + link.creator_id = creator.id + link.url = relation.xpath("relationEntry").text + link.note = note + link.save + end + end + + tipo = relation.xpath("relationEntry/@localType").text + if tipo == "BIBTEXT" || tipo == "BIBSBN" || tipo == "FONTEURI" || tipo == "FONTETEXT" + title = relation.xpath("relationEntry").text.squish + + if tipo == "BIBSBN" || tipo == "FONTEURI" + source_url = relation.xpath("@href").text + if source_url.present? && source_url != "" + link = CreatorUrl.new + link.db_source = self.identifier + link.creator_id = creator.id + link.url = source_url + link.save + end + end + + if title.present? && title != "" + source_by_title = Source.find_by_title(title) + if source_by_title.nil? + source = Source.new + datetime = Time.now.strftime("%Y-%m-%d %H:%M:%S") + source.created_by = user_id + source.updated_by = user_id + source.group_id = group_id + source.created_at = datetime + source.updated_at = datetime + source.db_source = self.identifier + source.legacy_id = document.xpath("eac-cpf/control/recordId").text + if tipo == "BIBTEXT" || tipo == "BIBSBN" + source.source_type_code = 1 # bibliografia + elsif tipo == "FONTETEXT" || tipo == "FONTEURI" + source.source_type_code = 3 # fonte archivistica + end + source.title = title + source.short_title = title.truncate(50, separator: /\s/) + if Source.where("short_title = '#{source.short_title.gsub(/'/, "''")}'").present? + source.sneaky_save + source.short_title << " - #{source.id.to_s}" + end + source.save! + if tipo == "BIBSBN" || tipo == "FONTEURI" + fonte_url = relation.xpath("@href").text + if fonte_url.present? && fonte_url != "" + source_url = SourceUrl.new + source_url.url = fonte_url + source_url.source_id = source.id + source_url.save! + end + end + source_id = source.id + else + source_id = source_by_title.id + end + rel_creator_source = RelCreatorSource.new + rel_creator_source.creator_id = creator.id + rel_creator_source.source_id = source_id + rel_creator_source.save! + end + end + end + end + + creator.save! + Rails.logger.info "Produttore #{creator.id} salvato" + + return_bundle = {creator_id: creator.id, legacy_fond_ids: Array.new} + # ripristina eventuali relazioni con dei complessi + if document.xpath("eac-cpf/cpfDescription/relations/resourceRelation/relationEntry[@localType='complesso']").present? + Rails.logger.info "Associazione complessi al produttore #{creator.id}" + document.xpath("eac-cpf/cpfDescription/relations/resourceRelation/relationEntry[@localType='complesso']").each do |related_fond| + return_bundle[:legacy_fond_ids].push related_fond.text + Rails.logger.info "Associazione complesso con legacy_id #{related_fond.text[3..10].to_i.to_s}" + end + end + + return return_bundle + end + + #import scheda anagrafica + #document Nokogiri::XML + #user_id utente che effettua l'import + #group_id gruppo dell'utente che effettua l'import + def import_anagraphic(document, user_id, group_id) + Rails.logger.info "import_anagraphic start" + Rails.logger.info document + datetime = Time.now.strftime("%Y-%m-%d %H:%M:%S") + + anagraphic = Anagraphic.new + + document.xpath("eac-cpf/cpfDescription/identity/nameEntry/part").each do |nameEntry| + if (nameEntry.xpath("@localType").text == "cognome") + anagraphic.surname = nameEntry.text + else + anagraphic.name = nameEntry.text + end + end + + if document.xpath("eac-cpf/cpfDescription/description/existDates/dateRange/fromDate").present? + anagraphic.start_date = document.xpath("eac-cpf/cpfDescription/description/existDates/dateRange/fromDate/@standardDate").first.text + end + + if document.xpath("eac-cpf/cpfDescription/description/existDates/dateRange/toDate").present? + anagraphic.end_date = document.xpath("eac-cpf/cpfDescription/description/existDates/dateRange/toDate/@standardDate").first.text + end + + document.xpath("eac-cpf/cpfDescription/description/place").each do |place| + if (place.xpath("placeRole").text == "TesauroSAN/luogo di nascita") + anagraphic.start_date_place = place.xpath("placeEntry").text + elsif (place.xpath("placeRole").text == "TesauroSAN/luogo di morte") + anagraphic.end_date_place = place.xpath("placeEntry").text + end + end + + anagraphic.legacy_id = document.xpath("eac-cpf/control/recordId").text + anagraphic.db_source = self.identifier + anagraphic.group_id = group_id + anagraphic.created_at = datetime + anagraphic.updated_at = datetime + anagraphic.sneaky_save! + + self.importable_id = anagraphic.id + + document.xpath("eac-cpf/control/otherRecordId").each do |otherRecordId| + anag_identifier = AnagIdentifier.new + anag_identifier.anagraphic_id = anagraphic.id + anag_identifier.identifier = otherRecordId.text + anag_identifier.qualifier = CGI.unescape(otherRecordId.xpath("@localType").text) + anag_identifier.created_at = datetime + anag_identifier.updated_at = datetime + anag_identifier.save! + end + + anagraphic.save + return_bundle = {anagraphic_id: anagraphic.id} + return return_bundle + end + + #import soggetti conservatore + #document Nokogiri::XML + #user_id utente che effettua l'import + #group_id gruppo dell'utente che effettua l'import + def import_custodian(document, user_id, group_id) + datetime = Time.now.strftime("%Y-%m-%d %H:%M:%S") + + custodian = Custodian.new + + custodian_type = "" + description = document.xpath("scons/tipologia").first.text + case description + when "TesauroSAN/archivio_di_Stato" + custodian_type = "stato" + when "TesauroSAN/regione-regione_a_statuto_speciale_conservatore" + custodian_type = "regione" + when "TesauroSAN/ente_territoriale" + custodian_type = "ente pubblico territoriale" + when "TesauroSAN/ente_diverso" + custodian_type = "ente funzionale territoriale" + when "TesauroSAN/ente_economico-impresa-studio_professionale_conservatore" + custodian_type = "ente economico / impresa" + when "TesauroSAN/istituto_di_credito" + custodian_type = "ente di credito, assicurativo, previdenziale" + when "TesauroSAN/ente_di_assistenza-beneficenza-previdenza-servizi_alla_persona" + custodian_type = "ente di assistenza e beneficenza" + when "TesauroSAN/ente_sanitario" + custodian_type = "ente sanitario" + when "TesauroSAN/ente_di_cultura-ente_di_ricerca" + custodian_type = "ente di istruzione e ricerca" + when "TesauroSAN/ente_ricreativo-sportivo-turistico_conservatore" + custodian_type = "ente di cultura, ricreativo, sportivo, turistico" + when "TesauroSAN/sindacato-organizzazione_sindacale_conservatore" + custodian_type = "partito politico, organizzazione sindacale" + when "TesauroSAN/arte-ordine-collegio-associazione_di_categoria" + custodian_type = "ordine professionale, associazione di categoria" + when "TesauroSAN/ente_e_associazione_di_culto_cattolico" + custodian_type = "ente e associazione della chiesa cattolica" + when "TesauroSAN/ente_e_associazione_di_culti_acattolici" + custodian_type = "ente e associazione di culto acattolico" + when "TesauroSAN/persona-famiglia" + custodian_type = "persona o famiglia" + + when "archivio_di_Stato" + custodian_type = "stato" + when "regione-regione_a_statuto_speciale_conservatore" + custodian_type = "regione" + when "ente_territoriale" + custodian_type = "ente pubblico territoriale" + when "ente_diverso" + custodian_type = "ente funzionale territoriale" + when "ente_economico-impresa-studio_professionale_conservatore" + custodian_type = "ente economico / impresa" + when "istituto_di_credito" + custodian_type = "ente di credito, assicurativo, previdenziale" + when "ente_di_assistenza-beneficenza-previdenza-servizi_alla_persona" + custodian_type = "ente di assistenza e beneficenza" + when "ente_sanitario" + custodian_type = "ente sanitario" + when "ente_di_cultura-ente_di_ricerca" + custodian_type = "ente di istruzione e ricerca" + when "ente_ricreativo-sportivo-turistico_conservatore" + custodian_type = "ente di cultura, ricreativo, sportivo, turistico" + when "sindacato-organizzazione_sindacale_conservatore" + custodian_type = "partito politico, organizzazione sindacale" + when "arte-ordine-collegio-associazione_di_categoria" + custodian_type = "ordine professionale, associazione di categoria" + when "ente_e_associazione_di_culto_cattolico" + custodian_type = "ente e associazione della chiesa cattolica" + when "ente_e_associazione_di_culti_acattolici" + custodian_type = "ente e associazione di culto acattolico" + when "persona-famiglia" + custodian_type = "persona o famiglia" + end + custodian_type_id = CustodianType.select(:id).where(:custodian_type => custodian_type).first.id + custodian.custodian_type_id = custodian_type_id + + if document.xpath("scons/descrizione").present? + custodian.history = document.xpath("scons/descrizione").text.gsub(/\t/, '') + end + + if document.xpath("scons/servizi").present? + custodian.services = document.xpath("scons/servizi").text + end + + custodian.accessibility = "" + custodian.legacy_id = document.xpath("scons/identificativi/identificativo").text + custodian.db_source = self.identifier + custodian.created_by = user_id + custodian.updated_by = user_id + custodian.group_id = group_id + custodian.created_at = datetime + custodian.updated_at = datetime + custodian.sneaky_save! + + self.importable_id = custodian.id + + denominazioni = document.xpath("scons/denominazione") + if (denominazioni.size == 1) + custodian_name = CustodianName.new + custodian_name.custodian_id = custodian.id + custodian_name.name = denominazioni.first.text + + if denominazioni.xpath("@data").text != "" + custodian_name.name += " (" + denominazioni.xpath("@data").text + ")" + end + + custodian_name.created_at = datetime + custodian_name.updated_at = datetime + custodian_name.preferred = true + custodian_name.qualifier = "OT" + + custodian_name.save! + else + preferred_found = false + denominazioni.each do |denominazione| + if denominazione.xpath("@qualifica").text == "principale" + preferred_found = true + break + end + end + + denominazioni.each do |denominazione| + custodian_name = CustodianName.new + custodian_name.custodian_id = custodian.id + custodian_name.name = denominazione.text + + if denominazione.xpath("@data").text != "" + custodian_name.name += " (" + denominazione.xpath("@data").text + ")" + end + + custodian_name.created_at = datetime + custodian_name.updated_at = datetime + + qualifica = denominazione.xpath("@qualifica").text + preferred = false + note = "" + if (!preferred_found || (qualifica == "principale")) + preferred_found = true + + preferred = true + qualifier = "OT" + elsif (qualifica == "altraDenominazione") + qualifier = "OT" + elsif (qualifica == "parallela") + qualifier = "PA" + lingua = "" + if denominazione.xpath("boolean(@lingua)") + lingua_xml = denominazione.xpath("@lingua").text + if lingua_xml == "nnn" + lingua = "" + else + lingua = lingua_xml + end + else + lingua = "" + end + if lingua != "" + note = "codice lingua: " + lingua + end + elsif (qualifica == "acronimo") + qualifier = "AC" + else + qualifier = "OT" + end + custodian_name.preferred = preferred + custodian_name.qualifier = qualifier + custodian_name.note = note + custodian_name.save! + end + end + + document.xpath("scons/relazioni/relazione").each do |relazione| + tipo = relazione.xpath("@tipo").text + if tipo == "URL" || tipo == "BIBSBN" || tipo == "FONTEURI" + custodian_url = CustodianUrl.new + custodian_url.custodian_id = custodian.id + custodian_url.url = relazione.xpath("@href").text + custodian_url.note = relazione.text.squish + custodian_url.created_at = datetime + custodian_url.updated_at = datetime + custodian_url.save! + end + + if tipo == "BIBTEXT" || tipo == "BIBSBN" || tipo == "FONTETEXT" || tipo == "FONTEURI" + title = relazione.text.squish + if title.present? && title != "" + source_by_title = Source.find_by_title(title) + if source_by_title.nil? + source = Source.new + source.created_by = user_id + source.updated_by = user_id + source.group_id = group_id + source.created_at = datetime + source.updated_at = datetime + source.db_source = self.identifier + source.legacy_id = custodian.legacy_id + if tipo == "BIBTEXT" || tipo == "BIBSBN" + source.source_type_code = 1 # bibliografia + elsif tipo == "FONTETEXT" || tipo == "FONTEURI" + source.source_type_code = 3 # fonte archivistica + end + source.title = title + source.short_title = title.truncate(50, separator: /\s/) + if Source.where("short_title = '#{source.short_title.gsub(/'/, "''")}'").present? + source.sneaky_save + source.short_title << " - #{source.id.to_s}" + end + source.save! + if tipo == "BIBSBN" || tipo == "FONTEURI" + fonte_url = relazione.xpath("@href").text + if fonte_url.present? && fonte_url != "" + source_url = SourceUrl.new + source_url.url = fonte_url + source_url.source_id = source.id + source_url.save! + end + end + source_id = source.id + else + source_id = source_by_title.id + end + rel_custodian_source = RelCustodianSource.new + rel_custodian_source.custodian_id = custodian.id + rel_custodian_source.source_id = source_id + rel_custodian_source.save! + end + end + end + + if document.xpath("scons/identificativi/identificativo").present? + custodian_identifier = CustodianIdentifier.new + custodian_identifier.custodian_id = custodian.id + custodian_identifier.identifier = document.xpath("scons/identificativi/identificativo").text + custodian_identifier.identifier_source = document.xpath("scons/identificativi/identificativo/@tipo").text + custodian_identifier.note = "Identificativo di sistema" + + #if document.xpath("scons/identificativi/identificativo/@href").present? + # custodian_identifier.note = document.xpath("scons/identificativi/identificativo/@href").text + #else + # custodian_identifier.note = "Identificativo di sistema" + #end + + custodian_identifier.created_at = datetime + custodian_identifier.updated_at = datetime + custodian_identifier.save! + end + + document.xpath("scons/identificativi/altroidentificativo").each do |altroidentificativo| + custodian_identifier = CustodianIdentifier.new + custodian_identifier.custodian_id = custodian.id + custodian_identifier.identifier = altroidentificativo.text + custodian_identifier.identifier_source = altroidentificativo.xpath("@tipo").text + custodian_identifier.note = "Altro identificativo" + + #if altroidentificativo.xpath("@href").present? + # custodian_identifier.note = altroidentificativo.xpath("@href").text + #else + # custodian_identifier.note = "Altro identificativo" + #end + + custodian_identifier.created_at = datetime + custodian_identifier.updated_at = datetime + custodian_identifier.save! + end + + principale_found = false + document.xpath("scons/localizzazioni/localizzazione").each do |localizzazione| + custodian_building = CustodianBuilding.new + custodian_building.custodian_id = custodian.id + custodian_building.name = localizzazione.xpath("denominazione").text + custodian_building.address = localizzazione.xpath("indirizzo/@denominazioneStradale").text + + if custodian_building.address == "" + custodian_building.address = localizzazione.xpath("indirizzo").text.squish + if localizzazione.xpath("indirizzo/@numeroCivico").present? + numero_civico = localizzazione.xpath("indirizzo/@numeroCivico").text + if numero_civico != "" + custodian_building.address += (" " + numero_civico) + end + end + end + + custodian_building.postcode = localizzazione.xpath("indirizzo/@cap").text + custodian_building.city = localizzazione.xpath("indirizzo/@comune").text + custodian_building.country = localizzazione.xpath("indirizzo/@paese").text + custodian_building.legacy_id = localizzazione.xpath("@identificativo").text + custodian_building.created_at = datetime + custodian_building.updated_at = datetime + + custodian_building_type = "" + if (localizzazione.xpath("@consultazione").text == "S") + custodian_building_type = "sede di consultazione" + end + custodian_building.custodian_building_type = custodian_building_type + + custodian_building.save! + + localizzazione.xpath("contatto").each do |contatto| + custodian_contact = CustodianContact.new + custodian_contact.custodian_id = custodian.id + custodian_contact.contact = contatto.text + custodian_contact.contact_note = custodian_building.name; + custodian_contact.created_at = datetime + custodian_contact.updated_at = datetime + + if (contatto.xpath("@tipo").text == "telefono") + contact_type = "tel" + elsif (contatto.xpath("@tipo").text == "mail") + contact_type = "email" + elsif (contatto.xpath("@tipo").text == "pec") + contact_type = "pec" + elsif (contatto.xpath("@tipo").text == "fax") + contact_type = "fax" + elsif (contatto.xpath("@tipo").text == "sitoweb") + contact_type = "web" + end + custodian_contact.contact_type = contact_type + + custodian_contact.save! + end + + if localizzazione.xpath("boolean(orario)") + if !custodian.accessibility.empty? + custodian.accessibility += "\n\n" + end + custodian.accessibility += "Orari Sede " + custodian_building.name + " - " + localizzazione.xpath("orario").text.squish + end + + if localizzazione.xpath("boolean(accesso)") + if !custodian.accessibility.empty? + custodian.accessibility += "\n" + end + custodian.accessibility += "Accesso Sede " + custodian_building.name + " - " + localizzazione.xpath("accesso").text.squish + end + + if ((localizzazione.xpath("@principale").text == "S") && !principale_found) + principale_found = true + + legal_status = nil + privato = localizzazione.xpath("@privato").text + if (privato == "S") + legal_status = "PR" + elsif (privato == "N") + legal_status = "PU" + end + custodian.legal_status = legal_status + end + end + + document.xpath("scons/info/evento").each do |evento| + custodian_editor = CustodianEditor.new + custodian_editor.custodian_id = custodian.id + custodian_editor.created_at = datetime + custodian_editor.updated_at = datetime + + name = "" + if evento.xpath("boolean(agente/nome)") + name = evento.xpath("agente/nome").first.text + end + if evento.xpath("boolean(agente/cognome)") + if !name.empty? + name += " " + end + name += evento.xpath("agente/cognome").first.text + end + if evento.xpath("boolean(agente/denominazione)") + name = evento.xpath("agente/denominazione").first.text + end + custodian_editor.name = name + + if evento.xpath("agente/@tipo").present? + custodian_editor.qualifier = evento.xpath("agente/@tipo").first.text + end + + date_str = evento.xpath("@dataEvento").first.text + if !date_str.empty? + date_time = DateTime::strptime(date_str, "%Y-%m-%dT%H:%M:%S") + custodian_editor.edited_at = date_time.strftime("%Y-%m-%d") + end + + editing_type = "" + xml_editing_type = evento.xpath("@tipoEvento").first.text + if (xml_editing_type == "creazione") + editing_type = "inserimento dati" + elsif (xml_editing_type == "modifica") + editing_type = "aggiornamento scheda" + elsif (xml_editing_type == "cancellazione") + editing_type = "aggiornamento scheda" + elsif (xml_editing_type == "altro") + editing_type = "schedatura" + end + custodian_editor.editing_type = editing_type + + custodian_editor.save! + end + + custodian.save! + + return_bundle = {custodian_id: custodian.id} + return return_bundle + end + + #import fonti archivistiche + #document Nokogiri::XML + #user_id utente che effettua l'import + #group_id gruppo dell'utente che effettua l'import + def import_source(document, user_id, group_id) + source = Source.new + datetime = Time.now.strftime("%Y-%m-%d %H:%M:%S") + + source.created_by = user_id + source.updated_by = user_id + source.group_id = group_id + source.created_at = datetime + source.updated_at = datetime + source.db_source = self.identifier + source.legacy_id = document.xpath("ead/control/recordid").text + source.title = nil + document.xpath("ead/control/filedesc/titlestmt/titleproper").each do |title| + if source.title.nil? + if title.xpath("@lang").present? + source.title = "[#{title.xpath("@lang").text}: #{title.text}]\n\n" + else + source.title = "[#{title.text}]\n" + end + else + source.title += "[#{title.xpath("@lang").text}: #{title.text}]\n" + end + end + + source_Curator = document.xpath('ead/control/filedesc/titlestmt/author[@localtype="Curator"]') + source_curatore = document.xpath('ead/control/filedesc/titlestmt/author[@localtype="curatore"]') + source_author = document.xpath('ead/control/filedesc/titlestmt/author') + + if source_Curator.present? + source.editor = source_Curator.text.squish + elsif source_curatore.present? + source.editor = source_curatore.text.squish + elsif source_author.present? + source.author = source_author.text.squish + end + + source.publisher = document.xpath('ead/control/filedesc/publicationstmt/publisher').text + source.place = document.xpath('ead/control/filedesc/publicationstmt/address/addressline').text + + document.xpath("ead/control/filedesc/notestmt/controlnote").each do |controlnote| + if controlnote.xpath("p").present? + control_note = controlnote.xpath("p").text.squish + if control_note != "" + if !source.abstract.nil? && source.abstract != "" + source.abstract += "\n" + control_note + else + source.abstract = control_note + end + end + end + end + + compilatori = "" + if document.xpath("ead/control/maintenancehistory/maintenanceevent").present? + document.xpath("ead/control/maintenancehistory/maintenanceevent").each do |maintenance_event| + + tipo_evento = "" + data_evento = "" + tipo_agente = "" + nome_agente = "" + descrizione_evento = "" + + if maintenance_event.xpath("eventtype").present? + tipo_evento = maintenance_event.xpath("eventtype").text.squish + end + + if maintenance_event.xpath("eventdatetime").present? + data_evento = maintenance_event.xpath("eventdatetime").text.squish + end + + if maintenance_event.xpath("agenttype/@value").present? + tipo_agente = import_agent_type(maintenance_event.xpath("agenttype/@value").text) + end + + if maintenance_event.xpath("agent").present? + nome_agente = maintenance_event.xpath("agent").text.squish + end + + if maintenance_event.xpath("eventdescription").present? + descrizione_evento = maintenance_event.xpath("eventdescription").text.squish + end + + evento = "" + if nome_agente != "" || tipo_agente != "" + evento += "Compilatore: " + nome_agente + if tipo_agente != "" + if nome_agente != "" + evento += " " + end + evento += "(" + tipo_agente + ")" + end + evento += "\n" + end + + if data_evento != "" + evento += "Data intervento: " + data_evento + "\n" + end + + if tipo_evento != "" + evento += "Tipo intervento: " + tipo_evento + "\n" + end + + if descrizione_evento != "" + evento += "Descrizione evento: " + descrizione_evento + "\n" + end + + if evento != "" + evento = "\n" + evento + end + + compilatori += evento + end + + if compilatori != "" + compilatori = "COMPILATORI:\n" + compilatori + end + end + + if !source.abstract.nil? && source.abstract != "" + source.abstract += "\n\n" + compilatori + else + source.abstract = compilatori + end + + source_type = SourceType.where("source_types.source_type = ?", document.xpath('ead/control/filedesc/editionstmt/edition[@localtype="typology"]').text.downcase).first + if !source_type.present? + Rails.logger.info("Nessun source_type corrispondente alla tipologia indicata in: \n ead/control/filedesc/editionstmt/edition[@localtype='typology'], e` stato assegnato 'fonte archivistica' di default ") + source.source_type_code = 2 + else + if source_type.parent_code.nil? + source.source_type_code = source_type.code + else + source.source_type_code = source_type.parent_code + source.source_subtype_code = source_type.code + end + end + if document.xpath('ead/control/filedesc/editionstmt/edition[@localtype="published"]').text == 'no' + source.finding_aid_published = 0 + else + source.finding_aid_published = 1 + end + + if document.xpath("ead/control/filedesc/publicationstmt/date").present? + source.date_string = document.xpath("ead/control/filedesc/publicationstmt/date").text + end + + document.xpath("ead/control/otherrecordid").each do |other_record_id| + if (!source.legacy_description.nil? && source.legacy_description != "") + source.legacy_description += " " + other_record_id.text.squish + else + source.legacy_description = other_record_id.text.squish + end + end + + source.sneaky_save + + source.short_title = document.xpath("ead/control/filedesc/titlestmt/titleproper").text.truncate(50, separator: /\s/) + if Source.where("short_title = '#{source.short_title.gsub(/'/, "''")}'").present? + source.short_title << " - #{source.id.to_s}" + end + Rails.logger.info "Import: Salvataggio sorgente #{source.id}" + + source.save! + Rails.logger.info "Import: sorgente salvata" + + + i = 0 + until document.xpath("ead/control/representation")[i].nil? do + source_url = SourceUrl.new + source_url.note = document.xpath("ead/control/representation")[i].text + source_url.url = document.xpath("ead/control/representation/@href")[i].value + source_url.source_id = source.id + source_url.save! + i = i +1 + end + + document.xpath("ead/control/sources/source").each do |xmlSourceUrl| + if xmlSourceUrl.xpath("@href").present? + source_url = SourceUrl.new + source_url.url = xmlSourceUrl.xpath("@href").first.text + if xmlSourceUrl.xpath("sourceentry").present? + source_url.note = xmlSourceUrl.xpath("sourceentry").first.text + end + source_url.source_id = source.id + source_url.save! + end + end + + self.importable_id = source.id + + return_bundle = {source_id: source.id, legacy_fond_ids: Array.new} + + #if document.xpath("ead/control/localcontrol/term").present? + # document.xpath("ead/control/localcontrol/term/@identifier").each do |related_fond| + # Rails.logger.info "Associazione fonti a complessi" + # return_bundle[:legacy_fond_ids].push related_fond.text + # Rails.logger.info "Associazione complesso con legacy_id #{related_fond.text}" + # end + #end + + return return_bundle + end + + #import complessi archivistici + #document Nokogiri::XML + #user_id utente che effettua l'import + #group_id gruppo dell'utente che effettua l'import + def import_fond(document, user_id, group_id) + Rails.logger.info "Inizio importazione complesso da import.rb" + datetime = Time.now.strftime("%Y-%m-%d %H:%M:%S") + + fond = Fond.new + + fond_type = "" + level = document.xpath("archdesc/@level").first.text + if level == 'otherlevel' + level = path.xpath("archdesc/@otherlevel").text + end + fond_type = import_level_type(level) + + #fond_type = "sottosezione" + #when "otherlevel" + #fond_type = "categoria" + #when "otherlevel" + #fond_type = "classe" + #when "otherlevel" + #fond_type = "sottoclasse" + #when "otherlevel" + #fond_type = "rubrica" + #when "otherlevel" + #fond_type = "voce" + #when "otherlevel" + #fond_type = "sottovoce" + #when "otherlevel" + #fond_type = "titolo" + #when "otherlevel" + #fond_type = "sottotitolo" + #when "otherlevel" + #fond_type = "articolo" + # + fond.fond_type = fond_type + + #solo la prima Denominazione è considerata come principale + + document.xpath("//ead/archdesc/did/unittitle").each do |title| + if title.xpath('@localtype').text.downcase == "denominazione" + fond.name = title.text + end + end + + puts fond.inspect + puts fond + + fond.legacy_id = document.xpath("did/unitid").text.squish + fond.db_source = self.identifier + fond.created_by = user_id + fond.updated_by = user_id + fond.group_id = group_id + fond.created_at = datetime + fond.updated_at = datetime + + if document.xpath("//ead/archdesc/accessrestrict").present? + fond.access_condition = document.xpath("//ead/archdesc/accessrestrict").first.text + fond.access_condition_note = document.xpath("//ead/archdesc/accessrestrict/p").first.text + end + fond.published = false + if document.xpath("//ead/archdesc/processinfo/p").first.text.downcase == "pubblicata" + fond.published = true + end + + fond.history = document.xpath("//ead/archdesc/custodhist/p").text.squish + fond.length = document.xpath("//ead/archdesc/did/physdescstructured/quantity").text + #fond.extent = document.xpath("//ead/archdesc/did/physdescstructured/descriptivenote/p").text + fond.extent = document.xpath("//ead/archdesc/did/physdesc").text.squish + fond.description = document.xpath("//ead/archdesc/scopecontent/p").text.squish + fond.arrangement_note = document.xpath("//ead/archdesc/scopecontent/p").text.squish + + fond.sneaky_save! + + self.importable_id = fond.id + + if document.xpath("//ead/archdesc/processinfo/processinfo/p").present? + document.xpath("//ead/archdesc/processinfo[@localtype='compilatori']/processinfo[@localtype='compilatore']").each do |pi| + editor = FondEditor.new + editor.fond_id = fond.id + editor.name = pi.xpath("p/persname/part[@localtype='compilatore']").text + editor.qualifier = pi.xpath("p/persname/part[@localtype='qualifica']").text + tipo_intervento = pi.xpath("p/persname/part[@localtype='tipoIntervento']").text + if tipo_intervento == "inserimento" || tipo_intervento == "created" + editor.editing_type = "inserimento dati" + elsif tipo_intervento == "modifica" || tipo_intervento == "updated" + editor.editing_type = "aggiornamento scheda" + end + editor.edited_at = Date.parse pi.xpath("p/date").text + editor.save! + end + end + + puts fond.inspect + puts fond + + if document.xpath("//ead/archdesc/controlaccess/genreform").present? + document.xpath("//ead/archdesc/controlaccess/genreform").each do |fond_document| + rel__f_d = RelFondDocumentForm.new + rel__f_d.name = fond_document.xpath("part[@localtype='denominazione']").first.text.squish + rel__f_d.description = fond_document.xpath("part[@localtype='descrizione']").first.text.squish + rel__f_d.note = fond_document.xpath("part[@localtype='note']").first.text.squish + 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 + rel__f_d.save! + else + puts("Nessun DocumentForm trovato con il nome inserito. Non e' stato aggiunto alcun record del tipo 'RelFondDocumentForm'") + end + end + end + + #altre denominazioni + document.xpath("//ead/archdesc/did/unittitle").each do |unittitle| + if (unittitle.text != fond.name) + fond_name = FondName.new + fond_name.fond_id = fond.id + fond_name.name = unittitle.text + fond_name.created_at = datetime + fond_name.updated_at = datetime + fond_name.qualifier = "O" + fond_name.note = "" + if unittitle.xpath("@localtype").text == "denominazioneParallela" + fond_name.note = "Denominazione parallela;" + end + if unittitle.xpath("@lang").text.present? + fond_name.note += " Codice lingua: " + unittitle.xpath("@lang").text + end + fond_name.save! + end + end + + if document.xpath("boolean(//ead/archdesc/did/unitdatestructured/dateset)") + event = FondEvent.new + event.fond_id = fond.id + import_dateset(document.xpath("//ead/archdesc/did/unitdatestructured/dateset").first, event, datetime) + end + Rails.logger.info "Salvataggio complesso importato da import.rb > import_fond" + fond.save + Rails.logger.info "Salvataggio complesso COMPLETATO da import.rb > import_fond" + end + + #import unità archivistiche + #document Nokogiri::XML + #user_id utente che effettua l'import + #group_id gruppo dell'utente che effettua l'import + def import_unit(document, user_id, group_id) + root_unit_path = document.xpath("ead/archdesc/dsc/c") + + #La parte commentata serve ad importare la gerarchia delle unita in un fondo esistente nel db. + #fond_id = document.xpath("ead/control/recordid").text.to_i + #Rails.logger.info "Le unita' del file verranno importate nel complesso #{fond_id} del database, se presente" + #if Fond.exists?(fond_id) + # Rails.logger.info "complesso archivistico con id: #{fond_id} presente" + # fond = Fond.find(fond_id) + # if fond.ancestry == nil + # root_fond_id = fond_id + # else + # root_fond_id = fond.ancestry.root.id + # end + # import_unit_hierarchy root_unit_path, root_fond_id, fond_id, user_id, group_id, nil + #else + # Rails.logger.info "Complesso con id #{fond_id} non presente nel database, ne verra' creato uno nuovo per contenere le unita'" + + Rails.logger.info "Verra` importata la gerarchia dei complessi con le loro unita`" + self.importable_id = import_fond_hierarchy document.xpath("ead/archdesc"), user_id, group_id, '' + #end + root_unit = Unit.where(db_source: self.identifier, legacy_id: root_unit_path.xpath("did/unitid/@identifier").text).first + #self.importable_id = root_unit.id + Rails.logger.info "Unita' salvate a partire dalla radice #{root_unit_path.xpath("did/unitid/@identifier").text}, ora rappresentata dall'id #{self.importable_id}" + end + + #mapping tipologia di intervento + def import_editing_type(event_type) + editing_type = "" + + if event_type == "created" || event_type == "derived" + editing_type = "inserimento dati" + elsif event_type == "updated" + editing_type = "aggiornamento scheda" + elsif event_type == "revised" + editing_type = "revisione" + end + + return editing_type + end + + def import_agent_type(agent_type) + if agent_type == 'human' + 'persona' + elsif agent_type == 'machine' + 'software' + else + agent_type + end + end + + #mapping qualifica altra denominazione + def import_qualifer_type(localType) + qualifier = "" + + if localType == "altraDenominazione" + qualifier = "OT" + elsif localType == "acronimo" + qualifier = "AC" + else + qualifier = "OT" + end + + return qualifier + end + + def import_level_type(level) + case level + when "fonds" + "fondo" + when "recordgrp" + "complesso di fondi" + when "subfonds" + "sezione" + when "series" + "serie" + when "subseries" + "sottoserie" + when "subsubseries" + "sottosottoserie" + else + level + end + end + + #estrae la datazione dall'xml del tracciato EAD3 e la salva sul database + def import_dateset(dateset, event, datetime) + Rails.logger.info "inizio funzione import_dateset()" + event.preferred = true + event.is_valid = true + event.created_at = datetime + event.updated_at = datetime + + d = extract_archidate(dateset) + + event.start_date_display = d[:start_date_display] + event.start_date_from = d[:start_date_from] + event.start_date_to = d[:start_date_to] + event.start_date_format = d[:start_date_format] + event.start_date_spec = d[:start_date_spec] + event.start_date_valid = d[:start_date_valid] + + event.end_date_display = d[:end_date_display] + event.end_date_from = d[:end_date_from] + event.end_date_to = d[:end_date_to] + event.end_date_format = d[:end_date_format] + event.end_date_spec = d[:end_date_spec] + event.end_date_valid = d[:end_date_valid] + + event.note = d[:note] + + Rails.logger.info "fine funzione import_dateset(), salvataggio..." + Rails.logger.info "XML - [ #{dateset.text} \n Data = #{event.inspect}]" + event.sneaky_save + Rails.logger.info("...dateset salvato.") + end + + def extract_archidate(xml_item) + Rails.logger.info xml_item + ret = {} + + #Estremo cronologico iniziale uguale a estremo cronologico finale + if xml_item.xpath("datesingle[not(@localtype)]").present? || xml_item.xpath("dateSingle[not(@localtype)]").present? + single_date = {} + if xml_item.xpath("datesingle[not(@localtype)]").present? + single_date = extract_singledate(xml_item.xpath("datesingle[not(@localtype)]").first, true) + end + if xml_item.xpath("dateSingle[not(@localtype)]").present? + single_date = extract_singledate(xml_item.xpath("dateSingle[not(@localtype)]").first, true) + end + ret[:start_date_from] = single_date[:date_from] + ret[:start_date_to] = single_date[:date_to] + ret[:start_date_display] = single_date[:date_display] + ret[:start_date_format] = single_date[:date_format] + ret[:start_date_spec] = single_date[:date_spec] + ret[:start_date_valid] = single_date[:date_valid] + + if xml_item.xpath("datesingle[not(@localtype)]").present? + single_date = extract_singledate(xml_item.xpath("datesingle[not(@localtype)]").first, false, true) + end + if xml_item.xpath("dateSingle[not(@localtype)]").present? + single_date = extract_singledate(xml_item.xpath("dateSingle[not(@localtype)]").first, false, true) + end + ret[:end_date_from] = single_date[:date_from] + ret[:end_date_to] = single_date[:date_to] + ret[:end_date_display] = single_date[:date_display] + ret[:end_date_format] = single_date[:date_format] + ret[:end_date_spec] = single_date[:date_spec] + ret[:end_date_valid] = single_date[:date_valid] + end + + #Estremo cronologico iniziale diverso da estremo cronologico finale + if xml_item.xpath("daterange").present? || xml_item.xpath("dateRange").present? + single_date = {} + if (xml_item.xpath("daterange").present?) + single_date = extract_singledate(xml_item.xpath("daterange/fromdate").first, true) + end + if (xml_item.xpath("dateRange").present?) + single_date = extract_singledate(xml_item.xpath("dateRange/fromDate").first, true) + end + + ret[:start_date_from] = single_date[:date_from] + ret[:start_date_to] = single_date[:date_to] + ret[:start_date_display] = single_date[:date_display] + ret[:start_date_format] = single_date[:date_format] + ret[:start_date_spec] = single_date[:date_spec] + ret[:start_date_valid] = single_date[:date_valid] + + if (xml_item.xpath("daterange").present?) + single_date = extract_singledate(xml_item.xpath("daterange/todate").first, false) + end + if (xml_item.xpath("dateRange").present?) + single_date = extract_singledate(xml_item.xpath("dateRange/toDate").first, false) + end + ret[:end_date_from] = single_date[:date_from] + ret[:end_date_to] = single_date[:date_to] + ret[:end_date_display] = single_date[:date_display] + ret[:end_date_format] = single_date[:date_format] + ret[:end_date_spec] = single_date[:date_spec] + ret[:end_date_valid] = single_date[:date_valid] + end + + #Gestione per existDates eac-cpf + if xml_item.xpath("date").present? + single_date = extract_singledate(xml_item.xpath("date").first, true) + + ret[:start_date_from] = single_date[:date_from] + ret[:start_date_to] = single_date[:date_to] + ret[:start_date_display] = single_date[:date_display] + ret[:start_date_format] = single_date[:date_format] + ret[:start_date_spec] = single_date[:date_spec] + ret[:start_date_valid] = single_date[:date_valid] + + single_date = extract_singledate(xml_item.xpath("date").first, false, true) + + ret[:end_date_from] = single_date[:date_from] + ret[:end_date_to] = single_date[:date_to] + ret[:end_date_display] = single_date[:date_display] + ret[:end_date_format] = single_date[:date_format] + ret[:end_date_spec] = single_date[:date_spec] + ret[:end_date_valid] = single_date[:date_valid] + end + + #Gestione note alla data + if xml_item.xpath("datesingle[@localtype='noteAllaData']").present? + ret[:note] = xml_item.xpath("datesingle[@localtype='noteAllaData']").first.text.gsub(/\t/, '') + + elsif xml_item.xpath("dateSingle[@localtype='noteAllaData']").present? + ret[:note] = xml_item.xpath("dateSingle[@localtype='noteAllaData']").first.text.gsub(/\t/, '') - custodian_editor = {'custodian_editor' => { - 'custodian_id'=> cust_id, - 'name'=> rel_c["agente"]["cognome"], - 'qualifier'=> nil, - 'editing_type'=> rel_c["tipoevento"], - 'edited_at'=> rel_c["dataevento"], - 'legacy_id'=> cust_id - } - } + elsif xml_item.xpath("datesingle[@localtype='notealladata']").present? + ret[:note] = xml_item.xpath("datesingle[@localtype='notealladata']").first.text.gsub(/\t/, '') - File.open(TMP_IMPORTS + "/data.json","a") do |f| - f.write(custodian_editor.to_json) - f.write("\r\n") - end - - end + elsif xml_item.xpath("dateSingle[@localtype='notealladata']").present? + ret[:note] = xml_item.xpath("dateSingle[@localtype='notealladata']").first.text.gsub(/\t/, '') - def rel_custodian_name(rel_c, cust_id) - custodian_name = {'custodian_name' => { - 'custodian_id'=> cust_id, - 'preferred'=> true, - 'name'=> rel_c, - 'qualifier'=> "AU", - 'note'=> '', - 'legacy_id'=> cust_id - } - } + elsif xml_item.xpath("descriptiveNote/p").present? + ret[:note] = xml_item.xpath("descriptiveNote/p").first.text.gsub(/\t/, '') + + end - File.open(TMP_IMPORTS + "/data.json","a") do |f| - f.write(custodian_name.to_json) - f.write("\r\n") - end + return ret end - def extract_fond(zip_data_file) - xml = File.open(zip_data_file).read - json = Hash.from_xml(xml).to_json - parsed_xml_to_json = ActiveSupport::JSON.decode(json) - @fond_leg_id = rand(1..1000) - - fond_name = parsed_xml_to_json["ead"]["control"]["recordid"].present? ? parsed_xml_to_json["ead"]["control"]["recordid"] : nil - fond_first_levels = {"recordgrp" => "complesso di fondi", - "fonds" => "fondo", "subfonds" => "subfondo", - "series" => "serie", "subseries" => "sottoserie"} - if(parsed_xml_to_json["ead"]["archdesc"]["level"].present?) - if(parsed_xml_to_json["ead"]["archdesc"]["level"].include? "otherlevel") - fond_type = fond_first_levels[parsed_xml_to_json["ead"]["archdesc"]["otherlevel"]] - else - fond_type = fond_first_levels[parsed_xml_to_json["ead"]["archdesc"]["level"]] - end - else - fond_type = nil - end - fond_length = parsed_xml_to_json["ead"]["archdesc"]["did"]["physdescstructured"]["quantity"].present? ? parsed_xml_to_json["ead"]["archdesc"]["did"]["physdescstructured"]["quantity"] : nil - fond_extent = parsed_xml_to_json["ead"]["archdesc"]["did"]["physdescstructured"]["descriptivenote"].present? ? parsed_xml_to_json["ead"]["archdesc"]["did"]["physdescstructured"]["descriptivenote"]["p"] : nil - fond_description = parsed_xml_to_json["ead"]["archdesc"]["scopecontent"].present? ? parsed_xml_to_json["ead"]["archdesc"]["scopecontent"]["p"] : nil - arrangement_note = parsed_xml_to_json["ead"]["archdesc"]["arrangement"].present? ? parsed_xml_to_json["ead"]["archdesc"]["arrangement"]["p"] : nil - access_condition_note = parsed_xml_to_json["ead"]["archdesc"]["accessrestrict"].present? ? parsed_xml_to_json["ead"]["archdesc"]["accessrestrict"]["p"] : nil - #use_condition_note = parsed_xml_to_json["ead"]["archdesc"]["custodhist"].present? ? parsed_xml_to_json["ead"]["archdesc"]["custodhist"]["p"] : nil - fond_history = parsed_xml_to_json["ead"]["archdesc"]["custodhist"].present? ? parsed_xml_to_json["ead"]["archdesc"]["custodhist"]["p"] : nil - - fond = {'fond' => { - 'ancestry_depth'=> 0, - 'position'=> rand(1..1000), - 'sequence_number'=> 1, - 'trashed'=> false, - 'trashed_ancestor_id'=> nil, - 'units_count'=> 0, - 'name'=> fond_name, - 'fond_type'=> fond_type, - 'length'=> fond_length, - 'extent'=> fond_extent, - 'abstract'=> nil, - 'description'=> fond_description, - 'arrangement_note'=> arrangement_note, - 'related_materials'=> nil, - 'access_condition'=> nil, - 'access_condition_note'=> access_condition_note, - 'history' => fond_history, - 'use_condition'=> nil, - 'use_condition_note'=> '', - 'type_materials'=> nil, - 'preservation'=> nil, - 'preservation_note'=> nil, - 'description_type'=> nil, - 'note'=> nil, - 'legacy_id'=> @fond_leg_id, - 'legacy_parent_id'=> nil, - 'published'=> true, - } - } + def extract_singledate(xml_item_date, start, date_open = false) + singledate = {} - File.open(TMP_IMPORTS + "/data.json","w+") do |f| - f.write(fond.to_json) - f.write("\r\n") - end + singledate[:date_display] = xml_item_date.text - if parsed_xml_to_json["ead"]["archdesc"]["did"]["unittitle"].kind_of?(Array) - names_array = parsed_xml_to_json["ead"]["archdesc"]["did"]["unittitle"] - names_array.delete_at(0) - names_array.each do |na| - fond_name = na - rel_fond_name(fond_name, @fond_leg_id) - end + if xml_item_date.xpath("boolean(@notbefore)") || xml_item_date.xpath("boolean(@notBefore)") + if xml_item_date.xpath("boolean(@notbefore)") + singledate[:date_from] = xml_item_date.xpath("@notbefore").first.text + end + if xml_item_date.xpath("boolean(@notBefore)") + singledate[:date_from] = xml_item_date.xpath("@notBefore").first.text + end + if xml_item_date.text[0..3].downcase == "sec." + singledate[:date_format] = "C" + else + singledate[:date_format] = "Y" + end + singledate[:date_spec] = "idem" + end + if xml_item_date.xpath("boolean(@notafter)") || xml_item_date.xpath("boolean(@notAfter)") + if xml_item_date.xpath("boolean(@notafter)") + singledate[:date_to] = xml_item_date.xpath("@notafter").first.text + end + if xml_item_date.xpath("boolean(@notAfter)") + singledate[:date_to] = xml_item_date.xpath("@notAfter").first.text + end + if xml_item_date.text[0..3].downcase == "sec." + singledate[:date_format] = "C" + else + singledate[:date_format] = "Y" + end + singledate[:date_spec] = "idem" + end + if xml_item_date.xpath("boolean(@standarddate)") || xml_item_date.xpath("boolean(@standardDate)") || xml_item_date.xpath("not(@*)") + if xml_item_date.xpath("boolean(@standarddate)") + singledate[:date_from] = xml_item_date.xpath("@standarddate").text + end + if xml_item_date.xpath("boolean(@standardDate)") + singledate[:date_from] = xml_item_date.xpath("@standardDate").text + end + if xml_item_date.xpath("not(@*)") + singledate[:date_from] = xml_item_date.text end - #fond_event = parsed_xml_to_json["ead"]["archdesc"]["did"] - #rel_fond_event(fond_event, @fond_leg_id) + singledate[:date_format] = "YMD" + if singledate[:date_from].size == 4 + singledate[:date_format] = "Y" + if start + singledate[:date_from] << "-01-01" + else + singledate[:date_from] << "-12-31" + end + elsif singledate[:date_from].size == 7 && singledate[:date_from].include?("-") + singledate[:date_format] = "YM" + if start + singledate[:date_from] << "-01" + else + singledate[:date_from] << "-#{Time.days_in_month(date[5..6].to_i, date[0..3].to_i)}" + end + elsif singledate[:date_from].size == 6 && !singledate[:date_from].include?("-") + singledate[:date_format] = "YM" + singledate[:date_from] = singledate[:date_from][0..3] + "-" + singledate[:date_from][4..5] + if start + singledate[:date_from] << "-01" + else + singledate[:date_from] << "-#{Time.days_in_month(date[5..6].to_i, date[0..3].to_i)}" + end + elsif singledate[:date_from].size == 8 && !singledate[:date_from].include?("-") + singledate[:date_from] = singledate[:date_from][0..3] + "-" + singledate[:date_from][4..5] + "-" + singledate[:date_from][6..7] + end - if parsed_xml_to_json["ead"]["archdesc"]["dsc"]["c"] != nil - #length_c1 = parsed_xml_to_json["ead"]["archdesc"]["dsc"]["c"].length - length_c1 = 1 - num_c1 = 0 - begin - leg_id_for_children = rand(1..1000) - rel_fonds_def(parsed_xml_to_json["ead"]["archdesc"]["dsc"]["c"], 1, 1, 2, @fond_leg_id, leg_id_for_children) - #fond_event = parsed_xml_to_json["ead"]["archdesc"]["dsc"]["c"]["did"] - #rel_fond_event(fond_event, leg_id_for_children) - if parsed_xml_to_json["ead"]["archdesc"]["dsc"]["c"]["did"]["unittitle"].kind_of?(Array) - names_array = parsed_xml_to_json["ead"]["archdesc"]["dsc"]["c"]["did"]["unittitle"] - names_array.delete_at(0) - names_array.each do |na| - fond_name = na - rel_fond_name(fond_name, leg_id_for_children) - end - end - - if parsed_xml_to_json["ead"]["archdesc"]["dsc"]["c"]["c"].present? - if parsed_xml_to_json["ead"]["archdesc"]["dsc"]["c"]["c"].kind_of?(Array) - length_c2 = parsed_xml_to_json["ead"]["archdesc"]["dsc"]["c"]["c"].length - num_c2 = 0 - begin - rel_f = parsed_xml_to_json["ead"]["archdesc"]["dsc"]["c"]["c"][num_c2] - new_leg_id_for_children = rand(1..1000) - rel_fonds_def(rel_f, 2, num_c1+1, num_c1+3, leg_id_for_children, new_leg_id_for_children) - #fond_event = parsed_xml_to_json["ead"]["archdesc"]["dsc"]["c"]["c"][num_c2]["did"] - #rel_fond_event(fond_event, new_leg_id_for_children) - if parsed_xml_to_json["ead"]["archdesc"]["dsc"]["c"]["c"][num_c2]["did"]["unittitle"].kind_of?(Array) - names_array = parsed_xml_to_json["ead"]["archdesc"]["dsc"]["c"]["c"][num_c2]["did"]["unittitle"] - names_array.delete_at(0) - names_array.each do |na| - fond_name = na - rel_fond_name(fond_name, new_leg_id_for_children) - end - end - num_c2 +=1 - end while length_c2 > num_c2 - else - rel_f = parsed_xml_to_json["ead"]["archdesc"]["dsc"]["c"]["c"] - new_leg_id_for_children = rand(1..1000) - rel_fonds_def(rel_f, 2, num_c1+1, num_c1+3, leg_id_for_children, new_leg_id_for_children) - #fond_event = parsed_xml_to_json["ead"]["archdesc"]["dsc"]["c"]["c"]["did"] - #rel_fond_event(fond_event, new_leg_id_for_children) - if parsed_xml_to_json["ead"]["archdesc"]["dsc"]["c"]["c"]["did"]["unittitle"].kind_of?(Array) - names_array = parsed_xml_to_json["ead"]["archdesc"]["dsc"]["c"]["c"]["did"]["unittitle"] - names_array.delete_at(0) - names_array.each do |na| - fond_name = na - rel_fond_name(fond_name, new_leg_id_for_children) - end - end - end - end - num_c1 +=1 - end while length_c1 > num_c1 - end + if singledate[:date_format] == "YMD" && singledate[:date_display].size == 4 && singledate[:date_display].scan(/\D/).empty? + singledate[:date_format] = "Y" + end - length_editor = parsed_xml_to_json["ead"]["control"]["maintenancehistory"]["maintenanceevent"].length + singledate[:date_to] = singledate[:date_from] + end - num = 0 - begin - fond_editor = parsed_xml_to_json["ead"]["control"]["maintenancehistory"]["maintenanceevent"][num] - rel_fond_editor(fond_editor, @fond_leg_id) - num +=1 - end while length_editor > num - end + if singledate.key?(:date_from) && singledate[:date_from].size == 8 && !singledate[:date_from].include?("-") + singledate[:date_from] = singledate[:date_from][0..3] + "-" + singledate[:date_from][4..5] + "-" + singledate[:date_from][6..7] + end - def rel_fond_name(rel_f, fond_id) - fond_name_rel = {'fond_name' => { - 'fond_id'=> fond_id, - 'name'=> rel_f, - 'qualifier'=> 'O', - 'note'=> '', - 'legacy_id'=> fond_id - } - } - - File.open(TMP_IMPORTS + "/data.json","a") do |file| - file.write(fond_name_rel.to_json) - file.write("\r\n") - end - end + if singledate.key?(:date_to) && singledate[:date_to].size == 8 && !singledate[:date_to].include?("-") + singledate[:date_to] = singledate[:date_to][0..3] + "-" + singledate[:date_to][4..5] + "-" + singledate[:date_to][6..7] + end - def rel_fond_editor(rel_f, fond_id) + if singledate[:date_display].include? "ante" + singledate[:date_spec] = "ante" + elsif singledate[:date_display].include? "post" + singledate[:date_spec] = "post" + elsif singledate[:date_display].include? "circa" + singledate[:date_spec] = "circa" + else + singledate[:date_spec] = "idem" + end - fond_editor_rel = {'fond_editor' => { - 'fond_id'=> fond_id, - 'name'=> rel_f["agent"], - 'qualifier'=> rel_f["agent"], - 'editing_type'=> rel_f["eventtype"]["value"], - 'edited_at'=> rel_f["eventdatetime"], - 'legacy_id'=> fond_id - } - } - File.open(TMP_IMPORTS + "/data.json","a") do |file| - file.write(fond_editor_rel.to_json) - file.write("\r\n") - end - end + # Gestione estremo aperto (se non data singola) + exist_notbefore = xml_item_date.xpath("boolean(@notbefore)") || xml_item_date.xpath("boolean(@notBefore)") + exist_notafter = xml_item_date.xpath("boolean(@notafter)") || xml_item_date.xpath("boolean(@notAfter)") + if ((singledate[:date_display].empty? || singledate[:date_display] == "?" || singledate[:date_display] == "s.d." || singledate[:date_display] == "non indicata") && !start) || (date_open && !(exist_notbefore && exist_notafter)) + singledate[:date_format] = "O" + singledate[:date_valid] = "U" + singledate[:date_spec] = "idem" + singledate[:date_from] = "9999-12-31" + singledate[:date_to] = "9999-12-31" + end - def rel_fond_event(rel_f, fond_id) - if(rel_f["normal"] != nil) - date = rel_f["normal"] - st_date = date.split('/')[0][0..3] - end_date = date.split('/')[1][0..3] - else - date = rel_f["unitdate"] - if date.include? "[" - st_date = date[1..4] - end_date = date[1..4] - elsif date.include? " - " - st_date = date.split(' - ')[0] - end_date = date.split(' - ')[1] + #@certainty + if !singledate.key?(:date_valid) + if (singledate[:date_display].start_with?("[") and singledate[:date_display].end_with?("?]")) + singledate[:date_valid] = "UQ" + elsif singledate[:date_display].start_with?("[") + singledate[:date_valid] = "Q" + elsif singledate[:date_display].end_with?("?") + singledate[:date_valid] = "U" else - st_date = date - end_date = date + singledate[:date_valid] = "C" end end - - fond_event_rel = {'fond_event' => { - 'fond_id'=> fond_id, - 'preferred'=> true, - 'is_valid'=> true, - 'start_date_place'=> nil, - 'start_date_spec'=> 'idem', - 'start_date_from'=> st_date + '-01-01', - 'start_date_to'=> st_date + '-12-31', - 'start_date_valid'=> 'C', - 'start_date_format'=> 'Y', - 'start_date_display'=> st_date, - 'end_date_place'=> nil, - 'end_date_spec'=> 'idem', - 'end_date_from'=> end_date + '-01-01', - 'end_date_to'=> end_date + '-12-31', - 'end_date_valid'=> 'C', - 'end_date_format'=> 'Y', - 'end_date_display'=> end_date, - 'legacy_display_date'=> nil, - 'order_date'=> st_date + '-01-01|1|' + st_date + '-12-31|0|' + end_date + '-01-01|1|' + end_date + '-12-31|0|', - 'note'=> '', - 'legacy_id'=> fond_id - } - } - File.open(TMP_IMPORTS + "/data.json","a") do |file| - file.write(fond_event_rel.to_json) - file.write("\r\n") - end - end - def rel_fonds_def(rel_f, dep, pos, seq, fond_leg_id,leg_id_for_children) - if rel_f["did"]["unittitle"].kind_of?(Array) - names_array = rel_f["did"]["unittitle"] - fond_rel_name = names_array[0] - else - fond_rel_name = rel_f["did"]["unittitle"] - end - - fond_first_levels = {"recordgrp" => "complesso di fondi", - "fonds" => "fondo", "subfonds" => "subfondo", - "series" => "serie", "subseries" => "sottoserie"} - if(rel_f["level"].present?) - if(rel_f["level"].include? "otherlevel") - fond_type = fond_first_levels[rel_f["otherlevel"]] - else - fond_type = fond_first_levels[rel_f["level"]] - end - else - fond_type = nil - end - fond_length = rel_f["did"]["physdescstructured"]["quantity"].present? ? rel_f["did"]["physdescstructured"]["quantity"] : nil - fond_extent = rel_f["did"]["physdescstructured"]["descriptivenote"].present? ? rel_f["did"]["physdescstructured"]["descriptivenote"]["p"] : nil - fond_description = rel_f["scopecontent"].present? ? rel_f["scopecontent"]["p"] : nil - arrangement_note = rel_f["arrangement"].present? ? rel_f["arrangement"]["p"] : nil - access_condition_note = rel_f["accessrestrict"].present? ? rel_f["accessrestrict"]["p"] : nil - #use_condition_note = parsed_xml_to_json["ead"]["archdesc"]["custodhist"].present? ? parsed_xml_to_json["ead"]["archdesc"]["custodhist"]["p"] : nil - fond_history = rel_f["custodhist"].present? ? rel_f["custodhist"]["p"] : nil - - - fond_rel = {'fond' => { - 'ancestry_depth'=> dep, - 'position'=> pos, - 'sequence_number'=> seq, - 'trashed'=> false, - 'trashed_ancestor_id'=> nil, - 'units_count'=> 0, - 'name'=> fond_rel_name, - 'fond_type'=> fond_type, - 'length'=> fond_length, - 'extent'=> fond_extent, - 'abstract'=> nil, - 'description'=> fond_description, - 'arrangement_note'=> arrangement_note, - 'related_materials'=> nil, - 'access_condition'=> nil, - 'access_condition_note'=> access_condition_note, - 'history' => fond_history, - 'use_condition'=> nil, - 'use_condition_note'=> nil, - 'type_materials'=> nil, - 'preservation'=> nil, - 'preservation_note'=> nil, - 'description_type'=> nil, - 'note'=> nil, - 'legacy_id'=> leg_id_for_children, - 'legacy_parent_id'=> fond_leg_id, - 'published'=> true - } - } - File.open(TMP_IMPORTS + "/data.json","a") do |file| - file.write(fond_rel.to_json) - file.write("\r\n") - end + return singledate end + #calcolo data finale della data secolare + #il calcolo si base sui valori presenti nella lib archidate + def calc_end_periodo_data_secolare(date, date_display) + date_obj = Date::strptime(date, "%Y-%m-%d") + + if date_display.include?("prima metà") || date_display.include?("seconda metà") + date_str = date_obj.next_year(49).strftime("%Y-%m-%d") + elsif date_display.include?("inizio") || date_display.include?("fine") || date_display.include?("metà") + date_str = date_obj.next_year(9).strftime("%Y-%m-%d") + elsif date_display.include?("quarto") + date_str = date_obj.next_year(24).strftime("%Y-%m-%d") + else + date_str = "" + end -def import_zip_file(user, ability) - - @extracted_files.each do |ef| - if ef.to_s.include? TMP_IMPORTS + "/#{self.id}_ca" - extract_fond(ef) - elsif ef.to_s.include? TMP_IMPORTS + "/#{self.id}_data-custodians.xml" - extract_custodian(ef) - elsif ef.to_s.include? TMP_IMPORTS + "/#{self.id}_sp" - extract_creator(ef) - end - end + return date_str + end - #extract_fond(zip_data_file) - #if File.exist?(TMP_IMPORTS + "/#{self.id}_data-creator.xml") - # extract_creator(TMP_IMPORTS + "/#{self.id}_data-creator.xml") - #end - #if File.exist?(TMP_IMPORTS + "/#{self.id}_data-custodian.xml") - # extract_custodian(TMP_IMPORTS + "/#{self.id}_data-custodian.xml") - #end - - #extract_source(TMP_IMPORTS + "/#{self.id}_data-#{custodian}.xml") unless File.exist?(TMP_IMPORTS + "/#{self.id}_data-#{custodian}.xml") - #begin - # case self.importable_type - # when /Fond/ - # extract_fond(zip_data_file) - # when /Custodian/ - # extract_custodian(zip_data_file) - # when /Creator/ - # extract_creator(zip_data_file) - # when /Source/ - # extract_source(zip_data_file) - # end - #end - data_file = TMP_IMPORTS + "/data.json" - begin - lines = File.readlines(data_file) + #calcolo data iniziale della data secolare + #il calcolo si base sui valori presenti nella lib archidate + def calc_start_periodo_data_secolare(date, date_display) + date_obj = Date::strptime(date, "%Y-%m-%d") + + if date_display.include?("prima metà") || date_display.include?("seconda metà") + date_str = date_obj.next_year(-49).strftime("%Y-%m-%d") + elsif date_display.include?("inizio") || date_display.include?("fine") || date_display.include?("metà") + date_str = date_obj.next_year(-9).strftime("%Y-%m-%d") + elsif date_display.include?("quarto") + date_str = date_obj.next_year(-24).strftime("%Y-%m-%d") + else + date_str = "" + end - unit_aef_import_units_count = 0 + return date_str + end + #import xml relativo ai tracciati EAD3, SCONS2, EAC-CPF, ICAR-IMPORT + #ritorna 0: errore di import + # 1: import ok + # 2: errore di validazione xml + def import_xml_file(user, ability) + begin ActiveRecord::Base.transaction do + document = Nokogiri::XML(File.open(xml_data_file)) - model = nil - prev_model = nil - object = nil - - lines.each do |line| - next if line.blank? - data = ActiveSupport::JSON.decode(line.strip) - key = data.keys.first - ipdata = data[key] - - model = key.camelize.constantize - - ipdata.delete_if{|k, v| not model.column_names.include? k} - + if (!document.errors.empty?) + Rails.logger.info("errore: syntax error in xml") + return 0 + end - object = model.new(ipdata) + #rimozione namespace: ad esempio xsi:schemaLocation diventa schemaLocation + #per poter usare xpath più agevolmente il namespace è rimosso + document.remove_namespaces! - object.db_source = self.identifier + group_id = "" + if user.is_multi_group_user?() + group_id = ability.target_group_id + else + group_id = user.rel_user_groups[0].group_id + end - if object.has_attribute? 'group_id' - object.group_id = if user.is_multi_group_user?() then ability.target_group_id else user.rel_user_groups[0].group_id end + #l'xsd del tracciato EAD3 ha un elemento non deterministico + #e.anyname + #quando è istanziato l'oggetto schema è lanciata l'eccezione + #Nokogiri::XML::SyntaxError: complex type 'e.anyname': The content model is not determinist. + #non sembra essere possibile utilizzare l'xsd con la versione attuale di nokogiri + #non è inoltre possibile aggiornare nokogiri perché le versioni successive non sono compatibili con la versione di ruby utilizzata + #perciò la validazione non è effettuata in caso di EAD3 + + skip_validation = true + + xsd_link = "" + header_tag = "" + if (document.xpath("boolean(//icar-import)")) + header_tag = "icar-import" + skip_validation = true + elsif (document.xpath("boolean(//eac-cpf)")) + header_tag = "eac-cpf" + elsif (document.xpath("boolean(//scons)")) + header_tag = "scons" + elsif (document.xpath("boolean(//ead)")) + header_tag = "ead" + skip_validation = true + elsif (document.xpath("boolean(//icar-import)")) + header_tag = "icar-import" + skip_validation = true + else + Rails.logger.info("error: l'xml non è relativo al formato SCONS2, EAC-CPF, EAD3 o ICAR-IMPORT") + return 0 + end + document.xpath("//" + header_tag + "/@schemaLocation").first.value.split(" ").each do |schemaLocation| + if (schemaLocation.start_with?("http") && schemaLocation.end_with?(".xsd")) + xsd_link = schemaLocation + break end + end + if xsd_link == "" + Rails.logger.info("error: l'xml non contiene il link all'xsd") + return 0 + end - object.created_by = user.id if object.has_attribute? 'created_by' - object.updated_by = user.id if object.has_attribute? 'updated_by' - - object.sneaky_save! - if model != prev_model && !prev_model.nil? - prev_object = prev_model.new - set_lacking_field_values(prev_object) + #la versione di Ruby utilizzata non prevede i redirect da http a https o viceversa + #workaround: in redirect.uri c'è l'url verso il quale deve essere effettuata la redirezione + # si effettuano massimo 3 tentativi per cercare di accedere all'xsd + if !skip_validation + uri = URI.parse(xsd_link) + tries = 3 + begin + uri.open(redirect: false) + rescue OpenURI::HTTPRedirect => redirect + uri = redirect.uri #"Location" response header + retry if (tries -= 1) > 0 + raise end - prev_model = model + + schema = Nokogiri::XML::Schema(uri.read) + document_w_namespace = Nokogiri::XML(File.open(xml_data_file)) #la validazione deve essere condotta sull'xml completo di namespace + validation_errors = schema.validate(document_w_namespace) + else + validation_errors = Array.new end - if !object.nil? - set_lacking_field_values(object) + if validation_errors.empty? + + if (document.xpath("boolean(//icar-import)")) + import_icar_import document, user.id, group_id + self.importable_type = "Fond" + elsif (document.xpath("boolean(//eac-cpf)")) + if document.xpath("boolean(//eac-cpf/cpfDescription/identity/@localType)") + local_type = document.xpath("//eac-cpf/cpfDescription/identity/@localType").first.value + if (local_type == "profiloIstituzionale") + import_institution(document, user.id, group_id) + self.importable_type = "Institution" + elsif (local_type == "soggettoProduttore") + import_creator(document, user.id, group_id) + self.importable_type = "Creator" + end + elsif document.xpath("//eac-cpf/cpfDescription/identity/entityType").first.text == "person" && + document.xpath("boolean(//eac-cpf/cpfDescription/identity/entityId)") && + document.xpath("//eac-cpf/cpfDescription/identity/entityId/@localType").text == "" + import_anagraphic(document, user.id, group_id) + self.importable_type = "Anagraphic" + else + Rails.logger.info("error: l'xml relativo al formato EAC-CPF non è corretto") + return 0 + end + elsif (document.xpath("boolean(//scons)")) + import_custodian(document, user.id, group_id) + self.importable_type = "Custodian" + elsif (document.xpath("boolean(//ead)")) + if ((document.xpath("//ead/archdesc/did/*").size == 1) && (document.xpath("//ead/archdesc/did/unittitle").text == "") && + !document.xpath("boolean(//ead/archdesc/dsc)")) + import_source(document, user.id, group_id) + self.importable_type = "Source" + else + if !document.xpath("//ead/control/filedesc/titlestmt/titleproper/@encodinganalog").empty? && !document.xpath("//ead/control/recordid/@*").empty? + import_unit(document, user.id, group_id) + #import_fond(document, user.id, group_id) + self.importable_type = "Fond" + else + import_unit(document, user.id, group_id) + self.importable_type = "Fond" + # self.importable_type = "Unit" #TODO da rivedere: in realtà dovrebbe essere comunque l'import di un complesso, quello che contiene l'unita' + end + end + else + Rails.logger.info("error: l'xml non è relativo al formato SCONS2, EAC-CPF, EAD3 o ICAR-IMPORT") + return 0 + end + else + validation_errors.each do |error| + Rails.logger.info("validation error: #{error}") + end + return 2 end end - update_statements_zip - return true + return 1 rescue Exception => e - Rails.logger.info "import_zip_file Errore=" + e.message.to_s - return false + Rails.logger.info("\n\nEccezione - e.message: #{e.message}\n\n") + # Decommentare le due righe seguenti in caso di necessità + #Rails.logger.info("\n\nEccezione - e.backtrace") + #e.backtrace.each { |line| logger.error line } + return 0 ensure end + end - end - -# def import_aef_file(user) + # def import_aef_file(user) def import_aef_file(user, ability) -# Upgrade 2.2.0 fine -=begin - File.open(data_file) do |file| - begin - ActiveRecord::Base.transaction do - lines = file.enum_for(:each_line) - lines.each do |line| - next if line.blank? - data = ActiveSupport::JSON.decode(line.strip) - key = data.keys.first - model = key.camelize.constantize - data[key].delete_if{|k, v| not model.column_names.include? k} - object = model.new(data[key]) - object.db_source = self.identifier - object.group_id = user.group_id if object.has_attribute? 'group_id' - object.created_by = user.id if object.has_attribute? 'created_by' - object.updated_by = user.id if object.has_attribute? 'updated_by' - object.send(:create_without_callbacks) - end - end - update_statements - return true - rescue - return false - ensure - file.close - end - end -=end + + # Upgrade 2.2.0 fine + + #File.open(data_file) do |file| + # begin + # ActiveRecord::Base.transaction do + # lines = file.enum_for(:each_line) + # lines.each do |line| + # next if line.blank? + # data = ActiveSupport::JSON.decode(line.strip) + # key = data.keys.first + # model = key.camelize.constantize + # data[key].delete_if{|k, v| not model.column_names.include? k} + # object = model.new(data[key]) + # object.db_source = self.identifier + # object.group_id = user.group_id if object.has_attribute? 'group_id' + # object.created_by = user.id if object.has_attribute? 'created_by' + # object.updated_by = user.id if object.has_attribute? 'updated_by' + # object.send(:create_without_callbacks) + # end + # end + # update_statements + # return true + # rescue + # return false + # ensure + # file.close + # end + #end begin lines = File.readlines(data_file) -# Upgrade 2.2.0 inizio + # Upgrade 2.2.0 inizio unit_aef_import_units_count = 0 -# Upgrade 2.2.0 fine + # Upgrade 2.2.0 fine ActiveRecord::Base.transaction do -# Upgrade 2.0.0 inizio + # Upgrade 2.0.0 inizio model = nil prev_model = nil object = nil -# Upgrade 2.0.0 fine + # Upgrade 2.0.0 fine lines.each do |line| next if line.blank? data = ActiveSupport::JSON.decode(line.strip) key = data.keys.first -# Upgrade 2.1.0 inizio + # 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 + # 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} + # 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 + # 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' + # 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 ability.target_group_id else user.rel_user_groups[0].group_id end + object.group_id = if user.is_multi_group_user?() then + ability.target_group_id + else + user.rel_user_groups[0].group_id + end end if (self.is_unit_aef_file?) @@ -1016,12 +3578,12 @@ def import_aef_file(user, ability) unit_aef_import_units_count += 1 end end -# Upgrade 2.2.0 fine + # 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) + # Upgrade 2.0.0 inizio + #object.send(:create_without_callbacks) object.sneaky_save! if model != prev_model && !prev_model.nil? prev_object = prev_model.new @@ -1032,12 +3594,12 @@ def import_aef_file(user, ability) if !object.nil? set_lacking_field_values(object) end -# Upgrade 2.0.0 fine + # Upgrade 2.0.0 fine end -# Upgrade 2.2.0 inizio -# update_statements + # Upgrade 2.2.0 inizio + #update_statements update_statements(unit_aef_import_units_count) -# Upgrade 2.2.0 fine + # Upgrade 2.2.0 fine return true rescue Exception => e Rails.logger.info "import_aef_file Errore=" + e.message.to_s @@ -1046,31 +3608,20 @@ def import_aef_file(user, ability) end end - def update_statements_zip - begin - ActiveRecord::Base.transaction do - update_fonds_ancestry - update_one_to_many_relations - update_many_to_many_relations - self.importable_id = Fond.find_by_db_source_and_ancestry("#{self.identifier}", nil).id - end - end - end -# Upgrade 2.2.0 inizio -# def update_statements + # Upgrade 2.2.0 inizio + #def update_statements def update_statements(unit_aef_import_units_count) -# Upgrade 2.2.0 fine + # Upgrade 2.2.0 fine begin ActiveRecord::Base.transaction do -# Upgrade 2.2.0 inizio -=begin - update_fonds_ancestry - update_units_fond_id - update_subunits_ancestry if db_has_subunits? - update_one_to_many_relations - update_many_to_many_relations - update_digital_objects if db_has_digital_objects? -=end + # Upgrade 2.2.0 inizio + #update_fonds_ancestry + #update_units_fond_id + #update_subunits_ancestry if db_has_subunits? + #update_one_to_many_relations + #update_many_to_many_relations + #update_digital_objects if db_has_digital_objects? + if (self.is_unit_aef_file?) units_aef_file_update_tables(unit_aef_import_units_count) else @@ -1082,16 +3633,16 @@ def update_statements(unit_aef_import_units_count) update_digital_objects if db_has_digital_objects? end update_sc2_second_level_relations -# Upgrade 2.2.0 fine -# Upgrade 2.1.0 inizio - #if imported_file_version < "2.1.0" -# Upgrade 3.0.0 inizio + # Upgrade 2.2.0 fine + # Upgrade 2.1.0 inizio + #if imported_file_version < "2.1.0" + # Upgrade 3.0.0 inizio if !imported_file_version.nil? && imported_file_version < "2.1.0" -# Upgrade 3.0.0 fine + # Upgrade 3.0.0 fine Import.restore_d_f_s(self.identifier) Import.restore_bdm_oa(self.identifier) end -# Upgrade 2.1.0 fine + # Upgrade 2.1.0 fine if self.importable_type == 'Fond' self.importable_id = Fond.find_by_db_source_and_ancestry("#{self.identifier}", nil).id @@ -1102,10 +3653,10 @@ def update_statements(unit_aef_import_units_count) end end -# Upgrade 2.0.0 inizio -# assegna created_at, updated_at con la data corrente sul modello object + # Upgrade 2.0.0 inizio + # assegna created_at, updated_at con la data corrente sul modello object def set_lacking_field_values(object) - current_datetime = Time.now.utc.strftime("%Y-%m-%d %H:%M:%S") # nel db le date sono in utc + current_datetime = Time.now.utc.strftime("%Y-%m-%d %H:%M:%S") # nel db le date sono in utc table_name = object.class.table_name.to_s sqlSetClause = "" @@ -1115,7 +3666,9 @@ def set_lacking_field_values(object) sqlWhereClause = sqlWhereClause + " AND (created_at IS NULL)" end if object.attributes.include? "updated_at" - if !sqlSetClause.empty? then sqlSetClause = sqlSetClause + "," end + if !sqlSetClause.empty? then + sqlSetClause = sqlSetClause + "," + end sqlSetClause = sqlSetClause + "updated_at = '#{current_datetime}'" sqlWhereClause = sqlWhereClause + " AND (updated_at IS NULL)" end @@ -1125,37 +3678,45 @@ def set_lacking_field_values(object) ar_connection.execute(sqlStmt) end end -# Upgrade 2.0.0 fine + # Upgrade 2.0.0 fine def update_fonds_ancestry(parent_id = nil, ancestry = nil) -# Upgrade 2.0.0 inizio -# Fond.find_each(:conditions => {:legacy_parent_id => parent_id, :db_source => self.identifier}) do |node| + # Upgrade 2.0.0 inizio + #Fond.find_each(:conditions => {:legacy_parent_id => parent_id, :db_source => self.identifier}) do |node| Fond.where({:legacy_parent_id => parent_id, :db_source => self.identifier}).find_each do |node| -# Upgrade 2.0.0 fine + # Upgrade 2.0.0 fine node.without_ancestry_callbacks do node.update_attribute :ancestry, ancestry end - update_fonds_ancestry node.legacy_id, if ancestry.nil? then "#{node.id}" else "#{ancestry}/#{node.id}" end + update_fonds_ancestry node.legacy_id, if ancestry.nil? then + "#{node.id}" + else + "#{ancestry}/#{node.id}" + end end end -# Upgrade 2.2.0 inizio + # Upgrade 2.2.0 inizio def units_aef_file_update_tables(unit_aef_import_units_count) # maxsn = max sequence_number di tutte le unità del fondo considerato per l'importazione sqlWhereClause = "(fond_id=#{self.ref_fond_id}) AND (root_fond_id=#{prv_get_ref_root_fond_id}) AND (db_source IS NULL OR db_source <> '#{self.identifier}')" maxsn = Unit.where(sqlWhereClause).maximum("sequence_number") - if (maxsn.nil?) then maxsn = 0 end - + if (maxsn.nil?) then + maxsn = 0 + end + # maxpos = max position di tutte le unità non sotto-unità o sotto-sotto-unità del fondo considerato per l'importazione sqlWhereClause = "(fond_id=#{self.ref_fond_id}) AND (ancestry IS NULL) AND (db_source IS NULL OR db_source <> '#{self.identifier}')" maxpos = Unit.where(sqlWhereClause).maximum("position") - if (maxpos.nil?) then maxpos = 0 end + if (maxpos.nil?) then + maxpos = 0 + end # incrementa sequence_number delle unità del fondo radice considerato che avevano sequence_number > maxsn di un numero pari al numero di nuove unità importate (unit_aef_import_units_count) in modo da "fare spazio" nella sequenza alle nuove arrivate sqlWhereClause = "(root_fond_id=#{prv_get_ref_root_fond_id}) AND (db_source IS NULL OR db_source <> '#{self.identifier}') AND (sequence_number > #{maxsn})" sqlStmt = "UPDATE units SET sequence_number=sequence_number+#{unit_aef_import_units_count} WHERE #{sqlWhereClause}" ar_connection.execute(sqlStmt) - + # alle nuove unità importate si eseguono i seguenti aggiornamenti: # setta sequence_number in modo che si incastrino nella posizione prevista (in coda a quelle del fondo considerato) sqlWhereClause = "db_source = '#{self.identifier}'" @@ -1163,7 +3724,7 @@ def units_aef_file_update_tables(unit_aef_import_units_count) ar_connection.execute(sqlStmt) update_subunits_ancestry if db_has_subunits? - + posindex = maxpos + 1 prev_ancestry = "" prev_ancestry_depth = 0 @@ -1171,28 +3732,30 @@ def units_aef_file_update_tables(unit_aef_import_units_count) Unit.where(sqlWhereClause).order("ancestry_depth, sequence_number").each do |unit| ancestry = unit.ancestry - if (ancestry.nil?) then ancestry = "" end + if (ancestry.nil?) then + ancestry = "" + end ancestry_depth = unit.ancestry_depth if (ancestry != prev_ancestry || ancestry_depth != prev_ancestry_depth) posindex = 1 end unit.update_column("position", posindex) - + posindex += 1 prev_ancestry = ancestry prev_ancestry_depth = ancestry_depth end - + update_one_to_many_relations - + update_digital_objects if db_has_digital_objects? # aggiorna l'informazione sul numero di unità collegate al fondo di riferimento sqlStmt = "UPDATE fonds SET units_count=units_count+#{unit_aef_import_units_count} WHERE id=#{self.ref_fond_id}" ar_connection.execute(sqlStmt) end -# Upgrade 2.2.0 fine - + # Upgrade 2.2.0 fine + def update_units_fond_id case adapter when 'sqlite' @@ -1288,20 +3851,20 @@ def update_subunits_ancestry def update_one_to_many_relations entities = { - :fonds => ["fond_events", "fond_identifiers", "fond_langs", "fond_names", "fond_owners", "fond_urls", "fond_editors"], -# Upgrade 2.2.0 inizio -# :units => ["unit_events", "unit_identifiers", "unit_damages", "unit_langs", "unit_other_reference_numbers", "unit_urls", "unit_editors", "iccd_authors", "iccd_descriptions", "iccd_tech_specs", "iccd_damages", "iccd_subjects"], - :units => ["unit_events", "unit_identifiers", "unit_damages", "unit_langs", "unit_other_reference_numbers", "unit_urls", "unit_editors", "iccd_authors", "iccd_descriptions", "iccd_tech_specs", "iccd_damages", "iccd_subjects", "sc2s", "sc2_textual_elements", "sc2_visual_elements", "sc2_authors", "sc2_commissions", "sc2_techniques", "sc2_scales", "fsc_organizations", "fsc_nationalities", "fsc_codes", "fsc_opens", "fsc_closes", "fe_identifications", "fe_contexts", "fe_operas", "fe_designers", "fe_cadastrals", "fe_land_parcels", "fe_fract_land_parcels", "fe_fract_edil_parcels"], -# Upgrade 2.2.0 fine - :creators => ["creator_events", "creator_identifiers", "creator_legal_statuses", "creator_names", "creator_urls", "creator_activities", "creator_editors"], - :custodians => ["custodian_buildings", "custodian_contacts", "custodian_identifiers", "custodian_names", "custodian_owners", "custodian_urls", "custodian_editors"], -# Upgrade 2.0.0 inizio -# :projects => ["project_credits", "project_urls"], - :projects => ["project_managers", "project_stakeholders", "project_urls"], -# Upgrade 2.0.0 fine - :sources => ["source_urls"], - :institutions => ["institution_editors"], - :document_forms => ["document_form_editors"] + :fonds => ["fond_events", "fond_identifiers", "fond_langs", "fond_names", "fond_owners", "fond_urls", "fond_editors"], + # Upgrade 2.2.0 inizio + # :units => ["unit_events", "unit_identifiers", "unit_damages", "unit_langs", "unit_other_reference_numbers", "unit_urls", "unit_editors", "iccd_authors", "iccd_descriptions", "iccd_tech_specs", "iccd_damages", "iccd_subjects"], + :units => ["unit_events", "unit_identifiers", "unit_damages", "unit_langs", "unit_other_reference_numbers", "unit_urls", "unit_editors", "iccd_authors", "iccd_descriptions", "iccd_tech_specs", "iccd_damages", "iccd_subjects", "sc2s", "sc2_textual_elements", "sc2_visual_elements", "sc2_authors", "sc2_commissions", "sc2_techniques", "sc2_scales", "fsc_organizations", "fsc_nationalities", "fsc_codes", "fsc_opens", "fsc_closes", "fe_identifications", "fe_contexts", "fe_operas", "fe_designers", "fe_cadastrals", "fe_land_parcels", "fe_fract_land_parcels", "fe_fract_edil_parcels"], + # Upgrade 2.2.0 fine + :creators => ["creator_events", "creator_identifiers", "creator_legal_statuses", "creator_names", "creator_urls", "creator_activities", "creator_editors"], + :custodians => ["custodian_buildings", "custodian_contacts", "custodian_identifiers", "custodian_names", "custodian_owners", "custodian_urls", "custodian_editors"], + # Upgrade 2.0.0 inizio + # :projects => ["project_credits", "project_urls"], + :projects => ["project_managers", "project_stakeholders", "project_urls"], + # Upgrade 2.0.0 fine + :sources => ["source_urls"], + :institutions => ["institution_editors"], + :document_forms => ["document_form_editors"] } entities.each do |target, tables| @@ -1336,18 +3899,18 @@ def update_one_to_many_relations def update_many_to_many_relations tables = { - :rel_creator_creators => ["creators", "creators"], - :rel_creator_fonds => ["creators", "fonds"], - :rel_creator_institutions => ["creators", "institutions"], - :rel_creator_sources => ["creators", "sources"], - :rel_custodian_fonds => ["custodians", "fonds"], - :rel_custodian_sources => ["custodians", "sources"], - :rel_fond_document_forms => ["fonds", "document_forms"], - :rel_fond_headings => ["fonds", "headings"], - :rel_fond_sources => ["fonds", "sources"], - :rel_project_fonds => ["projects", "fonds"], - :rel_unit_headings => ["units", "headings"], - :rel_unit_sources => ["units", "sources"] + :rel_creator_creators => ["creators", "creators"], + :rel_creator_fonds => ["creators", "fonds"], + :rel_creator_institutions => ["creators", "institutions"], + :rel_creator_sources => ["creators", "sources"], + :rel_custodian_fonds => ["custodians", "fonds"], + :rel_custodian_sources => ["custodians", "sources"], + :rel_fond_document_forms => ["fonds", "document_forms"], + :rel_fond_headings => ["fonds", "headings"], + :rel_fond_sources => ["fonds", "sources"], + :rel_project_fonds => ["projects", "fonds"], + :rel_unit_headings => ["units", "headings"], + :rel_unit_sources => ["units", "sources"] } tables.each do |table, entities| @@ -1429,18 +3992,18 @@ def update_many_to_many_relations def update_digital_objects attachable_entities = { - 'Fond' => 'fonds', - 'Unit' => 'units', - 'Creator' => 'creators', - 'Custodian' => 'custodians', - 'Source' => 'sources' + 'Fond' => 'fonds', + 'Unit' => 'units', + 'Creator' => 'creators', + 'Custodian' => 'custodians', + 'Source' => 'sources' } attachable_entities.each do |value, table| -# Upgrade 2.0.0 inizio -# set = DigitalObject.all(:conditions => {:attachable_type => value, :db_source => self.identifier}) + # Upgrade 2.0.0 inizio + #set = DigitalObject.all(:conditions => {:attachable_type => value, :db_source => self.identifier}) set = DigitalObject.where({:attachable_type => value, :db_source => self.identifier}) -# Upgrade 2.0.0 fine + # Upgrade 2.0.0 fine unless set.blank? ids = set.map(&:id).join(',') case adapter @@ -1477,38 +4040,37 @@ def update_digital_objects end end - -# Upgrade 3.0.0 inizio -# Copia degli oggetti digitali dall'aef alla destinazione fisica - Zip::File.open("#{Rails.root}/public/imports/#{self.id}/#{self.data_file_name}") { |zip_file| - zip_file.each { |f| - if (f.name.include? "public") && (f.name.include? "digital_objects") - f_path=File.join("#{Rails.root}/", f.name) - FileUtils.mkdir_p(File.dirname(f_path)) - zip_file.extract(f, f_path){ true } unless File.exist?(f_path) - end - } + # Upgrade 3.0.0 inizio + # Copia degli oggetti digitali dall'aef alla destinazione fisica + Zip::File.open("#{Rails.root}/public/imports/#{self.id}/#{self.data_file_name}") { |zip_file| + zip_file.each { |f| + if (f.name.include? "public") && (f.name.include? "digital_objects") + f_path = File.join("#{Rails.root}/", f.name) + FileUtils.mkdir_p(File.dirname(f_path)) + zip_file.extract(f, f_path) { true } unless File.exist?(f_path) + end } - -# Upgrade 3.0.0 fine - + } + # Upgrade 3.0.0 fine end -# Upgrade 2.2.0 inizio + # Upgrade 2.2.0 inizio def update_sc2_second_level_relations tables = - [ - {:table => "sc2_attribution_reasons", :parent_table => "sc2_authors", :foreign_key => "sc2_author_id" }, - {:table => "sc2_commission_names", :parent_table => "sc2_commissions", :foreign_key => "sc2_commission_id" } - ] - + [ + {:table => "sc2_attribution_reasons", :parent_table => "sc2_authors", :foreign_key => "sc2_author_id"}, + {:table => "sc2_commission_names", :parent_table => "sc2_commissions", :foreign_key => "sc2_commission_id"} + ] + tables.each do |settings| table = settings[:table] parent_table = settings[:parent_table] if ((!table.nil? || table != "") && (!parent_table.nil? || parent_table != "")) foreign_key = settings[:foreign_key] - if (foreign_key.nil? || foreign_key == "") then foreign_key = "#{parent_table}".singularize + "_id" end + if (foreign_key.nil? || foreign_key == "") then + foreign_key = "#{parent_table}".singularize + "_id" + end case adapter when 'sqlite' sql_stmt = "UPDATE #{table} SET #{foreign_key} = (SELECT id @@ -1540,28 +4102,46 @@ def update_sc2_second_level_relations end end end -# Upgrade 2.2.0 fine + # Upgrade 2.2.0 fine def is_valid_file? + if @is_batch_import == true + src_file = File.join(Rails.root, "public", "imports", "batch_import", @batch_import_filename) + + dst_path = File.join(Rails.root, "public", "imports", self.id.to_s, ".") + dirname = File.dirname(dst_path) + unless File.directory?(dirname) + FileUtils.mkdir_p(dirname) + end + + extension = File.extname(@batch_import_filename).downcase + filename = "#{Time.now.strftime("%Y%m%d%H%M%S")}" + + full_dst_filename = filename + "_batch_import" + extension + dst_file = File.join(Rails.root, "public", "imports", self.id.to_s, full_dst_filename) + FileUtils.copy_file(src_file, dst_file) + + self.data_file_name = full_dst_filename + end + begin extension = File.extname(data_file_name).downcase.gsub('.', '') -# Upgrade 3.0.0 inizio - raise Zip::ZipInternalError unless ['aef', 'csv', 'zip'].include? extension - #raise Zip::ZipInternalError unless ['aef', 'csv'].include? extension - + # Upgrade 3.0.0 inizio + raise Zip::ZipInternalError unless ['aef', 'csv', 'xml'].include? extension + rescue Zip::ZipInternalError - raise 'Il file fornito non è di formato aef o csv o zip' + raise 'Formato file non supportato.' end -# Upgrade 3.0.0 fine + # Upgrade 3.0.0 fine if ['aef'].include? extension files = ["metadata.json", "data.json"] begin - # Upgrade 2.0.0 inizio - # Zip::ZipFile.open("#{Rails.root}/public/imports/#{self.id}/#{self.data_file_name}") do |zipfile| + # Upgrade 2.0.0 inizio + # Zip::ZipFile.open("#{Rails.root}/public/imports/#{self.id}/#{self.data_file_name}") do |zipfile| Zip::File.open("#{Rails.root}/public/imports/#{self.id}/#{self.data_file_name}") do |zipfile| - # Upgrade 2.0.0 fine - # Upgrade 3.0.0 inizio - # esclusi dal controllo di validità i file degli oggetti digitali + # Upgrade 2.0.0 fine + # Upgrade 3.0.0 inizio + # esclusi dal controllo di validità i file degli oggetti digitali zipfile.each do |entry| if (entry.directory?) && (entry.to_s.include? "public") next @@ -1574,7 +4154,7 @@ def is_valid_file? end end end - # Upgrade 3.0.0 fine + # Upgrade 3.0.0 fine end rescue Zip::ZipInternalError raise 'Il file fornito non è di formato aef' @@ -1584,7 +4164,8 @@ def is_valid_file? raise 'Il file aef è danneggiato' rescue Zip::ZipDestinationFileExistsError raise "Errore interno di #{APP_NAME}, stale files nella directory tmp" - rescue + rescue StandardError => e + Rails.logger.error e.inspect raise "Si è verificato un errore nell'elaborazione del file aef" end @@ -1609,136 +4190,17 @@ def is_valid_file? ensure file.close end - end - elsif ['zip'].include? extension - files = ["ca", "custodians", "sp", "sources"] - @extracted_files = [] - - metadata_files = ["metadata.json"] - begin - # Upgrade 2.0.0 inizio - # Zip::ZipFile.open("#{Rails.root}/public/imports/#{self.id}/#{self.data_file_name}") do |zipfile| - Zip::File.open("#{Rails.root}/public/imports/#{self.id}/#{self.data_file_name}") do |zipfile1| - # Upgrade 2.0.0 fine - # Upgrade 3.0.0 inizio - # esclusi dal controllo di validità i file degli oggetti digitali - zipfile1.each do |entry1| - if (entry1.directory?) && (entry1.to_s.include? "public") - next - else - if ((entry1.to_s.include? "public") || (entry1.to_s.include? "ca") || (entry1.to_s.include? "custodians") || (entry1.to_s.include? "sp") || (entry1.to_s.include? "sources")) - next - else - raise Zip::ZipEntryNameError unless metadata_files.include? entry1.to_s - zipfile1.extract(entry1, TMP_IMPORTS + "/#{self.id}_#{entry1.to_s}") - end - end - end - # Upgrade 3.0.0 fine - end - rescue Zip::ZipInternalError - raise 'Il file fornito non è di formato zip' - rescue Zip::ZipEntryNameError - raise 'Il file fornito contiene dati non validi' - rescue Zip::ZipCompressionMethodError - raise 'Il file zip è danneggiato' - rescue Zip::ZipDestinationFileExistsError - raise "Errore interno di #{APP_NAME}, stale files nella directory tmp" - rescue - raise "Si è verificato un errore nell'elaborazione del file zip" - end - - File.open(metadata_file) do |file| - begin - lines = file.enum_for(:each_line) - lines.each do |line| - next if line.blank? - data = ActiveSupport::JSON.decode(line.strip) - unless AEF_COMPATIBLE_VERSIONS.include?(data['version']) - aef_version = data['version'].to_s.scan(%r([0-9])).join(".") - raise "File incompatibile con questa versione di #{APP_NAME} (#{APP_VERSION}).
- Il file zip è stato prodotto con la versione #{aef_version}." - end - self.importable_type = data['attached_entity'] - - self.imported_file_version = data['version'].to_s.scan(%r([0-9])).join(".") - end - rescue Exception => e - raise e.message - ensure - file.close - end - end - - - - - begin - # Upgrade 2.0.0 inizio - # Zip::ZipFile.open("#{Rails.root}/public/imports/#{self.id}/#{self.data_file_name}") do |zipfile| - Zip::File.open("#{Rails.root}/public/imports/#{self.id}/#{self.data_file_name}") do |zipfile| - # Upgrade 2.0.0 fine - # Upgrade 3.0.0 inizio - # esclusi dal controllo di validità i file degli oggetti digitali - zipfile.each do |entry| - if (entry.directory?) && (entry.to_s.include? "public") - next - else - if ((entry.to_s.include? "public") || (entry.to_s.include? "metadata")) - next - else - entry_name = '' - entry_array = entry.to_s.split('-') - if entry_array[0].include? 'data' - entry_secondary_array = entry_array[1].split('.') - entry_name = entry_secondary_array[0] - else - entry_name = entry_array[0] - end - - raise Zip::ZipEntryNameError unless files.include? entry_name.to_s - zipfile.extract(entry, TMP_IMPORTS + "/#{self.id}_#{entry.to_s}") - @extracted_files.push(TMP_IMPORTS + "/#{self.id}_#{entry.to_s}") - #self.importable_type = "Fond" - #case entry.to_s - # when /fond/ - # self.importable_type = "Fond" - # when /custodian/ - # self.importable_type = "Custodian" - # when /creator/ - # self.importable_type = "Creator" - # when /source/ - # self.importable_type = "Source" - #end - #self.imported_file_version = APP_VERSION - end - - end - end - # Upgrade 3.0.0 fine - end - rescue Zip::ZipInternalError - raise 'Il file fornito non è di formato zip' - rescue Zip::ZipEntryNameError - raise 'Il file fornito contiene dati non validi' - rescue Zip::ZipCompressionMethodError - raise 'Il file zip è danneggiato' - rescue Zip::ZipDestinationFileExistsError - raise "Errore interno di #{APP_NAME}, stale files nella directory tmp" - rescue - raise "Si è verificato un errore nell'elaborazione del file zip" end - else + elsif ['csv'].include? extension self.importable_type = "Unit" end - # Upgrade 3.0.0 fine end def wipe_all_related_records tables = ar_connection.tables - ["schema_migrations"] begin ActiveRecord::Base.transaction do -# Upgrade 2.2.0 inizio + # Upgrade 2.2.0 inizio importable_type = Import.where("identifier = '#{self.identifier}'").first.importable_type if (importable_type == "Unit") # l'idea è decrementare il campo units_count dei fondi che contengono le unità importate che si stanno cancellando. @@ -1751,29 +4213,29 @@ def wipe_all_related_records sql_stmt = "update fonds set units_count=units_count-#{n_units} where id=#{fond_id}" ar_connection.execute(sql_stmt) end - end -# Upgrade 2.2.0 fine + end + # Upgrade 2.2.0 fine tables.each do |table| model = table.classify.constantize object = model.new if object.has_attribute? 'db_source' -# Upgrade 3.0.0 inizio -# Vengono eliminati fisicamente gli oggetti digitali precedentemente importati -# insieme alle cartelle corrispondenti e prima dell'eliminazione dei record corrispondenti su db + # Upgrade 3.0.0 inizio + # Vengono eliminati fisicamente gli oggetti digitali precedentemente importati + # insieme alle cartelle corrispondenti e prima dell'eliminazione dei record corrispondenti su db if table.include? "digital_objects" digital_object_ids = DigitalObject.where(:db_source => self.identifier).map(&:access_token) digital_object_ids.each do |doi| delete_digital_folder(doi) end end -# Upgrade 3.0.0 fine + # Upgrade 3.0.0 fine model.delete_all("db_source = '#{self.identifier}'") end end end return true rescue Exception => e -Rails.logger.info "################ Errore=" + e.message + Rails.logger.info "################ Errore=" + e.message return false end end @@ -1789,23 +4251,24 @@ def prv_get_ref_root_fond_id end return ref_root_fond_id end -# Upgrade 2.2.0 fine - + # Upgrade 2.2.0 fine def sanitize_file_name - extension = File.extname(data_file_name).downcase - filename = "#{Time.now.strftime("%Y%m%d%H%M%S")}" - self.data.instance_write(:file_name, "#{filename}#{extension}") + if !@is_batch_import + extension = File.extname(data_file_name).downcase + filename = "#{Time.now.strftime("%Y%m%d%H%M%S")}" + self.data.instance_write(:file_name, "#{filename}#{extension}") + end end def prv_adjust_ante_210_project(key, ipdata) begin if key == "project" case ipdata["project_type"] - when "riordino e schedatura" - ipdata["project_type"] = "riordino" - when "schedatura" - ipdata["project_type"] = "recupero" + when "riordino e schedatura" + ipdata["project_type"] = "riordino" + when "schedatura" + ipdata["project_type"] = "recupero" end end rescue Exception => e @@ -1824,51 +4287,51 @@ def prv_adjust_ante_210_project_credits(key, ipdata) if ipdata["credit_type"] == "PS" if ipdata.has_key?("qualifier") case ipdata["qualifier"] - when "coordinatore" - key = "project_stakeholder" - ipdata["qualifier"] = "coordinamento operativo" - when "finanziatore" - key = "project_stakeholder" - ipdata["qualifier"] = "finanziamento" - when "promotore" - key = "project_stakeholder" - ipdata["qualifier"] = "promozione" - when "realizzatore" - key = "project_stakeholder" - ipdata["qualifier"] = "realizzazione" - when "schedatore" - key = "project_manager" - when "responsabile scientifico" - key = "project_manager" -# Upgrade 2.1.0 inizio - else - key = "project_stakeholder" -# Upgrade 2.1.0 fine + when "coordinatore" + key = "project_stakeholder" + ipdata["qualifier"] = "coordinamento operativo" + when "finanziatore" + key = "project_stakeholder" + ipdata["qualifier"] = "finanziamento" + when "promotore" + key = "project_stakeholder" + ipdata["qualifier"] = "promozione" + when "realizzatore" + key = "project_stakeholder" + ipdata["qualifier"] = "realizzazione" + when "schedatore" + key = "project_manager" + when "responsabile scientifico" + key = "project_manager" + # Upgrade 2.1.0 inizio + else + key = "project_stakeholder" + # Upgrade 2.1.0 fine end end else # caso ipdata["credit_type"] == "PM" o ipdata["credit_type"] == qualsiasi altro valore if ipdata.has_key?("qualifier") case ipdata["qualifier"] - when "coordinatore" - key = "project_manager" - when "finanziatore" - key = "project_stakeholder" - ipdata["qualifier"] = "finanziamento" - when "promotore" - key = "project_stakeholder" - ipdata["qualifier"] = "promozione" - when "realizzatore" - key = "project_stakeholder" - ipdata["qualifier"] = "realizzazione" - when "schedatore" - key = "project_manager" - when "responsabile scientifico" - key = "project_manager" -# Upgrade 2.1.0 inizio - else - key = "project_manager" -# Upgrade 2.1.0 fine + when "coordinatore" + key = "project_manager" + when "finanziatore" + key = "project_stakeholder" + ipdata["qualifier"] = "finanziamento" + when "promotore" + key = "project_stakeholder" + ipdata["qualifier"] = "promozione" + when "realizzatore" + key = "project_stakeholder" + ipdata["qualifier"] = "realizzazione" + when "schedatore" + key = "project_manager" + when "responsabile scientifico" + key = "project_manager" + # Upgrade 2.1.0 inizio + else + key = "project_manager" + # Upgrade 2.1.0 fine end end end diff --git a/app/models/institution.rb b/app/models/institution.rb index 565d4a5..0aba35a 100644 --- a/app/models/institution.rb +++ b/app/models/institution.rb @@ -8,6 +8,8 @@ class Institution < ActiveRecord::Base has_many :institution_editors, -> { order(:edited_at) }, :dependent => :destroy # Upgrade 2.0.0 fine + has_one :import, :as => :importable, :dependent => :destroy + # Upgrade 2.2.0 inizio belongs_to :group # Upgrade 2.2.0 fine @@ -23,3 +25,4 @@ class Institution < ActiveRecord::Base end + diff --git a/app/models/source.rb b/app/models/source.rb index 93294eb..0c79e9d 100644 --- a/app/models/source.rb +++ b/app/models/source.rb @@ -19,6 +19,8 @@ class Source < ActiveRecord::Base # Upgrade 2.2.0 inizio has_one :first_digital_object, -> { where({:position => 1}) }, :as => :attachable, :class_name => DigitalObject # Upgrade 2.2.0 fine + + has_one :import, :as => :importable, :dependent => :destroy # Many-to-many associations (rel) # OPTIMIZE: valutare uso di Polymorphic Association. Quali pro/contro ? diff --git a/app/models/unit.rb b/app/models/unit.rb index c5349d8..6c7f3ca 100644 --- a/app/models/unit.rb +++ b/app/models/unit.rb @@ -4,6 +4,12 @@ class Unit < ActiveRecord::Base + # INIZIO - require richiesti per l'import batch + require File.join(File.dirname(__FILE__), ".", "unit_event.rb") + require File.join(File.dirname(__FILE__), ".", "term.rb") + require File.join(File.dirname(__FILE__), ".", "vocabulary.rb") + # FINE - require richiesti per l'import batch + MAX_LEVEL_OF_NODES = 2 cattr_reader :per_page @@ -83,7 +89,6 @@ class Unit < ActiveRecord::Base accepts_nested_attributes_for :fe_fract_edil_parcels, :allow_destroy => true, :reject_if => :fe_fract_edil_parcels_reject_if def fe_identifications_reject_if(attributes) - Rails.logger.info("qua dentro") exists = attributes[:id].present? empty = attributes[:code].blank? attributes.merge!({_destroy: 1}) if exists and empty @@ -119,13 +124,8 @@ def fe_cadastrals_reject_if(attributes) end def fe_land_parcels_reject_if(attributes) - Rails.logger.info("attributes[:id]: #{attributes[:id]}") exists = attributes[:id].present? - Rails.logger.info("exists: #{exists}") - - Rails.logger.info("attributes[:land_parcel_number]: #{attributes[:land_parcel_number]}") empty = attributes[:land_parcel_number].blank? - Rails.logger.info("empty: #{empty}") attributes.merge!({_destroy: 1}) if exists and empty return (!exists and empty) end @@ -619,3 +619,4 @@ def set_root_fond_id end end + diff --git a/app/views/creators/_creator_ead.xml.builder b/app/views/creators/_creator_ead.xml.builder index c8a1dbb..33bed30 100644 --- a/app/views/creators/_creator_ead.xml.builder +++ b/app/views/creators/_creator_ead.xml.builder @@ -41,16 +41,9 @@ xml.control do xml.citation "ISAAR(CPF)" end xml.maintenanceHistory do - xml.maintenanceEvent do - xml.eventType "created" - xml.eventDateTime "" - xml.agentType "human" - xml.agent "" - end - editors = creator.creator_editors if editors.present? - event_types = { + event_types = { "aggiornamento scheda" => "updated", "inserimento dati" => "created", "integrazione successiva" => "updated", @@ -61,16 +54,16 @@ xml.control do } editors.each do |editor| xml.maintenanceEvent do - if editor.editing_type.present? - editing_type = editor.editing_type.downcase - event_type = event_types.key?(editing_type) ? event_types[editing_type] : "unknown" - else - event_type = "unknown" - end + if editor.editing_type.present? + editing_type = editor.editing_type.downcase + event_type = event_types.key?(editing_type) ? event_types[editing_type] : "unknown" + else + event_type = "unknown" + end if editor.edited_at.present? - edited_at = editor.edited_at.strftime("%Y-%m-%dT%H:%M:%S") - end + edited_at = editor.edited_at.strftime("%Y-%m-%dT%H:%M:%S") + end xml.eventType event_type if !edited_at.nil? @@ -94,18 +87,34 @@ xml.cpfDescription do xml.entityType entityType case creator_type when 'c' - xml.nameEntry do - xml.part creator.preferred_name.name + parallel_names = Array.new + creator.other_names.each do |other_name| + if other_name.qualifier.downcase == "pa" + parallel_name = a = {'id' => other_name.id, 'name' => other_name.name, 'note' => other_name.note} + parallel_names << parallel_name + end + end + if parallel_names.empty? + xml.nameEntry do + xml.part creator.preferred_name.name + end + else + xml.nameEntryParallel do + xml.nameEntry do + xml.part creator.preferred_name.name + end + parallel_names.each do |parallel_name| + xml.nameEntry do + xml.part parallel_name['name'], :"xml:lang" => parallel_name['note'] + end + end + end end creator.other_names.each do |other_name| qualifiers = {"au" => "altraDenominazione", "pa" => "parallela", "ac" => "altraDenominazione", "ot" => "altraDenominazione"} qualifier = qualifiers.key?(other_name.qualifier.downcase) ? qualifiers[other_name.qualifier.downcase] : "altraDenominazione" if qualifier == "parallela" - xml.nameEntryParallel do - xml.nameEntry do - xml.part other_name.name, :lang => other_name.note - end - end + next else xml.nameEntry do xml.part other_name.name, :localType => qualifier @@ -240,9 +249,6 @@ xml.cpfDescription do xml.placeRole "TesauroSAN/sede", :vocabularySource => "http://dati.san.beniculturali.it/SAN/TesauroSAN/Tipo_luogo_CPF" xml.placeEntry "non indicato", :vocabularySource => "http://dati.san.beniculturali.it/ASI" end - xml.localDescription :localType => "titoli" do - xml.term creator.note, :vocabularySource => "NIERA" - end end if creator.creator_legal_statuses.present? status = {"PU" => "Pubblico", "PR" => "Privato", "EC" => "Ecclesiastico", "NA" => "Non definito"} @@ -257,7 +263,8 @@ xml.cpfDescription do end if creator.history.present? xml.biogHist do - xml.abstract creator.history + xml.abstract creator.abstract + xml.p creator.history end end end diff --git a/app/views/creators/_creators_ead.xml.builder b/app/views/creators/_creators_ead.xml.builder index 4069450..1060085 100644 --- a/app/views/creators/_creators_ead.xml.builder +++ b/app/views/creators/_creators_ead.xml.builder @@ -9,4 +9,4 @@ xml.tag! "eac-cpf", { records.each do |creator| xml << render(:partial => "creator_ead.xml", :locals => {:creator => creator, :fond_ids => fond_ids}) end -end \ No newline at end of file +end diff --git a/app/views/creators/_form.html.erb b/app/views/creators/_form.html.erb index dd124f4..4408aba 100644 --- a/app/views/creators/_form.html.erb +++ b/app/views/creators/_form.html.erb @@ -38,7 +38,7 @@ <%= f.label :creator_corporate_type, t('creator_corporate_type'), {:class => "hide"} %> <%= select( "creator", "creator_corporate_type_id", CreatorCorporateType.all.collect {|p| [ p.corporate_type.capitalize, p.id ] }, - {:include_blank => false, + {:include_blank => "---", :selected => @creator.creator_corporate_type_id}, :class => "hide span5") %> diff --git a/app/views/creators/show.xml.builder b/app/views/creators/show.xml.builder index 9f7dcee..a591651 100644 --- a/app/views/creators/show.xml.builder +++ b/app/views/creators/show.xml.builder @@ -45,7 +45,7 @@ xml.tag! "eac-cpf", { xml.nameEntry do xml.part @creator.preferred_name.name, :localType => "Denominazione" end - qualifier = {"AU" => "Altra denominazione principale", "PA" => "Denominazione parallela", "AC" => "Acronimo", "OT" => "Altre denominazioni"} + qualifier = {"PA" => "Denominazione parallela", "AC" => "Acronimo", "OT" => "Altre denominazioni"} @creator.other_names.each do |other_name| entityQualifier = qualifier[other_name.qualifier] xml.nameEntry :localType => entityQualifier do diff --git a/app/views/custodians/_custodian_ead.xml.builder b/app/views/custodians/_custodian_ead.xml.builder index 243d47a..a1871fb 100644 --- a/app/views/custodians/_custodian_ead.xml.builder +++ b/app/views/custodians/_custodian_ead.xml.builder @@ -44,7 +44,17 @@ xml.tag! "scons", { if custodian.other_names.present? qualifiers = {"au" => "altraDenominazione", "pa" => "parallela", "ac" => "acronimo", "ot" => "altraDenominazione"} custodian.other_names.each do |other_name| - xml.denominazione other_name.name, :qualifica => qualifiers[other_name.qualifier.downcase] + qualifica = qualifiers[other_name.qualifier.downcase] + if (qualifica == "parallela") + if (other_name.note.nil? || other_name.note.empty? || (other_name.note.downcase.match(/(a-z){3}/) == nil)) + lingua = "nnn" + else + lingua = other_name.note.downcase + end + xml.denominazione other_name.name, :qualifica => qualifica, :lingua => lingua + else + xml.denominazione other_name.name, :qualifica => qualifica + end end end custodian_types = { @@ -67,6 +77,11 @@ xml.tag! "scons", { custodian_type = custodian.custodian_type.present? ? custodian_types[custodian.custodian_type.custodian_type.downcase] : "altro" xml.tipologia custodian_type xml.localizzazioni do + if custodian.legal_status == "PU" + privato = "N" + else + privato = "S" + end custodian.custodian_buildings.each_with_index do |custodian_building, i| if i == 0 principale = "S" @@ -78,7 +93,7 @@ xml.tag! "scons", { else consultazione = "N" end - xml.localizzazione :identificativo => custodian_building.id, :principale => principale, :consultazione => consultazione, :privato => "N" do + xml.localizzazione :identificativo => custodian_building.id, :principale => principale, :consultazione => consultazione, :privato => privato do xml.denominazione custodian_building.name attributes = {:paese => "ITA", :comune => custodian_building.city} if custodian_building.postcode.present? @@ -90,7 +105,7 @@ xml.tag! "scons", { xml.indirizzo attributes if (i < 1) if custodian.custodian_contacts.present? - contact_types = {"tel" => "telefono", "fax" => "fax", "email" => "mail"} + contact_types = {"tel" => "telefono", "fax" => "fax", "email" => "mail", "pec" => "pec", "web" => "web"} custodian.custodian_contacts.each do |custodian_contacts| contact_type = custodian_contacts.contact_type? ? contact_types[custodian_contacts.contact_type.downcase] : "altro" xml.contatto custodian_contacts.contact, :tipo => contact_type diff --git a/app/views/digital_objects/_digital_object.xml.builder b/app/views/digital_objects/_digital_object.xml.builder index 9fab030..5a3b563 100644 --- a/app/views/digital_objects/_digital_object.xml.builder +++ b/app/views/digital_objects/_digital_object.xml.builder @@ -147,4 +147,4 @@ xml.tag! "envelope:recordBody" do end end -end \ No newline at end of file +end diff --git a/app/views/digital_objects/all.html.erb b/app/views/digital_objects/all.html.erb index 4a1f172..f63ee1e 100644 --- a/app/views/digital_objects/all.html.erb +++ b/app/views/digital_objects/all.html.erb @@ -3,7 +3,37 @@ <% end %> <%# TODO: [1.x] search e filtri per digital_objects %> +
+
+   + + <%= form_tag('/digital_objects/all', :method => :get, :class => "skip-prompt form-search pull-right") do %> + <%= text_field_tag :q, params[:q], :class => "search-query", :placeholder => "Complesso Archivistico"%> + <%= text_field_tag :unit, params[:unit], :class => "search-query", :placeholder => "Unità" %> + <%= submit_tag "Cerca", :name => "", :class => "btn btn-small" %> + <% end %> + <% if params[:q].present? || params[:unit].present? %> + <%= link_to raw(' ' + t('export') + " AEF"), + { + controller: :exports, + action: :fonds_aef, + remote: true, + fonds: @fond_ids_AEF + }, + {onclick:'alert("Export AEF iniziato.\n Al termine il risultato sara\' posizionato nella cartella: archimista/tmp/exports.")', :class => "btn btn-small" } %> + <%= link_to raw(' ' + t('export') + " EAD"), + { + controller: :exports, + action: :units_ead, + remote: true, + units: @unit_ids, + fonds: @fond_ids_EAD + }, + { onclick:'alert("Export EAD3 iniziato.\n\n Al termine il risultato sara\' posizionato nella cartella: archimista/tmp/exports.")', :class => "btn btn-small" } %> + <% end %> +
+ <% if @digital_objects.size > 0 %> <%= display_page_entries_info @digital_objects %> diff --git a/app/views/editors/index.html.erb b/app/views/editors/index.html.erb index 3f0888e..c6e2d30 100644 --- a/app/views/editors/index.html.erb +++ b/app/views/editors/index.html.erb @@ -37,7 +37,7 @@ <%# Upgrade 2.2.0 inizio %> <% if current_user.is_multi_group_user?() || current_user.is_superadmin?() %> - <%= editor.group.short_name %> + <% unless editor.group.nil? %><%= editor.group.short_name %><% end %> <% end %> <%# Upgrade 2.2.0 fine %> diff --git a/app/views/exports/index.html.erb b/app/views/exports/index.html.erb index 5d54539..f02502c 100644 --- a/app/views/exports/index.html.erb +++ b/app/views/exports/index.html.erb @@ -10,7 +10,7 @@

<%= check_box_tag 'inc_digit'%><%= label_tag 'inc_digit', 'Includi gli oggetti digitali', :class => 'digital_checkbox exports_checkbox' %>

<%= check_box_tag 'inc_entities'%><%= label_tag 'inc_entities', 'Includi le entità correlate all\'oggetto da esportare', :class => 'digital_checkbox exports_checkbox' %>

<%= check_box_tag 'inc_san'%><%= label_tag 'inc_san', 'Esporta le entità selezionate in formato CAT-SAN e METS-SAN', :class => 'digital_checkbox exports_checkbox' %>

-

<%= check_box_tag 'inc_ead'%><%= label_tag 'inc_ead', 'Esporta le entità selezionate in formato EAD e EAC-CPF', :class => 'digital_checkbox exports_checkbox' %>

+

<%= check_box_tag 'inc_ead'%><%= label_tag 'inc_ead', 'Esporta il complesso selezionato in formato ICAR-IMPORT', :class => 'digital_checkbox exports_checkbox' %>


- <% total_count = @fond.is_root? ? @fond.active_descendant_units_count : @fond.units_count %> + <% total_count = @fond.is_root? ? @fond.active_descendant_units_count : @fond.active_descendant_units_count_children %> <%= link_to "#{number_with_delimiter(total_count)} " + t('view_unit').downcase, fond_units_path(@fond) %> <%= "(totale del complesso)" if @fond.is_root? %> <%= link_to t('new_unit'), new_fond_unit_path(@fond), :class => 'btn btn-mini' %> diff --git a/app/views/fonds/_merge_with.html.erb b/app/views/fonds/_merge_with.html.erb index 2a4d683..c058dca 100644 --- a/app/views/fonds/_merge_with.html.erb +++ b/app/views/fonds/_merge_with.html.erb @@ -1,7 +1,7 @@ <%# OPTIMIZE: valutare se spostare questo js in fond-merge.js %> diff --git a/app/views/units/_form.html.erb b/app/views/units/_form.html.erb index 0075b19..6b5ed29 100644 --- a/app/views/units/_form.html.erb +++ b/app/views/units/_form.html.erb @@ -3,12 +3,25 @@ <%= javascript_include_tag "relations" %> <%= javascript_include_tag "live_search" %> <%= javascript_include_tag "sources" %> + <%= javascript_include_tag "digit_number" %> <%# Upgrade 2.1.0 inizio %> <%= javascript_include_tag "units-sc" %> <%# Upgrade 2.1.0 fine %> <% end %> + + <%# Upgrade 2.0.0 inizio %> <%#= render :partial => "shared/generic_error_message", :object => @unit %> <%= render :partial => "shared/generic_error_message", object: @unit, as: "object" %> @@ -284,7 +297,9 @@
<%= f.label :tmp_reference_string, t('tmp_reference_string') %>
-
<%= f.text_field :tmp_reference_number, :class => "span3" %>
+
<%= f.number_field :tmp_reference_number, :onkeypress=>"return isNumberKey(event)" , :class => "span3"%>
+ +
<%= f.text_field :tmp_reference_string, :class => "span6" %>
@@ -671,3 +686,4 @@ <%# Upgrade 2.2.0 inizio %> <%= render :partial => 'create_unit_reference_number_options' %> <%# Upgrade 2.2.0 fine %> + diff --git a/config/initializers/metadata.rb b/config/initializers/metadata.rb index e8bec01..87bdb82 100644 --- a/config/initializers/metadata.rb +++ b/config/initializers/metadata.rb @@ -1,8 +1,8 @@ # Application metadata APP_NAME = "Archimista" -APP_VERSION = "3.1.0" +APP_VERSION = "3.1.1" APP_STATUS = "" -AEF_COMPATIBLE_VERSIONS = [110, 120, 121, 200, 210, 211, 220, 300, 301, 302, 310] +AEF_COMPATIBLE_VERSIONS = [110, 120, 121, 200, 210, 211, 220, 300, 301, 302, 310, 311] APP_CREATOR = "INGLOBA360 srl" APP_EDITION = "server" # server | standalone | hub IM_ENABLED = DigitalObject.is_enabled? @@ -13,7 +13,7 @@ PROVIDER = "ARC-ICAR" # Url base -BASE_URL = "http://archivista.icar.beniculturali.it/" +BASE_URL = "http://archivista.icar.beniculturali.it" # Url base dei complessi archivistici. FONDS_URL = "#{BASE_URL}/fonds" @@ -28,7 +28,10 @@ SOURCES_URL = "#{BASE_URL}/sources" # Url base delle unità archivistiche. -UNITS_URL = "#{BASE_URL}/units" +#UNITS_URL = "#{BASE_URL}/units" + +# Url base delle unità archivistiche, relativa alla Url base dei complessi archivistici FONDS_URL +UNITS_URL = "units" # Url base degli oggetti digitali. DIGITAL_OBJECTS_URL = "#{BASE_URL}/digital_objects" @@ -44,3 +47,4 @@ ICAR_IMPORT_CONTACT_MAIL = "email@archimista.it" ICAR_IMPORT_FILE_DESC_TITLE = "Export ICAR-IMPORT" ICAR_IMPORT_FILE_DESC_ABSTRACT = "Esportazione complesso archivistico." + diff --git a/config/initializers/pdfkit.rb b/config/initializers/pdfkit.rb index 61c8eb5..b0e55e9 100644 --- a/config/initializers/pdfkit.rb +++ b/config/initializers/pdfkit.rb @@ -7,7 +7,7 @@ end if osCurrent.downcase.start_with?("windows") if Rails.env.development? - config.wkhtmltopdf = 'S:/PortableApps/wkhtmltopdf/wkhtmltopdf.exe' + config.wkhtmltopdf = 'C:/wkhtmltox/bin/wkhtmltopdf.exe' else config.wkhtmltopdf = File.expand_path("../../wkhtmltopdf/wkhtmltopdf.exe", File.dirname(__FILE__)) end @@ -21,4 +21,6 @@ :disable_smart_shrinking => true, :encoding => "UTF-8" } + + config.verbose = true end diff --git a/config/locales/it.yml b/config/locales/it.yml index 482e1c0..87d07b8 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -47,7 +47,6 @@ it: show_record: "Anteprima scheda" PU: "pubblico" PR: "privato" - AU: "altra denominazione principale" PA: "denominazione parallela" AC: "acronimo" OT: "altra denominazione" diff --git a/config/locales/views/creators.yml b/config/locales/views/creators.yml index d2e71bc..5cec46e 100644 --- a/config/locales/views/creators.yml +++ b/config/locales/views/creators.yml @@ -12,6 +12,10 @@ en: authorized_name: "Authorized name" parallel_name: "Parallel name" acronym: "Acronym" + intestazione: "Intestazione" + patronimico: "Patronimico" + pseudonimo: "Pseudonimo/Alias" + soprannome: "Soprannome" other_names: "Other names" other_names: "Other name" residence: "Residence" @@ -67,6 +71,10 @@ it: authorized_name: "Altra denominazione principale" parallel_name: "Denominazione parallela" acronym: "Acronimo" + intestazione: "Intestazione" + patronimico: "Patronimico" + pseudonimo: "Pseudonimo/Alias" + soprannome: "Soprannome" other_names: "Altre denominazioni" other_name: "Altra denominazione" residence: "Sede" diff --git a/config/locales/views/custodians.yml b/config/locales/views/custodians.yml index 3801d37..93ddd67 100644 --- a/config/locales/views/custodians.yml +++ b/config/locales/views/custodians.yml @@ -29,6 +29,7 @@ en: fax: "Fax" email: "Email" web: "Website" + pec: "Pec" contact_note: "Note" buildings: "Buildings" custodian_identifiers: "Custodian identifiers" @@ -86,6 +87,7 @@ it: fax: "Fax" email: "Email" web: "Sito web" + pec: "Pec" contact_note: "Annotazioni" buildings: "Sedi" custodian_identifiers: "Codici identificativi" diff --git a/config/locales/views/fonds.yml b/config/locales/views/fonds.yml index 3341995..3a83924 100644 --- a/config/locales/views/fonds.yml +++ b/config/locales/views/fonds.yml @@ -80,7 +80,7 @@ en: it: trash: "Cestino" fond_description: "Contenuto" - new_unit: 'Nuova unità' + new_unit: 'Nuova unità' fonds: "Complessi archivistici" fond: "Complesso archivistico" listing_fonds: "Complessi archivistici" @@ -157,3 +157,4 @@ it: level: "Livello" fond_editors: "Compilatori" fond_editor: "Compilatore" + diff --git a/config/locales/views/units.yml b/config/locales/views/units.yml index 521c52b..1c2011d 100644 --- a/config/locales/views/units.yml +++ b/config/locales/views/units.yml @@ -371,7 +371,7 @@ it: cardboard: "Cartoncino" film: "Pellicola o altro supporto fotografico" other: "Altro" - view_unit: "Unità archivistiche collegate" + view_unit: "Unità archivistiche di primo livello collegate" fragile: "Fragile" funghi_e_batteri: "Funghi e batteri" strappi: "Strappi" diff --git a/config/routes.rb b/config/routes.rb index bef4d09..a1f6887 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -233,11 +233,32 @@ collection do get :download get :xml -# Upgrade 2.2.0 inizio + get :fonds_aef + get :units_ead + # Upgrade 2.2.0 inizio post :units -# Upgrade 2.2.0 fine + # Upgrade 2.2.0 fine end end + resources :exports_batch, :only => [:index] do + collection do + post :icarimport + post :aefallfonds + post :aeffondsnoancestry + post :aefallfondsnoancestry + post :aefprojects + post :aefallprojects + post :aefcustodiansproject + post :aefcustodians + post :aefallcustodians + post :xmlallfonds + post :xmlfondsnoancestry + post :xmlallfondsnoancestry + post :xmlsourcesproject + post :xmlsources + post :xmlallsources + end + end # Vocabolari resources :vocabularies, :only => [:index] diff --git a/db/migrate/20190913101326_update_headings.rb b/db/migrate/20190913101326_update_headings.rb new file mode 100644 index 0000000..50f63af --- /dev/null +++ b/db/migrate/20190913101326_update_headings.rb @@ -0,0 +1,8 @@ +class UpdateHeadings < ActiveRecord::Migration + def up + change_column :headings, :qualifier, :text, :limit => 16777215 + end + def down + change_column :headings, :qualifier, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191120152439_update_fonds.rb b/db/migrate/20191120152439_update_fonds.rb new file mode 100644 index 0000000..a781b77 --- /dev/null +++ b/db/migrate/20191120152439_update_fonds.rb @@ -0,0 +1,28 @@ +class UpdateFonds < ActiveRecord::Migration + def up + change_column :fonds, :name, :text, :limit => 16777215 + change_column :fonds, :extent, :text, :limit => 16777215 + change_column :fonds, :abstract, :text, :limit => 16777215 + change_column :fonds, :description, :text, :limit => 16777215 + change_column :fonds, :history, :text, :limit => 16777215 + change_column :fonds, :arrangement_note, :text, :limit => 16777215 + change_column :fonds, :related_materials, :text, :limit => 16777215 + change_column :fonds, :note, :text, :limit => 16777215 + change_column :fonds, :access_condition_note, :text, :limit => 16777215 + change_column :fonds, :use_condition_note, :text, :limit => 16777215 + change_column :fonds, :preservation_note, :text, :limit => 16777215 + end + def down + change_column :fonds, :name, :text, :limit => 16777215 + change_column :fonds, :extent, :text, :limit => 16777215 + change_column :fonds, :abstract, :text, :limit => 16777215 + change_column :fonds, :description, :text, :limit => 16777215 + change_column :fonds, :history, :text, :limit => 16777215 + change_column :fonds, :arrangement_note, :text, :limit => 16777215 + change_column :fonds, :related_materials, :text, :limit => 16777215 + change_column :fonds, :note, :text, :limit => 16777215 + change_column :fonds, :access_condition_note, :text, :limit => 16777215 + change_column :fonds, :use_condition_note, :text, :limit => 16777215 + change_column :fonds, :preservation_note, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191121093705_update_fond_names.rb b/db/migrate/20191121093705_update_fond_names.rb new file mode 100644 index 0000000..6193023 --- /dev/null +++ b/db/migrate/20191121093705_update_fond_names.rb @@ -0,0 +1,10 @@ +class UpdateFondNames < ActiveRecord::Migration + def up + change_column :fond_names, :name, :text, :limit => 16777215 + change_column :fond_names, :note, :text, :limit => 16777215 + end + def down + change_column :fond_names, :name, :text, :limit => 16777215 + change_column :fond_names, :note, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191121102409_update_fond_events.rb b/db/migrate/20191121102409_update_fond_events.rb new file mode 100644 index 0000000..0b8ebcd --- /dev/null +++ b/db/migrate/20191121102409_update_fond_events.rb @@ -0,0 +1,8 @@ +class UpdateFondEvents < ActiveRecord::Migration + def up + change_column :fond_events, :note, :text, :limit => 16777215 + end + def down + change_column :fond_events, :note, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191121105837_update_fond_owners.rb b/db/migrate/20191121105837_update_fond_owners.rb new file mode 100644 index 0000000..00d2770 --- /dev/null +++ b/db/migrate/20191121105837_update_fond_owners.rb @@ -0,0 +1,8 @@ +class UpdateFondOwners < ActiveRecord::Migration + def up + change_column :fond_owners, :owner, :text, :limit => 16777215 + end + def down + change_column :fond_owners, :owner, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191121110829_update_fond_urls.rb b/db/migrate/20191121110829_update_fond_urls.rb new file mode 100644 index 0000000..589bc78 --- /dev/null +++ b/db/migrate/20191121110829_update_fond_urls.rb @@ -0,0 +1,8 @@ +class UpdateFondUrls < ActiveRecord::Migration + def up + change_column :fond_urls, :note, :text, :limit => 16777215 + end + def down + change_column :fond_urls, :note, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191121111304_update_fond_identifiers.rb b/db/migrate/20191121111304_update_fond_identifiers.rb new file mode 100644 index 0000000..1bfbf18 --- /dev/null +++ b/db/migrate/20191121111304_update_fond_identifiers.rb @@ -0,0 +1,8 @@ +class UpdateFondIdentifiers < ActiveRecord::Migration + def up + change_column :fond_identifiers, :note, :text, :limit => 16777215 + end + def down + change_column :fond_identifiers, :note, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191121130737_update_units.rb b/db/migrate/20191121130737_update_units.rb new file mode 100644 index 0000000..98a3460 --- /dev/null +++ b/db/migrate/20191121130737_update_units.rb @@ -0,0 +1,41 @@ +class UpdateUnits < ActiveRecord::Migration + def up + change_column :units, :title, :text, :limit => 16777215 + change_column :units, :content, :text, :limit => 16777215 + change_column :units, :extent, :text, :limit => 16777215 + change_column :units, :arrangement_note, :text, :limit => 16777215 + change_column :units, :related_materials, :text, :limit => 16777215 + change_column :units, :physical_description, :text, :limit => 16777215 + change_column :units, :preservation_note, :text, :limit => 16777215 + change_column :units, :restoration, :text, :limit => 16777215 + change_column :units, :note, :text, :limit => 16777215 + change_column :units, :access_condition_note, :text, :limit => 16777215 + change_column :units, :use_condition_note, :text, :limit => 16777215 + change_column :units, :tmp_reference_string, :text, :limit => 16777215 + change_column :units, :reference_number, :text, :limit => 16777215 + change_column :units, :fsc_name, :text, :limit => 16777215 + change_column :units, :fsc_surname, :text, :limit => 16777215 + change_column :units, :physical_container_type, :text, :limit => 16777215 + change_column :units, :physical_container_title, :text, :limit => 16777215 + change_column :units, :physical_container_number, :text, :limit => 16777215 + end + def down + change_column :units, :title, :text, :limit => 16777215 + change_column :units, :content, :text, :limit => 16777215 + change_column :units, :extent, :text, :limit => 16777215 + change_column :units, :arrangement_note, :text, :limit => 16777215 + change_column :units, :related_materials, :text, :limit => 16777215 + change_column :units, :physical_description, :text, :limit => 16777215 + change_column :units, :preservation_note, :text, :limit => 16777215 + change_column :units, :restoration, :text, :limit => 16777215 + change_column :units, :note, :text, :limit => 16777215 + change_column :units, :access_condition_note, :text, :limit => 16777215 + change_column :units, :use_condition_note, :text, :limit => 16777215 + change_column :units, :tmp_reference_string, :text, :limit => 16777215 + change_column :units, :reference_number, :text, :limit => 16777215 + change_column :units, :fsc_name, :text, :limit => 16777215 + change_column :units, :fsc_surname, :text, :limit => 16777215 + change_column :units, :physical_container_type, :text, :limit => 16777215 + change_column :units, :physical_container_number, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191121131948_update_unit_events.rb b/db/migrate/20191121131948_update_unit_events.rb new file mode 100644 index 0000000..e927c97 --- /dev/null +++ b/db/migrate/20191121131948_update_unit_events.rb @@ -0,0 +1,8 @@ +class UpdateUnitEvents < ActiveRecord::Migration + def up + change_column :unit_events, :note, :text, :limit => 16777215 + end + def down + change_column :unit_events, :note, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191121143417_update_creators.rb b/db/migrate/20191121143417_update_creators.rb new file mode 100644 index 0000000..655a1ba --- /dev/null +++ b/db/migrate/20191121143417_update_creators.rb @@ -0,0 +1,14 @@ +class UpdateCreators < ActiveRecord::Migration + def up + change_column :creators, :abstract, :text, :limit => 16777215 + change_column :creators, :history, :text, :limit => 16777215 + change_column :creators, :note, :text, :limit => 16777215 + change_column :creators, :residence, :text, :limit => 16777215 + end + def down + change_column :creators, :abstract, :text, :limit => 16777215 + change_column :creators, :history, :text, :limit => 16777215 + change_column :creators, :note, :text, :limit => 16777215 + change_column :creators, :residence, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191121144940_update_creator_names.rb b/db/migrate/20191121144940_update_creator_names.rb new file mode 100644 index 0000000..d4dd4aa --- /dev/null +++ b/db/migrate/20191121144940_update_creator_names.rb @@ -0,0 +1,14 @@ +class UpdateCreatorNames < ActiveRecord::Migration + def up + change_column :creator_names, :name, :text, :limit => 16777215 + change_column :creator_names, :first_name, :text, :limit => 16777215 + change_column :creator_names, :last_name, :text, :limit => 16777215 + change_column :creator_names, :note, :text, :limit => 16777215 + end + def down + change_column :creator_names, :name, :text, :limit => 16777215 + change_column :creator_names, :first_name, :text, :limit => 16777215 + change_column :creator_names, :last_name, :text, :limit => 16777215 + change_column :creator_names, :note, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191121150756_update_creator_activities.rb b/db/migrate/20191121150756_update_creator_activities.rb new file mode 100644 index 0000000..e1b8848 --- /dev/null +++ b/db/migrate/20191121150756_update_creator_activities.rb @@ -0,0 +1,10 @@ +class UpdateCreatorActivities < ActiveRecord::Migration + def up + change_column :creator_activities, :activity, :text, :limit => 16777215 + change_column :creator_activities, :note, :text, :limit => 16777215 + end + def down + change_column :creator_activities, :activity, :text, :limit => 16777215 + change_column :creator_activities, :note, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191121152618_update_custodian_names.rb b/db/migrate/20191121152618_update_custodian_names.rb new file mode 100644 index 0000000..233b353 --- /dev/null +++ b/db/migrate/20191121152618_update_custodian_names.rb @@ -0,0 +1,10 @@ +class UpdateCustodianNames < ActiveRecord::Migration + def up + change_column :custodian_names, :name, :text, :limit => 16777215 + change_column :custodian_names, :note, :text, :limit => 16777215 + end + def down + change_column :custodian_names, :name, :text, :limit => 16777215 + change_column :custodian_names, :note, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191121154751_update_custodians.rb b/db/migrate/20191121154751_update_custodians.rb new file mode 100644 index 0000000..7f80d68 --- /dev/null +++ b/db/migrate/20191121154751_update_custodians.rb @@ -0,0 +1,18 @@ +class UpdateCustodians < ActiveRecord::Migration + def up + change_column :custodians, :history, :text, :limit => 16777215 + change_column :custodians, :holdings, :text, :limit => 16777215 + change_column :custodians, :collecting_policies, :text, :limit => 16777215 + change_column :custodians, :administrative_structure, :text, :limit => 16777215 + change_column :custodians, :accessibility, :text, :limit => 16777215 + change_column :custodians, :services, :text, :limit => 16777215 + end + def down + change_column :custodians, :history, :text, :limit => 16777215 + change_column :custodians, :holdings, :text, :limit => 16777215 + change_column :custodians, :collecting_policies, :text, :limit => 16777215 + change_column :custodians, :administrative_structure, :text, :limit => 16777215 + change_column :custodians, :accessibility, :text, :limit => 16777215 + change_column :custodians, :services, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191122090252_update_custodian_contacts.rb b/db/migrate/20191122090252_update_custodian_contacts.rb new file mode 100644 index 0000000..938aae6 --- /dev/null +++ b/db/migrate/20191122090252_update_custodian_contacts.rb @@ -0,0 +1,8 @@ +class UpdateCustodianContacts < ActiveRecord::Migration + def up + change_column :custodian_contacts, :contact_note, :text, :limit => 16777215 + end + def down + change_column :custodian_contacts, :contact_note, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191122090606_update_custodian_urls.rb b/db/migrate/20191122090606_update_custodian_urls.rb new file mode 100644 index 0000000..6e5956a --- /dev/null +++ b/db/migrate/20191122090606_update_custodian_urls.rb @@ -0,0 +1,8 @@ +class UpdateCustodianUrls < ActiveRecord::Migration + def up + change_column :custodian_urls, :note, :text, :limit => 16777215 + end + def down + change_column :custodian_urls, :note, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191122090823_update_custodian_identifiers.rb b/db/migrate/20191122090823_update_custodian_identifiers.rb new file mode 100644 index 0000000..18708ae --- /dev/null +++ b/db/migrate/20191122090823_update_custodian_identifiers.rb @@ -0,0 +1,8 @@ +class UpdateCustodianIdentifiers < ActiveRecord::Migration + def up + change_column :custodian_identifiers, :note, :text, :limit => 16777215 + end + def down + change_column :custodian_identifiers, :note, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191122092849_update_custodian_buildings.rb b/db/migrate/20191122092849_update_custodian_buildings.rb new file mode 100644 index 0000000..3304def --- /dev/null +++ b/db/migrate/20191122092849_update_custodian_buildings.rb @@ -0,0 +1,10 @@ +class UpdateCustodianBuildings < ActiveRecord::Migration + def up + change_column :custodian_buildings, :name, :text, :limit => 16777215 + change_column :custodian_buildings, :description, :text, :limit => 16777215 + end + def down + change_column :custodian_buildings, :name, :text, :limit => 16777215 + change_column :custodian_buildings, :description, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191122093947_update_institutions.rb b/db/migrate/20191122093947_update_institutions.rb new file mode 100644 index 0000000..35edc21 --- /dev/null +++ b/db/migrate/20191122093947_update_institutions.rb @@ -0,0 +1,12 @@ +class UpdateInstitutions < ActiveRecord::Migration + def up + change_column :institutions, :name, :text, :limit => 16777215 + change_column :institutions, :description, :text, :limit => 16777215 + change_column :institutions, :note, :text, :limit => 16777215 + end + def down + change_column :institutions, :name, :text, :limit => 16777215 + change_column :institutions, :description, :text, :limit => 16777215 + change_column :institutions, :note, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191122094656_update_document_forms.rb b/db/migrate/20191122094656_update_document_forms.rb new file mode 100644 index 0000000..e71fc32 --- /dev/null +++ b/db/migrate/20191122094656_update_document_forms.rb @@ -0,0 +1,12 @@ +class UpdateDocumentForms < ActiveRecord::Migration + def up + change_column :document_forms, :name, :text, :limit => 16777215 + change_column :document_forms, :description, :text, :limit => 16777215 + change_column :document_forms, :note, :text, :limit => 16777215 + end + def down + change_column :document_forms, :name, :text, :limit => 16777215 + change_column :document_forms, :description, :text, :limit => 16777215 + change_column :document_forms, :note, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191122095515_update_projects.rb b/db/migrate/20191122095515_update_projects.rb new file mode 100644 index 0000000..581edc1 --- /dev/null +++ b/db/migrate/20191122095515_update_projects.rb @@ -0,0 +1,12 @@ +class UpdateProjects < ActiveRecord::Migration + def up + change_column :projects, :name, :text, :limit => 16777215 + change_column :projects, :description, :text, :limit => 16777215 + change_column :projects, :note, :text, :limit => 16777215 + end + def down + change_column :projects, :name, :text, :limit => 16777215 + change_column :projects, :description, :text, :limit => 16777215 + change_column :projects, :note, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191122095856_update_project_urls.rb b/db/migrate/20191122095856_update_project_urls.rb new file mode 100644 index 0000000..0cea411 --- /dev/null +++ b/db/migrate/20191122095856_update_project_urls.rb @@ -0,0 +1,8 @@ +class UpdateProjectUrls < ActiveRecord::Migration + def up + change_column :project_urls, :note, :text, :limit => 16777215 + end + def down + change_column :project_urls, :note, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191122101544_update_sources.rb b/db/migrate/20191122101544_update_sources.rb new file mode 100644 index 0000000..8d49c00 --- /dev/null +++ b/db/migrate/20191122101544_update_sources.rb @@ -0,0 +1,26 @@ +class UpdateSources < ActiveRecord::Migration + def up + change_column :sources, :short_title, :text, :limit => 16777215 + change_column :sources, :title, :text, :limit => 16777215 + change_column :sources, :date_string, :text, :limit => 255 + change_column :sources, :abstract, :text, :limit => 16777215 + change_column :sources, :author, :text, :limit => 16777215 + change_column :sources, :editor, :text, :limit => 16777215 + change_column :sources, :place, :text, :limit => 16777215 + change_column :sources, :publisher, :text, :limit => 16777215 + change_column :sources, :related_item, :text, :limit => 16777215 + change_column :sources, :related_item_specs, :text, :limit => 16777215 + end + def down + change_column :sources, :short_title, :text, :limit => 16777215 + change_column :sources, :title, :text, :limit => 16777215 + change_column :sources, :date_string, :text, :limit => 255 + change_column :sources, :abstract, :text, :limit => 16777215 + change_column :sources, :author, :text, :limit => 16777215 + change_column :sources, :editor, :text, :limit => 16777215 + change_column :sources, :place, :text, :limit => 16777215 + change_column :sources, :publisher, :text, :limit => 16777215 + change_column :sources, :related_item, :text, :limit => 16777215 + change_column :sources, :related_item_specs, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191122103658_update_source_urls.rb b/db/migrate/20191122103658_update_source_urls.rb new file mode 100644 index 0000000..5de5a25 --- /dev/null +++ b/db/migrate/20191122103658_update_source_urls.rb @@ -0,0 +1,10 @@ +class UpdateSourceUrls < ActiveRecord::Migration + def up + change_column :source_urls, :url, :text, :limit => 65535 + change_column :source_urls, :note, :text, :limit => 16777215 + end + def down + change_column :source_urls, :url, :text, :limit => 65535 + change_column :source_urls, :note, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191202092611_update_fond_editors.rb b/db/migrate/20191202092611_update_fond_editors.rb new file mode 100644 index 0000000..4f8d944 --- /dev/null +++ b/db/migrate/20191202092611_update_fond_editors.rb @@ -0,0 +1,10 @@ +class UpdateFondEditors < ActiveRecord::Migration + def up + change_column :fond_editors, :name, :text, :limit => 16777215 + change_column :fond_editors, :qualifier, :text, :limit => 16777215 + end + def down + change_column :fond_editors, :name, :text, :limit => 16777215 + change_column :fond_editors, :qualifier, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191202094446_update_creator_editors.rb b/db/migrate/20191202094446_update_creator_editors.rb new file mode 100644 index 0000000..bd165f7 --- /dev/null +++ b/db/migrate/20191202094446_update_creator_editors.rb @@ -0,0 +1,10 @@ +class UpdateCreatorEditors < ActiveRecord::Migration + def up + change_column :creator_editors, :name, :text, :limit => 16777215 + change_column :creator_editors, :qualifier, :text, :limit => 16777215 + end + def down + change_column :creator_editors, :name, :text, :limit => 16777215 + change_column :creator_editors, :qualifier, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191202095907_update_creator_events.rb b/db/migrate/20191202095907_update_creator_events.rb new file mode 100644 index 0000000..be7191f --- /dev/null +++ b/db/migrate/20191202095907_update_creator_events.rb @@ -0,0 +1,12 @@ +class UpdateCreatorEvents < ActiveRecord::Migration + def up + change_column :creator_events, :note, :text, :limit => 16777215 + change_column :creator_events, :start_date_place, :text, :limit => 16777215 + change_column :creator_events, :end_date_place, :text, :limit => 16777215 + end + def down + change_column :creator_events, :note, :text, :limit => 16777215 + change_column :creator_events, :start_date_place, :text, :limit => 16777215 + change_column :creator_events, :end_date_place, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191202100425_update_creator_legal_statuses.rb b/db/migrate/20191202100425_update_creator_legal_statuses.rb new file mode 100644 index 0000000..609694c --- /dev/null +++ b/db/migrate/20191202100425_update_creator_legal_statuses.rb @@ -0,0 +1,8 @@ +class UpdateCreatorLegalStatuses < ActiveRecord::Migration + def up + change_column :creator_legal_statuses, :note, :text, :limit => 16777215 + end + def down + change_column :creator_legal_statuses, :note, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191202101559_update_creator_urls.rb b/db/migrate/20191202101559_update_creator_urls.rb new file mode 100644 index 0000000..da07f67 --- /dev/null +++ b/db/migrate/20191202101559_update_creator_urls.rb @@ -0,0 +1,10 @@ +class UpdateCreatorUrls < ActiveRecord::Migration +def up + change_column :creator_urls, :url, :text, :limit => 65535 + change_column :creator_urls, :note, :text, :limit => 16777215 + end + def down + change_column :creator_urls, :url, :text, :limit => 65535 + change_column :creator_urls, :note, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191202111540_update_creator_identifiers.rb b/db/migrate/20191202111540_update_creator_identifiers.rb new file mode 100644 index 0000000..3ad20db --- /dev/null +++ b/db/migrate/20191202111540_update_creator_identifiers.rb @@ -0,0 +1,12 @@ +class UpdateCreatorIdentifiers < ActiveRecord::Migration + def up + change_column :creator_identifiers, :identifier, :text, :limit => 16777215 + change_column :creator_identifiers, :identifier_source, :text, :limit => 16777215 + change_column :creator_identifiers, :note, :text, :limit => 16777215 + end + def down + change_column :creator_identifiers, :identifier, :text, :limit => 16777215 + change_column :creator_identifiers, :identifier_source, :text, :limit => 16777215 + change_column :creator_identifiers, :note, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191202134905_update_unit_urls.rb b/db/migrate/20191202134905_update_unit_urls.rb new file mode 100644 index 0000000..83a47fa --- /dev/null +++ b/db/migrate/20191202134905_update_unit_urls.rb @@ -0,0 +1,10 @@ +class UpdateUnitUrls < ActiveRecord::Migration +def up + change_column :unit_urls, :url, :text, :limit => 65535 + change_column :unit_urls, :note, :text, :limit => 16777215 + end + def down + change_column :unit_urls, :url, :text, :limit => 65535 + change_column :unit_urls, :note, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191202135957_update_unit_identifiers.rb b/db/migrate/20191202135957_update_unit_identifiers.rb new file mode 100644 index 0000000..e000b6b --- /dev/null +++ b/db/migrate/20191202135957_update_unit_identifiers.rb @@ -0,0 +1,12 @@ +class UpdateUnitIdentifiers < ActiveRecord::Migration +def up + change_column :unit_identifiers, :identifier, :text, :limit => 16777215 + change_column :unit_identifiers, :identifier_source, :text, :limit => 16777215 + change_column :unit_identifiers, :note, :text, :limit => 16777215 + end + def down + change_column :unit_identifiers, :identifier, :text, :limit => 16777215 + change_column :unit_identifiers, :identifier_source, :text, :limit => 16777215 + change_column :unit_identifiers, :note, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191202140523_update_unit_editors.rb b/db/migrate/20191202140523_update_unit_editors.rb new file mode 100644 index 0000000..0bda431 --- /dev/null +++ b/db/migrate/20191202140523_update_unit_editors.rb @@ -0,0 +1,10 @@ +class UpdateUnitEditors < ActiveRecord::Migration +def up + change_column :unit_editors, :name, :text, :limit => 16777215 + change_column :unit_editors, :qualifier, :text, :limit => 16777215 + end + def down + change_column :unit_editors, :name, :text, :limit => 16777215 + change_column :unit_editors, :qualifier, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191202144758_update_fsc_organization.rb b/db/migrate/20191202144758_update_fsc_organization.rb new file mode 100644 index 0000000..c752acc --- /dev/null +++ b/db/migrate/20191202144758_update_fsc_organization.rb @@ -0,0 +1,8 @@ +class UpdateFscOrganization < ActiveRecord::Migration +def up + change_column :fsc_organizations, :organization, :text, :limit => 16777215 + end + def down + change_column :fsc_organizations, :organization, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191202145045_update_fsc_nationalities.rb b/db/migrate/20191202145045_update_fsc_nationalities.rb new file mode 100644 index 0000000..153bc7f --- /dev/null +++ b/db/migrate/20191202145045_update_fsc_nationalities.rb @@ -0,0 +1,8 @@ +class UpdateFscNationalities < ActiveRecord::Migration +def up + change_column :fsc_nationalities, :nationality, :text, :limit => 16777215 + end + def down + change_column :fsc_nationalities, :nationality, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191202151409_update_unit_other_reference_numbers.rb b/db/migrate/20191202151409_update_unit_other_reference_numbers.rb new file mode 100644 index 0000000..2006074 --- /dev/null +++ b/db/migrate/20191202151409_update_unit_other_reference_numbers.rb @@ -0,0 +1,12 @@ +class UpdateUnitOtherReferenceNumbers < ActiveRecord::Migration +def up + change_column :unit_other_reference_numbers, :other_reference_number, :text, :limit => 16777215 + change_column :unit_other_reference_numbers, :qualifier, :text, :limit => 16777215 + change_column :unit_other_reference_numbers, :note, :text, :limit => 16777215 + end + def down + change_column :unit_other_reference_numbers, :other_reference_number, :text, :limit => 16777215 + change_column :unit_other_reference_numbers, :qualifier, :text, :limit => 16777215 + change_column :unit_other_reference_numbers, :note, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191203083955_update_fe_identifications.rb b/db/migrate/20191203083955_update_fe_identifications.rb new file mode 100644 index 0000000..46a0390 --- /dev/null +++ b/db/migrate/20191203083955_update_fe_identifications.rb @@ -0,0 +1,12 @@ +class UpdateFeIdentifications < ActiveRecord::Migration +def up + change_column :fe_identifications, :code, :text, :limit => 16777215 + change_column :fe_identifications, :category, :text, :limit => 16777215 + change_column :fe_identifications, :identification_class, :text, :limit => 16777215 + end + def down + change_column :fe_identifications, :code, :text, :limit => 16777215 + change_column :fe_identifications, :category, :text, :limit => 16777215 + change_column :fe_identifications, :identification_class, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191203090509_update_fe_contexts.rb b/db/migrate/20191203090509_update_fe_contexts.rb new file mode 100644 index 0000000..02cf988 --- /dev/null +++ b/db/migrate/20191203090509_update_fe_contexts.rb @@ -0,0 +1,12 @@ +class UpdateFeContexts < ActiveRecord::Migration +def up + change_column :fe_contexts, :classification, :text, :limit => 16777215 + change_column :fe_contexts, :applicant, :text, :limit => 16777215 + change_column :fe_contexts, :request, :text, :limit => 16777215 + end + def down + change_column :fe_contexts, :classification, :text, :limit => 16777215 + change_column :fe_contexts, :applicant, :text, :limit => 16777215 + change_column :fe_contexts, :request, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191203092608_update_fe_operas.rb b/db/migrate/20191203092608_update_fe_operas.rb new file mode 100644 index 0000000..b6d2030 --- /dev/null +++ b/db/migrate/20191203092608_update_fe_operas.rb @@ -0,0 +1,16 @@ +class UpdateFeOperas < ActiveRecord::Migration +def up + change_column :fe_operas, :building_name, :text, :limit => 16777215 + change_column :fe_operas, :building_type, :text, :limit => 16777215 + change_column :fe_operas, :place_name, :text, :limit => 16777215 + change_column :fe_operas, :place_type, :text, :limit => 16777215 + change_column :fe_operas, :district, :text, :limit => 16777215 + end + def down + change_column :fe_operas, :building_name, :text, :limit => 16777215 + change_column :fe_operas, :building_type, :text, :limit => 16777215 + change_column :fe_operas, :place_name, :text, :limit => 16777215 + change_column :fe_operas, :place_type, :text, :limit => 16777215 + change_column :fe_operas, :district, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191203094002_update_fe_designers.rb b/db/migrate/20191203094002_update_fe_designers.rb new file mode 100644 index 0000000..d075543 --- /dev/null +++ b/db/migrate/20191203094002_update_fe_designers.rb @@ -0,0 +1,10 @@ +class UpdateFeDesigners < ActiveRecord::Migration +def up + change_column :fe_designers, :designer_name, :text, :limit => 16777215 + change_column :fe_designers, :designer_role, :text, :limit => 16777215 + end + def down + change_column :fe_designers, :designer_name, :text, :limit => 16777215 + change_column :fe_designers, :designer_role, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191203094501_update_fe_cadastrals.rb b/db/migrate/20191203094501_update_fe_cadastrals.rb new file mode 100644 index 0000000..8fb4c33 --- /dev/null +++ b/db/migrate/20191203094501_update_fe_cadastrals.rb @@ -0,0 +1,8 @@ +class UpdateFeCadastrals < ActiveRecord::Migration +def up + change_column :fe_cadastrals, :cadastral_municipality, :text, :limit => 16777215 + end + def down + change_column :fe_cadastrals, :cadastral_municipality, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191203095048_update_fe_land_parcels.rb b/db/migrate/20191203095048_update_fe_land_parcels.rb new file mode 100644 index 0000000..bf8dea8 --- /dev/null +++ b/db/migrate/20191203095048_update_fe_land_parcels.rb @@ -0,0 +1,8 @@ +class UpdateFeLandParcels < ActiveRecord::Migration +def up + change_column :fe_land_parcels, :land_parcel_number, :text, :limit => 16777215 + end + def down + change_column :fe_land_parcels, :land_parcel_number, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191203105439_update_sc2_textual_elements.rb b/db/migrate/20191203105439_update_sc2_textual_elements.rb new file mode 100644 index 0000000..6dfad91 --- /dev/null +++ b/db/migrate/20191203105439_update_sc2_textual_elements.rb @@ -0,0 +1,8 @@ +class UpdateSc2TextualElements < ActiveRecord::Migration +def up + change_column :sc2_textual_elements, :isri, :text, :limit => 16777215 + end + def down + change_column :sc2_textual_elements, :isri, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191203105728_update_sc2_visual_elements.rb b/db/migrate/20191203105728_update_sc2_visual_elements.rb new file mode 100644 index 0000000..91a68d5 --- /dev/null +++ b/db/migrate/20191203105728_update_sc2_visual_elements.rb @@ -0,0 +1,8 @@ +class UpdateSc2VisualElements < ActiveRecord::Migration +def up + change_column :sc2_visual_elements, :stmd, :text, :limit => 16777215 + end + def down + change_column :sc2_visual_elements, :stmd, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191203110608_update_sc2s.rb b/db/migrate/20191203110608_update_sc2s.rb new file mode 100644 index 0000000..26a9f16 --- /dev/null +++ b/db/migrate/20191203110608_update_sc2s.rb @@ -0,0 +1,12 @@ +class UpdateSc2s < ActiveRecord::Migration +def up + change_column :sc2s, :sgti, :text, :limit => 16777215 + change_column :sc2s, :cmmr, :text, :limit => 16777215 + change_column :sc2s, :lrc, :text, :limit => 16777215 + end + def down + change_column :sc2s, :sgti, :text, :limit => 16777215 + change_column :sc2s, :cmmr, :text, :limit => 16777215 + change_column :sc2s, :lrc, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191203110852_update_sc2_authors.rb b/db/migrate/20191203110852_update_sc2_authors.rb new file mode 100644 index 0000000..541f690 --- /dev/null +++ b/db/migrate/20191203110852_update_sc2_authors.rb @@ -0,0 +1,8 @@ +class UpdateSc2Authors < ActiveRecord::Migration +def up + change_column :sc2_authors, :autn, :text, :limit => 16777215 + end + def down + change_column :sc2_authors, :autn, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191203111527_update_sc2_commission_names.rb b/db/migrate/20191203111527_update_sc2_commission_names.rb new file mode 100644 index 0000000..779be24 --- /dev/null +++ b/db/migrate/20191203111527_update_sc2_commission_names.rb @@ -0,0 +1,8 @@ +class UpdateSc2CommissionNames < ActiveRecord::Migration +def up + change_column :sc2_commission_names, :cmmn, :text, :limit => 16777215 + end + def down + change_column :sc2_commission_names, :cmmn, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191203111907_update_sc2_commissions.rb b/db/migrate/20191203111907_update_sc2_commissions.rb new file mode 100644 index 0000000..f8f12ea --- /dev/null +++ b/db/migrate/20191203111907_update_sc2_commissions.rb @@ -0,0 +1,8 @@ +class UpdateSc2Commissions < ActiveRecord::Migration +def up + change_column :sc2_commissions, :cmmc, :text, :limit => 16777215 + end + def down + change_column :sc2_commissions, :cmmc, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20191206152223_update_langs.rb b/db/migrate/20191206152223_update_langs.rb new file mode 100644 index 0000000..2202797 --- /dev/null +++ b/db/migrate/20191206152223_update_langs.rb @@ -0,0 +1,10 @@ +class UpdateLangs < ActiveRecord::Migration + def up + Lang.update_all(active: 1) + Lang.where(it_name: "").update_all("it_name=en_name") + Lang.where(it_name: nil).update_all("it_name=en_name") + end + def down + Lang.update_all(active: 0) + end +end diff --git a/db/migrate/20200313083401_change_access_condition_to_fonds.rb b/db/migrate/20200313083401_change_access_condition_to_fonds.rb new file mode 100644 index 0000000..15850f1 --- /dev/null +++ b/db/migrate/20200313083401_change_access_condition_to_fonds.rb @@ -0,0 +1,6 @@ +class ChangeAccessConditionToFonds < ActiveRecord::Migration + def change + change_column :fonds, :access_condition, :text, :limit => 16777215 + change_column :fonds, :access_condition_note, :text, :limit => 16777215 + end +end diff --git a/db/migrate/20200316141358_update_qualify_to_custodian_names.rb b/db/migrate/20200316141358_update_qualify_to_custodian_names.rb new file mode 100644 index 0000000..1c571be --- /dev/null +++ b/db/migrate/20200316141358_update_qualify_to_custodian_names.rb @@ -0,0 +1,5 @@ +class UpdateQualifyToCustodianNames < ActiveRecord::Migration + def change + CustodianName.connection.execute("UPDATE custodian_names set qualifier='OT' where qualifier='AU'") + end +end diff --git a/db/migrate/20200316160622_update_qualify_to_creator_names.rb b/db/migrate/20200316160622_update_qualify_to_creator_names.rb new file mode 100644 index 0000000..165dca5 --- /dev/null +++ b/db/migrate/20200316160622_update_qualify_to_creator_names.rb @@ -0,0 +1,5 @@ +class UpdateQualifyToCreatorNames < ActiveRecord::Migration + def change + CreatorName.connection.execute("UPDATE creator_names set qualifier='OT' where qualifier='AU'") + end +end diff --git a/db/migrate/20200316163355_remove_au_qualify_from_terms.rb b/db/migrate/20200316163355_remove_au_qualify_from_terms.rb new file mode 100644 index 0000000..ebcbf07 --- /dev/null +++ b/db/migrate/20200316163355_remove_au_qualify_from_terms.rb @@ -0,0 +1,5 @@ +class RemoveAuQualifyFromTerms < ActiveRecord::Migration + def change + Term.connection.execute("DELETE FROM terms WHERE term_key='authorized_name' and term_value='AU'") + end +end diff --git a/db/migrate/20200320083311_add_pec_and_web_items_to_terms.rb b/db/migrate/20200320083311_add_pec_and_web_items_to_terms.rb new file mode 100644 index 0000000..a0e78cf --- /dev/null +++ b/db/migrate/20200320083311_add_pec_and_web_items_to_terms.rb @@ -0,0 +1,15 @@ +class AddPecAndWebItemsToTerms < ActiveRecord::Migration + def change + Term.connection.execute( + "insert into terms (vocabulary_id, position, term_key, term_value, created_at, updated_at) + select id, 4, 'pec', 'pec', SYSDATE(), SYSDATE() + from vocabularies + where name = 'custodian_contacts.contact_type'") + + Term.connection.execute( + "insert into terms (vocabulary_id, position, term_key, term_value, created_at, updated_at) + select id, 5, 'web', 'web', SYSDATE(), SYSDATE() + from vocabularies + where name = 'custodian_contacts.contact_type'") + end +end diff --git a/db/migrate/20200422153736_add_creator_qualifier_items_to_terms.rb b/db/migrate/20200422153736_add_creator_qualifier_items_to_terms.rb new file mode 100644 index 0000000..00670a3 --- /dev/null +++ b/db/migrate/20200422153736_add_creator_qualifier_items_to_terms.rb @@ -0,0 +1,27 @@ +class AddCreatorQualifierItemsToTerms < ActiveRecord::Migration + def change + Term.connection.execute( + "insert into terms (vocabulary_id, position, term_key, term_value, created_at, updated_at) + select id, 5, 'intestazione', 'IN', SYSDATE(), SYSDATE() + from vocabularies + where name = 'creator_names.qualifier'") + + Term.connection.execute( + "insert into terms (vocabulary_id, position, term_key, term_value, created_at, updated_at) + select id, 6, 'patronimico', 'PT', SYSDATE(), SYSDATE() + from vocabularies + where name = 'creator_names.qualifier'") + + Term.connection.execute( + "insert into terms (vocabulary_id, position, term_key, term_value, created_at, updated_at) + select id, 7, 'pseudonimo', 'AL', SYSDATE(), SYSDATE() + from vocabularies + where name = 'creator_names.qualifier'") + + Term.connection.execute( + "insert into terms (vocabulary_id, position, term_key, term_value, created_at, updated_at) + select id, 7, 'soprannome', 'SN', SYSDATE(), SYSDATE() + from vocabularies + where name = 'creator_names.qualifier'") + end +end diff --git a/db/migrate/20200430064258_update_headings_group_id.rb b/db/migrate/20200430064258_update_headings_group_id.rb new file mode 100644 index 0000000..9f36fdd --- /dev/null +++ b/db/migrate/20200430064258_update_headings_group_id.rb @@ -0,0 +1,13 @@ +class UpdateHeadingsGroupId < ActiveRecord::Migration + def up + change_column_default(:headings, :group_id, '1') + Term.connection.execute("UPDATE headings SET group_id = '1' WHERE ISNULL(group_id)") + end + + def down + change_column_default(:headings, :group_id, nil) + + # ATTENZIONE: quanto segue può coinvolgere più righe di quelle coinvolte nel metodo up + Term.connection.execute("UPDATE headings SET group_id = NULL WHERE group_id = '1'") + end +end diff --git a/db/schema.rb b/db/schema.rb index 3592462..9cb0755 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180130115554) do +ActiveRecord::Schema.define(version: 20200430064258) do create_table "activities", force: :cascade do |t| t.string "identifier", limit: 255 @@ -61,8 +61,8 @@ create_table "creator_activities", force: :cascade do |t| t.integer "creator_id", limit: 4 - t.string "activity", limit: 255 - t.string "note", limit: 255 + t.text "activity", limit: 16777215 + t.text "note", limit: 16777215 t.string "db_source", limit: 255 t.string "legacy_id", limit: 255 t.datetime "created_at" @@ -87,8 +87,8 @@ create_table "creator_editors", force: :cascade do |t| t.integer "creator_id", limit: 4 - t.string "name", limit: 255 - t.string "qualifier", limit: 255 + t.text "name", limit: 16777215 + t.text "qualifier", limit: 16777215 t.string "editing_type", limit: 255 t.date "edited_at" t.string "db_source", limit: 255 @@ -104,14 +104,14 @@ t.integer "creator_id", limit: 4, null: false t.boolean "preferred", limit: 1, default: false t.boolean "is_valid", limit: 1, default: true, null: false - t.string "start_date_place", limit: 255 + t.text "start_date_place", limit: 16777215 t.string "start_date_spec", limit: 255 t.date "start_date_from" t.date "start_date_to" t.string "start_date_valid", limit: 255 t.string "start_date_format", limit: 255 t.string "start_date_display", limit: 255 - t.string "end_date_place", limit: 255 + t.text "end_date_place", limit: 16777215 t.string "end_date_spec", limit: 255 t.date "end_date_from" t.date "end_date_to" @@ -132,8 +132,8 @@ create_table "creator_identifiers", force: :cascade do |t| t.integer "creator_id", limit: 4 - t.string "identifier", limit: 255 - t.string "identifier_source", limit: 255 + t.text "identifier", limit: 16777215 + t.text "identifier_source", limit: 16777215 t.text "note", limit: 16777215 t.string "db_source", limit: 255 t.string "legacy_id", limit: 255 @@ -160,9 +160,9 @@ create_table "creator_names", force: :cascade do |t| t.integer "creator_id", limit: 4 t.boolean "preferred", limit: 1, default: false - t.string "name", limit: 255 - t.string "first_name", limit: 255 - t.string "last_name", limit: 255 + t.text "name", limit: 16777215 + t.text "first_name", limit: 16777215 + t.text "last_name", limit: 16777215 t.text "note", limit: 16777215 t.string "qualifier", limit: 255 t.string "patronymic", limit: 255 @@ -178,7 +178,7 @@ create_table "creator_urls", force: :cascade do |t| t.integer "creator_id", limit: 4 - t.string "url", limit: 255 + t.text "url", limit: 65535 t.text "note", limit: 16777215 t.integer "position", limit: 4 t.string "db_source", limit: 255 @@ -193,7 +193,7 @@ create_table "creators", force: :cascade do |t| t.string "creator_type", limit: 1 t.integer "creator_corporate_type_id", limit: 4 - t.string "residence", limit: 255 + t.text "residence", limit: 16777215 t.text "abstract", limit: 16777215 t.text "history", limit: 16777215 t.string "legal_status", limit: 255 @@ -216,7 +216,7 @@ create_table "custodian_buildings", force: :cascade do |t| t.integer "custodian_id", limit: 4 t.string "custodian_building_type", limit: 255 - t.string "name", limit: 255 + t.text "name", limit: 16777215 t.text "description", limit: 16777215 t.string "address", limit: 255 t.string "postcode", limit: 255 @@ -236,7 +236,7 @@ t.integer "custodian_id", limit: 4 t.string "contact", limit: 255 t.string "contact_type", limit: 255 - t.string "contact_note", limit: 255 + t.text "contact_note", limit: 16777215 t.string "db_source", limit: 255 t.string "legacy_id", limit: 255 t.datetime "created_at" @@ -278,7 +278,7 @@ create_table "custodian_names", force: :cascade do |t| t.integer "custodian_id", limit: 4 t.boolean "preferred", limit: 1, default: false - t.string "name", limit: 255 + t.text "name", limit: 16777215 t.string "qualifier", limit: 255 t.text "note", limit: 16777215 t.string "db_source", limit: 255 @@ -389,7 +389,7 @@ create_table "document_forms", force: :cascade do |t| t.string "identifier_source", limit: 255 t.string "identifier", limit: 255 - t.string "name", limit: 255 + t.text "name", limit: 16777215 t.text "description", limit: 16777215 t.integer "status", limit: 4 t.text "note", limit: 16777215 @@ -419,10 +419,133 @@ add_index "editors", ["db_source", "legacy_id"], name: "index_editors_on_source_and_legacy_id", using: :btree add_index "editors", ["group_id"], name: "index_editors_on_group_id", using: :btree + create_table "fe_cadastrals", force: :cascade do |t| + t.integer "unit_id", limit: 4 + t.integer "way_code", limit: 4 + t.text "cadastral_municipality", limit: 16777215 + t.integer "municipality_code", limit: 4 + t.integer "paper_code", limit: 4 + t.string "db_source", limit: 255 + t.string "legacy_id", limit: 255 + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "fe_cadastrals", ["db_source", "legacy_id"], name: "index_fe_cadastrals_on_source_and_legacy_id", using: :btree + add_index "fe_cadastrals", ["unit_id"], name: "index_fe_cadastrals_on_unit_id", using: :btree + + create_table "fe_contexts", force: :cascade do |t| + t.integer "unit_id", limit: 4 + t.integer "number", limit: 4 + t.integer "sub_number", limit: 4 + t.text "classification", limit: 16777215 + t.text "applicant", limit: 16777215 + t.text "request", limit: 16777215 + t.integer "license_number", limit: 4 + t.integer "license_year", limit: 4 + t.integer "protocol_number", limit: 4 + t.date "license_date" + t.integer "habitability_number", limit: 4 + t.integer "habitability_year", limit: 4 + t.date "habitability_date" + t.string "db_source", limit: 255 + t.string "legacy_id", limit: 255 + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "fe_contexts", ["db_source", "legacy_id"], name: "index_fe_contexts_on_source_and_legacy_id", using: :btree + add_index "fe_contexts", ["unit_id"], name: "index_fe_contexts_on_unit_id", using: :btree + + create_table "fe_designers", force: :cascade do |t| + t.integer "unit_id", limit: 4 + t.text "designer_name", limit: 16777215 + t.text "designer_role", limit: 16777215 + t.string "db_source", limit: 255 + t.string "legacy_id", limit: 255 + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "fe_designers", ["db_source", "legacy_id"], name: "index_fe_designers_on_source_and_legacy_id", using: :btree + add_index "fe_designers", ["unit_id"], name: "index_fe_designers_on_unit_id", using: :btree + + create_table "fe_fract_edil_parcels", force: :cascade do |t| + t.integer "unit_id", limit: 4 + t.integer "fract_edil_parcel_number", limit: 4 + t.integer "material_portion", limit: 4 + t.string "db_source", limit: 255 + t.string "legacy_id", limit: 255 + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "fe_fract_edil_parcels", ["db_source", "legacy_id"], name: "index_fe_fract_edil_parcels_on_source_and_legacy_id", using: :btree + add_index "fe_fract_edil_parcels", ["unit_id"], name: "index_fe_fract_edil_parcels_on_unit_id", using: :btree + + create_table "fe_fract_land_parcels", force: :cascade do |t| + t.integer "unit_id", limit: 4 + t.integer "fract_land_parcel_number", limit: 4 + t.integer "edil_parcel_number", limit: 4 + t.string "db_source", limit: 255 + t.string "legacy_id", limit: 255 + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "fe_fract_land_parcels", ["db_source", "legacy_id"], name: "index_fe_fract_land_parcels_on_source_and_legacy_id", using: :btree + add_index "fe_fract_land_parcels", ["unit_id"], name: "index_fe_fract_land_parcels_on_unit_id", using: :btree + + create_table "fe_identifications", force: :cascade do |t| + t.integer "unit_id", limit: 4 + t.text "code", limit: 16777215 + t.integer "file_year", limit: 4 + t.text "category", limit: 16777215 + t.text "identification_class", limit: 16777215 + t.string "db_source", limit: 255 + t.string "legacy_id", limit: 255 + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "fe_identifications", ["db_source", "legacy_id"], name: "index_fe_identifications_on_source_and_legacy_id", using: :btree + add_index "fe_identifications", ["unit_id"], name: "index_fe_identifications_on_unit_id", using: :btree + + create_table "fe_land_parcels", force: :cascade do |t| + t.integer "unit_id", limit: 4 + t.text "land_parcel_number", limit: 16777215 + t.string "db_source", limit: 255 + t.string "legacy_id", limit: 255 + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "fe_land_parcels", ["db_source", "legacy_id"], name: "index_fe_land_parcels_on_source_and_legacy_id", using: :btree + add_index "fe_land_parcels", ["unit_id"], name: "index_fe_land_parcels_on_unit_id", using: :btree + + create_table "fe_operas", force: :cascade do |t| + t.integer "unit_id", limit: 4 + t.boolean "is_present", limit: 1, default: false, null: false + t.string "status", limit: 10 + t.text "building_name", limit: 16777215 + t.text "building_type", limit: 16777215 + t.text "place_name", limit: 16777215 + t.text "place_type", limit: 16777215 + t.string "house_number", limit: 255 + t.text "district", limit: 16777215 + t.string "db_source", limit: 255 + t.string "legacy_id", limit: 255 + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "fe_operas", ["db_source", "legacy_id"], name: "index_fe_operas_on_source_and_legacy_id", using: :btree + add_index "fe_operas", ["unit_id"], name: "index_fe_operas_on_unit_id", using: :btree + create_table "fond_editors", force: :cascade do |t| t.integer "fond_id", limit: 4 - t.string "name", limit: 255 - t.string "qualifier", limit: 255 + t.text "name", limit: 16777215 + t.text "qualifier", limit: 16777215 t.string "editing_type", limit: 255 t.date "edited_at" t.string "db_source", limit: 255 @@ -492,7 +615,7 @@ create_table "fond_names", force: :cascade do |t| t.integer "fond_id", limit: 4 - t.string "name", limit: 255 + t.text "name", limit: 16777215 t.string "qualifier", limit: 255 t.text "note", limit: 16777215 t.string "db_source", limit: 255 @@ -506,7 +629,7 @@ create_table "fond_owners", force: :cascade do |t| t.integer "fond_id", limit: 4 - t.string "owner", limit: 255 + t.text "owner", limit: 16777215 t.string "db_source", limit: 255 t.string "legacy_id", limit: 255 t.datetime "created_at" @@ -538,7 +661,7 @@ t.boolean "trashed", limit: 1, default: false, null: false t.integer "trashed_ancestor_id", limit: 4 t.integer "units_count", limit: 4, default: 0, null: false - t.string "name", limit: 255 + t.text "name", limit: 16777215 t.string "fond_type", limit: 255 t.float "length", limit: 24 t.text "extent", limit: 16777215 @@ -547,7 +670,7 @@ t.text "history", limit: 16777215 t.text "arrangement_note", limit: 16777215 t.text "related_materials", limit: 16777215 - t.string "access_condition", limit: 255 + t.text "access_condition", limit: 16777215 t.text "access_condition_note", limit: 16777215 t.string "use_condition", limit: 255 t.text "use_condition_note", limit: 16777215 @@ -598,7 +721,7 @@ create_table "fsc_nationalities", force: :cascade do |t| t.integer "unit_id", limit: 4 - t.string "nationality", limit: 255 + t.text "nationality", limit: 16777215 t.string "db_source", limit: 255 t.string "legacy_id", limit: 255 t.datetime "created_at" @@ -622,7 +745,7 @@ create_table "fsc_organizations", force: :cascade do |t| t.integer "unit_id", limit: 4 - t.string "organization", limit: 255 + t.text "organization", limit: 16777215 t.string "db_source", limit: 255 t.string "legacy_id", limit: 255 t.datetime "created_at" @@ -670,8 +793,8 @@ t.string "heading_type", limit: 255 t.string "name", limit: 255 t.string "dates", limit: 255 - t.string "qualifier", limit: 255 - t.integer "group_id", limit: 4 + t.text "qualifier", limit: 16777215 + t.integer "group_id", limit: 4, default: 1 t.string "db_source", limit: 255 t.string "legacy_id", limit: 255 t.datetime "created_at" @@ -835,7 +958,7 @@ create_table "institutions", force: :cascade do |t| t.string "identifier", limit: 255 t.string "identifier_source", limit: 255 - t.string "name", limit: 255 + t.text "name", limit: 16777215 t.text "description", limit: 16777215 t.integer "status", limit: 4 t.text "note", limit: 16777215 @@ -931,7 +1054,7 @@ create_table "projects", force: :cascade do |t| t.string "project_type", limit: 255 - t.string "name", limit: 255 + t.text "name", limit: 16777215 t.integer "start_year", limit: 4 t.integer "end_year", limit: 4 t.string "status", limit: 255 @@ -1176,7 +1299,7 @@ create_table "sc2_authors", force: :cascade do |t| t.integer "unit_id", limit: 4 t.string "autr", limit: 50 - t.string "autn", limit: 150 + t.text "autn", limit: 16777215 t.string "auta", limit: 100 t.string "db_source", limit: 255 t.string "legacy_id", limit: 255 @@ -1191,7 +1314,7 @@ create_table "sc2_commission_names", force: :cascade do |t| t.integer "sc2_commission_id", limit: 4 - t.string "cmmn", limit: 70 + t.text "cmmn", limit: 16777215 t.string "db_source", limit: 255 t.string "legacy_id", limit: 255 t.datetime "created_at" @@ -1203,7 +1326,7 @@ create_table "sc2_commissions", force: :cascade do |t| t.integer "unit_id", limit: 4 - t.string "cmmc", limit: 100 + t.text "cmmc", limit: 16777215 t.string "db_source", limit: 255 t.string "legacy_id", limit: 255 t.datetime "created_at" @@ -1253,7 +1376,7 @@ create_table "sc2_textual_elements", force: :cascade do |t| t.integer "unit_id", limit: 4 - t.string "isri", limit: 2200 + t.text "isri", limit: 16777215 t.string "db_source", limit: 255 t.string "legacy_id", limit: 255 t.datetime "created_at" @@ -1265,7 +1388,7 @@ create_table "sc2_visual_elements", force: :cascade do |t| t.integer "unit_id", limit: 4 - t.string "stmd", limit: 500 + t.text "stmd", limit: 16777215 t.string "db_source", limit: 255 t.string "legacy_id", limit: 255 t.datetime "created_at" @@ -1285,9 +1408,9 @@ create_table "sc2s", force: :cascade do |t| t.integer "unit_id", limit: 4 - t.string "sgti", limit: 250 - t.string "cmmr", limit: 25 - t.string "lrc", limit: 250 + t.text "sgti", limit: 16777215 + t.text "cmmr", limit: 16777215 + t.text "lrc", limit: 16777215 t.string "lrd", limit: 50 t.string "mtce", limit: 250 t.string "sdtt", limit: 50 @@ -1316,7 +1439,7 @@ create_table "source_urls", force: :cascade do |t| t.integer "source_id", limit: 4 - t.string "url", limit: 255 + t.text "url", limit: 65535 t.text "note", limit: 16777215 t.integer "position", limit: 4 t.string "db_source", limit: 255 @@ -1332,16 +1455,16 @@ t.boolean "use_legacy", limit: 1, default: false t.integer "source_type_code", limit: 4 t.integer "source_subtype_code", limit: 4 - t.string "short_title", limit: 255 - t.string "author", limit: 255 + t.text "short_title", limit: 16777215 + t.text "author", limit: 16777215 t.text "title", limit: 16777215 - t.string "editor", limit: 255 - t.string "publisher", limit: 255 - t.string "place", limit: 255 + t.text "editor", limit: 16777215 + t.text "publisher", limit: 16777215 + t.text "place", limit: 16777215 t.integer "year", limit: 4, default: 0 - t.string "date_string", limit: 255 - t.string "related_item", limit: 255 - t.string "related_item_specs", limit: 255 + t.text "date_string", limit: 255 + t.text "related_item", limit: 16777215 + t.text "related_item_specs", limit: 16777215 t.text "abstract", limit: 16777215 t.string "identifier", limit: 255 t.boolean "finding_aid_published", limit: 1 @@ -1401,8 +1524,8 @@ create_table "unit_editors", force: :cascade do |t| t.integer "unit_id", limit: 4 - t.string "name", limit: 255 - t.string "qualifier", limit: 255 + t.text "name", limit: 16777215 + t.text "qualifier", limit: 16777215 t.string "editing_type", limit: 255 t.date "edited_at" t.string "db_source", limit: 255 @@ -1446,8 +1569,8 @@ create_table "unit_identifiers", force: :cascade do |t| t.integer "unit_id", limit: 4 - t.string "identifier", limit: 255 - t.string "identifier_source", limit: 255 + t.text "identifier", limit: 16777215 + t.text "identifier_source", limit: 16777215 t.text "note", limit: 16777215 t.string "db_source", limit: 255 t.string "legacy_id", limit: 255 @@ -1472,8 +1595,8 @@ create_table "unit_other_reference_numbers", force: :cascade do |t| t.integer "unit_id", limit: 4 - t.string "other_reference_number", limit: 255 - t.string "qualifier", limit: 255 + t.text "other_reference_number", limit: 16777215 + t.text "qualifier", limit: 16777215 t.text "note", limit: 16777215 t.string "db_source", limit: 255 t.string "legacy_id", limit: 255 @@ -1486,7 +1609,7 @@ create_table "unit_urls", force: :cascade do |t| t.integer "unit_id", limit: 4 - t.string "url", limit: 255 + t.text "url", limit: 65535 t.text "note", limit: 16777215 t.integer "position", limit: 4 t.string "db_source", limit: 255 @@ -1506,9 +1629,9 @@ t.string "ancestry", limit: 255 t.integer "ancestry_depth", limit: 4 t.string "tsk", limit: 5 - t.string "reference_number", limit: 255 + t.text "reference_number", limit: 16777215 t.integer "tmp_reference_number", limit: 4 - t.string "tmp_reference_string", limit: 255 + t.text "tmp_reference_string", limit: 16777215 t.text "title", limit: 16777215 t.boolean "given_title", limit: 1 t.integer "folder_number", limit: 4 @@ -1522,9 +1645,9 @@ t.text "related_materials", limit: 16777215 t.string "physical_type", limit: 255 t.text "physical_description", limit: 16777215 - t.string "physical_container_type", limit: 255 - t.string "physical_container_title", limit: 255 - t.string "physical_container_number", limit: 255 + t.text "physical_container_type", limit: 16777215 + t.text "physical_container_title", limit: 16777215 + t.text "physical_container_number", limit: 16777215 t.string "preservation", limit: 255 t.text "preservation_note", limit: 16777215 t.text "restoration", limit: 16777215 @@ -1545,11 +1668,11 @@ t.datetime "created_at" t.datetime "updated_at" t.string "sc2_tsk", limit: 10 - t.text "extent", limit: 65535 + t.text "extent", limit: 16777215 t.boolean "published", limit: 1, default: true t.string "file_type", limit: 255 - t.string "fsc_name", limit: 255 - t.string "fsc_surname", limit: 255 + t.text "fsc_name", limit: 16777215 + t.text "fsc_surname", limit: 16777215 end add_index "units", ["ancestry"], name: "index_units_on_ancestry", using: :btree diff --git a/db/seeds/terms.json b/db/seeds/terms.json index 10eab05..e7e8785 100644 --- a/db/seeds/terms.json +++ b/db/seeds/terms.json @@ -1,10 +1,13 @@ {"vocabulary_id":1,"position":1,"term_key":"corporate_body","term_value":"C"} {"vocabulary_id":1,"position":2,"term_key":"person","term_value":"P"} {"vocabulary_id":1,"position":3,"term_key":"family","term_value":"F"} -{"vocabulary_id":2,"position":1,"term_key":"authorized_name","term_value":"AU"} {"vocabulary_id":2,"position":2,"term_key":"parallel_name","term_value":"PA"} {"vocabulary_id":2,"position":3,"term_key":"acronym","term_value":"AC"} {"vocabulary_id":2,"position":4,"term_key":"other_name","term_value":"OT"} +{"vocabulary_id":2,"position":5,"term_key":"intestazione","term_value":"IN"} +{"vocabulary_id":2,"position":6,"term_key":"patronimico","term_value":"PT"} +{"vocabulary_id":2,"position":7,"term_key":"pseudonimo","term_value":"AL"} +{"vocabulary_id":2,"position":8,"term_key":"soprannome","term_value":"SN"} {"vocabulary_id":3,"position":1,"term_key":"public","term_value":"PU"} {"vocabulary_id":3,"position":2,"term_key":"private","term_value":"PR"} {"vocabulary_id":3,"position":3,"term_key":"ecclesiastic","term_value":"EC"} @@ -12,6 +15,8 @@ {"vocabulary_id":4,"position":1,"term_key":"tel","term_value":"tel"} {"vocabulary_id":4,"position":2,"term_key":"fax","term_value":"fax"} {"vocabulary_id":4,"position":3,"term_key":"email","term_value":"email"} +{"vocabulary_id":4,"position":4,"term_key":"pec","term_value":"pec"} +{"vocabulary_id":4,"position":5,"term_key":"web","term_value":"web"} {"vocabulary_id":5,"position":2,"term_key":"riordino","term_value":"riordino"} {"vocabulary_id":5,"position":3,"term_key":"recupero","term_value":"recupero"} {"vocabulary_id":5,"position":1,"term_key":"censimento","term_value":"censimento"} @@ -81,7 +86,6 @@ {"vocabulary_id":14,"position":21,"term_key":"acidita","term_value":"acidità"} {"vocabulary_id":14,"position":22,"term_key":"usura","term_value":"usura"} {"vocabulary_id":14,"position":23,"term_key":"rottura_cuciture","term_value":"rottura delle cuciture"} -{"vocabulary_id":15,"position":1,"term_key":"authorized_name","term_value":"AU"} {"vocabulary_id":15,"position":2,"term_key":"parallel_name","term_value":"PA"} {"vocabulary_id":15,"position":3,"term_key":"acronym","term_value":"AC"} {"vocabulary_id":15,"position":4,"term_key":"other_name","term_value":"OT"} diff --git a/lib/archidate/validations.rb b/lib/archidate/validations.rb index 2cd22d0..b76aa23 100644 --- a/lib/archidate/validations.rb +++ b/lib/archidate/validations.rb @@ -62,7 +62,7 @@ def no_future_end_date end def no_intersection - errors.add :start_date_from, :intersection if different_bounds? && has_intersection? + errors.add :start_date_from, :intersection if false && different_bounds? && has_intersection? end def no_inversion diff --git a/lib/exporter/Configurazione_dl.rb b/lib/exporter/Configurazione_dl.rb index 9c0ca41..ac73376 100644 --- a/lib/exporter/Configurazione_dl.rb +++ b/lib/exporter/Configurazione_dl.rb @@ -10,3 +10,4 @@ DL_HACOMPLESSO ="san.cat.complArch.113436" DL_UNITID ="DATINI:san.cat.complArch.113436" DL_UNITTITLE ="Carteggio, Archivio di Stato di Prato, Datini, Fondaco di Avignone, Carteggio diretto al fondaco da Aigues Mortes a Valenza" + diff --git a/lib/exporter/views/anagraphics/_anagraphic_ead.xml.builder b/lib/exporter/views/anagraphics/_anagraphic_ead.xml.builder index e00d708..c074e7e 100644 --- a/lib/exporter/views/anagraphics/_anagraphic_ead.xml.builder +++ b/lib/exporter/views/anagraphics/_anagraphic_ead.xml.builder @@ -84,3 +84,4 @@ xml.cpfDescription do end end end + diff --git a/lib/exporter/views/anagraphics/anagraphics_ead.xml.builder b/lib/exporter/views/anagraphics/anagraphics_ead.xml.builder index e910795..26c4392 100644 --- a/lib/exporter/views/anagraphics/anagraphics_ead.xml.builder +++ b/lib/exporter/views/anagraphics/anagraphics_ead.xml.builder @@ -11,4 +11,4 @@ xml.tag! "eac-cpf", { records.each do |anagraphic| xml << render(:partial => "anagraphic_ead.xml", :locals => {:anagraphic => anagraphic}) end -end \ No newline at end of file +end diff --git a/lib/exporter/views/creators/_creator.xml.builder b/lib/exporter/views/creators/_creator.xml.builder index 5b81edd..905ccc6 100644 --- a/lib/exporter/views/creators/_creator.xml.builder +++ b/lib/exporter/views/creators/_creator.xml.builder @@ -105,3 +105,4 @@ xml.catRecord do end end + diff --git a/lib/exporter/views/creators/_creator_ead.xml.builder b/lib/exporter/views/creators/_creator_ead.xml.builder index c8a1dbb..559c9a2 100644 --- a/lib/exporter/views/creators/_creator_ead.xml.builder +++ b/lib/exporter/views/creators/_creator_ead.xml.builder @@ -94,18 +94,34 @@ xml.cpfDescription do xml.entityType entityType case creator_type when 'c' - xml.nameEntry do - xml.part creator.preferred_name.name + parallel_names = Array.new + creator.other_names.each do |other_name| + if other_name.qualifier.downcase == "pa" + parallel_name = a = {'id' => other_name.id, 'name' => other_name.name, 'note' => other_name.note} + parallel_names << parallel_name + end + end + if parallel_names.empty? + xml.nameEntry do + xml.part creator.preferred_name.name + end + else + xml.nameEntryParallel do + xml.nameEntry do + xml.part creator.preferred_name.name + end + parallel_names.each do |parallel_name| + xml.nameEntry do + xml.part parallel_name['name'], :"xml:lang" => parallel_name['note'] + end + end + end end creator.other_names.each do |other_name| qualifiers = {"au" => "altraDenominazione", "pa" => "parallela", "ac" => "altraDenominazione", "ot" => "altraDenominazione"} qualifier = qualifiers.key?(other_name.qualifier.downcase) ? qualifiers[other_name.qualifier.downcase] : "altraDenominazione" if qualifier == "parallela" - xml.nameEntryParallel do - xml.nameEntry do - xml.part other_name.name, :lang => other_name.note - end - end + next else xml.nameEntry do xml.part other_name.name, :localType => qualifier @@ -180,11 +196,17 @@ xml.cpfDescription do "organo giudiziario" => "TesauroSAN/statali", "organo periferico dello stato" => "TesauroSAN/organo_e_ufficio_statale_periferico_di_periodo_postunitario", "ente ecclesiastico" => "TesauroSAN/corporazione_religiosa" - } - ente_type = creator.creator_corporate_type.corporate_type.downcase - corporate_type = corporate_types.key?(ente_type) ? corporate_types[ente_type] : "altro" - xml.term corporate_type, :vocabularySource => "http://dati.san.beniculturali.it/SAN/TesauroSAN/sottotipologia_ente" - end + } + + if creator.creator_corporate_type.nil? + ente_type = "" + else + ente_type = creator.creator_corporate_type.corporate_type.downcase + end + + corporate_type = corporate_types.key?(ente_type) ? corporate_types[ente_type] : "altro" + xml.term corporate_type, :vocabularySource => "http://dati.san.beniculturali.it/SAN/TesauroSAN/sottotipologia_ente" + end when 'p' if creator.preferred_event.present? xml.existDates do @@ -240,9 +262,6 @@ xml.cpfDescription do xml.placeRole "TesauroSAN/sede", :vocabularySource => "http://dati.san.beniculturali.it/SAN/TesauroSAN/Tipo_luogo_CPF" xml.placeEntry "non indicato", :vocabularySource => "http://dati.san.beniculturali.it/ASI" end - xml.localDescription :localType => "titoli" do - xml.term creator.note, :vocabularySource => "NIERA" - end end if creator.creator_legal_statuses.present? status = {"PU" => "Pubblico", "PR" => "Privato", "EC" => "Ecclesiastico", "NA" => "Non definito"} diff --git a/lib/exporter/views/creators/creators_ead.xml.builder b/lib/exporter/views/creators/creators_ead.xml.builder index 63f7f47..84a6f4f 100644 --- a/lib/exporter/views/creators/creators_ead.xml.builder +++ b/lib/exporter/views/creators/creators_ead.xml.builder @@ -14,4 +14,4 @@ xml.tag! "eac-cpf", { records.each do |creator| xml << render(:partial => "creator_ead.xml", :locals => {:creator => creator, :fond_ids => fond_ids}) end -end \ No newline at end of file +end diff --git a/lib/exporter/views/custodians/_custodian.xml.builder b/lib/exporter/views/custodians/_custodian.xml.builder index c0e5849..48f1213 100644 --- a/lib/exporter/views/custodians/_custodian.xml.builder +++ b/lib/exporter/views/custodians/_custodian.xml.builder @@ -46,4 +46,4 @@ xml.catRecord do end end -end \ No newline at end of file +end diff --git a/lib/exporter/views/custodians/_custodian_ead.xml.builder b/lib/exporter/views/custodians/_custodian_ead.xml.builder index 243d47a..965001f 100644 --- a/lib/exporter/views/custodians/_custodian_ead.xml.builder +++ b/lib/exporter/views/custodians/_custodian_ead.xml.builder @@ -44,7 +44,17 @@ xml.tag! "scons", { if custodian.other_names.present? qualifiers = {"au" => "altraDenominazione", "pa" => "parallela", "ac" => "acronimo", "ot" => "altraDenominazione"} custodian.other_names.each do |other_name| - xml.denominazione other_name.name, :qualifica => qualifiers[other_name.qualifier.downcase] + qualifica = qualifiers[other_name.qualifier.downcase] + if (qualifica == "parallela") + if (other_name.note.nil? || other_name.note.empty? || (other_name.note.downcase.match(/(a-z){3}/) == nil)) + lingua = "nnn" + else + lingua = other_name.note.downcase + end + xml.denominazione other_name.name, :qualifica => qualifica, :lingua => lingua + else + xml.denominazione other_name.name, :qualifica => qualifica + end end end custodian_types = { @@ -67,6 +77,11 @@ xml.tag! "scons", { custodian_type = custodian.custodian_type.present? ? custodian_types[custodian.custodian_type.custodian_type.downcase] : "altro" xml.tipologia custodian_type xml.localizzazioni do + if custodian.legal_status == "PU" + privato = "N" + else + privato = "S" + end custodian.custodian_buildings.each_with_index do |custodian_building, i| if i == 0 principale = "S" @@ -78,7 +93,7 @@ xml.tag! "scons", { else consultazione = "N" end - xml.localizzazione :identificativo => custodian_building.id, :principale => principale, :consultazione => consultazione, :privato => "N" do + xml.localizzazione :identificativo => custodian_building.id, :principale => principale, :consultazione => consultazione, :privato => privato do xml.denominazione custodian_building.name attributes = {:paese => "ITA", :comune => custodian_building.city} if custodian_building.postcode.present? diff --git a/lib/exporter/views/custodians/custodians_ead.xml.builder b/lib/exporter/views/custodians/custodians_ead.xml.builder index 4f664c7..52d75e1 100644 --- a/lib/exporter/views/custodians/custodians_ead.xml.builder +++ b/lib/exporter/views/custodians/custodians_ead.xml.builder @@ -3,4 +3,4 @@ if (defined?(is_icar_import)).nil? or is_icar_import != true end records.each do |custodian| xml << render(:partial => "custodian_ead.xml", :locals => {:custodian => custodian}) -end \ No newline at end of file +end diff --git a/lib/exporter/views/digital_objects/_digital_object.xml.builder b/lib/exporter/views/digital_objects/_digital_object.xml.builder index 9fab030..5a3b563 100644 --- a/lib/exporter/views/digital_objects/_digital_object.xml.builder +++ b/lib/exporter/views/digital_objects/_digital_object.xml.builder @@ -147,4 +147,4 @@ xml.tag! "envelope:recordBody" do end end -end \ No newline at end of file +end diff --git a/lib/exporter/views/fonds/_ead_fonds.xml.builder b/lib/exporter/views/fonds/_ead_fonds.xml.builder index b6ba412..0fc4ada 100644 --- a/lib/exporter/views/fonds/_ead_fonds.xml.builder +++ b/lib/exporter/views/fonds/_ead_fonds.xml.builder @@ -1,18 +1,18 @@ unless fonds.empty? fond_first_levels = { "archivio" => "fonds", + "fondo" => "fonds", "complesso di fondi" => "recordgrp", "iperfondo" => "recordgrp", - "fondo" => "fonds", "subfondo" => "subfonds", "sezione" => "subfonds", - "sottosezione" => "otherlevel", "partizione" => "subfonds", "sottopartizione" => "subfonds", + "parte" => "subfonds", "serie" => "series", "sottoserie" => "subseries", "sottosottoserie" => "subseries", - "parte" => "subfonds", + "sottosezione" => "otherlevel", "categoria" => "otherlevel", "classe" => "otherlevel", "sottoclasse" => "otherlevel", @@ -26,11 +26,11 @@ unless fonds.empty? fonds.each do |fond| ca_id_str = sprintf '%08d', fond.id - if fond.fond_type.present? + if !fond.fond_type.present? tags = {:level => "fonds", :id => "CA-#{ca_id_str}"} else level = fond.fond_type - if fond_first_levels[level].nil? + if (fond_first_levels[level] == "otherlevel") tags = {:level => "otherlevel", :otherlevel => level, :id => "CA-#{ca_id_str}"} else tags = {:level => fond_first_levels[level], :id => "CA-#{ca_id_str}"} diff --git a/lib/exporter/views/fonds/_fond_desc_child_ii.xml.builder b/lib/exporter/views/fonds/_fond_desc_child_ii.xml.builder index 23bd0f7..abe6195 100644 --- a/lib/exporter/views/fonds/_fond_desc_child_ii.xml.builder +++ b/lib/exporter/views/fonds/_fond_desc_child_ii.xml.builder @@ -19,4 +19,4 @@ fond.children.each do |children| :fond => children }) end -end \ No newline at end of file +end diff --git a/lib/exporter/views/fonds/_fond_desc_ii.xml.builder b/lib/exporter/views/fonds/_fond_desc_ii.xml.builder index 7a823a0..89a137d 100644 --- a/lib/exporter/views/fonds/_fond_desc_ii.xml.builder +++ b/lib/exporter/views/fonds/_fond_desc_ii.xml.builder @@ -177,4 +177,4 @@ else :fond_types => fond_types, :fond => fond }) -end \ No newline at end of file +end diff --git a/lib/exporter/views/fonds/_fond_ead.xml.builder b/lib/exporter/views/fonds/_fond_ead.xml.builder index d06a075..590d0dc 100644 --- a/lib/exporter/views/fonds/_fond_ead.xml.builder +++ b/lib/exporter/views/fonds/_fond_ead.xml.builder @@ -52,18 +52,38 @@ xml.control :repositoryencoding => "iso15511", end end -fond_first_levels = {"archivio" => "fonds", "complesso di fondi" => "recordgrp", "iperfondo" => "recordgrp", - "fondo" => "fonds", "subfondo" => "subfonds", "sezione" => "subfonds", - "partizione" => "subfonds", "sottopartizione" => "subfonds", "serie" => "series", - "sottoserie" => "subseries", "sottosottoserie" => "subseries", "parte" => "subfonds"} +fond_first_levels = { + "archivio" => "fonds", + "fondo" => "fonds", + "complesso di fondi" => "recordgrp", + "iperfondo" => "recordgrp", + "subfondo" => "subfonds", + "sezione" => "subfonds", + "partizione" => "subfonds", + "sottopartizione" => "subfonds", + "parte" => "subfonds", + "serie" => "series", + "sottoserie" => "subseries", + "sottosottoserie" => "subseries", + "sottosezione" => "otherlevel", + "categoria" => "otherlevel", + "classe" => "otherlevel", + "sottoclasse" => "otherlevel", + "rubrica" => "otherlevel", + "voce" => "otherlevel", + "sottovoce" => "otherlevel", + "titolo" => "otherlevel", + "sottotitolo" => "otherlevel", + "articolo" => "otherlevel" +} fond_second_levels = {"fascicolo" => "file", "unità" => "item"} ca_id_str = sprintf '%08d', fond.id -if fond.fond_type.present? +if !fond.fond_type.present? tags = {:level => "fonds", :id => "CA-#{ca_id_str}"} else level = fond.fond_type - if fond_first_levels[level].nil? + if (fond_first_levels[level] == "otherlevel") tags = {:level => "otherlevel", :otherlevel => level, :id => "CA-#{ca_id_str}"} else tags = {:level => fond_first_levels[level], :id => "CA-#{ca_id_str}"} diff --git a/lib/exporter/views/fonds/_fond_parent_ii.xml.builder b/lib/exporter/views/fonds/_fond_parent_ii.xml.builder index 2b15286..f0c29f2 100644 --- a/lib/exporter/views/fonds/_fond_parent_ii.xml.builder +++ b/lib/exporter/views/fonds/_fond_parent_ii.xml.builder @@ -45,4 +45,4 @@ else }) end end -end \ No newline at end of file +end diff --git a/lib/exporter/views/fonds/fonds_ead.xml.builder b/lib/exporter/views/fonds/fonds_ead.xml.builder index 7698dcd..69f67bc 100644 --- a/lib/exporter/views/fonds/fonds_ead.xml.builder +++ b/lib/exporter/views/fonds/fonds_ead.xml.builder @@ -9,4 +9,4 @@ xml.ead :"xsi:schemaLocation" => "http://ead3.archivists.org/schema/ http://www. xml << render(:partial => "fond_ead.xml", :locals => {:fond => fond}) end -end \ No newline at end of file +end diff --git a/lib/exporter/views/fonds/fonds_ii.xml.builder b/lib/exporter/views/fonds/fonds_ii.xml.builder index e3365ae..faf2d02 100644 --- a/lib/exporter/views/fonds/fonds_ii.xml.builder +++ b/lib/exporter/views/fonds/fonds_ii.xml.builder @@ -101,4 +101,4 @@ xml.ead :"xsi:schemaLocation" => "http://ead3.archivists.org/schema/ http://www. end end end -end \ No newline at end of file +end diff --git a/lib/exporter/views/icar-import/icar-import.xml.builder b/lib/exporter/views/icar-import/icar-import.xml.builder index a24a69d..9965039 100644 --- a/lib/exporter/views/icar-import/icar-import.xml.builder +++ b/lib/exporter/views/icar-import/icar-import.xml.builder @@ -141,4 +141,4 @@ xml.tag! "icar-import:icar-import", { end end end -end \ No newline at end of file +end diff --git a/lib/exporter/views/institutions/_institution_ead.xml.builder b/lib/exporter/views/institutions/_institution_ead.xml.builder index b5385ea..6300e9c 100644 --- a/lib/exporter/views/institutions/_institution_ead.xml.builder +++ b/lib/exporter/views/institutions/_institution_ead.xml.builder @@ -108,3 +108,4 @@ xml.cpfDescription do end end end + diff --git a/lib/exporter/views/institutions/institutions_ead.xml.builder b/lib/exporter/views/institutions/institutions_ead.xml.builder index 5afa3ab..a48fe9f 100644 --- a/lib/exporter/views/institutions/institutions_ead.xml.builder +++ b/lib/exporter/views/institutions/institutions_ead.xml.builder @@ -11,4 +11,4 @@ xml.tag! "eac-cpf", { records.each do |institution| xml << render(:partial => "institution_ead.xml", :locals => {:institution => institution}) end -end \ No newline at end of file +end diff --git a/lib/exporter/views/sources/_source_ead.xml.builder b/lib/exporter/views/sources/_source_ead.xml.builder index 99e7555..c6926e9 100644 --- a/lib/exporter/views/sources/_source_ead.xml.builder +++ b/lib/exporter/views/sources/_source_ead.xml.builder @@ -140,3 +140,4 @@ xml.archdesc :level => first_fond_level do xml.unittitle end end + diff --git a/lib/exporter/views/sources/sources_ead.xml.builder b/lib/exporter/views/sources/sources_ead.xml.builder index 5aa3ee2..86a783c 100644 --- a/lib/exporter/views/sources/sources_ead.xml.builder +++ b/lib/exporter/views/sources/sources_ead.xml.builder @@ -10,4 +10,4 @@ xml.tag! "ead", { records.each do |source| xml << render(:partial => "source_ead.xml", :locals => {:source => source}) end -end \ No newline at end of file +end diff --git a/lib/exporter/views/units/_unit_child_ead.xml.builder b/lib/exporter/views/units/_unit_child_ead.xml.builder index 9404abc..313de19 100644 --- a/lib/exporter/views/units/_unit_child_ead.xml.builder +++ b/lib/exporter/views/units/_unit_child_ead.xml.builder @@ -33,4 +33,4 @@ if unit.has_children? }) end end -end \ No newline at end of file +end diff --git a/lib/exporter/views/units/_unit_desc_ead.xml.builder b/lib/exporter/views/units/_unit_desc_ead.xml.builder index b7a4b63..9327ecd 100644 --- a/lib/exporter/views/units/_unit_desc_ead.xml.builder +++ b/lib/exporter/views/units/_unit_desc_ead.xml.builder @@ -7,6 +7,9 @@ end sc2_tsk = unit_types["sc2_tsks"].key?(unit.sc2_tsk) ? unit_types["sc2_tsks"][unit.sc2_tsk] : nil if file_type.nil? and sc2_tsk.nil? + if unit_type.empty? + unit_type = "otherlevel" + end attributes = {:level => unit_type} else if !file_type.nil? diff --git a/lib/exporter/views/units/_unit_desc_inside_ead.xml.builder b/lib/exporter/views/units/_unit_desc_inside_ead.xml.builder index dff1531..9fd9441 100644 --- a/lib/exporter/views/units/_unit_desc_inside_ead.xml.builder +++ b/lib/exporter/views/units/_unit_desc_inside_ead.xml.builder @@ -204,7 +204,7 @@ "schedatura" => "inserimento" } editors.each do |editor| - xml.processinfo do + xml.processinfo :localtype => "compilatore" do xml.p do xml.persname do if editor.editing_type.present? @@ -217,7 +217,7 @@ xml.part editor.name, :localtype => "compilatore" xml.part editor.qualifier, :localtype => "qualifica" end - dateTime = Time.now.strftime("%Y-%m-%dT%H:%M:%S") + dateTime = editor.edited_at.strftime("%Y-%m-%dT%H:%M:%S") #Time.now.strftime("%Y-%m-%dT%H:%M:%S") xml.date dateTime, :localtype => "dataIntervento" end end @@ -393,7 +393,8 @@ end end - xml.relation :relationtype => "otherrelationtype", :href => "#{UNITS_URL}/#{unit.id}", :otherrelationtype => "URL" do + #xml.relation :relationtype => "otherrelationtype", :href => "#{UNITS_URL}/#{unit.id}", :otherrelationtype => "URL" do + xml.relation :relationtype => "otherrelationtype", :href => "#{FONDS_URL}/#{unit.fond_id}/#{UNITS_URL}/#{unit.id}", :otherrelationtype => "URL" do xml.relationentry PROVIDER end reluniturls = unit.unit_urls @@ -652,6 +653,9 @@ child_sc2_tsk = unit_types["sc2_tsks"].key?(child_unit.sc2_tsk) ? unit_types["sc2_tsks"][child_unit.sc2_tsk] : nil if child_file_type.nil? and child_sc2_tsk.nil? + if child_unit_type.empty? + child_unit_type = "otherlevel" + end attributes = {:level => child_unit_type} else if !child_file_type.nil? diff --git a/lib/exporter/views/units/_unit_ead.xml.builder b/lib/exporter/views/units/_unit_ead.xml.builder index eacd78d..82b4b2d 100644 --- a/lib/exporter/views/units/_unit_ead.xml.builder +++ b/lib/exporter/views/units/_unit_ead.xml.builder @@ -81,18 +81,18 @@ end fond_types = { "archivio" => "fonds", + "fondo" => "fonds", "complesso di fondi" => "recordgrp", "iperfondo" => "recordgrp", - "fondo" => "fonds", "subfondo" => "subfonds", "sezione" => "subfonds", - "sottosezione" => "otherlevel", "partizione" => "subfonds", "sottopartizione" => "subfonds", + "parte" => "subfonds", "serie" => "series", "sottoserie" => "subseries", "sottosottoserie" => "subseries", - "parte" => "subfonds", + "sottosezione" => "otherlevel", "categoria" => "otherlevel", "classe" => "otherlevel", "sottoclasse" => "otherlevel", diff --git a/lib/exporter/views/units/_unit_fond_ead.xml.builder b/lib/exporter/views/units/_unit_fond_ead.xml.builder index f037e49..fbc62f4 100644 --- a/lib/exporter/views/units/_unit_fond_ead.xml.builder +++ b/lib/exporter/views/units/_unit_fond_ead.xml.builder @@ -70,4 +70,4 @@ else }) end end -end \ No newline at end of file +end diff --git a/lib/exporter/views/units/_unit_parent_ead.xml.builder b/lib/exporter/views/units/_unit_parent_ead.xml.builder index b50233f..d02945e 100644 --- a/lib/exporter/views/units/_unit_parent_ead.xml.builder +++ b/lib/exporter/views/units/_unit_parent_ead.xml.builder @@ -11,6 +11,9 @@ end parent_sc2_tsk = unit_types["sc2_tsks"].key?(parent_unit.sc2_tsk) ? unit_types["sc2_tsks"][parent_unit.sc2_tsk] : nil if parent_file_type.nil? and parent_sc2_tsk.nil? + if parent_unit_type.empty? + parent_unit_type = "otherlevel" + end xml.c :level => parent_unit_type do xml.did do pua_id_str = sprintf '%08d', parent_unit.id diff --git a/lib/exporter/views/units/_unit_root_fond_archdesc_ead.xml.builder b/lib/exporter/views/units/_unit_root_fond_archdesc_ead.xml.builder index cdc340a..51d4403 100644 --- a/lib/exporter/views/units/_unit_root_fond_archdesc_ead.xml.builder +++ b/lib/exporter/views/units/_unit_root_fond_archdesc_ead.xml.builder @@ -65,4 +65,4 @@ xml.dsc do :sequence_numbers => sequence_numbers }) end -end \ No newline at end of file +end diff --git a/lib/exporter/views/units/unit_ii.xml.builder b/lib/exporter/views/units/unit_ii.xml.builder index 7b9ac24..279c3b0 100644 --- a/lib/exporter/views/units/unit_ii.xml.builder +++ b/lib/exporter/views/units/unit_ii.xml.builder @@ -192,7 +192,9 @@ xml.c attributes do unit.digital_objects.each do |dob| dobj_id_str = sprintf '%08d', dob.id - xml.dao :daotype => "derived", :linkrole => dob.asset_content_type, :id => "OD-#{dobj_id_str}", :href => "#{DIGITAL_OBJECTS_URL}/#{dob.access_token}/original.jpg" + #xml.dao :daotype => "derived", :linkrole => dob.asset_content_type, :id => "OD-#{dobj_id_str}", :href => "#{DIGITAL_OBJECTS_URL}/#{dob.access_token}/original.jpg" + dob_file_ext = dob.asset_file_name.split('.').last + xml.dao :daotype => "derived", :linkrole => dob.asset_content_type, :id => "OD-#{dobj_id_str}", :href => "#{dob.access_token}/original.#{dob_file_ext}" end end @@ -245,7 +247,7 @@ xml.c attributes do "schedatura" => "inserimento" } editors.each do |editor| - xml.processinfo do + xml.processinfo :localtype => "compilatore" do xml.p do xml.persname do if editor.editing_type.present? @@ -434,7 +436,8 @@ xml.c attributes do end end - xml.relation :relationtype => "otherrelationtype", :href => "#{UNITS_URL}/#{unit.id}", :otherrelationtype => "URL" do + #xml.relation :relationtype => "otherrelationtype", :href => "#{UNITS_URL}/#{unit.id}", :otherrelationtype => "URL" do + xml.relation :relationtype => "otherrelationtype", :href => "#{FONDS_URL}/#{unit.fond_id}/#{UNITS_URL}/#{unit.id}", :otherrelationtype => "URL" do xml.relationentry PROVIDER end reluniturls = unit.unit_urls @@ -684,4 +687,4 @@ xml.c attributes do unit.children.each do |child| xml << view.render(:file => "unit_ii.xml.builder", :locals => {:unit => child, :view => view}) end -end \ No newline at end of file +end diff --git a/lib/exporter/views/units/units_ead.xml.builder b/lib/exporter/views/units/units_ead.xml.builder index 8afc0bb..b366605 100644 --- a/lib/exporter/views/units/units_ead.xml.builder +++ b/lib/exporter/views/units/units_ead.xml.builder @@ -8,4 +8,4 @@ xml.instruct! :xml, :version => "1.0", :encoding => "UTF-8" records.each do |unit| xml << render(:partial => "unit_ead.xml", :locals => {:unit => unit}) end -end \ No newline at end of file +end diff --git a/lib/report_support.rb b/lib/report_support.rb index 3b53e96..ff0d40e 100644 --- a/lib/report_support.rb +++ b/lib/report_support.rb @@ -591,7 +591,8 @@ def prv_html_print_field(dont_use_fld_captions, ai, caption_postfix, text) op_html = op_html + "" + ai.name_caption + caption_postfix + "" op_html = op_html + "

" end - op_html = op_html + textilize_with_entities(text) + #op_html = op_html + textilize_with_entities(text) + op_html = op_html + textilize_with_entities(text.gsub('b. ', 'b. ')) # bug fix: la stringa 'b. ' viene rimpiazzata con ''; causa: bug in textilize ? return op_html end diff --git a/lib/tasks/archimista_aef.rake b/lib/tasks/archimista_aef.rake index 002b6ab..17f3b35 100644 --- a/lib/tasks/archimista_aef.rake +++ b/lib/tasks/archimista_aef.rake @@ -1,7 +1,7 @@ require 'zip' require 'builder' -TMP_AEF_EXPORTS = "#{Rails.root}/tmp/exports" +TMP_AEF_EXPORTS = "#{Rails.root}/public/exports" namespace :aef do diff --git a/lib/tasks/archimista_ead.rake b/lib/tasks/archimista_ead.rake index 413cedf..3e87481 100644 --- a/lib/tasks/archimista_ead.rake +++ b/lib/tasks/archimista_ead.rake @@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), "..", "exporter/Configurazione_dl.rb") require 'zip' require 'builder' -TMP_RAKE_EAD_EXPORTS = "#{Rails.root}/tmp/exports" +TMP_RAKE_EAD_EXPORTS = "#{Rails.root}/public/exports" namespace :ead do @@ -49,6 +49,7 @@ namespace :ead do xml = view.render(:file => "#{file}.builder", :locals => {:records => [records], :fond_ids => ids}) File.open(file_dest, 'w+') { |f| f.write(xml) } file_dest_path = file_dest.path + file_dest.close Zip::File.open(zip_file_name, Zip::File::CREATE) do |zipfile| zipfile.add(file_name, file_dest_path) @@ -64,12 +65,14 @@ namespace :ead do end def build_icar_import(fond) - zip_file_name = TMP_RAKE_EAD_EXPORTS + "/icar-import.zip" + prefix = Time.now.strftime("%Y-%m-%d-%H-%M-%S-") + + zip_file_name = TMP_RAKE_EAD_EXPORTS + "/#{prefix}icar-import-#{fond.id}.zip" File.delete(zip_file_name) if File.exist?(zip_file_name) - file_name = "icar-import-#{fond.id}.xml" + file_name = "#{prefix}icar-import-#{fond.id}.xml" data_file_name = TMP_RAKE_EAD_EXPORTS + "/" + file_name - file_dest = File.new(data_file_name, 'w+') + file_dest = File.new(data_file_name, 'w+') view = ActionView::Base.new(views_path("icar-import")) xml = ::Builder::XmlMarkup.new(target: file_dest, :indent => 2) digital_objects = Array.new @@ -86,36 +89,46 @@ namespace :ead do Zip::File.open(zip_file_name, Zip::File::CREATE) do |zipfile| zipfile.add(file_name, file_dest.path) end - File.delete(TMP_RAKE_EAD_EXPORTS + "/" + file_name) if File.exist?(TMP_RAKE_EAD_EXPORTS + "/" + file_name) - - #oggetti digitali - fonds_id = Array.new - fonds_id.push(fond.id) - if fond.ancestry.nil? - query = "ancestry LIKE '#{fond.id}/%' OR ancestry = '#{fond.id}'" - else - query = "ancestry LIKE '#{fond.ancestry}/%' OR ancestry = '#{fond.ancestry}'" + + begin + file_dest.close + File.delete(data_file_name) if File.exist?(data_file_name) + rescue Exception => e + puts "ECCEZIONE in archimista_ead.rake > build_icar_import: #{e.message}" end - children_ids = Fond.where(query).pluck(:id) - fonds_id = fonds_id + children_ids - unit_ids = Unit.where(fond_id: fonds_id).pluck(:id) - digital_objects = DigitalObject.where(attachable_id: unit_ids) - if !digital_objects.empty? - Zip::File.open(zip_file_name, false) do |zipfile| - digital_objects.each do |digital_object| - dob_id_str = sprintf '%08d', digital_object.id - file_path = "#{Rails.root}/public/digital_objects/#{digital_object.access_token}/original." - if digital_object.asset_content_type == "application/pdf" - file_path.concat("pdf") - else - file_path.concat("jpg") - end - if File.file?(file_path) - zipfile.add("OD-#{dob_id_str}/#{digital_object.asset_file_name}", file_path) + + #oggetti digitali + begin + fonds_id = Array.new + fonds_id.push(fond.id) + if fond.ancestry.nil? + query = "ancestry LIKE '#{fond.id}/%' OR ancestry = '#{fond.id}'" + else + query = "ancestry LIKE '#{fond.ancestry}/%' OR ancestry = '#{fond.ancestry}'" + end + children_ids = Fond.where(query).pluck(:id) + fonds_id = fonds_id + children_ids + unit_ids = Unit.where(fond_id: fonds_id).pluck(:id) + digital_objects = DigitalObject.where(attachable_id: unit_ids) + 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 + puts "ECCEZIONE nell'esportazione di un Oggetto Digitale: #{e.message}" + end end end end + rescue Exception => e + puts "ECCEZIONE nell'esportazione di Oggetti Digitali: #{e.message}" end + puts "Creazione file ICAR-IMPORT terminata." end desc "Genera metadati EAD relativi a: [fonds | creators | institutions | custodians | sources | units | anagraphics | icar-import]" @@ -130,7 +143,8 @@ namespace :ead do @fonds = Fond.find_by_sql(query) if @fonds.count > 0 puts "Creazione file EAD contenente #{@fonds.count} complessi archivistici ..." - zip_file_name = TMP_RAKE_EAD_EXPORTS + "/fonds.zip" + prefix = Time.now.strftime("%Y-%m-%d-%H-%M-%S-") + zip_file_name = TMP_RAKE_EAD_EXPORTS + "/" + prefix + "fonds.zip" puts "... Attendere, creazione file in corso ..." File.delete(zip_file_name) if File.exist?(zip_file_name) @fonds.each do |f| @@ -139,7 +153,7 @@ namespace :ead do part_zips_count = Zip::File.split(zip_file_name, 1_152, false) puts "File creato: #{zip_file_name}" - Dir.glob("#{zip_file_name}.*").each { |file| File.delete(file)} + Dir.glob("#{TMP_RAKE_EAD_EXPORTS}/ca-*.xml").each { |file| File.delete(file)} else puts "Nessun complesso archivistico trovato." end @@ -234,7 +248,8 @@ namespace :ead do @sources = Source.find_by_sql(query) if @sources.count > 0 puts "Creazione file EAD contenente #{@sources.count} fonti / strumenti di ricerca ..." - zip_file_name = TMP_RAKE_EAD_EXPORTS + "/sources.zip" + prefix = Time.now.strftime("%Y-%m-%d-%H-%M-%S-") + zip_file_name = TMP_RAKE_EAD_EXPORTS + "/" + prefix + "sources.zip" puts "... Attendere, creazione file in corso ..." File.delete(zip_file_name) if File.exist?(zip_file_name) @sources.each do |s| @@ -327,4 +342,4 @@ namespace :ead do puts "Argomento non valido.\nScegli tra [fonds | creators | institutions | custodians | sources | units | anagraphics | icar-import]" end end -end \ No newline at end of file +end diff --git a/lib/tasks/archimista_import.rake b/lib/tasks/archimista_import.rake new file mode 100644 index 0000000..50d6b72 --- /dev/null +++ b/lib/tasks/archimista_import.rake @@ -0,0 +1,150 @@ +=begin + +Esegue l'importazione batch di file aef o in formato XML secondo i tracciati +EAD3, EAC-CPF, SCONS2, ICAR-IMPORT + +Lanciare nella console come segue: + + RAILS_ENV=production rake import[,] + +dove: + + è la username dell'utente Archimista con cui eseguire l'import + + + è il nome del file da importare che deve essere preventivamente + copiato nella cartella: #{Rails.root}/public/imports/batch_import/ + +Esempio: + + RAILS_ENV=production rake import["admin_archimista","Complesso.xml"] + +NB: non inserire spazi prima, dopo e tra i valori dei parametri + e + per evitare l'errore: "Don't know how to build task" + +=end +require File.join(File.dirname(__FILE__), "../../app/controllers", "application_controller.rb") +require File.join(File.dirname(__FILE__), "../../app/controllers", "imports_controller.rb") +require File.join(File.dirname(__FILE__), "../../config/initializers", "devise.rb") +require File.join(File.dirname(__FILE__), "../../app/models", "user.rb") +require File.join(File.dirname(__FILE__), "../../app/models", "rel_user_group.rb") +require File.join(File.dirname(__FILE__), "../../app/models", "digital_object.rb") +require File.join(File.dirname(__FILE__), "../../config/initializers", "metadata.rb") +require 'fileutils' +require 'active_record' + +task :default => [:import] + +DEBUG_MODE = false + +USO_DEL_TASK = "\n>>> Il task Esegue l'importazione batch di file aef o in formato XML\n secondo i tracciati EAD3, EAC-CPF, SCONS2, ICAR-IMPORT\n\n USO DEL TASK:\n RAILS_ENV=production rake import[,]\n\n Esempio:\n RAILS_ENV=production rake import[\"admin_archimista\",\"Complesso.xml\"]\n\n NB: il file da importare deve essere preventivamente copiato nella cartella:\n #{Rails.root}/public/imports/batch_import/" + +task :import, [:username, :import_filename] do |task, args| + + puts "\n> Esecuzione task di importazione" + + if DEBUG_MODE + puts "\n" + puts "+ Rails.root : #{Rails.root}" + puts "+ Rails.env : #{Rails.env}" + puts "+ Rails.logger.nil? : #{Rails.logger.nil?}" + puts "+ Rake file full path : #{__FILE__}" + puts "+ args[:username] : #{args[:username]}" + puts "+ args[:import_filename] : #{args[:import_filename]}" + end + + if Rails.logger.nil? + puts "\n>>> Rails.logger è NIL" + log_file_name = "#{Rails.env}.log" + Rails.logger = Logger.new("#{Rails.root}/log/#{log_file_name}") + puts "\n> Rails.logger sta ora loggando su #{log_file_name}" + Rails.logger.info "Inizio log del rake task #{__FILE__}" + end + + I18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}')] + I18n.locale = :it + I18n.default_locale = :it + puts "\n> I18n.locale : #{I18n.locale}" + if DEBUG_MODE + puts "+ I18n.load_path : #{I18n.load_path}" + puts "+ I18n.t 'created_at' : #{I18n.t 'created_at'}" # test di traduzione + end + + db_config = Rails.application.config.database_configuration[Rails.env] + if DEBUG_MODE + puts "\n+ db_config: #{db_config}" + end + + ActiveRecord::Base.establish_connection(db_config) + ActiveRecord::Base.connection + + if ActiveRecord::Base.connected? + puts "\n> Connesso al Database" + else + puts "\n>>> NON CONNESSO AL DATABASE" + puts "\n>>> Task terminato." + exit + end + + username = args[:username] + if !username.nil? + username.strip! + else + username = "" + end + + if username == "" + puts USO_DEL_TASK + puts "\n>>> USERNAME DELL'UTENTE PER L'IMPORT NON SPECIFICATO" + puts "\n>>> Task terminato." + exit + end + + batch_import_user = User.where(username: username).first + if batch_import_user.present? + puts "\n> Utente per l'import trovato" + puts " Username: #{username}" + puts " ID : #{batch_import_user[:id]}" + puts " E-mail : #{batch_import_user[:email]}" + else + puts "\n>>> USERNAME DELL'UTENTE PER L'IMPORT NON TROVATO" + puts " Username: #{username}" + puts "\n>>> Task terminato." + exit + end + + batch_import_filename = args[:import_filename] + if !batch_import_filename.nil? + batch_import_filename.strip! + else + batch_import_filename = "" + end + + if batch_import_filename == "" + puts USO_DEL_TASK + puts "\n>>> NOME DEL FILE DA IMPORTARE NON SPECIFICATO" + puts "\n>>> Task terminato." + exit + end + + src_file = File.join(Rails.root, "public", "imports", "batch_import", batch_import_filename) + if !File.file?(src_file) + puts USO_DEL_TASK + puts "\n>>> FILE DA IMPORTARE NON TROVATO" + puts " Filename: #{batch_import_filename}" + puts "\n>>> Task terminato." + exit + end + + @imports_controller = ImportsController.new + @imports_controller.is_batch_import = true + @imports_controller.batch_import_user = batch_import_user + @imports_controller.batch_import_filename = batch_import_filename + + require File.join(File.dirname(__FILE__), "../../app/models", "import.rb") + + @imports_controller.new + @imports_controller.create + +end diff --git a/lib/tasks/archimista_san.rake b/lib/tasks/archimista_san.rake index 5088ab9..a12f134 100644 --- a/lib/tasks/archimista_san.rake +++ b/lib/tasks/archimista_san.rake @@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), "..", "exporter/Configurazione_dl.rb") require 'zip' require 'builder' -TMP_RAKE_EXPORTS = "#{Rails.root}/tmp/exports" +TMP_RAKE_EXPORTS = "#{Rails.root}/public/exports" namespace :san do diff --git a/lib/tasks/repair.rake b/lib/tasks/repair.rake index 414d4b8..826883f 100644 --- a/lib/tasks/repair.rake +++ b/lib/tasks/repair.rake @@ -26,6 +26,7 @@ namespace :repair do "rel_project_fonds" => ["project_id", "fond_id"], "rel_unit_headings" => ["unit_id", "heading_id"], "rel_unit_sources" => ["unit_id", "source_id"], + "rel_unit_anagraphics" => ["unit_id", "anagraphic_id"] } tables.each do |table, foreign_keys| diff --git a/public/assets/.gitignore b/public/assets/.gitignore index e69de29..5e7d273 100644 --- a/public/assets/.gitignore +++ b/public/assets/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/public/images/logo-lombardia.jpg b/public/images/logo-lombardia.jpg index eb28d8f..8ea89af 100644 Binary files a/public/images/logo-lombardia.jpg and b/public/images/logo-lombardia.jpg differ diff --git a/public/javascripts/fonds-merge.js b/public/javascripts/fonds-merge.js index 49cb87b..ea550d3 100644 --- a/public/javascripts/fonds-merge.js +++ b/public/javascripts/fonds-merge.js @@ -1,28 +1,41 @@ $(document).ready(function () { $.jump_to_fonds = {}; - $(document).delegate(".merge", 'click', function () { var id = $(this).attr('data-id'); $.get('fonds/' + id + '/merge_with').success(function (data) { - + $('#merge-with-container').html(data); $('#merge-with-container #merge-fonds-modal').modal("show"); - + }); }); $(document).delegate("#fonds-list input[@name='new_root_id']", 'click', function (event) { - var target_value = event.target.value; - $.jump_to_fonds.tree = $("#jump-to-tree" + target_value); - $.jump_to_fonds.jump(target_value); + var id = $(this).val(); + + if($('#fondmerge-'+id).hasClass('open')){ + $('#fondmerge-'+id).removeClass('open'); + }else{ + $('.dropdown.divmerge').each(function () { + if ($(this).hasClass('open')) { + $(this).removeClass('open'); + } + }); + $('#fondmerge-'+id).addClass('open'); + + var target_value = event.target.value; + $.jump_to_fonds.tree = $("#jump-to-tree" + target_value); + $.jump_to_fonds.jump(target_value); + } + }); $.jump_to_fonds.tree_setup = function ($tree, root_id, current_node_id) { - var self, target_node_id; + var self, target_node_id, target_name; self = this; @@ -50,7 +63,8 @@ $(document).ready(function () { .delegate("li a", "click", function (event) { event.stopPropagation(); target_node_id = $(this).parent("li").attr('id').split('-').pop(); - $tree.trigger("node_selected.custom_jstree", target_node_id); + target_name = $(this)[0].innerText; + $tree.trigger("node_selected.custom_jstree", {target_node_id: target_node_id, target_name: target_name}); }) .delegate($tree, "click", function (event) { event.stopPropagation(); @@ -59,7 +73,7 @@ $(document).ready(function () { }; $.jump_to_fonds.jump = function (target_id) { - + var self, root_id, current_node_id, action; self = this; @@ -68,40 +82,25 @@ $.jump_to_fonds.jump = function (target_id) { root_id = target_id; current_node_id = target_id; action = self.tree.data('action'); - + self.tree_setup(self.tree, root_id, current_node_id); self.tree.bind("loaded.jstree", function (event, data) { $(this).jstree("open_all"); }); - self.tree.bind('node_selected.custom_jstree', function (event, target_node_id) { + self.tree.bind('node_selected.custom_jstree', function (event, target_node) { if (action === "gridview" ) { } else { $('.dropdown.divmerge').removeClass('open'); - $("input[name='choosen_root_id']").val(target_node_id); + $("input[name='choosen_root_id']").val(target_node.target_node_id); + $('#fonds-list input[name="new_root_id"]').parent().find(".sub-selected" ).text(""); + $('#fonds-list input[name="new_root_id"]:checked ').parent().find(".sub-selected" ).text(" - " + target_node.target_name); $("#confirm-merge").prop('disabled', false).removeClass('disabled'); } }); }; - - - $(document).delegate("#fonds-list input[@name='new_root_id']", 'click', function () { - var id = $(this).val(); - - if($('#fondmerge-'+id).hasClass('open')){ - $('#fondmerge-'+id).removeClass('open'); - }else{ - $('.dropdown.divmerge').each(function () { - if ($(this).hasClass('open')) { - $(this).removeClass('open'); - } - }); - $('#fondmerge-'+id).addClass('open'); - } - }); - $(document).delegate('.livesearch', 'click', function () { var id = $(this).find("input").val(); $('.livesearch').each(function () { diff --git a/public/javascripts/imports-exports.js b/public/javascripts/imports-exports.js index b16b514..2752842 100644 --- a/public/javascripts/imports-exports.js +++ b/public/javascripts/imports-exports.js @@ -15,17 +15,19 @@ $(document).ready(function() { $("#inc_ead").click(function(event) { if ($("#inc_ead").is(":checked")) { + $("#inc_digit").attr('checked', true); + $("#inc_digit").attr("disabled", true); + $("#inc_entities").attr('checked', true); + $("#inc_entities").attr('disabled', true); $("#inc_san").attr('checked', false); $("#inc_san").attr("disabled", true); - $("#inc_digit").attr('checked', false); - $("#inc_digit").attr("disabled", true); - $("#sources").removeClass('tab-xml'); - $("#creators").removeClass('tab-xml'); } else { - $("#inc_san").removeAttr("disabled"); - $("#inc_digit").removeAttr("disabled"); - $("#sources").addClass('tab-xml'); - $("#creators").addClass('tab-xml'); + $("#inc_digit").attr('checked', false); + $("#inc_digit").attr("disabled", false); + $("#inc_entities").attr('checked', false); + $("#inc_entities").attr('disabled', false); + $("#inc_san").attr('checked', false); + $("#inc_san").attr("disabled", false); } }); @@ -483,6 +485,8 @@ $(document).ready(function() { $('#export-tabs a:first').tab('show'); $('#export-tabs li a').click(function(event) { + $("#inc_digit").attr('checked', false); + $("#inc_digit").attr("disabled", false); if ($(this).text().includes('Progetti')) { $("#inc_ead").prop('checked', false); $("#inc_ead").attr("disabled", true); @@ -490,9 +494,12 @@ $(document).ready(function() { $("#inc_san").attr("disabled", true); $("#inc_entities").prop('checked', false); $("#inc_entities").attr("disabled", true); + } else if ($(this).text().includes('Complessi')) { + $("#inc_ead").prop('checked', false); + $("#inc_ead").attr("disabled", false); } else { $("#inc_ead").prop('checked', false); - $("#inc_ead").removeAttr("disabled"); + $("#inc_ead").attr("disabled", true); $("#inc_san").prop('checked', false); $("#inc_san").removeAttr("disabled"); $("#inc_entities").prop('checked', false); @@ -500,7 +507,5 @@ $(document).ready(function() { $("#sources").addClass('tab-xml'); $("#creators").addClass('tab-xml'); } - }); - }); \ No newline at end of file diff --git a/public/javascripts/jqGrid/jquery.jqGrid.min.js b/public/javascripts/jqGrid/jquery.jqGrid.min.js index 5e4f791..f04bb3f 100644 --- a/public/javascripts/jqGrid/jquery.jqGrid.min.js +++ b/public/javascripts/jqGrid/jquery.jqGrid.min.js @@ -1,12 +1,12 @@ -/* -* jqGrid 4.3.1 - jQuery Grid -* Copyright (c) 2008, Tony Tomov, tony@trirand.com -* Dual licensed under the MIT and GPL licenses -* http://www.opensource.org/licenses/mit-license.php -* http://www.gnu.org/licenses/gpl-2.0.html -* Date:2011-12-20 -* Modules: grid.base.js; jquery.fmatter.js; grid.custom.js; grid.common.js; grid.formedit.js; grid.filter.js; grid.inlinedit.js; grid.celledit.js; jqModal.js; jqDnR.js; grid.subgrid.js; grid.grouping.js; grid.treegrid.js; grid.import.js; JsonXml.js; grid.tbltogrid.js; grid.jqueryui.js; -*/ +/* +* jqGrid 4.3.1 - jQuery Grid +* Copyright (c) 2008, Tony Tomov, tony@trirand.com +* Dual licensed under the MIT and GPL licenses +* http://www.opensource.org/licenses/mit-license.php +* http://www.gnu.org/licenses/gpl-2.0.html +* Date:2011-12-20 +* Modules: grid.base.js; jquery.fmatter.js; grid.custom.js; grid.common.js; grid.formedit.js; grid.filter.js; grid.inlinedit.js; grid.celledit.js; jqModal.js; jqDnR.js; grid.subgrid.js; grid.grouping.js; grid.treegrid.js; grid.import.js; JsonXml.js; grid.tbltogrid.js; grid.jqueryui.js; +*/ /* jqGrid 4.3.1 - jQuery Grid Copyright (c) 2008, Tony Tomov, tony@trirand.com diff --git a/public/javascripts/livesearch_fondmerge.js b/public/javascripts/livesearch_fondmerge.js new file mode 100644 index 0000000..17e44e1 --- /dev/null +++ b/public/javascripts/livesearch_fondmerge.js @@ -0,0 +1,129 @@ +jQuery.fn.liveUpdateFondMerge = function (list, options) { + + var cache = {}, + settings = $.extend({ + 'url': '', + 'field': '', + 'targetClass': 'livesearch', + 'selectedClass': 'highlight', + 'group_id': { + group_id: -1 + }, + 'exclude': { + exclude: [] + } + }, options); + + /* private methods */ + + function fill(data) { + var items = []; + $.each(data, function (key, val) { + + var liHtml = '
  • '; + liHtml += '