ro-bundle 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,80 @@
1
+ #------------------------------------------------------------------------------
2
+ # Copyright (c) 2014 The University of Manchester, UK.
3
+ #
4
+ # BSD Licenced. See LICENCE.rdoc for details.
5
+ #
6
+ # Author: Robert Haines
7
+ #------------------------------------------------------------------------------
8
+
9
+ #
10
+ module ROBundle
11
+
12
+ # A class to represent an ORE Proxy for an Aggregate as per the specification
13
+ #of the
14
+ # {JSON structure}[https://researchobject.github.io/specifications/bundle/#json-structure]
15
+ # of the manifest.
16
+ class Proxy < ManifestEntry
17
+
18
+ # :call-seq:
19
+ # new
20
+ # new(folder)
21
+ # new(folder, filename)
22
+ #
23
+ # Create a new ORE Proxy. If +folder+ is not supplied then "/" is assumed.
24
+ def initialize(object = "", filename = nil)
25
+ super()
26
+
27
+ if object.instance_of?(Hash)
28
+ @structure = object
29
+ init_provenance_defaults(@structure)
30
+ else
31
+ @structure = {}
32
+ @structure[:uri] = UUID.generate(:urn)
33
+ @structure[:folder] = folder_slashes(object)
34
+ @structure[:filename] = filename
35
+ end
36
+ end
37
+
38
+ # :call-seq:
39
+ # folder
40
+ #
41
+ # Return the folder field of this Proxy.
42
+ def folder
43
+ @structure[:folder]
44
+ end
45
+
46
+ # :call-seq:
47
+ # filename
48
+ #
49
+ # Return the filename field of this Proxy.
50
+ def filename
51
+ @structure[:filename]
52
+ end
53
+
54
+ # :call-seq:
55
+ # uri -> String in the form of a urn:uuid URI.
56
+ #
57
+ # Return the annotation id of this Annotation.
58
+ def uri
59
+ @structure[:uri]
60
+ end
61
+
62
+ # :call-seq:
63
+ # to_json(options = nil) -> String
64
+ #
65
+ # Write this Proxy out as a json string. Takes the same options as
66
+ # JSON#generate.
67
+ def to_json(*a)
68
+ JSON.generate(Util.clean_json(@structure),*a)
69
+ end
70
+
71
+ private
72
+
73
+ def folder_slashes(folder)
74
+ folder = "/#{folder}" unless folder.start_with?('/')
75
+ folder = "#{folder}/" unless folder.end_with?('/')
76
+ folder
77
+ end
78
+
79
+ end
80
+ end
@@ -17,7 +17,7 @@ module ROBundle
17
17
  #
18
18
  # Remove empty strings and nils from a json hash structure.
19
19
  def self.clean_json(structure)
20
- structure.delete_if do |_, v|
20
+ structure.dup.delete_if do |_, v|
21
21
  v.nil? || (v.respond_to?(:empty?) && v.empty?)
22
22
  end
23
23
  end
@@ -9,5 +9,5 @@
9
9
  #
10
10
  module ROBundle
11
11
  # The version number of this library as a String.
12
- VERSION = "0.1.0"
12
+ VERSION = "0.2.0"
13
13
  end
@@ -1,5 +1,5 @@
1
1
  #------------------------------------------------------------------------------
2
- # Copyright (c) 2014 The University of Manchester, UK.
2
+ # Copyright (c) 2014, 2015 The University of Manchester, UK.
3
3
  #
4
4
  # BSD Licenced. See LICENCE.rdoc for details.
5
5
  #
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
19
19
  "Research Object (RO) bundles."
20
20
  spec.description = "This library provides an API for manipulating "\
21
21
  "Research Object (RO) bundles. The RO bundle specification can be found "\
22
- "at http://purl.org/wf4ever/ro-bundle."
23
- spec.homepage = "http://www.taverna.org.uk"
22
+ "at https://w3id.org/bundle/."
23
+ spec.homepage = "http://www.researchobject.org/"
24
24
  spec.license = "BSD"
25
25
 
26
26
  spec.files = `git ls-files`.split($/)
@@ -35,9 +35,10 @@ Gem::Specification.new do |spec|
35
35
  spec.required_ruby_version = ">= 1.9.3"
36
36
  spec.add_development_dependency "bundler", "~> 1.5"
37
37
  spec.add_development_dependency "rake", "~> 10.1"
38
- spec.add_development_dependency("rdoc", "~> 4.1")
38
+ spec.add_development_dependency "rdoc", "~> 4.1"
39
+ spec.add_development_dependency "test-unit", "~> 3.0"
39
40
  spec.add_development_dependency "coveralls"
40
- spec.add_runtime_dependency "ucf", "~> 1.0"
41
+ spec.add_runtime_dependency "ucf", "~> 2.0"
41
42
  spec.add_runtime_dependency "json", "~> 1.8"
42
43
  spec.add_runtime_dependency "uuid", "~> 2.3"
43
44
  end
@@ -11,9 +11,9 @@
11
11
  "name": "Alice W. Land" },
12
12
  "history": "evolution.ttl",
13
13
  "aggregates": [
14
- { "file": "/folder/soup.jpeg" },
15
- { "uri": "http://example.com/blog/" },
16
- { "file": "/README.txt",
14
+ { "uri": "/folder/soup.jpeg" },
15
+ { "uri": "http://example.com/blog/" },
16
+ { "uri": "/README.txt",
17
17
  "mediatype": "text/plain",
18
18
  "createdBy": {
19
19
  "uri": "http://example.com/foaf#bob",
@@ -21,15 +21,15 @@
21
21
  "createdOn": "2013-02-12T19:37:32.939Z" },
22
22
  { "uri": "http://example.com/comments.txt",
23
23
  "bundledAs": {
24
- "uri": "urn:uuid:a0cf8616-bee4-4a71-b21e-c60e6499a644",
24
+ "uri": "urn:uuid:a0cf8616-bee4-4a71-b21e-c60e6499a644",
25
25
  "folder": "/folder/",
26
26
  "filename": "external.txt" }
27
27
  }
28
28
  ],
29
29
  "annotations": [
30
- { "annotation": "urn:uuid:d67466b4-3aeb-4855-8203-90febe71abdf",
31
- "about": "/folder/soup.jpeg",
32
- "content": "annotations/soup-properties.ttl" },
30
+ { "uri": "urn:uuid:d67466b4-3aeb-4855-8203-90febe71abdf",
31
+ "about": "/folder/soup.jpeg",
32
+ "content": "annotations/soup-properties.ttl" },
33
33
 
34
34
  { "about": "urn:uuid:a0cf8616-bee4-4a71-b21e-c60e6499a644",
35
35
  "content": "http://example.com/blog/they-aggregated-our-file" },
@@ -0,0 +1,17 @@
1
+ {
2
+ "@context": [
3
+ "https://w3id.org/bundle/context"
4
+ ],
5
+ "id": "/",
6
+ "manifest": "manifest.json",
7
+ "aggregates": [
8
+ { "uri": "http://example.com/blog/2012" },
9
+ { "uri": "http://example.com/blog/2013" }
10
+ ],
11
+ "@graph": [
12
+ { "@id": "http://example.com/blog/2013",
13
+ "dct:replaces": "http://example.com/blog/2012" },
14
+ { "@id": "http://example.com/blog/2012",
15
+ "dct:isReplacedBy": "http://example.com/blog/2013" }
16
+ ]
17
+ }
@@ -25,7 +25,10 @@ class FakeProvenance
25
25
  @structure ||= init_provenance_defaults(
26
26
  {
27
27
  :createdBy => { :name => "Robert Haines" },
28
- :createdOn => "2014-08-20T11:30:00+01:00"
28
+ :createdOn => "2014-08-20T11:30:00+01:00",
29
+ :retrievedBy => { :name => "Robert Haines" },
30
+ :retrievedFrom => "http://example.org/thing",
31
+ :retrievedOn => "2014-11-10T18:30:00Z"
29
32
  }
30
33
  )
31
34
  end
@@ -22,7 +22,7 @@ class TestAddAnnotation < Test::Unit::TestCase
22
22
  annotation2 = ROBundle::Annotation.new(entry, uri)
23
23
  annotation3 = ROBundle::Annotation.new(annotation1)
24
24
 
25
- ROBundle::File.create(filename) do |b|
25
+ bundle = ROBundle::File.create(filename) do |b|
26
26
  b.add_aggregate(entry, $man_ex3)
27
27
 
28
28
  ann = b.add_annotation(annotation1)
@@ -33,17 +33,20 @@ class TestAddAnnotation < Test::Unit::TestCase
33
33
 
34
34
  ann1, ann2, ann3 = b.annotations
35
35
 
36
- assert b.annotation?(ann1.annotation_id)
36
+ assert b.annotation?(ann1.uri)
37
37
  assert_same annotation1, ann1
38
38
 
39
- assert b.annotation?(ann2.annotation_id)
39
+ assert b.annotation?(ann2.uri)
40
40
  assert_same annotation2, ann2
41
41
  assert_equal uri, ann2.content
42
42
 
43
- assert b.annotation?(ann3.annotation_id)
43
+ assert b.annotation?(ann3.uri)
44
44
  assert_same annotation3, ann3
45
+ assert b.commit_required?
45
46
  end
46
47
 
48
+ refute bundle.commit_required?
49
+
47
50
  ROBundle::File.open(filename) do |b|
48
51
  refute b.aggregates.empty?
49
52
  refute b.annotations.empty?
@@ -51,14 +54,14 @@ class TestAddAnnotation < Test::Unit::TestCase
51
54
 
52
55
  ann1, ann2, ann3 = b.annotations
53
56
 
54
- assert b.annotation?(ann1.annotation_id)
57
+ assert b.annotation?(ann1.uri)
55
58
  assert_not_same annotation1, ann1
56
59
 
57
- assert b.annotation?(ann2.annotation_id)
60
+ assert b.annotation?(ann2.uri)
58
61
  assert_not_same annotation2, ann2
59
62
  assert_equal uri, ann2.content
60
63
 
61
- assert b.annotation?(ann3.annotation_id)
64
+ assert b.annotation?(ann3.uri)
62
65
  assert_not_same annotation3, ann3
63
66
  end
64
67
  end
@@ -124,10 +127,10 @@ class TestAddAnnotation < Test::Unit::TestCase
124
127
 
125
128
  ann1, ann2, ann3 = b.annotations
126
129
 
127
- assert b.annotation?(ann1.annotation_id)
130
+ assert b.annotation?(ann1.uri)
128
131
  refute b.aggregate?(ann1.content)
129
132
 
130
- assert b.annotation?(ann2.annotation_id)
133
+ assert b.annotation?(ann2.uri)
131
134
  assert b.aggregate?(ann2.content)
132
135
 
133
136
  assert b.annotation?(ann3)
@@ -141,10 +144,10 @@ class TestAddAnnotation < Test::Unit::TestCase
141
144
 
142
145
  ann1, ann2, ann3 = b.annotations
143
146
 
144
- assert b.annotation?(ann1.annotation_id)
147
+ assert b.annotation?(ann1.uri)
145
148
  refute b.aggregate?(ann1.content)
146
149
 
147
- assert b.annotation?(ann2.annotation_id)
150
+ assert b.annotation?(ann2.uri)
148
151
  assert b.aggregate?(ann2.content)
149
152
 
150
153
  assert b.annotation?(ann3)
@@ -174,10 +177,10 @@ class TestAddAnnotation < Test::Unit::TestCase
174
177
 
175
178
  ann1, ann2, ann3 = b.annotations
176
179
 
177
- assert b.annotation?(ann1.annotation_id)
180
+ assert b.annotation?(ann1.uri)
178
181
  refute b.aggregate?(ann1.content)
179
182
 
180
- assert b.annotation?(ann2.annotation_id)
183
+ assert b.annotation?(ann2.uri)
181
184
  assert b.aggregate?(ann2.content)
182
185
 
183
186
  assert b.annotation?(ann3)
@@ -191,10 +194,10 @@ class TestAddAnnotation < Test::Unit::TestCase
191
194
 
192
195
  ann1, ann2, ann3 = b.annotations
193
196
 
194
- assert b.annotation?(ann1.annotation_id)
197
+ assert b.annotation?(ann1.uri)
195
198
  refute b.aggregate?(ann1.content)
196
199
 
197
- assert b.annotation?(ann2.annotation_id)
200
+ assert b.annotation?(ann2.uri)
198
201
  assert b.aggregate?(ann2.content)
199
202
 
200
203
  assert b.annotation?(ann3)
@@ -223,11 +226,11 @@ class TestAddAnnotation < Test::Unit::TestCase
223
226
 
224
227
  ann1, ann2, ann3 = b.annotations
225
228
 
226
- assert b.annotation?(ann1.annotation_id)
229
+ assert b.annotation?(ann1.uri)
227
230
  refute b.aggregate?(ann1.content)
228
231
  assert_equal content, b.file.read(".ro/#{ann1.content}")
229
232
 
230
- assert b.annotation?(ann2.annotation_id)
233
+ assert b.annotation?(ann2.uri)
231
234
  assert b.aggregate?(ann2.content)
232
235
  assert_equal content, b.file.read(ann2.content)
233
236
 
@@ -243,11 +246,11 @@ class TestAddAnnotation < Test::Unit::TestCase
243
246
 
244
247
  ann1, ann2, ann3 = b.annotations
245
248
 
246
- assert b.annotation?(ann1.annotation_id)
249
+ assert b.annotation?(ann1.uri)
247
250
  refute b.aggregate?(ann1.content)
248
251
  assert_equal content, b.file.read(".ro/#{ann1.content}")
249
252
 
250
- assert b.annotation?(ann2.annotation_id)
253
+ assert b.annotation?(ann2.uri)
251
254
  assert b.aggregate?(ann2.content)
252
255
  assert_equal content, b.file.read(ann2.content)
253
256
 
@@ -280,10 +283,10 @@ class TestAddAnnotation < Test::Unit::TestCase
280
283
 
281
284
  ann1, ann2, ann3 = b.annotations
282
285
 
283
- assert b.annotation?(ann1.annotation_id)
286
+ assert b.annotation?(ann1.uri)
284
287
  refute b.aggregate?(ann1.content)
285
288
 
286
- assert b.annotation?(ann2.annotation_id)
289
+ assert b.annotation?(ann2.uri)
287
290
  refute b.aggregate?(uri1)
288
291
  assert b.aggregate?(ann2.content)
289
292
 
@@ -298,10 +301,10 @@ class TestAddAnnotation < Test::Unit::TestCase
298
301
 
299
302
  ann1, ann2, ann3 = b.annotations
300
303
 
301
- assert b.annotation?(ann1.annotation_id)
304
+ assert b.annotation?(ann1.uri)
302
305
  refute b.aggregate?(ann1.content)
303
306
 
304
- assert b.annotation?(ann2.annotation_id)
307
+ assert b.annotation?(ann2.uri)
305
308
  refute b.aggregate?(uri1)
306
309
  assert b.aggregate?(ann2.content)
307
310
 
@@ -333,10 +336,10 @@ class TestAddAnnotation < Test::Unit::TestCase
333
336
 
334
337
  ann1, ann2, ann3 = b.annotations
335
338
 
336
- assert b.annotation?(ann1.annotation_id)
339
+ assert b.annotation?(ann1.uri)
337
340
  refute b.aggregate?(ann1.content)
338
341
 
339
- assert b.annotation?(ann2.annotation_id)
342
+ assert b.annotation?(ann2.uri)
340
343
  refute b.aggregate?(uri1)
341
344
  assert b.aggregate?(ann2.content)
342
345
 
@@ -351,10 +354,10 @@ class TestAddAnnotation < Test::Unit::TestCase
351
354
 
352
355
  ann1, ann2, ann3 = b.annotations
353
356
 
354
- assert b.annotation?(ann1.annotation_id)
357
+ assert b.annotation?(ann1.uri)
355
358
  refute b.aggregate?(ann1.content)
356
359
 
357
- assert b.annotation?(ann2.annotation_id)
360
+ assert b.annotation?(ann2.uri)
358
361
  refute b.aggregate?(uri1)
359
362
  assert b.aggregate?(ann2.content)
360
363
 
@@ -383,11 +386,11 @@ class TestAddAnnotation < Test::Unit::TestCase
383
386
 
384
387
  ann1, ann2, ann3 = b.annotations
385
388
 
386
- assert b.annotation?(ann1.annotation_id)
389
+ assert b.annotation?(ann1.uri)
387
390
  refute b.aggregate?(ann1.content)
388
391
  assert_equal content, b.file.read(".ro/#{ann1.content}")
389
392
 
390
- assert b.annotation?(ann2.annotation_id)
393
+ assert b.annotation?(ann2.uri)
391
394
  assert b.aggregate?(ann2.content)
392
395
  assert_equal content, b.file.read(ann2.content)
393
396
 
@@ -403,11 +406,11 @@ class TestAddAnnotation < Test::Unit::TestCase
403
406
 
404
407
  ann1, ann2, ann3 = b.annotations
405
408
 
406
- assert b.annotation?(ann1.annotation_id)
409
+ assert b.annotation?(ann1.uri)
407
410
  refute b.aggregate?(ann1.content)
408
411
  assert_equal content, b.file.read(".ro/#{ann1.content}")
409
412
 
410
- assert b.annotation?(ann2.annotation_id)
413
+ assert b.annotation?(ann2.uri)
411
414
  assert b.aggregate?(ann2.content)
412
415
  assert_equal content, b.file.read(ann2.content)
413
416
 
@@ -433,7 +436,7 @@ class TestAddAnnotation < Test::Unit::TestCase
433
436
  b.add_annotation(annotation1)
434
437
  b.add_annotation(annotation2)
435
438
 
436
- ann = b.add_annotation(annotation1.annotation_id, $man_ex3)
439
+ ann = b.add_annotation(annotation1.uri, $man_ex3)
437
440
  b.add_annotation(annotation1, $man_ex3, :aggregate => true)
438
441
  b.add_annotation(annotation2, entry)
439
442
 
@@ -441,10 +444,10 @@ class TestAddAnnotation < Test::Unit::TestCase
441
444
 
442
445
  _, _, ann1, ann2, ann3 = b.annotations
443
446
 
444
- assert b.annotation?(ann1.annotation_id)
447
+ assert b.annotation?(ann1.uri)
445
448
  refute b.aggregate?(ann1.content)
446
449
 
447
- assert b.annotation?(ann2.annotation_id)
450
+ assert b.annotation?(ann2.uri)
448
451
  assert b.aggregate?(ann2.content)
449
452
 
450
453
  assert b.annotation?(ann3)
@@ -458,10 +461,10 @@ class TestAddAnnotation < Test::Unit::TestCase
458
461
 
459
462
  _, _, ann1, ann2, ann3 = b.annotations
460
463
 
461
- assert b.annotation?(ann1.annotation_id)
464
+ assert b.annotation?(ann1.uri)
462
465
  refute b.aggregate?(ann1.content)
463
466
 
464
- assert b.annotation?(ann2.annotation_id)
467
+ assert b.annotation?(ann2.uri)
465
468
  assert b.aggregate?(ann2.content)
466
469
 
467
470
  assert b.annotation?(ann3)
@@ -493,10 +496,10 @@ class TestAddAnnotation < Test::Unit::TestCase
493
496
 
494
497
  _, ann1, ann2, ann3 = b.annotations
495
498
 
496
- assert b.annotation?(ann1.annotation_id)
499
+ assert b.annotation?(ann1.uri)
497
500
  refute b.aggregate?(ann1.content)
498
501
 
499
- assert b.annotation?(ann2.annotation_id)
502
+ assert b.annotation?(ann2.uri)
500
503
  assert b.aggregate?(ann2.content)
501
504
 
502
505
  assert b.annotation?(ann3)
@@ -510,10 +513,10 @@ class TestAddAnnotation < Test::Unit::TestCase
510
513
 
511
514
  _, ann1, ann2, ann3 = b.annotations
512
515
 
513
- assert b.annotation?(ann1.annotation_id)
516
+ assert b.annotation?(ann1.uri)
514
517
  refute b.aggregate?(ann1.content)
515
518
 
516
- assert b.annotation?(ann2.annotation_id)
519
+ assert b.annotation?(ann2.uri)
517
520
  assert b.aggregate?(ann2.content)
518
521
 
519
522
  assert b.annotation?(ann3)
@@ -541,11 +544,11 @@ class TestAddAnnotation < Test::Unit::TestCase
541
544
 
542
545
  _, ann1, ann2 = b.annotations
543
546
 
544
- assert b.annotation?(ann1.annotation_id)
547
+ assert b.annotation?(ann1.uri)
545
548
  refute b.aggregate?(ann1.content)
546
549
  assert_equal content, b.file.read(".ro/#{ann1.content}")
547
550
 
548
- assert b.annotation?(ann2.annotation_id)
551
+ assert b.annotation?(ann2.uri)
549
552
  assert b.aggregate?(ann2.content)
550
553
  assert_equal content, b.file.read(ann2.content)
551
554
  end
@@ -557,11 +560,11 @@ class TestAddAnnotation < Test::Unit::TestCase
557
560
 
558
561
  _, ann1, ann2 = b.annotations
559
562
 
560
- assert b.annotation?(ann1.annotation_id)
563
+ assert b.annotation?(ann1.uri)
561
564
  refute b.aggregate?(ann1.content)
562
565
  assert_equal content, b.file.read(".ro/#{ann1.content}")
563
566
 
564
- assert b.annotation?(ann2.annotation_id)
567
+ assert b.annotation?(ann2.uri)
565
568
  assert b.aggregate?(ann2.content)
566
569
  assert_equal content, b.file.read(ann2.content)
567
570
  end