Skip to content

Commit

Permalink
Add parsing of submission if present (#741)
Browse files Browse the repository at this point in the history
Co-authored-by: Jaymee Hyppolite <[email protected]>
  • Loading branch information
carolyncole and JaymeeH authored May 29, 2024
1 parent 192aa88 commit a3b5b9c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
27 changes: 24 additions & 3 deletions app/models/mediaflux/http/asset_metadata_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,30 @@ def parse(asset)
path: asset.xpath("./path").text,
type: asset.xpath("./type").text,
namespace: asset.xpath("./namespace").text,
accumulators: asset.xpath("./collection/accumulator/value"), # list of accumulator values in xml format. Can parse further through xpath
project_id: asset.xpath("//tigerdata:project/ProjectID", "tigerdata" => "tigerdata").text,
project_directory: asset.xpath("//tigerdata:project/ProjectDirectory", "tigerdata" => "tigerdata").text
accumulators: asset.xpath("./collection/accumulator/value") # list of accumulator values in xml format. Can parse further through xpath
}.merge(parse_project(asset))
end

def parse_project(asset)
project = asset.xpath("//tigerdata:project", "tigerdata" => "tigerdata").first
if project.present?
{
project_id: project.xpath("./ProjectID").text,
project_directory: project.xpath("./ProjectDirectory").text,
submission: parse_submission(project)
}
else
{}
end
end

def parse_submission(project)
submission = project.xpath("./Submission")
{
requested_by: submission.xpath("./RequestedBy").text,
requested_on: submission.xpath("./RequestDateTime").text,
approved_by: submission.xpath("./ApprovedBy").text,
approved_on: submission.xpath("./ApprovalDateTime").text
}
end
end
Expand Down
4 changes: 4 additions & 0 deletions spec/models/mediaflux/http/asset_metadata_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
expect(metadata[:quota_allocation]).to eq("300 GB")
expect(metadata[:project_directory]).to eq("accum-07576")
expect(metadata[:project_id]).to eq("doi-not-generated")
expect(metadata[:submission]).to eq({ approved_by: "",
approved_on: "",
requested_by: "cac9",
requested_on: "06-May-2024 14:04:49" })
expect(WebMock).to have_requested(:post, mediflux_url)
end
end
Expand Down

0 comments on commit a3b5b9c

Please sign in to comment.