DM-508 - update to use the new API

This commit is contained in:
Valentin Mihai 2023-10-06 13:12:52 +03:00
parent 80fa240731
commit eb266fc565
6 changed files with 67 additions and 33 deletions

View File

@ -42,9 +42,9 @@
</div>
<div>{{ entry.componentValues[0].valueDescription }}</div>
<div>
<ul *ngIf="entry.componentValues[0].componentLogEntityReferences; else noReferences" class="pl-0">
<ul *ngIf="entry.componentValues[0].entityReferences; else noReferences" class="pl-0">
<li
*ngFor="let reference of entry.componentValues[0].componentLogEntityReferences"
*ngFor="let reference of entry.componentValues[0].entityReferences"
[innerHTML]="
'component-log-dialog.annotations'
| translate

View File

@ -63,21 +63,35 @@ export class StructuredComponentManagementDialogComponent extends BaseDialogComp
exportJSON() {
return firstValueFrom(
this._componentLogService.exportJSON(this.data.file.dossierId, this.data.file.fileId, this.data.file.filename),
this._componentLogService.exportJSON(
this.data.file.dossierTemplateId,
this.data.file.dossierId,
this.data.file.fileId,
this.data.file.filename,
),
);
}
exportXML() {
return firstValueFrom(
this._componentLogService.exportXML(this.data.file.dossierId, this.data.file.fileId, this.data.file.filename),
this._componentLogService.exportXML(
this.data.file.dossierTemplateId,
this.data.file.dossierId,
this.data.file.fileId,
this.data.file.filename,
),
);
}
async exportAllInDossier() {
const allFilesInDossier = this._filesMapService.get(this.data.file.dossierId);
for (const file of allFilesInDossier) {
await firstValueFrom(this._componentLogService.exportJSON(file.dossierId, file.fileId, file.filename));
await firstValueFrom(this._componentLogService.exportXML(file.dossierId, file.fileId, file.filename));
await firstValueFrom(
this._componentLogService.exportJSON(this.data.file.dossierTemplateId, file.dossierId, file.fileId, file.filename),
);
await firstValueFrom(
this._componentLogService.exportXML(this.data.file.dossierTemplateId, file.dossierId, file.fileId, file.filename),
);
}
}
@ -106,7 +120,11 @@ export class StructuredComponentManagementDialogComponent extends BaseDialogComp
async #loadData(): Promise<void> {
this._loadingService.start();
const componentLogData = await firstValueFrom(
this._componentLogService.getComponentLogData(this.data.file.dossierId, this.data.file.fileId),
this._componentLogService.getComponentLogData(
this.data.file.dossierTemplateId,
this.data.file.dossierId,
this.data.file.fileId,
),
);
this.componentLogData.set(componentLogData);
this._loadingService.stop();

View File

@ -4,20 +4,24 @@ import { catchError, map, tap } from 'rxjs/operators';
import { Observable, of } from 'rxjs';
import { HttpHeaders } from '@angular/common/http';
import { saveAs } from 'file-saver';
import { ComponentLogEntry, IComponentLogData, IComponentLogEntry } from '@red/domain';
import { filterEach, mapEach } from '@common-ui/utils';
import { ComponentDetails, ComponentLogEntry, IComponentLogData, IComponentLogEntry } from '@red/domain';
import { mapEach } from '@common-ui/utils';
@Injectable({ providedIn: 'root' })
export class ComponentLogService extends GenericService<void> {
protected readonly _defaultModelPath = 'import-redactions';
protected readonly _defaultModelPath = '';
getComponentLogData(dossierId: string, fileId: string): Observable<ComponentLogEntry[]> {
return this._getOne<IComponentLogData>([dossierId, fileId], 'componentLog').pipe(
map(data => data.componentLogEntries),
catchError(() => of({} as IComponentLogEntry[])),
filterEach(log => !!log.componentValues[0].componentLogEntityReferences.length),
mapEach(log => new ComponentLogEntry(log)),
);
getComponentLogData(dossierTemplateId: string, dossierId: string, fileId: string): Observable<ComponentLogEntry[]> {
return this._http
.get<IComponentLogData>(`/api/dossier-templates/${dossierTemplateId}/dossiers/${dossierId}/files/${fileId}/components`, {
params: { includeDetails: true },
})
.pipe(
map(data => data.componentDetails),
catchError(() => of({} as ComponentDetails)),
map(componentDetails => this.#filterComponentDetails(componentDetails)),
mapEach(log => new ComponentLogEntry(log)),
);
}
override(dossierId: string, fileId: string, componentOverrides: Record<string, string>): Observable<void> {
@ -28,8 +32,8 @@ export class ComponentLogService extends GenericService<void> {
return this._post({ components }, `componentLog/override/revert/${dossierId}/${fileId}`);
}
exportJSON(dossierId: string, fileId: string, name: string): Observable<ComponentLogEntry[]> {
return this.getComponentLogData(dossierId, fileId).pipe(
exportJSON(dossierTemplateId: string, dossierId: string, fileId: string, name: string): Observable<ComponentLogEntry[]> {
return this.getComponentLogData(dossierTemplateId, dossierId, fileId).pipe(
tap(data => {
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
saveAs(blob, name + '.component_log.json');
@ -37,8 +41,8 @@ export class ComponentLogService extends GenericService<void> {
);
}
exportXML(dossierId: string, fileId: string, name: string): Observable<string> {
return this._getComponentLogDataAsXML(dossierId, fileId).pipe(
exportXML(dossierTemplateId, dossierId: string, fileId: string, name: string): Observable<string> {
return this.#getComponentLogDataAsXML(dossierTemplateId, dossierId, fileId).pipe(
tap(data => {
const blob = new Blob([data], { type: 'application/xml' });
saveAs(blob, name + '.component_log.xml');
@ -46,16 +50,23 @@ export class ComponentLogService extends GenericService<void> {
);
}
private _getComponentLogDataAsXML(dossierId: string, fileId: string) {
const entityPath = [dossierId, fileId].map(item => encodeURIComponent(item)).join('/');
#getComponentLogDataAsXML(dossierTemplateId: string, dossierId: string, fileId: string) {
let headers = new HttpHeaders();
headers = headers.set('accept', 'application/xml');
return this._http.get(`/${this._serviceName}/${encodeURI('componentLog')}/${entityPath}`, {
return this._http.get(`/api/dossier-templates/${dossierTemplateId}/dossiers/${dossierId}/files/${fileId}/components`, {
headers: headers,
responseType: 'text',
observe: 'body',
});
}
#filterComponentDetails(componentDetails: ComponentDetails): IComponentLogEntry[] {
return Object.keys(componentDetails)
.filter(function (key) {
const component = componentDetails[key];
return !!component.componentValues[0].entityReferences.length;
})
.reduce((res, key) => (res.push(componentDetails[key]), res), []);
}
}

View File

@ -1,7 +1,10 @@
import { IComponentLogEntry } from './component-log-entry';
import { ComponentDetails } from './component-log-entry';
export interface IComponentLogData {
analysisNumber: number;
componentRulesVersion: number;
componentLogEntries: Array<IComponentLogEntry>;
filename: string | null;
fileId: string;
dossierId: string;
dossierTemplateId: string;
components: Record<string, Array<string>>;
componentDetails: ComponentDetails;
}

View File

@ -1,5 +1,7 @@
import { ComponentValue, IComponentValue } from './component-value';
export type ComponentDetails = Record<string, Record<'componentValues', IComponentValue>>;
export interface IComponentLogEntry {
name: string;
componentValues: IComponentValue[];

View File

@ -1,4 +1,4 @@
export interface ComponentLogEntityReference {
export interface EntityReference {
readonly id: string;
readonly type: string;
readonly entityRuleId: string;
@ -10,7 +10,7 @@ export interface IComponentValue {
readonly originalValue: string;
readonly valueDescription: string;
readonly componentRuleId: string;
readonly componentLogEntityReferences: ComponentLogEntityReference[];
readonly entityReferences: EntityReference[];
}
export class ComponentValue implements IComponentValue {
@ -18,13 +18,13 @@ export class ComponentValue implements IComponentValue {
readonly originalValue: string;
readonly valueDescription: string;
readonly componentRuleId: string;
readonly componentLogEntityReferences: ComponentLogEntityReference[];
readonly entityReferences: EntityReference[];
constructor(value: IComponentValue) {
this.value = value.value;
this.originalValue = value.originalValue;
this.valueDescription = value.valueDescription;
this.componentRuleId = value.componentRuleId;
this.componentLogEntityReferences = value.componentLogEntityReferences ?? [];
this.entityReferences = value.entityReferences ?? [];
}
}