Force usage of Site Area to get Charging Stations
MODIFY
src/client/oicp/CpoOICPClient.ts
src/client/oicp/CpoOICPClient.ts
@@ -210,7 +210,7 @@ export default class CpoOICPClient extends OICPClient {
do {
// Get all charging stations from tenant
chargingStations = (await ChargingStationStorage.getChargingStations(this.tenant.id,
- { siteIDs: [site.id], public: true }, { skip: currentChargingStationSkip, limit: Constants.DB_RECORD_COUNT_DEFAULT })).result;
+ { siteIDs: [site.id], public: true, withSiteArea: true }, { skip: currentChargingStationSkip, limit: Constants.DB_RECORD_COUNT_DEFAULT })).result;
if (!Utils.isEmptyArray(chargingStations)) {
// Convert (public) charging stations to OICP EVSEs
const evses = await OICPUtils.convertChargingStationsToEVSEs(this.tenant, site, chargingStations, options);
@@ -358,7 +358,7 @@ export default class CpoOICPClient extends OICPClient {
do {
// Get all charging stations from tenant
chargingStations = (await ChargingStationStorage.getChargingStations(this.tenant.id,
- { siteIDs: [site.id], public: true }, { skip: currentChargingStationSkip, limit: Constants.DB_RECORD_COUNT_DEFAULT })).result;
+ { siteIDs: [site.id], public: true, withSiteArea: true }, { skip: currentChargingStationSkip, limit: Constants.DB_RECORD_COUNT_DEFAULT })).result;
if (!Utils.isEmptyArray(chargingStations)) {
// Convert (public) charging stations to OICP EVSE Statuses
const evseStatuses = OICPUtils.convertChargingStationsToEvseStatuses(chargingStations, options);

MODIFY
src/scheduler/tasks/CheckChargingStationTemplateTask.ts
src/scheduler/tasks/CheckChargingStationTemplateTask.ts
@@ -51,7 +51,7 @@ export default class CheckChargingStationTemplateTask extends SchedulerTask {
}
// Get the charging stations
const chargingStations = await ChargingStationStorage.getChargingStations(tenant.id, {
- issuer: true
+ issuer: true, withSiteArea: true
}, Constants.DB_PARAMS_MAX_LIMIT);
// Update
for (const chargingStation of chargingStations.result) {

MODIFY
src/scheduler/tasks/CheckOfflineChargingStationsTask.ts
src/scheduler/tasks/CheckOfflineChargingStationsTask.ts
@@ -25,8 +25,7 @@ export default class CheckOfflineChargingStationsTask extends SchedulerTask {
// Compute the date some minutes ago
const offlineSince = moment().subtract(Configuration.getChargingStationConfig().maxLastSeenIntervalSecs, 'seconds').toDate();
const chargingStations = await ChargingStationStorage.getChargingStations(tenant.id, {
- issuer: true,
- offlineSince
+ issuer: true, withSiteArea: true, offlineSince
}, Constants.DB_PARAMS_MAX_LIMIT);
if (chargingStations.count > 0) {
for (let i = chargingStations.result.length - 1; i >= 0; i--) {

MODIFY
src/scheduler/tasks/CheckPreparingSessionNotStartedTask.ts
src/scheduler/tasks/CheckPreparingSessionNotStartedTask.ts
@@ -23,7 +23,8 @@ export default class CheckPreparingSessionNotStartedTask extends SchedulerTask {
// Get Charging Stations
const chargingStations = await ChargingStationStorage.getChargingStations(tenant.id, {
'statusChangedBefore': moment().subtract(config.preparingStatusMaxMins, 'minutes').toDate(),
- 'connectorStatuses': [ChargePointStatus.PREPARING]
+ 'connectorStatuses': [ChargePointStatus.PREPARING],
+ withSiteArea: true
}, Constants.DB_PARAMS_MAX_LIMIT);
for (const chargingStation of chargingStations.result) {
// Get site owner and then send notification

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
@@ -364,7 +364,7 @@ export default class OCPIUtilsService {
const evses: OCPIEvse[] = [];
// Convert charging stations to evse(s)
const chargingStations = await ChargingStationStorage.getChargingStations(tenant.id,
- { ...dbFilters, siteIDs: [ siteID ], public: true, issuer: true },
+ { ...dbFilters, siteIDs: [ siteID ], public: true, issuer: true, withSiteArea: true },
dbParams ?? Constants.DB_PARAMS_MAX_LIMIT,
[ 'id', 'chargePoints', 'connectors', 'coordinates', 'lastSeen', 'siteAreaID', 'siteID' ]);
for (const chargingStation of chargingStations.result) {

MODIFY
src/server/ocpp/utils/OCPPUtils.ts
src/server/ocpp/utils/OCPPUtils.ts
@@ -1029,7 +1029,7 @@ export default class OCPPUtils {
} else {
// Compute it for Charging Stations
const chargingStationsOfSiteArea = await ChargingStationStorage.getChargingStations(tenant.id,
- { siteAreaIDs: [siteArea.id] }, Constants.DB_PARAMS_MAX_LIMIT);
+ { siteAreaIDs: [siteArea.id], withSiteArea: true }, Constants.DB_PARAMS_MAX_LIMIT);
for (const chargingStationOfSiteArea of chargingStationsOfSiteArea.result) {
if (Utils.objectHasProperty(chargingStationOfSiteArea, 'connectors')) {
for (const connector of chargingStationOfSiteArea.connectors) {

MODIFY
src/server/rest/v1/service/ChargingStationService.ts
src/server/rest/v1/service/ChargingStationService.ts
@@ -1385,6 +1385,7 @@ export default class ChargingStationService {
search: filteredRequest.Search,
withNoSiteArea: filteredRequest.WithNoSiteArea,
withSite: filteredRequest.WithSite,
+ withSiteArea: true,
chargingStationIDs: filteredRequest.ChargingStationID ? filteredRequest.ChargingStationID.split('|') : null,
connectorStatuses: filteredRequest.ConnectorStatus ? filteredRequest.ConnectorStatus.split('|') : null,
connectorTypes: filteredRequest.ConnectorType ? filteredRequest.ConnectorType.split('|') : null,

MODIFY
src/server/rest/v1/service/LoggingService.ts
src/server/rest/v1/service/LoggingService.ts
@@ -106,7 +106,7 @@ export default class LoggingService {
if (Utils.isComponentActiveFromToken(req.user, TenantComponents.ORGANIZATION) && Authorizations.isSiteAdmin(req.user)) {
// Optimization: Retrieve Charging Stations to get the logs only for the Site Admin user
const chargingStations = await ChargingStationStorage.getChargingStations(req.user.tenantID,
- { siteIDs: req.user.sitesAdmin }, Constants.DB_PARAMS_MAX_LIMIT);
+ { siteIDs: req.user.sitesAdmin, withSiteArea: true }, Constants.DB_PARAMS_MAX_LIMIT);
// Check if Charging Station is already filtered
if (chargingStations.count === 0) {
filteredRequest.Source = '';

MODIFY
src/storage/mongodb/ChargingStationStorage.ts
src/storage/mongodb/ChargingStationStorage.ts
@@ -137,6 +137,7 @@ export default class ChargingStationStorage {
const chargingStationsMDB = await ChargingStationStorage.getChargingStations(tenantID, {
chargingStationIDs: [id],
withSite: true,
+ withSiteArea: true,
includeDeleted: params.includeDeleted,
issuer: params.issuer,
siteIDs: params.siteIDs,
@@ -148,6 +149,7 @@ export default class ChargingStationStorage {
projectFields?: string[]): Promise<ChargingStation> {
const chargingStationsMDB = await ChargingStationStorage.getChargingStations(tenantID, {
ocpiEvseID,
+ withSiteArea: true,
}, Constants.DB_PARAMS_SINGLE_RECORD, projectFields);
return chargingStationsMDB.count === 1 ? chargingStationsMDB.result[0] : null;
}
@@ -158,6 +160,7 @@ export default class ChargingStationStorage {
const chargingStationsMDB = await ChargingStationStorage.getChargingStations(tenantID, {
ocpiLocationID,
ocpiEvseUid,
+ withSiteArea: true
}, Constants.DB_PARAMS_SINGLE_RECORD, projectFields);
return chargingStationsMDB.count === 1 ? chargingStationsMDB.result[0] : null;
}
@@ -166,6 +169,7 @@ export default class ChargingStationStorage {
projectFields?: string[]): Promise<ChargingStation> {
const chargingStationsMDB = await ChargingStationStorage.getChargingStations(tenantID, {
oicpEvseID: oicpEvseID,
+ withSiteArea: true
}, Constants.DB_PARAMS_SINGLE_RECORD, projectFields);
return chargingStationsMDB.count === 1 ? chargingStationsMDB.result[0] : null;
}
@@ -173,7 +177,7 @@ export default class ChargingStationStorage {
public static async getChargingStations(tenantID: string,
params: {
search?: string; chargingStationIDs?: string[]; chargingStationSerialNumbers?: string[]; siteAreaIDs?: string[]; withNoSiteArea?: boolean;
- connectorStatuses?: string[]; connectorTypes?: string[]; statusChangedBefore?: Date;
+ connectorStatuses?: string[]; connectorTypes?: string[]; statusChangedBefore?: Date; withSiteArea?: boolean;
ocpiEvseUid?: string; ocpiEvseID?: string; ocpiLocationID?: string; oicpEvseID?: string;
siteIDs?: string[]; withSite?: boolean; includeDeleted?: boolean; offlineSince?: Date; issuer?: boolean;
locCoordinates?: number[]; locMaxDistanceMeters?: number; public?: boolean;
@@ -366,10 +370,12 @@ export default class ChargingStationStorage {
asField: 'connectors.user', oneToOneCardinality: true, objectIDFields: ['createdBy', 'lastChangedBy']
}, { sort: dbParams.sort });
// Site Area
+ if (params.withSiteArea) {
DatabaseUtils.pushSiteAreaLookupInAggregation({
tenantID, aggregation: aggregation, localField: 'siteAreaID', foreignField: '_id',
asField: 'siteArea', oneToOneCardinality: true
});
+ }
// Site
if (params.withSite && !params.withNoSiteArea) {
DatabaseUtils.pushSiteLookupInAggregation({
@@ -389,7 +395,6 @@ export default class ChargingStationStorage {
// Project
DatabaseUtils.projectFields(aggregation, projectFields);
// Reorder connector ID
- // TODO: To remove when SiteID optimization will be implemented
if (!Utils.containsGPSCoordinates(params.locCoordinates)) {
aggregation.push({
$sort: dbParams.sort

MODIFY
src/storage/mongodb/SiteStorage.ts
src/storage/mongodb/SiteStorage.ts
@@ -470,7 +470,7 @@ export default class SiteStorage {
if (params.withOnlyChargingStations || params.withAvailableChargingStations) {
// Get the chargers
const chargingStations = await ChargingStationStorage.getChargingStations(tenant.id,
- { siteIDs: [siteMDB.id], includeDeleted: false }, Constants.DB_PARAMS_MAX_LIMIT);
+ { siteIDs: [siteMDB.id], includeDeleted: false, withSiteArea: true }, Constants.DB_PARAMS_MAX_LIMIT);
// Skip site with no charging stations if asked
if (params.withOnlyChargingStations && chargingStations.count === 0) {
continue;

Force usage of Site Area to get Charging Stations