Class: GoodData::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/gooddata/project.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Project

Initialize new project

Parameters:

  • attrs (Hash) (defaults to: {})

    project attributes

Options Hash (attrs):

  • :title (String)

    project title

  • :authorization (String)

    project authorization

  • :summary (String)

    project summary (Optional)

  • :guided (Integer)

    guided navigation (Optional)

  • :driver (String) — default: Optional
  • :template (String)

    project template url (Optional)


57
58
59
60
61
# File 'lib/gooddata/project.rb', line 57

def initialize(attrs = {})
  attrs.each do |key, value|
    send("#{key}=", value)
  end
end

Instance Attribute Details

#authorization=(value) ⇒ Object (writeonly)

Sets the attribute authorization

Parameters:

  • value

    the value to set the attribute authorization to.


10
11
12
# File 'lib/gooddata/project.rb', line 10

def authorization=(value)
  @authorization = value
end

#driver=(value) ⇒ Object (writeonly)

Sets the attribute driver

Parameters:

  • value

    the value to set the attribute driver to.


10
11
12
# File 'lib/gooddata/project.rb', line 10

def driver=(value)
  @driver = value
end

#guidedObject

Returns the value of attribute guided


9
10
11
# File 'lib/gooddata/project.rb', line 9

def guided
  @guided
end

#idObject (readonly)

Returns the value of attribute id


8
9
10
# File 'lib/gooddata/project.rb', line 8

def id
  @id
end

#rawObject (readonly)

Returns the value of attribute raw


8
9
10
# File 'lib/gooddata/project.rb', line 8

def raw
  @raw
end

#stateObject (readonly)

Returns the value of attribute state


8
9
10
# File 'lib/gooddata/project.rb', line 8

def state
  @state
end

#summaryObject

Returns the value of attribute summary


9
10
11
# File 'lib/gooddata/project.rb', line 9

def summary
  @summary
end

#template=(value) ⇒ Object (writeonly)

Sets the attribute template

Parameters:

  • value

    the value to set the attribute template to.


10
11
12
# File 'lib/gooddata/project.rb', line 10

def template=(value)
  @template = value
end

#titleObject

Returns the value of attribute title


9
10
11
# File 'lib/gooddata/project.rb', line 9

def title
  @title
end

Class Method Details

.allArray<Project>

Get all projects

Returns:

  • (Array<Project>)

    Array of GoodData projects


15
16
17
18
19
20
21
22
# File 'lib/gooddata/project.rb', line 15

def self.all
  GoodData.get("/gdc/account/profile/{user-id}/projects")['projects'].map do |json|
    project = new.parse(json)    # Skip GoodSales Demo project

    next if project.id == 'la84vcyhrq8jwbu4wpipw66q2sqeb923'
    project
  end.compact
end

.create(attrs) ⇒ Project

Create GoodData project

Parameters:

  • attrs (Hash)

    project attributes

Options Hash (attrs):

  • :title (String)

    project title

  • :authorization (String)

    project authorization

  • :summary (String)

    project summary (Optional)

  • :guided (Integer)

    guided navigation (Optional)

  • :driver (String) — default: Optional
  • :template (String)

    project template url (Optional)

Returns:


40
41
42
43
44
# File 'lib/gooddata/project.rb', line 40

def self.create(attrs)
  project = new(attrs)
  project.save
  project
end

.find(id) ⇒ Project

Get project by id

Parameters:

  • id (String)

    project id

Returns:


29
30
31
32
# File 'lib/gooddata/project.rb', line 29

def self.find(id)
  project = GoodData.get("/gdc/projects/#{id}")
  new.parse(project)
end

Instance Method Details

#add_user(user, roles = ['dashboardOnlyRole']) ⇒ Object

Add user to project

Parameters:

  • user (User, String)

    user model or user id

  • roles (Array<String>) (defaults to: ['dashboardOnlyRole'])

    role identifier


123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/gooddata/project.rb', line 123

def add_user(user, roles = ['dashboardOnlyRole'])
  # Extract user id if whole user model was provided
  user = user.id if user.is_a? GoodData::User
  payload = {
    user: {
      content: {
        status: 'ENABLED',
        userRoles: roles.map{|role| get_role_url(role)}
      },
      links: {
        self: "/gdc/account/profile/#{user}"
      }
    }
  }      
  GoodData.post("/gdc/projects/#{@id}/users", payload)
end

#as_json(include_users = false) ⇒ Hash

Get project attributes

Returns:

  • (Hash)

    project attributes


209
210
211
212
213
214
215
216
217
218
# File 'lib/gooddata/project.rb', line 209

def as_json(include_users = false)
  response = {
    id: id,
    title: title,
    state: state,
    summary: summary
  }
  response[:users] = users.map(&:as_json) if include_users
  return response
end

#build_process(attrs = {}) ⇒ Process

Build new Process for Project

Parameters:

  • attrs (Hash) (defaults to: {})

    process attributes

Options Hash (attrs):

  • :name (String)

    process name

  • :path (String)

    path to ETL archive

  • :project_id (String)

    id of target project

Returns:

  • (Process)

    CloudConnect Process


146
147
148
# File 'lib/gooddata/project.rb', line 146

def build_process(attrs = {})
  Process.new({project_id: id, name: title}.merge(attrs))
end

#build_schedule(attrs = {}) ⇒ Schedule

Build new Schedule for Project

Parameters:

  • attrs (Hash) (defaults to: {})

    project attributes

Options Hash (attrs):

  • :account_id (String)

    customer account id

  • :project_id (String)

    GoodData project id

  • :process_id (String)

    GoodData process id

  • :graph (String)

    graph path

Returns:


156
157
158
# File 'lib/gooddata/project.rb', line 156

def build_schedule(attrs = {})
  Schedule.new({project_id: id}.merge(attrs))
end

#deleteObject

Delete GoodData project


114
115
116
# File 'lib/gooddata/project.rb', line 114

def delete
  GoodData.delete("/gdc/projects/#{@id}")
end

#get_role_url(role) ⇒ String

Get Role url

Parameters:

  • role (String)

    role identifier

Returns:

  • (String)

    role url

Raises:

  • (ArgumentError)

175
176
177
178
179
180
181
182
183
184
185
# File 'lib/gooddata/project.rb', line 175

def get_role_url(role)
  user_role = nil  # Get list of roles for current object

  GoodData.get("/gdc/projects/#{id}/roles")['projectRoles']['roles'].each do |role_url|
    # Use current url if role identifier matches
    user_role = role_url if GoodData.get(role_url)['projectRole']['meta']['identifier'] == role
    break if user_role
  end
  raise ArgumentError, "project doesn't have role with #{role} identifier" unless user_role
  return user_role
end

#parse(attrs) ⇒ Project

Parse GoodData project

Parameters:

  • attrs (Hash)

    Parse JSON response for GoodData project

Returns:


68
69
70
71
72
73
74
75
76
# File 'lib/gooddata/project.rb', line 68

def parse(attrs)
  @id = attrs['project']['links']['self'].split('/').last
  @title = attrs['project']['meta']['title']
  @summary = attrs['project']['meta']['summary']
  @state = attrs['project']['content']['state']
  @guided = attrs['project']['content']['guidedNavigation']
  @raw = attrs['project']
  self
end

#processesArray<Process>

Get Project processes

Returns:

  • (Array<Process>)

    Array of GoodData processes


164
165
166
167
168
# File 'lib/gooddata/project.rb', line 164

def processes
  GoodData.get("/gdc/projects/#{id}/dataload/processes")['processes']['items'].map do |process|
    Process.new.parse(process)
  end
end

#reloadObject


106
107
108
109
# File 'lib/gooddata/project.rb', line 106

def reload
  project = GoodData.get("/gdc/projects/#{@id}")
  parse(project)
end

#saveString

Save project to GoodData

Parameters:

  • environment (String)

    project environment

Returns:

  • (String)

    project id

Raises:

  • (NotImplementedError)

83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/gooddata/project.rb', line 83

def save()
  # Raise exception if project already exists in GoodData
  raise NotImplementedError, "Update is not supported by GoodData" if @id  # Build a payload

  payload = {
    project: {
      content: {
        guidedNavigation: @guided || 1,
        driver: @driver || 'Pg',
        authorizationToken: @authorization
      },
      meta: {
        title: @title,
        summary: @summary
      }
    }
  }
  payload.merge!(projectTemplate: @template) if @template  # Create a new project

  response = GoodData.post('/gdc/projects', payload)
  @id = response['uri'].split('/').last
end

#set_palette(palette) ⇒ Object

Set color palette for project

Parameters:

  • palette (String)

    palette as json


201
202
203
# File 'lib/gooddata/project.rb', line 201

def set_palette(palette)
  GoodData.put("/gdc/projects/#{id}/styleSettings", palette)
end

#usersArray<User>

Get project users

Returns:

  • (Array<User>)

    project users


191
192
193
194
195
# File 'lib/gooddata/project.rb', line 191

def users
  GoodData.get("/gdc/projects/#{id}/users")['users'].map do |user|
    User.new.parse_project(user)
  end
end