218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
# File 'lib/gooddata/models/metadata.rb', line 218
def save
fail('Validation failed') unless validate
opts = {
:client => client,
:project => project
}
if saved?
client.put(uri, to_json)
else
explicit_identifier = meta['identifier']
klass = self.class
if explicit_identifier && klass[explicit_identifier, opts]
fail "Identifier '#{explicit_identifier}' already in use"
end
req_uri = project.md['obj']
result = client.post(req_uri, to_json)
saved_object = self.class[result['uri'], opts]
@json = saved_object.json
if explicit_identifier
meta['identifier'] = explicit_identifier
begin
client.put(uri, to_json)
rescue => e
client.delete(uri)
raise e
end
end
end
self
end
|