Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
intranet-csv-import
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
project-open
intranet-csv-import
Commits
131ebe88
Commit
131ebe88
authored
Jul 02, 2016
by
Frank Bergmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Improving ConfDB CSV import
parent
b2bfe768
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
41 deletions
+61
-41
intranet-csv-import-procs.tcl
tcl/intranet-csv-import-procs.tcl
+19
-1
import-im_conf_item.tcl
www/import-im_conf_item.tcl
+42
-40
No files found.
tcl/intranet-csv-import-procs.tcl
View file @
131ebe88
...
...
@@ -44,6 +44,24 @@ ad_proc -public im_csv_import_guess_im_project { } {} {
return
$mapping
}
ad_proc -public im_csv_import_guess_im_conf_item
{
}
{}
{
set mapping
{
{
conf_item_name
"Conf Item Name"
no_change
""
}
{
conf_item_nr
"Conf Item Nr"
no_change
""
}
{
conf_item_code
"Conf Item Code"
no_change
""
}
{
conf_item_parent_id
"Parent Conf Item Nr"
conf_item_parent_nrs
""
}
{
conf_item_cost_center_id
"Conf Item Cost Center Code"
cost_center
""
}
{
conf_item_status_id
"Conf Item Status"
category
"Intranet Conf Item Status"
}
{
conf_item_type_id
"Conf Item Type"
category
"Intranet Conf Item Type"
}
{
conf_item_owner_id
"Conf Item Owner"
user_name
""
}
{
conf_item_owner_id
"Conf Item Owner Email"
user_name
""
}
{
conf_item_version
"Conf Item Version"
no_change
""
}
{
description
"Description"
no_change
""
}
{
note
"Note"
no_change
""
}
}
return
$mapping
}
ad_proc -public im_csv_import_guess_im_hour
{
}
{}
{
set mapping
{
{
project_id
"Parent Nrs"
project_parent_nrs
""
}
...
...
@@ -241,7 +259,7 @@ ad_proc -public im_csv_import_guess_map {
<li>
}
{
set field_name_lower
[
csv_norm
$field
_name
]
ns_log Notice
"im_csv_import_guess_map: trying to guess attribute_name for field_name=
$field
_name_lower"
ns_log Notice
"im_csv_import_guess_map: trying to guess attribute_name for field_name=
$field
_name_lower
of object_type=
$object
_type
"
im_security_alert_check_alphanum -location
"im_csv_import_guess_map: object_type"
-value
$object
_type
# Check for manual override static mapping
...
...
www/import-im_conf_item.tcl
View file @
131ebe88
...
...
@@ -231,7 +231,7 @@ foreach csv_line_fields $values_list_of_lists {
# conf_item_nr needs to be there
if
{
""
==
$conf
_item_nr
}
{
set conf_item_nr
[
string
trim
[
string
tolower
$conf
_item_name
]
]
set conf_item_nr
[
regsub
{[
^a-z0-9_
]}
[
string
trim
[
string
tolower
$conf
_item_name
]]
"_"
]
}
if
{
""
==
$conf
_item_nr
}
{
if
{
$ns
_write_p
}
{
...
...
@@ -241,20 +241,6 @@ foreach csv_line_fields $values_list_of_lists {
continue
}
# parent_nrs contains a space separated list
if
{[
catch
{
set result
[
im_csv_import_convert_conf_item_parent_nrs
$conf
_item_parent_nrs
]
}
err_msg
]}
{
if
{
$ns
_write_p
}
{
ns_write
"<li><font color=red>Error: We have found an error parsing Parent NRs '
$conf
_item_parent_nrs'.<pre>
\n
$err
_msg</pre>"
}
continue
}
set conf_item_parent_id
[
lindex
$result
0
]
set err
[
lindex
$result
1
]
if
{
""
!=
$err
}
{
if
{
$ns
_write_p
}
{
ns_write
"<li><font color=red>Error: <pre>
$err
</pre></font>
\n
"
}
continue
}
# Status is a required field
set conf_item_status_id
[
im_id_from_category
$conf
_item_status
"Intranet Conf Item Status"
]
if
{
""
==
$conf
_item_status_id
}
{
...
...
@@ -277,47 +263,56 @@ foreach csv_line_fields $values_list_of_lists {
set conf_item_parent_id_sql
"is null"
}
set conf_item_id
[
db_string conf_item_id
"
# Check if we find the same conf item by name with it's parent.
set conf_item_id_name
[
db_string conf_item_id
"
select conf_item_id
from im_conf_items
where conf_item_parent_id
$conf
_item_parent_id_sql and
lower(trim(conf_item_n
r)) = lower(trim(:conf_item_nr
))
lower(trim(conf_item_n
ame)) = lower(trim(:conf_item_name
))
"
-default
""
]
set conf_item_id
2
[
db_string conf_item_id
"
select conf_item_id
from im_conf_items
where conf_item_parent_id
$conf
_item_parent_id_sql and
lower(trim(conf_item_name)) = lower(trim(:conf_item_name
))
set conf_item_id
_nr
[
db_string conf_item_id
"
select conf_item_id
from im_conf_items
where conf_item_parent_id
$conf
_item_parent_id_sql and
lower(trim(conf_item_nr)) = lower(trim(:conf_item_nr
))
"
-default
""
]
if
{
$conf
_item_id !=
$conf
_item_id2 &&
""
!=
$conf
_item_id &&
""
!=
$conf
_item_id2
}
{
set conf_item_id_code
[
db_string conf_item_id
"
select conf_item_id
from im_conf_items
where lower(trim(conf_item_code)) = lower(trim(:conf_item_code))
"
-default
""
]
set conf_item_id
""
if
{
""
eq
$conf
_item_id
}
{
set conf_item_id
$conf
_item_id_name
}
if
{
""
eq
$conf
_item_id
}
{
set conf_item_id
$conf
_item_id_nr
}
if
{
""
eq
$conf
_item_id
}
{
set conf_item_id
$conf
_item_id_code
}
set error_p 0
if
{
$conf
_item_id_name ne
""
&&
$conf
_item_id_name ne
$conf
_item_id
}
{
set error_p 1
}
if
{
$conf
_item_id_nr ne
""
&&
$conf
_item_id_nr ne
$conf
_item_id
}
{
set error_p 1
}
if
{
$conf
_item_id_code ne
""
&&
$conf
_item_id_code ne
$conf
_item_id
}
{
set error_p 1
}
if
{
$error
_p
}
{
if
{
$ns
_write_p
}
{
ns_write
"<li><font color=red>
Error
: We have found two different conf_items, one with
ns_write
"<li><font color=red>
Warning
: We have found two different conf_items, one with
'Conf_Item Nr'=
$conf
_item_nr and a second one with 'Conf_Item Name'='
$conf
_item_name'.<br>
Please change one of the two conf_items to avoid this ambiguity.
</font>
\n
"
}
continue
}
if
{
""
==
$conf
_item_id
}
{
set conf_item_id
$conf
_item_id2
}
# Check for problems with conf_item_code
set conf_item_code_exists_p
[
db_string conf_item_code_existis_p
"
select count(*)
from im_conf_items p
where p.conf_item_id != :conf_item_id and
lower(trim(conf_item_code)) = lower(trim(:conf_item_code))
"
]
if
{
""
!=
$conf
_item_code &&
$conf
_item_code_exists_p
}
{
if
{
$ns
_write_p
}
{
ns_write
"<li><font color=red>Error: conf_item_code='
$conf
_item_code' already exists in the system.</font>"
}
continue
}
# Create a new conf_item if necessary
if
{
""
==
$conf
_item_id
}
{
if
{
$ns
_write_p
}
{
ns_write
"<li>Going to create conf_item: name='
$conf
_item_name', nr='
$conf
_item_nr'
\n
"
}
# Default code for conf item.
# Conf item codes are unique system wide!
if
{
""
==
$conf
_item_code
}
{
set conf_item_code
[
db_string code
"select nextval('im_conf_item_code_seq') from dual"
]
}
set var_hash
(
conf_item_name
)
$conf
_item_name
set var_hash
(
conf_item_nr
)
$conf
_item_nr
set var_hash
(
conf_item_code
)
$conf
_item_code
...
...
@@ -332,6 +327,13 @@ foreach csv_line_fields $values_list_of_lists {
}
}
else
{
if
{
$ns
_write_p
}
{
ns_write
"<li>Conf_Item already exists: name='
$conf
_item_name', nr='
$conf
_item_nr', id='
$conf
_item_id'
\n
"
}
# Make sure to use the right code, which is unique system wide
db_1row conf_item_info
"
select conf_item_code
from im_conf_items
where conf_item_id = :conf_item_id
"
}
if
{
$ns
_write_p
}
{
ns_write
"<li>Going to update the conf_item.
\n
"
}
...
...
@@ -357,7 +359,7 @@ foreach csv_line_fields $values_list_of_lists {
# Add the conf_item lead to the list of conf_item members
if
{
""
!=
$conf
_item_owner_id
}
{
set role_id
[
im_biz_object_role_
conf_item_manag
er
]
set role_id
[
im_biz_object_role_
full_memb
er
]
im_biz_object_add_role
$conf
_item_owner_id
$conf
_item_id
$role
_id
}
...
...
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