Commit c0d2a4ef authored by Frank Bergmann's avatar Frank Bergmann

- Working on Risk import

parent 3fd42c59
......@@ -548,4 +548,45 @@ ad_proc -public im_csv_import_convert_project_parent_nrs {
}
return [im_csv_import_convert_project_parent_nrs -parent_id $parent_id $parent_nrs]
}
# ---------------------------------------------------------------------
#
# ---------------------------------------------------------------------
ad_proc -public im_csv_import_check_list_of_lists {
lol
} {
Check that the parameter is a list of lists with all
line having the same length.
Returns a HTML string of LI error messages or an emtpy
string if there was no issue.
} {
set length_list [list]
set min_length 1000
set max_length 0
set result ""
foreach line $lol {
set length [llength $line]
if {$length > $max_length} { set max_length $length }
if {$length < $min_length} { set min_length $length }
lappend length_list $length
}
set ctr 0
foreach line $lol {
set length [llength $line]
if {$length < 4} {
append result "<li>Line #$ctr: Found a (nearly) empty line with only $length columns.\n"
}
if {$length < $max_length} {
# append result "<li>Line #$ctr: Found a line with $length elements which doesn't match the $max_length width.\n"
}
incr ctr
}
return $result
}
\ No newline at end of file
......@@ -97,6 +97,11 @@ set headers [im_csv_split $header $separator]
set header_len [llength $headers]
set values_lol [im_csv_get_values $lines_content $separator]
# Check if there are lines with less then 4 elements
# set error [im_csv_import_check_list_of_lists $values_lol]
# if {"" != $error} { ad_return_complaint 1 $error }
# Take a sample of max_row rows from the file and show
set max_row 10
for {set i 1} {$i <= $max_row} {incr i} {
......
......@@ -66,7 +66,6 @@ set header_fields [im_csv_split $header $separator]
set header_len [llength $header_fields]
set values_list_of_lists [im_csv_get_values $lines_content $separator]
# ad_return_complaint 1 "<pre>[array get column]<br>[array get map]<br>[array get parser]<br>[array get parser_args]<br>$header_fields</pre>"
......@@ -126,6 +125,15 @@ foreach csv_line_fields $values_list_of_lists {
if {$ns_write_p} { ns_write "</ul><hr><ul>\n" }
if {$ns_write_p} { ns_write "<li>Starting to parse line $cnt\n" }
if {[llength $csv_line_fields] < 4} {
if {$ns_write_p} {
ns_write "<li><font color=red>Error: We found a row with only [llength $csv_line_fields] columns.<br>
This is probabily because of a multi-line field in the row before.<br>Please correct the CSV file.</font>\n"
}
continue
}
# Preset values, defined by CSV sheet:
set risk_name ""
set risk_project_id ""
......@@ -213,13 +221,13 @@ foreach csv_line_fields $values_list_of_lists {
# Status is a required field
if {"" == $risk_status_id} {
if {$ns_write_p} { ns_write "<li><font color=brown>Warning: Didn't find risk status '$risk_status', using default status 'Open'</font>\n" }
set risk_status_id [im_risk_status_active]
set risk_status_id [im_risk_status_open]
}
# Type is a required field
if {"" == $risk_type_id} {
if {$ns_write_p} { ns_write "<li><font color=brown>Warning: Didn't find risk type '$risk_type', using default type 'Other'</font>\n" }
set risk_type_id [im_risk_type_default]
set risk_type_id [im_risk_type_risk]
}
# -------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment