Use car storage
Fixed typos in logging
Add try...catch in for loop
Use new Server Type to ID the logs
MODIFY
src/bootstrap/LocalCarCatalogBootstrap.ts
src/bootstrap/LocalCarCatalogBootstrap.ts
@@ -19,6 +19,7 @@ export default class LocalCarCatalogBootstrap {
const cars = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/cars/cars-definition.json`, 'utf8'));
if (!Utils.isEmptyArray(cars)) {
for (const car of cars) {
+ try {
const chargeStandardTables: CarCatalogConverter[] = [];
const chargeAlternativeTables: CarCatalogChargeAlternativeTable[] = [];
const chargeOptionTables: CarCatalogChargeOptionTable[] = [];
@@ -28,7 +29,8 @@ export default class LocalCarCatalogBootstrap {
evsePhaseVolt: car.Charge_Standard_Table[chargeStandard].EVSE_PhaseVolt,
evsePhaseAmp: car.Charge_Standard_Table[chargeStandard].EVSE_PhaseAmp,
evsePhase: car.Charge_Standard_Table[chargeStandard].EVSE_Phase,
- evsePhaseVoltCalculated: car.Charge_Standard_Table[chargeStandard].EVSE_Phase === 3 ? Voltage.VOLTAGE_400 : car.Charge_Standard_Table[chargeStandard].EVSE_PhaseVolt,
+ evsePhaseVoltCalculated: car.Charge_Standard_Table[chargeStandard].EVSE_Phase === 3 ?
+ Voltage.VOLTAGE_400 : car.Charge_Standard_Table[chargeStandard].EVSE_PhaseVolt,
chargePhaseVolt: car.Charge_Standard_Table[chargeStandard].Charge_PhaseVolt,
chargePhaseAmp: car.Charge_Standard_Table[chargeStandard].Charge_PhaseAmp,
chargePhase: car.Charge_Standard_Table[chargeStandard].Charge_Phase,
@@ -193,12 +195,9 @@ export default class LocalCarCatalogBootstrap {
const thumbImageMIME = thumbImage.getMIME();
const base64ThumbImage = await thumbImage.getBase64Async(thumbImageMIME);
carCatalog.image = base64ThumbImage;
- await global.database.getCollection<any>(Constants.DEFAULT_TENANT, 'carcatalogs').deleteOne({
- _id: carCatalog.id
- });
- await global.database.getCollection<any>(Constants.DEFAULT_TENANT, 'carcatalogimages').deleteMany({
- carID: carCatalog.id
- });
+ // Delete Car Catalog
+ await CarStorage.deleteCarCatalog(carCatalog.id);
+ await CarStorage.deleteCarCatalogImages(carCatalog.id);
carCatalog.createdOn = new Date();
carCatalog.lastChangedOn = carCatalog.createdOn;
for (const imageURL of carCatalog.imageURLs) {
@@ -207,29 +206,42 @@ export default class LocalCarCatalogBootstrap {
const imageMIME = image.getMIME();
const base64Image = await image.getBase64Async(imageMIME);
// Save car catalog images
- await CarStorage.saveCarImage(carCatalog.id, base64Image);
+ await CarStorage.saveCarCatalogImage(carCatalog.id, base64Image);
}
// Save
await CarStorage.saveCarCatalog(carCatalog);
created++;
+ } catch (error) {
+ const message = `Error while importing the local Car ID '${car.Vehicle_ID as string}': ${error.message as string}`;
+ await Logging.logError({
+ tenantID: Constants.DEFAULT_TENANT,
+ action: ServerAction.UPDATE_LOCAL_CAR_CATALOGS,
+ module: MODULE_NAME, method: 'uploadLocalCarCatalogsFromFile',
+ message, detailedMessages: { error: error.stack }
+ });
+ Utils.isDevelopmentEnv() && Logging.logConsoleError(message);
+ }
}
}
} catch (error) {
+ const message = `Error while importing the local Cars: ${error.message as string}`;
await Logging.logError({
tenantID: Constants.DEFAULT_TENANT,
- module: MODULE_NAME, method: 'importLocalCarCatalog',
- action: ServerAction.CAR_CATALOG_SYNCHRONIZATION,
- message: `Error while importing the local Cars: ${error.message}`,
- detailedMessages: { error: error.message, stack: error.stack }
+ action: ServerAction.UPDATE_LOCAL_CAR_CATALOGS,
+ module: MODULE_NAME, method: 'uploadLocalCarCatalogsFromFile',
+ message, detailedMessages: { error: error.stack }
});
- } // Log in the default tenant
+ Utils.isDevelopmentEnv() && Logging.logConsoleError(message);
+ }
+ // Log in the default tenant
if (created > 0) {
+ const message = `${created} local Car(s) catalog created in the default tenant`;
await Logging.logDebug({
tenantID: Constants.DEFAULT_TENANT,
- action: ServerAction.CAR_CATALOG_SYNCHRONIZATION,
- module: MODULE_NAME, method: 'importLocalCarCatalog',
- message: `${created} local Car(s) catalog created in the default tenant`
+ action: ServerAction.UPDATE_LOCAL_CAR_CATALOGS,
+ message, module: MODULE_NAME, method: 'uploadLocalCarCatalogsFromFile',
});
+ Utils.isDevelopmentEnv() && Logging.logConsoleInfo(message);
}
}
}

MODIFY
src/integration/car/CarIntegration.ts
src/integration/car/CarIntegration.ts
@@ -29,11 +29,11 @@ export default abstract class CarIntegration {
// Get thumbnail image
externalCar.image = await this.getCarCatalogThumb(externalCar);
// Delete old car catalogs images
- await CarStorage.deleteCarImages(externalCar.id);
+ await CarStorage.deleteCarCatalogImages(externalCar.id);
// Get images
for (const imageURL of externalCar.imageURLs) {
const image = await this.getCarCatalogImage(externalCar, imageURL);
- await CarStorage.saveCarImage(externalCar.id, image);
+ await CarStorage.saveCarCatalogImage(externalCar.id, image);
}
// Create the images hash
externalCar.imagesHash = externalCarImagesHash;
@@ -58,12 +58,12 @@ export default abstract class CarIntegration {
// Get thumbnail image
externalCar.image = await this.getCarCatalogThumb(externalCar);
// Delete old car catalogs images
- await CarStorage.deleteCarImages(externalCar.id);
+ await CarStorage.deleteCarCatalogImages(externalCar.id);
// Get images
for (const imageURL of externalCar.imageURLs) {
// Get images
const image = await this.getCarCatalogImage(externalCar, imageURL);
- await CarStorage.saveCarImage(externalCar.id, image);
+ await CarStorage.saveCarCatalogImage(externalCar.id, image);
}
// Create the Hash
externalCar.imagesHash = externalCarImagesHash;

MODIFY
src/start.ts
src/start.ts
@@ -133,6 +133,8 @@ export default class Bootstrap {
// Log
await this.logDuration(startTimeMillis, 'Async Task manager has been started successfully');
+ // Update of manually uploaded data
+ if (Bootstrap.migrationConfig.active) {
// -------------------------------------------------------------------------
// Update Charging Station Templates
// -------------------------------------------------------------------------
@@ -150,6 +152,7 @@ export default class Bootstrap {
await LocalCarCatalogBootstrap.uploadLocalCarCatalogsFromFile();
// Log
await this.logDuration(startTimeMillis, 'Local car catalogs has been imported successfully');
+ }
// Keep the server names globally
if (serverStarted.length === 1) {

MODIFY
src/storage/mongodb/CarStorage.ts
src/storage/mongodb/CarStorage.ts
@@ -314,28 +314,28 @@ export default class CarStorage {
return carToSave.id;
}
- public static async saveCarImage(carID: number, carImageToSave: string): Promise<void> {
+ public static async saveCarCatalogImage(id: number, carImageToSave: string): Promise<void> {
// Debug
const startTime = Logging.traceDatabaseRequestStart();
// Save new image
await global.database.getCollection<any>(Constants.DEFAULT_TENANT, 'carcatalogimages').findOneAndReplace(
- { _id: Utils.hash(`${carImageToSave}~${carID}`), },
- { carID: Utils.convertToInt(carID), image: carImageToSave },
+ { _id: Utils.hash(`${carImageToSave}~${id}`), },
+ { carID: Utils.convertToInt(id), image: carImageToSave },
{ upsert: true }
);
// Debug
await Logging.traceDatabaseRequestEnd(Constants.DEFAULT_TENANT_OBJECT, MODULE_NAME, 'saveCarImage', startTime, carImageToSave);
}
- public static async deleteCarImages(carID: number): Promise<void> {
+ public static async deleteCarCatalogImages(id: number): Promise<void> {
// Debug
const startTime = Logging.traceDatabaseRequestStart();
// Delete car catalogs images
await global.database.getCollection(Constants.DEFAULT_TENANT, 'carcatalogimages').deleteMany(
- { carID: Utils.convertToInt(carID) }
+ { carID: id }
);
// Debug
- await Logging.traceDatabaseRequestEnd(Constants.DEFAULT_TENANT_OBJECT, MODULE_NAME, 'deleteCarImages', startTime, { carID });
+ await Logging.traceDatabaseRequestEnd(Constants.DEFAULT_TENANT_OBJECT, MODULE_NAME, 'deleteCarImages', startTime, { carID: id });
}
public static async getCarCatalogImage(id: number): Promise<{ id: number; image: string }> {
@@ -742,4 +742,14 @@ export default class CarStorage {
// Debug
await Logging.traceDatabaseRequestEnd(tenant, MODULE_NAME, 'deleteCar', startTime, { carID });
}
+
+ public static async deleteCarCatalog(id: number): Promise<void> {
+ // Debug
+ const startTime = Logging.traceDatabaseRequestStart();
+ // Delete singular site area
+ await global.database.getCollection(Constants.DEFAULT_TENANT, 'carcatalogs')
+ .deleteOne({ '_id': id });
+ // Debug
+ await Logging.traceDatabaseRequestEnd(Constants.DEFAULT_TENANT_OBJECT, MODULE_NAME, 'deleteCarCatalog', startTime, { carID: id });
+ }
}

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -279,6 +279,7 @@ export enum ServerAction {
USER_CREATE_PASSWORD = 'UserCreatePassword',
ADMIN_ACCOUNT_VERIFICATION = 'AdminAccountVerificationNotification',
+ UPDATE_LOCAL_CAR_CATALOGS = 'UpdateLocalCarCatalogs',
CAR_CATALOG_SYNCHRONIZATION_FAILED = 'CarCatalogSynchronizationFailed',
CAR_CATALOG_SYNCHRONIZATION = 'CarCatalogSynchronization',
SESSION_NOT_STARTED_AFTER_AUTHORIZE = 'SessionNotStartedAfterAuthorize',

Use car storage
Fixed typos in logging
Add try...catch in for loop
Use new Server Type to ID the logs