X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FIdTagsCache.ts;h=890ac1fbf12892a04c7afcde3e27d04f09845154;hb=178956d8c51c6a2b4ecc55b592dfb9ee339b8105;hp=a4ce9a100608d2959529b46995e38ed13788b0a0;hpb=7b5dbe910fc30484324da90ee209ab7002bc5071;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/IdTagsCache.ts b/src/charging-station/IdTagsCache.ts index a4ce9a10..890ac1fb 100644 --- a/src/charging-station/IdTagsCache.ts +++ b/src/charging-station/IdTagsCache.ts @@ -3,7 +3,7 @@ import fs from 'node:fs'; import type { ChargingStation } from './ChargingStation'; import { ChargingStationUtils } from './ChargingStationUtils'; import { FileType, IdTagDistribution } from '../types'; -import { ErrorUtils, FileUtils, Utils, logger } from '../utils'; +import { Utils, handleFileException, logger, watchJsonFile } from '../utils'; type IdTagsCacheValueType = { idTags: string[]; @@ -31,9 +31,9 @@ export class IdTagsCache { * Get one idtag from the cache given the distribution * Must be called after checking the cache is not an empty array * - * @param distribution - * @param chargingStation - * @param connectorId + * @param distribution - + * @param chargingStation - + * @param connectorId - * @returns */ public getIdTag( @@ -59,15 +59,12 @@ export class IdTagsCache { * Get all idtags from the cache * Must be called after checking the cache is not an empty array * - * @param file + * @param file - * @returns */ public getIdTags(file: string): string[] | undefined { if (this.hasIdTagsCache(file) === false) { - this.setIdTagsCache( - Utils.isNotEmptyString(file) ? file : 'empty', - this.getIdTagsFromFile(file) - ); + this.setIdTagsCache(file, this.getIdTagsFromFile(file)); } return this.getIdTagsCache(file); } @@ -119,7 +116,7 @@ export class IdTagsCache { private setIdTagsCache(file: string, idTags: string[]) { return this.idTagsCaches.set(file, { idTags, - idTagsFileWatcher: FileUtils.watchJsonFile( + idTagsFileWatcher: watchJsonFile( file, FileType.Authorization, this.logPrefix(file), @@ -133,7 +130,7 @@ export class IdTagsCache { this.deleteIdTagsCache(file); this.deleteIdTagsCacheIndexes(file); } catch (error) { - ErrorUtils.handleFileException( + handleFileException( file, FileType.Authorization, error as NodeJS.ErrnoException, @@ -175,7 +172,7 @@ export class IdTagsCache { try { return JSON.parse(fs.readFileSync(file, 'utf8')) as string[]; } catch (error) { - ErrorUtils.handleFileException( + handleFileException( file, FileType.Authorization, error as NodeJS.ErrnoException, @@ -183,7 +180,6 @@ export class IdTagsCache { ); } } - logger.info(`${this.logPrefix(file)} No id tags file given in configuration`); return []; }