Skip to content

Commit

Permalink
Pass includeIncomplete flag to queryGraphicRepresentations (backport #…
Browse files Browse the repository at this point in the history
…7145) [release/4.8.x] (#7154)
  • Loading branch information
mergify[bot] authored Sep 13, 2024
1 parent 2c83e6b commit abbad2b
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/frontend-tiles",
"comment": "",
"type": "none"
}
],
"packageName": "@itwin/frontend-tiles"
}
5 changes: 3 additions & 2 deletions extensions/frontend-tiles/src/FrontendTiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ export async function* queryMeshExports(args: QueryMeshExportsArgs): AsyncIterab
},
format: "IMDL",
urlPrefix: args.urlPrefix,
includeIncomplete: args.includeIncomplete,
enableCDN: args.enableCDN,
};

for await (const data of queryGraphicRepresentations(graphicsArgs)){
for await (const data of queryGraphicRepresentations(graphicsArgs)) {
const meshExport = {
id: data.representationId,
displayName: data.displayName,
status: "Complete",
status: data.status,
request: {
iModelId: data.dataSource.id,
changesetId: data.dataSource.changeId ?? "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type GraphicRepresentationFormat = "IMDL" | "3DTILES" | string;
* The status of a Graphic Representation indicates the progress of that generation process.
* @beta
*/
// ###TODO this needs to be expanded to include more statuses, and/or "failed" needs to be replaced with "invalid".
export enum GraphicRepresentationStatus {
InProgress = "In progress",
Complete = "Complete",
Expand Down Expand Up @@ -136,7 +137,7 @@ export async function* queryGraphicRepresentations(args: QueryGraphicRepresentat
};

/* eslint-disable-next-line @typescript-eslint/naming-convention */
_links: {
_links?: {
mesh: {
href: string;
};
Expand Down Expand Up @@ -184,7 +185,7 @@ export async function* queryGraphicRepresentations(args: QueryGraphicRepresentat
representationId: foundSource.id,
status: foundSource.status,
format: args.format,
url: foundSource._links.mesh.href,
url: foundSource._links?.mesh.href,
dataSource: {
iTwinId: args.dataSource.iTwinId,
id: foundSource.request.iModelId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface TestJsonResponse {
};

/* eslint-disable-next-line @typescript-eslint/naming-convention */
_links: {
_links?: {
mesh: {
href: string;
};
Expand Down Expand Up @@ -73,7 +73,7 @@ interface SourceProps {
}

function makeSource(props: SourceProps): TestJsonResponse {
return {
const source: TestJsonResponse = {
id: props.id,
displayName: props.id,
status: props.status ?? "Complete",
Expand All @@ -84,13 +84,15 @@ function makeSource(props: SourceProps): TestJsonResponse {
geometryOptions: { },
viewDefinitionFilter: { },
},
/* eslint-disable-next-line @typescript-eslint/naming-convention */
_links: {
mesh: {
href: props.href ?? "mesh.edu",
},
},
};

// Ensure _links is only defined if a url is provided through props.
// We need to properly test cases where _links is undefined, because it may be undefined in the mesh export service response.
if (props.href) {
/* eslint-disable-next-line @typescript-eslint/naming-convention */
source._links = { mesh: { href: props.href } };
}
return source;
}

interface SourcesProps {
Expand Down Expand Up @@ -124,6 +126,8 @@ const testArgs = {
};

describe("queryGraphicRepresentations", () => {
before(async () => IModelApp.startup());
after(async () => IModelApp.shutdown());

it("returns no results upon error", async () => {
await mockFetch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as sinon from "sinon";
import { Range3d } from "@itwin/core-geometry";
import { Cartographic, EcefLocation } from "@itwin/core-common";
import { BlankConnection, IModelApp } from "@itwin/core-frontend";
import { MeshExport, MeshExports } from "../../FrontendTiles";
import { MeshExport, MeshExports, queryMeshExports } from "../../FrontendTiles";
import { obtainIModelTilesetUrl } from "../../GraphicsProvider/GraphicsProvider";

use(chaiAsPromised);
Expand Down Expand Up @@ -98,39 +98,39 @@ async function makeExportsResponse(props: ExportsProps): Promise<Response> {

const accessToken = "this-is-a-fake-access-token";

describe("obtainIModelTilesetUrl", () => {
before(async () => IModelApp.startup());
after(async () => IModelApp.shutdown());
async function fetchExports(resource: RequestInfo | URL, exportProps: ExportProps[]): Promise<Response> {
expect(typeof resource).to.equal("string");
const url = resource as string;

async function fetchExports(resource: RequestInfo | URL): Promise<Response> {
expect(typeof resource).to.equal("string");
const url = resource as string;
const result = url.match(/changesetId=([^\&]+)/);
if (result) {
const changesetId = result[1];
exportProps = exportProps.filter((x) => x.changesetId === changesetId);
}

let exports: ExportProps[] = [
{ id: "a", href: "http://tiles.com/a", changesetId: "aaa" },
{ id: "b", href: "http://tiles.com/b", changesetId: "bbb" },
{ id: "c", href: "http://tiles.com/c", changesetId: "ccc" },
];
return makeExportsResponse({ exports: exportProps });
}

const result = url.match(/changesetId=([^\&]+)/);
if (result) {
const changesetId = result[1];
exports = exports.filter((x) => x.changesetId === changesetId);
}
interface ObtainUrlArgs {
id?: string;
changesetId?: string;
exact?: boolean;
}

return makeExportsResponse({ exports });
}
describe("obtainIModelTilesetUrl", () => {
before(async () => IModelApp.startup());
after(async () => IModelApp.shutdown());

interface ObtainUrlArgs {
id?: string;
changesetId?: string;
exact?: boolean;
}
const exportProps: ExportProps[] = [
{ id: "a", href: "http://tiles.com/a", changesetId: "aaa" },
{ id: "b", href: "http://tiles.com/b", changesetId: "bbb" },
{ id: "c", href: "http://tiles.com/c", changesetId: "ccc" },
];

async function expectUrl(expected: string | undefined, args: ObtainUrlArgs): Promise<void> {
const iModel = new TestConnection(args);
await mockFetch(
async (resource) => fetchExports(resource),
async (resource) => fetchExports(resource, exportProps),
async () => {
const url = await obtainIModelTilesetUrl({
iTwinId: iModel.iTwinId,
Expand Down Expand Up @@ -165,3 +165,64 @@ describe("obtainIModelTilesetUrl", () => {
await expectUrl(undefined, { id: "imdl", changesetId: "bbbbbb", exact: true });
});
});

describe("queryMeshExports", () => {
before(async () => IModelApp.startup());
after(async () => IModelApp.shutdown());
const args: ObtainUrlArgs = { id: "imdl", changesetId: "aaa" };

const exportProps: ExportProps[] = [
{ id: "1", href: "http://tiles.com/a1", changesetId: "aaa", status: "Complete" },
{ id: "2", href: "http://tiles.com/a2", changesetId: "aaa", status: "Invalid" },
{ id: "3", href: "http://tiles.com/a3", changesetId: "aaa", status: "InProgress" },
];

it("queryMeshExports doesn't return incomplete exports if includeIncomplete flag is false", async () => {
const iModel = new TestConnection(args);
await mockFetch(
async (resource) => fetchExports(resource, exportProps),
async () => {
const queryArgs = {
iTwinId: "test",
iModelId: iModel.iModelId,
changesetId: iModel.changeset?.id,
accessToken,
};

const exports: MeshExport[] = [];
for await (const data of queryMeshExports(queryArgs)) {
exports.push(data);
}

expect(exports.length).to.equal(1);
expect(exports[0].status).to.equal("Complete");
},
);
});

it("queryMeshExports returns incomplete exports if includeIncomplete flag is true", async () => {
const iModel = new TestConnection(args);
await mockFetch(
async (resource) => fetchExports(resource, exportProps),
async () => {
const queryArgs = {
iTwinId: "test",
iModelId: iModel.iModelId,
changesetId: iModel.changeset?.id,
accessToken,
includeIncomplete: true,
};

const exports: MeshExport[] = [];
for await (const data of queryMeshExports(queryArgs)) {
exports.push(data);
}

expect(exports.length).to.equal(3);
expect(exports[0].status).to.equal("Complete");
expect(exports[1].status).to.equal("Invalid");
expect(exports[2].status).to.equal("InProgress");
},
);
});
});

0 comments on commit abbad2b

Please sign in to comment.