<commit_before>require 'jinx/helpers/inflector'
require 'jinx/migration/migratable'
require 'galena/seed'

module CaTissue
  # Augment the classes below with sufficient content to pass the create mandatory attribute validation.
  # This simulates an existing administrative object for testing purposes.
  #
  # This file is not placed in the specs support directory, since it is dynamically loaded as a shim.
  shims CollectionProtocol, CollectionProtocolEvent, Site, StorageContainer, User

  class CollectionProtocol
    # Augments +Jinx::Migratable.migrate+ for the Galena example by adding the following defaults:
    # * the CP principal_investigator defaults to the {Galena::Seed#protocol} PI
    # * if the sites is empty, then the {Galena::Seed#tissue_bank} is added
    #   to the CP sites
    #
    # @param (see Jinx::Migratable#migrate)
    def migrate(row, migrated)
      super
      self.title ||= migration_default_title(migrated)
      self.principal_investigator ||= Galena.administrative_objects.protocol.principal_investigator
      sites << Galena.administrative_objects.tissue_bank if sites.empty?
      coordinators << Galena.administrative_objects.tissue_bank.coordinator if coordinators.empty?
    end
    
    private
    
    # @param (see #migrate)
    # @return [String, nil] the short title of the {Galena::Seed} protocol which
    #   matches this protocol's event, or nil if no match 
    def migration_default_title(migrated)
      cpe = migrated.detect { |obj| CaTissue::CollectionProtocolEvent === obj } || return
      pcl = Galena.administrative_objects.protocols.detect { |p| p.events.first.label == cpe.label } || return
      pcl.title
    end
  end
  
  class CollectionProtocolEvent
    # Augments +Jinx::Migratable.migrate+ for the example by adding the following defaults:
    # * create a {CaTissue::TissueSpecimenRequirement}
    # * copy the event point from {Galena::Seed}
    #
    # @param (see Jinx::Migratable#migrate)
    def migrate(row, migrated)
      super
      match = Galena.administrative_objects.protocols.detect_value do |pcl|
        cpe = pcl.events.first
        cpe if cpe.label == label
      end
      if match then
        self.event_point ||= match.event_point
        rqmt = match.requirements.first
        CaTissue::TissueSpecimenRequirement.new(:collection_event => self, :specimen_type => rqmt.specimen_type)
      else
        CaTissue::TissueSpecimenRequirement.new(:collection_event => self)
      end
    end
  end

  class Site
    # Augments +Jinx::Migratable.migrate+ for the example by merging the content of the
    # {Galena::Seed} site which matches on this Site's name, if any.
    #
    # @param (see Jinx::Migratable#migrate)
    def migrate(row, migrated)
      super
      # Match the site by name. Account for uniquification by a partial match, e.g.
      # 'Galena_Hospital_41893443' matches the site named 'Galena Hospital'.
      tmpl = TEMPLATES.detect { |site| name[site.name.gsub('_', ' ')] }
      # merge the default mandatory attribute values
      if tmpl then merge(tmpl, mandatory_attributes) end
    end
    
    private
    
    TEMPLATES = [Galena.administrative_objects.hospital, Galena.administrative_objects.tissue_bank]
  end

  class StorageContainer
    # Augments +Jinx::Migratable.migrate+ for the example by setting the
    # the container site and type to the {Galena::Seed}
    # box site and type, resp.
    #
    # @param (see Jinx::Migratable#migrate)
    def migrate(row, migrated)
      super
      self.site ||= Galena.administrative_objects.tissue_bank
      self.storage_type ||= Galena.administrative_objects.box_type
    end
  end
  
  class SpecimenEventParameters
    # Fills in the event parameters user details.
    #<commit_msg>There is only a single seed CP.<commit_after>require 'jinx/helpers/inflector'
require 'jinx/migration/migratable'
require 'galena/seed'

module CaTissue
  # Augment the classes below with sufficient content to pass the create mandatory attribute validation.
  # This simulates an existing administrative object for testing purposes.
  #
  # This file is not placed in the specs support directory, since it is dynamically loaded as a shim.
  shims CollectionProtocol, CollectionProtocolEvent, Site, StorageContainer, User

  class CollectionProtocol
    # Augments +Jinx::Migratable.migrate+ for the Galena example by adding the following defaults:
    # * the CP principal_investigator defaults to the {Galena::Seed#protocol} PI
    # * if the sites is empty, then the {Galena::Seed#tissue_bank} is added
    #   to the CP sites
    #
    # @param (see Jinx::Migratable#migrate)
    def migrate(row, migrated)
      super
      self.title ||= Galena.administrative_objects.protocol.title
      self.principal_investigator ||= Galena.administrative_objects.protocol.principal_investigator
      sites << Galena.administrative_objects.tissue_bank if sites.empty?
      coordinators << Galena.administrative_objects.tissue_bank.coordinator if coordinators.empty?
    end
  end
  
  class CollectionProtocolEvent
    # Augments +Jinx::Migratable.migrate+ for the example by adding the following defaults:
    # * create a {CaTissue::TissueSpecimenRequirement}
    # * copy the event point from {Galena::Seed}
    #
    # @param (see Jinx::Migratable#migrate)
    def migrate(row, migrated)
      super
      cpe = Galena.administrative_objects.protocol.events.first
      self.event_point ||= cpe.event_point
      rqmt = cpe.requirements.first
      CaTissue::TissueSpecimenRequirement.new(:collection_event => self, :specimen_type => rqmt.specimen_type)
    end
  end

  class Site
    # Augments +Jinx::Migratable.migrate+ for the example by merging the content of the
    # {Galena::Seed} site which matches on this Site's name, if any.
    #
    # @param (see Jinx::Migratable#migrate)
    def migrate(row, migrated)
      super
      # Match the site by name. Account for uniquification by a partial match, e.g.
      # 'Galena_Hospital_41893443' matches the site named 'Galena Hospital'.
      tmpl = TEMPLATES.detect { |site| name[site.name.gsub('_', ' ')] }
      # merge the default mandatory attribute values
      if tmpl then merge(tmpl, mandatory_attributes) end
    end
    
    private
    
    TEMPLATES ||= [Galena.administrative_objects.hospital, Galena.administrative_objects.tissue_bank]
  end

  class StorageContainer
    # Augments +Jinx::Migratable.migrate+ for the example by setting the
    # the container site and type to the {Galena::Seed}
    # box site and type, resp.
    #
    # @param (see Jinx::Migratable#migrate)
    def migrate(row, migrated)
      super
      self.site ||= Galena.administrative_objects.tissue_bank
      self.storage_type ||= Galena.administrative_objects.box_type
    end
  end
  
  class SpecimenEventParameters
    # Fills in the event parameters user details.
    #
{'fraction_non_alphanumeric': 0.08162672476397967, 'fraction_numerical': 0.0023238925199709514, 'mean_word_length': 3.500653594771242, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 8, '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': '3281420', 'n_tokens_mistral': 2098, 'n_tokens_neox': 2062, 'n_words': 598}