Fixed OCPI eMSP Auth
MODIFY
src/server/ocpi/OCPIUtils.ts
src/server/ocpi/OCPIUtils.ts
@@ -204,7 +204,7 @@ export default class OCPIUtils {
});
}
// Get existing charging station
- const currentChargingStation = await ChargingStationStorage.getChargingStationByOcpiLocationUid(
+ const currentChargingStation = await ChargingStationStorage.getChargingStationByOcpiLocationEvseUid(
tenant, location.id, evse.uid);
// Delete Charging Station
if (currentChargingStation && evse.status === OCPIEvseStatus.REMOVED) {

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/cpo/CPOCommandsEndpoint.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/cpo/CPOCommandsEndpoint.ts
@@ -111,7 +111,7 @@ export default class CPOCommandsEndpoint extends AbstractEndpoint {
return this.buildOCPIResponse(OCPICommandResponseType.REJECTED);
}
// Get the Charging Station
- const chargingStation = await ChargingStationStorage.getChargingStationByOcpiLocationUid(
+ const chargingStation = await ChargingStationStorage.getChargingStationByOcpiLocationEvseUid(
tenant, startSession.location_id, startSession.evse_uid);
if (!chargingStation) {
await Logging.logError({

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/emsp/EMSPLocationsEndpoint.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/emsp/EMSPLocationsEndpoint.ts
@@ -329,7 +329,7 @@ export default class EMSPLocationsEndpoint extends AbstractEndpoint {
});
}
// Get the Charging Station
- const chargingStation = await ChargingStationStorage.getChargingStationByOcpiLocationUid(
+ const chargingStation = await ChargingStationStorage.getChargingStationByOcpiLocationEvseUid(
tenant, locationID, evseUID);
if (!chargingStation) {
throw new AppError({

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/emsp/EMSPTokensEndpoint.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/emsp/EMSPTokensEndpoint.ts
@@ -81,7 +81,7 @@ export default class EMSPTokensEndpoint extends AbstractEndpoint {
ocpiError: OCPIStatusCode.CODE_2002_NOT_ENOUGH_INFORMATION_ERROR
});
}
- if (!locationReference.evse_uids || locationReference.evse_uids.length === 0) {
+ if (Utils.isEmptyArray(locationReference.evse_uids)) {
throw new AppError({
action: ServerAction.OCPI_AUTHORIZE_TOKEN,
module: MODULE_NAME, method: 'authorizeRequest',
@@ -95,12 +95,13 @@ export default class EMSPTokensEndpoint extends AbstractEndpoint {
action: ServerAction.OCPI_AUTHORIZE_TOKEN,
module: MODULE_NAME, method: 'authorizeRequest',
errorCode: HTTPError.GENERAL_ERROR,
- message: 'Invalid or missing parameters : does not support authorization request on multiple Charging Stations',
+ message: 'Does not support authorization request on multiple Charging Stations',
ocpiError: OCPIStatusCode.CODE_2001_INVALID_PARAMETER_ERROR
});
}
- const chargingStation = await ChargingStationStorage.getChargingStationByOcpiEvseID(
- tenant, locationReference.evse_uids[0]);
+ // Get the Charging Station
+ const chargingStation = await ChargingStationStorage.getChargingStationByOcpiLocationEvseUid(
+ tenant, locationReference.location_id, locationReference.evse_uids[0]);
if (!chargingStation) {
throw new AppError({
action: ServerAction.OCPI_AUTHORIZE_TOKEN,
@@ -135,12 +136,11 @@ export default class EMSPTokensEndpoint extends AbstractEndpoint {
allowedStatus = OCPIAllowed.NOT_ALLOWED;
}
}
- const authorizationInfo: OCPIAuthorizationInfo = {
+ return OCPIUtils.success({
allowed: allowedStatus,
authorization_id: Utils.generateUUID(),
location: locationReference
- };
- return OCPIUtils.success(authorizationInfo);
+ });
}
}

MODIFY
src/storage/mongodb/ChargingStationStorage.ts
src/storage/mongodb/ChargingStationStorage.ts
@@ -17,6 +17,7 @@ import { InactivityStatus } from '../../types/Transaction';
import Logging from '../../utils/Logging';
import Utils from '../../utils/Utils';
import moment from 'moment';
+import { ServerAction } from '../../types/Server';
const MODULE_NAME = 'ChargingStationStorage';
@@ -120,10 +121,20 @@ export default class ChargingStationStorage {
ocpiEvseID,
withSiteArea: true,
}, Constants.DB_PARAMS_SINGLE_RECORD, projectFields);
- return chargingStationsMDB.count === 1 ? chargingStationsMDB.result[0] : null;
+ // No unique key on OCPI Location (avoid create several Site Area with the same location ID)
+ if (chargingStationsMDB.count > 1) {
+ await Logging.logWarning({
+ tenantID: tenant.id,
+ action: ServerAction.UNKNOWN_ACTION,
+ module: MODULE_NAME, method: 'getSiteAreaByOcpiLocationUid',
+ message: `Multiple Charging Station with same OCPI EVSE ID '${ocpiEvseID}'`,
+ detailedMessages: { ocpiEvseID, chargingStations: chargingStationsMDB.result }
+ });
+ }
+ return chargingStationsMDB.count >= 1 ? chargingStationsMDB.result[0] : null;
}
- public static async getChargingStationByOcpiLocationUid(tenant: Tenant, ocpiLocationID: string = Constants.UNKNOWN_STRING_ID,
+ public static async getChargingStationByOcpiLocationEvseUid(tenant: Tenant, ocpiLocationID: string = Constants.UNKNOWN_STRING_ID,
ocpiEvseUid: string = Constants.UNKNOWN_STRING_ID,
projectFields?: string[]): Promise<ChargingStation> {
const chargingStationsMDB = await ChargingStationStorage.getChargingStations(tenant, {

Fixed OCPI eMSP Auth