Fixed OICP not saved + Optimized saving charging station only needed data
MODIFY
src/authorization/Authorizations.ts
src/authorization/Authorizations.ts
@@ -1044,7 +1044,8 @@ export default class Authorizations {
// Clean up
if (!user.authorizationID) {
chargingStation.remoteAuthorizations = [];
- await ChargingStationStorage.saveChargingStation(tenant.id, chargingStation);
+ await ChargingStationStorage.saveChargingStationRemoteAuthorizations(
+ tenant.id, chargingStation.id, chargingStation.remoteAuthorizations);
}
}
// Retrieve Auth token from OCPI

MODIFY
src/client/ocpi/EmspOCPIClient.ts
src/client/ocpi/EmspOCPIClient.ts
@@ -405,6 +405,7 @@ export default class EmspOCPIClient extends OCPIClient {
chargingStation.siteAreaID = siteArea.id;
chargingStation.siteID = siteArea.siteID;
await ChargingStationStorage.saveChargingStation(this.tenant.id, chargingStation);
+ await ChargingStationStorage.saveChargingStationOcpiData(this.tenant.id, chargingStation.id, chargingStation.ocpiData);
await Logging.logDebug({
tenantID: this.tenant.id,
action: ServerAction.OCPI_PULL_LOCATIONS,

MODIFY
src/integration/charging-station-vendor/ChargingStationVendorIntegration.ts
src/integration/charging-station-vendor/ChargingStationVendorIntegration.ts
@@ -114,10 +114,10 @@ export default abstract class ChargingStationVendorIntegration {
// Update the charger's connectors
const limitAmpsPerConnector = this.chargePointToConnectorLimitAmps(chargePoint, maxAmps);
for (const connector of chargingStation.connectors) {
+ // Set
connector.amperageLimit = limitAmpsPerConnector;
}
- // Save it
- await ChargingStationStorage.saveChargingStation(tenant.id, chargingStation);
+ await ChargingStationStorage.saveChargingStationConnectors(tenant.id, chargingStation.id, chargingStation.connectors);
}
return result;
}
@@ -145,8 +145,8 @@ export default abstract class ChargingStationVendorIntegration {
});
}
}
- // Save it
- await ChargingStationStorage.saveChargingStation(tenant.id, chargingStation);
+ // Save
+ await ChargingStationStorage.saveChargingStationConnectors(tenant.id, chargingStation.id, chargingStation.connectors);
}
}
}

MODIFY
src/migration/tasks/UpdateChargingStationStaticLimitationTask.ts
src/migration/tasks/UpdateChargingStationStaticLimitationTask.ts
@@ -52,7 +52,8 @@ export default class UpdateChargingStationStaticLimitationTask extends Migration
try {
// Call the limitation
const result = await chargingStationVendor.setStaticPowerLimitation(tenant, chargingStation, chargePoint, amperageChargePointMax);
- if (result.status === OCPPConfigurationStatus.ACCEPTED || result.status === OCPPConfigurationStatus.REBOOT_REQUIRED) {
+ if (result.status === OCPPConfigurationStatus.ACCEPTED ||
+ result.status === OCPPConfigurationStatus.REBOOT_REQUIRED) {
chargePointUpdated = true;
updated++;
} else {
@@ -83,7 +84,7 @@ export default class UpdateChargingStationStaticLimitationTask extends Migration
connector.amperageLimit = Utils.getChargingStationAmperage(chargingStation, chargePoint, connectorID);
}
}
- await ChargingStationStorage.saveChargingStation(tenant.id, chargingStation);
+ await ChargingStationStorage.saveChargingStationConnectors(tenant.id, chargingStation.id, chargingStation.connectors);
updated++;
}
}
@@ -94,7 +95,7 @@ export default class UpdateChargingStationStaticLimitationTask extends Migration
connector.amperageLimit = connector.amperage;
}
}
- await ChargingStationStorage.saveChargingStation(tenant.id, chargingStation);
+ await ChargingStationStorage.saveChargingStationConnectors(tenant.id, chargingStation.id, chargingStation.connectors);
updated++;
}
}

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
@@ -1002,7 +1002,7 @@ export default class OCPIUtilsService {
connector.currentInstantWatts = 0;
connector.currentInactivityStatus = null;
}
- await ChargingStationStorage.saveChargingStation(tenant.id, chargingStation);
+ await ChargingStationStorage.saveChargingStationConnectors(tenant.id, chargingStation.id, chargingStation.connectors);
}
}
}

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
@@ -187,7 +187,8 @@ export default class CPOCommandsEndpoint extends AbstractEndpoint {
);
}
// Save Auth
- await ChargingStationStorage.saveChargingStation(tenant.id, chargingStation);
+ await ChargingStationStorage.saveChargingStationRemoteAuthorizations(
+ tenant.id, chargingStation.id, chargingStation.remoteAuthorizations);
// Called Async as the response to the eMSP is sent asynchronously and this request has to finish before the command returns
void this.remoteStartTransaction(tenant, chargingStation, connector, startSession, ocpiEndpoint).catch(() => { });
// Ok

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
@@ -289,7 +289,7 @@ export default class EMSPLocationsEndpoint extends AbstractEndpoint {
if (ocpiConnector.standard) {
foundConnector.type = OCPIUtilsService.convertOCPIConnectorType2ConnectorType(ocpiConnector.standard);
}
- await ChargingStationStorage.saveChargingStation(tenant.id, chargingStation);
+ await ChargingStationStorage.saveChargingStationConnectors(tenant.id, chargingStation.id, chargingStation.connectors);
}
private async updateEvse(tenant: Tenant, evse: OCPIEvse, location: OCPILocation) {
@@ -359,7 +359,7 @@ export default class EMSPLocationsEndpoint extends AbstractEndpoint {
type: OCPIUtilsService.convertOCPIConnectorType2ConnectorType(evseConnector.standard),
});
}
- await ChargingStationStorage.saveChargingStation(tenant.id, chargingStation);
+ await ChargingStationStorage.saveChargingStationConnectors(tenant.id, chargingStation.id, chargingStation.connectors);
}
}

MODIFY
src/server/ocpp/json/WSConnection.ts
src/server/ocpp/json/WSConnection.ts
@@ -127,12 +127,10 @@ export default abstract class WSConnection {
if (Configuration.isCloudFoundry()) {
// Yes: Save the CF App and Instance ID to call the Charging Station from the Rest server
const chargingStation = await ChargingStationStorage.getChargingStation(this.tenantID, this.getChargingStationID());
- // Found?
if (chargingStation) {
// Update CF Instance
- chargingStation.cfApplicationIDAndInstanceIndex = Configuration.getCFApplicationIDAndInstanceIndex();
- // Save it
- await ChargingStationStorage.saveChargingStation(this.tenantID, chargingStation);
+ await ChargingStationStorage.saveChargingStationCFApplicationIDAndInstanceIndex(
+ this.tenantID, chargingStation.id, Configuration.getCFApplicationIDAndInstanceIndex());
}
}
} catch (error) {

MODIFY
src/server/oicp/OICPUtils.ts
src/server/oicp/OICPUtils.ts
@@ -54,11 +54,10 @@ export default class OICPUtils {
for (const chargingStation of chargingStations) {
if (chargingStation.issuer && chargingStation.public) {
const chargingStationEvses = OICPUtils.convertChargingStation2MultipleEvses(chargingStation.siteArea, chargingStation, options);
- // Update the Charging Station
- chargingStation.oicpData = {
+ // Update the Charging Station's OICP Data
+ await ChargingStationStorage.saveChargingStationOicpData(tenant.id, chargingStation.id, {
evses: chargingStationEvses
- };
- await ChargingStationStorage.saveChargingStation(tenant.id, chargingStation);
+ });
evses.push(...chargingStationEvses);
}
}

MODIFY
src/server/oicp/oicp-services-impl/oicp-2.3.0/CPORemoteAuthorizationsEndpoint.ts
src/server/oicp/oicp-services-impl/oicp-2.3.0/CPORemoteAuthorizationsEndpoint.ts
@@ -135,7 +135,8 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint {
);
}
// Save Auth
- await ChargingStationStorage.saveChargingStation(tenant.id, chargingStation);
+ await ChargingStationStorage.saveChargingStationRemoteAuthorizations(
+ tenant.id, chargingStation.id, chargingStation.remoteAuthorizations);
// Start the transaction
const result = await this.remoteStartTransaction(tenant, chargingStation, connector, authorizeRemoteStart);
if (result?.status === OCPPRemoteStartStopStatus.ACCEPTED) {

MODIFY
src/server/rest/v1/service/TransactionService.ts
src/server/rest/v1/service/TransactionService.ts
@@ -1002,9 +1002,8 @@ export default class TransactionService {
// Check connector
const foundConnector = Utils.getConnectorFromID(transaction.chargeBox, transaction.connectorId);
if (foundConnector && transaction.id === foundConnector.currentTransactionID) {
- // Clear connector
OCPPUtils.checkAndFreeChargingStationConnector(transaction.chargeBox, transaction.connectorId);
- await ChargingStationStorage.saveChargingStation(loggedUser.tenantID, transaction.chargeBox);
+ await ChargingStationStorage.saveChargingStationConnectors(loggedUser.tenantID, transaction.chargeBox.id, transaction.chargeBox.connectors);
}
// To Delete
transactionsIDsToDelete.push(transactionID);

MODIFY
src/storage/mongodb/ChargingStationStorage.ts
src/storage/mongodb/ChargingStationStorage.ts
import { ChargePointStatus, OCPPFirmwareStatus } from '../../types/ocpp/OCPPServer';
import { ChargingProfile, ChargingProfilePurposeType, ChargingRateUnitType } from '../../types/ChargingProfile';
-import ChargingStation, { ChargePoint, ChargingStationOcpiData, ChargingStationOcppParameters, ChargingStationTemplate, Connector, ConnectorType, CurrentType, OcppParameter, PhaseAssignmentToGrid, Voltage } from '../../types/ChargingStation';
+import ChargingStation, { ChargePoint, ChargingStationOcpiData, ChargingStationOcppParameters, ChargingStationOicpData, ChargingStationTemplate, Connector, ConnectorType, CurrentType, OcppParameter, PhaseAssignmentToGrid, RemoteAuthorization, Voltage } from '../../types/ChargingStation';
import { ChargingStationInError, ChargingStationInErrorType } from '../../types/InError';
import { GridFSBucket, GridFSBucketReadStream, GridFSBucketWriteStream, ObjectID } from 'mongodb';
import global, { FilterParams } from '../../types/GlobalType';
@@ -581,12 +581,10 @@ export default class ChargingStationStorage {
(chargePoint) => ChargingStationStorage.filterChargePointMDB(chargePoint)) : [],
coordinates: Utils.containsGPSCoordinates(chargingStationToSave.coordinates) ? chargingStationToSave.coordinates.map(
(coordinate) => Utils.convertToFloat(coordinate)) : [],
- remoteAuthorizations: chargingStationToSave.remoteAuthorizations ? chargingStationToSave.remoteAuthorizations : [],
currentIPAddress: chargingStationToSave.currentIPAddress,
capabilities: chargingStationToSave.capabilities,
ocppStandardParameters: chargingStationToSave.ocppStandardParameters,
ocppVendorParameters: chargingStationToSave.ocppVendorParameters,
- ocpiData: chargingStationToSave.ocpiData
};
// Add Created/LastChanged By
DatabaseUtils.addLastChangedCreatedProps(chargingStationMDB, chargingStationToSave);
@@ -600,22 +598,63 @@ export default class ChargingStationStorage {
return chargingStationMDB._id;
}
- public static async saveChargingStationConnector(tenantID: string, chargingStation: ChargingStation, connector: Connector): Promise<void> {
+ public static async saveChargingStationConnectors(tenantID: string, id: string, connectors: Connector[]): Promise<void> {
// Debug
- const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'saveChargingStationConnector');
+ const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'saveChargingStationConnectors');
+ // Check Tenant
+ await DatabaseUtils.checkTenant(tenantID);
// Ensure good typing
- const connectorMDB = ChargingStationStorage.filterConnectorMDB(connector);
+ const connectorsMDB = connectors.map((connector) =>
+ ChargingStationStorage.filterConnectorMDB(connector));
+ // Modify document
+ await global.database.getCollection<any>(tenantID, 'chargingstations').findOneAndUpdate(
+ { '_id': id },
+ {
+ $set: {
+ connectors: connectorsMDB
+ }
+ },
+ { upsert: true });
+ // Debug
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'saveChargingStationConnectors', uniqueTimerID, connectors);
+ }
+
+ public static async saveChargingStationCFApplicationIDAndInstanceIndex(tenantID: string, id: string,
+ cfApplicationIDAndInstanceIndex: string): Promise<void> {
+ // Debug
+ const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'saveChargingStationCFApplicationIDAndInstanceIndex');
// Check Tenant
await DatabaseUtils.checkTenant(tenantID);
- const updatedFields: any = {};
- updatedFields['connectors.' + (connector.connectorId - 1).toString()] = connectorMDB;
// Modify document
await global.database.getCollection<ChargingStation>(tenantID, 'chargingstations').findOneAndUpdate(
- { '_id': chargingStation.id },
- { $set: updatedFields },
+ { '_id': id },
+ {
+ $set: {
+ cfApplicationIDAndInstanceIndex
+ }
+ },
{ upsert: true });
// Debug
- await Logging.traceEnd(tenantID, MODULE_NAME, 'saveChargingStationConnector', uniqueTimerID, updatedFields);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'saveChargingStationCFApplicationIDAndInstanceIndex', uniqueTimerID, cfApplicationIDAndInstanceIndex);
+ }
+
+ public static async saveChargingStationOicpData(tenantID: string, id: string,
+ oicpData: ChargingStationOicpData): Promise<void> {
+ // Debug
+ const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'saveChargingStationOicpData');
+ // Check Tenant
+ await DatabaseUtils.checkTenant(tenantID);
+ // Modify document
+ await global.database.getCollection<ChargingStation>(tenantID, 'chargingstations').findOneAndUpdate(
+ { '_id': id },
+ {
+ $set: {
+ oicpData
+ }
+ },
+ { upsert: false });
+ // Debug
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'saveChargingStationOicpData', uniqueTimerID, oicpData);
}
public static async saveChargingStationLastSeen(tenantID: string, id: string,
@@ -664,6 +703,25 @@ export default class ChargingStationStorage {
await Logging.traceEnd(tenantID, MODULE_NAME, 'saveChargingStationOcpiData', uniqueTimerID, ocpiData);
}
+ public static async saveChargingStationRemoteAuthorizations(tenantID: string, id: string,
+ remoteAuthorizations: RemoteAuthorization[]): Promise<void> {
+ // Debug
+ const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'saveChargingStationRemoteAuthorizations');
+ // Check Tenant
+ await DatabaseUtils.checkTenant(tenantID);
+ // Modify document
+ await global.database.getCollection<ChargingStation>(tenantID, 'chargingstations').findOneAndUpdate(
+ { '_id': id },
+ {
+ $set: {
+ remoteAuthorizations
+ }
+ },
+ { upsert: false });
+ // Debug
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'saveChargingStationRemoteAuthorizations', uniqueTimerID, remoteAuthorizations);
+ }
+
public static async saveChargingStationFirmwareStatus(tenantID: string, id: string, firmwareUpdateStatus: OCPPFirmwareStatus): Promise<void> {
// Debug
const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'saveChargingStationFirmwareStatus');

MODIFY
src/storage/mongodb/ConsumptionStorage.ts
src/storage/mongodb/ConsumptionStorage.ts
@@ -45,7 +45,7 @@ export default class ConsumptionStorage {
// Insert
await global.database.getCollection<any>(tenantID, 'consumptions').insertMany(consumptionsMDB);
// Debug
- await Logging.traceEnd(tenantID, MODULE_NAME, 'saveConsumptions', uniqueTimerID);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'saveConsumptions', uniqueTimerID, consumptionsToSave);
// Return
return consumptionsMDB.map((consumptionMDB) => consumptionMDB._id);
}

MODIFY
src/storage/mongodb/TagStorage.ts
src/storage/mongodb/TagStorage.ts
@@ -83,7 +83,7 @@ export default class TagStorage {
{ ordered: false }
);
// Debug
- await Logging.traceEnd(tenantID, MODULE_NAME, 'saveImportedTags', uniqueTimerID);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'saveImportedTags', uniqueTimerID, importedTagsToSave);
return result.insertedCount;
}

MODIFY
src/storage/mongodb/UserStorage.ts
src/storage/mongodb/UserStorage.ts
@@ -314,7 +314,7 @@ export default class UserStorage {
{ ordered: false }
);
// Debug
- await Logging.traceEnd(tenantID, MODULE_NAME, 'saveImportedUsers', uniqueTimerID);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'saveImportedUsers', uniqueTimerID, importedUsersToSave);
return result.insertedCount;
}

Fixed OICP not saved + Optimized saving charging station only needed data