app/models/in_progress_etd.rb
# If this record is associated with an Etd record
# that has already been persisted to fedora, we
# need to refresh the JSON data store with the
# latest data from the Etd.  (This record
# may contain stale data if the Etd record was
# updated outside the UI, e.g. a background job.)
If this record is associated with an Etd record
that has already been persisted to fedora, we
need to refresh the JSON data store with the
latest data from the Etd.  (This record
may contain stale data if the Etd record was
updated outside the UI, e.g. a background job.)
If this record is associated with an Etd record that has already been persisted to fedora we need to refresh the JSON data store with the latest data from the Etd . ( This record may contain stale data if the Etd record was updated outside the UI e . g . a background job . )
def refresh_from_etd!
    return if etd_id.blank?
    etd = Etd.find etd_id
    new_data = {}
    new_data['ipe_id'] = id unless id.blank?
    new_data['etd_id'] = etd_id unless etd_id.blank?
    all_simple_fields.each do |field|
      new_value = etd.send field
      new_data[field] = new_value[0] unless new_value.blank?
    end
    new_data['degree_awarded'] = etd.degree_awarded 
    new_data['embargo_length'] = etd.embargo_length
    new_data['keyword'] = etd.keyword
    new_data['department'] = etd.department
    new_data['research_field'] = etd.research_field
    new_data['other_copyrights'] = etd.other_copyrights
    new_data['patents'] = etd.patents
    new_data['requires_permissions'] = etd.requires_permissions
    new_data['partnering_agency'] = etd.partnering_agency
    em_type = EmbargoTypeFromAttributes.new(etd.files_embargoed, etd.toc_embargoed, etd.abstract_embargoed)
    new_data['embargo_type'] = em_type.s
    etd_members = etd.committee_members.map { |member| JSON.parse(member.to_json) }.map { |values| { name: values["name"], affiliation: values["affiliation"] } }.uniq
    members = []
    etd_members.each do |member|
      if member[:affiliation] != 'Emory University'
        members.push(name: member[:name], affiliation: member[:affiliation], affiliation_type: 'Non-Emory')
      end
      if member[:affiliation] == 'Emory University'
        members.push(name: member[:name], affiliation: member[:affiliation], affiliation_type: 'Emory University')
      end
    end
    new_data['committee_members_attributes'] = members.uniq unless members.blank?
    etd_chairs = etd.committee_chair.map { |chair| JSON.parse(chair.to_json) }.map { |values| { name: values["name"], affiliation: values["affiliation"] } }.uniq
    chairs = []
    etd_chairs.each do |chair|
      if chair[:affiliation] != ['Emory University']
        chairs.push(name: chair[:name], affiliation: chair[:affiliation], affiliation_type: 'Non-Emory')
      end
      if chair[:affiliation] == ['Emory University']
        chairs.push(name: chair[:name], affiliation: chair[:affiliation], affiliation_type: 'Emory University')
      end
    end
    new_data['committee_chair_attributes'] = chairs.uniq unless chairs.blank?
    primary_file = file_for_refresh(etd.primary_file_fs.first)
    new_data['files'] = primary_file.to_json unless primary_file.blank?
    unless etd.supplemental_files_fs.blank?
      new_data['supplemental_files'], new_data['supplemental_file_metadata'] = supplemental_files_for_refresh(etd)
    end
    self.data = new_data.to_json
    save!
  end
def refresh_from_etd! return if etd_id . blank? etd = Etd . find etd_id new_data = { } new_data [ 'ipe_id' ] = id unless id . blank? new_data [ 'etd_id' ] = etd_id unless etd_id . blank? all_simple_fields . each do | field | new_value = etd . send field new_data [ field ] = new_value [ 0 ] unless new_value . blank? end new_data [ 'degree_awarded' ] = etd . degree_awarded new_data [ 'embargo_length' ] = etd . embargo_length new_data [ 'keyword' ] = etd . keyword new_data [ 'department' ] = etd . department new_data [ 'research_field' ] = etd . research_field new_data [ 'other_copyrights' ] = etd . other_copyrights new_data [ 'patents' ] = etd . patents new_data [ 'requires_permissions' ] = etd . requires_permissions new_data [ 'partnering_agency' ] = etd . partnering_agency em_type = EmbargoTypeFromAttributes . new ( etd . files_embargoed , etd . toc_embargoed , etd . abstract_embargoed ) new_data [ 'embargo_type' ] = em_type . s etd_members = etd . committee_members . map { | member | JSON . parse ( member . to_json ) } . map { | values | { name : values [ "name" ] , affiliation : values [ "affiliation" ] } } . uniq members = [ ] etd_members . each do | member | if member [ :affiliation ] != 'Emory University' members . push ( name : member [ :name ] , affiliation : member [ :affiliation ] , affiliation_type : 'Non-Emory' ) end if member [ :affiliation ] == 'Emory University' members . push ( name : member [ :name ] , affiliation : member [ :affiliation ] , affiliation_type : 'Emory University' ) end end new_data [ 'committee_members_attributes' ] = members . uniq unless members . blank? etd_chairs = etd . committee_chair . map { | chair | JSON . parse ( chair . to_json ) } . map { | values | { name : values [ "name" ] , affiliation : values [ "affiliation" ] } } . uniq chairs = [ ] etd_chairs . each do | chair | if chair [ :affiliation ] != [ 'Emory University' ] chairs . push ( name : chair [ :name ] , affiliation : chair [ :affiliation ] , affiliation_type : 'Non-Emory' ) end if chair [ :affiliation ] == [ 'Emory University' ] chairs . push ( name : chair [ :name ] , affiliation : chair [ :affiliation ] , affiliation_type : 'Emory University' ) end end new_data [ 'committee_chair_attributes' ] = chairs . uniq unless chairs . blank? primary_file = file_for_refresh ( etd . primary_file_fs . first ) new_data [ 'files' ] = primary_file . to_json unless primary_file . blank? unless etd . supplemental_files_fs . blank? new_data [ 'supplemental_files' ] , new_data [ 'supplemental_file_metadata' ] = supplemental_files_for_refresh ( etd ) end self . data = new_data . to_json save! end
If this record is associated with an Etd record
that has already been persisted to fedora, we
need to refresh the JSON data store with the
latest data from the Etd.
If this record is associated with an Etd record that has already been persisted to fedora we need to refresh the JSON data store with the latest data from the Etd .
# Fedora returns arrays for these -- we aren't using arrays in the form # so this needs to use an array accessor # Needed by javascript # This code allows you to display and add chairs and members on the # edit form, but not remove them.