Class: Pho::Update::Changeset

Inherits:
Object
  • Object
show all
Defined in:
lib/pho/changeset.rb

Overview

Models a Changeset: a delta to an RDF graph

The RDF Schema for Changesets can be found at:

http://vocab.org/changeset/schema

Further reading:

http://n2.talis.com/wiki/Changesets

The Platform Changeset protocol is described at:

http://n2.talis.com/wiki/Changeset_Protocol

Processing of batch changesets is described at:

http://n2.talis.com/wiki/Metabox

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subject_of_change, creator_name = nil, change_reason = nil) {|_self| ... } ⇒ Changeset

Constructor. Parameter should be the URI of the subject of change

subject_of_change

the URI of the resource being changed

creator_name

the name of the creator of this change (optional)

change_reason

the reason for the change (optional)

Yields:

  • (_self)

Yield Parameters:



222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/pho/changeset.rb', line 222

def initialize(subject_of_change, creator_name=nil, change_reason=nil)
  u = URI.parse(subject_of_change)
  #this should catch literals
  if u.scheme() == nil
    raise URI::InvalidURIError.new("Invalid URI")
  end
  @subject_of_change = subject_of_change
  @creator_name = creator_name
  @change_reason = change_reason
  @additions = Array.new
  @removals = Array.new
  yield self if block_given?
end

Instance Attribute Details

#change_reasonObject

Reason for the change being made



215
216
217
# File 'lib/pho/changeset.rb', line 215

def change_reason
  @change_reason
end

#creator_nameObject

Creator name



213
214
215
# File 'lib/pho/changeset.rb', line 213

def creator_name
  @creator_name
end

#subject_of_changeObject (readonly)

URI of the subject of change for this changeset



211
212
213
# File 'lib/pho/changeset.rb', line 211

def subject_of_change
  @subject_of_change
end

Instance Method Details

#add_addition(statement) ⇒ Object

Include a Statement in the Changeset as an addition



281
282
283
284
285
286
# File 'lib/pho/changeset.rb', line 281

def add_addition(statement)
  if statement.subject != @subject_of_change
    raise "Subject of statement must match subject of change of changeset"
  end
  @additions << statement
end

#add_additions(statements) ⇒ Object

Add an array of statements as additions



289
290
291
292
293
# File 'lib/pho/changeset.rb', line 289

def add_additions(statements)
  statements.each do |statement|
    add_addition(statement)
  end
end

#add_removal(statement) ⇒ Object

Include a Statement in the Changeset as a removal



301
302
303
304
305
306
# File 'lib/pho/changeset.rb', line 301

def add_removal(statement)
  if statement.subject != @subject_of_change
    raise "Subject of statement must match subject of change of changeset"
  end
  @removals << statement
end

#add_removals(statements) ⇒ Object

Add an array of statements as removals



309
310
311
312
313
# File 'lib/pho/changeset.rb', line 309

def add_removals(statements)
  statements.each do |statement|
    add_removal(statement)
  end
end

#additionsObject

Return the Statement describing the addition in this Changeset



276
277
278
# File 'lib/pho/changeset.rb', line 276

def additions()
  return @additions
end

#removalsObject

Return the list of Statements describing the removals in this Changeset



296
297
298
# File 'lib/pho/changeset.rb', line 296

def removals()
  return @removals
end

#submit(store, versioned = false) ⇒ Object

Submit this changeset to the specified store

store

the store to which the changeset should be applied



318
319
320
# File 'lib/pho/changeset.rb', line 318

def submit(store, versioned=false)
  return store.submit_changeset(self.to_rdf, versioned)
end

#to_rdf(include_root = true) ⇒ Object

Serialize this changeset as RDF/XML suitable for submitting to the Platform.



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/pho/changeset.rb', line 241

def to_rdf(include_root=true)
  rdf = ""
  if include_root
    rdf << "<rdf:RDF xmlns:cs=\"http://purl.org/vocab/changeset/schema#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">"  
  end
  
  rdf << " <cs:ChangeSet>"
  rdf << "  <cs:subjectOfChange rdf:resource=\"#{@subject_of_change}\"/>"
  if @creator_name
    rdf << "  <cs:creatorName>#{@creator_name}</cs:creatorName>"
  end
  if @change_reason
    rdf << "  <cs:changeReason>#{@change_reason}</cs:changeReason>"
  end
  @additions.each do |add|
      rdf << "  <cs:addition>"
      rdf << add.to_rdf
      rdf << "  </cs:addition>"                                
  end
  @removals.each do |remove|
    rdf << "  <cs:removal>"
    rdf << remove.to_rdf
    rdf << "  </cs:removal>"                                
  end
  
  rdf << " </cs:ChangeSet>"
  
  if include_root
    rdf << "</rdf:RDF>"  
  end
  
  return rdf        
end

#to_sObject



236
237
238
# File 'lib/pho/changeset.rb', line 236

def to_s
  return to_rdf
end