Skip to content

Commit

Permalink
update the eradicator to support the eradication of not archived subm…
Browse files Browse the repository at this point in the history
…issions if wanted
  • Loading branch information
syphax-bouazzouni committed Jan 24, 2022
1 parent 179de6f commit 62d174f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
16 changes: 13 additions & 3 deletions bin/ncbo_ontology_submissions_eradicate
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ def eradicate(ontology_acronym, submissions , logger)
logger.info "Start removing submission #{submission.submissionId.to_s}"
NcboCron::Models::OntologySubmissionEradicator.new.eradicate ontology_acronym, submission
logger.info"Submission #{submission.submissionId.to_s} deleted successfully"
rescue NcboCron::Models::OntologySubmissionEradicator::RemoveNotArchivedSubmissionException
logger.info "Submission #{submission.submissionId.to_s} is not archived"
ask? logger, 'Do you want to force remove ? (Y/n)'
NcboCron::Models::OntologySubmissionEradicator.new.eradicate ontology_acronym, submission, true
logger.info"Submission #{submission.submissionId.to_s} deleted successfully"
rescue NcboCron::Models::OntologySubmissionEradicator::RemoveSubmissionFileException => e
logger.error "RemoveSubmissionFileException in submission #{submission.submissionId.to_s} : #{e.message}"
rescue NcboCron::Models::OntologySubmissionEradicator::RemoveSubmissionDataException => e
Expand All @@ -77,6 +82,12 @@ def eradicate(ontology_acronym, submissions , logger)
end
end

def ask?(logger, prompt)
logger.info prompt
choice = gets.chomp.downcase
exit(1) if choice.eql? 'n'
end

begin
logger = Logger.new($stderr)

Expand All @@ -89,9 +100,8 @@ begin

logger.info "You are attempting to remove the following submissions of #{ontology_acronym} : #{submissions_to_delete.map{ |s| s.submissionId }.join(', ')}"
logger.info 'They will be deleted from the triple store and local files'
logger.info 'Do you confirm ? (Y/n)'
choice = gets.chomp.downcase
exit(1) if choice.eql? 'n'
ask? logger, 'Do you confirm ? (Y/n)'

eradicate ontology_acronym , submissions_to_delete, logger
exit(0)
end
11 changes: 7 additions & 4 deletions lib/ncbo_cron/ontology_submission_eradicator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ class RemoveSubmissionFileException < StandardError
class RemoveSubmissionDataException < StandardError
end

class RemoveNotArchivedSubmissionException < StandardError
end

def initialize()
end

def eradicate(ontology_acronym, submission)
def eradicate(ontology_acronym, submission , force=false)
submission.bring(:submissionStatus) if submission.bring(:submissionStatus)
if submission.archived?
if submission.archived? || force
delete_submission_files ontology_acronym, submission
delete_submission_data submission
else
raise RemoveSubmissionDataException, "Submission #{submission.submissionId} is not an archived submission"
else submission.ready?
raise RemoveNotArchivedSubmissionException, "Submission #{submission.submissionId} is not an archived submission"
end

end
Expand Down

0 comments on commit 62d174f

Please sign in to comment.