11import { Component , OnInit , Input , ViewEncapsulation } from '@angular/core' ;
2- import { StixObject , Group , Mitigation , Software , Technique , Campaign , Asset } from '../classes/stix' ;
2+ import { StixObject , Group , Mitigation , Software , Technique , Campaign , Asset , DetectionStrategy } from '../classes/stix' ;
33import { ViewModelsService } from '../services/viewmodels.service' ;
44import { DataService } from '../services/data.service' ;
55import { ViewModel } from '../classes' ;
@@ -13,6 +13,7 @@ import { ViewModel } from '../classes';
1313export class SearchAndMultiselectComponent implements OnInit {
1414 @Input ( ) viewModel : ViewModel ;
1515
16+ public domain ;
1617 public stixTypes : any [ ] = [ ] ;
1718 public techniqueResults : Technique [ ] = [ ] ;
1819 // Data Components is a map mainly because it is a collection of labels that map to
@@ -25,15 +26,15 @@ export class SearchAndMultiselectComponent implements OnInit {
2526 0 : true , // techniques panel
2627 1 : false , // groups panel
2728 2 : false , // software panel
28- 3 : false , // campaign panel
29- 4 : false , // mitigations panel
30- 5 : false , // data components panel
31- 6 : false , // assets panel
29+ 3 : false , // mitigations panel
30+ 4 : false , // campaigns panel
31+ 5 : false , // assets panel
32+ 6 : false , // data sources OR detection strategies panel
3233 } ;
3334
3435 public fields = [
3536 {
36- label : 'name ' ,
37+ label : 'Name ' ,
3738 field : 'name' ,
3839 enabled : true ,
3940 } ,
@@ -43,15 +44,10 @@ export class SearchAndMultiselectComponent implements OnInit {
4344 enabled : true ,
4445 } ,
4546 {
46- label : 'description ' ,
47+ label : 'Description ' ,
4748 field : 'description' ,
4849 enabled : true ,
4950 } ,
50- {
51- label : 'data sources' ,
52- field : 'datasources' ,
53- enabled : true ,
54- } ,
5551 ] ;
5652
5753 private debounceFunction ;
@@ -92,6 +88,15 @@ export class SearchAndMultiselectComponent implements OnInit {
9288 }
9389
9490 ngOnInit ( ) {
91+ this . domain = this . dataService . getDomain ( this . viewModel . domainVersionID ) ;
92+ // backwards compatibility for old data sources
93+ if ( this . domain . supportsLegacyDataSources ) {
94+ this . fields . push ( {
95+ label : 'Data Sources' ,
96+ field : 'datasources' ,
97+ enabled : true ,
98+ } ) ;
99+ }
95100 this . getResults ( ) ;
96101 }
97102
@@ -202,8 +207,8 @@ export class SearchAndMultiselectComponent implements OnInit {
202207 * Retrieve master list of techniques and sub-techniques
203208 */
204209 public getTechniques ( ) : void {
205- let allTechniques = this . dataService . getDomain ( this . viewModel . domainVersionID ) . techniques ;
206- for ( let technique of allTechniques ) {
210+ let allTechniques = this . domain . techniques ;
211+ for ( let technique of this . domain . techniques ) {
207212 allTechniques = allTechniques . concat ( technique . subtechniques ) ;
208213 }
209214 this . techniqueResults = this . filterAndSort ( allTechniques , this . _query , true ) ;
@@ -213,40 +218,46 @@ export class SearchAndMultiselectComponent implements OnInit {
213218 * Retrieve master list of STIX objects
214219 */
215220 public getStixData ( ) : void {
216- let domain = this . dataService . getDomain ( this . viewModel . domainVersionID ) ;
217-
218221 this . stixTypes = [
219222 {
220223 label : 'threat groups' ,
221- objects : this . filterAndSort ( domain . groups , this . _query ) ,
224+ objects : this . filterAndSort ( this . domain . groups , this . _query ) ,
222225 } ,
223226 {
224227 label : 'software' ,
225- objects : this . filterAndSort ( domain . software , this . _query ) ,
228+ objects : this . filterAndSort ( this . domain . software , this . _query ) ,
226229 } ,
227230 {
228231 label : 'mitigations' ,
229- objects : this . filterAndSort ( domain . mitigations , this . _query ) ,
232+ objects : this . filterAndSort ( this . domain . mitigations , this . _query ) ,
230233 } ,
231234 {
232235 label : 'campaigns' ,
233- objects : this . filterAndSort ( domain . campaigns , this . _query ) ,
236+ objects : this . filterAndSort ( this . domain . campaigns , this . _query ) ,
234237 } ,
235238 {
236239 label : 'assets' ,
237- objects : this . filterAndSort ( domain . assets , this . _query ) ,
240+ objects : this . filterAndSort ( this . domain . assets , this . _query ) ,
238241 } ,
239242 ] ;
240243
241- domain . dataComponents . forEach ( ( c ) => {
242- const source = c . source ( this . viewModel . domainVersionID ) ;
243- const label = `${ source . name } : ${ c . name } ` ;
244+ if ( this . domain . detectionStrategies . length ) {
245+ this . stixTypes . push ( {
246+ label : 'detection strategies' ,
247+ objects : this . filterAndSort ( this . domain . detectionStrategies , this . _query ) ,
248+ } )
249+ }
250+
251+ const legacyFormat = this . domain . supportsLegacyDataSources ;
252+ for ( let dc of this . domain . dataComponents ) {
253+ const source = legacyFormat ? dc . source ( this . viewModel . domainVersionID ) : dc ;
254+ const label = legacyFormat ? `${ source . name } : ${ dc . name } ` : source . name ;
244255 const obj = {
245- objects : c . techniques ( this . viewModel . domainVersionID ) ,
256+ objects : dc . techniques ( this . viewModel . domainVersionID ) ,
246257 url : source . url ,
247- } ;
258+ }
248259 this . stixDataComponents . set ( label , obj ) ;
249- } ) ;
260+ }
250261 this . stixDataComponentLabels = this . filterAndSortLabels ( Array . from ( this . stixDataComponents . keys ( ) ) , this . _query ) ;
251262 }
252263
@@ -323,22 +334,15 @@ export class SearchAndMultiselectComponent implements OnInit {
323334
324335 public getRelated ( stixObject : StixObject ) : Technique [ ] {
325336 // master list of all techniques and sub-techniques
326- let techniques = this . dataService . getDomain ( this . viewModel . domainVersionID ) . techniques ;
327- let allTechniques = techniques . concat ( this . dataService . getDomain ( this . viewModel . domainVersionID ) . subtechniques ) ;
337+ let techniques = this . domain . techniques ;
338+ let allTechniques = techniques . concat ( this . domain . subtechniques ) ;
328339 let domainVersionID = this . viewModel . domainVersionID ;
329340
330- if ( stixObject instanceof Group ) {
331- return allTechniques . filter ( ( technique : Technique ) => ( stixObject as Group ) . relatedTechniques ( domainVersionID ) . includes ( technique . id ) ) ;
332- } else if ( stixObject instanceof Software ) {
333- return allTechniques . filter ( ( technique : Technique ) => ( stixObject as Software ) . relatedTechniques ( domainVersionID ) . includes ( technique . id ) ) ;
334- } else if ( stixObject instanceof Mitigation ) {
335- return allTechniques . filter ( ( technique : Technique ) =>
336- ( stixObject as Mitigation ) . relatedTechniques ( domainVersionID ) . includes ( technique . id )
337- ) ;
338- } else if ( stixObject instanceof Campaign ) {
339- return allTechniques . filter ( ( technique : Technique ) => ( stixObject as Campaign ) . relatedTechniques ( domainVersionID ) . includes ( technique . id ) ) ;
340- } else if ( stixObject instanceof Asset ) {
341- return allTechniques . filter ( ( technique : Technique ) => ( stixObject as Asset ) . relatedTechniques ( domainVersionID ) . includes ( technique . id ) ) ;
341+ const types = [ Group , Software , Mitigation , Campaign , Asset , DetectionStrategy ] ;
342+ const matchedType = types . find ( StixType => stixObject instanceof StixType ) ;
343+ if ( matchedType ) {
344+ return allTechniques . filter ( ( technique : Technique ) => ( stixObject as any ) . relatedTechniques ( domainVersionID ) . includes ( technique . id ) ) ;
342345 }
346+ return [ ] ;
343347 }
344348}
0 commit comments