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

pulibrary / tigerdata-app / 5205f704-d89d-4c43-8cfa-9e6783edc33a

29 Feb 2024 07:04PM UTC coverage: 60.206% (-29.9%) from 90.092%
5205f704-d89d-4c43-8cfa-9e6783edc33a

push

circleci

jrgriffiniii
Ensuring that the storage usage and storage capacity is retrieved for
Mediaflux Projects and rendered on the "contents" Project View

11 of 34 new or added lines in 4 files covered. (32.35%)

451 existing lines in 34 files now uncovered.

935 of 1553 relevant lines covered (60.21%)

9.47 hits per line

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

17.91
/app/models/mediaflux/http/create_asset_request.rb
1
# frozen_string_literal: true
2
module Mediaflux
1✔
3
  module Http
1✔
4
    class CreateAssetRequest < Request
1✔
5
      attr_reader :namespace, :asset_name, :collection
1✔
6

7
      # Constructor
8
      # @param session_token [String] the API token for the authenticated session
9
      # @param name [String] Name of the Asset
10
      # @param collection [Boolean] create a collection asset if true
11
      # @param namespace [String] Optional Parent namespace for the asset to be created in
12
      # @param pid [String] Optional Parent collection id (use this or a namespace not both)
13
      # @param tigerdata_values [Hash] Optional parameter for the tigerdata metdata to be applied to the new asset in the meta field
14
      # @param xml_namespace [String]
15
      def initialize(session_token:, namespace: nil, name:, collection: true, tigerdata_values: nil, xml_namespace: nil, xml_namespace_uri: nil, pid: nil)
1✔
16
        super(session_token: session_token)
7✔
UNCOV
17
        @namespace = namespace
×
UNCOV
18
        @asset_name = name
×
UNCOV
19
        @collection = collection
×
UNCOV
20
        @tigerdata_values = tigerdata_values
×
UNCOV
21
        @xml_namespace = xml_namespace || self.class.default_xml_namespace
×
UNCOV
22
        @xml_namespace_uri = xml_namespace_uri || self.class.default_xml_namespace_uri
×
UNCOV
23
        @pid = pid
×
24
      end
25

26
      # Specifies the Mediaflux service to use when creating assets
27
      # @return [String]
28
      def self.service
1✔
UNCOV
29
        "asset.create"
×
30
      end
31

32
      def id
1✔
UNCOV
33
        @id ||= response_xml.xpath("/response/reply/result/id").text
×
UNCOV
34
        @id
×
35
      end
36

37
      private
1✔
38

39
        # The generated XML mimics what we get when we issue an Aterm command as follows:
40
        # > asset.set :id path=/sandbox_ns/rdss_collection
41
        #     :meta <
42
        #       :tigerdata:project <
43
        #         :title "RDSS test project"
44
        #         :description "The description of the project"
45
        #         ...the rest of the fields go here..
46
        #       >
47
        #     >
48
        #
49
        def build_http_request_body(name:)
1✔
UNCOV
50
          super do |xml|
×
UNCOV
51
            xml.args do
×
UNCOV
52
              xml.name asset_name
×
UNCOV
53
              xml.namespace namespace if namespace.present?
×
UNCOV
54
              tigerdata_values_xml(xml)
×
UNCOV
55
              collection_xml(xml)
×
UNCOV
56
              if @pid.present?
×
UNCOV
57
                xml.pid @pid
×
58
              end
59
            end
60
          end
61
        end
62

63
        def collection_xml(xml)
1✔
UNCOV
64
          return unless collection
×
UNCOV
65
          xml.collection do
×
UNCOV
66
            xml.parent.set_attribute("cascade-contained-asset-index", true)
×
UNCOV
67
            xml.parent.set_attribute("contained-asset-index", true)
×
UNCOV
68
            xml.parent.set_attribute("unique-name-index", true)
×
UNCOV
69
            xml.text(collection)
×
70
          end
UNCOV
71
          xml.type "application/arc-asset-collection"
×
72
        end
73

74
        # rubocop:disable Metrics/MethodLength
75
        # rubocop:disable Metrics/AbcSize
76
        def tigerdata_values_xml(xml)
1✔
UNCOV
77
          return unless @tigerdata_values
×
UNCOV
78
          xml.meta do
×
UNCOV
79
            doc = xml.doc
×
UNCOV
80
            root = doc.root
×
81
            # Define the namespace only if this is required
UNCOV
82
            root.add_namespace_definition(@xml_namespace, @xml_namespace_uri)
×
83

UNCOV
84
            element_name = @xml_namespace.nil? ? "project" : "#{@xml_namespace}:project"
×
UNCOV
85
            xml.send(element_name) do
×
UNCOV
86
              xml.Code @tigerdata_values[:code]
×
UNCOV
87
              xml.Title @tigerdata_values[:title]
×
UNCOV
88
              xml.Description @tigerdata_values[:description] if @tigerdata_values[:description].present?
×
UNCOV
89
              xml.Status @tigerdata_values[:status]
×
UNCOV
90
              xml.DataSponsor @tigerdata_values[:data_sponsor]
×
UNCOV
91
              xml.DataManager @tigerdata_values[:data_manager]
×
UNCOV
92
              departments = @tigerdata_values[:departments] || []
×
UNCOV
93
              departments.each do |department|
×
UNCOV
94
                xml.Department department
×
95
              end
UNCOV
96
              ro_users = @tigerdata_values[:data_user_read_only] || []
×
UNCOV
97
              ro_users.each do |ro_user|
×
UNCOV
98
                xml.DataUser do
×
UNCOV
99
                  xml.parent.set_attribute("ReadOnly", true)
×
UNCOV
100
                  xml.text(ro_user)
×
101
                end
102
              end
UNCOV
103
              rw_users = @tigerdata_values[:data_user_read_write] || []
×
UNCOV
104
              rw_users.each do |rw_user|
×
UNCOV
105
                xml.DataUser rw_user
×
106
              end
UNCOV
107
              xml.CreatedOn @tigerdata_values[:created_on]
×
UNCOV
108
              xml.CreatedBy @tigerdata_values[:created_by]
×
UNCOV
109
              xml.ProjectID @tigerdata_values[:project_id]
×
UNCOV
110
              xml.StorageCapacity @tigerdata_values[:storage_capacity]
×
UNCOV
111
              xml.StoragePerformance @tigerdata_values[:storage_performance]
×
UNCOV
112
              xml.ProjectPurpose @tigerdata_values[:project_purpose]
×
113
            end
114
          end
115
        end
116
      # rubocop:enable Metrics/AbcSize
117
      # rubocop:enable Metrics/MethodLength
118
    end
119
  end
120
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