justiz_sync 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b5a6baf253fa7526a90c2a9f79c3ac3fc860039
4
- data.tar.gz: ddaf477b1753c677df99cacd42b8cb45dcc1d3e3
3
+ metadata.gz: 91ddc84cf4f63d03b44b185ccb85ef0867c0cdff
4
+ data.tar.gz: 6f6c67c180778487e22e1f7fc9c27c3f73952d3e
5
5
  SHA512:
6
- metadata.gz: 799d9dd3b349b433c3dc44f3590a974a9b84012466c8cab1acf8f51d512261d4a02b76f5110c27ec277ef01e0ea41e00a078c9c8fce3cc76e21dc32d3594a52f
7
- data.tar.gz: 8bc9eccd7c823322886f3f77c9254607e1ab593f81509fca477c9be89982daa5b58838d6817ab6ff3a020b0e03dc51c069bf52175c59e8cadf9e01b889e894bb
6
+ metadata.gz: fde1adc301c76978f2d286ad06e360ab9267fb7bbfe0008b2c61f122dbb45b98ed2477f29a7df4aad65f635309b67091398a07a7f5611c6db8121c17b0498933
7
+ data.tar.gz: 9d7a3be8790ea5c3ed00d31032ce5f819e7709181c549a900b32137c24630da41450346525bbef3818c866820c08d3779218d776b1cc4ff0fbe2bd5d89ca438e
data/justiz_sync.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "justiz", "~> 0.1.3"
21
+ spec.add_dependency "justiz", "~> 0.2.1"
22
22
  spec.add_dependency "opencrx", "~> 0.2.0"
23
23
  spec.add_dependency "thor"
24
24
 
@@ -11,16 +11,12 @@ module JustizSync
11
11
  desc 'sync', 'sync all records from justiz to opencrx'
12
12
  def sync
13
13
  transfer = Transfer.new(options)
14
- if (state = options['state'])
15
- transfer.sync_state(state)
16
- else
17
- transfer.sync
18
- end
14
+ transfer.sync
19
15
  end
20
16
  end
21
17
 
22
18
  class Transfer
23
- attr_reader :options
19
+ attr_reader :options, :stream
24
20
  def initialize(options)
25
21
  @options = options
26
22
  STDOUT.sync = true
@@ -28,24 +24,33 @@ module JustizSync
28
24
  end
29
25
 
30
26
  def sync
27
+ @stream = Stream.new
28
+ delete_unused = false
29
+ if (state = options['state'])
30
+ sync_state(state)
31
+ else
32
+ sync_all
33
+ delete_unused = true
34
+ end
35
+ stream.close(delete_unused)
36
+ end
37
+
38
+ def sync_all
31
39
  states = scraper.states
32
- total = 0
33
40
  states.keys.each do |state|
34
- total += sync_state(state)
41
+ sync_state(state)
35
42
  end
36
- puts "Total #{total} synchronized"
37
43
  end
38
44
 
39
45
  def sync_state(state)
40
46
  courts = scraper.contacts_for(state)
41
47
  puts "Syncing #{state} #{courts.length} courts"
42
48
  sync_courts(courts)
43
- courts.length
44
49
  end
45
50
 
46
51
  def sync_courts(courts)
47
52
  courts.each_with_index do |court, index|
48
- OpencrxCourt.sync(court)
53
+ stream.sync(court)
49
54
  puts if verbose && index && (index % 20 == 0)
50
55
  putc('.') if verbose
51
56
  end
@@ -1,14 +1,12 @@
1
1
  require 'opencrx'
2
2
 
3
3
  module JustizSync
4
-
5
4
  class OpencrxCourt
6
5
  TAG = 'justiz'
7
6
 
8
7
  attr_reader :court
9
8
 
10
9
  class << self
11
-
12
10
  def sync(justiz_court)
13
11
  OpencrxCourt.new(justiz_court).sync
14
12
  end
@@ -19,7 +17,27 @@ module JustizSync
19
17
  end
20
18
 
21
19
  def find_tagged
22
- Opencrx::Model::LegalEntity.query(query: "thereExistsUserString2().equalTo(\"#{TAG}\")")
20
+ tagged = []
21
+ position = 0
22
+ size = 500
23
+ begin
24
+ result_set = Opencrx::Model::LegalEntity.query(size: size, position: position,
25
+ query: "thereExistsUserString2().equalTo(\"#{TAG}\")")
26
+ position += result_set.length
27
+ tagged += result_set
28
+ end while result_set && result_set.more?
29
+ tagged
30
+ end
31
+
32
+ def all_ids
33
+ find_tagged.map { |crx| crx.userString1 }
34
+ end
35
+
36
+ def destroy(ids)
37
+ ids.each do |id|
38
+ crx = find(id)
39
+ crx.destroy if crx
40
+ end
23
41
  end
24
42
 
25
43
  # court.id is stored in openCRX userString1
@@ -0,0 +1,26 @@
1
+ module JustizSync
2
+ class Stream
3
+ def initialize
4
+ @ids= []
5
+ @total_items = 0
6
+ @new_items = 0
7
+ end
8
+
9
+ def sync(court)
10
+ @ids << court.id
11
+ @total_items += 1
12
+ @new_items += OpencrxCourt.new(court).sync
13
+ end
14
+
15
+ def close(delete_unused = false)
16
+ all_ids = OpencrxCourt.all_ids
17
+ unused = all_ids - @ids
18
+ puts "#{@total_items} processed"
19
+ puts "#{@new_items} new entrie(s)"
20
+ if delete_unused
21
+ OpencrxCourt.destroy(unused)
22
+ puts "#{unused.length} deleted entrie(s)"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module JustizSync
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
data/lib/justiz_sync.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'justiz_sync/version'
2
2
  require 'justiz_sync/opencrx_court'
3
+ require 'justiz_sync/stream'
3
4
  require 'justiz_sync/cli'
4
5
 
5
6
  module JustizSync
data/spec/cli_spec.rb CHANGED
@@ -6,7 +6,7 @@ describe JustizSync::Cli do
6
6
  JustizSync::Cli.start(%w(sync --verbose --state=BRD))
7
7
  end
8
8
 
9
- it "syncs all records" do
9
+ xit "syncs all records" do
10
10
  JustizSync::Cli.start(%w(sync --verbose))
11
11
  end
12
12
  end
@@ -1,20 +1,21 @@
1
1
  require_relative "spec_helper"
2
2
 
3
3
  describe JustizSync::OpencrxCourt do
4
+ let(:court) { Justiz::Contact.new(court: 'TEST Staatsanwaltschaft Düsseldorf',
5
+ location: 'Fritz-Roeber-Straße 2, 40213 Düsseldorf',
6
+ post: 'P.O.Box 123, 40999 Düsseldorf - Post',
7
+ phone: '0211 6025 0',
8
+ fax: '0211 6025 2929',
9
+ justiz_id: 'R1100S',
10
+ url: 'http://www.sta-duesseldorf.nrw.de',
11
+ email: 'poststelle@sta-duesseldorf.nrw.de') }
12
+
13
+
4
14
  before do
5
15
  Opencrx::connect("http://localhost:8080", "guest", "guest")
6
16
  end
7
17
 
8
18
  context "sync" do
9
- let(:court) { Justiz::Contact.new(court: 'TEST Staatsanwaltschaft Düsseldorf',
10
- location: 'Fritz-Roeber-Straße 2, 40213 Düsseldorf',
11
- post: 'P.O.Box 123, 40999 Düsseldorf - Post',
12
- phone: '0211 6025 0',
13
- fax: '0211 6025 2929',
14
- justiz_id: 'R1100S',
15
- url: 'http://www.sta-duesseldorf.nrw.de',
16
- email: 'poststelle@sta-duesseldorf.nrw.de') }
17
-
18
19
  before do
19
20
  delete_courts(court.id)
20
21
  end
@@ -43,12 +44,6 @@ describe JustizSync::OpencrxCourt do
43
44
  expect(find_attribute(addresses, :emailAddress)).to eq([court.email])
44
45
  end
45
46
 
46
- def delete_courts(id)
47
- while (crx = JustizSync::OpencrxCourt.find(id))
48
- crx.destroy
49
- end
50
- end
51
-
52
47
  it "should create and find court" do
53
48
  expect(JustizSync::OpencrxCourt.sync(court)).to eq(1)
54
49
  crx = JustizSync::OpencrxCourt.find(court.id)
@@ -56,18 +51,19 @@ describe JustizSync::OpencrxCourt do
56
51
  delete_courts(court.id)
57
52
  end
58
53
 
59
- it "should update court" do
60
- JustizSync::OpencrxCourt.sync(court)
61
-
62
- updated_court = court.dup
63
- updated_court.url += ' Update'
64
-
65
- expect(JustizSync::OpencrxCourt.sync(updated_court)).to eq(1)
66
- crx = JustizSync::OpencrxCourt.find(court.id)
67
- match_court(updated_court, crx)
68
- crx.destroy
69
- expect(JustizSync::OpencrxCourt.find(court.id)).to_not be
70
- end
54
+ # id is now digest, so any changes creates a new id
55
+ #it "should update court" do
56
+ # JustizSync::OpencrxCourt.sync(court)
57
+ #
58
+ # updated_court = court.dup
59
+ # updated_court.url += ' Update'
60
+ #
61
+ # expect(JustizSync::OpencrxCourt.sync(updated_court)).to eq(1)
62
+ # crx = JustizSync::OpencrxCourt.find(court.id)
63
+ # match_court(updated_court, crx)
64
+ # crx.destroy
65
+ # expect(JustizSync::OpencrxCourt.find(court.id)).to_not be
66
+ #end
71
67
 
72
68
  it "should not update unchanged court" do
73
69
  JustizSync::OpencrxCourt.sync(court)
@@ -78,16 +74,4 @@ describe JustizSync::OpencrxCourt do
78
74
  crx.destroy
79
75
  end
80
76
  end
81
-
82
- context "tagged" do
83
- xit "deletes tagged entries" do
84
- total = 0
85
- begin
86
- result_set = JustizSync::OpencrxCourt.find_tagged
87
- result_set.each(&:destroy)
88
- total += result_set.length
89
- end while result_set && result_set.more?
90
- puts "#{total} destroyed"
91
- end
92
- end
93
77
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,9 @@
1
1
  require 'rspec'
2
2
  require 'justiz_sync'
3
3
  require 'awesome_print'
4
+
5
+ def delete_courts(id)
6
+ while (crx = JustizSync::OpencrxCourt.find(id))
7
+ crx.destroy
8
+ end
9
+ end
@@ -0,0 +1,34 @@
1
+ require_relative "spec_helper"
2
+
3
+ describe JustizSync::OpencrxCourt do
4
+ let(:court1) { Justiz::Contact.new(court: 'TEST 1') }
5
+ let(:court2) { Justiz::Contact.new(court: 'TEST 2') }
6
+
7
+ before do
8
+ Opencrx::connect("http://localhost:8080", "guest", "guest")
9
+ end
10
+
11
+ before do
12
+ ids = JustizSync::OpencrxCourt.all_ids
13
+ JustizSync::OpencrxCourt.destroy(ids)
14
+ end
15
+
16
+ it "streams" do
17
+ JustizSync::OpencrxCourt.sync(court1)
18
+ stream = JustizSync::Stream.new
19
+ stream.sync(court2)
20
+ stream.close(true)
21
+ crx = JustizSync::OpencrxCourt.find(court1.id)
22
+ expect(crx).to_not be
23
+ crx = JustizSync::OpencrxCourt.find(court2.id)
24
+ expect(crx.name).to eq(court2.court)
25
+ crx.destroy
26
+ end
27
+
28
+ it "deletes all entries" do
29
+ stream = JustizSync::Stream.new
30
+ stream.close
31
+ result_set = JustizSync::OpencrxCourt.find_tagged
32
+ expect(result_set.length).to eq(0)
33
+ end
34
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: justiz_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Park
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-26 00:00:00.000000000 Z
11
+ date: 2013-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: justiz
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.3
19
+ version: 0.2.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.3
26
+ version: 0.2.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: opencrx
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -127,10 +127,12 @@ files:
127
127
  - lib/justiz_sync.rb
128
128
  - lib/justiz_sync/cli.rb
129
129
  - lib/justiz_sync/opencrx_court.rb
130
+ - lib/justiz_sync/stream.rb
130
131
  - lib/justiz_sync/version.rb
131
132
  - spec/cli_spec.rb
132
133
  - spec/opencrx_court_spec.rb
133
134
  - spec/spec_helper.rb
135
+ - spec/stream_spec.rb
134
136
  homepage: https://github.com/mike-park/justiz_sync
135
137
  licenses:
136
138
  - MIT
@@ -159,3 +161,4 @@ test_files:
159
161
  - spec/cli_spec.rb
160
162
  - spec/opencrx_court_spec.rb
161
163
  - spec/spec_helper.rb
164
+ - spec/stream_spec.rb