app/controllers/granules_controller.rb
# This performs two actions.   First, it removes the specified granule using the "granule id" and then ingests a
# new random granule from CMR and associates it with the collection.
This performs two actions.   First, it removes the specified granule using the "granule id" and then ingests a
new random granule from CMR and associates it with the collection.
This performs two actions . First it removes the specified granule using the " granule id " and then ingests a new random granule from CMR and associates it with the collection .
def replace
    granule = Granule.find(params[:id])
    collection = granule.collection
    authorize! :replace_granule, granule
       flash[:notice] = "A new granule has been selected for this collection"
     else
       flash[:alert] = "This granule is in review, and can no longer be changed to a different granule"
     end
    begin
      granule.destroy
      collection.add_granule(current_user)
      flash[:notice] = "A new granule has been selected for this collection"
      redirect_to collection_path(id: 1, record_id: collection.records.first.id)
    rescue ActiveRecord::ActiveRecordError => e
      flash[:notice] = 'Sorry, Error occurred replacing the granule review.'
      Rails.logger.error("Sorry, Error occurred replacing the granule review.  error={e.message}")
      redirect_to collection_path(id: 1, record_id: collection.records.first.id)
    rescue Cmr::CmrError => e
      flash[:notice] = 'Sorry, Error occurred retrieving granule metadata from CMR.'
      Rails.logger.error("Sorry, Error occurred retrieving granule metadata from CMR.  error={e.message}")
      redirect_to collection_path(id: 1, record_id: collection.records.first.id)
    end
  end
def replace granule = Granule . find ( params [ :id ] ) collection = granule . collection authorize! :replace_granule , granule begin granule . destroy collection . add_granule ( current_user ) flash [ :notice ] = "A new granule has been selected for this collection" redirect_to collection_path ( id : 1 , record_id : collection . records . first . id ) rescue ActiveRecord :: ActiveRecordError => e flash [ :notice ] = 'Sorry, Error occurred replacing the granule review.' Rails . logger . error ( "Sorry, Error occurred replacing the granule review.  error=#{e.message}" ) redirect_to collection_path ( id : 1 , record_id : collection . records . first . id ) rescue Cmr :: CmrError => e flash [ :notice ] = 'Sorry, Error occurred retrieving granule metadata from CMR.' Rails . logger . error ( "Sorry, Error occurred retrieving granule metadata from CMR.  error=#{e.message}" ) redirect_to collection_path ( id : 1 , record_id : collection . records . first . id ) end end
This performs two actions.
This performs two actions .
# Removing temporarily until we come up with a process flow that allows them to reopen the record after it has # been closed.   A new ticket should be created allowing them to reopen a record. # if record.open? #   granule.destroy #   collection.add_granule(current_user) # #   flash[:notice] = "A new granule has been selected for this collection" # else #   flash[:alert] = "This granule is in review, and can no longer be changed to a different granule" # end #