2 // ========================LICENSE_START=================================
5 // Copyright (C) 2021: Nordix Foundation
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 // ========================LICENSE_END===================================
27 type IdNotMappedError struct {
31 func (inme IdNotMappedError) Error() string {
32 return fmt.Sprintf("O-RU-ID: %v not mapped.", inme.Id)
35 type LookupService interface {
37 GetODuID(oRuId string) (string, error)
40 type LookupServiceImpl struct {
41 csvFileHelper CsvFileHelper
44 oRuIdToODuIdMap map[string]string
47 func NewLookupServiceImpl(fileHelper CsvFileHelper, fileName string) *LookupServiceImpl {
48 s := LookupServiceImpl{
49 csvFileHelper: fileHelper,
50 csvFileName: fileName,
52 s.oRuIdToODuIdMap = make(map[string]string)
56 func (s LookupServiceImpl) Init() error {
57 if csvData, err := s.csvFileHelper.GetCsvFromFile(s.csvFileName); err == nil {
58 for _, each := range csvData {
59 s.oRuIdToODuIdMap[each[0]] = each[1]
67 func (s LookupServiceImpl) GetODuID(oRuId string) (string, error) {
68 if oDuId, ok := s.oRuIdToODuIdMap[oRuId]; ok {
71 return "", IdNotMappedError{Id: oRuId}