Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add classification to internal data model #2810

Merged
merged 2 commits into from
Feb 24, 2025
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
24 changes: 24 additions & 0 deletions src/ElectronBackend/input/__tests__/importFromFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ const inputFileContent: ParsedOpossumInputFile = {
a: 1,
folder: {},
},
config: {
classifications: {
0: 'UNKNOWN',
1: 'CRITICAL',
},
},
externalAttributions: {
[externalAttributionUuid]: {
source,
Expand Down Expand Up @@ -107,6 +113,12 @@ const expectedFileContent: ParsedFileContent = {
projectTitle: 'Test Title',
},
resources: { a: 1, folder: {} },
config: {
classifications: {
0: 'UNKNOWN',
1: 'CRITICAL',
},
},
manualAttributions: {
attributions: {},
resourcesToAttributions: {},
Expand Down Expand Up @@ -362,6 +374,12 @@ describe('Test of loading function', () => {
resources: {
a: 1,
},
config: {
classifications: {
0: 'UNKNOWN',
1: 'CRITICAL',
},
},
externalAttributions: {
[externalAttributionUuid]: {
source,
Expand Down Expand Up @@ -418,6 +436,12 @@ describe('Test of loading function', () => {
const expectedLoadedFile: ParsedFileContent = {
metadata: EMPTY_PROJECT_METADATA,
resources: { a: 1 },
config: {
classifications: {
0: 'UNKNOWN',
1: 'CRITICAL',
},
},
manualAttributions: {
attributions: {
[manualAttributionUuid]: {
Expand Down
6 changes: 6 additions & 0 deletions src/ElectronBackend/input/__tests__/parseFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ const correctInput: ParsedOpossumInputFile = {
projectId: '2a58a469-738e-4508-98d3-a27bce6e71f7',
fileCreationDate: '2020-07-23 11:47:13.764544',
},
config: {
classifications: {
0: 'UNKNOWN',
1: 'CRITICAL',
},
},
externalAttributions: {
[testUuid]: {
source: {
Expand Down
1 change: 1 addition & 0 deletions src/ElectronBackend/input/importFromFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export async function loadInputAndOutputFromFilePath(
mainWindow.webContents.send(AllowedFrontendChannels.FileLoaded, {
metadata: parsedInputData.metadata,
resources: parsedInputData.resources,
config: parsedInputData.config,
manualAttributions: {
attributions: manualAttributions,
resourcesToAttributions: parsedOutputData.resourcesToAttributions,
Expand Down
2 changes: 2 additions & 0 deletions src/ElectronBackend/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import {
BaseUrlsForSources,
ExternalAttributionSources,
ProjectConfig,
ProjectMetadata,
RawAttributions,
Resources,
Expand Down Expand Up @@ -45,6 +46,7 @@ export interface RawFrequentLicense {
export interface ParsedOpossumInputFile {
metadata: ProjectMetadata;
resources: Resources;
config: ProjectConfig;
externalAttributions: RawAttributions;
resourcesToAttributions: ResourcesToAttributions;
frequentLicenses?: Array<RawFrequentLicense>;
Expand Down
5 changes: 5 additions & 0 deletions src/Frontend/shared-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
AttributionData,
FrequentLicenses,
PackageInfo,
ProjectConfig,
ProjectMetadata,
} from '../shared/shared-types';
import { text } from '../shared/text';
Expand Down Expand Up @@ -33,6 +34,10 @@ export const EMPTY_PROJECT_METADATA: ProjectMetadata = {
fileCreationDate: '',
};

export const EMPTY_PROJECT_CONFIG: ProjectConfig = {
classifications: {},
};

export const EMPTY_DISPLAY_PACKAGE_INFO: PackageInfo = {
id: '',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
FrequentLicenses,
PackageInfo,
ParsedFileContent,
ProjectConfig,
Resources,
ResourcesToAttributions,
} from '../../../../../shared/shared-types';
Expand All @@ -20,6 +21,7 @@ import { initialResourceState } from '../../../reducers/resource-reducer';
import {
getAttributionBreakpoints,
getBaseUrlsForSources,
getClassifications,
getExternalAttributionSources,
getExternalData,
getFilesWithChildren,
Expand All @@ -45,6 +47,13 @@ const testResources: Resources = {
},
};

const testConfig: ProjectConfig = {
classifications: {
0: 'UNKNOWN',
1: 'CRITICAL',
},
};

const testManualAttributionUuid_1 = '4d9f0b16-fbff-11ea-adc1-0242ac120002';
const testManualAttributionUuid_2 = 'b5da73d4-f400-11ea-adc1-0242ac120002';
const testTemporaryDisplayPackageInfo: PackageInfo = {
Expand Down Expand Up @@ -129,6 +138,7 @@ describe('loadFromFile', () => {
const testParsedFileContent: ParsedFileContent = {
metadata: EMPTY_PROJECT_METADATA,
resources: testResources,
config: testConfig,
manualAttributions: {
attributions: testManualAttributions,
resourcesToAttributions: testResourcesToManualAttributions,
Expand All @@ -149,6 +159,7 @@ describe('loadFromFile', () => {
},
};
const expectedResources: Resources = testResources;
const expectedConfig: ProjectConfig = testConfig;
const expectedManualData: AttributionData = {
attributions: testManualAttributions,
resourcesToAttributions: testResourcesToManualAttributions,
Expand Down Expand Up @@ -212,6 +223,9 @@ describe('loadFromFile', () => {

testStore.dispatch(loadFromFile(testParsedFileContent));
expect(getResources(testStore.getState())).toEqual(expectedResources);
expect(getClassifications(testStore.getState())).toEqual(
expectedConfig.classifications,
);
expect(getManualData(testStore.getState())).toEqual(expectedManualData);
expect(getExternalData(testStore.getState())).toEqual(expectedExternalData);
expect(getFrequentLicensesNameOrder(testStore.getState())).toEqual(
Expand Down Expand Up @@ -248,6 +262,7 @@ describe('loadFromFile', () => {
const testParsedFileContent: ParsedFileContent = {
metadata: EMPTY_PROJECT_METADATA,
resources: testResources,
config: testConfig,
manualAttributions: {
attributions: testManualAttributions,
resourcesToAttributions: testResourcesToManualAttributions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ExternalAttributionSources,
FrequentLicenses,
PackageInfo,
ProjectConfig,
ProjectMetadata,
Resources,
ResourcesToAttributions,
Expand All @@ -24,6 +25,7 @@ import {
ACTION_SET_FILES_WITH_CHILDREN,
ACTION_SET_FREQUENT_LICENSES,
ACTION_SET_MANUAL_ATTRIBUTION_DATA,
ACTION_SET_PROJECT_CONFIG,
ACTION_SET_PROJECT_METADATA,
ACTION_SET_RESOURCES,
ACTION_SET_TEMPORARY_PACKAGE_INFO,
Expand All @@ -36,6 +38,7 @@ import {
SetFrequentLicensesAction,
SetIsPreferenceFeatureEnabled,
SetManualDataAction,
SetProjectConfigAction,
SetProjectMetadata,
SetResourcesAction,
SetTemporaryDisplayPackageInfoAction,
Expand All @@ -49,6 +52,10 @@ export function setResources(resources: Resources | null): SetResourcesAction {
return { type: ACTION_SET_RESOURCES, payload: resources };
}

export function setConfig(config: ProjectConfig): SetProjectConfigAction {
return { type: ACTION_SET_PROJECT_CONFIG, payload: config };
}

export function setManualData(
attributions: Attributions,
resourcesToAttributions: ResourcesToAttributions,
Expand Down
3 changes: 3 additions & 0 deletions src/Frontend/state/actions/resource-actions/load-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { AppThunkAction } from '../../types';
import {
setAttributionBreakpoints,
setBaseUrlsForSources,
setConfig,
setExternalAttributionSources,
setExternalData,
setFilesWithChildren,
Expand All @@ -24,6 +25,8 @@ export function loadFromFile(
return (dispatch) => {
dispatch(setResources(parsedFileContent.resources));

dispatch(setConfig(parsedFileContent.config));

dispatch(
setManualData(
parsedFileContent.manualAttributions.attributions,
Expand Down
8 changes: 8 additions & 0 deletions src/Frontend/state/actions/resource-actions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ExternalAttributionSources,
FrequentLicenses,
PackageInfo,
ProjectConfig,
ProjectMetadata,
Resources,
ResourcesToAttributions,
Expand All @@ -18,6 +19,7 @@ export const ACTION_SET_SELECTED_ATTRIBUTION_ID =
'ACTION_SET_SELECTED_ATTRIBUTION_ID';
export const ACTION_RESET_RESOURCE_STATE = 'ACTION_RESET_RESOURCE_STATE';
export const ACTION_SET_RESOURCES = 'ACTION_SET_RESOURCES';
export const ACTION_SET_PROJECT_CONFIG = 'ACTION_SET_PROJECT_CONFIG';
export const ACTION_SET_MANUAL_ATTRIBUTION_DATA =
'ACTION_SET_MANUAL_ATTRIBUTION_DATA';
export const ACTION_SET_EXTERNAL_ATTRIBUTION_DATA =
Expand Down Expand Up @@ -63,6 +65,7 @@ export const ACTION_SET_ENABLE_PREFERENCE_FEATURE =
export type ResourceAction =
| ResetResourceStateAction
| SetResourcesAction
| SetProjectConfigAction
| SetManualDataAction
| SetExternalDataAction
| SetFrequentLicensesAction
Expand Down Expand Up @@ -97,6 +100,11 @@ export interface SetResourcesAction {
payload: Resources | null;
}

export interface SetProjectConfigAction {
type: typeof ACTION_SET_PROJECT_CONFIG;
payload: ProjectConfig;
}

export interface SetManualDataAction {
type: typeof ACTION_SET_MANUAL_ATTRIBUTION_DATA;
payload: AttributionData;
Expand Down
10 changes: 10 additions & 0 deletions src/Frontend/state/reducers/resource-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import {
ExternalAttributionSources,
FrequentLicenses,
PackageInfo,
ProjectConfig,
ProjectMetadata,
Resources,
} from '../../../shared/shared-types';
import {
EMPTY_ATTRIBUTION_DATA,
EMPTY_DISPLAY_PACKAGE_INFO,
EMPTY_FREQUENT_LICENSES,
EMPTY_PROJECT_CONFIG,
EMPTY_PROJECT_METADATA,
ROOT_PATH,
} from '../../shared-constants';
Expand All @@ -36,6 +38,7 @@ import {
ACTION_SET_FILES_WITH_CHILDREN,
ACTION_SET_FREQUENT_LICENSES,
ACTION_SET_MANUAL_ATTRIBUTION_DATA,
ACTION_SET_PROJECT_CONFIG,
ACTION_SET_PROJECT_METADATA,
ACTION_SET_RESOLVED_EXTERNAL_ATTRIBUTIONS,
ACTION_SET_RESOURCES,
Expand Down Expand Up @@ -71,6 +74,7 @@ export const initialResourceState: ResourceState = {
isPreferenceFeatureEnabled: false,
manualData: EMPTY_ATTRIBUTION_DATA,
metadata: EMPTY_PROJECT_METADATA,
config: EMPTY_PROJECT_CONFIG,
resolvedExternalAttributions: new Set(),
resources: null,
resourceIds: null,
Expand All @@ -92,6 +96,7 @@ export type ResourceState = {
isPreferenceFeatureEnabled: boolean;
manualData: AttributionData;
metadata: ProjectMetadata;
config: ProjectConfig;
resolvedExternalAttributions: Set<string>;
resources: Resources | null;
resourceIds: Array<string> | null;
Expand All @@ -117,6 +122,11 @@ export const resourceState = (
? getResourceIdsFromResources(action.payload)
: null,
};
case ACTION_SET_PROJECT_CONFIG:
return {
...state,
config: action.payload,
};
case ACTION_SET_MANUAL_ATTRIBUTION_DATA:
return {
...state,
Expand Down
5 changes: 5 additions & 0 deletions src/Frontend/state/selectors/resource-selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Attributions,
AttributionsToResources,
BaseUrlsForSources,
Classifications,
ExternalAttributionSources,
FrequentLicenseName,
LicenseTexts,
Expand Down Expand Up @@ -141,6 +142,10 @@ export function getProjectMetadata(state: State): ProjectMetadata {
return state.resourceState.metadata;
}

export function getClassifications(state: State): Classifications {
return state.resourceState.config.classifications;
}

export function getPackageInfoOfSelectedAttribution(
state: State,
): PackageInfo | null {
Expand Down
2 changes: 2 additions & 0 deletions src/Frontend/test-helpers/general-test-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import {
} from '../../shared/shared-types';
import {
EMPTY_FREQUENT_LICENSES,
EMPTY_PROJECT_CONFIG,
EMPTY_PROJECT_METADATA,
} from '../shared-constants';
import { canResourceHaveChildren } from '../util/can-resource-have-children';

const EMPTY_PARSED_FILE_CONTENT: ParsedFileContent = {
metadata: EMPTY_PROJECT_METADATA,
resources: {},
config: EMPTY_PROJECT_CONFIG,
manualAttributions: {
attributions: {},
resourcesToAttributions: {},
Expand Down
1 change: 1 addition & 0 deletions src/Frontend/util/get-stripped-package-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const strippedPackageInfoTemplate: {
} = {
attributionConfidence: true,
comment: true,
classification: false,
copyright: true,
count: false,
criticality: false,
Expand Down
10 changes: 10 additions & 0 deletions src/shared/shared-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ interface EphemeralPackageInfoProps {

export interface PackageInfo extends EphemeralPackageInfoProps {
attributionConfidence?: number;
classification?: number;
comment?: string;
copyright?: string;
count?: number;
Expand Down Expand Up @@ -139,9 +140,18 @@ export interface ProjectMetadata {
[otherMetadata: string]: unknown;
}

export interface Classifications {
[classification: number]: string;
}

export interface ProjectConfig {
classifications: Classifications;
}

export interface ParsedFileContent {
metadata: ProjectMetadata;
resources: Resources;
config: ProjectConfig;
manualAttributions: InputFileAttributionData;
externalAttributions: InputFileAttributionData;
frequentLicenses: FrequentLicenses;
Expand Down
1 change: 1 addition & 0 deletions src/testing/Faker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ class OpossumModule {
return {
metadata: OpossumModule.metadata(),
resources: {},
config: { classifications: {} },
externalAttributions: {},
resourcesToAttributions: {},
...props,
Expand Down
Loading