lib/daengine/teamsite_metadata_parser.rb in daengine-0.1.7 vs lib/daengine/teamsite_metadata_parser.rb in daengine-0.1.8

- old
+ new

@@ -21,11 +21,11 @@ "TeamSite/Metadata/enterprise_last_content_update_date" => 'doc_changed_at', "TeamSite/Metadata/enterprise_content_type_id" => 'content_type' } @@validations = { "TeamSite/Metadata/display_on_website" => lambda { |val| /Y|1/ =~ val }, - "TeamSite/Metadata/enterprise_expiration_date" => lambda { |val| Time.parse(val) > 1.minute.from_now }, + "TeamSite/Metadata/enterprise_expiration_date" => lambda {|val| !val.blank? }, # "TeamSite/Metadata/enterprise_unpublish_date" => lambda {|val| val.blank? }, "path" => lambda {|val| !(/\/manifest\// =~ val) } } @@logger = nil @@ -77,33 +77,36 @@ error_files = [] update_count = 0; delete_count = 0; added_count = 0; assets.keys.each do |key| da = nil begin - if(!assets[key]['unpublished_at'].blank?) - DigitalAsset.where(guid: key).delete_all - delete_count += 1 + if (!assets[key]['unpublished_at'].nil?) + DigitalAsset.where(guid: key).try :delete_all + delete_count += 1 + elsif (assets[key]['expires_at'].nil? || (assets[key]['expires_at'] < 1.minute.from_now)) + DigitalAsset.where(guid: key).try :delete_all + delete_count += 1 else da = DigitalAsset.find_or_initialize_by(guid: key) creating = da.new? da.documents = [] da.update_attributes!(assets[key]) if(creating) added_count += 1 - else + else update_count += 1 end end rescue Exception => e - error_files << e.to_s + #puts "--**Exception**--- #{e}" error_files << "#{da.try(:guid)}, #{da.try(:errors).try(:full_messages)}" end end log_txt = "TeamsiteMetadataParser: Failed to save/update following DigitalAssets in database:\n" error_files.each do |asset_file| log_txt = log_txt + "> #{asset_file}\n" end - Daengine.log(log_txt, "warn") if error_files + Daengine.log(log_txt, "warn") if !error_files.empty? DigitalAsset.purge! # if the purge criteria is met, purge anything not updated Daengine.log("TeamsiteMetadataParser: #{added_count} records added, #{update_count} updated, #{delete_count} removed", "info") end end