red-ui/libs/red-domain/src/lib/files/file.model.ts
2022-02-28 19:32:21 +02:00

133 lines
5.8 KiB
TypeScript

import { Entity } from '@iqser/common-ui';
import { StatusSorter } from '../shared';
import { isProcessingStatuses, ProcessingFileStatus, ProcessingFileStatuses, WorkflowFileStatus, WorkflowFileStatuses } from './types';
import { IFile } from './file';
import { FileAttributes } from '../file-attributes';
export class File extends Entity<IFile> implements IFile {
readonly added?: string;
readonly allManualRedactionsApplied: boolean;
readonly analysisDuration?: number;
readonly analysisRequired: boolean;
readonly annotationModificationDate?: string;
readonly approvalDate?: string;
readonly assignee?: string;
readonly dictionaryVersion?: number;
readonly dossierDictionaryVersion?: number;
readonly dossierId: string;
readonly excluded: boolean;
readonly excludedFromAutomaticAnalysis: boolean;
readonly fileAttributes?: FileAttributes;
readonly fileId: string;
readonly filename: string;
readonly hasAnnotationComments: boolean;
readonly hasHints: boolean;
readonly hasImages: boolean;
readonly hasRedactions: boolean;
readonly hasUpdates: boolean;
readonly lastOCRTime?: string;
readonly lastProcessed?: string;
readonly lastReviewer?: string;
readonly lastApprover?: string;
readonly lastUpdated?: string;
readonly lastUploaded?: string;
readonly legalBasisVersion?: number;
readonly numberOfAnalyses: number;
readonly numberOfPages?: number;
readonly rulesVersion?: number;
readonly uploader?: string;
readonly excludedPages: number[];
readonly hasSuggestions: boolean;
readonly processingStatus: ProcessingFileStatus;
readonly workflowStatus: WorkflowFileStatus;
readonly fileManipulationDate: string;
readonly statusSort: number;
readonly cacheIdentifier?: string;
readonly hintsOnly: boolean;
readonly hasNone: boolean;
readonly isNew: boolean;
readonly isError: boolean;
readonly isProcessing: boolean;
readonly isInitialProcessing: boolean;
readonly isApproved: boolean;
readonly isUnprocessed: boolean;
readonly isUnderReview: boolean;
readonly isUnderApproval: boolean;
readonly canBeApproved: boolean;
readonly canBeOpened: boolean;
readonly canBeOCRed: boolean;
constructor(file: IFile, readonly reviewerName: string) {
super(file);
this.added = file.added;
this.allManualRedactionsApplied = !!file.allManualRedactionsApplied;
this.analysisDuration = file.analysisDuration;
this.analysisRequired = !!file.analysisRequired && !file.excluded;
this.annotationModificationDate = file.annotationModificationDate;
this.approvalDate = file.approvalDate;
this.assignee = file.assignee;
this.dictionaryVersion = file.dictionaryVersion;
this.dossierDictionaryVersion = file.dossierDictionaryVersion;
this.dossierId = file.dossierId;
this.excluded = !!file.excluded;
this.excludedFromAutomaticAnalysis = !!file.excludedFromAutomaticAnalysis;
this.fileAttributes = file.fileAttributes;
this.fileId = file.fileId;
this.filename = file.filename;
this.hasAnnotationComments = !!file.hasAnnotationComments;
this.hasHints = !!file.hasHints;
this.hasImages = !!file.hasImages;
this.hasRedactions = !!file.hasRedactions;
this.hasUpdates = !!file.hasUpdates;
this.lastOCRTime = file.lastOCRTime;
this.lastProcessed = file.lastProcessed;
this.lastReviewer = file.lastReviewer;
this.lastApprover = file.lastApprover;
this.lastUpdated = file.lastUpdated;
this.lastUploaded = file.lastUploaded;
this.legalBasisVersion = file.legalBasisVersion;
this.numberOfAnalyses = file.numberOfAnalyses;
this.processingStatus = file.processingStatus;
this.workflowStatus = file.workflowStatus;
this.isError = this.processingStatus === ProcessingFileStatuses.ERROR;
this.isUnprocessed = this.processingStatus === ProcessingFileStatuses.UNPROCESSED;
this.numberOfPages = this.isError ? 0 : file.numberOfPages ?? 0;
this.rulesVersion = file.rulesVersion;
this.uploader = file.uploader;
this.excludedPages = file.excludedPages || [];
this.hasSuggestions = !!file.hasSuggestions;
this.fileManipulationDate = file.fileManipulationDate;
this.statusSort = StatusSorter[this.workflowStatus];
this.cacheIdentifier = btoa(this.fileManipulationDate ?? '');
this.hintsOnly = this.hasHints && !this.hasRedactions;
this.hasNone = !this.hasRedactions && !this.hasHints && !this.hasSuggestions;
this.isProcessing = isProcessingStatuses.includes(this.processingStatus);
this.isInitialProcessing = this.isProcessing && this.numberOfAnalyses === 0;
this.isApproved = this.workflowStatus === WorkflowFileStatuses.APPROVED;
this.isNew = this.workflowStatus === WorkflowFileStatuses.NEW;
this.isUnderReview = this.workflowStatus === WorkflowFileStatuses.UNDER_REVIEW;
this.isUnderApproval = this.workflowStatus === WorkflowFileStatuses.UNDER_APPROVAL;
this.canBeApproved = !this.hasSuggestions && !this.isProcessing && !this.isError;
this.canBeOpened = !this.isError && !this.isUnprocessed && this.numberOfAnalyses > 0;
this.canBeOCRed = !this.excluded && !this.lastOCRTime && (this.isNew || this.isUnderReview || this.isUnderApproval);
if (!this.fileAttributes || !this.fileAttributes.attributeIdToValue) {
this.fileAttributes = { attributeIdToValue: {} };
}
}
get id(): string {
return this.fileId;
}
get searchKey(): string {
return this.filename;
}
get routerLink(): string | undefined {
return this.canBeOpened ? `/main/dossiers/${this.dossierId}/file/${this.fileId}` : undefined;
}
}