Add bootstrap class
DELETE
src/assets/ups-template-e-Mobility-credentials.json
-{
- "evDBKey": "",
- "smtpUsername": "",
- "smtpPassword": "",
- "smtpBackupUsername": "",
- "smtpBackupPassword": "",
- "userTokenKey": "",
- "captchaSecretKey": "",
- "cryptoKey": "",
- "firebasePrivateKeyID": "",
- "firebasePrivateKey": ""
-}

ADD
src/bootstrap/ChargingStationTemplate.ts
+import ChargingStationStorage from '../storage/mongodb/ChargingStationStorage';
+import { ChargingStationTemplate } from '../types/ChargingStation';
+import Configuration from '../utils/Configuration';
+import Constants from '../utils/Constants';
+import Logging from '../utils/Logging';
+import { ServerAction } from '../types/Server';
+import Utils from '../utils/Utils';
+import fs from 'fs';
+
+export default class ChargingStationBootstrapTemplate {
+ public static async updateChargingStationTemplatesFromFile(): Promise<void> {
+ // Read File
+ let chargingStationTemplates: ChargingStationTemplate[];
+ try {
+ chargingStationTemplates = JSON.parse(fs.readFileSync(Configuration.getChargingStationTemplatesConfig().templatesFilePath, 'utf8'));
+ } catch (error) {
+ await Logging.logActionExceptionMessage(Constants.DEFAULT_TENANT, ServerAction.UPDATE_CHARGING_STATION_TEMPLATES, error);
+ return;
+ }
+ // Delete all previous templates
+ await ChargingStationStorage.deleteChargingStationTemplates();
+ // Update Templates
+ for (const chargingStationTemplate of chargingStationTemplates) {
+ try {
+ // Set the hashes
+ chargingStationTemplate.hash = Utils.hash(JSON.stringify(chargingStationTemplate));
+ chargingStationTemplate.hashTechnical = Utils.hash(JSON.stringify(chargingStationTemplate.technical));
+ chargingStationTemplate.hashCapabilities = Utils.hash(JSON.stringify(chargingStationTemplate.capabilities));
+ chargingStationTemplate.hashOcppStandard = Utils.hash(JSON.stringify(chargingStationTemplate.ocppStandardParameters));
+ chargingStationTemplate.hashOcppVendor = Utils.hash(JSON.stringify(chargingStationTemplate.ocppVendorParameters));
+ // Save
+ await ChargingStationStorage.saveChargingStationTemplate(chargingStationTemplate);
+ } catch (error) {
+ error.message = `Charging Station Template ID '${chargingStationTemplate.id}' is not valid: ${error.message as string}`;
+ await Logging.logActionExceptionMessage(Constants.DEFAULT_TENANT, ServerAction.UPDATE_CHARGING_STATION_TEMPLATES, error);
+ Utils.isDevelopmentEnv() && Logging.logConsoleError(error.message);
+ }
+ }
+ }
+}

MODIFY
src/start.ts
src/start.ts
@@ -4,9 +4,9 @@ import { ServerAction, ServerType } from './types/Server';
import AsyncTaskManager from './async-task/AsyncTaskManager';
import CentralRestServer from './server/rest/CentralRestServer';
import CentralSystemRestServiceConfiguration from './types/configuration/CentralSystemRestServiceConfiguration';
+import ChargingStationBootstrapTemplate from './bootstrap/ChargingStationTemplate';
import ChargingStationConfiguration from './types/configuration/ChargingStationConfiguration';
import ChargingStationStorage from './storage/mongodb/ChargingStationStorage';
-import { ChargingStationTemplate } from './types/ChargingStation';
import Configuration from './utils/Configuration';
import Constants from './utils/Constants';
import I18nManager from './utils/I18nManager';
@@ -25,7 +25,6 @@ import SchedulerManager from './scheduler/SchedulerManager';
import SoapCentralSystemServer from './server/ocpp/soap/SoapCentralSystemServer';
import StorageConfiguration from './types/configuration/StorageConfiguration';
import Utils from './utils/Utils';
-import fs from 'fs';
import global from './types/GlobalType';
const MODULE_NAME = 'Bootstrap';
@@ -139,7 +138,7 @@ export default class Bootstrap {
// -------------------------------------------------------------------------
startTimeMillis = await this.logAndGetStartTimeMillis('Charging Station templates is being updated...');
// Load and Save the Charging Station templates
- await this.updateChargingStationTemplatesFromFile();
+ await ChargingStationBootstrapTemplate.updateChargingStationTemplatesFromFile();
// Log
await this.logDuration(startTimeMillis, 'Charging Station templates have been updated successfully');
@@ -163,36 +162,6 @@ export default class Bootstrap {
}
}
- private static async updateChargingStationTemplatesFromFile(): Promise<void> {
- // Read File
- let chargingStationTemplates: ChargingStationTemplate[];
- try {
- chargingStationTemplates = JSON.parse(fs.readFileSync(Configuration.getChargingStationTemplatesConfig().templatesFilePath, 'utf8'));
- } catch (error) {
- await Logging.logActionExceptionMessage(Constants.DEFAULT_TENANT, ServerAction.UPDATE_CHARGING_STATION_TEMPLATES, error);
- return;
- }
- // Delete all previous templates
- await ChargingStationStorage.deleteChargingStationTemplates();
- // Update Templates
- for (const chargingStationTemplate of chargingStationTemplates) {
- try {
- // Set the hashes
- chargingStationTemplate.hash = Utils.hash(JSON.stringify(chargingStationTemplate));
- chargingStationTemplate.hashTechnical = Utils.hash(JSON.stringify(chargingStationTemplate.technical));
- chargingStationTemplate.hashCapabilities = Utils.hash(JSON.stringify(chargingStationTemplate.capabilities));
- chargingStationTemplate.hashOcppStandard = Utils.hash(JSON.stringify(chargingStationTemplate.ocppStandardParameters));
- chargingStationTemplate.hashOcppVendor = Utils.hash(JSON.stringify(chargingStationTemplate.ocppVendorParameters));
- // Save
- await ChargingStationStorage.saveChargingStationTemplate(chargingStationTemplate);
- } catch (error) {
- error.message = `Charging Station Template ID '${chargingStationTemplate.id}' is not valid: ${error.message as string}`;
- await Logging.logActionExceptionMessage(Constants.DEFAULT_TENANT, ServerAction.UPDATE_CHARGING_STATION_TEMPLATES, error);
- Utils.isDevelopmentEnv() && Logging.logConsoleError(error.message);
- }
- }
- }
-
private static async logAndGetStartTimeMillis(logMessage: string): Promise<number> {
const timeStartMillis = Date.now();
Logging.logConsoleDebug(logMessage);

Add bootstrap class