Assert GPS coords are correct in OCPI
Renaming
MODIFY
src/client/ocpi/CpoOCPIClient.ts
src/client/ocpi/CpoOCPIClient.ts
@@ -1072,13 +1072,14 @@ export default class CpoOCPIClient extends OCPIClient {
}
private async convertChargingStationToOCPILocation(tenant: Tenant, site: Site, chargingStation: ChargingStation,
- connectorId: number, countryId: string, partyId: string): Promise<OCPILocation> {
+ connectorID: number, countryID: string, partyID: string): Promise<OCPILocation> {
+ const hasValidGpsCoordinates = Utils.hasValidGpsCoordinates(site.address?.coordinates);
const connectors: OCPIConnector[] = [];
let status: ChargePointStatus;
- const connector = Utils.getConnectorFromID(chargingStation, connectorId);
+ const connector = Utils.getConnectorFromID(chargingStation, connectorID);
let chargePoint;
if (connector) {
- connectors.push(await OCPIUtilsService.convertConnector2OCPIConnector(tenant, chargingStation, connector, countryId, partyId));
+ connectors.push(await OCPIUtilsService.convertConnector2OCPIConnector(tenant, chargingStation, connector, countryID, partyID));
status = connector.status;
chargePoint = Utils.getChargePointFromID(chargingStation, connector.chargePointID);
}
@@ -1088,15 +1089,15 @@ export default class CpoOCPIClient extends OCPIClient {
address: Utils.convertAddressToOneLine(site.address),
city: site.address?.city,
postal_code: site.address?.postalCode,
- country: countries.getAlpha3Code(site.address.country, CountriesList.countries[countryId].languages[0]),
+ country: countries.getAlpha3Code(site.address.country, CountriesList.countries[countryID].languages[0]),
coordinates: {
- latitude: site.address?.coordinates[1]?.toString(),
- longitude: site.address?.coordinates[0]?.toString()
+ longitude: hasValidGpsCoordinates ? site.address.coordinates[0].toString() : Constants.SFDP_LONGITUDE.toString(),
+ latitude: hasValidGpsCoordinates ? site.address.coordinates[1].toString() : Constants.SFDP_LATTITUDE.toString()
},
type: OCPILocationType.UNKNOWN,
evses: [{
- uid: OCPIUtils.buildEvseUID(chargingStation, Utils.getConnectorFromID(chargingStation, connectorId)),
- evse_id: RoamingUtils.buildEvseID(countryId, partyId, chargingStation.id, chargePoint && chargePoint.cannotChargeInParallel ? chargePoint.chargePointID : connectorId),
+ uid: OCPIUtils.buildEvseUID(chargingStation, Utils.getConnectorFromID(chargingStation, connectorID)),
+ evse_id: RoamingUtils.buildEvseID(countryID, partyID, chargingStation.id, chargePoint && chargePoint.cannotChargeInParallel ? chargePoint.chargePointID : connectorID),
location_id: chargingStation.siteID,
status: OCPIUtilsService.convertStatus2OCPIStatus(status),
capabilities: [OCPICapability.REMOTE_START_STOP_CAPABLE, OCPICapability.RFID_READER],

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPIUtilsService.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPIUtilsService.ts
@@ -173,6 +173,7 @@ export default class OCPIUtilsService {
public static async convertSite2Location(tenant: Tenant, site: Site,
options: OCPILocationOptions, withChargingStations: boolean): Promise<OCPILocation> {
+ const hasValidGpsCoordinates = Utils.hasValidGpsCoordinates(site.address?.coordinates);
// Build object
return {
id: site.id,
@@ -183,8 +184,8 @@ export default class OCPIUtilsService {
postal_code: site.address.postalCode,
country: countries.getAlpha3Code(site.address.country, CountriesList.countries[options.countryID].languages[0]),
coordinates: {
- longitude: site.address.coordinates[0].toString(),
- latitude: site.address.coordinates[1].toString()
+ longitude: hasValidGpsCoordinates ? site.address.coordinates[0].toString() : Constants.SFDP_LONGITUDE.toString(),
+ latitude: hasValidGpsCoordinates ? site.address.coordinates[1].toString() : Constants.SFDP_LATTITUDE.toString()
},
evses: withChargingStations ?
await OCPIUtilsService.getEvsesFromSite(tenant, site.id, options, Constants.DB_PARAMS_MAX_LIMIT) : [],
@@ -708,7 +709,8 @@ export default class OCPIUtilsService {
}
}
- public static async convertConnector2OCPIConnector(tenant: Tenant, chargingStation: ChargingStation, connector: Connector, countryId: string, partyId: string): Promise<OCPIConnector> {
+ public static async convertConnector2OCPIConnector(tenant: Tenant, chargingStation: ChargingStation,
+ connector: Connector, countryID: string, partyID: string): Promise<OCPIConnector> {
let type: OCPIConnectorType, format: OCPIConnectorFormat;
const chargePoint = Utils.getChargePointFromID(chargingStation, connector?.chargePointID);
const voltage: OCPIVoltage = OCPIUtilsService.getChargingStationOCPIVoltage(chargingStation, chargePoint, connector.connectorId);
@@ -738,7 +740,7 @@ export default class OCPIUtilsService {
break;
}
return {
- id: RoamingUtils.buildEvseID(countryId, partyId, chargingStation.id, connector.connectorId),
+ id: RoamingUtils.buildEvseID(countryID, partyID, chargingStation.id, connector.connectorId),
standard: type,
format: format,
voltage: voltage,

MODIFY
src/storage/mongodb/AssetStorage.ts
src/storage/mongodb/AssetStorage.ts
@@ -47,7 +47,7 @@ export default class AssetStorage {
name: assetToSave.name,
siteAreaID: DatabaseUtils.convertToObjectID(assetToSave.siteAreaID),
siteID: DatabaseUtils.convertToObjectID(assetToSave.siteID),
- coordinates: Utils.containsGPSCoordinates(assetToSave.coordinates) ? assetToSave.coordinates.map(
+ coordinates: Utils.hasValidGpsCoordinates(assetToSave.coordinates) ? assetToSave.coordinates.map(
(coordinate) => Utils.convertToFloat(coordinate)) : [],
assetType: assetToSave.assetType,
excludeFromSmartCharging: Utils.convertToBoolean(assetToSave.excludeFromSmartCharging),

MODIFY
src/storage/mongodb/ChargingStationStorage.ts
src/storage/mongodb/ChargingStationStorage.ts
@@ -163,7 +163,7 @@ export default class ChargingStationStorage {
// Create Aggregation
const aggregation = [];
// Position coordinates
- if (Utils.containsGPSCoordinates(params.locCoordinates)) {
+ if (Utils.hasValidGpsCoordinates(params.locCoordinates)) {
aggregation.push({
$geoNear: {
near: {
@@ -321,7 +321,7 @@ export default class ChargingStationStorage {
dbParams.sort = { _id: 1 };
}
// Position coordinates
- if (Utils.containsGPSCoordinates(params.locCoordinates)) {
+ if (Utils.hasValidGpsCoordinates(params.locCoordinates)) {
// Override (can have only one sort)
dbParams.sort = { distanceMeters: 1 };
}
@@ -370,7 +370,7 @@ export default class ChargingStationStorage {
// Project
DatabaseUtils.projectFields(aggregation, projectFields);
// Reorder connector ID
- if (!Utils.containsGPSCoordinates(params.locCoordinates)) {
+ if (!Utils.hasValidGpsCoordinates(params.locCoordinates)) {
aggregation.push({
$sort: dbParams.sort
});
@@ -554,7 +554,7 @@ export default class ChargingStationStorage {
(backupConnector) => ChargingStationStorage.filterConnectorMDB(backupConnector)) : [],
chargePoints: chargingStationToSave.chargePoints ? chargingStationToSave.chargePoints.map(
(chargePoint) => ChargingStationStorage.filterChargePointMDB(chargePoint)) : [],
- coordinates: Utils.containsGPSCoordinates(chargingStationToSave.coordinates) ? chargingStationToSave.coordinates.map(
+ coordinates: Utils.hasValidGpsCoordinates(chargingStationToSave.coordinates) ? chargingStationToSave.coordinates.map(
(coordinate) => Utils.convertToFloat(coordinate)) : [],
currentIPAddress: chargingStationToSave.currentIPAddress,
capabilities: chargingStationToSave.capabilities,

MODIFY
src/storage/mongodb/CompanyStorage.ts
src/storage/mongodb/CompanyStorage.ts
@@ -57,7 +57,7 @@ export default class CompanyStorage {
department: companyToSave.address.department,
region: companyToSave.address.region,
country: companyToSave.address.country,
- coordinates: Utils.containsGPSCoordinates(companyToSave.address.coordinates) ? companyToSave.address.coordinates.map(
+ coordinates: Utils.hasValidGpsCoordinates(companyToSave.address.coordinates) ? companyToSave.address.coordinates.map(
(coordinate) => Utils.convertToFloat(coordinate)) : [],
};
}
@@ -92,7 +92,7 @@ export default class CompanyStorage {
// Create Aggregation
const aggregation = [];
// Position coordinates
- if (Utils.containsGPSCoordinates(params.locCoordinates)) {
+ if (Utils.hasValidGpsCoordinates(params.locCoordinates)) {
aggregation.push({
$geoNear: {
near: {
@@ -161,7 +161,7 @@ export default class CompanyStorage {
dbParams.sort = { name: 1 };
}
// Position coordinates
- if (Utils.containsGPSCoordinates(params.locCoordinates)) {
+ if (Utils.hasValidGpsCoordinates(params.locCoordinates)) {
dbParams.sort = { distanceMeters: 1 };
}
aggregation.push({

MODIFY
src/storage/mongodb/SiteAreaStorage.ts
src/storage/mongodb/SiteAreaStorage.ts
@@ -107,7 +107,7 @@ export default class SiteAreaStorage {
department: siteAreaToSave.address.department,
region: siteAreaToSave.address.region,
country: siteAreaToSave.address.country,
- coordinates: Utils.containsGPSCoordinates(siteAreaToSave.address.coordinates) ? siteAreaToSave.address.coordinates.map(
+ coordinates: Utils.hasValidGpsCoordinates(siteAreaToSave.address.coordinates) ? siteAreaToSave.address.coordinates.map(
(coordinate) => Utils.convertToFloat(coordinate)) : [],
};
}
@@ -144,7 +144,7 @@ export default class SiteAreaStorage {
// Create Aggregation
const aggregation = [];
// Position coordinates
- if (Utils.containsGPSCoordinates(params.locCoordinates)) {
+ if (Utils.hasValidGpsCoordinates(params.locCoordinates)) {
aggregation.push({
$geoNear: {
near: {
@@ -232,7 +232,7 @@ export default class SiteAreaStorage {
dbParams.sort = { name: 1 };
}
// Position coordinates
- if (Utils.containsGPSCoordinates(params.locCoordinates)) {
+ if (Utils.hasValidGpsCoordinates(params.locCoordinates)) {
dbParams.sort = { distanceMeters: 1 };
}
aggregation.push({

MODIFY
src/storage/mongodb/SiteStorage.ts
src/storage/mongodb/SiteStorage.ts
@@ -253,7 +253,7 @@ export default class SiteStorage {
department: siteToSave.address.department,
region: siteToSave.address.region,
country: siteToSave.address.country,
- coordinates: Utils.containsGPSCoordinates(siteToSave.address.coordinates) ? siteToSave.address.coordinates.map(
+ coordinates: Utils.hasValidGpsCoordinates(siteToSave.address.coordinates) ? siteToSave.address.coordinates.map(
(coordinate) => Utils.convertToFloat(coordinate)) : [],
};
}
@@ -303,7 +303,7 @@ export default class SiteStorage {
// Create Aggregation
const aggregation = [];
// Position coordinates
- if (Utils.containsGPSCoordinates(params.locCoordinates)) {
+ if (Utils.hasValidGpsCoordinates(params.locCoordinates)) {
aggregation.push({
$geoNear: {
near: {
@@ -394,7 +394,7 @@ export default class SiteStorage {
dbParams.sort = { name: 1 };
}
// Position coordinates
- if (Utils.containsGPSCoordinates(params.locCoordinates)) {
+ if (Utils.hasValidGpsCoordinates(params.locCoordinates)) {
dbParams.sort = { distanceMeters: 1 };
}
aggregation.push({

MODIFY
src/storage/mongodb/TenantStorage.ts
src/storage/mongodb/TenantStorage.ts
@@ -72,7 +72,7 @@ export default class TenantStorage {
department: tenantToSave.address.department,
region: tenantToSave.address.region,
country: tenantToSave.address.country,
- coordinates: Utils.containsGPSCoordinates(tenantToSave.address.coordinates) ? tenantToSave.address.coordinates.map(
+ coordinates: Utils.hasValidGpsCoordinates(tenantToSave.address.coordinates) ? tenantToSave.address.coordinates.map(
(coordinate) => Utils.convertToFloat(coordinate)) : [],
}
});

MODIFY
src/storage/mongodb/UserStorage.ts
src/storage/mongodb/UserStorage.ts
@@ -252,7 +252,7 @@ export default class UserStorage {
department: userToSave.address.department,
region: userToSave.address.region,
country: userToSave.address.country,
- coordinates: Utils.containsGPSCoordinates(userToSave.address.coordinates) ? userToSave.address.coordinates.map(
+ coordinates: Utils.hasValidGpsCoordinates(userToSave.address.coordinates) ? userToSave.address.coordinates.map(
(coordinate) => Utils.convertToFloat(coordinate)) : [],
};
}

MODIFY
src/utils/Constants.ts
src/utils/Constants.ts
@@ -40,6 +40,9 @@ export default class Constants {
public static readonly IMPORT_BATCH_INSERT_SIZE = 250;
public static readonly BATCH_PAGE_SIZE = 1000;
+ public static readonly SFDP_LATTITUDE = 43.585784;
+ public static readonly SFDP_LONGITUDE = 7.0377592;
+
public static readonly LOCK_WAIT_MILLIS = 1000;
public static readonly SMART_CHARGING_LOCK_SECS = 5;

MODIFY
src/utils/Utils.ts
src/utils/Utils.ts
@@ -1172,15 +1172,15 @@ export default class Utils {
});
}
- public static containsAddressGPSCoordinates(address: Address): boolean {
+ public static hasValidAddressGpsCoordinates(address: Address): boolean {
// Check if GPS are available
- if (address && Utils.containsGPSCoordinates(address.coordinates)) {
+ if (address && Utils.hasValidGpsCoordinates(address.coordinates)) {
return true;
}
return false;
}
- public static containsGPSCoordinates(coordinates: number[]): boolean {
+ public static hasValidGpsCoordinates(coordinates: number[]): boolean {
// Check if GPs are available
if (!Utils.isEmptyArray(coordinates) && coordinates.length === 2 && coordinates[0] && coordinates[1]) {
// Check Longitude & Latitude

Assert GPS coords are correct in OCPI
Renaming