in web/src/app/services/data-loader.service.ts [121:295]
private async responseDataToViewInspection(
response: KHIFile,
referenceResolver: ReferenceResolverStore,
): Promise<InspectionData> {
if (typeof response.version === 'undefined') {
const errorMessage =
'Unsupported KHI version schema. Maybe this file was exported for older KHI version. Please use older version to use the file or query the range again with this newer version';
alert(errorMessage);
throw new Error(errorMessage);
}
const logs: LogEntry[] = [];
const startTime = response.metadata.header.startTimeUnixSeconds * 1000;
const endTime = response.metadata.header.endTimeUnixSeconds * 1000;
const logIdToLogIndex: { [logId: string]: number } = {
'': -1,
};
const timelineIdToTimeline: {
[timelineId: string]: KHIFileTimeline | undefined;
} = {};
this.progress.updateProgress({
message: 'Processing logs...',
percent: 0,
mode: 'indeterminate',
});
// Process logs
for (const l of response.logs) {
const time = Date.parse(l.ts);
logIdToLogIndex[l.id] = logs.length;
logs.push(
new LogEntry(
logs.length,
l.displayId,
l.type,
l.severity,
time,
await lastValueFrom(
referenceResolver.getText(
ToTextReferenceFromKHIFileBinary(l.summary),
),
),
ToTextReferenceFromKHIFileBinary(l.body),
l.annotations,
),
);
}
this.progress.updateProgress({
message: 'Processing timelines...',
percent: 0,
mode: 'indeterminate',
});
for (const timeline of response.timelines) {
timelineIdToTimeline[timeline.id] = timeline;
}
// Process resource hierarchy
const timelines: ResourceTimeline[] = [];
for (
let apiVersionIndex = 0;
apiVersionIndex < response.resources.length;
apiVersionIndex++
) {
const apiVersionResource = response.resources[apiVersionIndex];
for (
let kindIndex = 0;
kindIndex < apiVersionResource.children.length;
kindIndex++
) {
const kindResource = apiVersionResource.children[kindIndex];
const kindTimeline = new ResourceTimeline(
kindResource.timeline,
kindResource.path,
[],
[],
kindResource.relationship,
);
timelines.push(kindTimeline);
for (
let namespaceIndex = 0;
namespaceIndex < kindResource.children.length;
namespaceIndex++
) {
const namespaceResource = kindResource.children[namespaceIndex];
const namespaceTimeline = new ResourceTimeline(
namespaceResource.timeline,
namespaceResource.path,
[],
[],
namespaceResource.relationship,
);
timelines.push(namespaceTimeline);
kindTimeline.addChildTimeline(namespaceTimeline);
for (
let nameIndex = 0;
nameIndex < namespaceResource.children.length;
nameIndex++
) {
const nameResource = namespaceResource.children[nameIndex];
// timeline can be null when the children is defined but no event/revisions are included
const timeline =
timelineIdToTimeline[nameResource.timeline] ?? null;
const nameTimeline = new ResourceTimeline(
nameResource.timeline,
nameResource.path,
await this.revisionDataToViewRevisions(
nameResource,
timeline?.revisions ?? [],
logIdToLogIndex,
startTime,
endTime,
referenceResolver,
),
this.eventDataToViewEvents(
timeline?.events ?? [],
logs,
logIdToLogIndex,
),
nameResource.relationship,
);
timelines.push(nameTimeline);
namespaceTimeline.addChildTimeline(nameTimeline);
for (
let subresoruceIndex = 0;
subresoruceIndex < nameResource.children.length;
subresoruceIndex++
) {
const subResourceResource =
nameResource.children[subresoruceIndex];
// timeline can be null when the children is defined but no event/revisions are included
const timeline =
timelineIdToTimeline[subResourceResource.timeline] ?? null;
const subresourceTimeline = new ResourceTimeline(
subResourceResource.timeline,
subResourceResource.path,
await this.revisionDataToViewRevisions(
subResourceResource,
timeline?.revisions ?? [],
logIdToLogIndex,
startTime,
endTime,
referenceResolver,
),
this.eventDataToViewEvents(
timeline?.events ?? [],
logs,
logIdToLogIndex,
),
subResourceResource.relationship,
);
timelines.push(subresourceTimeline);
nameTimeline.addChildTimeline(subresourceTimeline);
}
}
}
}
}
// Create cache of relationship from log entry to timeline
for (const timeline of timelines) {
for (const event of timeline.events) {
logs[event.logIndex].relatedTimelines.add(timeline);
}
for (const revision of timeline.revisions) {
if (revision.logIndex !== -1)
logs[revision.logIndex].relatedTimelines.add(timeline);
}
}
return new InspectionData(
response.metadata.header,
new TimeRange(startTime, endTime),
referenceResolver,
timelines,
logs,
);
}