Use of siteID/Site in Charging Station object
MODIFY
src/authorization/Authorizations.ts
src/authorization/Authorizations.ts
@@ -54,11 +54,11 @@ export default class Authorizations {
public static async canStartTransaction(loggedUser: UserToken, chargingStation: ChargingStation): Promise<boolean> {
let context: AuthorizationContext;
if (Utils.isComponentActiveFromToken(loggedUser, TenantComponents.ORGANIZATION)) {
- if (!chargingStation || !chargingStation.siteArea || !chargingStation.siteArea.site) {
+ if (!chargingStation || !chargingStation.siteArea || !chargingStation.site) {
return false;
}
context = {
- site: chargingStation.siteArea.site.id,
+ site: chargingStation.site.id,
sites: loggedUser.sites,
sitesAdmin: loggedUser.sitesAdmin
};
@@ -269,7 +269,7 @@ export default class Authorizations {
context = {
tagIDs: loggedUser.tagIDs,
owner: loggedUser.id,
- site: isOrgCompActive && chargingStation.siteArea ? chargingStation.siteArea.site.id : null,
+ site: isOrgCompActive ? chargingStation.siteID : null,
sites: loggedUser.sites,
sitesAdmin: loggedUser.sitesAdmin
};
@@ -1068,9 +1068,8 @@ export default class Authorizations {
});
}
// Site -----------------------------------------------------
- chargingStation.siteArea.site = chargingStation.siteArea.site ??
- (chargingStation.siteArea.siteID ? await SiteStorage.getSite(tenant, chargingStation.siteArea.siteID) : null);
- if (!chargingStation.siteArea.site) {
+ chargingStation.site = await SiteStorage.getSite(tenant, chargingStation.siteID);
+ if (!chargingStation.site) {
// Reject Site Not Found
throw new BackendError({
source: chargingStation.id,

MODIFY
src/authorization/AuthorizationsDefinition.ts
src/authorization/AuthorizationsDefinition.ts
@@ -181,7 +181,7 @@ const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
attributes: [
'id', 'inactive', 'public', 'chargingStationURL', 'issuer', 'maximumPower', 'excludeFromSmartCharging', 'lastReboot',
'siteAreaID', 'siteArea.id', 'siteArea.name', 'siteArea.smartCharging', 'siteArea.siteID',
- 'siteArea.site.id', 'siteArea.site.name', 'siteID', 'voltage', 'coordinates', 'forceInactive', 'manualConfiguration', 'firmwareUpdateStatus',
+ 'site.id', 'site.name', 'siteID', 'voltage', 'coordinates', 'forceInactive', 'manualConfiguration', 'firmwareUpdateStatus',
'capabilities', 'endpoint', 'chargePointVendor', 'chargePointModel', 'ocppVersion', 'ocppProtocol', 'lastSeen',
'firmwareVersion', 'currentIPAddress', 'ocppStandardParameters', 'ocppVendorParameters', 'connectors', 'chargePoints',
'createdOn', 'chargeBoxSerialNumber', 'chargePointSerialNumber', 'powerLimitUnit'
@@ -471,7 +471,7 @@ const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
attributes: [
'id', 'inactive', 'public', 'chargingStationURL', 'issuer', 'maximumPower', 'excludeFromSmartCharging', 'lastReboot',
'siteAreaID', 'siteArea.id', 'siteArea.name', 'siteArea.smartCharging', 'siteArea.siteID',
- 'siteArea.site.id', 'siteArea.site.name', 'siteID', 'voltage', 'coordinates', 'forceInactive', 'manualConfiguration', 'firmwareUpdateStatus',
+ 'site.id', 'site.name', 'siteID', 'voltage', 'coordinates', 'forceInactive', 'manualConfiguration', 'firmwareUpdateStatus',
'capabilities', 'endpoint', 'chargePointVendor', 'chargePointModel', 'ocppVersion', 'ocppProtocol', 'lastSeen',
'firmwareVersion', 'currentIPAddress', 'ocppStandardParameters', 'ocppVendorParameters', 'connectors', 'chargePoints',
'createdOn', 'chargeBoxSerialNumber', 'chargePointSerialNumber', 'powerLimitUnit'
@@ -661,7 +661,7 @@ const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
attributes: [
'id', 'inactive', 'public', 'chargingStationURL', 'issuer', 'maximumPower', 'excludeFromSmartCharging', 'lastReboot',
'siteAreaID', 'siteArea.id', 'siteArea.name', 'siteArea.smartCharging', 'siteArea.siteID',
- 'siteArea.site.id', 'siteArea.site.name', 'siteID', 'voltage', 'coordinates', 'forceInactive', 'manualConfiguration', 'firmwareUpdateStatus',
+ 'site.id', 'site.name', 'siteID', 'voltage', 'coordinates', 'forceInactive', 'manualConfiguration', 'firmwareUpdateStatus',
'capabilities', 'endpoint', 'chargePointVendor', 'chargePointModel', 'ocppVersion', 'ocppProtocol', 'lastSeen',
'firmwareVersion', 'currentIPAddress', 'ocppStandardParameters', 'ocppVendorParameters', 'connectors', 'chargePoints',
'createdOn', 'chargeBoxSerialNumber', 'chargePointSerialNumber', 'powerLimitUnit'

MODIFY
src/server/ocpp/services/OCPPService.ts
src/server/ocpp/services/OCPPService.ts
@@ -698,9 +698,10 @@ export default class OCPPService {
private async processConnectorStatusNotification(tenant: Tenant, chargingStation: ChargingStation, statusNotification: OCPPStatusNotificationRequestExtended) {
// Get Connector
- const connector = await this.checkAndGetConnectorFromStatusNotification(tenant, chargingStation, statusNotification);
+ const { connector, newConnector } = await this.checkAndGetConnectorFromStatusNotification(
+ tenant, chargingStation, statusNotification);
// Status must be different
- if (!await this.hasStatusNotificationChanged(tenant, chargingStation, connector, statusNotification)) {
+ if (!newConnector && !await this.hasStatusNotificationChanged(tenant, chargingStation, connector, statusNotification)) {
return;
}
// Check last Transaction
@@ -806,9 +807,12 @@ export default class OCPPService {
}
private async checkAndGetConnectorFromStatusNotification(tenant: Tenant, chargingStation: ChargingStation,
- statusNotification: OCPPStatusNotificationRequestExtended): Promise<Connector> {
+ statusNotification: OCPPStatusNotificationRequestExtended): Promise<{ connector: Connector, newConnector: boolean }> {
+ let newConnector = false;
let foundConnector = Utils.getConnectorFromID(chargingStation, statusNotification.connectorId);
if (!foundConnector) {
+ // To be saved
+ newConnector = true;
// Check backup first
foundConnector = Utils.getBackupConnectorFromID(chargingStation, statusNotification.connectorId);
if (foundConnector) {
@@ -838,7 +842,7 @@ export default class OCPPService {
}
}
}
- return foundConnector;
+ return { connector: foundConnector, newConnector };
}
private async checkAndUpdateLastCompletedTransaction(tenant: Tenant, chargingStation: ChargingStation,
@@ -1683,9 +1687,8 @@ export default class OCPPService {
// Set the Site Area ID
startTransaction.siteAreaID = chargingStation.siteAreaID;
// Set the Site ID. ChargingStation$siteArea$site checked by TagIDAuthorized.
- const site = chargingStation.siteArea ? chargingStation.siteArea.site : null;
- if (site) {
- startTransaction.siteID = site.id;
+ if (chargingStation.site) {
+ startTransaction.siteID = chargingStation.site.id;
}
}
}

MODIFY
src/server/rest/v1/service/AuthorizationService.ts
src/server/rest/v1/service/AuthorizationService.ts
@@ -524,7 +524,7 @@ export default class AuthorizationService {
projectFields: [
'id', 'inactive', 'public', 'chargingStationURL', 'issuer', 'maximumPower', 'excludeFromSmartCharging', 'lastReboot',
'siteAreaID', 'siteArea.id', 'siteArea.name', 'siteArea.smartCharging', 'siteArea.siteID',
- 'siteArea.site.id', 'siteArea.site.name', 'siteID', 'voltage', 'coordinates', 'forceInactive', 'manualConfiguration', 'firmwareUpdateStatus',
+ 'site.id', 'site.name', 'siteID', 'voltage', 'coordinates', 'forceInactive', 'manualConfiguration', 'firmwareUpdateStatus',
'capabilities', 'endpoint', 'chargePointVendor', 'chargePointModel', 'ocppVersion', 'ocppProtocol', 'lastSeen',
'firmwareVersion', 'currentIPAddress', 'ocppStandardParameters', 'ocppVendorParameters', 'connectors', 'chargePoints',
'createdOn', 'chargeBoxSerialNumber', 'chargePointSerialNumber', 'powerLimitUnit'

MODIFY
src/server/rest/v1/service/ChargingStationService.ts
src/server/rest/v1/service/ChargingStationService.ts
@@ -950,7 +950,7 @@ export default class ChargingStationService {
// Get OCPP Params
const dataToExport = ChargingStationService.convertOCPPParamsToCSV({
params: ocppParameters.result,
- siteName: chargingStation.siteArea.site.name,
+ siteName: chargingStation.site.name,
siteAreaName: chargingStation.siteArea.name,
chargingStationName: chargingStation.id
}, writeHeader);
@@ -1357,7 +1357,7 @@ export default class ChargingStationService {
projectFields = [
'id', 'inactive', 'connectorsStatus', 'connectorsConsumption', 'public', 'firmwareVersion', 'chargePointVendor', 'chargePointModel',
'ocppVersion', 'ocppProtocol', 'lastSeen', 'firmwareUpdateStatus', 'coordinates', 'issuer', 'voltage', 'distanceMeters',
- 'siteAreaID', 'siteArea.id', 'siteArea.name', 'siteArea.siteID', 'siteArea.site.name', 'siteArea.address', 'siteID', 'maximumPower', 'powerLimitUnit',
+ 'siteAreaID', 'siteArea.id', 'siteArea.name', 'siteArea.siteID', 'site.name', 'siteArea.address', 'siteID', 'maximumPower', 'powerLimitUnit',
'chargePointModel', 'chargePointSerialNumber', 'chargeBoxSerialNumber', 'connectors.connectorId', 'connectors.status', 'connectors.type', 'connectors.power', 'connectors.errorCode',
'connectors.currentTotalConsumptionWh', 'connectors.currentInstantWatts', 'connectors.currentStateOfCharge', 'connectors.info',
'connectors.currentTransactionID', 'connectors.currentTotalInactivitySecs', 'connectors.currentTagID', 'chargePoints', 'lastReboot', 'createdOn',

MODIFY
src/storage/mongodb/ChargingStationStorage.ts
src/storage/mongodb/ChargingStationStorage.ts
@@ -377,10 +377,10 @@ export default class ChargingStationStorage {
});
}
// Site
- if (params.withSite && !params.withNoSiteArea) {
+ if (params.withSite) {
DatabaseUtils.pushSiteLookupInAggregation({
- tenantID, aggregation: aggregation, localField: 'siteArea.siteID', foreignField: '_id',
- asField: 'siteArea.site', oneToOneCardinality: true
+ tenantID, aggregation: aggregation, localField: 'siteID', foreignField: '_id',
+ asField: 'site', oneToOneCardinality: true
});
}
// Change ID

MODIFY
src/storage/mongodb/TransactionStorage.ts
src/storage/mongodb/TransactionStorage.ts
@@ -273,7 +273,7 @@ export default class TransactionStorage {
chargeBoxIDs?: string[]; siteAreaIDs?: string[]; siteIDs?: string[]; connectorIDs?: number[]; startDateTime?: Date;
endDateTime?: Date; stop?: any; minimalPrice?: boolean; reportIDs?: string[]; tagIDs?: string[]; inactivityStatus?: string[];
ocpiSessionID?: string; ocpiAuthorizationID?: string; ocpiSessionDateFrom?: Date; ocpiSessionDateTo?: Date; ocpiCdrDateFrom?: Date; ocpiCdrDateTo?: Date;
- ocpiSessionChecked?: boolean; ocpiCdrChecked?: boolean; oicpSessionID?: string;
+ ocpiSessionChecked?: boolean; ocpiCdrChecked?: boolean; oicpSessionID?: string; withSite?: boolean; withSiteArea?: boolean;
statistics?: 'refund' | 'history' | 'ongoing'; refundStatus?: string[]; withTag?: boolean; hasUserID?: boolean;
},
dbParams: DbParams, projectFields?: string[]):
@@ -615,18 +615,32 @@ export default class TransactionStorage {
}
});
}
- // Transaction tag
+ // Tag
if (params.withTag) {
DatabaseUtils.pushTagLookupInAggregation({
tenantID, aggregation: aggregation, asField: 'tag', localField: 'tagID',
foreignField: '_id', oneToOneCardinality: true
});
}
- // Charge Box
+ // Charging Station
DatabaseUtils.pushChargingStationLookupInAggregation({
tenantID, aggregation: aggregation, localField: 'chargeBoxID', foreignField: '_id',
asField: 'chargeBox', oneToOneCardinality: true, oneToOneCardinalityNotNull: false
});
+ // Site Area
+ if (params.withSiteArea) {
+ DatabaseUtils.pushSiteAreaLookupInAggregation({
+ tenantID, aggregation: aggregation, localField: 'siteAreaID', foreignField: '_id',
+ asField: 'siteArea', oneToOneCardinality: true
+ });
+ }
+ // Site
+ if (params.withSite) {
+ DatabaseUtils.pushSiteLookupInAggregation({
+ tenantID, aggregation: aggregation, localField: 'siteID', foreignField: '_id',
+ asField: 'site', oneToOneCardinality: true
+ });
+ }
DatabaseUtils.pushConvertObjectIDToString(aggregation, 'chargeBox.siteAreaID');
// Add Connector and Status
if (projectFields && projectFields.includes('status')) {

MODIFY
src/types/ChargingStation.ts
src/types/ChargingStation.ts
@@ -7,6 +7,7 @@ import { KeyValue } from './GlobalType';
import { OCPIEvse } from './ocpi/OCPIEvse';
import { OICPEvseDataRecord } from './oicp/OICPEvse';
import { OICPIdentification } from './oicp/OICPIdentification';
+import Site from './Site';
import SiteArea from './SiteArea';
import User from './User';
@@ -54,6 +55,7 @@ export default interface ChargingStation extends CreatedUpdatedProps {
remoteAuthorizations: RemoteAuthorization[];
currentIPAddress?: string|string[];
siteArea?: SiteArea;
+ site?: Site;
capabilities?: ChargingStationCapabilities;
ocppStandardParameters?: KeyValue[];
ocppVendorParameters?: KeyValue[];

Use of siteID/Site in Charging Station object