Skip to content

Commit

Permalink
refactor!: rename groups to capability_groups in export schema
Browse files Browse the repository at this point in the history
Rename `groups` to `capability_groups` in accordance with the schema.

refactor!: rename `group` to `capability_group` in export schema

feat: only export `related_score` when a sub-technique has an assigned score

fix: prefix single-digit days and months with `0` in accordance with the schema
  • Loading branch information
mikecarenzo authored Feb 7, 2024
1 parent ea8f2e8 commit b5ff4ac
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ export class UniversalSchemaMappingFileSerializer extends MappingFileSerializer
author : file.author,
contact : file.author_contact,
organization : file.author_organization,
creation_date : file.creation_date.toLocaleDateString("en-US"),
last_update : file.modified_date.toLocaleDateString("en-US"),
creation_date : file.creation_date.toLocaleDateString("es-pa"),
last_update : file.modified_date.toLocaleDateString("es-pa"),
mapping_types : file.mapping_types,
groups : file.mapping_groups
capability_groups : file.mapping_groups
},
mapping_objects
}
Expand Down Expand Up @@ -102,11 +102,11 @@ export class UniversalSchemaMappingFileSerializer extends MappingFileSerializer
references : obj.references,
comments : obj.comments ?? undefined,
mapping_type : obj.mapping_type,
group : obj.mapping_group ?? undefined,
capability_group : obj.mapping_group ?? undefined,
status : obj.mapping_status ?? undefined,
score_category : obj.score_category ?? undefined,
score_value : obj.score_value ?? undefined,
related_score : (/T[0-9]{4}/i.exec(obj.target_id ?? "") ?? [undefined])[0]
related_score : this.computeRelatedScore(obj)
}
}

Expand Down Expand Up @@ -141,6 +141,23 @@ export class UniversalSchemaMappingFileSerializer extends MappingFileSerializer
}
}

/**
* Computes a {@link MappingObjectExport}'s related score.
* @param obj
* The mapping object export.
* @returns
* The related score (if the object has one).
*/
private computeRelatedScore(obj: MappingObjectExport): string | undefined {
const hasScore = (obj.score_value ?? obj.score_category) !== null;
const technique = /(T[0-9]{4})\.[0-9]{3}/i.exec(obj.target_id ?? "");
if(hasScore && technique) {
return technique[1];
} else {
return undefined;
}
}


///////////////////////////////////////////////////////////////////////////
// 2. Deserialization ///////////////////////////////////////////////////
Expand Down Expand Up @@ -173,7 +190,7 @@ export class UniversalSchemaMappingFileSerializer extends MappingFileSerializer
creation_date : new Date(meta.creation_date),
modified_date : new Date(meta.last_update),
mapping_types : meta.mapping_types,
mapping_groups : meta.groups,
mapping_groups : meta.capability_groups,
mapping_statuses: {
"complete" : "Complete",
"in_progress" : "In Progress",
Expand Down Expand Up @@ -267,7 +284,7 @@ export class UniversalSchemaMappingFileSerializer extends MappingFileSerializer
references : obj.references ?? [],
comments : obj.comments ?? null,
mapping_type : obj.mapping_type ?? null,
mapping_group : obj.group ?? null,
mapping_group : obj.capability_group ?? null,
mapping_status : obj.status ?? "in_progress",
score_category : obj.score_category ?? null,
score_value : obj.score_value ?? null
Expand Down Expand Up @@ -395,7 +412,7 @@ type UniversalSchemaMappingFile = {
creation_date : string,
last_update : string,
mapping_types : UniversalSchemaMappingTypes,
groups : UniversalSchemaMappingGroups
capability_groups : UniversalSchemaMappingGroups
},
mapping_objects : UniversalSchemaMappingObject[]
}
Expand Down Expand Up @@ -434,7 +451,7 @@ type UniversalSchemaMappingObject = {
references : string[],
comments? : string,
mapping_type : string | null,
group? : string,
capability_group? : string,
status? : string
score_category? : string,
score_value? : string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export default defineComponent({
.mapping-object-header {
flex-shrink: 0;
display: grid;
grid-template-columns: 40px minmax(0, 1fr) 36px 225px 36px minmax(0, 1fr) 40px;
grid-template-columns: 40px minmax(0, 1fr) 36px 15.5% 36px minmax(0, 1fr) 40px;
align-items: center;
color: #c7c7c7;
height: 40px;
Expand Down

0 comments on commit b5ff4ac

Please sign in to comment.