From 06927d5b4629c37f544be13a55045d475d82b00d Mon Sep 17 00:00:00 2001
From: carolyncole <1599081+carolyncole@users.noreply.github.com>
Date: Wed, 1 May 2024 15:05:57 -0400
Subject: [PATCH] Adding xtoshell_xml to Request to make utilizing the tool
easier (#674)
---
app/models/mediaflux/http/request.rb | 10 ++++++++++
docs/aterm_101.md | 4 ++--
.../http/asset_create_request_spec.rb | 18 ++++++++++++++++++
3 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/app/models/mediaflux/http/request.rb b/app/models/mediaflux/http/request.rb
index 412bf77d..9aece971 100644
--- a/app/models/mediaflux/http/request.rb
+++ b/app/models/mediaflux/http/request.rb
@@ -132,6 +132,16 @@ def xml_payload( name: self.class.service)
xml_payload = body.to_xml
end
+ # The output of this routine can be passed to xtoshell in aterm. The output of which can be sent to service.execute
+ # @param [String] name name of the service this request will send
+ # @return [String] xml that can be passed to xtoshell without manipulation
+ def xtoshell_xml( name: self.class.service)
+ xml_builder = build_http_request_body(name: )
+ xml_builder.doc.xpath("//request/service/@session").remove
+ xml = xml_builder.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XML | Nokogiri::XML::Node::SaveOptions::NO_DECLARATION)
+ xml.strip.gsub("\"","'").gsub("","").gsub("","")
+ end
+
private
def http_request
diff --git a/docs/aterm_101.md b/docs/aterm_101.md
index 3b05c5ee..1e100464 100644
--- a/docs/aterm_101.md
+++ b/docs/aterm_101.md
@@ -411,11 +411,11 @@ For example:
**Note 2** Our version of mediaflux in docker does not have this command. The xtoshell command does exist on td-meta1
```
session_id = User.first.mediaflux_session
- project = project.first
+ project = Project.first
project_name = ProjectMediaflux.safe_name(project.directory)
project_namespace = "#{Rails.configuration.mediaflux['api_root_ns']}/#{project_name}NS"
store_name = Store.default(session_id: session_id).name
namespace = Mediaflux::Http::NamespaceCreateRequest.new(namespace: project_namespace, description: "Namespace for project #{project.title}", store: store_name, session_token: session_id)
- puts namespace.xml_payload.gsub("\n","").gsub(" "," ").gsub(" "," ").gsub(" "," ").gsub("\"","'").gsub("> <","><").gsub("","").gsub("","").gsub(/session='.*'/,"")
+ puts "\n\n #{namespace.xtoshell_xml}\n\n"
```
Copy the output and in aterm run `service.execute` and paste the output
diff --git a/spec/models/mediaflux/http/asset_create_request_spec.rb b/spec/models/mediaflux/http/asset_create_request_spec.rb
index 834cb5e9..c070a1e2 100644
--- a/spec/models/mediaflux/http/asset_create_request_spec.rb
+++ b/spec/models/mediaflux/http/asset_create_request_spec.rb
@@ -138,4 +138,22 @@
expect(create_request.xml_payload).to eq(expected_xml)
end
end
+
+ describe "#xtoshell_xml" do
+ it "creates the asset create xml in a format that can be passed to xtoshell in aterm" do
+ project = FactoryBot.create :project, project_id: "abc-123"
+ tigerdata_values = ProjectMediaflux.project_values(project:)
+ create_request = described_class.new(session_token: nil, name: "testasset", collection: false, tigerdata_values: tigerdata_values)
+ expected_xml = "testasset" \
+ "#{project.directory}#{project.metadata[:title]}" \
+ "#{project.metadata[:description]}#{project.metadata[:status]}" \
+ "#{project.metadata[:data_sponsor]}#{project.metadata[:data_manager]}" \
+ "RDSSPRDS#{ProjectMediaflux.format_date_for_mediaflux(project.metadata[:created_on])}" \
+ "#{project.metadata[:created_by]}abc-123500GB" \
+ "standard#{project.metadata[:created_by]}" \
+ "#{ProjectMediaflux.format_date_for_mediaflux(project.metadata[:created_on])}" \
+ "research0.6.1"
+ expect(create_request.xtoshell_xml).to eq(expected_xml)
+ end
+ end
end