• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / tigerdata-app / 8d70f2ab-acc5-4aab-b64b-743d66ddd2eb

29 Aug 2025 06:22PM UTC coverage: 87.983% (-0.1%) from 88.118%
8d70f2ab-acc5-4aab-b64b-743d66ddd2eb

Pull #1801

circleci

JaymeeH
Merge branch '1586-request-mailer' of https://github.com/pulibrary/tiger-data-app into 1586-request-mailer
Pull Request #1801: 1586 request mailer

10 of 10 new or added lines in 2 files covered. (100.0%)

1173 existing lines in 56 files now uncovered.

2482 of 2821 relevant lines covered (87.98%)

317.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.87
/app/models/mediaflux/asset_metadata_request.rb
1
# frozen_string_literal: true
2
module Mediaflux
2✔
3
  # Get metadata about an asset in mediaflux
4
  # @example
5
  #   metadata_request = Mediaflux::AssetMetadataRequest.new(
6
  #   session_token: current_user.mediaflux_session, id: mediaflux_id).metadata
7
  class AssetMetadataRequest < Request
2✔
8
    attr_reader :id
2✔
9

10
    # Constructor
11
    # @param session_token [String] the API token for the authenticated session
12
    # @param id [Integer] Id of the Asset to return the metadata for
13
    def initialize(session_token:, id:)
2✔
14
      super(session_token: session_token)
185✔
15
      @id = id
185✔
16
    end
17

18
    # Specifies the Mediaflux service to use when getting asset metadata
19
    # @return [String]
20
    def self.service
2✔
21
      "asset.get"
370✔
22
    end
23

24
    # parse the returned XML into a hash about the asset that can be utilized
25
    def metadata
2✔
26
      xml = response_xml
182✔
27
      asset = xml.xpath("/response/reply/result/asset")
178✔
28
      metadata = parse(asset)
178✔
29

30
      if metadata[:collection]
178✔
31
        metadata[:total_file_count] = asset.xpath("./collection/accumulator/value/non-collections").text
105✔
32
        metadata[:size] = asset.xpath("./collection/accumulator/value/total/@h").text
105✔
33
        metadata[:accum_names] = asset.xpath("./collection/accumulator/@name")
105✔
34
        metadata[:ctime] = asset.xpath("./ctime")
105✔
35
      end
36

37
      parse_image(asset.xpath("./meta/mf-image"), metadata) # this does not do anything because mf-image is not a part of the meta xpath
178✔
38

39
      parse_note(asset.xpath("./meta/mf-note"), metadata) # this does not do anything because mf-note is not a part of the meta xpath
178✔
40

41
      parse_quota(asset.xpath("./collection/quota"), metadata)
178✔
42
      metadata
178✔
43
    end
44

45
    private
2✔
46

47
      def build_http_request_body(name:)
2✔
48
        super do |xml|
370✔
49
          xml.args do
370✔
50
            xml.id id
370✔
51
          end
52
        end
53
      end
54

55
      def parse_note(note, metadata)
2✔
56
        if note.count > 0
178✔
UNCOV
57
          metadata[:mf_note] = note.text
1✔
58
        end
59
      end
60

61
      def parse_image(image, metadata)
2✔
62
        if image.count > 0
178✔
63
          metadata[:image_size] = image.xpath("./width").text + " X " + image.xpath("./height").text
×
64
        end
65
      end
66

67
      def parse_quota(quota, metadata)
2✔
68
        metadata[:quota_allocation] = quota.xpath("./allocation/@h").text
178✔
69
        metadata[:quota_allocation_raw] = quota.xpath("./allocation").text.to_i
178✔
70
        metadata[:quota_used] = quota.xpath("./used/@h").text
178✔
71
        metadata[:quota_used_raw] = quota.xpath("./used").text.to_i
178✔
72
      end
73

74
      # Update this to match full 0.6.1 schema
75
      def parse(asset)
2✔
76
        {
77
          id: asset.xpath("./@id").text,
178✔
78
          name: asset.xpath("./name").text,
79
          creator: asset.xpath("./creator/user").text,
80
          description: asset.xpath("./description").text,
81
          collection: asset.xpath("./@collection")&.text == "true",
82
          path: asset.xpath("./path").text,
83
          type: asset.xpath("./type").text,
84
          namespace: asset.xpath("./namespace").text,
85
          accumulators: asset.xpath("./collection/accumulator/value") # list of accumulator values in xml format. Can parse further through xpath
86
        }.merge(parse_project(asset.xpath("//tigerdata:project", "tigerdata" => "tigerdata").first))
87
      end
88

89
      def parse_project(project)
2✔
90
        return {} if project.blank?
178✔
91
        {
92
          description: project.xpath("./Description").text,
104✔
93
          data_sponsor: project.xpath("./DataSponsor").text,
94
          data_manager: project.xpath("./DataManager").text,
95
          departments: project.xpath("./Department").children.map(&:text),
96
          project_directory: project.xpath("./ProjectDirectory").text,
97
          project_id: project.xpath("./ProjectID").text,
98
          ro_users: project.xpath("./DataUser[@ReadOnly]").map(&:text),
99
          rw_users: project.xpath("./DataUser[not(@ReadOnly)]").map(&:text),
100
          submission: parse_submission(project),
101
          title: project.xpath("./Title").text
102
        }.merge(parse_project_dates(project))
103
      end
104

105
      def parse_project_dates(project)
2✔
106
        {
107
          created_by: project.xpath("./CreatedBy").text,
104✔
108
          created_on: project.xpath("./CreatedOn").text,
109
          updated_by: project.xpath("./UpdatedBy").text,
110
          updated_on: project.xpath("./UpdatedOn").text
111
        }
112
      end
113

114
      def parse_submission(project)
2✔
115
        submission = project.xpath("./Submission")
104✔
116
        {
117
          requested_by: submission.xpath("./RequestedBy").text,
104✔
118
          requested_on: submission.xpath("./RequestDateTime").text,
119
          approved_by: submission.xpath("./ApprovedBy").text,
120
          approved_on: submission.xpath("./ApprovalDateTime").text
121
        }
122
      end
123
  end
124
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc