lib/catissue/database.rb
def strip_collectible_event_parameters(obj, template)
      if obj.collected? then
        return if CaTissue::SpecimenCollectionGroup === obj
        if obj.identifier then
          if obj.changed?(:collection_status) then
            fseps = fetch_association(obj, :specimen_event_parameters)
            obj.collectible_event_parameters.each do |cep|
              fcep = fseps.detect { |fsep| cep.class === fsep }
              cep.merge(fcep) if fcep
            end
            template.collectible_event_parameters.each do |cep|
              fcep = fseps.detect { |fsep| cep.class === fsep }
              cep.merge(fcep) if fcep
            end
          end
          return
        end
      end
      ceps = template.specimen_event_parameters.select { |ep| CollectibleEventParameters === ep }
      unless ceps.empty? then
        ceps.each { |cep| template.specimen_event_parameters.delete(cep) }
        logger.debug { "Worked around caTissue bug by stripping the following collectible event parameters from the #{template} template: #{ceps.pp_s}." }
      end
      if CaTissue::Specimen === template then
        obj.children.each do |spc|
          tmpl = spc.match_in(template.children)
          ceps.concat(strip_collectible_event_parameters(spc, tmpl)) if tmpl
        end
      end
      ceps
    end
def strip_collectible_event_parameters(obj, template)
      if obj.collected? then
        return if CaTissue::SpecimenCollectionGroup === obj
        if obj.identifier then
          if obj.changed?(:collection_status) then
            fseps = fetch_association(obj, :specimen_event_parameters)
            obj.collectible_event_parameters.each do |cep|
              fcep = fseps.detect { |fsep| cep.class === fsep }
              cep.merge(fcep) if fcep
            end
            template.collectible_event_parameters.each do |cep|
              fcep = fseps.detect { |fsep| cep.class === fsep }
              cep.merge(fcep) if fcep
            end
          end
          return
        end
      end
      ceps = template.specimen_event_parameters.select { |ep| CollectibleEventParameters === ep }
      unless ceps.empty? then
        ceps.each { |cep| template.specimen_event_parameters.delete(cep) }
        logger.debug { "Worked around caTissue bug by stripping the following collectible event parameters from the #{template} template: #{ceps.pp_s}." }
      end
      if CaTissue::Specimen === template then
        obj.children.each do |spc|
          tmpl = spc.match_in(template.children)
          ceps.concat(strip_collectible_event_parameters(spc, tmpl)) if tmpl
        end
      end
      ceps
    end
Removes the unsaved {CollectibleEventParameters} from the given template to work around the
 caTissue bug described in {#save_with_template}.

 The CollectibleEventParameters are required if and only if one of the following is true:
 * the operation is a SCG save and the collected status is not pending
 * the operation is an update to a previously collected Specimen
 In all other cases, the CollectibleEventParameters are removed.

 This method is applied recursively to Specimen children.

 @param [Collectible] the Specimen or SCG template
 @return [<CollectibleEventParameters>] the removed event parameters