diff --git a/.gitignore b/.gitignore index 5e127519..82a5b926 100644 --- a/.gitignore +++ b/.gitignore @@ -69,4 +69,7 @@ public doc # Ignore test created to not get accidentally added to commit -project_create_8.txt \ No newline at end of file +project_create_8.txt + +# Ignore .yardoc +.yardoc/ \ No newline at end of file diff --git a/app/models/mediaflux/http/namespace_describe_request.rb b/app/models/mediaflux/http/namespace_describe_request.rb index acf0d6e1..0955c5de 100644 --- a/app/models/mediaflux/http/namespace_describe_request.rb +++ b/app/models/mediaflux/http/namespace_describe_request.rb @@ -1,22 +1,27 @@ # frozen_string_literal: true module Mediaflux module Http + # Describes a namespace + # @example + # namespace = Mediaflux::Http::NamespaceDescribeRequest.new(session_token: session_id).metadata + # => {:id=>"1", :path=>"/", :name=>"", :description=>"", :store=>"data"} + # @example + # namespace = Mediaflux::Http::NamespaceDescribeRequest.new(session_token: session_id, path: "/td-test-001/tigerdataNS").metadata + # => {:id=>"1182", :path=>"/td-test-001/tigerdataNS", :name=>"tigerdataNS", :description=>"TigerData client app root namespace", :store=>"db"} class NamespaceDescribeRequest < Request attr_reader :path, :id # Constructor # @param session_token [String] the API token for the authenticated session - # @param name [String] Name of the Asset - # @param collection [Boolean] create a collection asset if true - # @param namespace [String] Optional Parent namespace for the asset to be created in - # @param pid [Integer] Optional Parent id for the asset to be created in + # @param path [String] path of the asset to be described + # @param id [Integer] TODO: Define what this is and how to use it. def initialize(session_token:, path: nil, id: nil) super(session_token: session_token) @path = path @id = id end - # Specifies the Mediaflux service to use when creating assets + # Specifies the Mediaflux service to use # @return [String] def self.service "asset.namespace.describe" diff --git a/app/models/mediaflux/http/namespace_destroy_request.rb b/app/models/mediaflux/http/namespace_destroy_request.rb new file mode 100644 index 00000000..ecc7c2b8 --- /dev/null +++ b/app/models/mediaflux/http/namespace_destroy_request.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true +module Mediaflux + module Http + # Destroy a MediaFlux namespace and everything in it + # @example + # Mediaflux::Http::NamespaceDestroyRequest.new(session_token: session_id, namespace: "/td-test-001/tigerdataNS/Banana1NS").destroy + # => true + class NamespaceDestroyRequest < Request + attr_reader :description, :namespace, :store + + # Constructor + # @param session_token [String] the API token for the authenticated session + # @param namespace [String] name of namespace to be destroyed + def initialize(session_token:, namespace:) + super(session_token: session_token) + @namespace = namespace + end + + def destroy + resolve + if error? + response_error + end + end + + # Specifies the Mediaflux service to use when destroying namespaces + # @return [String] + def self.service + "asset.namespace.hard.destroy" + end + + private + + def build_http_request_body(name:) + super do |xml| + xml.args do + xml.namespace @namespace + xml.atomic true + end + end + end + end + end +end diff --git a/app/models/mediaflux/http/namespace_list_request.rb b/app/models/mediaflux/http/namespace_list_request.rb index 2ab1dcfd..ba04da48 100644 --- a/app/models/mediaflux/http/namespace_list_request.rb +++ b/app/models/mediaflux/http/namespace_list_request.rb @@ -1,15 +1,16 @@ # frozen_string_literal: true module Mediaflux module Http + # List all of the namespaces that are inside of a given namespace + # @example + # namespace_list = Mediaflux::Http::NamespaceListRequest.new(session_token: session_id, parent_namespace: "/td-test-001/tigerdataNS").namespaces + # => [{:id=>"1264", :name=>"Avocado1NS"}, {:id=>"1282", :name=>"Banana1NS"}] class NamespaceListRequest < Request attr_reader :parent_namespace # Constructor - # @param session_token [String] the API token for the authenticated session - # @param name [String] Name of the Asset - # @param collection [Boolean] create a collection asset if true - # @param namespace [String] Optional Parent namespace for the asset to be created in - # @param pid [Integer] Optional Parent id for the asset to be created in + # @param session_token [String] the API token for the authenticated session, same as session_id + # @param parent_namespace [String] Parent namespace for the query def initialize(session_token:, parent_namespace:) super(session_token: session_token) @parent_namespace = parent_namespace diff --git a/app/models/mediaflux/http/request.rb b/app/models/mediaflux/http/request.rb index 01fb86b4..cdf2412e 100644 --- a/app/models/mediaflux/http/request.rb +++ b/app/models/mediaflux/http/request.rb @@ -95,7 +95,6 @@ def resolved? # @return [Nokogiri::XML::Document] def response_xml resolve unless resolved? - Rails.logger.debug(response_body) @response_xml ||= Nokogiri::XML.parse(response_body) Rails.logger.debug(@response_xml) diff --git a/app/models/project_mediaflux.rb b/app/models/project_mediaflux.rb index c707b890..6cb310a3 100644 --- a/app/models/project_mediaflux.rb +++ b/app/models/project_mediaflux.rb @@ -1,5 +1,13 @@ # frozen_string_literal: true + +# Take an instance of Project and adds it to MediaFlux class ProjectMediaflux + # Create a project in MediaFlux + # + # @param project [Project] the project that needs to be added to MediaFlux + # @param session_id [] the session id for the user who is currently authenticated to MediaFlux + # @param xml_namespace [] + # @return [String] The id of the project that got created def self.create!(project:, session_id:, xml_namespace: nil) store_name = Store.default(session_id: session_id).name diff --git a/spec/models/mediaflux/http/namespace_destroy_request_spec.rb b/spec/models/mediaflux/http/namespace_destroy_request_spec.rb new file mode 100644 index 00000000..bdae0c4c --- /dev/null +++ b/spec/models/mediaflux/http/namespace_destroy_request_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true +require "rails_helper" + +RSpec.describe Mediaflux::Http::NamespaceDestroyRequest, type: :model, connect_to_mediaflux: true do + let(:valid_project) { FactoryBot.create(:project_with_dynamic_directory, project_id: "10.34770/tbd") } + let(:namespace) { "#{valid_project.directory}NS".strip.gsub(/[^A-Za-z\d]/, "-") } + let(:sponsor_user) { FactoryBot.create(:project_sponsor) } + let(:session_id) { sponsor_user.mediaflux_session } + it "deletes a namespace and everything inside of it" do + valid_project + mediaflux_id = ProjectMediaflux.create!(project: valid_project, session_id: session_id) + expect(mediaflux_id).not_to be_nil + namespace_list = Mediaflux::Http::NamespaceListRequest.new(session_token: session_id, parent_namespace: "/td-test-001/tigerdataNS").namespaces + namespace_names = namespace_list.map { |a| a[:name] } + expect(namespace_names).to include(namespace) + + # Destroy the namespace of the project and everything in it + described_class.new(session_token: session_id, namespace: "/td-test-001/tigerdataNS/#{namespace}").destroy + namespace_list = Mediaflux::Http::NamespaceListRequest.new(session_token: session_id, parent_namespace: "/td-test-001/tigerdataNS").namespaces + namespace_names = namespace_list.map { |a| a[:name] } + expect(namespace_names).not_to include(namespace) + response = described_class.new(session_token: session_id, namespace: "/td-test-001/tigerdataNS/#{namespace}").destroy + expect(response[:message]).to include("The namespace '/td-test-001/tigerdataNS/#{namespace}' does not exist or is not accessible") + end +end