jrdspace 0.0.10 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5374a48462982af2dd2b668f131d141b04cdee5
4
- data.tar.gz: 7569318017512c64a43db11edcaa0a4cfb0b9008
3
+ metadata.gz: c5db7f77a3d11787aba5287f24399b892124e5bb
4
+ data.tar.gz: bb17539e3e32642d8d8d2826fec7e496d638ba88
5
5
  SHA512:
6
- metadata.gz: 9c7636089366716a41e9e8d267534561f7edb4ff8efdfaf1e5391f176cab6643bca26e55268a40c9e3e1d33b0ec2515e54f7be9a6922888c00ad3602ff534043
7
- data.tar.gz: 9083ad89bf0161c5b61a447f1c2590e4639c16f1bf3179beb541a1c3443d48c3ce36f949746415b5e46ce0b8f968aba6666e80412f0ad2ad232b88a8f7df2759
6
+ metadata.gz: c076098fdff1062aef6d13e7b04817d9f967c5e30390c5e8d151265c24893fffa1634ec1142c6e0d625c448589cb0211ea4670c02f08e375794d1475b2a678e0
7
+ data.tar.gz: 46f5ce896a3bc98ff427fb78cacc37c796dc2017be8cbe01947c6b174538e8be0bd68bb3d0644bdd8b7f54825b832bf6437ab58cf59f2eb16ad464e23a744d15
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Jacob Brown
1
+ Copyright (c) 2016 Monika Mevenkamp
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -8,6 +8,8 @@ jrdspace contains an interactive console and therefore enables quick experimenta
8
8
 
9
9
  The companion project [cli-dspace](https://github.com/akinom/dspace-cli) contains utilities that make use of jrdspace.
10
10
 
11
+ Documentation is also available at [rubydoc.info](http://www.rubydoc.info/github/akinom/dspace-jruby)
12
+
11
13
  ## Installation
12
14
 
13
15
  ### Prerequisite
@@ -18,6 +20,7 @@ The companion project [cli-dspace](https://github.com/akinom/dspace-cli) contai
18
20
  ### Installation
19
21
 
20
22
  Add the gem to your projects Gemfile:
23
+
21
24
  ```
22
25
  gem 'jrdspace' # pull from rubygems
23
26
 
@@ -26,11 +29,14 @@ gem 'jrdspace', :git => 'https://github.com/akinom/dspace-jruby', :branch => 'ma
26
29
  ```
27
30
 
28
31
  Install the gem:
32
+
29
33
  ```
30
34
  bundle install
31
35
  ```
32
36
 
33
- Please note that I am still updating this gem ferquently as I discover bugs. So please keep do update frequently with
37
+ Please note that I am still updating this gem frequently as I discover bugs.
38
+ So please update frequently with
39
+
34
40
  ```
35
41
  bundle update
36
42
  ```
@@ -38,6 +44,7 @@ bundle update
38
44
  ## Usage
39
45
 
40
46
  To use in scripts simply include the following
47
+
41
48
  ```
42
49
  require 'dspace'
43
50
  DSpace.load(dspace_install_dir)
@@ -66,13 +73,20 @@ DSpace.load("/home/you/installs/dspace") # load from /home/you/installs/dspa
66
73
  ```
67
74
 
68
75
  The load method sets the environment up by reading configurations from the dspace.cfg file and by requiring all jar files from the ${dspace.dir}/lib directory. After a succesfull load you can start using Java classes by importing them, for example:
76
+
69
77
  ```
70
78
  java_import org.dspace.content.Item;
71
79
  ```
72
- The included classes DSpace, DCommunity, DCollection, ... from [lib/dspace](lib/dspace) provide convenience methods, such as retrieving all Communities or the Group with a given name:
80
+ The included classes DSpace, DCommunity, DCollection, ... from [lib/dspace](lib/dspace)
81
+ provide convenience methods, such as retrieving all Communities finding individual objects:
82
+
73
83
  ```
74
84
  DCommunity.all
75
- DSpace.fromString('GROUP.name')
85
+ DSpace.fromString ('some/handle')
86
+ DSpace.fromString ('ITEM.124')
87
+ DSpace.fromString ('EPERSON.a_netid')
88
+ DSpace.fromString ('GROUP.Anonymous')
89
+ DGroup.find('group_name')
76
90
  ```
77
91
 
78
92
  If you want to make changes you can 'login'
@@ -88,26 +102,15 @@ Remember to call the commit method if you want to save changes
88
102
  DSpace.commit
89
103
  ```
90
104
 
91
-
92
- Find Dspace stuff:
93
-
94
- ```
95
- DSpace.fromHandle ('xxxxx/yyy')
96
- DSpace.fromString ('ITEM.124')
97
- DSpace.fromString ('GROUP.Anonymous')
98
- DSpace.fromString ('EPERSON.a_netid')
99
- DCommunity.all
100
- DGroup.find('group_name')
101
- ```
102
- These methods use the relevant Java classes to locate the objects and return nil or a reference to the Java object found. All public Java methods can be called on returned references.
103
-
104
105
  The following prints a rudimentary community report:
106
+
105
107
  ```
106
108
  DCommunity.all.each { |c| puts [c.getCollections.length, c.getHandle, c.getName].join("\t") }
107
109
  ```
108
110
 
109
111
  Java objects can be converted to corresponding jrdspace objects, so that the additional functionality implemented by jrdspace classes becomes available.
110
- For example all jrdspace objects implement the parents and policies method:
112
+ For example all jrdspace objects derived from DSpaceObjects implement the parents and policies method:
113
+
111
114
  ```
112
115
  dso = DSpace.fromHandle('xxxxx/zzz')
113
116
  DSpace.create(dso).parents
@@ -1,4 +1,5 @@
1
1
  require 'dspace/dspace'
2
+ require 'dspace/dconstants'
2
3
  require 'dspace/dso'
3
4
  require 'dspace/deperson'
4
5
  require 'dspace/dgroup'
@@ -7,5 +8,5 @@ require 'dspace/dcommunity'
7
8
  require 'dspace/ditem'
8
9
  require 'dspace/dbitstream'
9
10
  require 'dspace/dbundle'
10
- require 'dspace/dworkflowitem'
11
- require 'dspace/dworkspaceitem'
11
+ require 'dspace/dwork'
12
+ require 'dspace/dmetadata'
@@ -1,14 +1,22 @@
1
+ ###
2
+ # This class wraps an org.dspace.content.Bitstream object
1
3
  class DBitstream
2
4
  include DSO
3
5
 
6
+ ##
7
+ # return array of all org.dspace.content.Bitstream objects
4
8
  def self.all()
5
9
  java_import org.dspace.content.Bitstream;
6
10
  return Bitstream.findAll(DSpace.context)
7
11
  end
8
12
 
13
+ ##
14
+ # returns nil or the org.dspace.content.Bitstream object with the given id
15
+ #
16
+ # id must be an integer
9
17
  def self.find(id)
10
18
  java_import org.dspace.content.Bitstream;
11
19
  return Bitstream.find(DSpace.context, id)
12
20
  end
13
21
 
14
- end
22
+ end
@@ -1,6 +1,12 @@
1
+ ###
2
+ # This class wraps an org.dspace.content.Bitstream object
1
3
  class DBundle
2
4
  include DSO
3
5
 
6
+ ##
7
+ # returns nil or the org.dspace.content.Bundle object with the given id
8
+ #
9
+ # id must be an integer
4
10
  def self.find(id)
5
11
  java_import org.dspace.content.Bundle;
6
12
  return Bundle.find(DSpace.context, id)
@@ -1,35 +1,44 @@
1
+ ##
2
+ # This class wraps an org.dspace.content.Collection object
1
3
  class DCollection
2
4
  include DSO
3
5
 
6
+ ##
7
+ # return array of all org.dspace.content.Collection objects
4
8
  def self.all()
5
9
  java_import org.dspace.content.Collection;
6
10
  return Collection.findAll(DSpace.context)
7
11
  end
8
12
 
13
+ ##
14
+ # returns nil or the org.dspace.content.Collection object with the given id
15
+ #
16
+ # id must be an integer
9
17
  def self.find(id)
10
18
  java_import org.dspace.content.Collection;
11
19
  return Collection.find(DSpace.context, id)
12
20
  end
13
21
 
14
-
15
- def self.findAll(name)
22
+ ##
23
+ # create and return org.dspace.content.Collection with given name in the given community
24
+ #
25
+ # community must be a org.dspace.content.Communiy obj
26
+ def self.create(name, community)
16
27
  java_import org.dspace.content.Collection;
17
- self.all.select do |c|
18
- c.getName == name
19
- end
28
+ new_col = Collection.create(DSpace.context)
29
+ new_col.setMetadata("name", name)
30
+ new_col.update
31
+ community.addCollection(new_col)
32
+ return new_col
20
33
  end
21
34
 
22
- def report()
23
- rpt = dso_report
24
- rpt[:name] = @obj.getName();
25
- group = @obj.getSubmitters();
26
- rpt[:submitters] = DGroup.new(group).report if group
27
- [1, 2, 3].each do |i|
28
- group = @obj.getWorkflowGroup(i);
29
- if (group) then
30
- rpt["workflow_group_#{i}".to_sym] = DGroup.new(group).report;
31
- end
35
+ ##
36
+ # return all items listed by the dspace item iterator
37
+ def items
38
+ items, iter = [], @obj.items
39
+ while (i = iter.next) do
40
+ items << i
32
41
  end
33
- return rpt;
42
+ items
34
43
  end
35
- end
44
+ end
@@ -1,30 +1,31 @@
1
+ ##
2
+ # This class wraps an org.dspace.content.Community object
1
3
  class DCommunity
2
4
  include DSO
3
5
 
6
+ ##
7
+ # return array of all org.dspace.content.Community objects
4
8
  def self.all()
5
9
  java_import org.dspace.content.Community;
6
10
  return Community.findAll(DSpace.context)
7
11
  end
8
12
 
13
+ ##
14
+ # returns nil or the org.dspace.content.Community object with the given id
15
+ #
16
+ # id must be an integer
9
17
  def self.find(id)
10
18
  java_import org.dspace.content.Community;
11
19
  return Community.find(DSpace.context, id)
12
20
  end
13
21
 
14
- def self.findAll(name)
15
- java_import org.dspace.content.Community;
16
- self.all.select do |c|
17
- c.getName == name
18
- end
19
- end
20
-
21
- def report
22
- rpt = dso_report
23
- list = @obj.getSubcommunities.collect {|sc| DCommunity.new(sc).report }
24
- rpt[:subcomunities] = list unless list.empty?
25
- list = @obj.getCollections.collect {|sc| DCollection.new(sc).report }
26
- rpt[:collections] = list unless list.empty?
27
- return rpt;
22
+ ##
23
+ # create and return top level org.dspace.content.Community with given name
24
+ def self.create(name)
25
+ comm = Community.create(nil, DSpace.context)
26
+ comm.setMetadata("name", name)
27
+ comm.update
28
+ return comm
28
29
  end
29
30
 
30
31
  end
@@ -0,0 +1,44 @@
1
+ ##
2
+ # This class wraps an org.dspace.content.Community object
3
+ class DConstants
4
+
5
+ ##
6
+ # constants corresponding to those defined in org.dspace.core.Constants
7
+ BITSTREAM = 0;
8
+ BUNDLE = 1;
9
+ ITEM = 2;
10
+ COLLECTION = 3;
11
+ COMMUNITY = 4;
12
+ SITE = 5;
13
+ GROUP = 6;
14
+ EPERSON = 7;
15
+
16
+ READ = 0;
17
+ WRITE = 1;
18
+ DELETE = 2;
19
+ ADD = 3;
20
+ REMOVE = 4;
21
+ WORKFLOW_STEP_1 = 5;
22
+ WORKFLOW_STEP_2 = 6;
23
+ WORKFLOW_STEP_3 = 7;
24
+ WORKFLOW_ABORT = 8;
25
+ DEFAULT_BITSTREAM_READ = 9;
26
+ DEFAULT_ITEM_READ = 10;
27
+ ADMIN = 11;
28
+
29
+
30
+ ##
31
+ # returns nil or the org.dspace.content.Community object with the given id
32
+ #
33
+ # id must be an integer
34
+ def self.typeStr(obj_type_id)
35
+ return org.dspace.core.Constants.typeText[obj_type_id].capitalize
36
+ end
37
+
38
+ ##
39
+ # return String for given action_id
40
+ def self.actionStr(action_id)
41
+ return org.dspace.core.Constants.actionText[action_id]
42
+ end
43
+
44
+ end
@@ -1,11 +1,31 @@
1
+ ##
2
+ # This class wraps an org.dspace.eperson.EPerson object
1
3
  class DEPerson
2
4
  include DSO
3
5
 
6
+ ##
7
+ # return array of all org.dspace.eperson.EPerson objects
4
8
  def self.all()
5
9
  java_import org.dspace.eperson.EPerson;
6
10
  return EPerson.findAll(DSpace.context, 1)
7
11
  end
8
12
 
13
+ ##
14
+ # returns nil or the org.dspace.eperson.EPerson object with the given netid, email, or id
15
+ # netid_or_email: must be a string or integer
16
+ def self.find(netid_email_or_id)
17
+ java_import org.dspace.eperson.EPerson;
18
+ raise "must give a netid_or_email value" unless netid_email_or_id
19
+ if netid_email_or_id.is_a? String then
20
+ return EPerson.findByNetid(DSpace.context, netid_email_or_id) || EPerson.findByEmail(DSpace.context, netid_email_or_id)
21
+ end
22
+ return EPerson.find(DSpace.context, netid_email_or_id)
23
+ end
24
+
25
+ ##
26
+ # create an org.dspace.eperson.EPerson with the given netid, name and email
27
+ #
28
+ # the EPerson is not committed to the database
9
29
  def self.create(netid, first, last, email)
10
30
  java_import org.dspace.eperson.EPerson;
11
31
  raise "must give a netid value" unless netid
@@ -24,19 +44,17 @@ class DEPerson
24
44
  return @dso;
25
45
  end
26
46
 
27
- def self.find(netid_or_email)
28
- java_import org.dspace.eperson.EPerson;
29
- raise "must give a netid_or_email value" unless netid_or_email
30
- return EPerson.findByNetid(DSpace.context, netid_or_email) || EPerson.findByEmail(DSpace.context, netid_or_email)
31
- end
32
-
47
+ ##
48
+ # return all groups where this user is a member
33
49
  def groups
34
50
  java_import org.dspace.eperson.Group;
35
51
  return Group.allMemberGroups(DSpace.context, @obj);
36
52
  end
37
53
 
38
- def group_names
39
- groups.collect { |g| g.getName}.sort
54
+ ##
55
+ # convert to string
56
+ def inspect
57
+ describe = @obj.getNetid || @obj.getEmail || @obj.getID
58
+ return "EPERSON.#{describe}"
40
59
  end
41
-
42
60
  end
@@ -1,14 +1,26 @@
1
+ ##
2
+ # This class wraps an org.dspace.eperson.Group object
1
3
  class DGroup
2
4
  include DSO
3
5
 
4
- ADMIN_ID = 1;
5
- ANONYMOUS_ID = 0;
6
+ ##
7
+ # id of administrator group
8
+ ADMIN_ID = 1
6
9
 
10
+ ##
11
+ # id of anonymous user group
12
+ ANONYMOUS_ID = 0
13
+
14
+ ##
15
+ # return array of all org.dspace.eperson.Group objects
7
16
  def self.all
8
17
  java_import org.dspace.eperson.Group;
9
18
  Group.findAll(DSpace.context, 1);
10
19
  end
11
20
 
21
+ ##
22
+ # returns nil or the org.dspace.eperson.Group object with the given name or id
23
+ # name_or_id: must be a string or integer
12
24
  def self.find(name_or_id)
13
25
  java_import org.dspace.eperson.Group;
14
26
  if (name_or_id.class == String)
@@ -18,6 +30,10 @@ class DGroup
18
30
  end
19
31
  end
20
32
 
33
+ ##
34
+ # find and return the existing group with the given name or create and return a new group with the given name
35
+ #
36
+ # name must be a string
21
37
  def self.find_or_create(name)
22
38
  raise "must give a name " unless name
23
39
  group = self.find(name);
@@ -32,17 +48,18 @@ class DGroup
32
48
  return group;
33
49
  end
34
50
 
51
+ ##
52
+ # return EPerson and Groups that are (direct) require 'faker;members of this DGroup
53
+ #
54
+ # name must be a string
35
55
  def members
36
- list = [];
37
- @obj.getMembers.each do |m|
38
- list << m;
39
- end
40
- @obj.getMemberGroups.each do |m|
41
- list << m;
42
- end
43
- return list;
56
+ return @obj.getMembers + @obj.getMemberGroups
44
57
  end
45
58
 
59
+ ##
60
+ # add a memeber to the group
61
+ #
62
+ # group_or_eperson must be a org.dspace.eperson.EPerson or Group object
46
63
  def addMember(group_or_eperson)
47
64
  raise "must give non nil group_or_eperson" if group_or_eperson.nil?
48
65
  @obj.addMember(group_or_eperson);
@@ -50,14 +67,9 @@ class DGroup
50
67
  return @obj;
51
68
  end
52
69
 
53
- def report
54
- rpt = dso_report
55
- @obj.getMemberGroups.each do |m|
56
- rpt[m.toString] = DGroup.new(m).report
57
- end
58
- list = @obj.getMembers()
59
- rpt['epersons'] = list.collect { |p| DEerson.new(p).report } unless list.empty?
60
- return rpt;
70
+ ##
71
+ # convert to string
72
+ def inspect
73
+ return "GROUP.#{@obj.getName}"
61
74
  end
62
-
63
75
  end
@@ -1,37 +1,49 @@
1
+ ##
2
+ # This class wraps an org.dspace.content.Item object
1
3
  class DItem
2
4
  include DSO;
3
5
 
6
+ ##
7
+ # return org.dspace.content.ItemIterator for all Items
4
8
  def self.iter
5
9
  java_import org.dspace.content.Item;
6
10
  Item.findAll(DSpace.context);
7
11
  end
8
12
 
9
- def self.all
13
+ ##
14
+ # return array of all org.dspace.content.Item objects
15
+ def self.all()
10
16
  java_import org.dspace.content.Item;
11
- list = []
12
- stp = iter
17
+ list, stp = [], iter
13
18
  while (i = stp.next)
14
19
  list << i
15
20
  end
16
21
  return list
17
22
  end
18
23
 
24
+ ##
25
+ # returns nil or the org.dspace.content.Item object with the given id
26
+ #
27
+ # id must be an integer
19
28
  def self.find(id)
20
29
  java_import org.dspace.content.Item;
21
- id = id.to_i if id.class == String
22
30
  return Item.find(DSpace.context, id)
23
31
  end
24
32
 
33
+ ##
34
+ # returns [] if restrict_to_dso is nil or all items that are contained in the given restrict_to_dso
35
+ #
36
+ # restrict_to_dso must be nil, or an instance of org.dspace.content.Item, Collection, or Community
25
37
  def self.inside(restrict_to_dso)
26
38
  java_import org.dspace.storage.rdbms.DatabaseManager
27
39
  java_import org.dspace.storage.rdbms.TableRow
28
40
 
29
41
  return [] if restrict_to_dso.nil?
30
- return [restrict_to_dso] if restrict_to_dso.getType == DSpace::ITEM
31
- return [] if restrict_to_dso.getType != DSpace::COLLECTION and restrict_to_dso.getType != DSpace::COMMUNITY
42
+ return [restrict_to_dso] if restrict_to_dso.getType == DConstants::ITEM
43
+ return [] if restrict_to_dso.getType != DConstants::COLLECTION and restrict_to_dso.getType != DConstants::COMMUNITY
32
44
 
33
45
  sql = "SELECT ITEM_ID FROM ";
34
- if (restrict_to_dso.getType() == DSpace::COLLECTION) then
46
+ if (restrict_to_dso.getType() == DConstants::COLLECTION) then
35
47
  sql = sql + " Collection2Item CO WHERE CO.Collection_Id = #{restrict_to_dso.getID}"
36
48
  else
37
49
  # must be COMMUNITY
@@ -49,14 +61,21 @@ class DItem
49
61
  return dsos
50
62
  end
51
63
 
64
+ ##
65
+ # returns the bitstreams in the given bundle
52
66
  def bitstreams(bundle = "ORIGINAL")
53
- bundle = @obj.getBundles.select { |b| b.getName() == bundle }[0]
54
- if (not bundle.nil?) then
55
- return bundle.getBitstreams
67
+ bundles = bundle.nil? ? @obj.getBundles : @obj.getBundles(bundle)
68
+ bits = []
69
+ bundles.each do |b|
70
+ bits += b.getBitstreams
56
71
  end
57
- return [];
72
+ bits
58
73
  end
59
74
 
75
+ ##
76
+ # creata a org.dspace.content.Item with the given metadata in the given collection
77
+ #
78
+ # metadata_hash use keys like dc.contributir.author and single string or arrays of values
60
79
  def self.install(collection, metadata_hash)
61
80
  java_import org.dspace.content.InstallItem;
62
81
  java_import org.dspace.content.WorkspaceItem;
@@ -0,0 +1,35 @@
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
10
+
11
+ ##
12
+ # returns nil or the org.dspace.content.MetadataField object with the given field_name
13
+ #
14
+ # field_name must be a formmatted string: schema.element[.qualifier]
15
+ def self.find(fully_qualified_metadata_field)
16
+ java_import org.dspace.content.MetadataSchema
17
+ java_import org.dspace.content.MetadataField
18
+ java_import org.dspace.storage.rdbms.DatabaseManager
19
+ java_import org.dspace.storage.rdbms.TableRow
20
+
21
+ (schema, element, qualifier) = fully_qualified_metadata_field.split('.')
22
+ schm = MetadataSchema.find(DSpace.context, schema)
23
+ raise "no such metadata schema: #{schema}" if schm.nil?
24
+ return MetadataField.find_by_element(DSpace.context, schm.getSchemaID, element, qualifier)
25
+ end
26
+
27
+ def inspect
28
+ java_import org.dspace.content.MetadataSchema
29
+ schema = MetadataSchema.find(DSpace.context, @obj.schemaID)
30
+ str = "#{schema.getName}.#{@obj.element}"
31
+ str += ".#{@obj.qualifier}" if @obj.qualifier
32
+ return str
33
+ end
34
+
35
+ end
@@ -1,10 +1,17 @@
1
+ ##
2
+ # This module contains methods to be included by classes that wrap objects
3
+ # that derive from org.dspace.content.DSpaceObject
1
4
  require 'json'
2
5
 
3
6
  module DSO
4
7
 
8
+ ##
9
+ # instanciates a wrapper object for the given dobj, which must derive from org.dspace.content.DSpaceObject
10
+ #
11
+ # the wrapper object's class must be compatible with the type of the given dobj
5
12
  def initialize(dobj)
6
13
  raise "must pass non null obj" unless dobj
7
- type = DSpace.const_get self.class.name[1..-1].upcase
14
+ type = DConstants.const_get self.class.name[1..-1].upcase
8
15
  @obj = dobj
9
16
  raise "#{dobj} is not a #{type} object" unless @obj.getType == type
10
17
  end
@@ -23,23 +30,6 @@ module DSO
23
30
  return moms;
24
31
  end
25
32
 
26
- def dso_report
27
- rpt = {};
28
- rpt[:name] = @obj.getName
29
- rpt[:obj] = @obj.toString()
30
- if (@obj.getHandle()) then
31
- rpt[:handle] = @obj.getHandle()
32
- end
33
- if (@obj.getParentObject()) then
34
- rpt[:parent] = @obj.getParentObject().to_s
35
- end
36
- return rpt;
37
- end
38
-
39
- def report
40
- dso_report
41
- end
42
-
43
33
  def policies()
44
34
  java_import org.dspace.authorize.AuthorizeManager
45
35
  pols = AuthorizeManager.getPolicies(DSpace.context, @obj)
@@ -65,10 +55,16 @@ module DSO
65
55
  mvs = [];
66
56
  while (iter = tri.next())
67
57
  field = MetadataField.find(DSpace.context, iter.getIntColumn("metadata_field_id"))
68
- mvs << [ DSpace.toString(field), iter.getStringColumn("text_value") ]
58
+ mvs << [ DMetadataField.new(field), iter.getStringColumn("text_value") ]
69
59
  end
70
60
  tri.close
71
61
  return mvs
72
62
  end
63
+
64
+ def inspect
65
+ return "nil" if @obj.nil?
66
+ return "#{@obj.getTypeText}.#{@obj.getID}"
67
+ end
68
+
73
69
  end
74
70
 
@@ -2,29 +2,35 @@ module DSpace
2
2
  ROOT = File.expand_path('../..', __FILE__)
3
3
  @@config = nil;
4
4
 
5
- BITSTREAM = 0;
6
- BUNDLE = 1;
7
- ITEM = 2;
8
- COLLECTION = 3;
9
- COMMUNITY = 4;
10
- SITE = 5;
11
- GROUP = 6;
12
- EPERSON = 7;
13
5
 
6
+ ##
7
+ # return the name of the wrapper klass that corresponds to the give parameter
8
+ #
9
+ # type_str_or_int must be oe of the integer values: BITTREAM .. EPERSON, or the corresponding string
14
10
  def self.objTypeStr(type_str_or_int)
15
- return type_str_or_int.capitalize if type_str_or_int.class == String and Constants.typeText.find_index type_str_or_int.upcase
16
- begin
17
- id = Integer(type_str_or_int)
18
- rescue
19
- raise "no such object type #{type_str_or_int}"
11
+ if type_str_or_int.class == String and Constants.typeText.find_index type_str_or_int.upcase then
12
+ klassName = type_str_or_int.capitalize
13
+ else
14
+ begin
15
+ id = Integer(type_str_or_int)
16
+ rescue
17
+ raise "no such object type #{type_str_or_int}"
18
+ end
19
+ klassName = DConstants.typeStr(id)
20
20
  end
21
- return Constants.typeText[id].capitalize
21
+ return "EPerson" if klassName == "Eperson"
22
+ return klassName
22
23
  end
23
24
 
25
+ ##
26
+ # convert string to corresponding constant: BITSTREAM, BUNDLE, ...
24
27
  def self.objTypeId(type_str_or_int)
25
28
  obj_typ = Constants.typeText.find_index objTypeStr(type_str_or_int).upcase
26
29
  end
27
30
 
31
+ ##
32
+ # load DSpace configurations and jar files from the dspace_dir directory;
33
+ # if dspace_dir is nil use the value of the environment variable 'DSPACE_HOME' or if undefined as well default to '/dspace'
28
34
  def self.load(dspace_dir = nil)
29
35
  if (@@config.nil?) then
30
36
  @@config = Config.new(dspace_dir || ENV['DSPACE_HOME'] || "/dspace")
@@ -37,37 +43,58 @@ module DSpace
37
43
  return @@config != nil
38
44
  end
39
45
 
46
+ ##
47
+ # return the current org.dspace.core.Context
48
+ #
49
+ # this method fails unless it is preceded by a successfull DSPace.load call
40
50
  def self.context
41
51
  raise "must call load to initialize" if @@config.nil?
42
52
  raise "should never happen" if @@config.context.nil?
43
53
  return @@config.context
44
54
  end
45
55
 
56
+ ##
57
+ # renew the current org.dspace.core.Context; this abandons any uncommited database changes
46
58
  def self.context_renew
47
59
  raise "must call load to initialize" if @@config.nil?
48
60
  raise "should never happen" if @@config.context.nil?
49
61
  return @@config.context_renew
50
62
  end
51
63
 
64
+ ##
65
+ # set the current dspace user to the one with the given netid
52
66
  def self.login(netid)
53
67
  self.context.setCurrentUser(DEPerson.find(netid))
54
68
  return nil
55
69
  end
56
70
 
71
+ ##
72
+ # commit changes to the database
57
73
  def self.commit
58
74
  self.context.commit
59
75
  end
60
76
 
77
+ ##
78
+ # commit a wrapper object for the given java object;
79
+ # the type of the warpper is determined by the class of the given java object
80
+ #
61
81
  def self.create(dso)
62
82
  raise "dso must not be nil" if dso.nil?
63
83
  klass = Object.const_get "D" + dso.class.name.gsub(/.*::/, '')
64
84
  klass.send :new, dso
65
85
  end
66
86
 
67
- def self.fromHandle(handle)
68
- return HandleManager.resolve_to_object(DSpace.context, handle);
69
- end
70
-
87
+ ##
88
+ # return the DSpace object that is identified by the given type and identifier
89
+ #
90
+ # type_str_or_int must be oe of the integer values: BITTREAM .. EPERSON, or the corresponding string
91
+ #
92
+ # identifier must be an integer or string value uniquely identifying the object
93
+ #
94
+ # DSpace.find(DSpace::COLLECTION, 106)
95
+ # DSpace.find("ITEM", 10)
96
+ # DSpace.find("GROUP", "Anonymous")
97
+ # DSpace.find("EPERSON", "her@there.com")
71
98
  def self.find(type_str_or_int, identifier)
72
99
  type_str = DSpace.objTypeStr(type_str_or_int)
73
100
  type_id = DSpace.objTypeId(type_str)
@@ -82,49 +109,40 @@ module DSpace
82
109
 
83
110
  def self.fromString(type_id_or_handle)
84
111
  #TODO handle MetadataField string
85
- splits = type_id_or_handle.split('.')
112
+ splits = type_id_or_handle.split('.', 2)
86
113
  if (2 == splits.length) then
87
114
  self.find(splits[0].upcase, splits[1])
88
115
  else
89
- self.fromHandle(type_id_or_handle)
90
- end
91
- end
92
-
93
- def self.toString(java_obj)
94
- return "nil" unless java_obj
95
- klass = java_obj.getClass.getName
96
- if (klass == "org.dspace.content.MetadataField") then
97
- java_import org.dspace.content.MetadataField
98
- java_import org.dspace.content.MetadataSchema
99
-
100
- schema = MetadataSchema.find(DSpace.context, java_obj.schemaID)
101
- str = "#{schema.getName}.#{java_obj.element}"
102
- str += ".#{java_obj.qualifier}" if java_obj.qualifier
103
- str
104
- else
105
- java_obj.toString
116
+ return HandleManager.resolve_to_object(DSpace.context, type_id_or_handle);
106
117
  end
107
118
  end
108
119
 
120
+ ##
121
+ # get a dspace service by name
109
122
  def self.getService(service_name, java_klass)
110
123
  org.dspace.utils.DSpace.new().getServiceManager().getServiceByName(service_name,java_klass)
111
124
  end
112
125
 
126
+ ##
127
+ # get the SoltServiveImpl
113
128
  def self.getIndexService()
114
129
  java_import org.dspace.discovery.SolrServiceImpl;
115
130
  self.getService("org.dspace.discovery.IndexingService", SolrServiceImpl)
116
131
  end
117
132
 
133
+ ##
134
+ # if value_or_nil is nil and restrict_to_type is nil return all DSpaceObjects have a value for the
135
+ # given metadata field
136
+ #
137
+ # if value_or_nil is not nil restrict to those whose value is equal to the given paramter
138
+ #
139
+ # if restrict_to_typ is not nil, restrict to results of the given type
140
+ #
141
+ # restrict_to_type must be one of BITSTREAM, .., EPERSON
142
+
118
143
  def self.findByMetadataValue(fully_qualified_metadata_field, value_or_nil, restrict_to_type)
119
- java_import org.dspace.content.MetadataSchema
120
- java_import org.dspace.content.MetadataField
121
144
  java_import org.dspace.storage.rdbms.DatabaseManager
122
- java_import org.dspace.storage.rdbms.TableRow
123
-
124
- (schema, element, qualifier) = fully_qualified_metadata_field.split('.')
125
- schm = MetadataSchema.find(DSpace.context, schema)
126
- raise "no such metadata schema: #{schema}" if schm.nil?
127
- field = MetadataField.find_by_element(DSpace.context, schm.getSchemaID, element, qualifier)
145
+ field = DMetadataField.find(fully_qualified_metadata_field)
128
146
  raise "no such metadata field #{fully_qualified_metadata_field}" if field.nil?
129
147
 
130
148
  sql = "SELECT MV.resource_id, MV.resource_type_id FROM MetadataValue MV";
@@ -145,11 +163,10 @@ module DSpace
145
163
  return dsos
146
164
  end
147
165
 
148
- def self.kernel
149
- @@config.kernel;
150
- end
151
-
152
- def self.help(klasses = [DSpace, DCommunity, DCollection, DItem, DGroup])
166
+ ##
167
+ # print available static methods for the give classes
168
+ def self.help(klasses = [DCommunity, DCollection, DItem, DBundle, DBitstream, DEPerson,
169
+ DWorkflowItem, DWorkspaceItem, DMetadataField, DConstants, DSpace])
153
170
  klasses.each do |klass|
154
171
  klass.singleton_methods.sort.each do |mn|
155
172
  m = klass.method(mn)
@@ -0,0 +1,77 @@
1
+ ##
2
+ # Helper module for DWorkflow and DWorkSpace
3
+ module DWork
4
+
5
+ ##
6
+ # returns all instances of klass if the obj parameter is nil, otherwise
7
+ # all instances of klass associated with the the given obj
8
+ #
9
+ # klass:: must be org.dspace.workflow.WorkflowItem and org.dspace.workflow.WorkspaceItem
10
+ # obj:: nil or instances of org.dspace.content.Item, Collection, or Community
11
+ def self.findAll(obj, klass)
12
+ if (obj.nil?) then
13
+ return klass.findAll(DSpace.context)
14
+ end
15
+ if (obj.getType == DConstants::COLLECTION)
16
+ return klass.findByCollection(DSpace.context, obj)
17
+ elsif (obj.getType == DConstants::COMMUNITY) then
18
+ wsis = []
19
+ obj.getAllCollections.each do |col|
20
+ wsis += findAll(col)
21
+ end
22
+ return wsis
23
+ elsif (obj.getType == DConstants::ITEM) then
24
+ wi = klass.findByItem(DSpace.context, obj)
25
+ # to be consistent return array with the unqiue wokflow item
26
+ return [wi] if wi
27
+ elsif (obj.getType == DConstants::EPERSON) then
28
+ wi = klass.findByEPerson(DSpace.context, obj)
29
+ end
30
+ # return empty array if no matching workspace items
31
+ return []
32
+ end
33
+
34
+ end
35
+
36
+ class DWorkflowItem
37
+
38
+ ##
39
+ # find org.dspace.workflow.WorkflowItem
40
+ #
41
+ # id must be an integer
42
+ def self.find(id)
43
+ java_import org.dspace.workflow.WorkflowItem
44
+ return WorkflowItem.find(DSpace.context, id)
45
+ end
46
+
47
+
48
+ ##
49
+ # returns all instances of org.dspace.workflow.WorkflowItem if the obj parameter is nil, otherwise
50
+ # all instances of org.dspace.workflow.WorkflowItem associated with the the given obj
51
+ def self.findAll(obj)
52
+ java_import org.dspace.workflow.WorkflowItem
53
+ return DWork.findAll(obj, WorkflowItem)
54
+ end
55
+
56
+ end
57
+
58
+ class DWorkspaceItem
59
+
60
+ ##
61
+ # find org.dspace.workflow.WorkspaceItem
62
+ #
63
+ # id must be an integer
64
+ def self.find(id)
65
+ java_import org.dspace.content.WorkspaceItem
66
+ return WorkspaceItem.find(DSpace.context, id)
67
+ end
68
+
69
+ ##
70
+ # returns all instances of org.dspace.workflow.WorkspaceItem if the obj parameter is nil, otherwise
71
+ # all instances of org.dspace.workflow.WorkspaceItem associated with the the given obj
72
+ def self.findAll(obj)
73
+ java_import org.dspace.content.WorkspaceItem
74
+ return DWork.findAll(obj, WorkspaceItem)
75
+ end
76
+
77
+ end
@@ -1,3 +1,3 @@
1
1
  module DSpace
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.12"
3
3
  end
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.10
4
+ version: 0.0.12
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-05-24 00:00:00.000000000 Z
11
+ date: 2016-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jar
@@ -84,13 +84,14 @@ files:
84
84
  - lib/dspace/dbundle.rb
85
85
  - lib/dspace/dcollection.rb
86
86
  - lib/dspace/dcommunity.rb
87
+ - lib/dspace/dconstants.rb
87
88
  - lib/dspace/deperson.rb
88
89
  - lib/dspace/dgroup.rb
89
90
  - lib/dspace/ditem.rb
91
+ - lib/dspace/dmetadata.rb
90
92
  - lib/dspace/dso.rb
91
93
  - lib/dspace/dspace.rb
92
- - lib/dspace/dworkflowitem.rb
93
- - lib/dspace/dworkspaceitem.rb
94
+ - lib/dspace/dwork.rb
94
95
  - lib/dspace/version.rb
95
96
  homepage: https://github.com/akinom/dspace-jruby
96
97
  licenses:
@@ -1,27 +0,0 @@
1
- #!/usr/bin/env jruby
2
- require 'dspace'
3
-
4
- class DWorkflowItem
5
- def self.findAll(obj)
6
- java_import org.dspace.workflow.WorkflowItem
7
- if (obj.nil?) then
8
- return WorkflowItem.findAll(DSpace.context)
9
- end
10
- if (obj.getType == DSpace::COLLECTION)
11
- return WorkflowItem.findByCollection(DSpace.context, obj)
12
- elsif (obj.getType == DSpace::COMMUNITY) then
13
- flows = []
14
- obj.getAllCollections.each do |col|
15
- flows += findAll(col)
16
- end
17
- return flows
18
- elsif (obj.getType == DSpace::ITEM) then
19
- wi = WorkflowItem.findByItem(DSpace.context, obj)
20
- # to be consistent return array with the unqiue wokflow item
21
- return [wi] if wi
22
- end
23
- # return empty array if no matching workflow items
24
- return []
25
- end
26
-
27
- end
@@ -1,27 +0,0 @@
1
- #!/usr/bin/env jruby
2
- require 'dspace'
3
-
4
- class DWorkspaceItem
5
- def self.findAll(obj)
6
- java_import org.dspace.content.WorkspaceItem
7
- if (obj.nil?) then
8
- return WorkspaceItem.findAll(DSpace.context)
9
- end
10
- if (obj.getType == DSpace::COLLECTION)
11
- return WorkspaceItem.findByCollection(DSpace.context, obj)
12
- elsif (obj.getType == DSpace::COMMUNITY) then
13
- wsis = []
14
- obj.getAllCollections.each do |col|
15
- wsis += findAll(col)
16
- end
17
- return wsis
18
- elsif (obj.getType == DSpace::ITEM) then
19
- wi = WorkspaceItem.findByItem(DSpace.context, obj)
20
- # to be consistent return array with the unqiue wokflow item
21
- return [wi] if wi
22
- end
23
- # return empty array if no matching workspace items
24
- return []
25
- end
26
-
27
- end