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

pulibrary / tigerdata-app / 634ff48b-928d-4ff0-a430-c65bc451782e

28 Jul 2025 05:59PM UTC coverage: 64.563% (+0.1%) from 64.418%
634ff48b-928d-4ff0-a430-c65bc451782e

Pull #1651

circleci

carolyncole
Remove ActivateProjectJob
The concept of activating will no longer be useful, since we are either importing the project or creating it from the front end
Pull Request #1651: Remove ActivateProjectJob

4 of 18 branches covered (22.22%)

2507 of 3883 relevant lines covered (64.56%)

311.79 hits per line

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

78.72
/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)
57✔
15
      @id = id
57✔
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"
114✔
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
56✔
27
      asset = xml.xpath("/response/reply/result/asset")
52✔
28
      metadata = parse(asset)
52✔
29

30
      if metadata[:collection]
52✔
31
        metadata[:total_file_count] = asset.xpath("./collection/accumulator/value/non-collections").text
×
32
        metadata[:size] = asset.xpath("./collection/accumulator/value/total/@h").text
×
33
        metadata[:accum_names] = asset.xpath("./collection/accumulator/@name")
×
34
        metadata[:ctime] = asset.xpath("./ctime")
×
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
52✔
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
52✔
40

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

45
    private
1✔
46

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

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

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

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

74
      # Update this to match full 0.6.1 schema
75
      def parse(asset)
1✔
76
        {
77
          id: asset.xpath("./@id").text,
52✔
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)
1✔
90
        return {} if project.blank?
52✔
91
        {
92
          description: project.xpath("./Description").text,
×
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)
1✔
106
        {
107
          created_by: project.xpath("./CreatedBy").text,
×
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)
1✔
115
        submission = project.xpath("./Submission")
×
116
        {
117
          requested_by: submission.xpath("./RequestedBy").text,
×
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