Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Back-end_Server
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Agendador
Back-end_Server
Commits
22e84d3a
Commit
22e84d3a
authored
Jul 16, 2018
by
Rafael Ravedutti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more information on citizen upload logs
Signed-off-by:
Rafael Ravedutti
<
rrlmachado@inf.ufpr.br
>
parent
3a8e2cc4
Pipeline
#16709
passed with stages
in 4 minutes and 8 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
22 deletions
+85
-22
app/models/citizen_upload.rb
app/models/citizen_upload.rb
+1
-4
app/workers/citizen_upload_worker.rb
app/workers/citizen_upload_worker.rb
+84
-18
No files found.
app/models/citizen_upload.rb
View file @
22e84d3a
...
...
@@ -7,10 +7,7 @@ class CitizenUpload < ApplicationRecord
has_attached_file
:log
,
path:
"/data/citizen_upload/:id/log.csv"
# Validates format of logs
# validates_attachment_content_type :log,
# :content_type => ['text/csv']
# Do not validate format of logs
do_not_validate_attachment_file_type
:log
# @params params [ActionController::Parameters] Parameters for searching
...
...
app/workers/citizen_upload_worker.rb
View file @
22e84d3a
...
...
@@ -31,15 +31,6 @@ class CitizenUploadWorker
status:
1
# parsing content
)
# Parse citizens from the CSV data
citizens
=
CSV
.
parse
(
content
).
map
{
|
row
|
Hash
[
columns
.
zip
(
row
)]
}
# Remove headers
citizens
=
citizens
.
drop
(
1
)
# Number of citizens to be uploaded
upload_size
=
citizens
.
length
# Line number starts with one
line_number
=
1
# Hash with errors
...
...
@@ -49,6 +40,41 @@ class CitizenUploadWorker
# Buffer containing accounts to create
account_to_create
=
Array
.
new
begin
# Parse citizens from the CSV data
citizens
=
CSV
.
parse
(
content
).
map
{
|
row
|
Hash
[
columns
.
zip
(
row
)]
}
# Remove headers
citizens
=
citizens
.
drop
(
1
)
# Number of citizens to be uploaded
upload_size
=
citizens
.
length
rescue
# Set citizens to nil
citizens
=
[]
# Upload size is zero
upload_size
=
1
# Add parsing error to log
errors
.
push
([
0
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
"Could not parse CSV file!"
])
end
# Update task status to in progress
CitizenUpload
.
update
(
upload_id
,
...
...
@@ -70,16 +96,34 @@ class CitizenUploadWorker
provider:
"cpf"
})
# Create default password for current citizen
account
.
password
=
citizen
.
birth_date
.
strftime
(
'%d%m%y'
)
# Citizen remaining info is added when .valid? method is called
if
citizen
.
valid?
and
account
.
valid?
if
citizen
.
valid?
# Create default password for current citizen
account
.
password
=
citizen
.
birth_date
.
strftime
(
'%d%m%y'
)
end
# Check if account is valid
if
account
.
valid?
# Check for permissions on the citizen to be added
if
permission
!=
"adm_c3sl"
and
citizen
.
city_id
!=
city_id
# If there was a permission error, store it in the errors hash
# errors.push("%d,Permission denied for this city" % [line_number])
errors
.
push
([
line_number
,
"Permission denied for this city"
])
errors
.
push
([
line_number
,
citizen_params
[
:name
],
citizen_params
[
:cpf
],
citizen_params
[
:rg
],
citizen_params
[
:birth_date
],
citizen_params
[
:cep
],
citizen_params
[
:address_number
],
citizen_params
[
:address_complement
],
citizen_params
[
:phone1
],
citizen_params
[
:phone2
],
citizen_params
[
:email
],
citizen_params
[
:pcd
],
citizen_params
[
:note
],
"Permission denied for this city"
])
else
# Add valid citizen with complete info to to_create array
inst
=
[
...
...
@@ -118,8 +162,22 @@ class CitizenUploadWorker
# Go through error messages
citizen
.
errors
.
full_messages
.
each
do
|
message
|
# Add current error in the list of errors
# errors.push("%d,%s" % [line_number, message])
errors
.
push
([
line_number
,
message
])
errors
.
push
([
line_number
,
citizen_params
[
:name
],
citizen_params
[
:cpf
],
citizen_params
[
:rg
],
citizen_params
[
:birth_date
],
citizen_params
[
:cep
],
citizen_params
[
:address_number
],
citizen_params
[
:address_complement
],
citizen_params
[
:phone1
],
citizen_params
[
:phone2
],
citizen_params
[
:email
],
citizen_params
[
:pcd
],
citizen_params
[
:note
],
message
])
end
end
...
...
@@ -187,8 +245,16 @@ class CitizenUploadWorker
# Get CSV path
path
=
"
#{
Rails
.
root
.
to_s
}
/tmp/citizen_uploads/
#{
upload_id
}
.csv"
# Open log CSV file for writing the log
CSV
.
open
(
path
,
"wb"
)
do
|
csv
|
csv
<<
[
"Line"
,
"Error Message"
]
# Add headers to log
csv
<<
[
"Linha"
,
"Nome"
,
"CPF"
,
"RG"
,
"Data de Nascimento"
,
"CEP"
,
"Numero"
,
"Complemento"
,
"Telefone 1"
,
"Telefone 2"
,
"E-mail"
,
"Deficiencia"
,
"Observacao"
,
"Erro"
]
# Go through the errors to add them into the log
errors
.
each
do
|
error
|
csv
<<
error
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment