jrdspace 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +114 -0
- data/Rakefile +1 -0
- data/bin/idspace +10 -0
- data/dspace.gemspec +27 -0
- data/lib/dspace.rb +9 -0
- data/lib/dspace/dbitstream.rb +9 -0
- data/lib/dspace/dbundle.rb +4 -0
- data/lib/dspace/dcollection.rb +29 -0
- data/lib/dspace/dcommunity.rb +25 -0
- data/lib/dspace/deperson.rb +42 -0
- data/lib/dspace/dgroup.rb +67 -0
- data/lib/dspace/ditem.rb +75 -0
- data/lib/dspace/dso.rb +57 -0
- data/lib/dspace/dspace.rb +187 -0
- data/lib/dspace/version.rb +3 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ca7f654c183e530d9bd2944d86932e9e236431ca
|
4
|
+
data.tar.gz: c1b7462812097642881381c0380e55498f88ae2f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 59590638b4618cc7ccba03f43a6d044506b24d64974d5d113031f965eedcf1d1f438529ae14dd093a40734787b69b951c05b6b9e20bfc558f70bd79f38ac430f
|
7
|
+
data.tar.gz: 457c84e7d6172faf9383637f9164ded2a9c75e3811743ad392bbc1710d9e8d68baecbaf4416ebacff7549c2eb34e7897f073f131b912462f5e6ca20ef470643c
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Jacob Brown
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
# jrdspace
|
2
|
+
|
3
|
+
jrdsapce is implemented in JRuby.
|
4
|
+
|
5
|
+
It provides a simple mechanism to connect to a [DSpace](https://github.com/DSpace/DSpace) installation and to access and manipulate the Java Objects managed by classes from the dspace-api package.
|
6
|
+
|
7
|
+
jrdspace contains an interactive console and therefore enables quick experimentation.
|
8
|
+
|
9
|
+
The companion project [cli-dspace](https://github.com/akinom/dspace-cli) contains utilities that make use of jrdspace.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
### Prerequisite
|
14
|
+
* JRuby [Get Started](http://jruby.org/getting-started)
|
15
|
+
* Package Manager [Bundler](http://bundler.io/)
|
16
|
+
* optional - but useful [RMV](https://rvm.io/)
|
17
|
+
|
18
|
+
### Installation
|
19
|
+
|
20
|
+
Add the gem to your projects Gemfile:
|
21
|
+
```
|
22
|
+
gem 'jrdspace' # pull from rubygems
|
23
|
+
|
24
|
+
gem 'jrdspace', :git => 'https://github.com/akinom/dspace-jruby', :branch => 'master`
|
25
|
+
|
26
|
+
```
|
27
|
+
|
28
|
+
Install the gem:
|
29
|
+
```
|
30
|
+
bundle install
|
31
|
+
```
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
To use in scripts simply include the following
|
36
|
+
```
|
37
|
+
require 'dspace'
|
38
|
+
DSpace.load(dspace_install_dir)
|
39
|
+
```
|
40
|
+
|
41
|
+
## Interactive Usage
|
42
|
+
|
43
|
+
The included idspace command starts an interactive console.
|
44
|
+
|
45
|
+
```
|
46
|
+
bundle exec idspace
|
47
|
+
> DSpace.load # load DSpace jars and configurations
|
48
|
+
> DSpace.help # lists all static methods of classes in jrdspace
|
49
|
+
```
|
50
|
+
|
51
|
+
Use Tab completion to see available methods
|
52
|
+
|
53
|
+
# Get Started
|
54
|
+
|
55
|
+
Connect to your dspace database and configurations
|
56
|
+
|
57
|
+
```
|
58
|
+
DSpace.load # load DSpace jars and configurations from ENV[DSPACE_HOME]
|
59
|
+
# or from /dspcae if DSPACE_HOME is undefined
|
60
|
+
DSpace.load("/home/you/installs/dspace") # load from /home/you/installs/dspace
|
61
|
+
```
|
62
|
+
|
63
|
+
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:
|
64
|
+
```
|
65
|
+
java_import org.dspace.content.Item;
|
66
|
+
```
|
67
|
+
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:
|
68
|
+
```
|
69
|
+
DCommunity.all
|
70
|
+
DSpace.fromString('GROUP.name')
|
71
|
+
```
|
72
|
+
|
73
|
+
If you want to make changes you can 'login'
|
74
|
+
|
75
|
+
```
|
76
|
+
DSpace.login # login with ENV['USER']
|
77
|
+
DSpace.login ('netid') # login with given netid
|
78
|
+
```
|
79
|
+
|
80
|
+
Remember to call the commit method if you want to save changes
|
81
|
+
|
82
|
+
```
|
83
|
+
DSpace.commit
|
84
|
+
```
|
85
|
+
|
86
|
+
|
87
|
+
Find Dspace stuff:
|
88
|
+
|
89
|
+
```
|
90
|
+
DSpace.fromHandle ('xxxxx/yyy')
|
91
|
+
DSpace.fromString ('ITEM.124')
|
92
|
+
DSpace.fromString ('GROUP.Anonymous')
|
93
|
+
DSpace.fromString ('EPERSON.a_netid')
|
94
|
+
DCommunity.all
|
95
|
+
DGroup.find('group_name')
|
96
|
+
```
|
97
|
+
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.
|
98
|
+
|
99
|
+
The following prints a rudimentary community report:
|
100
|
+
```
|
101
|
+
DCommunity.all.each { |c| puts [c.getCollections.length, c.getHandle, c.getName].join("\t") }
|
102
|
+
```
|
103
|
+
|
104
|
+
Java objects can be converted to corresponding jrdspace objects, so that the additional functionality implemented by jrdspace classes becomes available.
|
105
|
+
For example all jrdspace objects implement the parents and policies method:
|
106
|
+
```
|
107
|
+
dso = DSpace.fromHandle('xxxxx/zzz')
|
108
|
+
DSpace.create(dso).parents
|
109
|
+
DSpace.create(dso).policies
|
110
|
+
```
|
111
|
+
|
112
|
+
|
113
|
+
# Thanks
|
114
|
+
Thank you https://github.com/kardeiz/dscriptor to set me on the path to jruby with dspace
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/idspace
ADDED
data/dspace.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dspace/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "jrdspace"
|
8
|
+
spec.version = DSpace::VERSION
|
9
|
+
spec.authors = ["Monika Mevenkamp"]
|
10
|
+
spec.email = ["monikam@princeton.edu"]
|
11
|
+
|
12
|
+
spec.summary = %q{Jruby classes that interact with the dspace-api Java classes - v5}
|
13
|
+
spec.description = %q{jrdspace enables scripting of the dspace-api Java objects in a DSpace installation; it includes an interactive console}
|
14
|
+
spec.homepage = "https://github.com/akinom/dspace-jruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "bin"
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency 'jar'
|
23
|
+
spec.add_dependency 'json'
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
end
|
data/lib/dspace.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
class DCollection
|
2
|
+
include DSO
|
3
|
+
|
4
|
+
def self.all()
|
5
|
+
java_import org.dspace.content.Collection;
|
6
|
+
return Collection.findAll(DSpace.context)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.findAll(name)
|
10
|
+
java_import org.dspace.content.Collection;
|
11
|
+
self.all.select do |c|
|
12
|
+
c.getName == name
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def report()
|
17
|
+
rpt = dso_report
|
18
|
+
rpt[:name] = @obj.getName();
|
19
|
+
group = @obj.getSubmitters();
|
20
|
+
rpt[:submitters] = DGroup.new(group).report if group
|
21
|
+
[1, 2, 3].each do |i|
|
22
|
+
group = @obj.getWorkflowGroup(i);
|
23
|
+
if (group) then
|
24
|
+
rpt["workflow_group_#{i}".to_sym] = DGroup.new(group).report;
|
25
|
+
end
|
26
|
+
end
|
27
|
+
return rpt;
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class DCommunity
|
2
|
+
include DSO
|
3
|
+
|
4
|
+
def self.all()
|
5
|
+
java_import org.dspace.content.Community;
|
6
|
+
return Community.findAll(DSpace.context)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.findAll(name)
|
10
|
+
java_import org.dspace.content.Community;
|
11
|
+
self.all.select do |c|
|
12
|
+
c.getName == name
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def report
|
17
|
+
rpt = dso_report
|
18
|
+
list = @obj.getSubcommunities.collect {|sc| DCommunity.new(sc).report }
|
19
|
+
rpt[:subcomunities] = list unless list.empty?
|
20
|
+
list = @obj.getCollections.collect {|sc| DCollection.new(sc).report }
|
21
|
+
rpt[:collections] = list unless list.empty?
|
22
|
+
return rpt;
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class DEperson
|
2
|
+
include DSO
|
3
|
+
|
4
|
+
def self.all()
|
5
|
+
java_import org.dspace.eperson.EPerson;
|
6
|
+
return EPerson.findAll(DSpace.context, 1)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.create(netid, first, last, email)
|
10
|
+
java_import org.dspace.eperson.EPerson;
|
11
|
+
raise "must give a netid value" unless netid
|
12
|
+
raise "must give a first and last name" unless (first and last)
|
13
|
+
p = EPerson.findByNetid(DSpace.context, netid)
|
14
|
+
raise "netid #{netid} already in use" unless p.nil?
|
15
|
+
|
16
|
+
@dso = EPerson.create(DSpace.context)
|
17
|
+
@dso.first_name = first;
|
18
|
+
@dso.last_name = last;
|
19
|
+
@dso.netid = netid;
|
20
|
+
@dso.email = email
|
21
|
+
@dso.canLogIn = true;
|
22
|
+
@dso.update;
|
23
|
+
puts "Created #{@dso}"
|
24
|
+
return @dso;
|
25
|
+
end
|
26
|
+
|
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
|
+
|
33
|
+
def groups
|
34
|
+
java_import org.dspace.eperson.Group;
|
35
|
+
return Group.allMemberGroups(DSpace.context, @obj);
|
36
|
+
end
|
37
|
+
|
38
|
+
def group_names
|
39
|
+
groups.collect { |g| g.getName}.sort
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
class DGroup
|
2
|
+
include DSO
|
3
|
+
|
4
|
+
ADMIN_ID = 1;
|
5
|
+
ANONYMOUS_ID = 0;
|
6
|
+
|
7
|
+
def self.all
|
8
|
+
java_import org.dspace.eperson.Group;
|
9
|
+
Group.findAll(DSpace.context, 1);
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.find(name_or_id)
|
13
|
+
java_import org.dspace.eperson.Group;
|
14
|
+
if (name_or_id.class == String)
|
15
|
+
return Group.findByName(DSpace.context, name_or_id);
|
16
|
+
else
|
17
|
+
return Group.find(DSpace.context, name_or_id)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.find_or_create(name)
|
22
|
+
raise "must give a name " unless name
|
23
|
+
group = self.find(name);
|
24
|
+
if (group.nil?) then
|
25
|
+
group = Group.create(DSpace.context);
|
26
|
+
group.setName(name)
|
27
|
+
group.update();
|
28
|
+
puts "Created #{group.toString()}"
|
29
|
+
else
|
30
|
+
puts "Exists #{group.toString()}"
|
31
|
+
end
|
32
|
+
return group;
|
33
|
+
end
|
34
|
+
|
35
|
+
def members
|
36
|
+
list = [];
|
37
|
+
@dso.getMembers.each do |m|
|
38
|
+
list << m;
|
39
|
+
end
|
40
|
+
@dso.getMemberGroups.each do |m|
|
41
|
+
list << m;
|
42
|
+
end
|
43
|
+
return list;
|
44
|
+
end
|
45
|
+
|
46
|
+
def addMember(addGrouNameOrNetid)
|
47
|
+
add = DGroup.find(addGrouNameOrNetid)
|
48
|
+
if (add.nil?) then
|
49
|
+
add = DEperson.find(addGrouNameOrNetid);
|
50
|
+
end
|
51
|
+
raise "no such netid or group #{addGrouNameOrNetid}" if add.nil?
|
52
|
+
@dso.addMember(add);
|
53
|
+
@dso.update
|
54
|
+
return @dso;
|
55
|
+
end
|
56
|
+
|
57
|
+
def report
|
58
|
+
rpt = dso_report
|
59
|
+
@obj.getMemberGroups.each do |m|
|
60
|
+
rpt[m.toString] = DGroup.new(m).report
|
61
|
+
end
|
62
|
+
list = @obj.getMembers()
|
63
|
+
rpt['epersons'] = list.collect { |p| DEperson.new(p).report } unless list.empty?
|
64
|
+
return rpt;
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
data/lib/dspace/ditem.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
class DItem
|
2
|
+
include DSO;
|
3
|
+
|
4
|
+
def self.iter
|
5
|
+
java_import org.dspace.content.Item;
|
6
|
+
Item.findAll(DSpace.context);
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.all
|
10
|
+
java_import org.dspace.content.Item;
|
11
|
+
list = []
|
12
|
+
stp = iter
|
13
|
+
while (i = stp.next)
|
14
|
+
list << i
|
15
|
+
end
|
16
|
+
return list
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.inside(restrict_to_dso)
|
20
|
+
java_import org.dspace.storage.rdbms.DatabaseManager
|
21
|
+
java_import org.dspace.storage.rdbms.TableRow
|
22
|
+
|
23
|
+
return [] if restrict_to_dso.nil?
|
24
|
+
return [restrict_to_dso] if restrict_to_dso.getType == DSpace::ITEM
|
25
|
+
return [] if restrict_to_dso.getType != DSpace::COLLECTION and restrict_to_dso.getType != DSpace::COMMUNITY
|
26
|
+
|
27
|
+
sql = "SELECT ITEM_ID FROM ";
|
28
|
+
if (restrict_to_dso.getType() == DSpace::COLLECTION) then
|
29
|
+
sql = sql + " Collection2Item CO WHERE CO.Collection_Id = #{restrict_to_dso.getID}"
|
30
|
+
else
|
31
|
+
# must be COMMUNITY
|
32
|
+
sql = sql + " Community2Item CO WHERE CO.Community_Id = #{restrict_to_dso.getID}"
|
33
|
+
end
|
34
|
+
puts sql;
|
35
|
+
|
36
|
+
tri = DatabaseManager.query(DSpace.context, sql)
|
37
|
+
dsos = [];
|
38
|
+
while (i = tri.next())
|
39
|
+
item = DSpace.find('ITEM', i.getIntColumn("item_id"))
|
40
|
+
dsos << item
|
41
|
+
end
|
42
|
+
tri.close
|
43
|
+
return dsos
|
44
|
+
end
|
45
|
+
|
46
|
+
def bitstreams(bundle = "ORIGINAL")
|
47
|
+
bundle = @obj.getBundles.select { |b| b.getName() == bundle }[0]
|
48
|
+
if (not bundle.nil?) then
|
49
|
+
return bundle.getBitstreams
|
50
|
+
end
|
51
|
+
return [];
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.install(collection, metadata_hash)
|
55
|
+
java_import org.dspace.content.InstallItem;
|
56
|
+
java_import org.dspace.content.WorkspaceItem;
|
57
|
+
java_import org.dspace.content.Item;
|
58
|
+
|
59
|
+
wi = WorkspaceItem.create(DSpace.context, collection, false)
|
60
|
+
item = wi.getItem
|
61
|
+
metadata_hash.each do |key,value|
|
62
|
+
(schema, element,qualifier) = key.split('.')
|
63
|
+
if (value.class == Array ) then
|
64
|
+
value.each do |val|
|
65
|
+
item.addMetadata(schema, element, qualifier, nil, val);
|
66
|
+
end
|
67
|
+
else
|
68
|
+
item.addMetadata(schema, element, qualifier, nil, value);
|
69
|
+
end
|
70
|
+
end
|
71
|
+
InstallItem.installItem(DSpace.context, wi);
|
72
|
+
return item;
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
data/lib/dspace/dso.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module DSO
|
4
|
+
|
5
|
+
def initialize(dobj)
|
6
|
+
raise "must pass non null obj" unless dobj
|
7
|
+
type = DSpace.const_get self.class.name[1..-1].upcase
|
8
|
+
@obj = dobj
|
9
|
+
raise "#{dobj} is not a #{type} object" unless @obj.getType == type
|
10
|
+
end
|
11
|
+
|
12
|
+
def dso
|
13
|
+
return @obj
|
14
|
+
end
|
15
|
+
|
16
|
+
def parents
|
17
|
+
moms = [];
|
18
|
+
p = @obj.getParentObject()
|
19
|
+
while p do
|
20
|
+
moms << p;
|
21
|
+
p = p.getParentObject();
|
22
|
+
end
|
23
|
+
return moms;
|
24
|
+
end
|
25
|
+
|
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
|
+
def policies()
|
44
|
+
java_import org.dspace.authorize.AuthorizeManager
|
45
|
+
pols = AuthorizeManager.getPolicies(DSpace.context, @obj)
|
46
|
+
pols.collect do |p|
|
47
|
+
pp = p.getEPerson
|
48
|
+
pg = p.getGroup
|
49
|
+
hsh = { :action => p.getAction()}
|
50
|
+
hsh[:person] = pp.getName if pp
|
51
|
+
hsh[:group] = pg.getName if pg
|
52
|
+
hsh
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
@@ -0,0 +1,187 @@
|
|
1
|
+
module DSpace
|
2
|
+
ROOT = File.expand_path('../..', __FILE__)
|
3
|
+
@@config = nil;
|
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
|
+
|
14
|
+
def self.objTypeId(type_str_or_int)
|
15
|
+
obj_typ = Constants.typeText.find_index type_str_or_int
|
16
|
+
if obj_typ.nil? then
|
17
|
+
obj_typ = Integer(type_str_or_int)
|
18
|
+
raise "no such object typ #{type_str_or_int}" unless Constants.typeText[obj_typ]
|
19
|
+
end
|
20
|
+
return obj_typ;
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.objTypeStr(type_str_or_int)
|
24
|
+
return type_str_or_int if Constants.typeText.find_index type_str_or_int
|
25
|
+
obj_typ_id = Integer(type_str_or_int)
|
26
|
+
raise "no such object type #{type_str_or_int}" unless Constants.typeText[obj_typ_id]
|
27
|
+
return Constants.typeText[obj_typ_id];
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.load(dspace_dir = nil)
|
31
|
+
if (@@config.nil?) then
|
32
|
+
@@config = Config.new(dspace_dir || ENV['DSPACE_HOME'] || "/dspace")
|
33
|
+
self.context # initialize context now
|
34
|
+
java_import org.dspace.handle.HandleManager;
|
35
|
+
java_import org.dspace.core.Constants
|
36
|
+
java_import org.dspace.content.DSpaceObject
|
37
|
+
return true
|
38
|
+
else
|
39
|
+
puts "Already loaded #{@@config.dspace_cfg}"
|
40
|
+
end
|
41
|
+
return false
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.context
|
45
|
+
raise "must call load to initialize" if @@config.nil?
|
46
|
+
raise "should never happen" if @@config.context.nil?
|
47
|
+
return @@config.context
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.login(netid)
|
51
|
+
self.context.setCurrentUser(DEperson.find(netid))
|
52
|
+
return nil
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.commit
|
56
|
+
self.context.commit
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.create(dso)
|
60
|
+
raise "dso must not be nil" if dso.nil?
|
61
|
+
klass = Object.const_get "D" + dso.class.name.gsub(/.*::/,'')
|
62
|
+
klass.send :new, dso
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.fromString(type_id_or_handle)
|
66
|
+
splits = type_id_or_handle.split('.')
|
67
|
+
if (2 == splits.length) then
|
68
|
+
self.find(splits[0], splits[1])
|
69
|
+
else
|
70
|
+
self.fromHandle(type_id_or_handle)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.fromHandle(handle)
|
75
|
+
return HandleManager.resolve_to_object(DSpace.context, handle);
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.find(type_str_or_int, identifier)
|
79
|
+
type_str = DSpace.objTypeStr(type_str_or_int)
|
80
|
+
type_id = DSpace.objTypeId(type_str)
|
81
|
+
int_id = identifier.to_i
|
82
|
+
obj = DSpaceObject.find(DSpace.context, type_id, int_id)
|
83
|
+
if obj.nil? and klass.methods.include? :find
|
84
|
+
klass = Object.const_get "D" + type_str.capitalize
|
85
|
+
obj = klass.send :find, identifier
|
86
|
+
end
|
87
|
+
return obj
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.findByMetadataValue(fully_qualified_metadata_field, value_or_nil, restrict_to_type)
|
91
|
+
java_import org.dspace.content.MetadataSchema
|
92
|
+
java_import org.dspace.content.MetadataField
|
93
|
+
java_import org.dspace.storage.rdbms.DatabaseManager
|
94
|
+
java_import org.dspace.storage.rdbms.TableRow
|
95
|
+
|
96
|
+
(schema, element, qualifier) = fully_qualified_metadata_field.split('.')
|
97
|
+
schm = MetadataSchema.find(DSpace.context, schema)
|
98
|
+
raise "no such metadata schema: #{schema}" if schm.nil?
|
99
|
+
field = MetadataField.find_by_element(DSpace.context, schm.getSchemaID, element, qualifier)
|
100
|
+
raise "no such metadata field #{fully_qualified_metadata_field}" if field.nil?
|
101
|
+
|
102
|
+
sql = "SELECT MV.resource_id, MV.resource_type_id FROM MetadataValue MV";
|
103
|
+
sql = sql + " where MV.metadata_field_id= #{field.getFieldID} "
|
104
|
+
if (not value_or_nil.nil?) then
|
105
|
+
sql = sql + " AND MV.text_value LIKE '#{value_or_nil}'"
|
106
|
+
end
|
107
|
+
if (restrict_to_type) then
|
108
|
+
sql = sql + " AND MV.resource_type_id = #{objTypeId(restrict_to_type)}"
|
109
|
+
end
|
110
|
+
|
111
|
+
tri = DatabaseManager.queryTable(DSpace.context, "MetadataValue", sql)
|
112
|
+
dsos = [];
|
113
|
+
while (iter = tri.next())
|
114
|
+
dsos << self.find(iter.getIntColumn("resource_type_id"), iter.getIntColumn("resource_id") )
|
115
|
+
end
|
116
|
+
tri.close
|
117
|
+
return dsos
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
def self.kernel
|
122
|
+
@@config.kernel;
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.help( klasses = [ DSpace, DCommunity, DCollection, DItem, DGroup])
|
126
|
+
klasses.each do |klass|
|
127
|
+
klass.singleton_methods.sort.each do |mn|
|
128
|
+
m = klass.method(mn)
|
129
|
+
plist = m.parameters.collect { |p|
|
130
|
+
if (p[0] == :req) then
|
131
|
+
"#{p[1].to_s}"
|
132
|
+
else
|
133
|
+
"[ #{p[1].to_s} ]"
|
134
|
+
end
|
135
|
+
}
|
136
|
+
puts "#{klass.name}.#{mn.to_s} (#{plist.join(", ")})"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
return nil
|
140
|
+
end
|
141
|
+
|
142
|
+
class Config
|
143
|
+
def initialize(dspace_home)
|
144
|
+
@dspace_dir = dspace_home
|
145
|
+
puts "Using #{@dspace_dir}"
|
146
|
+
@dspace_cfg = "#{@dspace_dir}/config/dspace.cfg";
|
147
|
+
@dspace_jars ||= Dir[File.join(@dspace_dir, 'lib/*.jar')]
|
148
|
+
@context = nil;
|
149
|
+
@kernel = nil;
|
150
|
+
end
|
151
|
+
|
152
|
+
def dspace_dir
|
153
|
+
@dspace_dir || raise('dspace_dir is undefined');
|
154
|
+
end
|
155
|
+
|
156
|
+
def dspace_cfg
|
157
|
+
@dspace_cfg || raise('dspace.cfg is undefined');
|
158
|
+
end
|
159
|
+
|
160
|
+
def context
|
161
|
+
init
|
162
|
+
return @context
|
163
|
+
end
|
164
|
+
|
165
|
+
def init
|
166
|
+
if @context.nil? then
|
167
|
+
puts "Loading jars"
|
168
|
+
@dspace_jars.each do |jar|
|
169
|
+
require jar
|
170
|
+
end
|
171
|
+
puts "Loading #{@dspace_cfg}"
|
172
|
+
org.dspace.core.ConfigurationManager.load_config(@dspace_cfg)
|
173
|
+
|
174
|
+
kernel_impl = org.dspace.servicemanager.DSpaceKernelInit.get_kernel(nil)
|
175
|
+
if not kernel_impl.is_running then
|
176
|
+
puts "Starting new DSpaceKernel"
|
177
|
+
kernel_impl.start(@dspace_dir)
|
178
|
+
end
|
179
|
+
@kernel = kernel_impl;
|
180
|
+
|
181
|
+
@context = org.dspace.core.Context.new()
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
187
|
+
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jrdspace
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Monika Mevenkamp
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jar
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: jrdspace enables scripting of the dspace-api Java objects in a DSpace
|
70
|
+
installation; it includes an interactive console
|
71
|
+
email:
|
72
|
+
- monikam@princeton.edu
|
73
|
+
executables:
|
74
|
+
- idspace
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- bin/idspace
|
82
|
+
- dspace.gemspec
|
83
|
+
- lib/dspace.rb
|
84
|
+
- lib/dspace/dbitstream.rb
|
85
|
+
- lib/dspace/dbundle.rb
|
86
|
+
- lib/dspace/dcollection.rb
|
87
|
+
- lib/dspace/dcommunity.rb
|
88
|
+
- lib/dspace/deperson.rb
|
89
|
+
- lib/dspace/dgroup.rb
|
90
|
+
- lib/dspace/ditem.rb
|
91
|
+
- lib/dspace/dso.rb
|
92
|
+
- lib/dspace/dspace.rb
|
93
|
+
- lib/dspace/version.rb
|
94
|
+
homepage: https://github.com/akinom/dspace-jruby
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.0.14
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: Jruby classes that interact with the dspace-api Java classes - v5
|
118
|
+
test_files: []
|