neo4j-core 3.1.1 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +7 -12
- data/README.md +7 -7
- data/lib/neo4j-core.rb +3 -2
- data/lib/neo4j-core/active_entity.rb +8 -10
- data/lib/neo4j-core/cypher_translator.rb +61 -59
- data/lib/neo4j-core/hash_with_indifferent_access.rb +31 -22
- data/lib/neo4j-core/helpers.rb +15 -17
- data/lib/neo4j-core/label.rb +7 -6
- data/lib/neo4j-core/query.rb +271 -268
- data/lib/neo4j-core/query_clauses.rb +371 -355
- data/lib/neo4j-core/query_find_in_batches.rb +26 -26
- data/lib/neo4j-core/version.rb +1 -1
- data/lib/neo4j-embedded.rb +2 -2
- data/lib/neo4j-embedded/cypher_response.rb +40 -41
- data/lib/neo4j-embedded/embedded_database.rb +21 -22
- data/lib/neo4j-embedded/embedded_ha_session.rb +13 -11
- data/lib/neo4j-embedded/embedded_impermanent_session.rb +9 -8
- data/lib/neo4j-embedded/embedded_label.rb +64 -70
- data/lib/neo4j-embedded/embedded_node.rb +68 -73
- data/lib/neo4j-embedded/embedded_relationship.rb +6 -13
- data/lib/neo4j-embedded/embedded_session.rb +128 -132
- data/lib/neo4j-embedded/embedded_transaction.rb +34 -33
- data/lib/neo4j-embedded/property.rb +84 -77
- data/lib/neo4j-embedded/to_java.rb +24 -23
- data/lib/neo4j-server.rb +1 -1
- data/lib/neo4j-server/cypher_authentication.rb +105 -103
- data/lib/neo4j-server/cypher_label.rb +25 -23
- data/lib/neo4j-server/cypher_node.rb +180 -177
- data/lib/neo4j-server/cypher_node_uncommited.rb +11 -9
- data/lib/neo4j-server/cypher_relationship.rb +101 -102
- data/lib/neo4j-server/cypher_response.rb +171 -170
- data/lib/neo4j-server/cypher_session.rb +209 -205
- data/lib/neo4j-server/cypher_transaction.rb +66 -48
- data/lib/neo4j-server/resource.rb +17 -22
- data/lib/neo4j/entity_equality.rb +3 -4
- data/lib/neo4j/label.rb +13 -16
- data/lib/neo4j/node.rb +30 -34
- data/lib/neo4j/property_container.rb +3 -3
- data/lib/neo4j/property_validator.rb +4 -5
- data/lib/neo4j/relationship.rb +17 -22
- data/lib/neo4j/session.rb +19 -21
- data/lib/neo4j/tasks/config_server.rb +2 -3
- data/lib/neo4j/tasks/neo4j_server.rake +82 -74
- data/lib/neo4j/transaction.rb +23 -22
- data/neo4j-core.gemspec +21 -16
- metadata +72 -2
@@ -9,14 +9,14 @@ module Neo4j
|
|
9
9
|
|
10
10
|
|
11
11
|
# Sets the neo4j property
|
12
|
-
def []=(key,value)
|
12
|
+
def []=(key, value)
|
13
13
|
validate_property(value)
|
14
14
|
|
15
15
|
if value.nil?
|
16
16
|
remove_property(key)
|
17
17
|
else
|
18
|
-
set_property(key,value)
|
18
|
+
set_property(key, value)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
|
-
end
|
22
|
+
end
|
@@ -2,7 +2,6 @@ module Neo4j
|
|
2
2
|
module PropertyValidator
|
3
3
|
require 'set'
|
4
4
|
class InvalidPropertyException < Exception
|
5
|
-
|
6
5
|
end
|
7
6
|
|
8
7
|
# the valid values on a property, and arrays of those.
|
@@ -15,9 +14,9 @@ module Neo4j
|
|
15
14
|
end
|
16
15
|
|
17
16
|
def validate_property(value)
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
return if valid_property?(value)
|
18
|
+
|
19
|
+
fail Neo4j::PropertyValidator::InvalidPropertyException, "Not valid Neo4j Property value #{value.class}, valid: #{Neo4j::Node::VALID_PROPERTY_VALUE_CLASSES.to_a.join(', ')}"
|
21
20
|
end
|
22
21
|
end
|
23
|
-
end
|
22
|
+
end
|
data/lib/neo4j/relationship.rb
CHANGED
@@ -9,7 +9,6 @@ module Neo4j
|
|
9
9
|
# Furthermore, Neo4j guarantees that a relationship is never "hanging freely,"
|
10
10
|
# i.e. start_node, end_node and other_node are guaranteed to always return valid, non-nil nodes.
|
11
11
|
class Relationship
|
12
|
-
|
13
12
|
# A module that allows plugins to register wrappers around Neo4j::Node objects
|
14
13
|
module Wrapper
|
15
14
|
# Used by Neo4j::NodeMixin to wrap nodes
|
@@ -20,7 +19,6 @@ module Neo4j
|
|
20
19
|
def neo4j_obj
|
21
20
|
self
|
22
21
|
end
|
23
|
-
|
24
22
|
end
|
25
23
|
|
26
24
|
include PropertyContainer
|
@@ -28,39 +26,39 @@ module Neo4j
|
|
28
26
|
include Wrapper
|
29
27
|
|
30
28
|
# @return [Hash<Symbol,Object>] all properties of the relationship
|
31
|
-
def props
|
32
|
-
|
29
|
+
def props
|
30
|
+
fail 'not implemented'
|
33
31
|
end
|
34
32
|
|
35
33
|
# replace all properties with new properties
|
36
34
|
# @param [Hash] properties a hash of properties the relationship should have
|
37
35
|
def props=(properties)
|
38
|
-
|
36
|
+
fail 'not implemented'
|
39
37
|
end
|
40
38
|
|
41
39
|
# Updates the properties, keeps old properties
|
42
40
|
# @param [Hash<Symbol,Object>] properties hash of properties that should be updated on the relationship
|
43
41
|
def update_props(properties)
|
44
|
-
|
42
|
+
fail 'not implemented'
|
45
43
|
end
|
46
44
|
|
47
45
|
# Directly remove the property on the relationship (low level method, may need transaction)
|
48
46
|
def remove_property(key)
|
49
|
-
|
47
|
+
fail 'not implemented'
|
50
48
|
end
|
51
49
|
|
52
50
|
# Directly set the property on the relationship (low level method, may need transaction)
|
53
51
|
# @param [Hash, String] key
|
54
52
|
# @param value see Neo4j::PropertyValidator::VALID_PROPERTY_VALUE_CLASSES for valid values
|
55
53
|
def set_property(key, value)
|
56
|
-
|
54
|
+
fail 'not implemented'
|
57
55
|
end
|
58
56
|
|
59
57
|
# Directly get the property on the relationship (low level method, may need transaction)
|
60
58
|
# @param [Hash, String] key
|
61
59
|
# @return the value of the key
|
62
60
|
def get_property(key, value)
|
63
|
-
|
61
|
+
fail 'not implemented'
|
64
62
|
end
|
65
63
|
|
66
64
|
# Returns the start node of this relationship.
|
@@ -72,7 +70,7 @@ module Neo4j
|
|
72
70
|
# Same as #start_node but does not wrap the node
|
73
71
|
# @return [Neo4j::Node]
|
74
72
|
def _start_node
|
75
|
-
|
73
|
+
fail 'not implemented'
|
76
74
|
end
|
77
75
|
|
78
76
|
# Returns the end node of this relationship.
|
@@ -84,24 +82,24 @@ module Neo4j
|
|
84
82
|
# Same as #end_node but does not wrap the node
|
85
83
|
# @return [Neo4j::Node]
|
86
84
|
def _end_node
|
87
|
-
|
85
|
+
fail 'not implemented'
|
88
86
|
end
|
89
87
|
|
90
88
|
# @abstract
|
91
89
|
def del
|
92
|
-
|
90
|
+
fail 'not implemented'
|
93
91
|
end
|
94
92
|
|
95
93
|
# The unique neo4j id
|
96
94
|
# @abstract
|
97
95
|
def neo_id
|
98
|
-
|
96
|
+
fail 'not implemented'
|
99
97
|
end
|
100
98
|
|
101
99
|
# @return [true, false] if the relationship exists
|
102
100
|
# @abstract
|
103
101
|
def exist?
|
104
|
-
|
102
|
+
fail 'not implemented'
|
105
103
|
end
|
106
104
|
|
107
105
|
# Returns the relationship name
|
@@ -112,7 +110,7 @@ module Neo4j
|
|
112
110
|
# a.rels.first.rel_type # => :friends
|
113
111
|
# @return [Symbol] the type of the relationship
|
114
112
|
def rel_type
|
115
|
-
|
113
|
+
fail 'not implemented'
|
116
114
|
end
|
117
115
|
|
118
116
|
# A convenience operation that, given a node that is attached to this relationship, returns the other node.
|
@@ -134,14 +132,12 @@ module Neo4j
|
|
134
132
|
|
135
133
|
# Same as #other_node but can return a none wrapped node
|
136
134
|
def _other_node(node)
|
137
|
-
s = _start_node
|
138
|
-
e = _end_node
|
139
135
|
if node == _start_node
|
140
|
-
|
136
|
+
_end_node
|
141
137
|
elsif node == _end_node
|
142
|
-
|
138
|
+
_start_node
|
143
139
|
else
|
144
|
-
|
140
|
+
fail "Node #{node.inspect} is neither start nor end node"
|
145
141
|
end
|
146
142
|
end
|
147
143
|
|
@@ -159,7 +155,6 @@ module Neo4j
|
|
159
155
|
def _load(neo_id, session = Neo4j::Session.current)
|
160
156
|
session.load_relationship(neo_id)
|
161
157
|
end
|
162
|
-
|
163
158
|
end
|
164
159
|
end
|
165
|
-
end
|
160
|
+
end
|
data/lib/neo4j/session.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Neo4j
|
2
2
|
class Session
|
3
|
-
|
4
3
|
@@current_session = nil
|
5
4
|
@@all_sessions = {}
|
6
5
|
@@factories = {}
|
@@ -13,24 +12,24 @@ module Neo4j
|
|
13
12
|
# Only for embedded database
|
14
13
|
# @abstract
|
15
14
|
def start
|
16
|
-
|
15
|
+
fail 'not impl.'
|
17
16
|
end
|
18
17
|
|
19
18
|
# Only for embedded database
|
20
19
|
# @abstract
|
21
20
|
def shutdown
|
22
|
-
|
21
|
+
fail 'not impl.'
|
23
22
|
end
|
24
23
|
|
25
24
|
# Only for embedded database
|
26
25
|
# @abstract
|
27
26
|
def running
|
28
|
-
|
27
|
+
fail 'not impl.'
|
29
28
|
end
|
30
29
|
|
31
30
|
# @return [:embedded_db | :server_db]
|
32
31
|
def db_type
|
33
|
-
|
32
|
+
fail 'not impl.'
|
34
33
|
end
|
35
34
|
|
36
35
|
def auto_commit?
|
@@ -39,7 +38,7 @@ module Neo4j
|
|
39
38
|
|
40
39
|
# @abstract
|
41
40
|
def begin_tx
|
42
|
-
|
41
|
+
fail 'not impl.'
|
43
42
|
end
|
44
43
|
|
45
44
|
class CypherError < StandardError
|
@@ -67,14 +66,14 @@ module Neo4j
|
|
67
66
|
# @see http://docs.neo4j.org/chunked/milestone/cypher-query-lang.html The Cypher Query Language Documentation
|
68
67
|
#
|
69
68
|
def query(options = {})
|
70
|
-
|
69
|
+
fail 'not implemented, abstract'
|
71
70
|
end
|
72
71
|
|
73
72
|
# Same as #query but does not accept an DSL and returns the raw result from the database.
|
74
73
|
# Notice, it might return different values depending on which database is used, embedded or server.
|
75
74
|
# @abstract
|
76
75
|
def _query(*params)
|
77
|
-
|
76
|
+
fail 'not implemented'
|
78
77
|
end
|
79
78
|
|
80
79
|
class << self
|
@@ -95,19 +94,19 @@ module Neo4j
|
|
95
94
|
#
|
96
95
|
# @see also Neo4j::Server::CypherSession#open for :server_db params
|
97
96
|
# @param db_type the type of database, e.g. :embedded_db, or :server_db
|
98
|
-
def open(db_type
|
97
|
+
def open(db_type = :server_db, *params)
|
99
98
|
register(create_session(db_type, params))
|
100
99
|
end
|
101
100
|
|
102
101
|
def open_named(db_type, name, default = nil, *params)
|
103
|
-
|
102
|
+
fail 'Multiple sessions is currently only supported for Neo4j Server connections.' unless db_type == :server_db
|
104
103
|
register(create_session(db_type, params), name, default)
|
105
104
|
end
|
106
105
|
|
107
106
|
# @private
|
108
107
|
def create_session(db_type, params = {})
|
109
|
-
unless
|
110
|
-
|
108
|
+
unless @@factories[db_type]
|
109
|
+
fail "Can't connect to database '#{db_type}', available #{@@factories.keys.join(',')}"
|
111
110
|
end
|
112
111
|
@@factories[db_type].call(*params)
|
113
112
|
end
|
@@ -119,7 +118,7 @@ module Neo4j
|
|
119
118
|
|
120
119
|
# Returns the current session or raise an exception if no session is available
|
121
120
|
def current!
|
122
|
-
|
121
|
+
fail 'No session, please create a session first with Neo4j::Session.open(:server_db) or :embedded_db' unless current
|
123
122
|
current
|
124
123
|
end
|
125
124
|
|
@@ -130,7 +129,7 @@ module Neo4j
|
|
130
129
|
|
131
130
|
# Returns a session with given name or else raise an exception
|
132
131
|
def named(name)
|
133
|
-
@@all_sessions[name] ||
|
132
|
+
@@all_sessions[name] || fail("No session named #{name}.")
|
134
133
|
end
|
135
134
|
|
136
135
|
# Sets the session to be used as default
|
@@ -142,9 +141,8 @@ module Neo4j
|
|
142
141
|
# Registers a callback which will be called immediately if session is already available,
|
143
142
|
# or called when it later becomes available.
|
144
143
|
def on_session_available(&callback)
|
145
|
-
if
|
146
|
-
|
147
|
-
end
|
144
|
+
callback.call(Neo4j::Session.current) if Neo4j::Session.current
|
145
|
+
|
148
146
|
add_listener do |event, data|
|
149
147
|
callback.call(data) if event == :session_available
|
150
148
|
end
|
@@ -158,12 +156,12 @@ module Neo4j
|
|
158
156
|
end
|
159
157
|
|
160
158
|
|
161
|
-
"#{gem}
|
159
|
+
"#{gem}-gem/#{version} (https://github.com/neo4jrb/#{gem})"
|
162
160
|
end
|
163
161
|
|
164
162
|
# @private
|
165
163
|
def add_listener(&listener)
|
166
|
-
|
164
|
+
_listeners << listener
|
167
165
|
end
|
168
166
|
|
169
167
|
# @private
|
@@ -174,7 +172,7 @@ module Neo4j
|
|
174
172
|
|
175
173
|
# @private
|
176
174
|
def _notify_listeners(event, data)
|
177
|
-
_listeners.each {|li| li.call(event, data)}
|
175
|
+
_listeners.each { |li| li.call(event, data) }
|
178
176
|
end
|
179
177
|
|
180
178
|
# @private
|
@@ -194,7 +192,7 @@ module Neo4j
|
|
194
192
|
end
|
195
193
|
|
196
194
|
def inspect
|
197
|
-
|
195
|
+
"Neo4j::Session available: #{@@factories && @@factories.keys}"
|
198
196
|
end
|
199
197
|
|
200
198
|
# @private
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Neo4j
|
2
2
|
module Tasks
|
3
3
|
module ConfigServer
|
4
|
-
|
5
4
|
def config(source_text, port)
|
6
5
|
s = set_property(source_text, 'org.neo4j.server.webserver.https.enabled', 'false')
|
7
6
|
set_property(s, 'org.neo4j.server.webserver.port', port)
|
@@ -24,11 +23,11 @@ module Neo4j
|
|
24
23
|
# @return [Hash] The response from the server indicating success/failure.
|
25
24
|
def change_password(target_address, old_password, new_password)
|
26
25
|
uri = URI.parse("#{target_address}/user/neo4j/password")
|
27
|
-
response = Net::HTTP.post_form(uri,
|
26
|
+
response = Net::HTTP.post_form(uri, 'password' => old_password, 'new_password' => new_password)
|
28
27
|
JSON.parse(response.body)
|
29
28
|
end
|
30
29
|
|
31
30
|
extend self
|
32
31
|
end
|
33
32
|
end
|
34
|
-
end
|
33
|
+
end
|
@@ -4,27 +4,27 @@ require 'os'
|
|
4
4
|
require 'httparty'
|
5
5
|
require 'zip'
|
6
6
|
require 'httparty'
|
7
|
-
require File.expand_path(
|
7
|
+
require File.expand_path('../config_server', __FILE__)
|
8
8
|
|
9
9
|
namespace :neo4j do
|
10
10
|
def download_neo4j(file)
|
11
11
|
file_name, download_url = if OS::Underlying.windows?
|
12
|
-
[
|
12
|
+
['neo4j.zip', "http://dist.neo4j.org/neo4j-#{file}-windows.zip"]
|
13
13
|
else
|
14
|
-
[
|
14
|
+
['neo4j-unix.tar.gz', "http://dist.neo4j.org/neo4j-#{file}-unix.tar.gz"]
|
15
15
|
end
|
16
16
|
|
17
17
|
unless File.exist?(file_name)
|
18
18
|
# check if file is available
|
19
19
|
status = HTTParty.head(download_url).code
|
20
|
-
|
20
|
+
fail "#{file} is not available to download, try a different version" if status < 200 || status >= 300
|
21
21
|
df = File.open(file_name, 'wb')
|
22
22
|
success = false
|
23
23
|
begin
|
24
24
|
df << HTTParty.get(download_url)
|
25
25
|
success = true
|
26
26
|
ensure
|
27
|
-
df.close
|
27
|
+
df.close
|
28
28
|
File.delete(file_name) unless success
|
29
29
|
end
|
30
30
|
end
|
@@ -56,7 +56,7 @@ namespace :neo4j do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def install_location(args)
|
59
|
-
FileUtils.mkdir_p(
|
59
|
+
FileUtils.mkdir_p('db/neo4j')
|
60
60
|
"db/neo4j/#{get_environment(args)}"
|
61
61
|
end
|
62
62
|
|
@@ -64,7 +64,21 @@ namespace :neo4j do
|
|
64
64
|
"#{install_location(args)}/conf/neo4j-server.properties"
|
65
65
|
end
|
66
66
|
|
67
|
-
|
67
|
+
def start_server(command, args)
|
68
|
+
puts "Starting Neo4j #{get_environment(args)}..."
|
69
|
+
if OS::Underlying.windows?
|
70
|
+
if `reg query "HKU\\S-1-5-19"`.size > 0
|
71
|
+
`#{install_location(args)}/bin/Neo4j.bat #{command}` # start service
|
72
|
+
else
|
73
|
+
puts 'Starting Neo4j directly, not as a service.'
|
74
|
+
`#{install_location(args)}/bin/Neo4j.bat`
|
75
|
+
end
|
76
|
+
else
|
77
|
+
`#{install_location(args)}/bin/neo4j #{command}`
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
desc 'Install Neo4j with auth disabled in v2.2+, example neo4j:install[community-2.1.3,development]'
|
68
82
|
task :install, :edition, :environment do |_, args|
|
69
83
|
file = args[:edition]
|
70
84
|
environment = get_environment(args)
|
@@ -77,110 +91,104 @@ namespace :neo4j do
|
|
77
91
|
unless File.exist?(install_location(args))
|
78
92
|
Zip::ZipFile.open(downloaded_file) do |zip_file|
|
79
93
|
zip_file.each do |f|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
94
|
+
f_path = File.join('.', f.name)
|
95
|
+
FileUtils.mkdir_p(File.dirname(f_path))
|
96
|
+
begin
|
97
|
+
zip_file.extract(f, f_path) unless File.exist?(f_path)
|
98
|
+
rescue
|
99
|
+
puts "#{f.name} failed to extract."
|
100
|
+
end
|
87
101
|
end
|
88
102
|
end
|
89
103
|
FileUtils.mv "neo4j-#{file}", install_location(args)
|
90
104
|
FileUtils.rm downloaded_file
|
91
|
-
|
105
|
+
end
|
92
106
|
|
93
107
|
# Install if running with Admin Privileges
|
94
|
-
if
|
95
|
-
|
96
|
-
puts
|
108
|
+
if `reg query "HKU\\S-1-5-19"`.size > 0
|
109
|
+
`"#{install_location(args)}/bin/neo4j install"`
|
110
|
+
puts 'Neo4j Installed as a service.'
|
97
111
|
end
|
98
112
|
|
99
113
|
else
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
puts
|
114
|
+
`tar -xvf #{downloaded_file}`
|
115
|
+
`mv neo4j-#{file} #{install_location(args)}`
|
116
|
+
`rm #{downloaded_file}`
|
117
|
+
puts 'Neo4j Installed in to neo4j directory.'
|
104
118
|
end
|
105
119
|
rake_auth_toggle(args, :disable) unless /-2\.0|1\.[0-9]/.match(args[:edition])
|
106
120
|
puts "Type 'rake neo4j:start' or 'rake neo4j:start[ENVIRONMENT]' to start it\nType 'neo4j:config[ENVIRONMENT,PORT]' for changing server port, (default 7474)"
|
107
121
|
end
|
108
122
|
|
109
|
-
desc
|
123
|
+
desc 'Start the Neo4j Server'
|
110
124
|
task :start, :environment do |_, args|
|
111
|
-
|
112
|
-
if OS::Underlying.windows?
|
113
|
-
if %x[reg query "HKU\\S-1-5-19"].size > 0
|
114
|
-
%x[#{install_location(args)}/bin/Neo4j.bat start] #start service
|
115
|
-
else
|
116
|
-
puts "Starting Neo4j directly, not as a service."
|
117
|
-
%x[#{install_location(args)}/bin/Neo4j.bat]
|
118
|
-
end
|
119
|
-
else
|
120
|
-
%x[#{install_location(args)}/bin/neo4j start]
|
121
|
-
end
|
125
|
+
start_server('start', args)
|
122
126
|
end
|
123
127
|
|
124
|
-
desc
|
125
|
-
task :
|
128
|
+
desc 'Start the Neo4j Server asynchronously'
|
129
|
+
task :start_no_wait, :environment do |_, args|
|
130
|
+
start_server('start-no-wait', args)
|
131
|
+
end
|
126
132
|
|
133
|
+
desc 'Configure Server, e.g. rake neo4j:config[development,8888]'
|
134
|
+
task :config, :environment, :port do |_, args|
|
127
135
|
port = args[:port]
|
128
|
-
|
136
|
+
fail 'no port given' unless port
|
129
137
|
puts "Config Neo4j #{get_environment(args)} for port #{port}"
|
130
138
|
location = config_location(args)
|
131
139
|
text = File.read(location)
|
132
140
|
replace = Neo4j::Tasks::ConfigServer.config(text, port)
|
133
|
-
File.open(location,
|
141
|
+
File.open(location, 'w') { |file| file.puts replace }
|
134
142
|
end
|
135
143
|
|
136
|
-
desc
|
144
|
+
desc 'Stop the Neo4j Server'
|
137
145
|
task :stop, :environment do |_, args|
|
138
146
|
puts "Stopping Neo4j #{get_environment(args)}..."
|
139
147
|
if OS::Underlying.windows?
|
140
|
-
if
|
141
|
-
|
148
|
+
if `reg query "HKU\\S-1-5-19"`.size > 0
|
149
|
+
`#{install_location(args)}/bin/Neo4j.bat stop` # stop service
|
142
150
|
else
|
143
|
-
puts
|
151
|
+
puts 'You do not have administrative rights to stop the Neo4j Service'
|
144
152
|
end
|
145
153
|
else
|
146
|
-
|
154
|
+
`#{install_location(args)}/bin/neo4j stop`
|
147
155
|
end
|
148
156
|
end
|
149
157
|
|
150
|
-
desc
|
158
|
+
desc 'Get info the Neo4j Server'
|
151
159
|
task :info, :environment do |_, args|
|
152
160
|
puts "Info from Neo4j #{get_environment(args)}..."
|
153
161
|
if OS::Underlying.windows?
|
154
|
-
if
|
155
|
-
|
162
|
+
if `reg query "HKU\\S-1-5-19"`.size > 0
|
163
|
+
`#{install_location(args)}/bin/Neo4j.bat info` # stop service
|
156
164
|
else
|
157
|
-
puts
|
165
|
+
puts 'You do not have administrative rights to get info from the Neo4j Service'
|
158
166
|
end
|
159
167
|
else
|
160
|
-
puts
|
168
|
+
puts `#{install_location(args)}/bin/neo4j info`
|
161
169
|
end
|
162
170
|
end
|
163
171
|
|
164
|
-
desc
|
172
|
+
desc 'Restart the Neo4j Server'
|
165
173
|
task :restart, :environment do |_, args|
|
166
174
|
puts "Restarting Neo4j #{get_environment(args)}..."
|
167
175
|
if OS::Underlying.windows?
|
168
|
-
if
|
169
|
-
|
176
|
+
if `reg query "HKU\\S-1-5-19"`.size > 0
|
177
|
+
`#{install_location(args)}/bin/Neo4j.bat restart`
|
170
178
|
else
|
171
|
-
puts
|
179
|
+
puts 'You do not have administrative rights to restart the Neo4j Service'
|
172
180
|
end
|
173
181
|
else
|
174
|
-
|
182
|
+
`#{install_location(args)}/bin/neo4j restart`
|
175
183
|
end
|
176
184
|
end
|
177
185
|
|
178
|
-
desc
|
186
|
+
desc 'Reset the Neo4j Server'
|
179
187
|
task :reset_yes_i_am_sure, :environment do |_, args|
|
180
188
|
# Stop the server
|
181
189
|
if OS::Underlying.windows?
|
182
|
-
if
|
183
|
-
|
190
|
+
if `reg query "HKU\\S-1-5-19"`.size > 0
|
191
|
+
`#{install_location(args)}/bin/Neo4j.bat stop`
|
184
192
|
|
185
193
|
# Reset the database
|
186
194
|
FileUtils.rm_rf("#{install_location(args)}/data/graph.db")
|
@@ -190,12 +198,12 @@ namespace :neo4j do
|
|
190
198
|
FileUtils.rm_rf("#{install_location(args)}/data/log")
|
191
199
|
FileUtils.mkdir("#{install_location(args)}/data/log")
|
192
200
|
|
193
|
-
|
201
|
+
`#{install_location(args)}/bin/Neo4j.bat start`
|
194
202
|
else
|
195
|
-
puts
|
203
|
+
puts 'You do not have administrative rights to reset the Neo4j Service'
|
196
204
|
end
|
197
205
|
else
|
198
|
-
|
206
|
+
`#{install_location(args)}/bin/neo4j stop`
|
199
207
|
|
200
208
|
# Reset the database
|
201
209
|
FileUtils.rm_rf("#{install_location(args)}/data/graph.db")
|
@@ -206,31 +214,31 @@ namespace :neo4j do
|
|
206
214
|
FileUtils.mkdir("#{install_location(args)}/data/log")
|
207
215
|
|
208
216
|
# Start the server
|
209
|
-
|
217
|
+
`#{install_location(args)}/bin/neo4j start`
|
210
218
|
end
|
211
219
|
end
|
212
220
|
|
213
|
-
desc
|
214
|
-
task :change_password do
|
215
|
-
puts
|
216
|
-
puts
|
221
|
+
desc 'Neo4j 2.2: Change connection password'
|
222
|
+
task :change_password do
|
223
|
+
puts 'This will change the password for a Neo4j server'
|
224
|
+
puts 'Enter target IP address or host name without protocal and port, press enter for http://localhost:7474'
|
217
225
|
address = STDIN.gets.chomp
|
218
|
-
target_address = address.empty? ?
|
226
|
+
target_address = address.empty? ? 'http://localhost:7474' : address
|
219
227
|
|
220
|
-
puts
|
228
|
+
puts 'Input current password. Leave blank if this is a fresh installation of Neo4j.'
|
221
229
|
password = STDIN.gets.chomp
|
222
|
-
old_password = password.empty? ?
|
230
|
+
old_password = password.empty? ? 'neo4j' : password
|
223
231
|
|
224
|
-
puts
|
232
|
+
puts 'Input new password.'
|
225
233
|
new_password = STDIN.gets.chomp
|
226
|
-
|
234
|
+
fail 'A new password is required' if new_password.empty?
|
227
235
|
|
228
236
|
body = Neo4j::Tasks::ConfigServer.change_password(target_address, old_password, new_password)
|
229
237
|
if body['errors']
|
230
238
|
puts "An error was returned: #{body['errors'][0]['message']}"
|
231
239
|
else
|
232
|
-
puts
|
233
|
-
puts
|
240
|
+
puts 'Password changed successfully! Please update your app to use:'
|
241
|
+
puts 'username: neo4j'
|
234
242
|
puts "password: #{new_password}"
|
235
243
|
end
|
236
244
|
end
|
@@ -239,20 +247,20 @@ namespace :neo4j do
|
|
239
247
|
location = config_location(args)
|
240
248
|
text = File.read(location)
|
241
249
|
replace = Neo4j::Tasks::ConfigServer.toggle_auth(status, text)
|
242
|
-
File.open(location,
|
250
|
+
File.open(location, 'w') { |file| file.puts replace }
|
243
251
|
end
|
244
252
|
|
245
253
|
def auth_toggle_complete(status)
|
246
254
|
puts "Neo4j basic authentication #{status}. Restart server to apply."
|
247
255
|
end
|
248
256
|
|
249
|
-
desc
|
257
|
+
desc 'Neo4j 2.2: Enable Auth'
|
250
258
|
task :enable_auth, :environment do |_, args|
|
251
259
|
rake_auth_toggle(args, :enable)
|
252
260
|
auth_toggle_complete('enabled')
|
253
261
|
end
|
254
262
|
|
255
|
-
desc
|
263
|
+
desc 'Neo4j 2.2: Disable Auth'
|
256
264
|
task :disable_auth, :environment do |_, args|
|
257
265
|
rake_auth_toggle(args, :disable)
|
258
266
|
auth_toggle_complete('disabled')
|