-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.category.go
More file actions
121 lines (113 loc) · 5.04 KB
/
main.category.go
File metadata and controls
121 lines (113 loc) · 5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package main
import (
"bytes"
"encoding/xml"
"fmt"
"strings"
apiLib "github.com/hornbill/goApiLib"
)
//getCallCategoryID takes the Call Record and returns a correct Category ID if one exists on the Instance
func getCallCategoryID(callMap map[string]interface{}, categoryGroup string, espXmlmc *apiLib.XmlmcInstStruct, buffer *bytes.Buffer) (string, string) {
categoryID := ""
categoryString := ""
categoryNameMapping := ""
categoryCode := ""
if categoryGroup == "Request" {
categoryNameMapping = fmt.Sprintf("%v", mapGenericConf.CoreFieldMapping["h_category_id"])
categoryCode = getFieldValue(categoryNameMapping, callMap)
if swImportConf.CategoryMapping[categoryCode] != nil {
//Get Category Code from JSON mapping
categoryCode = fmt.Sprintf("%s", swImportConf.CategoryMapping[categoryCode])
} else {
//Mapping doesn't exist - replace hyphens from SW Profile code with another string, and try to use this
//SMProfileCodeSeperator allows us to specify in the config, the seperator used within Service Manager
//profile codes
categoryCode = strings.Replace(categoryCode, "-", swImportConf.SMProfileCodeSeperator, -1)
}
} else {
categoryNameMapping = fmt.Sprintf("%v", mapGenericConf.CoreFieldMapping["h_closure_category_id"])
categoryCode = getFieldValue(categoryNameMapping, callMap)
if swImportConf.ResolutionCategoryMapping[categoryCode] != nil {
//Get Category Code from JSON mapping
categoryCode = fmt.Sprintf("%s", swImportConf.ResolutionCategoryMapping[categoryCode])
} else {
//Mapping doesn't exist - replace hyphens from SW Profile code with colon, and try to use this
categoryCode = strings.Replace(categoryCode, "-", swImportConf.SMProfileCodeSeperator, -1)
}
}
if categoryCode != "" {
categoryID, categoryString = getCategoryID(categoryCode, categoryGroup, espXmlmc, buffer)
}
return categoryID, categoryString
}
//getCategoryID takes a Category Code string and returns a correct Category ID if one exists in the cache or on the Instance
func getCategoryID(categoryCode, categoryGroup string, espXmlmc *apiLib.XmlmcInstStruct, buffer *bytes.Buffer) (string, string) {
categoryID := ""
categoryString := ""
if categoryCode != "" {
categoryIsInCache, CategoryIDCache, CategoryNameCache := categoryInCache(categoryCode, categoryGroup+"Category")
//-- Check if we have cached the Category already
if categoryIsInCache {
categoryID = CategoryIDCache
categoryString = CategoryNameCache
} else {
categoryIsOnInstance, CategoryIDInstance, CategoryStringInstance := searchCategory(categoryCode, categoryGroup, espXmlmc, buffer)
//-- If Returned set output
if categoryIsOnInstance {
categoryID = CategoryIDInstance
categoryString = CategoryStringInstance
}
}
}
return categoryID, categoryString
}
// seachCategory -- Function to check if passed-through support category name is on the instance
func searchCategory(categoryCode, categoryGroup string, espXmlmc *apiLib.XmlmcInstStruct, buffer *bytes.Buffer) (bool, string, string) {
boolReturn := false
idReturn := ""
strReturn := ""
//-- ESP Query for category
espXmlmc.SetParam("codeGroup", categoryGroup)
espXmlmc.SetParam("code", categoryCode)
XMLCategorySearch, xmlmcErr := espXmlmc.Invoke("data", "profileCodeLookup")
if xmlmcErr != nil {
buffer.WriteString(loggerGen(4, "XMLMC API Invoke Failed for "+categoryGroup+" Category ["+categoryCode+"]: "+xmlmcErr.Error()))
return boolReturn, idReturn, strReturn
}
var xmlRespon xmlmcCategoryListResponse
err := xml.Unmarshal([]byte(XMLCategorySearch), &xmlRespon)
if err != nil {
buffer.WriteString(loggerGen(4, "Unable to unmarshal response for "+categoryGroup+" Category: "+err.Error()))
} else {
if xmlRespon.MethodResult != "ok" {
buffer.WriteString(loggerGen(5, "Unable to Search for "+categoryGroup+" Category ["+categoryCode+"]: ["+fmt.Sprintf("%v", xmlRespon.MethodResult)+"] "+xmlRespon.State.ErrorRet))
} else {
//-- Check Response
if xmlRespon.CategoryName != "" {
strReturn = xmlRespon.CategoryName
idReturn = xmlRespon.CategoryID
buffer.WriteString(loggerGen(3, "[CATEGORY] [SUCCESS] Methodcall result OK for "+categoryGroup+" Category ["+categoryCode+"] : ["+strReturn+"]"))
boolReturn = true
//-- Add Category to Cache
var newCategoryForCache categoryListStruct
newCategoryForCache.CategoryID = idReturn
newCategoryForCache.CategoryCode = categoryCode
newCategoryForCache.CategoryName = strReturn
categoryNamedMap := []categoryListStruct{newCategoryForCache}
switch categoryGroup {
case "Request":
mutexCategories.Lock()
categories = append(categories, categoryNamedMap...)
mutexCategories.Unlock()
case "Closure":
mutexCloseCategories.Lock()
closeCategories = append(closeCategories, categoryNamedMap...)
mutexCloseCategories.Unlock()
}
} else {
buffer.WriteString(loggerGen(5, "[CATEGORY] Methodcall result OK for "+categoryGroup+" Category ["+categoryCode+"] but category name blank: ["+xmlRespon.CategoryID+"] ["+xmlRespon.CategoryName+"]"))
}
}
}
return boolReturn, idReturn, strReturn
}