refactor(simulator): factor out template key deprecation handling
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 26 Mar 2023 14:58:01 +0000 (16:58 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 26 Mar 2023 14:58:01 +0000 (16:58 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts

index 831c662ef761b2c288ce7cddc24553e6500cab92..43fb6889fa65cfb48df6d44d599f328398d084ad 100644 (file)
@@ -854,6 +854,27 @@ export class ChargingStation {
     return template;
   }
 
+  private warnTemplateKeysDeprecation(stationTemplate: ChargingStationTemplate) {
+    const templateKeys: { key: string; deprecatedKey: string }[] = [
+      { key: 'supervisionUrls', deprecatedKey: 'supervisionUrl' },
+      { key: 'idTagsFile', deprecatedKey: 'authorizationFile' },
+    ];
+    for (const templateKey of templateKeys) {
+      ChargingStationUtils.warnDeprecatedTemplateKey(
+        stationTemplate,
+        templateKey.deprecatedKey,
+        this.templateFile,
+        this.logPrefix(),
+        `Use '${templateKey.key}' instead`
+      );
+      ChargingStationUtils.convertDeprecatedTemplateKey(
+        stationTemplate,
+        templateKey.deprecatedKey,
+        templateKey.key
+      );
+    }
+  }
+
   private getStationInfoFromTemplate(): ChargingStationInfo {
     const stationTemplate: ChargingStationTemplate | undefined = this.getTemplateFromFile();
     if (Utils.isNullOrUndefined(stationTemplate)) {
@@ -866,31 +887,7 @@ export class ChargingStation {
       logger.error(`${this.logPrefix()} ${errorMsg}`);
       throw new BaseError(errorMsg);
     }
-    // Deprecation template keys section
-    ChargingStationUtils.warnDeprecatedTemplateKey(
-      stationTemplate,
-      'supervisionUrl',
-      this.templateFile,
-      this.logPrefix(),
-      "Use 'supervisionUrls' instead"
-    );
-    ChargingStationUtils.convertDeprecatedTemplateKey(
-      stationTemplate,
-      'supervisionUrl',
-      'supervisionUrls'
-    );
-    ChargingStationUtils.warnDeprecatedTemplateKey(
-      stationTemplate,
-      'authorizationFile',
-      this.templateFile,
-      this.logPrefix(),
-      "Use 'idTagsFile' instead"
-    );
-    ChargingStationUtils.convertDeprecatedTemplateKey(
-      stationTemplate,
-      'authorizationFile',
-      'idTagsFile'
-    );
+    this.warnTemplateKeysDeprecation(stationTemplate);
     const stationInfo: ChargingStationInfo =
       ChargingStationUtils.stationTemplateToStationInfo(stationTemplate);
     stationInfo.hashId = ChargingStationUtils.getHashId(this.index, stationTemplate);