Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

fix: Update export options for pascalVOC rename #788

Merged
merged 1 commit into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/services/projectService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { generateKey } from "../common/crypto";
import { encryptProject, decryptProject } from "../common/utils";
import { ExportAssetState } from "../providers/export/exportProvider";
import { IVottJsonExportProviderOptions } from "../providers/export/vottJson";
import { IPascalVOCExportProviderOptions } from "../providers/export/pascalVOC";

describe("Project Service", () => {
let projectSerivce: IProjectService = null;
Expand Down Expand Up @@ -201,4 +202,23 @@ describe("Project Service", () => {
await projectSerivce.delete(testProject);
expect(storageProviderMock.deleteFile.mock.calls).toHaveLength(assets.length + 1);
});

it("Updates export settings to v2.1 supported values", async () => {
testProject = MockFactory.createTestProject("TestProject");
testProject.version = "2.0.0";
testProject.exportFormat = {
providerType: "tensorFlowPascalVOC",
providerOptions: {
assetState: ExportAssetState.All,
exportUnassigned: true,
testTrainSplit: 80,
} as IPascalVOCExportProviderOptions,
};

const encryptedProject = encryptProject(testProject, securityToken);
const decryptedProject = await projectSerivce.load(encryptedProject, securityToken);

expect(decryptedProject.exportFormat.providerType).toEqual("pascalVOC");
expect(decryptedProject.exportFormat.providerOptions).toEqual(testProject.exportFormat.providerOptions);
});
});
15 changes: 15 additions & 0 deletions src/services/projectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export default class ProjectService implements IProjectService {
loadedProject.exportFormat = defaultExportOptions;
}

this.ensureBackwardsCompatibility(loadedProject);

return Promise.resolve({ ...loadedProject });
} catch (e) {
const error = new AppError(ErrorCode.ProjectInvalidSecurityToken, "Error decrypting project settings");
Expand Down Expand Up @@ -163,4 +165,17 @@ export default class ProjectService implements IProjectService {

project.exportFormat.providerOptions = await exportProvider.save(project.exportFormat);
}

/**
* Ensures backwards compatibility with project
* @param project The project to update
*/
private ensureBackwardsCompatibility(project: IProject) {
if (project.version === "2.0.0") {
// Required for backwards compatibility with v2.0.0 release
if (project.exportFormat.providerType === "tensorFlowPascalVOC") {
project.exportFormat.providerType = "pascalVOC";
}
}
}
}