diff --git a/.env.build b/.env.build index c923eaf4..dbba983b 100644 --- a/.env.build +++ b/.env.build @@ -19,7 +19,6 @@ DATACITE_USAGE_SOURCE_TOKEN= ZBMATH_RELATED_SOURCE_TOKEN= ZBMATH_AUTHOR_SOURCE_TOKEN= ZBMATH_IDENTIFIER_SOURCE_TOKEN= -EVENTDATA_TOKEN= STAFF_ADMIN_TOKEN= CROSSREF_SOURCE_ID= CROSSREF_SOURCE_TOKEN= \ No newline at end of file diff --git a/app/models/concerns/helpable.rb b/app/models/concerns/helpable.rb deleted file mode 100644 index a02b1d02..00000000 --- a/app/models/concerns/helpable.rb +++ /dev/null @@ -1,17 +0,0 @@ -module Helpable - extend ActiveSupport::Concern - - module ClassMethods - def set_event_for_bus(event) - event["source_id"] = "datacite" - event["subj"] = format_for_bus(event["subj"]) - event["obj"] = format_for_bus(event["obj"]) - event - end - - def format_for_bus(metadata) - { "pid" => metadata["@id"], - "work_type_id" => metadata["@type"] }.compact - end - end -end diff --git a/app/models/crossref_import.rb b/app/models/crossref_import.rb index be86456b..58077a9b 100644 --- a/app/models/crossref_import.rb +++ b/app/models/crossref_import.rb @@ -125,7 +125,6 @@ def self.push_item(item) Rails.logger.info push_items.inspect - # don't send to Event Data Bus Array.wrap(push_items).each do |iiitem| data = { "data" => { diff --git a/app/models/crossref_related.rb b/app/models/crossref_related.rb index bcba5f49..2b0c76ab 100644 --- a/app/models/crossref_related.rb +++ b/app/models/crossref_related.rb @@ -172,7 +172,6 @@ def self.push_item(item) # there can be one or more references per DOI # send to DataCite Event Data Query API - # don't send to Event Data Bus Array.wrap(push_items).each do |iiitem| data = { "data" => { diff --git a/app/models/related_identifier.rb b/app/models/related_identifier.rb index d00beaf3..2bb3237b 100644 --- a/app/models/related_identifier.rb +++ b/app/models/related_identifier.rb @@ -2,7 +2,6 @@ class RelatedIdentifier < Base LICENSE = "https://creativecommons.org/publicdomain/zero/1.0/".freeze DATACITE_CROSSREF = "datacite_crossref" - include Helpable include Cacheable include Queueable @@ -143,30 +142,6 @@ def self.push_item(item) Rails.logger.info "[Event Data] #{iiitem['subj_id']} #{iiitem['relation_type_id']} #{iiitem['obj_id']} sent to the events queue." - # send to Event Data Bus - # we only send datacite_crossref events to the bus - if ENV["EVENTDATA_TOKEN"].present? && iiitem["source_id"] == DATACITE_CROSSREF - iiitem = set_event_for_bus(iiitem) - - host = ENV["EVENTDATA_URL"] - push_url = "#{host}/events" - response = Maremma.post(push_url, data: iiitem.to_json, - bearer: ENV["EVENTDATA_TOKEN"], - content_type: "json", - host: host) - - # return 0 if successful, 1 if error - if response.status == 201 - Rails.logger.info "[Event Data Bus] #{iiitem['subj_id']} #{iiitem['relation_type_id']} #{iiitem['obj_id']} pushed to Event Data service." - elsif response.status == 409 - Rails.logger.info "[Event Data Bus] #{iiitem['subj_id']} #{iiitem['relation_type_id']} #{iiitem['obj_id']} already pushed to Event Data service." - elsif response.body["errors"].present? - Rails.logger.error "[Event Data Bus] #{iiitem['subj_id']} #{iiitem['relation_type_id']} #{iiitem['obj_id']} had an error:" - Rails.logger.error "[Event Data Bus] #{response.body['errors']}" - end - else - Rails.logger.info "[Event Data Bus] #{iiitem['subj_id']} #{iiitem['relation_type_id']} #{iiitem['obj_id']} was not sent to Event Data Bus." - end end push_items.length end diff --git a/config/application.rb b/config/application.rb index 1a3a531d..bf22e486 100644 --- a/config/application.rb +++ b/config/application.rb @@ -39,7 +39,6 @@ ENV["VOLPINO_URL"] ||= "https://api.stage.datacite.org" ENV["LAGOTTINO_URL"] ||= "https://api.stage.datacite.org" ENV["SASHIMI_QUERY_URL"] ||= "https://api.stage.datacite.org" -ENV["EVENTDATA_URL"] ||= "https://bus-staging.eventdata.crossref.org" ENV["CROSSREF_QUERY_URL"] ||= "https://api.crossref.org" ENV["TRUSTED_IP"] ||= "10.0.40.1" ENV["SLACK_WEBHOOK_URL"] ||= "" diff --git a/spec/concerns/helpable_spec.rb b/spec/concerns/helpable_spec.rb deleted file mode 100644 index 00e0d389..00000000 --- a/spec/concerns/helpable_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require "rails_helper" - -describe RelatedIdentifier, type: :model do - it "format event for eventdata bus" do - event = File.read("#{fixture_path}datacite_event.json") - response = RelatedIdentifier.set_event_for_bus(JSON.parse(event)) - expect(response["id"]).to eq("c8bcd46c-3433-47ac-b8db-d039ce346d65") - expect(response["source_id"]).to eq("datacite") - expect(response["subj_id"]).to eq("https://doi.org/10.15468/dl.hy9tqg") - expect(response["relation_type_id"]).to eq("references") - expect(response["source_token"]).to eq("29a9a478-518f-4cbd-a133-a0dcef63d547") - expect(response["obj"]).to eq({ "pid" => "https://doi.org/10.15468/xgoxap", - "work_type_id" => "Dataset" }) - expect(response["subj"]).to eq({ - "pid" => "https://doi.org/10.15468/dl.hy9tqg", "work_type_id" => "Dataset" - }) - end -end diff --git a/spec/models/related_identifier_spec.rb b/spec/models/related_identifier_spec.rb index dd4e978f..21baa8d6 100644 --- a/spec/models/related_identifier_spec.rb +++ b/spec/models/related_identifier_spec.rb @@ -85,8 +85,6 @@ allow(ENV).to receive(:[]).with("LAGOTTINO_URL").and_return("https://fake.lagattino.com") allow(ENV).to receive(:[]).with("DATACITE_RELATED_SOURCE_TOKEN").and_return("DATACITE_RELATED_SOURCE_TOKEN") allow(ENV).to receive(:[]).with("USER_AGENT").and_return("default_user_agent") - allow(ENV).to receive(:[]).with("EVENTDATA_TOKEN").and_return("EVENTDATA_TOKEN") - allow(ENV).to receive(:[]).with("EVENTDATA_URL").and_return("https://fake.eventdataurl.com") allow(Base).to receive(:cached_datacite_response).and_return({ "foo" => "bar" }) allow(Maremma).to receive(:post).and_return(OpenStruct.new(status: 201)) allow(RelatedIdentifier).to receive(:send_event_import_message).and_return(nil) @@ -108,26 +106,6 @@ expect(Rails.logger).to have_received(:info).with("[Event Data] https://doi.org/10.1234/example example_type https://doi.org/10.5678/related sent to the events queue.") end - - it "does push the event to the event data bus when source_id is datacite_crossref" do - related_identifier = RelatedIdentifier.new - allow(ENV).to receive(:[]).with("DATACITE_CROSSREF_SOURCE_TOKEN").and_return("fake-token") - allow(related_identifier).to receive(:normalize_doi).with(valid_doi).and_return("normalized_doi") - allow(related_identifier).to receive(:normalize_doi).with(valid_related_identifier).and_return("normalized_related_identifier") - allow(related_identifier).to receive(:validate_prefix).with(valid_related_identifier).and_return("datacite") - allow(RelatedIdentifier).to receive(:cached_doi_ra).with("https://doi.org/10.5678/related").and_return("Crossref") - allow(RelatedIdentifier).to receive(:cached_doi_ra).with("https://doi.org/10.1234/example").and_return("DataCite") - allow(RelatedIdentifier).to receive(:cached_crossref_response).and_return({}) - allow(RelatedIdentifier).to receive(:cached_datacite_response).and_return({}) - allow(related_identifier).to receive(:set_event_for_bus).and_return({}) - allow(Rails.logger).to receive(:info) - - expect(RelatedIdentifier.push_item(item)).to eq(1) - expect(RelatedIdentifier).to have_received(:send_event_import_message).once - expect(Maremma).to have_received(:post).with("https://fake.eventdataurl.com/events", anything).once - expect(Rails.logger).to have_received(:info).with("[Event Data] https://doi.org/10.1234/example example_type https://doi.org/10.5678/related sent to the events queue.") - expect(Rails.logger).to have_received(:info).with("[Event Data Bus] https://doi.org/10.1234/example example_type https://doi.org/10.5678/related pushed to Event Data service.") - end end context "when the DOI is blank" do