possible fix for third project section.
This commit is contained in:
parent
1fbe8579ba
commit
3b37b18581
100
main/main.go
100
main/main.go
@ -34,12 +34,15 @@ func MPE_IsProject(input *Payload) (projectnumber string, project_name string) {
|
|||||||
separated_path := strings.Split(split_path, "/") //turn this into an array (slice?) to parse
|
separated_path := strings.Split(split_path, "/") //turn this into an array (slice?) to parse
|
||||||
var sb strings.Builder
|
var sb strings.Builder
|
||||||
// iterate through the path_data map. We want to find all strings that start with a number.
|
// iterate through the path_data map. We want to find all strings that start with a number.
|
||||||
for _, value := range separated_path {
|
for keyvalue, value := range separated_path {
|
||||||
matched := project_regex.MatchString(value)
|
matched := project_regex.MatchString(value)
|
||||||
if matched {
|
// Possible Fix for Project 3rd Number ID.
|
||||||
|
ProjectSection := keyvalue == 2|3|4 // /shared<0>/N-Data<1>/<2>/<3>/<4>/<5>/<6>
|
||||||
|
|
||||||
|
if matched && ProjectSection {
|
||||||
// if we match the Regex above, write values to SB. This will give us a string like "73|10 Office Of Somone|153 HelpMe|002 Phase 2"
|
// if we match the Regex above, write values to SB. This will give us a string like "73|10 Office Of Somone|153 HelpMe|002 Phase 2"
|
||||||
|
|
||||||
sb.WriteString(value + "|")
|
sb.WriteString(value + "|") // add pipe separator
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// DoNothing
|
// DoNothing
|
||||||
@ -49,61 +52,64 @@ func MPE_IsProject(input *Payload) (projectnumber string, project_name string) {
|
|||||||
// now to assemble project number and project name from the resulting values...
|
// now to assemble project number and project name from the resulting values...
|
||||||
project_text := sb.String()
|
project_text := sb.String()
|
||||||
project_slice := strings.Split(project_text, "|")
|
project_slice := strings.Split(project_text, "|")
|
||||||
// first value should be a digit, if not this can't be a project
|
if strings.Count(project_text, "|") > 2 { // if more than 2 pipe | chars in string, could be a project.
|
||||||
isProject0, err := regexp.MatchString(`(^[0-9])`, project_slice[0])
|
// first value should be a digit, if not this can't be a project
|
||||||
if err != nil {
|
isProject0, err := regexp.MatchString(`(^[0-9])`, project_slice[0])
|
||||||
fmt.Printf("err.Error(): %v\n", err.Error())
|
if err != nil {
|
||||||
}
|
fmt.Printf("err.Error(): %v\n", err.Error())
|
||||||
isProject1, err := regexp.MatchString(`(^[0-9])`, project_slice[1])
|
}
|
||||||
if err != nil {
|
isProject1, err := regexp.MatchString(`(^[0-9])`, project_slice[1])
|
||||||
fmt.Printf("err.Error(): %v\n", err.Error())
|
if err != nil {
|
||||||
}
|
fmt.Printf("err.Error(): %v\n", err.Error())
|
||||||
isProject2, err := regexp.MatchString(`(^[0-9])`, project_slice[2])
|
}
|
||||||
if err != nil {
|
isProject2, err := regexp.MatchString(`(^[0-9])`, project_slice[2])
|
||||||
fmt.Printf("err.Error(): %v\n", err.Error())
|
if err != nil {
|
||||||
}
|
fmt.Printf("err.Error(): %v\n", err.Error())
|
||||||
// isProject, _ = regexp.MatchString(`(^[0-9])`, project_slice[3])
|
}
|
||||||
if isProject0 && isProject1 && isProject2 {
|
// isProject, _ = regexp.MatchString(`(^[0-9])`, project_slice[3])
|
||||||
|
if isProject0 && isProject1 && isProject2 {
|
||||||
|
|
||||||
project_regex, _ := regexp.Compile(`(^[0-9]{1,3})`) // regex to match against
|
project_regex, _ := regexp.Compile(`(^[0-9]{1,3})`) // regex to match against
|
||||||
regex_tidy_string, _ := regexp.Compile(`[-_]+|^\s`) //regex to tidy up folder paths
|
regex_tidy_string, _ := regexp.Compile(`[-_]+|^\s`) //regex to tidy up folder paths
|
||||||
client_section := regex_tidy_string.ReplaceAllString(project_slice[1], "") // remove fancy chars from Client Name
|
client_section := regex_tidy_string.ReplaceAllString(project_slice[1], "") // remove fancy chars from Client Name
|
||||||
project_section := regex_tidy_string.ReplaceAllString(project_regex.ReplaceAllString(project_slice[2], ""), " ") // remove leading-digits
|
project_section := regex_tidy_string.ReplaceAllString(project_regex.ReplaceAllString(project_slice[2], ""), " ") // remove leading-digits
|
||||||
project_section_digits := strings.Split(regex_tidy_string.ReplaceAllString(project_slice[2], " "), " ") //split on space for MOST file folders...
|
project_section_digits := strings.Split(regex_tidy_string.ReplaceAllString(project_slice[2], " "), " ") //split on space for MOST file folders...
|
||||||
|
|
||||||
sb.Reset() // reset string builder so I can use it again!
|
sb.Reset() // reset string builder so I can use it again!
|
||||||
sb.WriteString(project_slice[0]) // 73
|
sb.WriteString(project_slice[0]) // 73
|
||||||
sb.WriteString(strings.Split(client_section, " ")[0] + "-") // 7310 -- Client Name
|
sb.WriteString(strings.Split(client_section, " ")[0] + "-") // 7310 -- Client Name
|
||||||
sb.WriteString(project_section_digits[0]) // 7310-10
|
sb.WriteString(project_section_digits[0]) // 7310-10
|
||||||
|
|
||||||
// do we have a third section of the project number?
|
// do we have a third section of the project number?
|
||||||
project_third := strings.Split(project_slice[3], " ")[0]
|
project_third := strings.Split(project_slice[3], " ")[0]
|
||||||
project_third_match, _ := regexp.MatchString(`(^[0-9]{1,3})`, project_third)
|
project_third_match, _ := regexp.MatchString(`(^[0-9]{1,3})`, project_third)
|
||||||
/* TODO: Better identification of the third number.
|
/* TODO: Better identification of the third number.
|
||||||
Currently seeing paths such as "/shared/n-data/12/34 test/45 ProjectName/deliverables/05 geotech" generating project numbers of 1234-45-05,
|
Currently seeing paths such as "/shared/n-data/12/34 test/45 ProjectName/deliverables/05 geotech" generating project numbers of 1234-45-05,
|
||||||
where it should be 1234-45
|
where it should be 1234-45
|
||||||
|
|
||||||
This is due to the RegEx Match looking for all folders that start with digits, and not being concerned about where they are in the string.
|
This is due to the RegEx Match looking for all folders that start with digits, and not being concerned about where they are in the string.
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
if project_third_match {
|
if project_third_match {
|
||||||
// if we have a third section, then add another section to the project number, and append to the project name
|
// if we have a third section, then add another section to the project number, and append to the project name
|
||||||
third_project_name := project_regex.ReplaceAllString(project_slice[3], "") // 7310-10-153
|
third_project_name := project_regex.ReplaceAllString(project_slice[3], "") // 7310-10-153
|
||||||
project_name = project_section + "-" + regex_tidy_string.ReplaceAllString(third_project_name, "") // remove project digits from beginning of string and append
|
project_name = project_section + "-" + regex_tidy_string.ReplaceAllString(third_project_name, "") // remove project digits from beginning of string and append
|
||||||
project_third = regex_tidy_string.ReplaceAllString(project_third, " ")
|
project_third = regex_tidy_string.ReplaceAllString(project_third, " ")
|
||||||
sb.WriteString("-" + project_third)
|
sb.WriteString("-" + project_third)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
project_name = project_section // remove project digits from beginning of string
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
projectnumber = sb.String() // I should now have a project number!
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
project_name = project_section // remove project digits from beginning of string
|
return "NotAProject", "NoPath"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
projectnumber = sb.String() // I should now have a project number!
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return "NotAProject", "NoPath"
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user