jrdspace 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c5db7f77a3d11787aba5287f24399b892124e5bb
4
- data.tar.gz: bb17539e3e32642d8d8d2826fec7e496d638ba88
3
+ metadata.gz: 068382596fdb06ed88b6628ebaaf0a8948d07b4b
4
+ data.tar.gz: c77b894f115059873b84251cc857b8c3b25a1419
5
5
  SHA512:
6
- metadata.gz: c076098fdff1062aef6d13e7b04817d9f967c5e30390c5e8d151265c24893fffa1634ec1142c6e0d625c448589cb0211ea4670c02f08e375794d1475b2a678e0
7
- data.tar.gz: 46f5ce896a3bc98ff427fb78cacc37c796dc2017be8cbe01947c6b174538e8be0bd68bb3d0644bdd8b7f54825b832bf6437ab58cf59f2eb16ad464e23a744d15
6
+ metadata.gz: d398ad2f1f4dcf31a17734247279af2d38e7dc9239f354412882b881ec9bb977a1cb475236940a157a2d5022ad909e1a0aa6bfb5db081556f885a0b25cb22650
7
+ data.tar.gz: 6eed5a0a82ea28511dda2ca04f73b0d92a8e2fa5bd29abef06a95b53121aa24df96aaddeaada3cea9a2456049a32836a313222bc334ddda000388eef1f5ba453
data/README.md CHANGED
@@ -15,7 +15,7 @@ Documentation is also available at [rubydoc.info](http://www.rubydoc.info/github
15
15
  ### Prerequisite
16
16
  * JRuby [Get Started](http://jruby.org/getting-started)
17
17
  * Package Manager [Bundler](http://bundler.io/)
18
- * optional - but useful [RMV](https://rvm.io/)
18
+ * optional - but useful [RVM](https://rvm.io/)
19
19
 
20
20
  ### Installation
21
21
 
@@ -84,9 +84,11 @@ provide convenience methods, such as retrieving all Communities finding individ
84
84
  DCommunity.all
85
85
  DSpace.fromString ('some/handle')
86
86
  DSpace.fromString ('ITEM.124')
87
- DSpace.fromString ('EPERSON.a_netid')
88
- DSpace.fromString ('GROUP.Anonymous')
89
- DGroup.find('group_name')
87
+ DCollection.find(10)
88
+ DEPerson.find ('email@there.edu')
89
+ DGroup.find('Anonymous')
90
+ DGroup.find(1)
91
+ DMetadataField.find('dc.contributor')
90
92
  ```
91
93
 
92
94
  If you want to make changes you can 'login'
@@ -109,12 +111,13 @@ DCommunity.all.each { |c| puts [c.getCollections.length, c.getHandle, c.getName]
109
111
  ```
110
112
 
111
113
  Java objects can be converted to corresponding jrdspace objects, so that the additional functionality implemented by jrdspace classes becomes available.
112
- For example all jrdspace objects derived from DSpaceObjects implement the parents and policies method:
114
+ For example all jrdspace objects derived from DSpaceObjects implement the parents, policies, and getMetaDataValues method:
113
115
 
114
116
  ```
115
- dso = DSpace.fromHandle('xxxxx/zzz')
117
+ dso = DSpace.fromString('xxxxx/zzz')
116
118
  DSpace.create(dso).parents
117
119
  DSpace.create(dso).policies
120
+ DSpace.create(dso).getMetaDataValues
118
121
  ```
119
122
 
120
123
 
data/lib/dspace.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'dspace/dspace'
2
2
  require 'dspace/dconstants'
3
3
  require 'dspace/dso'
4
+ require 'dspace/ddspaceobject'
4
5
  require 'dspace/deperson'
5
6
  require 'dspace/dgroup'
6
7
  require 'dspace/dcollection'
@@ -2,6 +2,7 @@
2
2
  # This class wraps an org.dspace.content.Bitstream object
3
3
  class DBitstream
4
4
  include DSO
5
+ include DDSpaceObject
5
6
 
6
7
  ##
7
8
  # return array of all org.dspace.content.Bitstream objects
@@ -2,6 +2,7 @@
2
2
  # This class wraps an org.dspace.content.Bitstream object
3
3
  class DBundle
4
4
  include DSO
5
+ include DDSpaceObject
5
6
 
6
7
  ##
7
8
  # returns nil or the org.dspace.content.Bundle object with the given id
@@ -2,6 +2,7 @@
2
2
  # This class wraps an org.dspace.content.Collection object
3
3
  class DCollection
4
4
  include DSO
5
+ include DDSpaceObject
5
6
 
6
7
  ##
7
8
  # return array of all org.dspace.content.Collection objects
@@ -2,6 +2,7 @@
2
2
  # This class wraps an org.dspace.content.Community object
3
3
  class DCommunity
4
4
  include DSO
5
+ include DDSpaceObject
5
6
 
6
7
  ##
7
8
  # return array of all org.dspace.content.Community objects
@@ -0,0 +1,50 @@
1
+ ##
2
+ # This module contains methods to be included by classes that wrap objects
3
+ # that derive from org.dspace.content.DSpaceObject
4
+ require 'json'
5
+
6
+ module DDSpaceObject
7
+
8
+ def parents
9
+ moms = [];
10
+ p = @obj.getParentObject()
11
+ while p do
12
+ moms << p;
13
+ p = p.getParentObject();
14
+ end
15
+ return moms;
16
+ end
17
+
18
+ def policies()
19
+ java_import org.dspace.authorize.AuthorizeManager
20
+ pols = AuthorizeManager.getPolicies(DSpace.context, @obj)
21
+ pols.collect do |p|
22
+ pp = p.getEPerson
23
+ pg = p.getGroup
24
+ hsh = { :action => p.getAction()}
25
+ hsh[:person] = pp.getName if pp
26
+ hsh[:group] = pg.getName if pg
27
+ hsh
28
+ end
29
+ end
30
+
31
+ def getMetaDataValues()
32
+ java_import org.dspace.content.MetadataSchema
33
+ java_import org.dspace.content.MetadataField
34
+ java_import org.dspace.storage.rdbms.DatabaseManager
35
+ java_import org.dspace.storage.rdbms.TableRow
36
+
37
+ sql = "SELECT MV.metadata_field_id, MV.text_value FROM METADATAVALUE MV " +
38
+ " WHERE RESOURCE_TYPE_ID = #{@obj.getType} AND RESOURCE_ID = #{@obj.getID}"
39
+ tri = DatabaseManager.queryTable(DSpace.context, "MetadataValue", sql)
40
+ mvs = [];
41
+ while (iter = tri.next())
42
+ field = MetadataField.find(DSpace.context, iter.getIntColumn("metadata_field_id"))
43
+ mvs << [ DMetadataField.new(field), iter.getStringColumn("text_value") ]
44
+ end
45
+ tri.close
46
+ return mvs
47
+ end
48
+
49
+ end
50
+
@@ -2,6 +2,7 @@
2
2
  # This class wraps an org.dspace.eperson.EPerson object
3
3
  class DEPerson
4
4
  include DSO
5
+ include DDSpaceObject
5
6
 
6
7
  ##
7
8
  # return array of all org.dspace.eperson.EPerson objects
@@ -54,7 +55,8 @@ class DEPerson
54
55
  ##
55
56
  # convert to string
56
57
  def inspect
58
+ return "nil" if @obj.nil?
57
59
  describe = @obj.getNetid || @obj.getEmail || @obj.getID
58
- return "EPERSON.#{describe}"
60
+ return "#<#{self.class.name}:#{describe}>"
59
61
  end
60
62
  end
data/lib/dspace/dgroup.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  # This class wraps an org.dspace.eperson.Group object
3
3
  class DGroup
4
4
  include DSO
5
+ include DDSpaceObject
5
6
 
6
7
  ##
7
8
  # id of administrator group
@@ -70,6 +71,6 @@ class DGroup
70
71
  ##
71
72
  # convert to string
72
73
  def inspect
73
- return "GROUP.#{@obj.getName}"
74
- end
74
+ return "nil" if @obj.nil?
75
+ return "#<#{self.class.name}:#{@obj.getName}>" end
75
76
  end
data/lib/dspace/ditem.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  # This class wraps an org.dspace.content.Item object
3
3
  class DItem
4
4
  include DSO;
5
+ include DDSpaceObject
5
6
 
6
7
  ##
7
8
  # return org.dspace.content.ItemIterator for all Items
@@ -1,12 +1,5 @@
1
1
  class DMetadataField
2
-
3
- ##
4
- # instantiate a wrapper for the given org.dspace.content.MetadataField
5
- def initialize(dobj)
6
- raise "must pass non null obj" unless dobj
7
- raise "must pass org.dspace.content.MetadataField obj" unless dobj.instance_of? org.dspace.content.MetadataField
8
- @obj = dobj
9
- end
2
+ include DSO
10
3
 
11
4
  ##
12
5
  # returns nil or the org.dspace.content.MetadataField object with the given field_name
@@ -25,11 +18,12 @@ class DMetadataField
25
18
  end
26
19
 
27
20
  def inspect
21
+ return "nil" if @obj.nil?
28
22
  java_import org.dspace.content.MetadataSchema
29
23
  schema = MetadataSchema.find(DSpace.context, @obj.schemaID)
30
24
  str = "#{schema.getName}.#{@obj.element}"
31
25
  str += ".#{@obj.qualifier}" if @obj.qualifier
32
- return str
26
+ return "#<#{self.class.name}:#{str}>"
33
27
  end
34
28
 
35
29
  end
data/lib/dspace/dso.rb CHANGED
@@ -10,60 +10,20 @@ module DSO
10
10
  #
11
11
  # the wrapper object's class must be compatible with the type of the given dobj
12
12
  def initialize(dobj)
13
- raise "must pass non null obj" unless dobj
14
- type = DConstants.const_get self.class.name[1..-1].upcase
15
13
  @obj = dobj
16
- raise "#{dobj} is not a #{type} object" unless @obj.getType == type
14
+ if dobj then
15
+ myname = self.class.name
16
+ raise "can't create #{myname} object from #{@obj}" if myname[1..-1] != @obj.getClass.getName.split('.')[-1]
17
+ end
17
18
  end
18
19
 
19
20
  def dso
20
21
  return @obj
21
22
  end
22
23
 
23
- def parents
24
- moms = [];
25
- p = @obj.getParentObject()
26
- while p do
27
- moms << p;
28
- p = p.getParentObject();
29
- end
30
- return moms;
31
- end
32
-
33
- def policies()
34
- java_import org.dspace.authorize.AuthorizeManager
35
- pols = AuthorizeManager.getPolicies(DSpace.context, @obj)
36
- pols.collect do |p|
37
- pp = p.getEPerson
38
- pg = p.getGroup
39
- hsh = { :action => p.getAction()}
40
- hsh[:person] = pp.getName if pp
41
- hsh[:group] = pg.getName if pg
42
- hsh
43
- end
44
- end
45
-
46
- def getMetaDataValues()
47
- java_import org.dspace.content.MetadataSchema
48
- java_import org.dspace.content.MetadataField
49
- java_import org.dspace.storage.rdbms.DatabaseManager
50
- java_import org.dspace.storage.rdbms.TableRow
51
-
52
- sql = "SELECT MV.metadata_field_id, MV.text_value FROM METADATAVALUE MV " +
53
- " WHERE RESOURCE_TYPE_ID = #{@obj.getType} AND RESOURCE_ID = #{@obj.getID}"
54
- tri = DatabaseManager.queryTable(DSpace.context, "MetadataValue", sql)
55
- mvs = [];
56
- while (iter = tri.next())
57
- field = MetadataField.find(DSpace.context, iter.getIntColumn("metadata_field_id"))
58
- mvs << [ DMetadataField.new(field), iter.getStringColumn("text_value") ]
59
- end
60
- tri.close
61
- return mvs
62
- end
63
-
64
24
  def inspect
65
25
  return "nil" if @obj.nil?
66
- return "#{@obj.getTypeText}.#{@obj.getID}"
26
+ return "#<#{self.class.name}:#{@obj.getID}>"
67
27
  end
68
28
 
69
29
  end
data/lib/dspace/dspace.rb CHANGED
@@ -113,6 +113,7 @@ module DSpace
113
113
  if (2 == splits.length) then
114
114
  self.find(splits[0].upcase, splits[1])
115
115
  else
116
+ java_import org.dspace.handle.HandleManager
116
117
  return HandleManager.resolve_to_object(DSpace.context, type_id_or_handle);
117
118
  end
118
119
  end
data/lib/dspace/dwork.rb CHANGED
@@ -34,6 +34,7 @@ module DWork
34
34
  end
35
35
 
36
36
  class DWorkflowItem
37
+ include DSO
37
38
 
38
39
  ##
39
40
  # find org.dspace.workflow.WorkflowItem
@@ -56,6 +57,7 @@ class DWorkflowItem
56
57
  end
57
58
 
58
59
  class DWorkspaceItem
60
+ include DSO
59
61
 
60
62
  ##
61
63
  # find org.dspace.workflow.WorkspaceItem
@@ -1,3 +1,3 @@
1
1
  module DSpace
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
data/test.rb ADDED
@@ -0,0 +1,45 @@
1
+ require 'dspace'
2
+ DSpace.load
3
+
4
+ def test_dso(ddso)
5
+ [:policies, :parents, :getMetaDataValues].each do |m|
6
+ puts "#{ddso.inspect}.#{m} -> #{ddso.send(m)}"
7
+ end
8
+ end
9
+
10
+ [DCommunity, DCollection, DItem, DBitstream].each do |klass|
11
+ puts klass.name + ".all"
12
+ all = klass.send :all
13
+ dso = all[0]
14
+ puts klass.name + ".find"
15
+ o = klass.send :find, dso.getID
16
+ ddso = DSpace.create(o)
17
+ puts "ddso.inspect #{ddso.inspect}"
18
+
19
+ o = DSpace.fromString("#{DConstants.typeStr(dso.getType)}.#{dso.getID}")
20
+ puts "ERROR #{o} != #{DSpace.create(dso).inspect}" if o != dso
21
+ if dso.getHandle then
22
+ o = DSpace.fromString(dso.getHandle)
23
+ puts "ERROR #{o} != #{DSpace.create(dso).inspect}" if o != dso
24
+ end
25
+
26
+ test_dso(ddso)
27
+ end
28
+
29
+ [DWorkflowItem, DWorkspaceItem].each do |klass|
30
+ puts klass.name + ".findAll"
31
+ all = klass.send :findAll, nil
32
+ id = all.length > 0 ? all[0].getID : nil
33
+ puts klass.name + ".find #{id}"
34
+ obj = klass.send(:find, id)
35
+ puts "#{klass}.new #{obj}"
36
+ puts klass.send(:new, obj).inspect
37
+ end
38
+
39
+ ditem = DSpace.create(DBitstream.all[0].getParentObject)
40
+ puts "#{ditem}.bitstreams => #{ditem.bitstreams}"
41
+ bundle = ditem.bitstreams[0].getBundles[0]
42
+ puts bundle
43
+ dbundle = DSpace.create(bundle)
44
+ test_dso(dbundle)
45
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jrdspace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Monika Mevenkamp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-06 00:00:00.000000000 Z
11
+ date: 2016-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jar
@@ -85,6 +85,7 @@ files:
85
85
  - lib/dspace/dcollection.rb
86
86
  - lib/dspace/dcommunity.rb
87
87
  - lib/dspace/dconstants.rb
88
+ - lib/dspace/ddspaceobject.rb
88
89
  - lib/dspace/deperson.rb
89
90
  - lib/dspace/dgroup.rb
90
91
  - lib/dspace/ditem.rb
@@ -93,6 +94,7 @@ files:
93
94
  - lib/dspace/dspace.rb
94
95
  - lib/dspace/dwork.rb
95
96
  - lib/dspace/version.rb
97
+ - test.rb
96
98
  homepage: https://github.com/akinom/dspace-jruby
97
99
  licenses:
98
100
  - MIT