[RICPLT-1783] Add ValidateAndBuildRanLoadInformationKey | Fix dependencies | Reformat...
[ric-plt/nodeb-rnib.git] / common / utils.go
1 //
2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //      http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16
17 package common
18
19 import (
20         "errors"
21         "fmt"
22 )
23
24 /*
25 ValidateAndBuildCellIdKey builds key according to the specified format returns the resulting string
26 */
27 func ValidateAndBuildCellIdKey(cellId string) (string, IRNibError) {
28         if cellId == "" {
29                 e := errors.New("#utils.ValidateAndBuildCellIdKey - an empty cell id received")
30                 return "", NewValidationError(e)
31         }
32         return fmt.Sprintf("CELL:%s", cellId), nil
33 }
34
35 /*
36 ValidateAndBuildNrCellIdKey builds key according to the specified format returns the resulting string
37 */
38 func ValidateAndBuildNrCellIdKey(cellId string) (string, IRNibError) {
39         if cellId == "" {
40                 e := errors.New("#utils.ValidateAndBuildNrCellIdKey - an empty cell id received")
41                 return "", NewValidationError(e)
42         }
43         return fmt.Sprintf("NRCELL:%s", cellId), nil
44 }
45
46 /*
47 ValidateAndBuildNodeBNameKey builds key according to the specified format returns the resulting string
48 */
49 func ValidateAndBuildNodeBNameKey(inventoryName string) (string, IRNibError) {
50         if inventoryName == "" {
51                 e := errors.New("#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received")
52                 return "", NewValidationError(e)
53         }
54         return fmt.Sprintf("RAN:%s", inventoryName), nil
55 }
56
57 /*
58 ValidateAndBuildNodeBIdKey builds key according to the specified format returns the resulting string
59 */
60 func ValidateAndBuildNodeBIdKey(nodeType string, plmnId string, nbId string) (string, IRNibError) {
61         if nodeType == "" {
62                 e := errors.New("#utils.ValidateAndBuildNodeBIdKey - an empty node type received")
63                 return "", NewValidationError(e)
64         }
65         if plmnId == "" {
66                 e := errors.New("#utils.ValidateAndBuildNodeBIdKey - an empty plmnId received")
67                 return "", NewValidationError(e)
68         }
69         if nbId == "" {
70                 e := errors.New("#utils.ValidateAndBuildNodeBIdKey - an empty nbId received")
71                 return "", NewValidationError(e)
72         }
73         return fmt.Sprintf("%s:%s:%s", nodeType, plmnId, nbId), nil
74 }
75
76 /*
77 ValidateAndBuildCellNamePciKey builds key according to the specified format returns the resulting string
78 */
79 func ValidateAndBuildCellNamePciKey(inventoryName string, pci uint32) (string, IRNibError) {
80         if inventoryName == "" {
81                 e := errors.New("#utils.ValidateAndBuildCellNamePciKey - an empty inventory name received")
82                 return "", NewValidationError(e)
83         }
84         return fmt.Sprintf("PCI:%s:%02x", inventoryName, pci), nil
85 }
86
87 func ValidateAndBuildRanLoadInformationKey(inventoryName string) (string, IRNibError) {
88
89         if inventoryName == "" {
90                 e := errors.New("#utils.ValidateAndBuildRanLoadInformationKey - an empty inventory name received")
91                 return "", NewValidationError(e)
92         }
93
94         return fmt.Sprintf("LOAD:%s", inventoryName), nil
95 }