Renamed 'private' to 'public' property in Charging Station
MODIFY
src/client/ocpi/CpoOCPIClient.ts
src/client/ocpi/CpoOCPIClient.ts
@@ -514,7 +514,7 @@ export default class CpoOCPIClient extends OCPIClient {
module: MODULE_NAME, method: 'patchChargingStationStatus',
});
}
- if (chargingStation.private) {
+ if (!chargingStation.public) {
throw new BackendError({
source: chargingStation.id,
action: ServerAction.OCPI_PATCH_STATUS,

MODIFY
src/migration/MigrationHandler.ts
src/migration/MigrationHandler.ts
+import cluster from 'cluster';
+import moment from 'moment';
+import LockingManager from '../locking/LockingManager';
+import MigrationStorage from '../storage/mongodb/MigrationStorage';
+import { LockEntity } from '../types/Locking';
+import { ServerAction } from '../types/Server';
+import Constants from '../utils/Constants';
+import Logging from '../utils/Logging';
import AddActivePropertyToTagsTask from './tasks/AddActivePropertyToTagsTask';
import AddConsumptionAmpsToConsumptionsTask from './tasks/AddConsumptionAmpsToConsumptionsTask';
import AddInactivityStatusInTransactionsTask from './tasks/AddInactivityStatusInTransactionsTask';
@@ -10,26 +18,19 @@ import AddTagTypeTask from './tasks/AddTagTypeTask';
import AddTransactionRefundStatusTask from './tasks/AddTransactionRefundStatusTask';
import CleanupMeterValuesTask from './tasks/CleanupMeterValuesTask';
import CleanupOrphanBadgeTask from './tasks/CleanupOrphanBadgeTask';
-import Constants from '../utils/Constants';
import InitialCarImportTask from './tasks/InitialCarImportTask';
-import { LockEntity } from '../types/Locking';
-import LockingManager from '../locking/LockingManager';
-import Logging from '../utils/Logging';
import MigrateCoordinatesTask from './tasks/MigrateCoordinatesTask';
import MigrateOcpiSettingTask from './tasks/MigrateOcpiSettingTask';
import MigrateOcpiTransactionsTask from './tasks/MigrateOcpiTransactionsTask';
-import MigrationStorage from '../storage/mongodb/MigrationStorage';
+import RecomputeAllTransactionsConsumptionsTask from './tasks/RecomputeAllTransactionsConsumptionsTask';
+import RenameChargingStationPropertiesTask from './tasks/RenameChargingStationPropertiesTask';
import RenameTagPropertiesTask from './tasks/RenameTagPropertiesTask';
import RenameTransactionsAndConsumptionsTask from './tasks/RenameTransactionsAndConsumptionsTask';
-import { ServerAction } from '../types/Server';
import SiteUsersHashIDsTask from './tasks/SiteUsersHashIDsTask';
import UpdateChargingStationStaticLimitationTask from './tasks/UpdateChargingStationStaticLimitationTask';
import UpdateChargingStationTemplatesTask from './tasks/UpdateChargingStationTemplatesTask';
import UpdateConsumptionsToObjectIDsTask from './tasks/UpdateConsumptionsToObjectIDsTask';
import UpdateLimitsInConsumptionsTask from './tasks/UpdateLimitsInConsumptionsTask';
-import cluster from 'cluster';
-import moment from 'moment';
-import RecomputeAllTransactionsConsumptionsTask from './tasks/RecomputeAllTransactionsConsumptionsTask';
const MODULE_NAME = 'MigrationHandler';
@@ -78,6 +79,7 @@ export default class MigrationHandler {
currentMigrationTasks.push(new RenameTransactionsAndConsumptionsTask());
currentMigrationTasks.push(new AddConsumptionAmpsToConsumptionsTask());
currentMigrationTasks.push(new RecomputeAllTransactionsConsumptionsTask());
+ currentMigrationTasks.push(new RenameChargingStationPropertiesTask());
// Get the already done migrations from the DB
const migrationTasksDone = await MigrationStorage.getMigrations();
// Check

ADD
src/migration/tasks/RenameChargingStationPropertiesTask.ts
+import Constants from '../../utils/Constants';
+import Logging from '../../utils/Logging';
+import MigrationTask from '../MigrationTask';
+import { ServerAction } from '../../types/Server';
+import Tenant from '../../types/Tenant';
+import TenantStorage from '../../storage/mongodb/TenantStorage';
+import global from '../../types/GlobalType';
+
+const MODULE_NAME = 'RenameTagPropertiesTask';
+
+export default class RenameChargingStationPropertiesTask extends MigrationTask {
+ async migrate() {
+ const tenants = await TenantStorage.getTenants({}, Constants.DB_PARAMS_MAX_LIMIT);
+ for (const tenant of tenants.result) {
+ await this.migrateTenant(tenant);
+ }
+ }
+
+ async migrateTenant(tenant: Tenant) {
+ // Add the status property to the refunded transactions
+ const result = await global.database.getCollection<any>(tenant.id, 'chargingstations').updateMany(
+ {},
+ { $rename: { 'private': 'public' } },
+ { upsert: false }
+ );
+ // Log in the default tenant
+ if (result.modifiedCount > 0) {
+ Logging.logDebug({
+ tenantID: Constants.DEFAULT_TENANT,
+ action: ServerAction.MIGRATION,
+ module: MODULE_NAME, method: 'migrateTenant',
+ message: `${result.modifiedCount} Charging Stations' properties have been updated in Tenant '${tenant.name}' ('${tenant.subdomain}')`
+ });
+ }
+ }
+
+ getVersion() {
+ return '1.0';
+ }
+
+ getName() {
+ return 'RenameChargingStationPropertiesTask';
+ }
+}

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/CPOCommandsEndpoint.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/CPOCommandsEndpoint.ts
@@ -133,7 +133,7 @@ export default class CPOCommandsEndpoint extends AbstractEndpoint {
});
return this.getOCPIResponse(OCPICommandResponseType.REJECTED);
}
- if (!chargingStation.issuer || chargingStation.private) {
+ if (!chargingStation.issuer || !chargingStation.public) {
Logging.logDebug({
tenantID: tenant.id,
action: ServerAction.OCPI_START_SESSION,

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPIMapping.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPIMapping.ts
@@ -114,7 +114,7 @@ export default class OCPIMapping {
const evses: any = [];
// Convert charging stations to evse(s)
siteArea.chargingStations.forEach((chargingStation) => {
- if (chargingStation.issuer === true && !chargingStation.private) {
+ if (chargingStation.issuer === true && chargingStation.public) {
evses.push(...OCPIMapping.convertChargingStation2MultipleEvses(tenant, chargingStation, options));
}
});

MODIFY
src/server/ocpp/services/OCPPService.ts
src/server/ocpp/services/OCPPService.ts
@@ -1055,7 +1055,7 @@ export default class OCPPService {
private async updateOCPIStatus(tenantID: string, chargingStation: ChargingStation, connector: Connector) {
const tenant: Tenant = await TenantStorage.getTenant(tenantID);
- if (chargingStation.issuer && !chargingStation.private && Utils.isTenantComponentActive(tenant, TenantComponents.OCPI)) {
+ if (chargingStation.issuer && chargingStation.public && Utils.isTenantComponentActive(tenant, TenantComponents.OCPI)) {
try {
const ocpiClient = await OCPIClientFactory.getAvailableOcpiClient(tenant, OCPIRole.CPO) as CpoOCPIClient;
if (ocpiClient) {

MODIFY
src/server/rest/service/ChargingStationService.ts
src/server/rest/service/ChargingStationService.ts
@@ -70,8 +70,8 @@ export default class ChargingStationService {
if (Utils.objectHasProperty(filteredRequest, 'maximumPower')) {
chargingStation.maximumPower = filteredRequest.maximumPower;
}
- if (Utils.objectHasProperty(filteredRequest, 'private')) {
- chargingStation.private = filteredRequest.private;
+ if (Utils.objectHasProperty(filteredRequest, 'public')) {
+ chargingStation.public = filteredRequest.public;
}
if (Utils.objectHasProperty(filteredRequest, 'excludeFromSmartCharging')) {
chargingStation.excludeFromSmartCharging = filteredRequest.excludeFromSmartCharging;

MODIFY
src/server/rest/service/security/ChargingStationSecurity.ts
src/server/rest/service/security/ChargingStationSecurity.ts
+import sanitize from 'mongo-sanitize';
+import Authorizations from '../../../../authorization/Authorizations';
import { ChargingProfile, ChargingSchedule, ChargingSchedulePeriod, Profile } from '../../../../types/ChargingProfile';
import ChargingStation, { Command } from '../../../../types/ChargingStation';
-import { HttpChargingProfilesRequest, HttpChargingStationCommandRequest, HttpChargingStationGetFirmwareRequest, HttpChargingStationLimitPowerRequest, HttpChargingStationOcppParametersRequest, HttpChargingStationParamsUpdateRequest, HttpChargingStationRequest, HttpChargingStationSetMaxIntensitySocketRequest, HttpChargingStationsRequest, HttpIsAuthorizedRequest, HttpTriggerSmartChargingRequest } from '../../../../types/requests/HttpChargingStationRequest';
-
-import Authorizations from '../../../../authorization/Authorizations';
-import { ChargePointStatus } from '../../../../types/ocpp/OCPPServer';
-import { ChargingStationInError } from '../../../../types/InError';
import { DataResult } from '../../../../types/DataResult';
+import { ChargingStationInError } from '../../../../types/InError';
+import { ChargePointStatus, OCPPBootNotificationRequestExtended, OCPPStatusNotificationRequestExtended } from '../../../../types/ocpp/OCPPServer';
import HttpByIDRequest from '../../../../types/requests/HttpByIDRequest';
+import { HttpChargingProfilesRequest, HttpChargingStationCommandRequest, HttpChargingStationGetFirmwareRequest, HttpChargingStationLimitPowerRequest, HttpChargingStationOcppParametersRequest, HttpChargingStationParamsUpdateRequest, HttpChargingStationRequest, HttpChargingStationSetMaxIntensitySocketRequest, HttpChargingStationsRequest, HttpIsAuthorizedRequest, HttpTriggerSmartChargingRequest } from '../../../../types/requests/HttpChargingStationRequest';
import HttpDatabaseRequest from '../../../../types/requests/HttpDatabaseRequest';
import { InactivityStatus } from '../../../../types/Transaction';
-import UserSecurity from './UserSecurity';
import UserToken from '../../../../types/UserToken';
import Utils from '../../../../utils/Utils';
+import UserSecurity from './UserSecurity';
import UtilsSecurity from './UtilsSecurity';
-import sanitize from 'mongo-sanitize';
+
export default class ChargingStationSecurity {
@@ -151,20 +151,22 @@ export default class ChargingStationSecurity {
chargingStations.result = filteredChargingStations;
}
- public static filterStatusNotificationsResponse(statusNotifications, loggedUser: UserToken) {
+ public static filterStatusNotificationsResponse(statusNotifications: OCPPStatusNotificationRequestExtended[],
+ loggedUser: UserToken): OCPPStatusNotificationRequestExtended[] {
// Check
if (!Authorizations.canListChargingStations(loggedUser)) {
- return null;
+ return [];
}
return statusNotifications;
}
- public static filterBootNotificationsResponse(statusNotifications, loggedUser: UserToken) {
+ public static filterBootNotificationsResponse(bootNotifications: OCPPBootNotificationRequestExtended[],
+ loggedUser: UserToken): OCPPBootNotificationRequestExtended[] {
// Check
if (!Authorizations.canListChargingStations(loggedUser)) {
- return null;
+ return [];
}
- return statusNotifications;
+ return bootNotifications;
}
public static filterChargingStationOcppParametersRequest(request: any): HttpChargingStationRequest {
@@ -243,8 +245,8 @@ export default class ChargingStationSecurity {
if (Utils.objectHasProperty(request, 'excludeFromSmartCharging')) {
filteredRequest.excludeFromSmartCharging = UtilsSecurity.filterBoolean(request.excludeFromSmartCharging);
}
- if (Utils.objectHasProperty(request, 'private')) {
- filteredRequest.private = UtilsSecurity.filterBoolean(request.private);
+ if (Utils.objectHasProperty(request, 'public')) {
+ filteredRequest.public = UtilsSecurity.filterBoolean(request.public);
}
if (Utils.objectHasProperty(request, 'siteAreaID')) {
filteredRequest.siteAreaID = sanitize(request.siteAreaID);

MODIFY
src/storage/mongodb/ChargingStationStorage.ts
src/storage/mongodb/ChargingStationStorage.ts
@@ -435,7 +435,7 @@ export default class ChargingStationStorage {
templateHashOcppStandard: chargingStationToSave.templateHashOcppStandard,
templateHashOcppVendor: chargingStationToSave.templateHashOcppVendor,
issuer: Utils.convertToBoolean(chargingStationToSave.issuer),
- private: Utils.convertToBoolean(chargingStationToSave.private),
+ public: Utils.convertToBoolean(chargingStationToSave.public),
siteAreaID: Utils.convertToObjectID(chargingStationToSave.siteAreaID),
chargePointSerialNumber: chargingStationToSave.chargePointSerialNumber,
chargePointModel: chargingStationToSave.chargePointModel,

MODIFY
src/storage/mongodb/SiteAreaStorage.ts
src/storage/mongodb/SiteAreaStorage.ts
@@ -249,7 +249,7 @@ export default class SiteAreaStorage {
if (projectFields) {
DatabaseUtils.projectFields(aggregation,
[...projectFields, 'chargingStations.id', 'chargingStations.connectors', 'chargingStations.lastHeartBeat',
- 'chargingStations.deleted', 'chargingStations.cannotChargeInParallel', 'chargingStations.private', 'chargingStations.inactive']);
+ 'chargingStations.deleted', 'chargingStations.cannotChargeInParallel', 'chargingStations.public', 'chargingStations.inactive']);
}
// Read DB
const siteAreasMDB = await global.database.getCollection<any>(tenantID, 'siteareas')

MODIFY
src/types/ChargingStation.ts
src/types/ChargingStation.ts
@@ -16,7 +16,7 @@ export default interface ChargingStation extends CreatedUpdatedProps {
templateHashOcppStandard?: string;
templateHashOcppVendor?: string;
issuer: boolean;
- private: boolean;
+ public: boolean;
siteAreaID?: string;
chargePointSerialNumber: string;
chargePointModel: string;

MODIFY
src/types/requests/HttpChargingStationRequest.ts
src/types/requests/HttpChargingStationRequest.ts
@@ -35,7 +35,7 @@ export interface HttpChargingStationParamsUpdateRequest {
id: string;
chargingStationURL: string;
maximumPower: number;
- private: boolean;
+ public: boolean;
excludeFromSmartCharging: boolean;
siteAreaID: string;
coordinates: number[];

Renamed 'private' to 'public' property in Charging Station