Skip to content

Commit

Permalink
rename asset_create_request for consistency in application (#660)
Browse files Browse the repository at this point in the history
Co-authored-by: Robert-Anthony Lee-Faison <leefaisonr@users.noreply.github.com>
  • Loading branch information
Seanwarren77 and leefaisonr authored Apr 25, 2024
1 parent e06f15d commit 180c95f
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Metrics/AbcSize:

Metrics/BlockLength:
Exclude:
- "app/models/mediaflux/http/create_asset_request.rb"
- "app/models/mediaflux/http/asset_create_request.rb"
- "config/environments/**/*"
- "lib/tasks/**/*"
- "spec/**/*"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module Mediaflux
module Http
class CreateAssetRequest < Request
class AssetCreateRequest < Request
attr_reader :namespace, :asset_name, :collection

# Constructor
Expand Down
6 changes: 3 additions & 3 deletions app/models/project_mediaflux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def self.create!(project:, session_id:, xml_namespace: nil)
tigerdata_values = project_values(project: project)
project_parent = Rails.configuration.mediaflux["api_root_collection"]
prepare_parent_collection(project_parent:, session_id:)
create_request = Mediaflux::Http::CreateAssetRequest.new(session_token: session_id, namespace: project_namespace, name: project_name, tigerdata_values: tigerdata_values,
create_request = Mediaflux::Http::AssetCreateRequest.new(session_token: session_id, namespace: project_namespace, name: project_name, tigerdata_values: tigerdata_values,
xml_namespace: xml_namespace, pid: project_parent)

#TODO: custom exception class raised for metadata issues. This would allow us to see them in Honeybadger and know how often they're happening.
Expand Down Expand Up @@ -97,7 +97,7 @@ def self.xml_payload(project:, xml_namespace: nil)
project_parent = Rails.configuration.mediaflux["api_root_collection"]

tigerdata_values = project_values(project: project)
create_request = Mediaflux::Http::CreateAssetRequest.new(session_token: nil, namespace: project_namespace, name: project_name, tigerdata_values: tigerdata_values,
create_request = Mediaflux::Http::AssetCreateRequest.new(session_token: nil, namespace: project_namespace, name: project_name, tigerdata_values: tigerdata_values,
xml_namespace: xml_namespace, pid: project_parent)
create_request.xml_payload
end
Expand Down Expand Up @@ -133,7 +133,7 @@ def prepare_parent_collection(project_parent:, session_id:)
get_parent = Mediaflux::Http::GetMetadataRequest.new(session_token: session_id, id: project_parent)
if get_parent.error?
if project_parent.include?("path=")
create_parent_request = Mediaflux::Http::CreateAssetRequest.new(session_token: session_id, namespace: Rails.configuration.mediaflux["api_root_collection_namespace"],
create_parent_request = Mediaflux::Http::AssetCreateRequest.new(session_token: session_id, namespace: Rails.configuration.mediaflux["api_root_collection_namespace"],
name: Rails.configuration.mediaflux["api_root_collection_name"])
raise "Can not create parent collection: #{create_parent_request.response_error}" if create_parent_request.error?
end
Expand Down
4 changes: 2 additions & 2 deletions app/services/test_asset_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def generate

def generate_level(parent_id, level)
return if level == 0
collection = Mediaflux::Http::CreateAssetRequest.new(session_token: mediaflux_session, name: "#{base_name}-#{level}", pid: parent_id)
collection = Mediaflux::Http::AssetCreateRequest.new(session_token: mediaflux_session, name: "#{base_name}-#{level}", pid: parent_id)
collection_id = collection.id # resolves the request and extracts the id
generate_directory(collection_id, directory_per_level)
generate_level(collection_id, level - 1)
Expand All @@ -28,7 +28,7 @@ def generate_level(parent_id, level)
def generate_directory(parent_id, directory_count)
return if directory_count == 0
name_extention = (0...10).map { ("a".."z").to_a[rand(26)] }.join
dir_collection = Mediaflux::Http::CreateAssetRequest.new(session_token: mediaflux_session, name: "#{base_name}-#{parent_id}-#{name_extention}", pid: parent_id)
dir_collection = Mediaflux::Http::AssetCreateRequest.new(session_token: mediaflux_session, name: "#{base_name}-#{parent_id}-#{name_extention}", pid: parent_id)
Mediaflux::Http::TestAssetCreateRequest.new(session_token: mediaflux_session, parent_id: dir_collection.id, count: file_count_per_directory).resolve
generate_directory(parent_id, directory_count - 1)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require "rails_helper"

RSpec.describe Mediaflux::Http::CreateAssetRequest, type: :model do
RSpec.describe Mediaflux::Http::AssetCreateRequest, type: :model do
let(:mediflux_url) { "http://mediaflux.example.com:8888/__mflux_svc__" }

let(:create_response) do
Expand Down
24 changes: 12 additions & 12 deletions spec/models/project_mediaflux_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

RSpec.describe ProjectMediaflux, type: :model, stub_mediaflux: true do
let(:namespace_request) { instance_double(Mediaflux::Http::NamespaceCreateRequest, resolve: true, "error?": false) }
let(:collection_request) { instance_double(Mediaflux::Http::CreateAssetRequest, id: 123) }
let(:collection_request) { instance_double(Mediaflux::Http::AssetCreateRequest, id: 123) }
let(:metadata_request) { instance_double(Mediaflux::Http::GetMetadataRequest, metadata: collection_metadata) }
let(:parent_metadata_request) { instance_double(Mediaflux::Http::GetMetadataRequest, "error?": false) }
let(:collection_metadata) { { id: "abc", name: "test", path: "td-demo-001/rc/test-ns/test", description: "description", namespace: "td-demo-001/rc/test-ns" } }
let(:project) { FactoryBot.build :project }
let(:current_user) { FactoryBot.create(:user, uid: "jh1234") }
let(:create_asset_request) { instance_double(Mediaflux::Http::GetMetadataRequest) }
let(:asset_create_request) { instance_double(Mediaflux::Http::GetMetadataRequest) }

describe "#create!" do
context "Using test data" do
Expand All @@ -18,13 +18,13 @@
namespace: "/td-test-001/tigerdataNS/big-dataNS",
description: "Namespace for project #{project.title}",
store: "db").and_return(namespace_request)
allow(Mediaflux::Http::CreateAssetRequest).to receive(:new).with(hash_including(session_token: "test-session-token", name: "big-data",
allow(Mediaflux::Http::AssetCreateRequest).to receive(:new).with(hash_including(session_token: "test-session-token", name: "big-data",
namespace: "/td-test-001/tigerdataNS/big-dataNS",
pid: "path=/td-test-001/tigerdata")).and_return(create_asset_request)
pid: "path=/td-test-001/tigerdata")).and_return(asset_create_request)
allow(Mediaflux::Http::GetMetadataRequest).to receive(:new).with(hash_including(session_token: "test-session-token",
id: "path=/td-test-001/tigerdata")).and_return(parent_metadata_request)
allow(create_asset_request).to receive(:resolve).and_return("<xml>...")
allow(create_asset_request).to receive(:id).and_return("123")
allow(asset_create_request).to receive(:resolve).and_return("<xml>...")
allow(asset_create_request).to receive(:id).and_return("123")
end

context "it formats dates correctly for MediaFlux" do
Expand All @@ -43,7 +43,7 @@
mediaflux_id = described_class.create!(project: project, session_id: "test-session-token")
expect(namespace_request).to have_received("error?")
expect(parent_metadata_request).to have_received("error?")
expect(create_asset_request).to have_received("id")
expect(asset_create_request).to have_received("id")
expect(mediaflux_id).to be "123"
end

Expand All @@ -52,8 +52,8 @@
let(:mediaflux_create_body) { Nokogiri::XML.parse(File.read(mediaflux_create_fixture_path)) }

before do
allow(create_asset_request).to receive(:id).and_return(nil)
allow(create_asset_request).to receive(:response_xml).and_return(mediaflux_create_body)
allow(asset_create_request).to receive(:id).and_return(nil)
allow(asset_create_request).to receive(:response_xml).and_return(mediaflux_create_body)
end

it "raises an error" do
Expand All @@ -65,18 +65,18 @@

context "when the parent colllection does not exist" do
let(:parent_metadata_request) { instance_double(Mediaflux::Http::GetMetadataRequest, metadata: {}, "error?": true) }
let(:parent_collection_request) { instance_double(Mediaflux::Http::CreateAssetRequest, id: 567, "error?": false) }
let(:parent_collection_request) { instance_double(Mediaflux::Http::AssetCreateRequest, id: 567, "error?": false) }

before do
allow(Mediaflux::Http::CreateAssetRequest).to receive(:new).with(hash_including(session_token: "test-session-token", name: "tigerdata",
allow(Mediaflux::Http::AssetCreateRequest).to receive(:new).with(hash_including(session_token: "test-session-token", name: "tigerdata",
namespace: "/td-test-001")).and_return(parent_collection_request)
end

it "creates a project namespace and collection and parent collection and returns the mediaflux id" do
mediaflux_id = described_class.create!(project: project, session_id: "test-session-token")
expect(namespace_request).to have_received("error?")
expect(parent_collection_request).to have_received("error?")
expect(create_asset_request).to have_received("id")
expect(asset_create_request).to have_received("id")
expect(mediaflux_id).to be "123"
end
end
Expand Down
28 changes: 14 additions & 14 deletions spec/services/test_asset_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
describe "#generate" do

let(:test_asset_create) { instance_double(Mediaflux::Http::TestAssetCreateRequest, resolve: true) }
let(:test_collection_create) { instance_double(Mediaflux::Http::CreateAssetRequest, id: "5678") }
let(:test_directory_create) { instance_double(Mediaflux::Http::CreateAssetRequest, id: "2222") }
let(:test_collection_create) { instance_double(Mediaflux::Http::AssetCreateRequest, id: "5678") }
let(:test_directory_create) { instance_double(Mediaflux::Http::AssetCreateRequest, id: "2222") }


before do
Expand All @@ -19,8 +19,8 @@

it "creates test data" do
allow(Mediaflux::Http::TestAssetCreateRequest).to receive(:new).with(session_token: "mediaflux_sessionid", parent_id: "2222", count: 1).and_return(test_asset_create)
allow(Mediaflux::Http::CreateAssetRequest).to receive(:new).with(session_token: "mediaflux_sessionid", pid: 1234, name: anything).and_return(test_collection_create)
allow(Mediaflux::Http::CreateAssetRequest).to receive(:new).with(session_token: "mediaflux_sessionid", pid: "5678", name: anything).and_return(test_directory_create)
allow(Mediaflux::Http::AssetCreateRequest).to receive(:new).with(session_token: "mediaflux_sessionid", pid: 1234, name: anything).and_return(test_collection_create)
allow(Mediaflux::Http::AssetCreateRequest).to receive(:new).with(session_token: "mediaflux_sessionid", pid: "5678", name: anything).and_return(test_directory_create)
subject.generate
expect(user).to have_received(:mediaflux_session)
expect(test_asset_create).to have_received(:resolve)
Expand All @@ -33,8 +33,8 @@

it "creates test data" do
allow(Mediaflux::Http::TestAssetCreateRequest).to receive(:new).with(session_token: "mediaflux_sessionid", parent_id: "2222", count: 3).and_return(test_asset_create)
allow(Mediaflux::Http::CreateAssetRequest).to receive(:new).with(session_token: "mediaflux_sessionid", pid: 1234, name: anything).and_return(test_collection_create)
allow(Mediaflux::Http::CreateAssetRequest).to receive(:new).with(session_token: "mediaflux_sessionid", pid: "5678", name: anything).and_return(test_directory_create)
allow(Mediaflux::Http::AssetCreateRequest).to receive(:new).with(session_token: "mediaflux_sessionid", pid: 1234, name: anything).and_return(test_collection_create)
allow(Mediaflux::Http::AssetCreateRequest).to receive(:new).with(session_token: "mediaflux_sessionid", pid: "5678", name: anything).and_return(test_directory_create)
subject.generate
expect(user).to have_received(:mediaflux_session)
expect(test_asset_create).to have_received(:resolve)
Expand All @@ -45,15 +45,15 @@

context "Multiple levels" do
let(:subject) { described_class.new(user:, project_id: project.id, levels: 2, directory_per_level: 1, file_count_per_directory: 1) }
let(:test_collection_create_level2) { instance_double(Mediaflux::Http::CreateAssetRequest, id: "91222") }
let(:test_collection_create_level2) { instance_double(Mediaflux::Http::AssetCreateRequest, id: "91222") }
let(:test_asset_create_level2) { instance_double(Mediaflux::Http::TestAssetCreateRequest, resolve: true) }
let(:test_directory_create_level2) { instance_double(Mediaflux::Http::CreateAssetRequest, id: "9222") }
let(:test_directory_create_level2) { instance_double(Mediaflux::Http::AssetCreateRequest, id: "9222") }

it "creates collections and files" do
allow(Mediaflux::Http::CreateAssetRequest).to receive(:new).with(session_token: "mediaflux_sessionid", pid: 1234, name: anything).and_return(test_collection_create)
allow(Mediaflux::Http::CreateAssetRequest).to receive(:new).with(session_token: "mediaflux_sessionid", pid: "5678", name: anything).and_return(test_directory_create, test_collection_create_level2)
allow(Mediaflux::Http::AssetCreateRequest).to receive(:new).with(session_token: "mediaflux_sessionid", pid: 1234, name: anything).and_return(test_collection_create)
allow(Mediaflux::Http::AssetCreateRequest).to receive(:new).with(session_token: "mediaflux_sessionid", pid: "5678", name: anything).and_return(test_directory_create, test_collection_create_level2)
allow(Mediaflux::Http::TestAssetCreateRequest).to receive(:new).with(session_token: "mediaflux_sessionid", parent_id: "2222", count: 1).and_return(test_asset_create)
allow(Mediaflux::Http::CreateAssetRequest).to receive(:new).with(session_token: "mediaflux_sessionid", pid: "91222", name: anything).and_return(test_directory_create_level2)
allow(Mediaflux::Http::AssetCreateRequest).to receive(:new).with(session_token: "mediaflux_sessionid", pid: "91222", name: anything).and_return(test_directory_create_level2)
allow(Mediaflux::Http::TestAssetCreateRequest).to receive(:new).with(session_token: "mediaflux_sessionid", parent_id: "9222", count: 1).and_return(test_asset_create_level2)
subject.generate
expect(test_asset_create).to have_received(:resolve)
Expand All @@ -66,12 +66,12 @@

context "Multiple directories" do
let(:subject) { described_class.new(user:, project_id: project.id, levels: 1, directory_per_level: 2, file_count_per_directory: 1) }
let(:test_directory_create_2) { instance_double(Mediaflux::Http::CreateAssetRequest, id: "9222") }
let(:test_directory_create_2) { instance_double(Mediaflux::Http::AssetCreateRequest, id: "9222") }
let(:test_asset_create_2) { instance_double(Mediaflux::Http::TestAssetCreateRequest, resolve: true) }

it "creates collections and files" do
allow(Mediaflux::Http::CreateAssetRequest).to receive(:new).with(session_token: "mediaflux_sessionid", pid: 1234, name: anything).and_return(test_collection_create)
allow(Mediaflux::Http::CreateAssetRequest).to receive(:new).with(session_token: "mediaflux_sessionid", pid: "5678", name: anything).and_return(test_directory_create, test_directory_create_2)
allow(Mediaflux::Http::AssetCreateRequest).to receive(:new).with(session_token: "mediaflux_sessionid", pid: 1234, name: anything).and_return(test_collection_create)
allow(Mediaflux::Http::AssetCreateRequest).to receive(:new).with(session_token: "mediaflux_sessionid", pid: "5678", name: anything).and_return(test_directory_create, test_directory_create_2)
allow(Mediaflux::Http::TestAssetCreateRequest).to receive(:new).with(session_token: "mediaflux_sessionid", parent_id: "2222", count: 1).and_return(test_asset_create)
allow(Mediaflux::Http::TestAssetCreateRequest).to receive(:new).with(session_token: "mediaflux_sessionid", parent_id: "9222", count: 1).and_return(test_asset_create_2)
subject.generate
Expand Down
4 changes: 2 additions & 2 deletions spec/services/test_project_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

describe "#generate" do

let(:test_collection_create) { instance_double(Mediaflux::Http::CreateAssetRequest, resolve: true, id: "5678") }
let(:test_collection_create) { instance_double(Mediaflux::Http::AssetCreateRequest, resolve: true, id: "5678") }
let(:test_namespace_describe) { instance_double(Mediaflux::Http::NamespaceDescribeRequest, "exists?": true)}
let(:test_store_list) { instance_double(Mediaflux::Http::StoreListRequest, stores: [{ id: "1", name: "db", tag: "", type: "database" }])}
let(:test_namespace_create) { instance_double(Mediaflux::Http::NamespaceCreateRequest, "error?": false) }
Expand All @@ -28,7 +28,7 @@
end

it "creates test data" do
allow(Mediaflux::Http::CreateAssetRequest).to receive(:new).with(session_token: "mediaflux_sessionid", name: "test-project-00001", namespace: "/td-test-001/tigerdataNS/test-project-00001NS",
allow(Mediaflux::Http::AssetCreateRequest).to receive(:new).with(session_token: "mediaflux_sessionid", name: "test-project-00001", namespace: "/td-test-001/tigerdataNS/test-project-00001NS",
tigerdata_values: {title: "Project 00001", updated_by: nil, updated_on: nil, code: "test-project-00001",
created_by: user.uid, created_on: anything, data_manager: user2.uid, data_sponsor: user2.uid, data_user_read_only: [], data_user_read_write: [],
departments: ["HPC"], description: "Description of project test-project 00001", project_id: "doi-not-generated", project_purpose: "Research", status: "pending", storage_capacity: "500 GB",
Expand Down

0 comments on commit 180c95f

Please sign in to comment.