geoff-importer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rbenv-version +1 -0
- data/.rspec +6 -0
- data/.rvmrc +54 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/geoff-importer.gemspec +31 -0
- data/lib/geoff-importer.rb +7 -0
- data/lib/geoff-importer/importer.rb +105 -0
- data/lib/geoff-importer/version.rb +5 -0
- data/lib/jars/geoff-core.jar +0 -0
- data/lib/jars/jackson-core-2.0.2.jar +0 -0
- data/lib/jars/jackson-core-lgpl-1.8.9.jar +0 -0
- data/lib/jars/jackson-databind-2.0.2.jar +0 -0
- data/lib/jars/jackson-mapper-lgpl-1.8.9.jar +0 -0
- data/spec/integration/importer_spec.rb +29 -0
- data/spec/spec_helper.rb +7 -0
- metadata +168 -0
data/.gitignore
ADDED
data/.rbenv-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
jruby-1.7.0
|
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use jruby" > .rvmrc
|
9
|
+
environment_id="jruby-1.7.0@geoff"
|
10
|
+
export JRUBY_OPTS='-J-Xms1024m -J-Xmx1024m -J-XX:+UseConcMarkSweepGC -J-XX:MaxPermSize=512m -J-Djruby.thread.pooling=true'
|
11
|
+
|
12
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
13
|
+
# rvmrc_rvm_version="1.16.19 (stable)" # 1.10.1 seams as a safe start
|
14
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
15
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
16
|
+
# return 1
|
17
|
+
# }
|
18
|
+
|
19
|
+
# Uncomment following line if you want options to be set only for given project.
|
20
|
+
# PROJECT_JRUBY_OPTS=( --1.9 )
|
21
|
+
# The variable PROJECT_JRUBY_OPTS requires the following to be run in shell:
|
22
|
+
# chmod +x ${rvm_path}/hooks/after_use_jruby_opts
|
23
|
+
|
24
|
+
# First we attempt to load the desired environment directly from the environment
|
25
|
+
# file. This is very fast and efficient compared to running through the entire
|
26
|
+
# CLI and selector. If you want feedback on which environment was used then
|
27
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
28
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
29
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
30
|
+
then
|
31
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
32
|
+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
33
|
+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
34
|
+
else
|
35
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
36
|
+
rvm --create "$environment_id" || {
|
37
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
38
|
+
return 1
|
39
|
+
}
|
40
|
+
fi
|
41
|
+
|
42
|
+
# If you use bundler, this might be useful to you:
|
43
|
+
# if [[ -s Gemfile ]] && {
|
44
|
+
# ! builtin command -v bundle >/dev/null ||
|
45
|
+
# builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
|
46
|
+
# }
|
47
|
+
# then
|
48
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
49
|
+
# gem install bundler
|
50
|
+
# fi
|
51
|
+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
52
|
+
# then
|
53
|
+
# bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
|
54
|
+
# fi
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Volker Pacher
|
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,29 @@
|
|
1
|
+
# Geoff::Importer
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'geoff-importer'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install geoff-importer
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'geoff-importer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "geoff-importer"
|
8
|
+
gem.version = Geoff::Importer::VERSION
|
9
|
+
gem.authors = ["Volker Pacher"]
|
10
|
+
gem.email = ["volker.pacher@gmail.com"]
|
11
|
+
gem.description = %q{importing of geoff files into a neo4j instance}
|
12
|
+
gem.summary = %q{
|
13
|
+
imports a geoff file into a neo4j instance,
|
14
|
+
if a db location is given it will instantiate a graph db there
|
15
|
+
otherwise it will use the db instance passed in
|
16
|
+
}
|
17
|
+
gem.homepage = "https://github.com/shutl/geoff_importer"
|
18
|
+
|
19
|
+
gem.files = `git ls-files`.split($/)
|
20
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
21
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
22
|
+
gem.require_paths = ["lib"]
|
23
|
+
|
24
|
+
gem.add_dependency("neo4j-community", '>= 1.8.M05', '< 1.9')
|
25
|
+
|
26
|
+
gem.add_development_dependency 'jruby-openssl'
|
27
|
+
gem.add_development_dependency 'rake'
|
28
|
+
gem.add_development_dependency 'rspec', '~>2.11.0'
|
29
|
+
gem.add_development_dependency 'ruby-debug'
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
class Geoff
|
2
|
+
class Error < StandardError ; end
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def log(message)
|
6
|
+
$stdout.puts message unless silent?
|
7
|
+
end
|
8
|
+
|
9
|
+
def silent?
|
10
|
+
false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module Importer
|
15
|
+
class LockedDatabase < Geoff::Error ; end
|
16
|
+
class MissingIndexedProperty < Geoff::Error ; end
|
17
|
+
class InvalidRules < Geoff::Error ; end
|
18
|
+
|
19
|
+
Subgraph = org.neo4j.geoff.Subgraph
|
20
|
+
EmbeddedDB = Java::OrgNeo4jKernel::EmbeddedGraphDatabase
|
21
|
+
|
22
|
+
class << self
|
23
|
+
def import geoff, db, node_map = {}
|
24
|
+
set_geoff geoff
|
25
|
+
set_db db
|
26
|
+
|
27
|
+
import_geoff node_map
|
28
|
+
shutdown if db.is_a? String
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
def set_db db
|
33
|
+
if db.is_a?(String)
|
34
|
+
debugger
|
35
|
+
raise Geoff::Importer::LockedDatabase.new('database is running') if locked?(db)
|
36
|
+
start_db(db)
|
37
|
+
else
|
38
|
+
@graph_db = db
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def set_geoff geoff
|
43
|
+
@geoff = if geoff.is_a? String
|
44
|
+
geoff.split "\n"
|
45
|
+
else
|
46
|
+
geoff.to_geoff
|
47
|
+
end
|
48
|
+
raise Geoff::Importer::InvalidRules.new('Invalid rules') unless validate_rules(@geoff)
|
49
|
+
end
|
50
|
+
|
51
|
+
def locked?(db)
|
52
|
+
Geoff.log 'check if database is running'
|
53
|
+
lock_file = File.join(db, 'neostore')
|
54
|
+
return false unless File.exist?(lock_file)
|
55
|
+
rfile = java.io.RandomAccessFile.new(lock_file, 'rw')
|
56
|
+
begin
|
57
|
+
lock = rfile.getChannel.tryLock
|
58
|
+
lock.release if lock
|
59
|
+
return lock == nil
|
60
|
+
rescue Exception => e
|
61
|
+
return false
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def start_db(db_path)
|
66
|
+
Geoff.log 'starting database'
|
67
|
+
@graph_db = EmbeddedDB.new(db_path)
|
68
|
+
end
|
69
|
+
|
70
|
+
def shutdown
|
71
|
+
Geoff.log 'shutdown db'
|
72
|
+
@graph_db.shutdown
|
73
|
+
end
|
74
|
+
|
75
|
+
def import_geoff node_map
|
76
|
+
node_map = map_root_node if node_map.empty?
|
77
|
+
Geoff.log 'importing geoff'
|
78
|
+
sub_graph = Subgraph.new(@geoff)
|
79
|
+
org.neo4j.geoff.Geoff.mergeIntoNeo4j(sub_graph, @graph_db, node_map );
|
80
|
+
end
|
81
|
+
|
82
|
+
def map_root_node
|
83
|
+
Geoff.log 'creating node_map'
|
84
|
+
{"ROOT" => @graph_db.reference_node}
|
85
|
+
end
|
86
|
+
|
87
|
+
def validate_rules(rules)
|
88
|
+
@invalid = Array(rules).map do |r|
|
89
|
+
validate_rule(r)
|
90
|
+
end.compact
|
91
|
+
|
92
|
+
@invalid.each { |r, message| Geoff.log "Rule '#{r}' is invalid: #{message}" }
|
93
|
+
@invalid.empty?
|
94
|
+
end
|
95
|
+
|
96
|
+
def validate_rule(rule)
|
97
|
+
Subgraph.new(Array(rule))
|
98
|
+
nil
|
99
|
+
rescue Exception => e
|
100
|
+
return [rule, e.message]
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path('spec/spec_helper')
|
2
|
+
require 'geoff-importer'
|
3
|
+
|
4
|
+
describe Geoff::Importer do
|
5
|
+
let(:db_path) { './db/test'}
|
6
|
+
let(:geoff_string) { '(A) {"name": "Alice"}' }
|
7
|
+
|
8
|
+
|
9
|
+
context 'running db' do
|
10
|
+
it 'raises error if db is passed in as string' do
|
11
|
+
db = Java::OrgNeo4jKernel::EmbeddedGraphDatabase.new(db_path)
|
12
|
+
# debugger
|
13
|
+
expect { Geoff::Importer.import(geoff_string, db_path) }.to raise_error
|
14
|
+
db.shutdown
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'inserts geoff into the db when passed with db instance' do
|
18
|
+
db = Java::OrgNeo4jKernel::EmbeddedGraphDatabase.new(db_path)
|
19
|
+
Geoff::Importer.import(geoff_string, db)
|
20
|
+
db.shutdown
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'non-running db' do
|
25
|
+
it 'inserts geoff into the db' do
|
26
|
+
Geoff::Importer.import(geoff_string, db_path)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: geoff-importer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Volker Pacher
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: neo4j-community
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ! '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 1.8.M05
|
21
|
+
- - !binary |-
|
22
|
+
PA==
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '1.9'
|
25
|
+
none: false
|
26
|
+
requirement: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 1.8.M05
|
31
|
+
- - !binary |-
|
32
|
+
PA==
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.9'
|
35
|
+
none: false
|
36
|
+
prerelease: false
|
37
|
+
type: :runtime
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: jruby-openssl
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: !binary |-
|
45
|
+
MA==
|
46
|
+
none: false
|
47
|
+
requirement: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: !binary |-
|
52
|
+
MA==
|
53
|
+
none: false
|
54
|
+
prerelease: false
|
55
|
+
type: :development
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: !binary |-
|
63
|
+
MA==
|
64
|
+
none: false
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: !binary |-
|
70
|
+
MA==
|
71
|
+
none: false
|
72
|
+
prerelease: false
|
73
|
+
type: :development
|
74
|
+
- !ruby/object:Gem::Dependency
|
75
|
+
name: rspec
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ~>
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 2.11.0
|
81
|
+
none: false
|
82
|
+
requirement: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ~>
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 2.11.0
|
87
|
+
none: false
|
88
|
+
prerelease: false
|
89
|
+
type: :development
|
90
|
+
- !ruby/object:Gem::Dependency
|
91
|
+
name: ruby-debug
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: !binary |-
|
97
|
+
MA==
|
98
|
+
none: false
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: !binary |-
|
104
|
+
MA==
|
105
|
+
none: false
|
106
|
+
prerelease: false
|
107
|
+
type: :development
|
108
|
+
description: importing of geoff files into a neo4j instance
|
109
|
+
email:
|
110
|
+
- volker.pacher@gmail.com
|
111
|
+
executables: []
|
112
|
+
extensions: []
|
113
|
+
extra_rdoc_files: []
|
114
|
+
files:
|
115
|
+
- .gitignore
|
116
|
+
- .rbenv-version
|
117
|
+
- .rspec
|
118
|
+
- .rvmrc
|
119
|
+
- Gemfile
|
120
|
+
- LICENSE.txt
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- geoff-importer.gemspec
|
124
|
+
- lib/geoff-importer.rb
|
125
|
+
- lib/geoff-importer/importer.rb
|
126
|
+
- lib/geoff-importer/version.rb
|
127
|
+
- lib/jars/geoff-core.jar
|
128
|
+
- lib/jars/jackson-core-2.0.2.jar
|
129
|
+
- lib/jars/jackson-core-lgpl-1.8.9.jar
|
130
|
+
- lib/jars/jackson-databind-2.0.2.jar
|
131
|
+
- lib/jars/jackson-mapper-lgpl-1.8.9.jar
|
132
|
+
- spec/integration/importer_spec.rb
|
133
|
+
- spec/spec_helper.rb
|
134
|
+
homepage: https://github.com/shutl/geoff_importer
|
135
|
+
licenses: []
|
136
|
+
post_install_message:
|
137
|
+
rdoc_options: []
|
138
|
+
require_paths:
|
139
|
+
- lib
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ! '>='
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
segments:
|
145
|
+
- 0
|
146
|
+
version: !binary |-
|
147
|
+
MA==
|
148
|
+
hash: 2
|
149
|
+
none: false
|
150
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ! '>='
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
segments:
|
155
|
+
- 0
|
156
|
+
version: !binary |-
|
157
|
+
MA==
|
158
|
+
hash: 2
|
159
|
+
none: false
|
160
|
+
requirements: []
|
161
|
+
rubyforge_project:
|
162
|
+
rubygems_version: 1.8.24
|
163
|
+
signing_key:
|
164
|
+
specification_version: 3
|
165
|
+
summary: imports a geoff file into a neo4j instance, if a db location is given it will instantiate a graph db there otherwise it will use the db instance passed in
|
166
|
+
test_files:
|
167
|
+
- spec/integration/importer_spec.rb
|
168
|
+
- spec/spec_helper.rb
|