@@ -11,6 +11,7 @@ import {
11
11
AttributionsToResources ,
12
12
DiscreteConfidence ,
13
13
ParsedFileContent ,
14
+ ResourcesToAttributions ,
14
15
} from '../../shared/shared-types' ;
15
16
import { getGlobalBackendState } from '../main/globalBackendState' ;
16
17
import {
@@ -256,68 +257,54 @@ function createJsonOutputFile(
256
257
inputFileMD5Checksum ?: string ,
257
258
) : OpossumOutputFile {
258
259
const externalAttributionsCopy = cloneDeep ( externalAttributions ) ;
259
- const preselectedExternalAttributions = Object . fromEntries (
260
- Object . entries ( externalAttributionsCopy ) . filter ( ( [ , packageInfo ] ) => {
260
+
261
+ const manualAttributions : Attributions = { } ;
262
+ const manualAttributionIdsToExternalAttributionIds : {
263
+ [ attributionId : string ] : string ;
264
+ } = { } ;
265
+ const manualAttributionIds = new Set < string > ( ) ;
266
+ for ( const attributionId of Object . keys ( externalAttributionsCopy ) ) {
267
+ const packageInfo = externalAttributionsCopy [ attributionId ] ;
268
+ if ( packageInfo . preSelected ) {
261
269
delete packageInfo . source ;
262
- return Boolean ( packageInfo . preSelected ) ;
263
- } ) ,
264
- ) ;
265
- const preselectedAttributionIdsToExternalAttributionIds = Object . fromEntries (
266
- Object . keys ( preselectedExternalAttributions ) . map ( ( attributionId ) => [
267
- attributionId ,
268
- uuid4 ( ) ,
269
- ] ) ,
270
- ) ;
271
- const preselectedAttributionsToResources = Object . fromEntries (
272
- Object . entries ( resourcesToExternalAttributions ) . map (
273
- ( [ resourceId , attributionIds ] ) => {
274
- const filteredAttributionIds = attributionIds . filter ( ( attributionId ) =>
275
- Object . keys ( preselectedExternalAttributions ) . includes ( attributionId ) ,
276
- ) ;
277
- return filteredAttributionIds . length
278
- ? [
279
- resourceId ,
280
- filteredAttributionIds . map (
281
- ( attributionId ) =>
282
- preselectedAttributionIdsToExternalAttributionIds [
283
- attributionId
284
- ] ,
285
- ) ,
286
- ]
287
- : [ ] ;
288
- } ,
289
- ) ,
290
- ) ;
291
- const preselectedAttributions = Object . fromEntries (
292
- Object . entries ( preselectedExternalAttributions ) . map (
293
- ( [ attributionId , packageInfo ] ) => [
294
- preselectedAttributionIdsToExternalAttributionIds [ attributionId ] ,
295
- packageInfo ,
296
- ] ,
297
- ) ,
298
- ) ;
270
+ if ( packageInfo . attributionConfidence !== undefined ) {
271
+ packageInfo . attributionConfidence =
272
+ packageInfo . attributionConfidence >= DiscreteConfidence . High
273
+ ? DiscreteConfidence . High
274
+ : DiscreteConfidence . Low ;
275
+ }
276
+
277
+ const newUUID = uuid4 ( ) ;
278
+ manualAttributions [ newUUID ] = packageInfo ;
279
+ manualAttributionIdsToExternalAttributionIds [ attributionId ] = newUUID ;
299
280
300
- for ( const attributionId of Object . keys ( preselectedAttributions ) ) {
301
- const attributionConfidence =
302
- preselectedAttributions [ attributionId ] . attributionConfidence ;
303
- if ( attributionConfidence !== undefined ) {
304
- preselectedAttributions [ attributionId ] . attributionConfidence =
305
- attributionConfidence >= DiscreteConfidence . High
306
- ? DiscreteConfidence . High
307
- : DiscreteConfidence . Low ;
281
+ manualAttributionIds . add ( attributionId ) ;
308
282
}
309
283
}
310
284
311
- const attributionJSON : OpossumOutputFile = {
285
+ const resourcesToAttributions : ResourcesToAttributions = { } ;
286
+ for ( const resourceId of Object . keys ( resourcesToExternalAttributions ) ) {
287
+ const attributionIds = resourcesToExternalAttributions [ resourceId ] ;
288
+ const filteredAttributionIds = attributionIds . filter ( ( attributionId ) =>
289
+ manualAttributionIds . has ( attributionId ) ,
290
+ ) ;
291
+
292
+ if ( filteredAttributionIds . length ) {
293
+ resourcesToAttributions [ resourceId ] = filteredAttributionIds . map (
294
+ ( attributionId ) =>
295
+ manualAttributionIdsToExternalAttributionIds [ attributionId ] ,
296
+ ) ;
297
+ }
298
+ }
299
+
300
+ return {
312
301
metadata : {
313
302
projectId,
314
303
fileCreationDate : String ( Date . now ( ) ) ,
315
304
inputFileMD5Checksum,
316
305
} ,
317
- manualAttributions : preselectedAttributions ,
318
- resourcesToAttributions : preselectedAttributionsToResources ,
306
+ manualAttributions,
307
+ resourcesToAttributions,
319
308
resolvedExternalAttributions : [ ] ,
320
309
} ;
321
-
322
- return attributionJSON ;
323
310
}
0 commit comments