refactor: remove payloadSchemaValidation from template in favor of ocppStrictCompliance
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 7 Jul 2023 21:46:47 +0000 (23:46 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 7 Jul 2023 21:46:47 +0000 (23:46 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
README.md
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/OCPPIncomingRequestService.ts
src/charging-station/ocpp/OCPPRequestService.ts
src/charging-station/ocpp/OCPPResponseService.ts
src/types/ChargingStationTemplate.ts

index 592b3eab3612bed7bdfe285bca49b2807c13dad3..dbf0533e9b89ba74547a03e96f8e8e572d905be2 100644 (file)
--- a/README.md
+++ b/README.md
@@ -132,7 +132,7 @@ But the modifications to test have to be done to the files in the build target d
 | supervisionUrlOcppKey                                |               | 'ConnectionUrl'                                                                                                                     | string                                                                                                                                                                   | the vendor string that will be used as a vendor OCPP parameter key to set the supervision URL                                                                                                                                              |
 | ocppVersion                                          | 1.6/2.0/2.0.1 | 1.6                                                                                                                                 | string                                                                                                                                                                   | OCPP version                                                                                                                                                                                                                               |
 | ocppProtocol                                         | json          | json                                                                                                                                | string                                                                                                                                                                   | OCPP protocol                                                                                                                                                                                                                              |
-| ocppStrictCompliance                                 | true/false    | false                                                                                                                               | boolean                                                                                                                                                                  | strict adherence to the OCPP version and protocol specifications                                                                                                                                                                           |
+| ocppStrictCompliance                                 | true/false    | false                                                                                                                               | boolean                                                                                                                                                                  | strict adherence to the OCPP version and protocol specifications. OCPP commands PDU validation against [OCA](https://www.openchargealliance.org/) JSON schemas                                                                             |
 | ocppPersistentConfiguration                          | true/false    | true                                                                                                                                | boolean                                                                                                                                                                  | enable persistent OCPP parameters storage by charging stations 'hashId'. The persistency is ensured by the charging stations configuration files in [dist/assets/configurations](dist/assets/configurations)                               |
 | stationInfoPersistentConfiguration                   | true/false    | true                                                                                                                                | boolean                                                                                                                                                                  | enable persistent station information and specifications storage by charging stations 'hashId'. The persistency is ensured by the charging stations configuration files in [dist/assets/configurations](dist/assets/configurations)        |
 | automaticTransactionGeneratorPersistentConfiguration | true/false    | true                                                                                                                                | boolean                                                                                                                                                                  | enable persistent automatic transaction generator configuration storage by charging stations 'hashId'. The persistency is ensured by the charging stations configuration files in [dist/assets/configurations](dist/assets/configurations) |
@@ -165,7 +165,6 @@ But the modifications to test have to be done to the files in the build target d
 | amperageLimitationUnit                               | A/cA/dA/mA    | A                                                                                                                                   | string                                                                                                                                                                   | charging stations amperage limit unit                                                                                                                                                                                                      |
 | enableStatistics                                     | true/false    | false                                                                                                                               | boolean                                                                                                                                                                  | enable charging stations statistics                                                                                                                                                                                                        |
 | mustAuthorizeAtRemoteStart                           | true/false    | true                                                                                                                                | boolean                                                                                                                                                                  | always send authorize at remote start transaction when AuthorizeRemoteTxRequests is enabled                                                                                                                                                |
-| payloadSchemaValidation                              | true/false    | true if ocppStrictCompliance is true/false if ocppStrictCompliance is false                                                         | boolean                                                                                                                                                                  | validate OCPP commands PDU against [OCA](https://www.openchargealliance.org/) JSON schemas                                                                                                                                                 |
 | beginEndMeterValues                                  | true/false    | false                                                                                                                               | boolean                                                                                                                                                                  | enable Transaction.{Begin,End} MeterValues                                                                                                                                                                                                 |
 | outOfOrderEndMeterValues                             | true/false    | false                                                                                                                               | boolean                                                                                                                                                                  | send Transaction.End MeterValues out of order. Need to relax OCPP specifications strict compliance ('ocppStrictCompliance' parameter)                                                                                                      |
 | meteringPerTransaction                               | true/false    | true                                                                                                                                | boolean                                                                                                                                                                  | enable metering history on a per transaction basis                                                                                                                                                                                         |
index 022f11bbbc23a6679f0137a8c531d93c2a7ddec9..1494cc56365d983ec779c50dbd858af18cad739f 100644 (file)
@@ -250,23 +250,6 @@ export class ChargingStation {
     return this.stationInfo.mustAuthorizeAtRemoteStart ?? true;
   }
 
-  public getPayloadSchemaValidation(): boolean {
-    if (
-      this.getOcppStrictCompliance() === true &&
-      (isNullOrUndefined(this.stationInfo.payloadSchemaValidation) ||
-        this.stationInfo.payloadSchemaValidation === false)
-    ) {
-      return true;
-    } else if (
-      this.getOcppStrictCompliance() === false &&
-      (isNullOrUndefined(this.stationInfo.payloadSchemaValidation) ||
-        this.stationInfo.payloadSchemaValidation === true)
-    ) {
-      return false;
-    }
-    return this.stationInfo.payloadSchemaValidation ?? true;
-  }
-
   public getNumberOfPhases(stationInfo?: ChargingStationInfo): number | undefined {
     const localStationInfo: ChargingStationInfo = stationInfo ?? this.stationInfo;
     switch (this.getCurrentOutType(stationInfo)) {
@@ -365,7 +348,7 @@ export class ChargingStation {
   }
 
   public getOcppStrictCompliance(): boolean {
-    return this.stationInfo?.ocppStrictCompliance ?? false;
+    return this.stationInfo?.ocppStrictCompliance ?? true;
   }
 
   public getVoltageOut(stationInfo?: ChargingStationInfo): number | undefined {
index 66dd198d0620f16261e7784ab6075c99822ae8d0..0fc67ed2867dfe0a83661f136202e7cbaeabb6ac 100644 (file)
@@ -84,7 +84,7 @@ export abstract class OCPPIncomingRequestService extends AsyncResource {
     schema: JSONSchemaType<T>,
     payload: T
   ): boolean {
-    if (chargingStation.getPayloadSchemaValidation() === false) {
+    if (chargingStation.getOcppStrictCompliance() === false) {
       return true;
     }
     const validate = this.ajv.compile(schema);
index 443c6c802cb5e532f878262f7cf40357594343b2..4ea134b6ef062d5860e2b36e29d8d7d29b794781 100644 (file)
@@ -197,7 +197,7 @@ export abstract class OCPPRequestService {
     commandName: RequestCommand | IncomingRequestCommand,
     payload: T
   ): boolean {
-    if (chargingStation.getPayloadSchemaValidation() === false) {
+    if (chargingStation.getOcppStrictCompliance() === false) {
       return true;
     }
     if (this.jsonSchemas.has(commandName as RequestCommand) === false) {
@@ -230,7 +230,7 @@ export abstract class OCPPRequestService {
     commandName: RequestCommand | IncomingRequestCommand,
     payload: T
   ): boolean {
-    if (chargingStation.getPayloadSchemaValidation() === false) {
+    if (chargingStation.getOcppStrictCompliance() === false) {
       return true;
     }
     if (
index caf826e0eef5fdab24396a9adda464243602128a..1bc4a8a8f6ae3a713da40be7ca0079aa96ae5865 100644 (file)
@@ -58,7 +58,7 @@ export abstract class OCPPResponseService {
     schema: JSONSchemaType<T>,
     payload: T
   ): boolean {
-    if (chargingStation.getPayloadSchemaValidation() === false) {
+    if (chargingStation.getOcppStrictCompliance() === false) {
       return true;
     }
     const validate = this.ajv.compile(schema);
index 10f9733fbe2f595a684c5a460babb29be13c7ae5..b9bd389bff499cef004cc787e5a7809b054d3dc3 100644 (file)
@@ -109,6 +109,7 @@ export type ChargingStationTemplate = {
   registrationMaxRetries?: number;
   enableStatistics?: boolean;
   mustAuthorizeAtRemoteStart?: boolean;
+  /** @deprecated Replaced by ocppStrictCompliance */
   payloadSchemaValidation?: boolean;
   amperageLimitationOcppKey?: string;
   amperageLimitationUnit?: AmpereUnits;