Remove import tags
MODIFY
src/scheduler/SchedulerManager.ts
src/scheduler/SchedulerManager.ts
@@ -7,7 +7,6 @@ import CheckSessionNotStartedAfterAuthorizeTask from './tasks/CheckSessionNotSta
import CheckUserAccountInactivityTask from './tasks/CheckUserAccountInactivityTask';
import Configuration from '../utils/Configuration';
import Constants from '../utils/Constants';
-import ImportTagsTask from './tasks/ImportTagsTask';
import ImportUsersTask from './tasks/ImportUsersTask';
import Logging from '../utils/Logging';
import LoggingDatabaseTableCleanupTask from './tasks/LoggingDatabaseTableCleanupTask';
@@ -136,9 +135,6 @@ export default class SchedulerManager {
case 'ImportUsersTask':
schedulerTask = new ImportUsersTask();
break;
- case 'ImportTagsTask':
- schedulerTask = new ImportTagsTask();
- break;
case 'MigrateSensitiveDataTask':
schedulerTask = new MigrateSensitiveDataTask();
break;

DELETE
src/scheduler/tasks/ImportTagsTask.ts
-import { ActionsResponse, ImportStatus } from '../../types/GlobalType';
-import Tag, { ImportedTag } from '../../types/Tag';
-
-import Constants from '../../utils/Constants';
-import { DataResult } from '../../types/DataResult';
-import DbParams from '../../types/database/DbParams';
-import LockingHelper from '../../locking/LockingHelper';
-import LockingManager from '../../locking/LockingManager';
-import Logging from '../../utils/Logging';
-import SchedulerTask from '../SchedulerTask';
-import { ServerAction } from '../../types/Server';
-import TagStorage from '../../storage/mongodb/TagStorage';
-import { TaskConfig } from '../../types/TaskConfig';
-import Tenant from '../../types/Tenant';
-import Utils from '../../utils/Utils';
-
-const MODULE_NAME = 'SynchronizeUsersImportTask';
-
-export default class ImportTagsTask extends SchedulerTask {
- public async processTenant(tenant: Tenant, config?: TaskConfig): Promise<void> {
- const importTagsLock = await LockingHelper.createImportTagsLock(tenant.id);
- if (importTagsLock) {
- try {
- const dbParams: DbParams = { limit: Constants.IMPORT_PAGE_SIZE, skip: 0 };
- let importedTags: DataResult<ImportedTag>;
- const result: ActionsResponse = {
- inError: 0,
- inSuccess: 0,
- };
- const startTime = new Date().getTime();
- // Get total number of Tags to import
- const totalTagsToImport = await TagStorage.getImportedTagsCount(tenant.id);
- if (totalTagsToImport > 0) {
- await Logging.logInfo({
- tenantID: tenant.id,
- action: ServerAction.TAGS_IMPORT,
- module: MODULE_NAME, method: 'processTenant',
- message: `${totalTagsToImport} Tag(s) are going to be imported...`
- });
- }
- do {
- // Get the imported tags
- importedTags = await TagStorage.getImportedTags(tenant.id, { status: ImportStatus.READY }, dbParams);
- for (const importedTag of importedTags.result) {
- try {
- // Existing tags
- const foundTag = await TagStorage.getTag(tenant.id, importedTag.id);
- if (foundTag) {
- // Check tag is already in use
- if (!foundTag.issuer) {
- throw new Error('Tag is not local to the organization');
- }
- if (foundTag.deleted) {
- throw new Error('Tag is deleted');
- }
- if (foundTag.userID) {
- throw new Error('Tag is already assigned to an user');
- }
- if (foundTag.active) {
- throw new Error('Tag is already active');
- }
- // Update it
- await TagStorage.saveTag(tenant.id, { ...foundTag, ...importedTag });
- // Remove the imported Tag
- await TagStorage.deleteImportedTag(tenant.id, importedTag.id);
- result.inSuccess++;
- continue;
- }
- // New Tag
- const tag: Tag = {
- id: importedTag.id,
- description: importedTag.description,
- issuer: true,
- deleted: false,
- active: false,
- createdBy: { id: importedTag.importedBy },
- createdOn: importedTag.importedOn,
- };
- // Save the new Tag
- await TagStorage.saveTag(tenant.id, tag);
- // Remove the imported Tag
- await TagStorage.deleteImportedTag(tenant.id, importedTag.id);
- result.inSuccess++;
- } catch (error) {
- // Update the imported Tag
- importedTag.status = ImportStatus.ERROR;
- importedTag.errorDescription = error.message;
- result.inError++;
- // Update it
- await TagStorage.saveImportedTag(tenant.id, importedTag);
- // Log
- await Logging.logError({
- tenantID: tenant.id,
- action: ServerAction.TAGS_IMPORT,
- module: MODULE_NAME, method: 'processTenant',
- message: `Error when importing Tag ID '${importedTag.id}': ${error.message}`,
- detailedMessages: { tag: importedTag, error: error.message, stack: error.stack }
- });
- }
- }
- // Log
- if (importedTags.result.length > 0 && (result.inError + result.inSuccess) > 0) {
- const intermediateDurationSecs = Math.round((new Date().getTime() - startTime) / 1000);
- await Logging.logDebug({
- tenantID: tenant.id,
- action: ServerAction.TAGS_IMPORT,
- module: MODULE_NAME, method: 'processTenant',
- message: `${result.inError + result.inSuccess}/${totalTagsToImport} Tag(s) have been processed in ${intermediateDurationSecs}s...`
- });
- }
- } while (!Utils.isEmptyArray(importedTags?.result));
- // Log final results
- const executionDurationSecs = Math.round((new Date().getTime() - startTime) / 1000);
- await Logging.logActionsResponse(tenant.id, ServerAction.TAGS_IMPORT, MODULE_NAME, 'processTenant', result,
- `{{inSuccess}} Tag(s) have been imported successfully in ${executionDurationSecs}s in Tenant ${Utils.buildTenantName(tenant)}`,
- `{{inError}} Tag(s) failed to be imported in ${executionDurationSecs}s in Tenant ${Utils.buildTenantName(tenant)}`,
- `{{inSuccess}} Tag(s) have been imported successfully but {{inError}} failed in ${executionDurationSecs}s in Tenant ${Utils.buildTenantName(tenant)}`,
- `Not Tag has been imported in ${executionDurationSecs}s in Tenant ${Utils.buildTenantName(tenant)}`
- );
- } catch (error) {
- // Log error
- await Logging.logActionExceptionMessage(tenant.id, ServerAction.TAGS_IMPORT, error);
- } finally {
- // Release the lock
- await LockingManager.release(importTagsLock);
- }
- }
- }
-}

MODIFY
src/server/rest/v1/service/TagService.ts
src/server/rest/v1/service/TagService.ts
import { Action, Entity } from '../../../../types/Authorization';
import { ActionsResponse, ImportStatus } from '../../../../types/GlobalType';
-import { AsyncTaskStatus, AsyncTaskType, AsyncTasks } from '../../../../types/AsyncTask';
+import { AsyncTaskType, AsyncTasks } from '../../../../types/AsyncTask';
import { HTTPAuthError, HTTPError } from '../../../../types/HTTPError';
import { NextFunction, Request, Response } from 'express';
import { OCPITokenType, OCPITokenWhitelist } from '../../../../types/ocpi/OCPIToken';
@@ -15,7 +15,6 @@ import Busboy from 'busboy';
import CSVError from 'csvtojson/v2/CSVError';
import Constants from '../../../../utils/Constants';
import EmspOCPIClient from '../../../../client/ocpi/EmspOCPIClient';
-import ImportTagsTask from '../../../../scheduler/tasks/ImportTagsTask';
import JSONStream from 'JSONStream';
import LockingHelper from '../../../../locking/LockingHelper';
import LockingManager from '../../../../locking/LockingManager';

Remove import tags