Project

General

Profile

Revision c06f1783

Added by Thomas McKay over 6 years ago

fixes #15743 - import and export of subscriptions one-per-line

View differences:

lib/hammer_cli_csv/content_views.rb
16 16
      REPOSITORIES = 'Repositories or Composites'
17 17
      ENVIRONMENTS = "Lifecycle Environments"
18 18

  
19
      def export
20
        CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
21
          csv << [NAME, LABEL, ORGANIZATION, COMPOSITE, REPOSITORIES, ENVIRONMENTS]
22
          @api.resource(:organizations).call(:index, {
23
              :per_page => 999999
24
          })['results'].each do |organization|
25
            next if option_organization && organization['name'] != option_organization
26

  
27
            composite_contentviews = []
28
            @api.resource(:content_views).call(:index, {
29
                'per_page' => 999999,
30
                'organization_id' => organization['id'],
31
                'nondefault' => true
32
            })['results'].each do |contentview|
33
              name = contentview['name']
34
              label = contentview['label']
35
              orgname = organization['name']
36
              environments = CSV.generate do |column|
37
                column << environment_names(contentview)
38
              end
39
              environments.delete!("\n")
40
              composite = contentview['composite'] == true ? 'Yes' : 'No'
41
              if composite == 'Yes'
42
                contentviews = CSV.generate do |column|
43
                  column << contentview['components'].collect do |component|
44
                    component['content_view']['name']
45
                  end
19
      def export(csv)
20
        csv << [NAME, LABEL, ORGANIZATION, COMPOSITE, REPOSITORIES, ENVIRONMENTS]
21
        @api.resource(:organizations).call(:index, {
22
            :per_page => 999999
23
        })['results'].each do |organization|
24
          next if option_organization && organization['name'] != option_organization
25

  
26
          composite_contentviews = []
27
          @api.resource(:content_views).call(:index, {
28
              'per_page' => 999999,
29
              'organization_id' => organization['id'],
30
              'nondefault' => true
31
          })['results'].each do |contentview|
32
            name = contentview['name']
33
            label = contentview['label']
34
            orgname = organization['name']
35
            environments = CSV.generate do |column|
36
              column << environment_names(contentview)
37
            end
38
            environments.delete!("\n")
39
            composite = contentview['composite'] == true ? 'Yes' : 'No'
40
            if composite == 'Yes'
41
              contentviews = CSV.generate do |column|
42
                column << contentview['components'].collect do |component|
43
                  component['content_view']['name']
46 44
                end
47
                contentviews.delete!("\n")
48
                composite_contentviews << [name, 1, label, orgname, composite, contentviews, environments]
49
              else
50
                repositories = export_column(contentview, 'repositories', 'name')
51
                csv << [name, label, orgname, composite, repositories, environments]
52 45
              end
46
              contentviews.delete!("\n")
47
              composite_contentviews << [name, 1, label, orgname, composite, contentviews, environments]
48
            else
49
              repositories = export_column(contentview, 'repositories', 'name')
50
              csv << [name, label, orgname, composite, repositories, environments]
53 51
            end
54
            composite_contentviews.each do |contentview|
55
              csv << contentview
56
            end
52
          end
53
          composite_contentviews.each do |contentview|
54
            csv << contentview
57 55
          end
58 56
        end
59 57
      end

Also available in: Unified diff