Skip to content

Commit

Permalink
fix(bulk-import): fix structure checker and change between werning an…
Browse files Browse the repository at this point in the history
…d error on terms
  • Loading branch information
Mihoub2 committed Oct 16, 2023
1 parent 40fae5c commit c133e8d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
39 changes: 20 additions & 19 deletions src/components/bulk-imports/lib/analysers/structures/checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,29 +132,29 @@ function rowsChecker(rows, index) {
message: `Le nom ${usualName} que vous souhaitez ajouter existe déjà ${duplicateNames.length} fois dans votre fichier d'import.`,
});
}
return warnings;
}

const checkDuplicates = (property, propertyName) => {
const duplicateValues = rowsWithoutIndex
.map((row) => row[property])
.filter((value) => value)
.filter((value, i, arr) => arr.indexOf(value) !== i);
function checkDuplicateIdentifiers(rows, index) {
const warnings = [];
const rowsWithoutIndex = rows.filter((r, i) => i !== index);
const identifiers = ['idref', 'wikidata', 'ror', 'uai', 'siret', 'ed'];
identifiers.forEach((identifier) => {
const { [identifier]: currentIdentifierValue } = rows[index];
if (currentIdentifierValue === null || currentIdentifierValue === undefined) {
return;
}

if (duplicateValues.length > 0) {
const duplicateIdentifiers = rowsWithoutIndex
.map((row) => row[identifier])
.filter((value) => value === currentIdentifierValue);

if (duplicateIdentifiers.length > 0) {
warnings.push({
message: `L'identifiant ${propertyName} ${rows[index][property]} que vous souhaitez ajouter existe déjà ${duplicateValues.length} fois dans votre fichier d'import.`,
message: `L'identifiant ${identifier.toUpperCase()} ${currentIdentifierValue} que vous souhaitez ajouter existe déjà ${duplicateIdentifiers.length} fois dans votre fichier d'import.`,
});
}
};

checkDuplicates('siret', 'SIRET');
checkDuplicates('ror', 'ROR');
checkDuplicates('orcid', 'ORCID');
checkDuplicates('idref', 'IDREF');
checkDuplicates('rnsr', 'RNSR');
checkDuplicates('ed', 'ED');
checkDuplicates('wikidata', 'Wikidata');
checkDuplicates('researchgate', 'ResearchGate');

});
return warnings;
}

Expand All @@ -172,6 +172,7 @@ export default async function checker(docs, index) {
const uaiDuplicate = await duplicateIdChecker('uai', doc.uai);
const wikidataDuplicate = await duplicateIdChecker('wikidata', doc.wikidata);
const edFormat = await idFormatChecker('ed', doc.ed);
const identifiersDuplicateInFile = await checkDuplicateIdentifiers(docs, index);
const idrefFormat = await idFormatChecker('idref', doc.idref);
const siretFormat = await idFormatChecker('siret', doc.siret);
const rnsrFormat = await idFormatChecker('rnsr', doc.rnsr);
Expand All @@ -182,7 +183,7 @@ export default async function checker(docs, index) {
const websiteChecked = await websiteChecker(doc);
const duplicateChecker = await rowsChecker(docs, index);
const warning = [...idrefDuplicate, ...duplicateChecker,
...siretDuplicate, ...edDuplicate, ...rnsrDuplicate, ...uaiDuplicate, ...rorDuplicate, ...wikidataDuplicate, ...nameDuplicateWarnings, ...websiteChecked];
...siretDuplicate, ...edDuplicate, ...rnsrDuplicate, ...uaiDuplicate, ...rorDuplicate, ...wikidataDuplicate, ...nameDuplicateWarnings, ...websiteChecked, ...identifiersDuplicateInFile];
const error = [...requiredErrors, ...legalCategoryCheck, ...categoriesErrors, ...edFormat, ...idrefFormat, ...siretFormat, ...rnsrFormat, ...rorFormat, ...uaiFormat, ...wikidataFormat];
let status = 'success';
if (warning.length) { status = 'warning'; }
Expand Down
4 changes: 2 additions & 2 deletions src/components/bulk-imports/lib/analysers/terms/checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ export default async function checker(docs, index) {
const rncpCheck = await rncpChecker(doc);
const wikidataFormatCheck = await idFormatChecker('wikidata', doc.wikidata);
const rncpFormatCheck = await idFormatChecker('rncp', doc.rncp);
const warning = [...websiteChecked, ...nameCheck, ...wikiCheck, ...rncpCheck];
const error = [...requiredErrors, ...wikidataFormatCheck, ...rncpFormatCheck];
const warning = [...websiteChecked, ...nameCheck, ...wikiCheck, ...rncpCheck, ...rncpFormatCheck, ...wikidataFormatCheck];
const error = [...requiredErrors];
let status = 'success';
if (warning.length) { status = 'warning'; }
if (error.length) { status = 'error'; }
Expand Down

0 comments on commit c133e8d

Please sign in to comment.