Added missing log's actions
Adjusted Server's actions
MODIFY
src/client/ocpi/CpoOCPIClient.ts
src/client/ocpi/CpoOCPIClient.ts
@@ -129,7 +129,7 @@ export default class CpoOCPIClient extends OCPIClient {
const emspUser = emspUsersMap.get(email);
// Get the Tag
const emspTag = tags.result.find((tag) => tag.id === token.uid);
- await OCPIUtilsService.updateToken(this.tenant, token, emspTag, emspUser);
+ await OCPIUtilsService.updateToken(this.tenant, token, emspTag, emspUser, ServerAction.OCPI_CPO_PULL_TOKENS);
result.success++;
} catch (error) {
result.failure++;

MODIFY
src/client/ocpi/EmspOCPIClient.ts
src/client/ocpi/EmspOCPIClient.ts
@@ -267,7 +267,7 @@ export default class EmspOCPIClient extends OCPIClient {
const startTime = new Date().getTime();
// Get cdrs endpoint url
let cdrsUrl = this.getEndpointUrl('cdrs', ServerAction.OCPI_EMSP_PULL_CDRS);
- const momentFrom = moment().utc().subtract(2, 'days').startOf('day');
+ const momentFrom = moment().utc().subtract(7, 'days').startOf('day');
cdrsUrl = `${cdrsUrl}?date_from=${momentFrom.format()}&limit=10`;
let nextResult = true;
do {
@@ -283,7 +283,7 @@ export default class EmspOCPIClient extends OCPIClient {
if (!Utils.isEmptyArray(cdrs)) {
await Promise.map(cdrs, async (cdr: OCPICdr) => {
try {
- await OCPIUtilsService.processCdr(this.tenant, cdr);
+ await OCPIUtilsService.processCdr(this.tenant, cdr, ServerAction.OCPI_EMSP_PULL_CDRS);
result.success++;
} catch (error) {
result.failure++;

MODIFY
src/server/ocpi/AbstractOCPIService.ts
src/server/ocpi/AbstractOCPIService.ts
@@ -102,7 +102,7 @@ export default abstract class AbstractOCPIService {
res.json(OCPIUtils.success({ 'version': this.getVersion(), 'endpoints': supportedEndpoints }));
}
- public async processEndpointAction(action: ServerAction, req: TenantIdHoldingRequest, res: Response, next: NextFunction): Promise<void> {
+ public async processEndpointAction(ocpiAction: string, req: TenantIdHoldingRequest, res: Response, next: NextFunction): Promise<void> {
try {
const registeredEndpoints = this.getRegisteredEndpoints();
// Get token from header
@@ -167,11 +167,11 @@ export default abstract class AbstractOCPIService {
// Pass tenant id to req
req.user.tenantID = tenant.id;
// Handle request action (endpoint)
- const endpoint = registeredEndpoints.get(action);
+ const endpoint = registeredEndpoints.get(ocpiAction);
if (endpoint) {
await Logging.logDebug({
tenantID: tenant.id,
- module: MODULE_NAME, method: action,
+ module: MODULE_NAME, method: ocpiAction,
message: `>> OCPI Request ${req.method} ${req.originalUrl}`,
action: ServerAction.OCPI_ENDPOINT,
detailedMessages: { params: req.body }
@@ -180,7 +180,7 @@ export default abstract class AbstractOCPIService {
if (response) {
await Logging.logDebug({
tenantID: tenant.id,
- module: MODULE_NAME, method: action,
+ module: MODULE_NAME, method: ocpiAction,
message: `<< OCPI Response ${req.method} ${req.originalUrl}`,
action: ServerAction.OCPI_ENDPOINT,
detailedMessages: { response }
@@ -189,7 +189,7 @@ export default abstract class AbstractOCPIService {
} else {
await Logging.logWarning({
tenantID: tenant.id,
- module: MODULE_NAME, method: action,
+ module: MODULE_NAME, method: ocpiAction,
message: `<< OCPI Endpoint ${req.method} ${req.originalUrl} not implemented`,
action: ServerAction.OCPI_ENDPOINT
});
@@ -200,26 +200,20 @@ export default abstract class AbstractOCPIService {
module: MODULE_NAME, method: 'processEndpointAction',
action: ServerAction.OCPI_ENDPOINT,
errorCode: HTTPError.NOT_IMPLEMENTED_ERROR,
- message: `Endpoint ${action} not implemented`,
+ message: `Endpoint '${ocpiAction}' not implemented`,
ocpiError: OCPIStatusCode.CODE_3000_GENERIC_SERVER_ERROR
});
}
} catch (error) {
await Logging.logError({
tenantID: req.tenant?.id ?? Constants.DEFAULT_TENANT,
- module: MODULE_NAME, method: action,
+ module: MODULE_NAME, method: ocpiAction,
message: `<< OCPI Response Error ${req.method} ${req.originalUrl}`,
- action: ServerAction.OCPI_ENDPOINT,
+ action: error.params?.action ?? ServerAction.OCPI_ENDPOINT,
detailedMessages: { error: error.stack }
});
- await Logging.logActionExceptionMessage(req.user && req.user.tenantID ? req.user.tenantID : Constants.DEFAULT_TENANT, ServerAction.OCPI_ENDPOINT, error);
- let errorCode: any = {};
- if (error instanceof AppError || error instanceof AppAuthError) {
- errorCode = error.params.errorCode;
- } else {
- errorCode = HTTPError.GENERAL_ERROR;
- }
- res.status(errorCode).json(OCPIUtils.toErrorResponse(error));
+ await Logging.logActionExceptionMessage(req.tenant?.id ?? Constants.DEFAULT_TENANT, error.params?.action ?? ServerAction.OCPI_ENDPOINT, error);
+ res.status(error.params?.errorCode ?? HTTPError.GENERAL_ERROR).json(OCPIUtils.toErrorResponse(error));
}
}
}

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
@@ -470,10 +470,10 @@ export default class OCPIUtilsService {
await OCPPUtils.updateChargingStationConnectorRuntimeDataWithTransaction(tenant, chargingStation, transaction, true);
}
- public static async processCdr(tenant: Tenant, cdr: OCPICdr): Promise<void> {
+ public static async processCdr(tenant: Tenant, cdr: OCPICdr, action: ServerAction): Promise<void> {
if (!OCPIUtilsService.validateCdr(cdr)) {
throw new AppError({
- module: MODULE_NAME, method: 'processCdr',
+ module: MODULE_NAME, method: 'processCdr', action,
errorCode: HTTPError.GENERAL_ERROR,
message: 'Cdr object is invalid',
detailedMessages: { cdr },
@@ -484,7 +484,7 @@ export default class OCPIUtilsService {
const transaction = await TransactionStorage.getOCPITransactionBySessionID(tenant, cdr.id);
if (!transaction) {
throw new AppError({
- module: MODULE_NAME, method: 'processCdr',
+ module: MODULE_NAME, method: 'processCdr', action,
errorCode: HTTPError.GENERAL_ERROR,
message: `No Transaction found for OCPI CDR ID '${cdr.id}'`,
detailedMessages: { cdr },
@@ -496,7 +496,7 @@ export default class OCPIUtilsService {
if (!chargingStation) {
throw new AppError({
...LoggingHelper.getTransactionProperties(transaction),
- module: MODULE_NAME, method: 'processCdr',
+ module: MODULE_NAME, method: 'processCdr', action,
errorCode: HTTPError.GENERAL_ERROR,
message: 'Charging Station does not exist',
detailedMessages: { transaction, cdr },
@@ -541,10 +541,10 @@ export default class OCPIUtilsService {
await OCPPUtils.updateChargingStationConnectorRuntimeDataWithTransaction(tenant, chargingStation, transaction, true);
}
- public static async updateToken(tenant: Tenant, token: OCPIToken, tag: Tag, emspUser: User): Promise<void> {
+ public static async updateToken(tenant: Tenant, token: OCPIToken, tag: Tag, emspUser: User, action: ServerAction): Promise<void> {
if (!OCPIUtilsService.validateToken(token)) {
throw new AppError({
- module: MODULE_NAME, method: 'updateToken',
+ module: MODULE_NAME, method: 'updateToken', action,
errorCode: StatusCodes.BAD_REQUEST,
message: 'Token object is invalid',
detailedMessages: { token },
@@ -554,7 +554,7 @@ export default class OCPIUtilsService {
// External organization
if (!emspUser) {
throw new AppError({
- module: MODULE_NAME, method: 'updateToken',
+ module: MODULE_NAME, method: 'updateToken', action,
errorCode: StatusCodes.CONFLICT,
message: 'eMSP User is mandatory',
detailedMessages: { token },
@@ -564,7 +564,7 @@ export default class OCPIUtilsService {
// External organization
if (emspUser.issuer) {
throw new AppError({
- module: MODULE_NAME, method: 'updateToken',
+ module: MODULE_NAME, method: 'updateToken', action,
errorCode: StatusCodes.CONFLICT,
message: 'Token already assigned to an internal user',
actionOnUser: emspUser,
@@ -575,7 +575,7 @@ export default class OCPIUtilsService {
// Check the tag
if (tag?.issuer) {
throw new AppError({
- module: MODULE_NAME, method: 'checkExistingTag',
+ module: MODULE_NAME, method: 'updateToken', action,
errorCode: StatusCodes.CONFLICT,
message: 'Token already exists in the current organization',
detailedMessages: token,

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/cpo/CPOTokensEndpoint.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/cpo/CPOTokensEndpoint.ts
@@ -142,7 +142,7 @@ export default class CPOTokensEndpoint extends AbstractEndpoint {
detailedMessages: { operator, token, tag }
});
}
- await OCPIUtilsService.updateToken(tenant, token, tag, tag.user);
+ await OCPIUtilsService.updateToken(tenant, token, tag, tag.user, ServerAction.OCPI_CPO_PUT_TOKEN);
return OCPIUtils.success();
}

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/emsp/EMSPCdrsEndpoint.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/emsp/EMSPCdrsEndpoint.ts
@@ -71,7 +71,7 @@ export default class EMSPCdrsEndpoint extends AbstractEndpoint {
private async postCdrRequest(req: Request, res: Response, next: NextFunction, tenant: Tenant): Promise<OCPIResponse> {
const cdr: OCPICdr = req.body as OCPICdr;
- await OCPIUtilsService.processCdr(tenant, cdr);
+ await OCPIUtilsService.processCdr(tenant, cdr, ServerAction.OCPI_EMSP_POST_CDR);
res.setHeader('Location', OCPIUtils.buildLocationUrl(req, this.getBaseUrl(req), cdr.id));
return OCPIUtils.success({});
}

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -144,36 +144,37 @@ export enum ServerAction {
OCPI_POST_CREDENTIALS = 'OcpiPostCredentials',
OCPI_DELETE_CREDENTIALS = 'OcpiDeleteCredentials',
- OCPI_CPO_AUTHORIZE_TOKEN = 'OcpiCpoAuthorizeToken',
OCPI_CPO_COMMAND = 'OcpiCpoCommand',
- OCPI_CPO_PUT_TOKEN = 'OcpiCpoPutToken',
- OCPI_CPO_PATCH_TOKEN = 'OcpiCpoPatchToken',
OCPI_CPO_PATCH_STATUS = 'OcpiCpoPatchStatus',
OCPI_CPO_CHECK_CDRS = 'OcpiCpoCheckCdrs',
OCPI_CPO_CHECK_SESSIONS = 'OcpiCpoCheckSessions',
- OCPI_CPO_CHECK_LOCATIONS = 'OcpiCpoCheckLocations',
- OCPI_CPO_PUSH_SESSIONS = 'OcpiCpoPushSessions',
- OCPI_CPO_PUSH_EVSE_STATUSES = 'OcpiCpoPushEVSEStatuses',
- OCPI_CPO_PUSH_CDRS = 'OcpiCpoPushCdrs',
OCPI_CPO_PULL_SESSIONS = 'OcpiCpoPullSessions',
- OCPI_CPO_PULL_TOKENS = 'OcpiCpoPullTokens',
+ OCPI_CPO_PUSH_SESSIONS = 'OcpiCpoPushSessions',
OCPI_CPO_START_SESSION = 'OcpiCpoStartSession',
OCPI_CPO_STOP_SESSION = 'OcpiCpoStopSession',
+ OCPI_CPO_CHECK_LOCATIONS = 'OcpiCpoCheckLocations',
OCPI_CPO_GET_LOCATIONS = 'OcpiCpoGetLocations',
+ OCPI_CPO_PUSH_EVSE_STATUSES = 'OcpiCpoPushEVSEStatuses',
+ OCPI_CPO_PUSH_CDRS = 'OcpiCpoPushCdrs',
+ OCPI_CPO_PULL_TOKENS = 'OcpiCpoPullTokens',
OCPI_CPO_GET_TOKEN = 'OcpiCpoGetToken',
+ OCPI_CPO_PUT_TOKEN = 'OcpiCpoPutToken',
+ OCPI_CPO_PATCH_TOKEN = 'OcpiCpoPatchToken',
+ OCPI_CPO_AUTHORIZE_TOKEN = 'OcpiCpoAuthorizeToken',
OCPI_CPO_GET_TARIFFS = 'OcpiCpoGetTariffs',
OCPI_EMSP_AUTHORIZE_TOKEN = 'OcpiEmspAuthorizeToken',
OCPI_EMSP_PATCH_LOCATION = 'OcpiEmspPatchLocation',
- OCPI_EMSP_PATCH_SESSION = 'OcpiEmspPatchSession',
- OCPI_EMSP_PUT_LOCATION = 'OcpiEmspPutLocation',
- OCPI_EMSP_PUT_SESSION = 'OcpiEmspPutSession',
- OCPI_EMSP_PUSH_TOKENS = 'OcpiEmspPushTokens',
- OCPI_EMSP_PULL_CDRS = 'OcpiEmspPullCdrs',
OCPI_EMSP_PULL_LOCATIONS = 'OcpiEmspPullLocations',
+ OCPI_EMSP_PUT_LOCATION = 'OcpiEmspPutLocation',
OCPI_EMSP_PULL_SESSIONS = 'OcpiEmspPullSessions',
+ OCPI_EMSP_PATCH_SESSION = 'OcpiEmspPatchSession',
+ OCPI_EMSP_PUT_SESSION = 'OcpiEmspPutSession',
OCPI_EMSP_START_SESSION = 'OcpiEmspStartSession',
OCPI_EMSP_STOP_SESSION = 'OcpiEmspStopSession',
+ OCPI_EMSP_PUSH_TOKENS = 'OcpiEmspPushTokens',
+ OCPI_EMSP_PULL_CDRS = 'OcpiEmspPullCdrs',
+ OCPI_EMSP_POST_CDR = 'OcpiEmspPostCdr',
OCPI_EMSP_RESERVE_NOW = 'OcpiEmspReserveNow',
OCPI_EMSP_UNLOCK_CONNECTOR = 'OcpiEmspUnlockConnector',
OCPI_EMSP_GET_TARIFF = 'OcpiEmspGetTariff',

Added missing log's actions
Adjusted Server's actions