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

pulibrary / tigerdata-app / a7a7c677-70ce-4fb7-93a9-85b7a17ef43a

10 Dec 2024 07:51PM UTC coverage: 83.95% (-0.3%) from 84.203%
a7a7c677-70ce-4fb7-93a9-85b7a17ef43a

Pull #1097

circleci

carolyncole
Adding a tble to display the contents of a project
Pull Request #1097: Adding a table to display the contents of a project

4 of 4 branches covered (100.0%)

2 of 9 new or added lines in 2 files covered. (22.22%)

12 existing lines in 4 files now uncovered.

2223 of 2648 relevant lines covered (83.95%)

332.31 hits per line

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

97.67
/app/models/mediaflux/asset_metadata_request.rb
1
# frozen_string_literal: true
2
module Mediaflux
1✔
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
1✔
8
    attr_reader :id
1✔
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:)
1✔
14
      super(session_token: session_token)
107✔
15
      @id = id
107✔
16
    end
17

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

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

30
      if metadata[:collection]
106✔
31
        metadata[:total_file_count] = asset.xpath("./collection/accumulator/value/non-collections").text
46✔
32
        metadata[:size] = asset.xpath("./collection/accumulator/value/total/@h").text
46✔
33
        metadata[:quota_allocation] = asset.xpath("./collection/quota/allocation/@h").text
46✔
34
        metadata[:accum_names] = asset.xpath("./collection/accumulator/@name")
46✔
35
        metadata[:quota_used] = asset.xpath("./collection/quota/used/@h").text
46✔
36
        metadata[:ctime] = asset.xpath("./ctime")
46✔
37

38
      end
39

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

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

44
      metadata
106✔
45
    end
46

47
    private
1✔
48

49
      def build_http_request_body(name:)
1✔
50
        super do |xml|
214✔
51
          xml.args do
214✔
52
            xml.id id
214✔
53
          end
54
        end
55
      end
56

57
      def parse_note(note, metadata)
1✔
58
        if note.count > 0
106✔
59
          metadata[:mf_note] = note.text
1✔
60
        end
61
      end
62

63
      def parse_image(image, metadata)
1✔
64
        if image.count > 0
106✔
UNCOV
65
          metadata[:image_size] = image.xpath("./width").text + " X " + image.xpath("./height").text
×
66
        end
67
      end
68

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

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

100
      def parse_project_dates(project)
1✔
101
        {
102
          created_by: project.xpath("./CreatedBy").text,
44✔
103
          created_on: project.xpath("./CreatedOn").text,
104
          updated_by: project.xpath("./UpdatedBy").text,
105
          updated_on: project.xpath("./UpdatedOn").text
106
        }
107
      end
108

109
      def parse_submission(project)
1✔
110
        submission = project.xpath("./Submission")
44✔
111
        {
112
          requested_by: submission.xpath("./RequestedBy").text,
44✔
113
          requested_on: submission.xpath("./RequestDateTime").text,
114
          approved_by: submission.xpath("./ApprovedBy").text,
115
          approved_on: submission.xpath("./ApprovalDateTime").text
116
        }
117
      end
118
  end
119
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