Skip to content

Commit

Permalink
Feature/fixed folders validation (#1213)
Browse files Browse the repository at this point in the history
* Add example json representing folder structure in docs

* Update model with optional fixed and margin attributes

* Adds first steps to build the map, missing transformation of coordinates

* Refactor improve performance by counting nodes and blacklisted nodes at the same time

* Refactor improve performance by removing one loop

* Fix typo in y properties

* Add coordinate transformation, map is finally visible, but not scalable yet

* Add edges to example json

* Refactor use values in line

* Add size increases based on margin

* Refactor abstract methods and improved readability

* Fix broken tests after changing the method header

* Remove margin since it's not required anymore

* Add snapshot test for fixed folders

* Fix incoming and outgoing edge points are now set correctly

* Fix root folder name should be set based on the root-name of the map

* Add API.md to document the changes for the cc.json-api

* Update api-versions for tests and files

* Presentation add example cc.json

* Presentation rename example cc.json

* Add validation for fixed folders, not finalized

* Add finalized validation
Fix nodes empty error

* Update collect errors again instead of throwing them instantly

* Update e2e test to use the error messages enum instead of plain strings

* Fix missing whitespace in test of dialog message

* Update rename fixed attributes

* Update snapshot since ids are no longer pre-decorated

* Update tests with renamed fixed attributes

* Refactor move static functions to helper file
Update jest.config to mock localStorage to test in IntelliJ

* Refactor convert class with static functions to exported objects with functions

* Refactor convert class with static functions to exported objects with functions

* Add no-else-return rule and fix errors

* Refactor use null propagation operator

* Update snapshots and remove unused snapshots

* Add eslint rule no-lonely-if and autofix errors

* Update visualization/app/codeCharta/util/treeMapGenerator.spec.ts

Co-authored-by: Ruben Bridgewater <ruben@bridgewater.de>

* Update visualization/app/codeCharta/util/fileHelper.ts

Co-authored-by: Ruben Bridgewater <ruben@bridgewater.de>

* Refactor rename isNodeToBeFlat to shouldNodeBeFlat

* Refactor use null coalescing to shorten code

* Refactor move shortcut return to the top to improve performance

* Update snapshot after renaming test

* Refactor rearrange function and add return statements to prevent obsolete calculations

* Refactor remove obsolete check in condition if attribute types are empty and added some more tests

* Add e2e test to ensure lower api versions are working without errors or warnings

* Refactor replace custom type KeyValuePair with Record<string, number>

* Update jsonschema

* Refactor replace _.cloneDeep with the rfdc library

* Update snapshot with new api version

* Add fixedPosition attribute of folders resulting in errors during validation after their name for easier debugging

* Fix outOfBounds-Check not checking for negative width and height

* Add another test to ensure the new out of bounds function is working

* Add print found api version when a warning is thrown

* Update visualization/app/codeCharta/util/fileValidator.ts

Co-authored-by: Ruben Bridgewater <ruben@bridgewater.de>

* Update remove individual titles and use a generic title for errors and warnings

* Refactor check if both nodes have the fixedPosition attribute before starting calculating overlaps

* Refactor remove obsolete .values() call

* Add found duplicate node to error message
Refactor use a more intuitive implementation to find duplicate nodes
Fix duplicate file in example

* Update snapshot with new file names

* Fix broken e2e test with wrong warning message

* Refactor use root instead of whole file as parameter to validate fixed folders

* Refactor reorder functions

* Revert "Refactor replace custom type KeyValuePair with Record<string, number>"

This reverts commit 061ec81.

* Update json schema with KeyValuePair instead of Record again

* Move API.md from visualization to root of project

* Add throw an error if we encountered a fixed folder and the api version is smaller than 1.2

Co-authored-by: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
NearW and BridgeAR authored Sep 11, 2020
1 parent 0360c32 commit a86e1f4
Show file tree
Hide file tree
Showing 23 changed files with 572 additions and 156 deletions.
32 changes: 32 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# API-Changelog

## 1.1

- An additional optional property `edges` has been added to the `cc.json`
- Defines an array of edges between buildings
- Use SCMLogParser to generate edges

```ts
export interface Edge {
fromNodeName: string
toNodeName: string
attributes: KeyValuePair
}
```

## 1.2

- An additional optional property `fixed` has been added to the `cc.json`
- Property can be set to direct children of the root-folder
- Define `x` and `y` as the top-left corner of the folder
- Define `width` and `height` for the length in x and y-direction
- Folders can't overlap and must be defined in range of `[0-100]`

```ts
export interface Fixed {
x: number
y: number
width: number
height: number
}
```
25 changes: 23 additions & 2 deletions analysis/tools/ValidationTool/src/main/resources/cc.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
},
"type": "object"
},
"fixedPosition": {
"$ref": "#/definitions/FixedPosition"
},
"id": {
"type": "number"
},
Expand Down Expand Up @@ -165,6 +168,24 @@
"required": ["apiVersion", "nodes", "projectName"],
"type": "object"
},
"FixedPosition": {
"properties": {
"height": {
"type": "number"
},
"left": {
"type": "number"
},
"top": {
"type": "number"
},
"width": {
"type": "number"
}
},
"required": ["height", "left", "top", "width"],
"type": "object"
},
"KeyValuePair": {
"additionalProperties": {
"type": "number"
Expand Down Expand Up @@ -210,7 +231,7 @@
"type": "object"
}
],
"minItems": 1,
"minItems": 0,
"type": "array"
},
"nodes": {
Expand All @@ -234,7 +255,7 @@
"type": "object"
}
],
"minItems": 1,
"minItems": 0,
"type": "array"
}
},
Expand Down
1 change: 1 addition & 0 deletions visualization/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module.exports = {
"@typescript-eslint/no-unused-vars": ["error"],
"object-shorthand": ["error", "always"],
"no-else-return": ["error"],
"no-lonely-if": ["error"],

// Do not apply inappropriate rules below
"@typescript-eslint/no-use-before-define":
Expand Down
2 changes: 1 addition & 1 deletion visualization/app/codeCharta/assets/sample1.cc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"projectName": "Sample Project with Edges",
"apiVersion": "1.1",
"apiVersion": "1.2",
"nodes": [
{
"name": "root",
Expand Down
2 changes: 1 addition & 1 deletion visualization/app/codeCharta/assets/sample2.cc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"projectName": "Sample Project",
"apiVersion": "1.1",
"apiVersion": "1.2",
"nodes": [
{
"name": "root",
Expand Down
2 changes: 1 addition & 1 deletion visualization/app/codeCharta/assets/sample3.cc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"projectName": "Sample Project",
"apiVersion": "1.1",
"apiVersion": "1.2",
"nodes": [
{
"name": "root",
Expand Down
3 changes: 2 additions & 1 deletion visualization/app/codeCharta/codeCharta.api.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export enum ExportBlacklistType {
export enum APIVersions {
ZERO_POINT_ONE = "0.1",
ONE_POINT_ZERO = "1.0",
ONE_POINT_ONE = "1.1"
ONE_POINT_ONE = "1.1",
ONE_POINT_TWO = "1.2"
}

export interface ExportScenario {
Expand Down
11 changes: 4 additions & 7 deletions visualization/app/codeCharta/codeCharta.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getCCFiles, isSingleState } from "./model/files/files.helper"
import { DialogService } from "./ui/dialog/dialog.service"
import { CCValidationResult, ERROR_MESSAGES } from "./util/fileValidator"
import { setNodeMetricData } from "./state/store/metricData/nodeMetricData/nodeMetricData.actions"
import packageJson from "../../package.json"
import { clone } from "./util/clone"

describe("codeChartaService", () => {
Expand Down Expand Up @@ -52,7 +53,7 @@ describe("codeChartaService", () => {

describe("loadFiles", () => {
const expected: CCFile = {
fileMeta: { apiVersion: "1.1", fileName, projectName: "Sample Map" },
fileMeta: { apiVersion: packageJson.codecharta.apiVersion, fileName, projectName: "Sample Map" },
map: {
attributes: {},
isExcluded: false,
Expand Down Expand Up @@ -169,8 +170,7 @@ describe("codeChartaService", () => {

it("should show error on invalid file", () => {
const expectedError: CCValidationResult = {
title: ERROR_MESSAGES.fileIsInvalid.title,
error: [ERROR_MESSAGES.fileIsInvalid.message],
error: [ERROR_MESSAGES.fileIsInvalid],
warning: []
}

Expand All @@ -182,8 +182,7 @@ describe("codeChartaService", () => {

it("should show error on a random string", () => {
const expectedError: CCValidationResult = {
title: ERROR_MESSAGES.apiVersionIsInvalid.title,
error: [ERROR_MESSAGES.apiVersionIsInvalid.message],
error: [ERROR_MESSAGES.apiVersionIsInvalid],
warning: []
}

Expand All @@ -195,7 +194,6 @@ describe("codeChartaService", () => {

it("should show error if a file is missing a required property", () => {
const expectedError: CCValidationResult = {
title: ERROR_MESSAGES.validationError.title,
error: ["Required error: should have required property 'projectName'"],
warning: []
}
Expand Down Expand Up @@ -224,7 +222,6 @@ describe("codeChartaService", () => {

it("should break the loop after the first invalid file was validated", () => {
const expectedError: CCValidationResult = {
title: ERROR_MESSAGES.validationError.title,
error: ["Required error: should have required property 'projectName'"],
warning: []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ export const fileWithFixedFolders: ExportCCFile = {
attributes: {},
children: [
{
name: "children_5",
name: "children_6",
type: NodeType.FILE,
attributes: {
custom_metric: 4
},
children: []
},
{
name: "children_6",
name: "children_7",
type: NodeType.FILE,
attributes: {
custom_metric: 0
Expand All @@ -111,15 +111,15 @@ export const fileWithFixedFolders: ExportCCFile = {
attributes: {},
children: [
{
name: "children_7",
name: "children_8",
type: NodeType.FILE,
attributes: {
custom_metric: 20
},
children: []
},
{
name: "children_8",
name: "children_9",
type: NodeType.FILE,
attributes: {
custom_metric: 5
Expand All @@ -140,15 +140,15 @@ export const fileWithFixedFolders: ExportCCFile = {
attributes: {},
children: [
{
name: "children_9",
name: "children_10",
type: NodeType.FILE,
attributes: {
custom_metric: 10
},
children: []
},
{
name: "children_10",
name: "children_11",
type: NodeType.FILE,
attributes: {
custom_metric: 0
Expand All @@ -169,15 +169,15 @@ export const fileWithFixedFolders: ExportCCFile = {
attributes: {},
children: [
{
name: "children_11",
name: "children_12",
type: NodeType.FILE,
attributes: {
custom_metric: 1
},
children: []
},
{
name: "children_12",
name: "children_13",
type: NodeType.FILE,
attributes: {
custom_metric: 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"projectName": "Sample Project with different edges",
"apiVersion": "1.1",
"apiVersion": "1.2",
"nodes": [
{
"name": "root",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"projectName": "Sample Project with Edges",
"apiVersion": "1.1",
"nodes": [
{
"name": "root",
"type": "Folder",
"attributes": {},
"children": [
{
"name": "sample1OnlyLeaf.scss",
"type": "File",
"attributes": {
"rloc": 400,
"functions": 10,
"mcc": 100,
"pairingRate": 32,
"avgCommits": 17
},
"link": "http://www.google.de"
},
{
"name": "bigLeaf.ts",
"type": "File",
"attributes": {
"rloc": 100,
"functions": 10,
"mcc": 1,
"pairingRate": 77,
"avgCommits": 56
},
"link": "http://www.google.de"
},
{
"name": "ParentLeaf",
"type": "Folder",
"attributes": {},
"children": [
{
"name": "smallLeaf.html",
"type": "File",
"attributes": {
"rloc": 30,
"functions": 100,
"mcc": 100,
"pairingRate": 60,
"avgCommits": 51
}
},
{
"name": "otherSmallLeaf.ts",
"type": "File",
"attributes": {
"rloc": 70,
"functions": 1000,
"mcc": 10,
"pairingRate": 65,
"avgCommits": 22
}
}
]
}
]
}
],
"edges": [
{
"fromNodeName": "/root/bigLeaf.ts",
"toNodeName": "/root/ParentLeaf/smallLeaf.html",
"attributes": {
"pairingRate": 89,
"avgCommits": 34
}
},
{
"fromNodeName": "/root/sample1OnlyLeaf.scss",
"toNodeName": "/root/ParentLeaf/smallLeaf.html",
"attributes": {
"pairingRate": 32,
"avgCommits": 17
}
},
{
"fromNodeName": "/root/ParentLeaf/otherSmallLeaf.ts",
"toNodeName": "/root/bigLeaf.ts",
"attributes": {
"pairingRate": 65,
"avgCommits": 22
}
}
],
"attributeTypes": {
"nodes": { "rloc": "absolute", "functions": "absolute", "mcc": "absolute", "pairingRate": "relative" },
"edges": { "pairingRate": "relative", "avgCommits": "absolute" }
}
}
4 changes: 2 additions & 2 deletions visualization/app/codeCharta/ui/dialog/dialog.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ export class DialogService {

const htmlMessage = this.buildHtmlMessage(warningSymbol, validationResult.warning)

this.showErrorDialog(htmlMessage, validationResult.title)
this.showErrorDialog(htmlMessage, "Validation Warning")
}

public showValidationErrorDialog(validationResult: CCValidationResult) {
const errorSymbol = '<i class="fa fa-exclamation-circle"></i> '

const htmlMessage = this.buildHtmlMessage(errorSymbol, validationResult.error)

this.showErrorDialogAndOpenFileChooser(htmlMessage, validationResult.title)
this.showErrorDialogAndOpenFileChooser(htmlMessage, "Validation Error")
}

private buildHtmlMessage(symbol: string, validationResult: string[]): string {
Expand Down
Loading

0 comments on commit a86e1f4

Please sign in to comment.