egov_utils 1.5.0.alpha3 → 1.5.0.alpha4

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
  SHA256:
3
- metadata.gz: 00ea00706e2722fb8728d9c844bd50438b452a8de9445ef23390fb995b989db9
4
- data.tar.gz: 9e678b274e4aa700191e2973675d94442a3545ed4c829ba5f2cc7e87015a5fbc
3
+ metadata.gz: 4e9f48c4a226521a80af25765e7eeb2b133c0112300560d9cb2f37cec56f34e2
4
+ data.tar.gz: 87565bb066e01ac9605fdc5ad1f3308ef9fcfbaa7c5f132b54c07427e4d0fad1
5
5
  SHA512:
6
- metadata.gz: 1ee1188c124f50fa5fc766c6438eb4883902972a75706ba9dd8ffc169396a3d91a0faca955c6aa8da70660a1b9da18febd9ffc89ed7b664842e70a64057363c9
7
- data.tar.gz: 1b8233de8f1b144cf788e1d2b3bce95407dfeb54a01c9db26e1b6ecc22912e39407b5dd0191f8f176e6fec6022490874e176c77b0f2f0a5d0ba0cb3c697e1bde
6
+ metadata.gz: bc7af836fdcab121db08350c450908e2df069f784d9283fdc407d8fef509b079bcccb215e5f8212e2f944cdcaebea49eecc3eca97afcf0f91741620a6c2e2262
7
+ data.tar.gz: 23587f1c431273f0f1d4161ddb2f865fb54094845e3f35d424041222a77cc37a8f5de3c8f1408d50262f9f66c45832d255d67c29418ed519be25138786612b93
@@ -0,0 +1,11 @@
1
+ module EgovUtils
2
+ class TownsController < ApplicationController
3
+ def index
4
+ selected = EgovUtils::Address.towns.lazy.select do |town|
5
+ /\A#{params[:term]}/i.match?(town.name)
6
+ end.first(10)
7
+
8
+ render json: { towns: selected.map(&:to_h) }
9
+ end
10
+ end
11
+ end
@@ -18,6 +18,7 @@ module EgovUtils
18
18
  District = Struct.new(:id, :name, :region_id)
19
19
  Region = Struct.new(:id, :name)
20
20
  Country = Struct.new(:iso_id, :code2, :code3, :name)
21
+ Town = Struct.new(:id, :name, :district_name)
21
22
 
22
23
  CZ_ISO_CODE = '203'
23
24
 
@@ -51,6 +52,15 @@ module EgovUtils
51
52
  @regions
52
53
  end
53
54
 
55
+ def self.towns
56
+ @towns ||= begin
57
+ towns = File.read(EgovUtils::Engine.root.join('config', 'obec.json'))
58
+ JSON.parse(towns).map do |town|
59
+ Town.new(*town.slice('code', 'name', 'district_name').values)
60
+ end
61
+ end
62
+ end
63
+
54
64
  def self.region_for_district(district_name)
55
65
  district = districts.detect{|d| d[:name] == district_name }
56
66
  regions.detect{|r| r[:id] == district[:region_id] } if district
@@ -10,9 +10,9 @@ module EgovUtils
10
10
  strategy_class.run!(remote_id:)
11
11
  end
12
12
 
13
- def strategy_class
13
+ def fetch_result
14
14
  if Rails.env.production?
15
- EgovUtils::Iszr::Addresses::FetchForNaturalPerson::FromRemoteReposiory
15
+ EgovUtils::Iszr::FindResultByAifo
16
16
  else
17
17
  EgovUtils::Iszr::Addresses::FetchForNaturalPerson::FromSampleData
18
18
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EgovUtils
4
+ module Iszr
5
+ class Client
6
+ def initialize(message)
7
+ @client = Savon.client(wsdl: config['endpoint'], log: true, log_level: :info, ssl_verify_mode: :none)
8
+ @message = message
9
+ end
10
+
11
+ def self.config
12
+ EgovUtils::Settings['iszr']
13
+ end
14
+
15
+ def call
16
+ client.call(
17
+ :get_data,
18
+ message: { 'tns:inputXml' => message }
19
+ )
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :client, :message
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EgovUtils
4
+ module Iszr
5
+ class FindResultByAifo < Request
6
+ string :remote_id
7
+
8
+ private
9
+
10
+ def handle_response!
11
+ EgovUtils::Address.new(
12
+ street: response_body.xpath('//UliceNazev').text,
13
+ house_number: response_body.xpath('//CisloDomovni').text,
14
+ orientation_number: response_body.xpath('//CisloOrientacni').text,
15
+ city: response_body.xpath('//ObecNazev').text,
16
+ postcode: response_body.xpath('//PostaKod').text,
17
+ egov_identifier: response_body.xpath('//AdresniMistoKod').text,
18
+ country: 203,
19
+ district: district.name,
20
+ region: region.name
21
+ )
22
+ end
23
+
24
+ def district
25
+ @district ||= begin
26
+ district =
27
+ EgovUtils::Address.towns.find do
28
+ _1.id == response_body.xpath('//ObecKod').text
29
+ end.district_name
30
+
31
+ EgovUtils::Address.districts.find { _1.name == district }
32
+ end
33
+ end
34
+
35
+ def region
36
+ @region ||=
37
+ EgovUtils::Address.regions.find { _1.id == district.region_id }
38
+ end
39
+
40
+ def body
41
+ Nokogiri::XML::Builder.new do |xml|
42
+ xml[service_id].RobCtiAifo2(
43
+ 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
44
+ 'xsi:schemaLocation' => 'urn:cz:isvs:iszr:schemas:IszrRobCtiAifo2:v1 IszrRobCtiAifo2.xsd',
45
+ 'xmlns:abs' => 'urn:cz:isvs:iszr:schemas:IszrAbstract:v1',
46
+ 'xmlns:E276' => 'urn:cz:isvs:iszr:schemas:IszrRobCtiAifo2:v1',
47
+ 'xmlns:reg' => 'urn:cz:isvs:reg:schemas:RegTypy:v1',
48
+ 'xmlns:rod' => 'urn:cz:isvs:rob:schemas:RobDotazyData:v1',
49
+ 'xmlns:rob' => 'urn:cz:isvs:rob:schemas:RobTypy:v1'
50
+ ) {
51
+ xml['abs'].ZadostInfo {
52
+ xml['reg'].CasZadosti Time.current.iso8601
53
+ xml['reg'].Agenda EgovUtils::Settings['iszr']['agenda']
54
+ xml['reg'].AgendovaRole EgovUtils::Settings['iszr']['agendova_role']
55
+ xml['reg'].Ovm '00025429'
56
+ xml['reg'].Ais EgovUtils::Settings['iszr']['ais']
57
+ xml['reg'].Subjekt '00025429'
58
+ xml['reg'].Uzivatel 'Administrator'
59
+ xml['reg'].DuvodUcel 'ztotozneni'
60
+ xml['reg'].AgendaZadostId SecureRandom.uuid
61
+ }
62
+ xml['abs'].AutorizaceInfo {
63
+ xml['abs'].SeznamUdaju 'Aifo Prijmeni Jmeno DatumNarozeni RUIANCti AdresaPobytu MistoNarozeni'
64
+ }
65
+ xml['abs'].MapaAifo(nacistData: true) {
66
+ xml['reg'].PrevodAifo {
67
+ xml['reg'].LokalniAifo 1
68
+ xml['reg'].GlobalniAifo remote_id
69
+ }
70
+ }
71
+ xml[service_id].Zadost {
72
+ xml[service_id].RobCtiAifo2Data {
73
+ xml['rod'].Aifo 1
74
+ xml['rod'].VyuzitiPoskytnuti 'poskytnuti'
75
+ }
76
+ }
77
+ }
78
+ end
79
+ end
80
+
81
+ def service_id
82
+ 'E276'
83
+ end
84
+ end
85
+ end
86
+ end
@@ -19,31 +19,70 @@ module EgovUtils
19
19
  end
20
20
  end
21
21
 
22
+ def response_error_code
23
+ @response_error_code ||=
24
+ response_body.xpath('//VysledekSubKod').last&.text&.presence
25
+ end
26
+
27
+ def internal_error_code
28
+ return unless response_error_code
29
+
30
+ code = if response_error_code == 'ZAZNAM NENALEZEN'
31
+ "not_found"
32
+ elsif response_error_code == 'PREKROCEN POCET'
33
+ "multiple_records_found"
34
+ end
35
+
36
+ if birth_place.present?
37
+ "extended_search_#{code}"
38
+ else
39
+ code
40
+ end
41
+ end
42
+
43
+ def handle_response!
44
+ if internal_error_code
45
+ errors.add(:base, internal_error_code)
46
+ return
47
+ end
48
+
49
+ EgovUtils::Services::Iszr::NaturalPeople.new(
50
+ firstname: response_body.xpath('//Jmeno').text.capitalize,
51
+ lastname: response_body.xpath('//Prijmeni').text.capitalize,
52
+ birth_date: response_body.xpath('//DatumNarozeni').text,
53
+ birth_place: response_body.xpath('//Lokalita/Nazev').text,
54
+ remote_id: response_body.xpath('//GlobalniAifo').text
55
+ )
56
+
57
+ end
58
+
22
59
  def search_stage_one
23
60
  Nokogiri::XML::Builder.new do |xml|
24
- xml['e05'].RobCtiPodleUdaju(
61
+ xml[service_id].RobCtiPodleUdaju2(
25
62
  'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
26
- 'xsi:schemaLocation' => 'urn:cz:isvs:iszr:schemas:IszrRobCtiPodleUdaju:v1 IszrRobCtiPodleUdaju.xsd',
63
+ 'xsi:schemaLocation' => 'urn:cz:isvs:iszr:schemas:IszrRobCtiPodleUdaju2:v1 IszrRobCtiPodleUdaju2.xsd',
27
64
  'xmlns:abs' => 'urn:cz:isvs:iszr:schemas:IszrAbstract:v1',
28
- 'xmlns:e05' => 'urn:cz:isvs:iszr:schemas:IszrRobCtiPodleUdaju:v1',
65
+ 'xmlns:E278' => 'urn:cz:isvs:iszr:schemas:IszrRobCtiPodleUdaju2:v1',
29
66
  'xmlns:reg' => 'urn:cz:isvs:reg:schemas:RegTypy:v1',
30
67
  'xmlns:rod' => 'urn:cz:isvs:rob:schemas:RobDotazyData:v1',
31
68
  'xmlns:rob' => 'urn:cz:isvs:rob:schemas:RobTypy:v1'
32
69
  ) {
33
70
  xml['abs'].ZadostInfo {
34
- xml['reg'].CasZadosti Time.current
35
- xml['reg'].Agenda 'A482'
36
- xml['reg'].AgendovaRole 'CTENAR'
71
+ xml['reg'].CasZadosti Time.current.iso8601
72
+ xml['reg'].Agenda EgovUtils::Settings['iszr']['agenda']
73
+ xml['reg'].AgendovaRole EgovUtils::Settings['iszr']['agendova_role']
37
74
  xml['reg'].Ovm '00025429'
38
- xml['reg'].Ais '124'
39
- xml['reg'].Uzivatel 'Uzivatel156'
40
- xml['reg'].AgendaZadostId '5a7b9af0-f759-4632-ab96-7bb06df1b98c'
75
+ xml['reg'].Ais EgovUtils::Settings['iszr']['ais']
76
+ xml['reg'].Subjekt '00025429'
77
+ xml['reg'].Uzivatel 'Administrator'
78
+ xml['reg'].DuvodUcel 'ztotozneni'
79
+ xml['reg'].AgendaZadostId SecureRandom.uuid
41
80
  }
42
81
  xml['abs'].AutorizaceInfo {
43
- xml['abs'].SeznamUdaju 'Aifo Prijmeni Jmeno AdresaPobytu DorucovaciAdresa DatumNarozeni MistoNarozeni DatumUmrti DatumPravniMociUmrti MistoUmrti DatovaSchrankaROB Doklad Obcanstvi'
82
+ xml['abs'].SeznamUdaju 'Aifo Prijmeni Jmeno DatumNarozeni RUIANCti AdresaPobytu MistoNarozeni'
44
83
  }
45
- xml['e05'].Zadost {
46
- xml['e05'].RobCtiPodleUdajuData {
84
+ xml[service_id].Zadost {
85
+ xml[service_id].RobCtiPodleUdaju2Data {
47
86
  xml['rod'].DatumNarozeni birth_date
48
87
  xml['rod'].Jmeno firstname
49
88
  xml['rod'].Prijmeni lastname
@@ -55,32 +94,36 @@ module EgovUtils
55
94
 
56
95
  def search_stage_two
57
96
  Nokogiri::XML::Builder.new do |xml|
58
- xml['e05'].RobCtiPodleUdaju(
97
+ xml[service_id].RobCtiPodleUdaju2(
59
98
  'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
60
- 'xsi:schemaLocation' => 'urn:cz:isvs:iszr:schemas:IszrRobCtiPodleUdaju:v1 IszrRobCtiPodleUdaju.xsd',
99
+ 'xsi:schemaLocation' => 'urn:cz:isvs:iszr:schemas:IszrRobCtiPodleUdaju2:v1 IszrRobCtiPodleUdaju2.xsd',
61
100
  'xmlns:abs' => 'urn:cz:isvs:iszr:schemas:IszrAbstract:v1',
62
- 'xmlns:e05' => 'urn:cz:isvs:iszr:schemas:IszrRobCtiPodleUdaju:v1',
101
+ 'xmlns:E278' => 'urn:cz:isvs:iszr:schemas:IszrRobCtiPodleUdaju2:v1',
63
102
  'xmlns:reg' => 'urn:cz:isvs:reg:schemas:RegTypy:v1',
64
103
  'xmlns:rod' => 'urn:cz:isvs:rob:schemas:RobDotazyData:v1',
65
104
  'xmlns:rob' => 'urn:cz:isvs:rob:schemas:RobTypy:v1'
66
105
  ) {
67
106
  xml['abs'].ZadostInfo {
68
- xml['reg'].CasZadosti Time.current
69
- xml['reg'].Agenda 'A482'
70
- xml['reg'].AgendovaRole 'CTENAR'
107
+ xml['reg'].CasZadosti Time.current.iso8601
108
+ xml['reg'].Agenda EgovUtils::Settings['iszr']['agenda']
109
+ xml['reg'].AgendovaRole EgovUtils::Settings['iszr']['agendova_role']
71
110
  xml['reg'].Ovm '00025429'
72
- xml['reg'].Ais '124'
73
- xml['reg'].Uzivatel 'Uzivatel156'
74
- xml['reg'].AgendaZadostId '5a7b9af0-f759-4632-ab96-7bb06df1b98c'
111
+ xml['reg'].Ais EgovUtils::Settings['iszr']['ais']
112
+ xml['reg'].Subjekt '00025429'
113
+ xml['reg'].Uzivatel 'Administrator'
114
+ xml['reg'].DuvodUcel 'ztotozneni'
115
+ xml['reg'].AgendaZadostId SecureRandom.uuid
75
116
  }
76
117
  xml['abs'].AutorizaceInfo {
77
- xml['abs'].SeznamUdaju 'Aifo Prijmeni Jmeno AdresaPobytu DorucovaciAdresa DatumNarozeni MistoNarozeni DatumUmrti DatumPravniMociUmrti MistoUmrti DatovaSchrankaROB Doklad Obcanstvi'
118
+ xml['abs'].SeznamUdaju 'Aifo Prijmeni Jmeno DatumNarozeni RUIANCti AdresaPobytu MistoNarozeni'
78
119
  }
79
- xml['e05'].Zadost {
80
- xml['e05'].RobCtiPodleUdajuData {
81
- xml['rod'].MistoNarozeni birth_place
120
+ xml[service_id].Zadost {
121
+ xml[service_id].RobCtiPodleUdaju2Data {
82
122
  xml['rod'].DatumNarozeni birth_date
83
123
  xml['rod'].Jmeno firstname
124
+ xml['rod'].MistoNarozeni {
125
+ xml['rob'].NarozeniCr birth_place
126
+ }
84
127
  xml['rod'].Prijmeni lastname
85
128
  }
86
129
  }
@@ -89,7 +132,7 @@ module EgovUtils
89
132
  end
90
133
 
91
134
  def service_id
92
- 'E05'
135
+ 'E278'
93
136
  end
94
137
  end
95
138
  end
@@ -2,7 +2,7 @@ module EgovUtils
2
2
  module Iszr
3
3
  class Request < ActiveInteraction::Base
4
4
  def execute
5
- envelope.to_xml
5
+ handle_response!
6
6
  end
7
7
 
8
8
  private
@@ -19,7 +19,7 @@ module EgovUtils
19
19
  }
20
20
  xml.SenderDetails {
21
21
  xml.Authentication(type: 'clear') {
22
- xml.ISId '124'
22
+ xml.ISId EgovUtils::Settings['iszr']['ais']
23
23
  }
24
24
  }
25
25
  }
@@ -31,6 +31,24 @@ module EgovUtils
31
31
  def encoded_body(body)
32
32
  Base64.encode64(body.to_xml)
33
33
  end
34
+
35
+ def response
36
+ @response ||= Client.new(envelope.to_xml).call
37
+ end
38
+
39
+ def response_body
40
+ @response_body ||= begin
41
+ body = Nokogiri::XML(
42
+ response.body[:get_data_response][:get_data_result]
43
+ ).xpath("//Body").text
44
+
45
+ Nokogiri::XML(Base64.decode64(body)).remove_namespaces!
46
+ end
47
+ end
48
+
49
+ def handle_response!
50
+ response_body
51
+ end
34
52
  end
35
53
  end
36
54
  end
@@ -18,16 +18,27 @@
18
18
  = label_tag 'birth_date', 'Datum narození'
19
19
  = date_field_tag :birth_date, {}, class: 'form-control'
20
20
  = link_to 'Vyhledat', {}, class: 'btn btn-primary'
21
- .legal-person-row.identification-form.legal_person.row
22
- .col-12
23
- .card
24
- .card-header Ztotožnění právnické osoby
25
- .card-body
26
- .form
27
- .form-group
28
- = label_tag 'ico', 'IČO'
29
- = text_field_tag :ico, {}, class: 'form-control'
30
- = link_to 'Vyhledat', nil, class: 'btn btn-primary'
21
+ .legal_person
22
+ .row
23
+ = form.fields_for(:legal_person, person.legal_person || EgovUtils::LegalPerson.new) do |fields|
24
+ .col-12= fields.text_field(:name)
25
+ .col-12.col-sm-6= fields.text_field(:ico)
26
+ .col-12.col-sm-6= fields.select2 :legal_form, list_values_for_select(azahara_attribute_for(EgovUtils::LegalPerson, 'legal_form'))
27
+ .row
28
+ .col-12
29
+ = form.fields_for(:residence, person.residence || EgovUtils::Address.new) do |fields|
30
+ = render 'egov_utils/addresses/form', form: fields, address: fields.object
31
+
32
+ -# .legal-person-row.identification-form.legal_person.row
33
+ -# .col-12
34
+ -# .card
35
+ -# .card-header Ztotožnění právnické osoby
36
+ -# .card-body
37
+ -# .form
38
+ -# .form-group
39
+ -# = label_tag 'ico', 'IČO'
40
+ -# = text_field_tag :ico, {}, class: 'form-control'
41
+ -# = link_to 'Vyhledat', nil, class: 'btn btn-primary'
31
42
  = form.hidden_field :remote_id
32
43
 
33
44
  :javascript
@@ -41,9 +52,11 @@
41
52
  firstname: $npr.find('input[name=firstname]').val(),
42
53
  lastname: $npr.find('input[name=lastname]').val(),
43
54
  birth_date: $npr.find('input[name=birth_date]').val(),
44
- birth_place: $npr.find('input[name=birth_place]').val()
55
+ birth_place: $npr.find('select[name=birth_place]').val()
45
56
  }
46
57
 
58
+ selected_birth_place = $npr.find('select[name=birth_place] option:selected').text().split('(')[0].trim();
59
+
47
60
  $.ajax({
48
61
  url: '/internals/iszr/search',
49
62
  data: {
@@ -82,21 +95,44 @@
82
95
  // Fill in the form with the data
83
96
  $old_person_form.find("input[name*='[firstname]']").val(form_data.firstname);
84
97
  $old_person_form.find("input[name*='[lastname]']").val(form_data.lastname);
85
- $old_person_form.find("input[name*='[birth_place]']").val(form_data.birth_place);
98
+ $old_person_form.find("input[name*='[birth_place]']").val(selected_birth_place);
86
99
  $old_person_form.find("input[name*='[birth_date]']").val(form_data.birth_date);
87
100
  }
88
101
  else if(error_kind == 'multiple_results_found') {
89
102
  $form_group = $('<div>').addClass('form-group');
90
103
  $label = $('<label>').attr('for', 'birth_place').text('Místo narození');
91
- $input = $('<input>').attr('type', 'text').attr('name', 'birth_place').addClass('form-control');
104
+ $input = $('<select>').attr('name', 'birth_place').addClass('form-control');
92
105
  $form_group.append($label).append($input);
106
+ $input.select2({
107
+ ajax: {
108
+ url: '/internals/towns',
109
+ data: function (params) {
110
+ var query = {
111
+ term: params.term
112
+ }
113
+
114
+ return query;
115
+ },
116
+ processResults: function(data) {
117
+ return {
118
+ results: data.towns.map(function(val) {
119
+ return {
120
+ id: val.id,
121
+ text: `${val.name} (okr. ${val.district_name})`
122
+ }
123
+ })
124
+ }
125
+ }
126
+ }
127
+ });
128
+
93
129
  $npr.find('.card-body .form .btn').before($form_group);
94
130
 
95
131
  $icon = $('<i>').addClass('fa').addClass('fa-times');
96
132
  $error_div = $('<div>').addClass('alert').addClass('alert-danger').append($icon).append(' Nalezeno více osob, zadejte místo narození');
97
133
  $npr.find('.card-body').prepend($error_div);
98
134
  }
99
- else if(error_kind == 'extended_search_multiple_records_found') {
135
+ else if(error_kind == 'extended_search_multiple_records_found' || error_kind == 'extended_search_not_found') {
100
136
  $icon = $('<i>').addClass('fa').addClass('fa-times');
101
137
  $error_div = $('<div>').addClass('alert').addClass('alert-danger').append($icon).append(' Nalezeno více osob, pokračujte, prosím, ručním zadáním údajů');
102
138
 
@@ -108,7 +144,7 @@
108
144
  // Fill in the form with the data
109
145
  $('.old-person-form').find("input[name*='[firstname]']").val(form_data.firstname);
110
146
  $('.old-person-form').find("input[name*='[lastname]']").val(form_data.lastname);
111
- $('.old-person-form').find("input[name*='[birth_place]']").val(form_data.birth_place);
147
+ $('.old-person-form').find("input[name*='[birth_place]']").val(selected_birth_place);
112
148
  $('.old-person-form').find("input[name*='[birth_date]']").val(form_data.birth_date);
113
149
  }
114
150
  }
@@ -3,6 +3,7 @@
3
3
  = bootstrap_form_tag(url: egov_utils.users_path, method: :get, layout: :inline) do |f|
4
4
  .form-group
5
5
  = f.text_field :search, value: params[:search], label: false, placeholder: t('label_search'), skip_label: true
6
+ = f.hidden_field :default_scope, value: params[:default_scope]
6
7
  = f.submit 'Vyhledat', class: 'btn btn-primary btn-sm'
7
8
 
8
9
  %table.table.table-striped