Skip to content

Commit 09512d5

Browse files
authored
Merge pull request #2810 from opossum-tool/feat/internal-model-for-classification
Add classification to internal data model
2 parents 711d47c + e63c3c0 commit 09512d5

15 files changed

+100
-0
lines changed

src/ElectronBackend/input/__tests__/importFromFile.test.ts

+24
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ const inputFileContent: ParsedOpossumInputFile = {
6666
a: 1,
6767
folder: {},
6868
},
69+
config: {
70+
classifications: {
71+
0: 'UNKNOWN',
72+
1: 'CRITICAL',
73+
},
74+
},
6975
externalAttributions: {
7076
[externalAttributionUuid]: {
7177
source,
@@ -107,6 +113,12 @@ const expectedFileContent: ParsedFileContent = {
107113
projectTitle: 'Test Title',
108114
},
109115
resources: { a: 1, folder: {} },
116+
config: {
117+
classifications: {
118+
0: 'UNKNOWN',
119+
1: 'CRITICAL',
120+
},
121+
},
110122
manualAttributions: {
111123
attributions: {},
112124
resourcesToAttributions: {},
@@ -362,6 +374,12 @@ describe('Test of loading function', () => {
362374
resources: {
363375
a: 1,
364376
},
377+
config: {
378+
classifications: {
379+
0: 'UNKNOWN',
380+
1: 'CRITICAL',
381+
},
382+
},
365383
externalAttributions: {
366384
[externalAttributionUuid]: {
367385
source,
@@ -418,6 +436,12 @@ describe('Test of loading function', () => {
418436
const expectedLoadedFile: ParsedFileContent = {
419437
metadata: EMPTY_PROJECT_METADATA,
420438
resources: { a: 1 },
439+
config: {
440+
classifications: {
441+
0: 'UNKNOWN',
442+
1: 'CRITICAL',
443+
},
444+
},
421445
manualAttributions: {
422446
attributions: {
423447
[manualAttributionUuid]: {

src/ElectronBackend/input/__tests__/parseFile.test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ const correctInput: ParsedOpossumInputFile = {
2525
projectId: '2a58a469-738e-4508-98d3-a27bce6e71f7',
2626
fileCreationDate: '2020-07-23 11:47:13.764544',
2727
},
28+
config: {
29+
classifications: {
30+
0: 'UNKNOWN',
31+
1: 'CRITICAL',
32+
},
33+
},
2834
externalAttributions: {
2935
[testUuid]: {
3036
source: {

src/ElectronBackend/input/importFromFile.ts

+1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export async function loadInputAndOutputFromFilePath(
167167
mainWindow.webContents.send(AllowedFrontendChannels.FileLoaded, {
168168
metadata: parsedInputData.metadata,
169169
resources: parsedInputData.resources,
170+
config: parsedInputData.config,
170171
manualAttributions: {
171172
attributions: manualAttributions,
172173
resourcesToAttributions: parsedOutputData.resourcesToAttributions,

src/ElectronBackend/types/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import {
66
BaseUrlsForSources,
77
ExternalAttributionSources,
8+
ProjectConfig,
89
ProjectMetadata,
910
RawAttributions,
1011
Resources,
@@ -45,6 +46,7 @@ export interface RawFrequentLicense {
4546
export interface ParsedOpossumInputFile {
4647
metadata: ProjectMetadata;
4748
resources: Resources;
49+
config: ProjectConfig;
4850
externalAttributions: RawAttributions;
4951
resourcesToAttributions: ResourcesToAttributions;
5052
frequentLicenses?: Array<RawFrequentLicense>;

src/Frontend/shared-constants.ts

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
AttributionData,
77
FrequentLicenses,
88
PackageInfo,
9+
ProjectConfig,
910
ProjectMetadata,
1011
} from '../shared/shared-types';
1112
import { text } from '../shared/text';
@@ -33,6 +34,10 @@ export const EMPTY_PROJECT_METADATA: ProjectMetadata = {
3334
fileCreationDate: '',
3435
};
3536

37+
export const EMPTY_PROJECT_CONFIG: ProjectConfig = {
38+
classifications: {},
39+
};
40+
3641
export const EMPTY_DISPLAY_PACKAGE_INFO: PackageInfo = {
3742
id: '',
3843
};

src/Frontend/state/actions/resource-actions/__tests__/load-actions.test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
FrequentLicenses,
1212
PackageInfo,
1313
ParsedFileContent,
14+
ProjectConfig,
1415
Resources,
1516
ResourcesToAttributions,
1617
} from '../../../../../shared/shared-types';
@@ -20,6 +21,7 @@ import { initialResourceState } from '../../../reducers/resource-reducer';
2021
import {
2122
getAttributionBreakpoints,
2223
getBaseUrlsForSources,
24+
getClassifications,
2325
getExternalAttributionSources,
2426
getExternalData,
2527
getFilesWithChildren,
@@ -45,6 +47,13 @@ const testResources: Resources = {
4547
},
4648
};
4749

50+
const testConfig: ProjectConfig = {
51+
classifications: {
52+
0: 'UNKNOWN',
53+
1: 'CRITICAL',
54+
},
55+
};
56+
4857
const testManualAttributionUuid_1 = '4d9f0b16-fbff-11ea-adc1-0242ac120002';
4958
const testManualAttributionUuid_2 = 'b5da73d4-f400-11ea-adc1-0242ac120002';
5059
const testTemporaryDisplayPackageInfo: PackageInfo = {
@@ -129,6 +138,7 @@ describe('loadFromFile', () => {
129138
const testParsedFileContent: ParsedFileContent = {
130139
metadata: EMPTY_PROJECT_METADATA,
131140
resources: testResources,
141+
config: testConfig,
132142
manualAttributions: {
133143
attributions: testManualAttributions,
134144
resourcesToAttributions: testResourcesToManualAttributions,
@@ -149,6 +159,7 @@ describe('loadFromFile', () => {
149159
},
150160
};
151161
const expectedResources: Resources = testResources;
162+
const expectedConfig: ProjectConfig = testConfig;
152163
const expectedManualData: AttributionData = {
153164
attributions: testManualAttributions,
154165
resourcesToAttributions: testResourcesToManualAttributions,
@@ -212,6 +223,9 @@ describe('loadFromFile', () => {
212223

213224
testStore.dispatch(loadFromFile(testParsedFileContent));
214225
expect(getResources(testStore.getState())).toEqual(expectedResources);
226+
expect(getClassifications(testStore.getState())).toEqual(
227+
expectedConfig.classifications,
228+
);
215229
expect(getManualData(testStore.getState())).toEqual(expectedManualData);
216230
expect(getExternalData(testStore.getState())).toEqual(expectedExternalData);
217231
expect(getFrequentLicensesNameOrder(testStore.getState())).toEqual(
@@ -248,6 +262,7 @@ describe('loadFromFile', () => {
248262
const testParsedFileContent: ParsedFileContent = {
249263
metadata: EMPTY_PROJECT_METADATA,
250264
resources: testResources,
265+
config: testConfig,
251266
manualAttributions: {
252267
attributions: testManualAttributions,
253268
resourcesToAttributions: testResourcesToManualAttributions,

src/Frontend/state/actions/resource-actions/all-views-simple-actions.ts

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
ExternalAttributionSources,
1010
FrequentLicenses,
1111
PackageInfo,
12+
ProjectConfig,
1213
ProjectMetadata,
1314
Resources,
1415
ResourcesToAttributions,
@@ -24,6 +25,7 @@ import {
2425
ACTION_SET_FILES_WITH_CHILDREN,
2526
ACTION_SET_FREQUENT_LICENSES,
2627
ACTION_SET_MANUAL_ATTRIBUTION_DATA,
28+
ACTION_SET_PROJECT_CONFIG,
2729
ACTION_SET_PROJECT_METADATA,
2830
ACTION_SET_RESOURCES,
2931
ACTION_SET_TEMPORARY_PACKAGE_INFO,
@@ -36,6 +38,7 @@ import {
3638
SetFrequentLicensesAction,
3739
SetIsPreferenceFeatureEnabled,
3840
SetManualDataAction,
41+
SetProjectConfigAction,
3942
SetProjectMetadata,
4043
SetResourcesAction,
4144
SetTemporaryDisplayPackageInfoAction,
@@ -49,6 +52,10 @@ export function setResources(resources: Resources | null): SetResourcesAction {
4952
return { type: ACTION_SET_RESOURCES, payload: resources };
5053
}
5154

55+
export function setConfig(config: ProjectConfig): SetProjectConfigAction {
56+
return { type: ACTION_SET_PROJECT_CONFIG, payload: config };
57+
}
58+
5259
export function setManualData(
5360
attributions: Attributions,
5461
resourcesToAttributions: ResourcesToAttributions,

src/Frontend/state/actions/resource-actions/load-actions.ts

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { AppThunkAction } from '../../types';
77
import {
88
setAttributionBreakpoints,
99
setBaseUrlsForSources,
10+
setConfig,
1011
setExternalAttributionSources,
1112
setExternalData,
1213
setFilesWithChildren,
@@ -24,6 +25,8 @@ export function loadFromFile(
2425
return (dispatch) => {
2526
dispatch(setResources(parsedFileContent.resources));
2627

28+
dispatch(setConfig(parsedFileContent.config));
29+
2730
dispatch(
2831
setManualData(
2932
parsedFileContent.manualAttributions.attributions,

src/Frontend/state/actions/resource-actions/types.ts

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
ExternalAttributionSources,
1010
FrequentLicenses,
1111
PackageInfo,
12+
ProjectConfig,
1213
ProjectMetadata,
1314
Resources,
1415
ResourcesToAttributions,
@@ -18,6 +19,7 @@ export const ACTION_SET_SELECTED_ATTRIBUTION_ID =
1819
'ACTION_SET_SELECTED_ATTRIBUTION_ID';
1920
export const ACTION_RESET_RESOURCE_STATE = 'ACTION_RESET_RESOURCE_STATE';
2021
export const ACTION_SET_RESOURCES = 'ACTION_SET_RESOURCES';
22+
export const ACTION_SET_PROJECT_CONFIG = 'ACTION_SET_PROJECT_CONFIG';
2123
export const ACTION_SET_MANUAL_ATTRIBUTION_DATA =
2224
'ACTION_SET_MANUAL_ATTRIBUTION_DATA';
2325
export const ACTION_SET_EXTERNAL_ATTRIBUTION_DATA =
@@ -63,6 +65,7 @@ export const ACTION_SET_ENABLE_PREFERENCE_FEATURE =
6365
export type ResourceAction =
6466
| ResetResourceStateAction
6567
| SetResourcesAction
68+
| SetProjectConfigAction
6669
| SetManualDataAction
6770
| SetExternalDataAction
6871
| SetFrequentLicensesAction
@@ -97,6 +100,11 @@ export interface SetResourcesAction {
97100
payload: Resources | null;
98101
}
99102

103+
export interface SetProjectConfigAction {
104+
type: typeof ACTION_SET_PROJECT_CONFIG;
105+
payload: ProjectConfig;
106+
}
107+
100108
export interface SetManualDataAction {
101109
type: typeof ACTION_SET_MANUAL_ATTRIBUTION_DATA;
102110
payload: AttributionData;

src/Frontend/state/reducers/resource-reducer.ts

+10
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import {
88
ExternalAttributionSources,
99
FrequentLicenses,
1010
PackageInfo,
11+
ProjectConfig,
1112
ProjectMetadata,
1213
Resources,
1314
} from '../../../shared/shared-types';
1415
import {
1516
EMPTY_ATTRIBUTION_DATA,
1617
EMPTY_DISPLAY_PACKAGE_INFO,
1718
EMPTY_FREQUENT_LICENSES,
19+
EMPTY_PROJECT_CONFIG,
1820
EMPTY_PROJECT_METADATA,
1921
ROOT_PATH,
2022
} from '../../shared-constants';
@@ -36,6 +38,7 @@ import {
3638
ACTION_SET_FILES_WITH_CHILDREN,
3739
ACTION_SET_FREQUENT_LICENSES,
3840
ACTION_SET_MANUAL_ATTRIBUTION_DATA,
41+
ACTION_SET_PROJECT_CONFIG,
3942
ACTION_SET_PROJECT_METADATA,
4043
ACTION_SET_RESOLVED_EXTERNAL_ATTRIBUTIONS,
4144
ACTION_SET_RESOURCES,
@@ -71,6 +74,7 @@ export const initialResourceState: ResourceState = {
7174
isPreferenceFeatureEnabled: false,
7275
manualData: EMPTY_ATTRIBUTION_DATA,
7376
metadata: EMPTY_PROJECT_METADATA,
77+
config: EMPTY_PROJECT_CONFIG,
7478
resolvedExternalAttributions: new Set(),
7579
resources: null,
7680
resourceIds: null,
@@ -92,6 +96,7 @@ export type ResourceState = {
9296
isPreferenceFeatureEnabled: boolean;
9397
manualData: AttributionData;
9498
metadata: ProjectMetadata;
99+
config: ProjectConfig;
95100
resolvedExternalAttributions: Set<string>;
96101
resources: Resources | null;
97102
resourceIds: Array<string> | null;
@@ -117,6 +122,11 @@ export const resourceState = (
117122
? getResourceIdsFromResources(action.payload)
118123
: null,
119124
};
125+
case ACTION_SET_PROJECT_CONFIG:
126+
return {
127+
...state,
128+
config: action.payload,
129+
};
120130
case ACTION_SET_MANUAL_ATTRIBUTION_DATA:
121131
return {
122132
...state,

src/Frontend/state/selectors/resource-selectors.ts

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
Attributions,
1010
AttributionsToResources,
1111
BaseUrlsForSources,
12+
Classifications,
1213
ExternalAttributionSources,
1314
FrequentLicenseName,
1415
LicenseTexts,
@@ -141,6 +142,10 @@ export function getProjectMetadata(state: State): ProjectMetadata {
141142
return state.resourceState.metadata;
142143
}
143144

145+
export function getClassifications(state: State): Classifications {
146+
return state.resourceState.config.classifications;
147+
}
148+
144149
export function getPackageInfoOfSelectedAttribution(
145150
state: State,
146151
): PackageInfo | null {

src/Frontend/test-helpers/general-test-helpers.ts

+2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ import {
1515
} from '../../shared/shared-types';
1616
import {
1717
EMPTY_FREQUENT_LICENSES,
18+
EMPTY_PROJECT_CONFIG,
1819
EMPTY_PROJECT_METADATA,
1920
} from '../shared-constants';
2021
import { canResourceHaveChildren } from '../util/can-resource-have-children';
2122

2223
const EMPTY_PARSED_FILE_CONTENT: ParsedFileContent = {
2324
metadata: EMPTY_PROJECT_METADATA,
2425
resources: {},
26+
config: EMPTY_PROJECT_CONFIG,
2527
manualAttributions: {
2628
attributions: {},
2729
resourcesToAttributions: {},

src/Frontend/util/get-stripped-package-info.ts

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const strippedPackageInfoTemplate: {
2626
} = {
2727
attributionConfidence: true,
2828
comment: true,
29+
classification: false,
2930
copyright: true,
3031
count: false,
3132
criticality: false,

src/shared/shared-types.ts

+10
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ interface EphemeralPackageInfoProps {
5252

5353
export interface PackageInfo extends EphemeralPackageInfoProps {
5454
attributionConfidence?: number;
55+
classification?: number;
5556
comment?: string;
5657
copyright?: string;
5758
count?: number;
@@ -139,9 +140,18 @@ export interface ProjectMetadata {
139140
[otherMetadata: string]: unknown;
140141
}
141142

143+
export interface Classifications {
144+
[classification: number]: string;
145+
}
146+
147+
export interface ProjectConfig {
148+
classifications: Classifications;
149+
}
150+
142151
export interface ParsedFileContent {
143152
metadata: ProjectMetadata;
144153
resources: Resources;
154+
config: ProjectConfig;
145155
manualAttributions: InputFileAttributionData;
146156
externalAttributions: InputFileAttributionData;
147157
frequentLicenses: FrequentLicenses;

src/testing/Faker.ts

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ class OpossumModule {
263263
return {
264264
metadata: OpossumModule.metadata(),
265265
resources: {},
266+
config: { classifications: {} },
266267
externalAttributions: {},
267268
resourcesToAttributions: {},
268269
...props,

0 commit comments

Comments
 (0)