Skip to content

Commit

Permalink
Add wasPreferred field to package info and schemas
Browse files Browse the repository at this point in the history
We add a field wasPreferred to the schemas for input and output files and the packageInfo for attributions which had previously been marked as preferred.

Signed-off-by: davidmundelius <[email protected]>
  • Loading branch information
davidmundelius committed Sep 29, 2023
1 parent 8a305d9 commit e3ddfe3
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 16 deletions.
3 changes: 2 additions & 1 deletion example-files/opossum_input.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@
"licenseName": "The MIT License (MIT)",
"copyright": "Copyright (c) 2013-present, Yuxi (Evan) You\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.",
"licenseText": "The MIT License (MIT)\n\nCopyright (c) 2013-present, Yuxi (Evan) You\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.",
"originId": "1eb75f3b-fc84-e781-ad9d-d46d6d61abf2"
"originId": "1eb75f3b-fc84-e781-ad9d-d46d6d61abf2",
"wasPreferred": true
},
"5f1948d6-63fa-4f7e-b02b-7799083511fc": {
"source": {
Expand Down
4 changes: 4 additions & 0 deletions src/ElectronBackend/input/OpossumInputFileSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@
"items": {
"type": "string"
}
},
"wasPreferred":{
"type": "boolean",
"description": "Indicates that the attribution had previously been marked as preferred."
}
},
"required": ["source"],
Expand Down
4 changes: 4 additions & 0 deletions src/ElectronBackend/input/OpossumOutputFileSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@
"items": {
"type": "string"
}
},
"wasPreferred":{
"type": "boolean",
"description": "Indicates that the attribution had previously been marked as preferred."
}
},
"required": [],
Expand Down
2 changes: 2 additions & 0 deletions src/ElectronBackend/input/__tests__/importFromFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const inputFileContent: ParsedOpossumInputFile = {
criticality: Criticality.High,
preferred: true,
preferredOverOriginIds: ['test-id'],
wasPreferred: true,
},
},
frequentLicenses: [
Expand Down Expand Up @@ -142,6 +143,7 @@ const expectedFileContent: ParsedFileContent = {
criticality: Criticality.High,
preferred: true,
preferredOverOriginIds: ['test-id'],
wasPreferred: true,
},
},
resourcesToAttributions: {
Expand Down
30 changes: 15 additions & 15 deletions src/ElectronBackend/output/__tests__/writeCsvToFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { createTempFolder, deleteFolder } from '../../test-helpers';
const testCsvHeader =
'"Index";"Confidence";"Comment";"Package Name";"Package Version";"Package Namespace";' +
'"Package Type";"PURL Appendix";"URL";"Copyright";"License Name";"License Text (truncated)";"Source";"First Party";' +
'"Follow-up";"Origin Attribution IDs";"pre-selected";"exclude-from-notice";"criticality";"needs-review";"preferred";"preferred-over-origin-ids";"Resources"';
'"Follow-up";"Origin Attribution IDs";"pre-selected";"exclude-from-notice";"criticality";"needs-review";"preferred";"preferred-over-origin-ids";"was-preferred";"Resources"';

describe('writeCsvToFile', () => {
it('writeCsvToFile short', async () => {
Expand All @@ -46,13 +46,13 @@ describe('writeCsvToFile', () => {
const content = await fs.promises.readFile(csvPath, 'utf8');
expect(content).toContain(testCsvHeader);
expect(content).toContain(
'"1";"";"";"";"";"";"";"";"";"";"";"license text, with; commas";"";"true";"";"";"";"";"";"";"";"";"/test.file"',
'"1";"";"";"";"";"";"";"";"";"";"";"license text, with; commas";"";"true";"";"";"";"";"";"";"";"";"";"/test.file"',
);
expect(content).toContain(
'"2";"";"";"Fancy name,: tt";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"/a/c/bla.mm"',
'"2";"";"";"Fancy name,: tt";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"/a/c/bla.mm"',
);
expect(content).toContain(
'"2";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"/b"',
'"2";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"/b"',
);
deleteFolder(temporaryPath);
});
Expand Down Expand Up @@ -117,10 +117,10 @@ describe('writeCsvToFile', () => {
const content = await fs.promises.readFile(csvPath, 'utf8');
expect(content).toContain(testCsvHeader);
expect(content).toContain(
'"1";"";"";"";"";"";"";"";"";"";"";"license text, with; commas";"";"true";"";"";"";"";"";"";"";"";"/test.file"',
'"1";"";"";"";"";"";"";"";"";"";"";"license text, with; commas";"";"true";"";"";"";"";"";"";"";"";"";"/test.file"',
);
expect(content).toContain(
'"2";"";"";"Fancy name,: tt";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"/a/c/bla.mm\n' +
'"2";"";"";"Fancy name,: tt";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"/a/c/bla.mm\n' +
'/b"',
);
deleteFolder(temporaryPath);
Expand Down Expand Up @@ -163,10 +163,10 @@ describe('writeCsvToFile', () => {
const content = await fs.promises.readFile(csvPath, 'utf8');
expect(content).toContain(testCsvHeader);
expect(content).toContain(
'"1";"";"";"";"";"";"";"";"";"";"";"license text, with; commas";"";"true";"";"";"";"";"";"";"";"";"/test.file"',
'"1";"";"";"";"";"";"";"";"";"";"";"license text, with; commas";"";"true";"";"";"";"";"";"";"";"";"";"/test.file"',
);
expect(content).toContain(
`"2";"";"";"Fancy name,: tt";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"${expectedResources}"`,
`"2";"";"";"Fancy name,: tt";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"${expectedResources}"`,
);
deleteFolder(temporaryPath);
});
Expand Down Expand Up @@ -453,25 +453,25 @@ describe('writeCsvToFile', () => {
const content = await fs.promises.readFile(csvPath, 'utf8');
expect(content).toContain(testCsvHeader);
expect(content).toContain(
'"1";"";"";"";"";"";"";"";"";"";"";"license text, with; commas";"";"true";"";"";"";"";"";"";"";"";"/test.file"',
'"1";"";"";"";"";"";"";"";"";"";"";"license text, with; commas";"";"true";"";"";"";"";"";"";"";"";"";"/test.file"',
);
expect(content).toContain(
`"2";"";"";"Fancy name with long license";"";"";"";"";"";"";"";"${expectedLicenseText}";"";"";"";"";"";"";"";"";"";"";"/a"`,
`"2";"";"";"Fancy name with long license";"";"";"";"";"";"";"";"${expectedLicenseText}";"";"";"";"";"";"";"";"";"";"";"";"/a"`,
);
expect(content).toContain(
'"2";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"/a/b"',
'"2";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"/a/b"',
);
expect(content).toContain(
'"2";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"/a/b/c"',
'"2";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"/a/b/c"',
);
expect(content).toContain(
'"2";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"/a/b/c/testi.bla"',
'"2";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"/a/b/c/testi.bla"',
);
expect(content).toContain(
'"2";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"/a/b/c/testi.blub"',
'"2";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"/a/b/c/testi.blub"',
);
expect(content).toContain(
'"2";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"/other"',
'"2";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"";"/other"',
);
deleteFolder(temporaryPath);
});
Expand Down
1 change: 1 addition & 0 deletions src/ElectronBackend/output/writeCsvToFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export function getHeadersFromColumns(columns: Array<KeysOfAttributionInfo>): {
needsReview: 'needs-review',
preferred: 'preferred',
preferredOverOriginIds: 'preferred-over-origin-ids',
wasPreferred: 'was-preferred',
};

const headers: { [key: string]: string } = {};
Expand Down
1 change: 1 addition & 0 deletions src/ElectronBackend/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ interface RawPackageInfo {
needsReview?: boolean;
preferred?: boolean;
preferredOverOriginIds?: Array<string>;
wasPreferred?: boolean;
}

export interface RawAttributions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function getFormattedCellData(
case 'needsReview':
case 'excludeFromNotice':
case 'preferred':
case 'wasPreferred':
cellData = attributionInfo[config.attributionProperty] ? 'Yes' : 'No';
break;
case 'icons':
Expand Down
2 changes: 2 additions & 0 deletions src/Frontend/util/__tests__/convert-package-info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ describe('convertPackageInfoToDisplayPackageInfo', () => {
'needsReview',
'preferred',
'preferredOverOriginIds',
'wasPreferred',
];
expect(testKeysOfPackageInfo).toEqual(expectedKeysOfPackageInfo);
});
Expand Down Expand Up @@ -137,6 +138,7 @@ describe('convertDisplayPackageInfoToPackageInfo', () => {
'attributionIds',
'preferred',
'preferredOverOriginIds',
'wasPreferred',
];
expect(testKeysOfDisplayPackageInfo).toEqual(
expectedKeysOfDisplayPackageInfo,
Expand Down
1 change: 1 addition & 0 deletions src/Frontend/util/get-display-package-info-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function getDisplayPackageInfoKeys(): Array<KeysOfDisplayPackageInfo> {
attributionIds: true,
preferred: true,
preferredOverOriginIds: true,
wasPreferred: true,
};
return Object.keys(
displayPackageInfoKeysObject,
Expand Down
1 change: 1 addition & 0 deletions src/shared/shared-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ interface PackageInfoCore {
needsReview?: boolean;
preferred?: boolean;
preferredOverOriginIds?: Array<string>;
wasPreferred?: boolean;
}

export interface PackageInfo extends PackageInfoCore {
Expand Down
1 change: 1 addition & 0 deletions src/shared/shared-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function getPackageInfoKeys(): Array<KeysOfPackageInfo> {
needsReview: true,
preferred: true,
preferredOverOriginIds: true,
wasPreferred: true,
};
return Object.keys(packageInfoKeysObject) as Array<KeysOfPackageInfo>;
}

0 comments on commit e3ddfe3

Please sign in to comment.