Class: JustizSync::OpencrxCourt

Inherits:
Object
  • Object
show all
Defined in:
lib/justiz_sync/opencrx_court.rb

Constant Summary collapse

TAG =
'justiz'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(court) ⇒ OpencrxCourt

Returns a new instance of OpencrxCourt.



32
33
34
# File 'lib/justiz_sync/opencrx_court.rb', line 32

def initialize(court)
  @court = court
end

Instance Attribute Details

#courtObject (readonly)

Returns the value of attribute court.



8
9
10
# File 'lib/justiz_sync/opencrx_court.rb', line 8

def court
  @court
end

Class Method Details

.find(id) ⇒ Object



16
17
18
19
# File 'lib/justiz_sync/opencrx_court.rb', line 16

def find(id)
  query = id_to_query(id)
  Opencrx::Model::LegalEntity.query(query).first
end

.find_taggedObject



21
22
23
# File 'lib/justiz_sync/opencrx_court.rb', line 21

def find_tagged
  Opencrx::Model::LegalEntity.query(query: "thereExistsUserString2().equalTo(\"#{TAG}\")")
end

.id_to_query(id) ⇒ Object

court.id is stored in openCRX userString1



26
27
28
# File 'lib/justiz_sync/opencrx_court.rb', line 26

def id_to_query(id)
  {query: "thereExistsUserString1().equalTo(\"#{id}\")"}
end

.sync(justiz_court) ⇒ Object



12
13
14
# File 'lib/justiz_sync/opencrx_court.rb', line 12

def sync(justiz_court)
  OpencrxCourt.new(justiz_court).sync
end

Instance Method Details

#addressesObject



81
82
83
# File 'lib/justiz_sync/opencrx_court.rb', line 81

def addresses
  @addresses ||= entity.query(:address, self.class.id_to_query(court.id))
end

#entityObject



85
86
87
# File 'lib/justiz_sync/opencrx_court.rb', line 85

def entity
  @entity ||= find_entity || create_entity
end

#syncObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/justiz_sync/opencrx_court.rb', line 36

def sync
  return 0 if entity.userString3 == court.digest

  entity.name = court.court
  entity.aliasName = court.justiz_id
  entity.userString3 = court.digest
  entity.save

  court_address = court.location_address
  process_address(Opencrx::Model::PostalAddress, usage(:visitor), court_address.city.blank?) do |address|
    address.postalStreet = court_address.street
    address.postalCode = court_address.plz
    address.postalCity = court_address.city
    address.postalCountry = country(:de)
  end

  court_address = court.post_address
  process_address(Opencrx::Model::PostalAddress, usage(:business), court_address.city.blank?) do |address|
    address.postalStreet = court_address.street
    address.postalCode = court_address.plz
    address.postalCity = court_address.city
    address.postalCountry = country(:de)
  end

  process_address(Opencrx::Model::PhoneNumber, usage(:business), court.phone.blank?) do |address|
    address.phoneNumberFull = court.phone
    address.automaticParsing = true
  end

  process_address(Opencrx::Model::PhoneNumber, usage(:fax), court.fax.blank?) do |address|
    address.phoneNumberFull = court.fax
    address.automaticParsing = true
  end

  process_address(Opencrx::Model::EMailAddress, usage(:business), court.email.blank?) do |address|
    address.emailAddress = court.email
  end

  process_address(Opencrx::Model::WebAddress, usage(:business), court.url.blank?) do |address|
    address.webUrl = court.url
  end

  1
end