Skip to content

Commit

Permalink
tmp: comment out import steps
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Dec 19, 2024
1 parent dcd6996 commit d54fa68
Showing 1 changed file with 70 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class SourcingDataImportService {

async importSourcingData(filePath: string, taskId: string): Promise<any> {
this.logger.log(`Starting import process`);
await this.fileService.isFilePresentInFs(filePath);
//await this.fileService.isFilePresentInFs(filePath);
try {
const parsedXLSXDataset: SourcingRecordsSheets =
await this.fileService.transformToJson(filePath, SHEETS_MAP);
Expand All @@ -77,80 +77,80 @@ export class SourcingDataImportService {
await this.excelValidator.validate(
parsedXLSXDataset as unknown as SourcingDataSheet,
);
if (validationErrors.length) {
throw new ExcelValidationError('Validation Errors', validationErrors);
}

//TODO: Implement transactional import. Move geocoding to first step

await this.dbCleaner.cleanDataBeforeImport();

const materials: Material[] =
await this.materialService.findAllUnpaginated();
if (!materials.length) {
throw new ServiceUnavailableException(
'No Materials found present in the DB. Please check the LandGriffon installation manual',
);
}
// if (validationErrors.length) {
// throw new ExcelValidationError('Validation Errors', validationErrors);
// }
//
// //TODO: Implement transactional import. Move geocoding to first step
//
// await this.dbCleaner.cleanDataBeforeImport();
//
// const materials: Material[] =
// await this.materialService.findAllUnpaginated();
// if (!materials.length) {
// throw new ServiceUnavailableException(
// 'No Materials found present in the DB. Please check the LandGriffon installation manual',
// );
// }
this.logger.log('Activating Indicators...');
const activeIndicators: Indicator[] =
await this.indicatorService.activateIndicators(
dtoMatchedData.indicators,
);
this.logger.log('Activating Materials...');
const activeMaterials: Material[] =
await this.materialService.activateMaterials(dtoMatchedData.materials);

await this.tasksService.updateImportTask({
taskId,
newLogs: [
`Activated indicators: ${activeIndicators
.map((i: Indicator) => i.name)
.join(', ')}`,
`Activated materials: ${activeMaterials
.map((i: Material) => i.hsCodeId)
.join(', ')}`,
],
});

const businessUnits: BusinessUnit[] =
await this.businessUnitService.createTree(dtoMatchedData.businessUnits);

const suppliers: Supplier[] = await this.supplierService.createTree(
dtoMatchedData.suppliers,
);

const { geoCodedSourcingData, errors } =
await this.geoCodingService.geoCodeLocations(
dtoMatchedData.sourcingData,
);
if (errors.length) {
throw new GeoCodingError(
'Import failed. There are GeoCoding errors present in the file',
errors,
);
}
const warnings: string[] = [];
geoCodedSourcingData.forEach((elem: SourcingData) => {
if (elem.locationWarning) warnings.push(elem.locationWarning);
});
warnings.length > 0 &&
(await this.tasksService.updateImportTask({
taskId,
newLogs: warnings,
}));

const sourcingDataWithOrganizationalEntities: SourcingLocation[] =
await this.relateSourcingDataWithOrganizationalEntities(
suppliers,
businessUnits,
materials,
geoCodedSourcingData,
);

await this.sourcingLocationService.save(
sourcingDataWithOrganizationalEntities,
);
// this.logger.log('Activating Materials...');
// const activeMaterials: Material[] =
// await this.materialService.activateMaterials(dtoMatchedData.materials);
//
// await this.tasksService.updateImportTask({
// taskId,
// newLogs: [
// `Activated indicators: ${activeIndicators
// .map((i: Indicator) => i.name)
// .join(', ')}`,
// `Activated materials: ${activeMaterials
// .map((i: Material) => i.hsCodeId)
// .join(', ')}`,
// ],
// });
//
// const businessUnits: BusinessUnit[] =
// await this.businessUnitService.createTree(dtoMatchedData.businessUnits);
//
// const suppliers: Supplier[] = await this.supplierService.createTree(
// dtoMatchedData.suppliers,
// );
//
// const { geoCodedSourcingData, errors } =
// await this.geoCodingService.geoCodeLocations(
// dtoMatchedData.sourcingData,
// );
// if (errors.length) {
// throw new GeoCodingError(
// 'Import failed. There are GeoCoding errors present in the file',
// errors,
// );
// }
// const warnings: string[] = [];
// geoCodedSourcingData.forEach((elem: SourcingData) => {
// if (elem.locationWarning) warnings.push(elem.locationWarning);
// });
// warnings.length > 0 &&
// (await this.tasksService.updateImportTask({
// taskId,
// newLogs: warnings,
// }));
//
// const sourcingDataWithOrganizationalEntities: SourcingLocation[] =
// await this.relateSourcingDataWithOrganizationalEntities(
// suppliers,
// businessUnits,
// materials,
// geoCodedSourcingData,
// );
//
// await this.sourcingLocationService.save(
// sourcingDataWithOrganizationalEntities,
// );

this.logger.log('Generating Indicator Records...');

Expand Down

0 comments on commit d54fa68

Please sign in to comment.