RED-5845 - Suggestion still available in cache after re-upload file with keepManualChanges=false

This commit is contained in:
Valentin Mihai 2023-01-03 20:52:54 +02:00
parent c0202400a8
commit 34595d5ca4

View File

@ -179,17 +179,19 @@ export class FileDataService extends EntitiesService<AnnotationWrapper, Annotati
}
async #buildRemovedRedactions(redactionLog: IRedactionLog, file: File): Promise<void> {
const redactionLogCopy = JSON.parse(JSON.stringify(redactionLog));
redactionLogCopy.redactionLogEntry = redactionLogCopy.redactionLogEntry.reduce((filtered, entry) => {
const lastChange = entry.manualChanges.at(-1);
const isRemoveChange = this.#isRemoveChange(lastChange?.manualRedactionType);
if (isRemoveChange) {
entry.manualChanges.pop();
filtered.push(entry);
}
return filtered;
}, []);
this._suggestionsService.removedRedactions = await this.#buildAnnotations(redactionLogCopy, file);
if (redactionLog.redactionLogEntry) {
const redactionLogCopy = JSON.parse(JSON.stringify(redactionLog));
redactionLogCopy.redactionLogEntry = redactionLogCopy.redactionLogEntry?.reduce((filtered, entry) => {
const lastChange = entry.manualChanges.at(-1);
const isRemoveChange = this.#isRemoveChange(lastChange?.manualRedactionType);
if (isRemoveChange) {
entry.manualChanges.pop();
filtered.push(entry);
}
return filtered;
}, []);
this._suggestionsService.removedRedactions = await this.#buildAnnotations(redactionLogCopy, file);
}
}
#isRemoveChange(type: ManualRedactionType) {
@ -201,41 +203,43 @@ export class FileDataService extends EntitiesService<AnnotationWrapper, Annotati
const sourceIdAnnotationIds: { [key: string]: RedactionLogEntry[] } = {};
let checkDictionary = true;
for (const redactionLogEntry of redactionLog.redactionLogEntry) {
const changeLogValues = this.#getChangeLogValues(redactionLogEntry, file);
if (changeLogValues.hidden) {
continue;
}
let dictionary = this._state.dictionaries.find(dict => dict.type === redactionLogEntry.type);
if (!dictionary && checkDictionary) {
const dictionaryRequest = this._dictionaryService.loadDictionaryDataForDossierTemplate(this._state.dossierTemplateId);
await firstValueFrom(dictionaryRequest);
checkDictionary = false;
dictionary = this._state.dictionaries.find(dict => dict.type === redactionLogEntry.type);
}
if (!dictionary) {
this.missingTypes.add(redactionLogEntry.type);
continue;
}
const redactionLogEntryWrapper: RedactionLogEntry = new RedactionLogEntry(
redactionLogEntry,
changeLogValues.changeLogType,
changeLogValues.isChangeLogEntry,
redactionLog.legalBasis,
!!dictionary?.hint,
);
if (redactionLogEntry.sourceId) {
if (!sourceIdAnnotationIds[redactionLogEntry.sourceId]) {
sourceIdAnnotationIds[redactionLogEntry.sourceId] = [];
if (redactionLog.redactionLogEntry) {
for (const redactionLogEntry of redactionLog.redactionLogEntry) {
const changeLogValues = this.#getChangeLogValues(redactionLogEntry, file);
if (changeLogValues.hidden) {
continue;
}
sourceIdAnnotationIds[redactionLogEntry.sourceId].push(redactionLogEntryWrapper);
}
result.push(redactionLogEntryWrapper);
let dictionary = this._state.dictionaries.find(dict => dict.type === redactionLogEntry.type);
if (!dictionary && checkDictionary) {
const dictionaryRequest = this._dictionaryService.loadDictionaryDataForDossierTemplate(this._state.dossierTemplateId);
await firstValueFrom(dictionaryRequest);
checkDictionary = false;
dictionary = this._state.dictionaries.find(dict => dict.type === redactionLogEntry.type);
}
if (!dictionary) {
this.missingTypes.add(redactionLogEntry.type);
continue;
}
const redactionLogEntryWrapper: RedactionLogEntry = new RedactionLogEntry(
redactionLogEntry,
changeLogValues.changeLogType,
changeLogValues.isChangeLogEntry,
redactionLog.legalBasis,
!!dictionary?.hint,
);
if (redactionLogEntry.sourceId) {
if (!sourceIdAnnotationIds[redactionLogEntry.sourceId]) {
sourceIdAnnotationIds[redactionLogEntry.sourceId] = [];
}
sourceIdAnnotationIds[redactionLogEntry.sourceId].push(redactionLogEntryWrapper);
}
result.push(redactionLogEntryWrapper);
}
}
const sourceKeys = Object.keys(sourceIdAnnotationIds);