<commit_before># Generated via
#  `rails generate hyrax:work Vdc::Resource`

module Hyrax
  class Vdc::ResourcesController < ApplicationController
    # Adds Hyrax behaviors to the controller.
    include Hyrax::WorksControllerBehavior
    include Hyrax::BreadcrumbsForWorks
    self.curation_concern_type = ::Vdc::Resource

    self.show_presenter = Hyrax::Vdc::ResourcePresenter

    def attributes_for_actor
      super.tap do |attributes|
        # TODO: Find out if there's a better way to get readme_file_ids_from_form,
        #       other than using a property from the resource model. Seems like there
        #       should be
        readme_file_ids_from_form = params.fetch(:readme_file_ids_from_form, nil)
        attributes[:readme_file_ids_from_form] = readme_file_ids_from_form
        attributes        
      end
    end

    def new
      # Set the default vdc creator to be the current user when creating a new resource
      curation_concern.vdc_creator << current_user.identifier_system
      super
    end

    def create
      super
      perform_cu_post_processing
    end

    #def edit
    #  super
    #end

    def update
      super
      perform_cu_post_processing
    end

    # Post-processing for Create and Update
    def perform_cu_post_processing
      # Reload to get all fields (including member extracted_text and mime_type) 
      # loaded properly
      curation_concern.reload 

      set_extent
      set_format
      set_doi

      curation_concern.save!
      
      # Reindex the members to get them into solr properly
      curation_concern.members.each{ |member| member.update_index } 
    end

    def set_extent
      curation_concern.extent = curation_concern.members.size
    end

    def set_format
      unique_formats = Set.new
      curation_concern.members.each do |member|
        unique_formats.add(member.mime_type)
      end
      curation_concern.format = unique_formats.to_a
    end<commit_msg>Github #59: Minor Bug - Fix Format when Child Works exists<commit_after># Generated via
#  `rails generate hyrax:work Vdc::Resource`

module Hyrax
  class Vdc::ResourcesController < ApplicationController
    # Adds Hyrax behaviors to the controller.
    include Hyrax::WorksControllerBehavior
    include Hyrax::BreadcrumbsForWorks
    self.curation_concern_type = ::Vdc::Resource

    self.show_presenter = Hyrax::Vdc::ResourcePresenter

    def attributes_for_actor
      super.tap do |attributes|
        # TODO: Find out if there's a better way to get readme_file_ids_from_form,
        #       other than using a property from the resource model. Seems like there
        #       should be
        readme_file_ids_from_form = params.fetch(:readme_file_ids_from_form, nil)
        attributes[:readme_file_ids_from_form] = readme_file_ids_from_form
        attributes        
      end
    end

    def new
      # Set the default vdc creator to be the current user when creating a new resource
      curation_concern.vdc_creator << current_user.identifier_system
      super
    end

    def create
      super
      perform_cu_post_processing
    end

    #def edit
    #  super
    #end

    def update
      super
      perform_cu_post_processing
    end

    # Post-processing for Create and Update
    def perform_cu_post_processing
      # Reload to get all fields (including member extracted_text and mime_type) 
      # loaded properly
      curation_concern.reload 

      set_extent
      set_format
      set_doi

      curation_concern.save!
      
      # Reindex the members to get them into solr properly
      curation_concern.members.each{ |member| member.update_index } 
    end

    def set_extent
      curation_concern.extent = curation_concern.members.size
    end

    def set_format
      unique_formats = Set.new
      curation_concern.members.each do |member|
        unique_formats.add(member.mime_type) if member.respond_to? (:mime_type)
      end
      curation_concern.format = unique_formats.to_a
    end
{'fraction_non_alphanumeric': 0.04852426213106553, 'fraction_numerical': 0.0005002501250625312, 'mean_word_length': 2.723463687150838, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5388891', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1157, 'n_words': 317}