Skip to content

Commit

Permalink
autoformatter
Browse files Browse the repository at this point in the history
  • Loading branch information
clemiller committed Feb 27, 2024
1 parent 5c2af76 commit d3e1221
Showing 1 changed file with 40 additions and 40 deletions.
80 changes: 40 additions & 40 deletions nav-app/src/app/services/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,31 @@ export class DataService {
public parseBundle(domain: Domain, stixBundles: any[]): void {
let platforms = new Set<string>();
let seenIDs = new Set<string>();
let matrixSDOs = [];
let idToTacticSDO = new Map<string, any>();
let matrixToTechniqueSDOs = new Map<string, any[]>();
let matrixSDOs = [];
let idToTacticSDO = new Map<string, any>();
let matrixToTechniqueSDOs = new Map<string, any[]>();
for (let bundle of stixBundles) {
let techniqueSDOs = [];
let bundleMatrices = [];
let bundleMatrices = [];
let idToTechniqueSDO = new Map<string, any>();
for (let sdo of bundle.objects) {
// iterate through stix domain objects in the bundle
// Filter out object not included in this domain if domains field is available
if (
!domain.isCustom &&
sdo.x_mitre_domains?.length > 0 &&
(domain.urls.length == 1 &&
!sdo.x_mitre_domains.includes(domain.domain_identifier))
domain.urls.length == 1 &&
!sdo.x_mitre_domains.includes(domain.domain_identifier)
) {
continue;
}

// filter out duplicates, except for matrices
// which are needed to properly build the datatables
if (sdo.type != 'x-mitre-matrix') {
if (seenIDs.has(sdo.id)) continue;
seenIDs.add(sdo.id);
}
// which are needed to properly build the datatables
if (sdo.type != 'x-mitre-matrix') {
if (seenIDs.has(sdo.id)) continue;
seenIDs.add(sdo.id);
}

// parse according to type
switch (sdo.type) {
Expand Down Expand Up @@ -108,7 +108,7 @@ export class DataService {
break;
case 'x-mitre-matrix':
matrixSDOs.push(sdo);
bundleMatrices.push(sdo);
bundleMatrices.push(sdo);
break;
case 'note':
domain.notes.push(new Note(sdo));
Expand All @@ -119,17 +119,17 @@ export class DataService {
// create techniques
this.createTechniques(techniqueSDOs, idToTechniqueSDO, domain);

// create map of matrices to techniques
for (let matrixSDO of bundleMatrices) {
if (!matrixToTechniqueSDOs.get(matrixSDO.id)) {
matrixToTechniqueSDOs.set(matrixSDO.id, techniqueSDOs);
} else {
matrixToTechniqueSDOs.get(matrixSDO.id).push(...techniqueSDOs);
}
}

// parse platforms
this.parsePlatforms(domain).forEach(platforms.add, platforms);
// create map of matrices to techniques
for (let matrixSDO of bundleMatrices) {
if (!matrixToTechniqueSDOs.get(matrixSDO.id)) {
matrixToTechniqueSDOs.set(matrixSDO.id, techniqueSDOs);
} else {
matrixToTechniqueSDOs.get(matrixSDO.id).push(...techniqueSDOs);
}
}

// parse platforms
this.parsePlatforms(domain).forEach(platforms.add, platforms);
}

// create matrices
Expand Down Expand Up @@ -174,23 +174,23 @@ export class DataService {
* @param domain the domain to add the matrix/tactics to
*/
public createMatrices(matrixSDOs: any[], idToTacticSDO: Map<string, any>, matrixToTechniqueSDOs, domain: Domain): void {
let createdMatrixIDs = [];
for (let matrixSDO of matrixSDOs) {
// check if matrix was already created
if (createdMatrixIDs.includes(matrixSDO.id)) continue;

// check if matrix is deprecated
if (matrixSDO.x_mitre_deprecated) continue;

// retrieve relevant matrix techniques
let techniqueSDOs = matrixToTechniqueSDOs.get(matrixSDO.id);
let techniqueIDs = techniqueSDOs.map(t => t.id);
let techniques = domain.techniques.filter(t => techniqueIDs.includes(t.id));
domain.matrices.push(new Matrix(matrixSDO, idToTacticSDO, techniques, this));

// add to list of created matrices
createdMatrixIDs.push(matrixSDO.id);
}
let createdMatrixIDs = [];
for (let matrixSDO of matrixSDOs) {
// check if matrix was already created
if (createdMatrixIDs.includes(matrixSDO.id)) continue;

// check if matrix is deprecated
if (matrixSDO.x_mitre_deprecated) continue;

// retrieve relevant matrix techniques
let techniqueSDOs = matrixToTechniqueSDOs.get(matrixSDO.id);
let techniqueIDs = techniqueSDOs.map((t) => t.id);
let techniques = domain.techniques.filter((t) => techniqueIDs.includes(t.id));
domain.matrices.push(new Matrix(matrixSDO, idToTacticSDO, techniques, this));

// add to list of created matrices
createdMatrixIDs.push(matrixSDO.id);
}
}

/**
Expand Down

0 comments on commit d3e1221

Please sign in to comment.