Skip to content

Commit

Permalink
Adding xtoshell_xml to Request to make utilizing the tool easier (#674)
Browse files Browse the repository at this point in the history
  • Loading branch information
carolyncole authored May 1, 2024
1 parent 1699caf commit 06927d5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
10 changes: 10 additions & 0 deletions app/models/mediaflux/http/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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("<args>","").gsub("</args>","")
end

private

def http_request
Expand Down
4 changes: 2 additions & 2 deletions docs/aterm_101.md
Original file line number Diff line number Diff line change
Expand Up @@ -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("<args>","").gsub("</args>","").gsub(/session='.*'/,"")
puts "\n\n #{namespace.xtoshell_xml}\n\n"
```
Copy the output and in aterm run `service.execute` and paste the output
18 changes: 18 additions & 0 deletions spec/models/mediaflux/http/asset_create_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<request xmlns:tigerdata='http://tigerdata.princeton.edu'><service name='asset.create'><name>testasset</name>" \
"<meta><tigerdata:project><ProjectDirectory>#{project.directory}</ProjectDirectory><Title>#{project.metadata[:title]}</Title>" \
"<Description>#{project.metadata[:description]}</Description><Status>#{project.metadata[:status]}</Status>" \
"<DataSponsor>#{project.metadata[:data_sponsor]}</DataSponsor><DataManager>#{project.metadata[:data_manager]}</DataManager>" \
"<Department>RDSS</Department><Department>PRDS</Department><CreatedOn>#{ProjectMediaflux.format_date_for_mediaflux(project.metadata[:created_on])}</CreatedOn>" \
"<CreatedBy>#{project.metadata[:created_by]}</CreatedBy><ProjectID>abc-123</ProjectID><StorageCapacity><Size>500</Size><Unit>GB</Unit></StorageCapacity>" \
"<Performance Requested='standard'>standard</Performance><Submission><RequestedBy>#{project.metadata[:created_by]}</RequestedBy>" \
"<RequestDateTime>#{ProjectMediaflux.format_date_for_mediaflux(project.metadata[:created_on])}</RequestDateTime></Submission>" \
"<ProjectPurpose>research</ProjectPurpose><SchemaVersion>0.6.1</SchemaVersion></tigerdata:project></meta></service></request>"
expect(create_request.xtoshell_xml).to eq(expected_xml)
end
end
end

0 comments on commit 06927d5

Please sign in to comment.