@@ -172,8 +172,16 @@ class WorkbenchDB {
172172 . then ( ( concs ) => concs . map ( ( conc ) => conc . fileId ) ) ;
173173 const pkgPromise = this . db . Package . findAll ( { attributes : [ 'fileId' ] } )
174174 . then ( ( pkgs ) => pkgs . map ( ( pkg ) => pkg . fileId ) ) ;
175-
176- return Promise . all ( [ analyzedPromise , NAPromise , OCPromise , NRPromise , pkgPromise ] ) . then ( ( promises ) => this . sync
175+ const approvedPromise = this . db . LicensePolicy . findAll ( { where : { label : 'Approved License' } , attributes : [ 'fileId' ] } )
176+ . then ( ( policies ) => policies . map ( ( policy ) => policy . fileId ) ) ;
177+ const prohibitedPromise = this . db . LicensePolicy . findAll ( { where : { label : 'Prohibited License' } , attributes : [ 'fileId' ] } )
178+ . then ( ( policies ) => policies . map ( ( policy ) => policy . fileId ) ) ;
179+ const recommendedPromise = this . db . LicensePolicy . findAll ( { where : { label : 'Recommended License' } , attributes : [ 'fileId' ] } )
180+ . then ( ( policies ) => policies . map ( ( policy ) => policy . fileId ) ) ;
181+ const restrictedPromise = this . db . LicensePolicy . findAll ( { where : { label : 'Restricted License' } , attributes : [ 'fileId' ] } )
182+ . then ( ( policies ) => policies . map ( ( policy ) => policy . fileId ) ) ;
183+
184+ return Promise . all ( [ analyzedPromise , NAPromise , OCPromise , NRPromise , pkgPromise , approvedPromise , prohibitedPromise , recommendedPromise , restrictedPromise ] ) . then ( ( promises ) => this . sync
177185 . then ( ( db ) => db . File . findAll ( query ) )
178186 . then ( ( files ) => {
179187 return files . map ( ( file ) => {
@@ -196,6 +204,10 @@ class WorkbenchDB {
196204 const oc = promises [ 2 ] ;
197205 const nr = promises [ 3 ] ;
198206 const packages = promises [ 4 ] ;
207+ const approvedPolicies = promises [ 5 ] ;
208+ const prohibitedPolicies = promises [ 6 ] ;
209+ const recommendedPolicies = promises [ 7 ] ;
210+ const restrictedPolicies = promises [ 8 ] ;
199211
200212 if ( analyzed . includes ( file . id ) ) {
201213 if ( file . type === 'file' ) {
@@ -227,6 +239,14 @@ class WorkbenchDB {
227239 } else if ( file . type === 'directory' ) {
228240 type = 'packageDir' ;
229241 }
242+ } else if ( approvedPolicies . includes ( file . id ) ) {
243+ type = 'approvedLicense' ;
244+ } else if ( prohibitedPolicies . includes ( file . id ) ) {
245+ type = 'prohibitedLicense' ;
246+ } else if ( recommendedPolicies . includes ( file . id ) ) {
247+ type = 'recommendedLicense' ;
248+ } else if ( restrictedPolicies . includes ( file . id ) ) {
249+ type = 'restrictedLicense' ;
230250 } else {
231251 type = file . type ;
232252 }
@@ -372,6 +392,7 @@ class WorkbenchDB {
372392 return this . db . File . bulkCreate ( files , options )
373393 . then ( ( ) => this . db . License . bulkCreate ( this . _addExtraFields ( files , 'licenses' ) , options ) )
374394 . then ( ( ) => this . db . LicenseExpression . bulkCreate ( this . _addExtraFields ( files , 'license_expressions' ) , options ) )
395+ . then ( ( ) => this . db . LicensePolicy . bulkCreate ( this . _addExtraFields ( files , 'license_policy' ) , options ) )
375396 . then ( ( ) => this . db . Copyright . bulkCreate ( this . _addExtraFields ( files , 'copyrights' ) , options ) )
376397 . then ( ( ) => this . db . Package . bulkCreate ( this . _addExtraFields ( files , 'packages' ) , options ) )
377398 . then ( ( ) => this . db . Email . bulkCreate ( this . _addExtraFields ( files , 'emails' ) , options ) )
@@ -388,6 +409,8 @@ class WorkbenchDB {
388409 return $ . map ( files , ( file ) => {
389410 if ( attribute === 'copyrights' ) {
390411 return this . _getNewCopyrights ( file ) ;
412+ } else if ( attribute === 'license_policy' ) {
413+ return this . _getLicensePolicy ( file ) ;
391414 }
392415 return $ . map ( file [ attribute ] || [ ] , ( value ) => {
393416 if ( attribute === 'license_expressions' ) {
@@ -402,6 +425,15 @@ class WorkbenchDB {
402425 } ) ;
403426 }
404427
428+ _getLicensePolicy ( file ) {
429+ if ( $ . isEmptyObject ( file . license_policy ) ) {
430+ return ;
431+ }
432+ const license_policy = file . license_policy ;
433+ license_policy . fileId = file . id ;
434+ return license_policy ;
435+ }
436+
405437 _getNewCopyrights ( file ) {
406438 const statements = file . copyrights ;
407439 const holders = file . holders ;
0 commit comments