From e098128fb613d21c2caacc9d4144beecb1820065 Mon Sep 17 00:00:00 2001 From: ClaudeROSSI Date: Mon, 27 Mar 2023 18:15:29 +0200 Subject: [PATCH 1/5] remote push notifications - less logs --- .../RemotePushNotificationTask.ts | 62 ++++++++++--------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/src/notification/remote-push-notification/RemotePushNotificationTask.ts b/src/notification/remote-push-notification/RemotePushNotificationTask.ts index cfffbc274b..66227f3280 100644 --- a/src/notification/remote-push-notification/RemotePushNotificationTask.ts +++ b/src/notification/remote-push-notification/RemotePushNotificationTask.ts @@ -491,20 +491,24 @@ export default class RemotePushNotificationTask implements NotificationTask { // Do it startTime = Logging.traceNotificationStart(); if (!user?.mobileData?.mobileToken) { - await Logging.logDebug({ - tenantID: tenant.id, - siteID: data?.siteID, - siteAreaID: data?.siteAreaID, - companyID: data?.companyID, - chargingStationID: data?.chargeBoxID, - action: ServerAction.REMOTE_PUSH_NOTIFICATION, - module: MODULE_NAME, method: 'sendRemotePushNotificationToUsers', - message: `'${notificationType}': No mobile token found for this User`, - actionOnUser: user.id, - }); + // await Logging.logDebug({ + // tenantID: tenant.id, + // siteID: data?.siteID, + // siteAreaID: data?.siteAreaID, + // companyID: data?.companyID, + // chargingStationID: data?.chargeBoxID, + // action: ServerAction.REMOTE_PUSH_NOTIFICATION, + // module: MODULE_NAME, method: 'sendRemotePushNotificationToUsers', + // message: `'${notificationType}': No mobile token found for this User`, + // actionOnUser: user.id, + // }); // Send nothing return Promise.resolve(); } + if (!user?.mobileData?.mobileVersion) { + // Stop sending notifications to old version of the mobile app + return Promise.resolve(); + } // Create message message = this.createMessage(tenant, notificationType, title, body, data, severity); // Get the right firebase apps @@ -524,7 +528,7 @@ export default class RemotePushNotificationTask implements NotificationTask { ); // Error if (response.failureCount > 0) { - void Logging.logError({ + Logging.logError({ tenantID: tenant.id, siteID: data?.siteID, siteAreaID: data?.siteAreaID, @@ -532,28 +536,28 @@ export default class RemotePushNotificationTask implements NotificationTask { chargingStationID: data?.chargeBoxID, action: ServerAction.REMOTE_PUSH_NOTIFICATION, module: MODULE_NAME, method: 'sendRemotePushNotificationToUsers', - message: `Error when sending Notification: '${notificationType}' - Error code: '${response.results[0]?.error?.code}'`, + message: `Notification: '${notificationType}' - Error code: '${response.results[0]?.error?.code}'`, actionOnUser: user.id, - detailedMessages: { response } - }); + detailedMessages: { response, mobileData: user.mobileData } + }).catch((error) => Logging.logPromiseError(error, tenant.id)); // Success } else { // Stop sending notification notificationSent = true; - void Logging.logDebug({ - tenantID: tenant.id, - siteID: data?.siteID, - siteAreaID: data?.siteAreaID, - companyID: data?.companyID, - chargingStationID: data?.chargeBoxID, - action: ServerAction.REMOTE_PUSH_NOTIFICATION, - module: MODULE_NAME, method: 'sendRemotePushNotificationToUsers', - message: `Notification Sent: '${notificationType}' - '${title}'`, - actionOnUser: user.id, - }); + // Logging.logDebug({ + // tenantID: tenant.id, + // siteID: data?.siteID, + // siteAreaID: data?.siteAreaID, + // companyID: data?.companyID, + // chargingStationID: data?.chargeBoxID, + // action: ServerAction.REMOTE_PUSH_NOTIFICATION, + // module: MODULE_NAME, method: 'sendRemotePushNotificationToUsers', + // message: `Notification Sent: '${notificationType}' - '${title}'`, + // actionOnUser: user.id, + // }).catch((error) => Logging.logPromiseError(error, tenant.id)); } } catch (error) { - void Logging.logError({ + Logging.logError({ tenantID: tenant.id, siteID: data?.siteID, siteAreaID: data?.siteAreaID, @@ -561,10 +565,10 @@ export default class RemotePushNotificationTask implements NotificationTask { chargingStationID: data?.chargeBoxID, action: ServerAction.REMOTE_PUSH_NOTIFICATION, module: MODULE_NAME, method: 'sendRemotePushNotificationToUsers', - message: `Error when sending Notification: '${notificationType}' - '${error.message as string}'`, + message: `Notification: '${notificationType}' - '${error.message as string}'`, actionOnUser: user.id, detailedMessages: { error: error.stack } - }); + }).catch((error2) => Logging.logPromiseError(error2, tenant.id)); } } } finally { From 0edace135681a74924c3ebacfce8bddab326bd5f Mon Sep 17 00:00:00 2001 From: ClaudeROSSI Date: Tue, 28 Mar 2023 09:50:06 +0200 Subject: [PATCH 2/5] remote push notification - logs --- .../remote-push-notification/RemotePushNotificationTask.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/notification/remote-push-notification/RemotePushNotificationTask.ts b/src/notification/remote-push-notification/RemotePushNotificationTask.ts index 66227f3280..992cce7b16 100644 --- a/src/notification/remote-push-notification/RemotePushNotificationTask.ts +++ b/src/notification/remote-push-notification/RemotePushNotificationTask.ts @@ -539,7 +539,7 @@ export default class RemotePushNotificationTask implements NotificationTask { message: `Notification: '${notificationType}' - Error code: '${response.results[0]?.error?.code}'`, actionOnUser: user.id, detailedMessages: { response, mobileData: user.mobileData } - }).catch((error) => Logging.logPromiseError(error, tenant.id)); + }).catch((error) => Logging.logPromiseError(error)); // Success } else { // Stop sending notification @@ -554,7 +554,7 @@ export default class RemotePushNotificationTask implements NotificationTask { // module: MODULE_NAME, method: 'sendRemotePushNotificationToUsers', // message: `Notification Sent: '${notificationType}' - '${title}'`, // actionOnUser: user.id, - // }).catch((error) => Logging.logPromiseError(error, tenant.id)); + // }).catch((error) => Logging.logPromiseError(error)); } } catch (error) { Logging.logError({ @@ -568,7 +568,7 @@ export default class RemotePushNotificationTask implements NotificationTask { message: `Notification: '${notificationType}' - '${error.message as string}'`, actionOnUser: user.id, detailedMessages: { error: error.stack } - }).catch((error2) => Logging.logPromiseError(error2, tenant.id)); + }).catch((error2) => Logging.logPromiseError(error2)); } } } finally { From 391ad80987b073b40ced2ee63cf52b0dcc98b2ac Mon Sep 17 00:00:00 2001 From: ClaudeROSSI Date: Tue, 28 Mar 2023 10:10:57 +0200 Subject: [PATCH 3/5] UpdateChargingStationWithTemplate - less verbose --- src/server/ocpp/utils/OCPPUtils.ts | 38 +++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/server/ocpp/utils/OCPPUtils.ts b/src/server/ocpp/utils/OCPPUtils.ts index a73ca740fe..0c44f48ad1 100644 --- a/src/server/ocpp/utils/OCPPUtils.ts +++ b/src/server/ocpp/utils/OCPPUtils.ts @@ -801,7 +801,10 @@ export default class OCPPUtils { action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, module: MODULE_NAME, method: 'enrichChargingStationConnectorWithTemplate', message: `Template for Connector ID '${connector.connectorId}' cannot be applied on manual configured charging station`, - detailedMessages: { chargingStation, connector } + detailedMessages: { + chargingStationData: LoggingHelper.shrinkChargingStationProperties(chargingStation), + connector + } }); return false; } @@ -880,7 +883,6 @@ export default class OCPPUtils { action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, module: MODULE_NAME, method: 'enrichChargingStationConnectorWithTemplate', message: `Template ID '${chargingStationTemplate.id}' has been applied on Connector ID '${connector.connectorId}' with success`, - detailedMessages: { chargingStationTemplate, chargingStation } }); return true; } @@ -891,7 +893,10 @@ export default class OCPPUtils { action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, module: MODULE_NAME, method: 'enrichChargingStationConnectorWithTemplate', message: `No Connector found in Template ID '${chargingStationTemplate.id}'`, - detailedMessages: { chargingStationTemplate, chargingStation } + detailedMessages: { + templateData: LoggingHelper.shrinkTemplateProperties(chargingStationTemplate), + chargingStationData: LoggingHelper.shrinkChargingStationProperties(chargingStation) + } }); return false; } @@ -902,7 +907,10 @@ export default class OCPPUtils { action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, module: MODULE_NAME, method: 'enrichChargingStationConnectorWithTemplate', message: 'No Template has been found for this Charging Station', - detailedMessages: { chargingStation, connector } + detailedMessages: { + chargingStationData: LoggingHelper.shrinkChargingStationProperties(chargingStation), + connector + } }); return false; } @@ -1521,7 +1529,9 @@ export default class OCPPUtils { action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, module: MODULE_NAME, method: 'enrichChargingStationWithTemplate', message: 'Template cannot be applied on manual configured charging station', - detailedMessages: { chargingStation } + detailedMessages: { + chargingStationData: LoggingHelper.shrinkChargingStationProperties(chargingStation) + } }); return templateUpdateResult; } @@ -1648,7 +1658,9 @@ export default class OCPPUtils { action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, module: MODULE_NAME, method: 'enrichChargingStationWithTemplate', message: `Template contains power limitation key '${parameter}' in OCPP parameters, skipping. Remove it from template!`, - detailedMessages: { chargingStationTemplate } + detailedMessages: { + templateData: LoggingHelper.shrinkTemplateProperties(chargingStationTemplate) + } }); continue; } @@ -1659,7 +1671,9 @@ export default class OCPPUtils { action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, module: MODULE_NAME, method: 'enrichChargingStationWithTemplate', message: `Template contains heartbeat interval key '${parameter}' in OCPP parameters, skipping. Remove it from template`, - detailedMessages: { chargingStationTemplate } + detailedMessages: { + templateData: LoggingHelper.shrinkTemplateProperties(chargingStationTemplate) + } }); continue; } @@ -1678,7 +1692,10 @@ export default class OCPPUtils { action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, module: MODULE_NAME, method: 'enrichChargingStationWithTemplateOcppParams', message: `Cannot find a matching section named '${ocppProperty}' in Template ID '${chargingStationTemplate.id}'`, - detailedMessages: { chargingStationTemplate, chargingStation } + detailedMessages: { + templateData: LoggingHelper.shrinkTemplateProperties(chargingStationTemplate), + chargingStationData: LoggingHelper.shrinkChargingStationProperties(chargingStation) + } }); } } @@ -1725,7 +1742,10 @@ export default class OCPPUtils { action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, module: MODULE_NAME, method: 'enrichChargingStationWithTemplateCapabilities', message: `Cannot find a matching section named 'capabilities' in Template ID '${chargingStationTemplate.id}'`, - detailedMessages: { chargingStationTemplate, chargingStation } + detailedMessages: { + templateData: LoggingHelper.shrinkTemplateProperties(chargingStationTemplate), + chargingStationData: LoggingHelper.shrinkChargingStationProperties(chargingStation) + } }); } } From f39ca5900ae8df9226712588573507edd57cd60c Mon Sep 17 00:00:00 2001 From: ClaudeROSSI Date: Tue, 28 Mar 2023 10:19:59 +0200 Subject: [PATCH 4/5] UpdateChargingStationWithTemplate - less verbose --- src/server/ocpp/utils/OCPPUtils.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/server/ocpp/utils/OCPPUtils.ts b/src/server/ocpp/utils/OCPPUtils.ts index 0c44f48ad1..b237414fcc 100644 --- a/src/server/ocpp/utils/OCPPUtils.ts +++ b/src/server/ocpp/utils/OCPPUtils.ts @@ -1573,17 +1573,6 @@ export default class OCPPUtils { templateData: LoggingHelper.shrinkTemplateProperties(chargingStationTemplate), } }); - } else { - await Logging.logDebug({ - ...LoggingHelper.getChargingStationProperties(chargingStation), - tenantID: tenant.id, - action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, - module: MODULE_NAME, method: 'enrichChargingStationWithTemplate', - message: `Template ID '${chargingStationTemplate.id}' has already been applied`, - detailedMessages: { - templateData: LoggingHelper.shrinkTemplateProperties(chargingStationTemplate) - } - }); } // Master/Slave: always override the charge point if (chargingStationTemplate.template.technical.masterSlave) { From ff4e4fcfe6cd2e5504e7ded9a6a4dd5a0b5e01fd Mon Sep 17 00:00:00 2001 From: Ramzi Siala <1226644+Ramzay@users.noreply.github.com> Date: Tue, 28 Mar 2023 12:58:20 +0200 Subject: [PATCH 5/5] Fix delete pricing on deleted CS --- src/server/rest/v1/service/PricingService.ts | 2 +- src/server/rest/v1/service/UtilsService.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server/rest/v1/service/PricingService.ts b/src/server/rest/v1/service/PricingService.ts index f4ca032361..b7f04fcd49 100644 --- a/src/server/rest/v1/service/PricingService.ts +++ b/src/server/rest/v1/service/PricingService.ts @@ -229,7 +229,7 @@ export default class PricingService { siteID = siteArea.siteID; break; case PricingEntity.CHARGING_STATION: - chargingStation = await UtilsService.checkAndGetChargingStationAuthorization(req.tenant, req.user, entityID, Action.READ, action); + chargingStation = await UtilsService.checkAndGetChargingStationAuthorization(req.tenant, req.user, entityID, Action.READ, action, null, { includeDeleted: true }); siteID = chargingStation.siteID; break; default: diff --git a/src/server/rest/v1/service/UtilsService.ts b/src/server/rest/v1/service/UtilsService.ts index e8c4780d96..5fc97750f7 100644 --- a/src/server/rest/v1/service/UtilsService.ts +++ b/src/server/rest/v1/service/UtilsService.ts @@ -128,7 +128,7 @@ export default class UtilsService { UtilsService.assertObjectExists(action, chargingStation, `ChargingStation ID '${chargingStationID}' does not exist`, MODULE_NAME, 'checkAndGetChargingStationAuthorization', userToken); // Check deleted - if (chargingStation?.deleted) { + if (!additionalFilters?.includeDeleted && chargingStation?.deleted) { throw new AppError({ ...LoggingHelper.getChargingStationProperties(chargingStation), errorCode: StatusCodes.NOT_FOUND,