Add worker configuration section
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStationUtils.ts
index c63a7f27e67411558c7f6f42b3be66859e2fecfa..7208fb80fe383fa916836306d63c33d9405f634a 100644 (file)
@@ -14,15 +14,13 @@ import { ChargingStationConfigurationUtils } from './ChargingStationConfiguratio
 import ChargingStationInfo from '../types/ChargingStationInfo';
 import Configuration from '../utils/Configuration';
 import Constants from '../utils/Constants';
-import { FileType } from '../types/FileType';
-import FileUtils from '../utils/FileUtils';
 import { SampledValueTemplate } from '../types/MeasurandPerPhaseSampledValueTemplates';
 import { StandardParametersKey } from '../types/ocpp/Configuration';
 import Utils from '../utils/Utils';
 import { WebSocketCloseEventStatusString } from '../types/WebSocket';
 import { WorkerProcessType } from '../types/Worker';
 import crypto from 'crypto';
-import fs from 'fs';
+import { fileURLToPath } from 'url';
 import logger from '../utils/Logger';
 import moment from 'moment';
 import path from 'path';
@@ -159,12 +157,12 @@ export class ChargingStationUtils {
 
   public static workerPoolInUse(): boolean {
     return [WorkerProcessType.DYNAMIC_POOL, WorkerProcessType.STATIC_POOL].includes(
-      Configuration.getWorkerProcess()
+      Configuration.getWorker().processType
     );
   }
 
   public static workerDynamicPoolInUse(): boolean {
-    return Configuration.getWorkerProcess() === WorkerProcessType.DYNAMIC_POOL;
+    return Configuration.getWorker().processType === WorkerProcessType.DYNAMIC_POOL;
   }
 
   /**
@@ -235,20 +233,11 @@ export class ChargingStationUtils {
   }
 
   public static createStationInfoHash(stationInfo: ChargingStationInfo): void {
-    const previousInfoHash = stationInfo?.infoHash ?? '';
     delete stationInfo.infoHash;
-    const currentInfoHash = crypto
+    stationInfo.infoHash = crypto
       .createHash(Constants.DEFAULT_HASH_ALGORITHM)
       .update(JSON.stringify(stationInfo))
       .digest('hex');
-    if (
-      Utils.isEmptyString(previousInfoHash) ||
-      (!Utils.isEmptyString(previousInfoHash) && currentInfoHash !== previousInfoHash)
-    ) {
-      stationInfo.infoHash = currentInfoHash;
-    } else {
-      stationInfo.infoHash = previousInfoHash;
-    }
   }
 
   public static createSerialNumber(
@@ -525,36 +514,11 @@ export class ChargingStationUtils {
     );
   }
 
-  public static getAuthorizedTags(
-    stationInfo: ChargingStationInfo,
-    templateFile: string,
-    logPrefix: string
-  ): string[] {
-    let authorizedTags: string[] = [];
-    const authorizationFile = ChargingStationUtils.getAuthorizationFile(stationInfo);
-    if (authorizationFile) {
-      try {
-        // Load authorization file
-        authorizedTags = JSON.parse(fs.readFileSync(authorizationFile, 'utf8')) as string[];
-      } catch (error) {
-        FileUtils.handleFileException(
-          logPrefix,
-          FileType.Authorization,
-          authorizationFile,
-          error as NodeJS.ErrnoException
-        );
-      }
-    } else {
-      logger.info(logPrefix + ' No authorization file given in template file ' + templateFile);
-    }
-    return authorizedTags;
-  }
-
   public static getAuthorizationFile(stationInfo: ChargingStationInfo): string | undefined {
     return (
       stationInfo.authorizationFile &&
       path.join(
-        path.resolve(__dirname, '../'),
+        path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../'),
         'assets',
         path.basename(stationInfo.authorizationFile)
       )