Revize 26d3ab59
Přidáno uživatelem Pavel Fidranský před téměř 6 roky(ů)
sources/src/main/webapp/imiger-raw-input-schema.json | ||
---|---|---|
1 |
{ |
|
2 |
"$schema": "http://json-schema.org/draft-07/schema#", |
|
3 |
"$id": "http://example.com/product.schema.json", |
|
4 |
"title": "IMiGEr - raw input schema", |
|
5 |
"description": "Diagram displayable by IMiGEr tool using raw input", |
|
6 |
"type": "object", |
|
7 |
"properties": { |
|
8 |
"attributeTypes": { |
|
9 |
"type": "array", |
|
10 |
"items": { |
|
11 |
"type": "object", |
|
12 |
"properties": { |
|
13 |
"dataType": { |
|
14 |
"type": "string" |
|
15 |
}, |
|
16 |
"name": { |
|
17 |
"type": "string" |
|
18 |
}, |
|
19 |
"text": { |
|
20 |
"type": "string" |
|
21 |
} |
|
22 |
}, |
|
23 |
"required": [ "dataType", "name" ] |
|
24 |
}, |
|
25 |
"minItems": 1, |
|
26 |
"uniqueItems": true |
|
27 |
}, |
|
28 |
"edgeArchetypes": { |
|
29 |
"type": "array", |
|
30 |
"items": { |
|
31 |
"type": "object", |
|
32 |
"properties": { |
|
33 |
"name": { |
|
34 |
"type": "string" |
|
35 |
}, |
|
36 |
"text": { |
|
37 |
"type": "string" |
|
38 |
} |
|
39 |
}, |
|
40 |
"required": [ "name" ] |
|
41 |
}, |
|
42 |
"minItems": 1, |
|
43 |
"uniqueItems": true |
|
44 |
}, |
|
45 |
"vertexArchetypes": { |
|
46 |
"type": "array", |
|
47 |
"items": { |
|
48 |
"type": "object", |
|
49 |
"properties": { |
|
50 |
"icon": { |
|
51 |
"type": "string" |
|
52 |
}, |
|
53 |
"name": { |
|
54 |
"type": "string" |
|
55 |
}, |
|
56 |
"text": { |
|
57 |
"type": "string" |
|
58 |
} |
|
59 |
}, |
|
60 |
"required": [ "name" ] |
|
61 |
}, |
|
62 |
"minItems": 1, |
|
63 |
"uniqueItems": true |
|
64 |
}, |
|
65 |
"vertices": { |
|
66 |
"type": "array", |
|
67 |
"items": { |
|
68 |
"type": "object", |
|
69 |
"properties": { |
|
70 |
"archetype": { |
|
71 |
"type": "integer", |
|
72 |
"minimum": 0 |
|
73 |
}, |
|
74 |
"attributes": { |
|
75 |
"type": "array", |
|
76 |
"items": { |
|
77 |
"type": "array", |
|
78 |
"minItems": 2, |
|
79 |
"maxItems": 2 |
|
80 |
} |
|
81 |
}, |
|
82 |
"id": { |
|
83 |
"type": "integer" |
|
84 |
}, |
|
85 |
"name": { |
|
86 |
"type": "string" |
|
87 |
}, |
|
88 |
"text": { |
|
89 |
"type": "string" |
|
90 |
}, |
|
91 |
"position": { |
|
92 |
"type": "object", |
|
93 |
"properties": { |
|
94 |
"x": { |
|
95 |
"type": "number" |
|
96 |
}, |
|
97 |
"y": { |
|
98 |
"type": "number" |
|
99 |
} |
|
100 |
}, |
|
101 |
"required": [ "x", "y" ] |
|
102 |
} |
|
103 |
}, |
|
104 |
"required": [ "id", "name" ] |
|
105 |
}, |
|
106 |
"minItems": 1, |
|
107 |
"uniqueItems": true |
|
108 |
}, |
|
109 |
"edges": { |
|
110 |
"type": "array", |
|
111 |
"items": { |
|
112 |
"type": "object", |
|
113 |
"properties": { |
|
114 |
"subedgeInfo": { |
|
115 |
"type": "array", |
|
116 |
"items": { |
|
117 |
"type": "object", |
|
118 |
"properties": { |
|
119 |
"id": { |
|
120 |
"type": "integer" |
|
121 |
}, |
|
122 |
"archetype": { |
|
123 |
"type": "integer", |
|
124 |
"minimum": 0 |
|
125 |
}, |
|
126 |
"attributes": { |
|
127 |
"type": "array", |
|
128 |
"items": { |
|
129 |
"type": "array", |
|
130 |
"minItems": 2, |
|
131 |
"maxItems": 2 |
|
132 |
} |
|
133 |
} |
|
134 |
}, |
|
135 |
"required": [ "id", "archetype", "attributes" ] |
|
136 |
} |
|
137 |
}, |
|
138 |
"id": { |
|
139 |
"type": "integer" |
|
140 |
}, |
|
141 |
"text": { |
|
142 |
"type": "string" |
|
143 |
}, |
|
144 |
"from": { |
|
145 |
"type": "integer" |
|
146 |
}, |
|
147 |
"to": { |
|
148 |
"type": "integer" |
|
149 |
} |
|
150 |
}, |
|
151 |
"required": [ "subedgeInfo", "id", "from", "to" ] |
|
152 |
}, |
|
153 |
"minItems": 1, |
|
154 |
"uniqueItems": true |
|
155 |
}, |
|
156 |
"possibleEnumValues": { |
|
157 |
"type": "object" |
|
158 |
}, |
|
159 |
"groups": { |
|
160 |
"type": "array", |
|
161 |
"items": { |
|
162 |
"type": "object", |
|
163 |
"properties": { |
|
164 |
"id": { |
|
165 |
"type": "integer" |
|
166 |
}, |
|
167 |
"name": { |
|
168 |
"type": "string" |
|
169 |
}, |
|
170 |
"verticesId": { |
|
171 |
"type": "array", |
|
172 |
"items": { |
|
173 |
"type": "integer" |
|
174 |
}, |
|
175 |
"minItems": 1 |
|
176 |
}, |
|
177 |
"verticesEdgeFromId": { |
|
178 |
"type": "array", |
|
179 |
"items": { |
|
180 |
"type": "integer" |
|
181 |
} |
|
182 |
}, |
|
183 |
"verticesEdgeToId": { |
|
184 |
"type": "array", |
|
185 |
"items": { |
|
186 |
"type": "integer" |
|
187 |
} |
|
188 |
}, |
|
189 |
"position": { |
|
190 |
"type": "object", |
|
191 |
"properties": { |
|
192 |
"x": { |
|
193 |
"type": "number" |
|
194 |
}, |
|
195 |
"y": { |
|
196 |
"type": "number" |
|
197 |
} |
|
198 |
}, |
|
199 |
"required": [ "x", "y" ] |
|
200 |
} |
|
201 |
}, |
|
202 |
"required": [ "id", "name", "verticesId" ] |
|
203 |
}, |
|
204 |
"uniqueItems": true |
|
205 |
}, |
|
206 |
"sideBar": { |
|
207 |
"type": "array", |
|
208 |
"items": { |
|
209 |
"type": "object", |
|
210 |
"properties": { |
|
211 |
"id": { |
|
212 |
"type": "string", |
|
213 |
"pattern": "^(group|vertex)-[0-9]+$" |
|
214 |
}, |
|
215 |
"isIconsDisplayed": { |
|
216 |
"type": "boolean" |
|
217 |
} |
|
218 |
}, |
|
219 |
"required": [ "id", "isIconsDisplayed" ] |
|
220 |
}, |
|
221 |
"uniqueItems": true |
|
222 |
}, |
|
223 |
"highlightedVertex": { |
|
224 |
"type": "string" |
|
225 |
}, |
|
226 |
"highlightedEdge": { |
|
227 |
"type": "string" |
|
228 |
} |
|
229 |
}, |
|
230 |
"required": [ "attributeTypes", "edgeArchetypes", "vertexArchetypes", "vertices", "edges", "possibleEnumValues", "groups", "sideBar", "highlightedVertex", "highlightedEdge" ] |
|
231 |
} |
sources/src/main/webapp/js/errors/ajvValidationError.js | ||
---|---|---|
1 |
/** |
|
2 |
* Error thrown when AJV JSON validation fails. |
|
3 |
*/ |
|
4 |
class AJVValidationError extends Error { |
|
5 |
constructor(message, errors) { |
|
6 |
super(message); |
|
7 |
this.name = new.target.name; |
|
8 |
this.errors = errors; |
|
9 |
} |
|
10 |
} |
sources/src/main/webapp/js/services/graphLoader.js | ||
---|---|---|
1 | 1 |
class GraphLoader { |
2 |
/** |
|
3 |
* @constructor |
|
4 |
*/ |
|
5 |
constructor() { |
|
6 |
this._ajv = new Ajv(); |
|
7 |
} |
|
2 | 8 |
|
3 | 9 |
/** |
4 | 10 |
* Loads a new graph using graph data passed as parameters. |
5 | 11 |
* @param {object} data Data of the graph. |
6 |
* @throws {InvalidArgumentError} Thrown when either graph data are incomplete.
|
|
12 |
* @throws {AJVValidationError} Thrown when graph data are incomplete.
|
|
7 | 13 |
*/ |
8 | 14 |
run(data) { |
9 |
if (Utils.isUndefined(data.vertices) || Utils.isUndefined(data.edges)) { |
|
10 |
throw new InvalidArgumentError('Invalid data.'); |
|
15 |
let isValid = this._ajv.validate(GraphLoader.rawInputSchema, data); |
|
16 |
if (isValid === false) { |
|
17 |
throw new AJVValidationError(this._ajv.errorsText(), this._ajv.errors); |
|
11 | 18 |
} |
12 | 19 |
|
13 | 20 |
const canvasSize = ((data.vertices.length * 75) / Math.round(Math.sqrt(data.vertices.length))) + 1000; |
... | ... | |
190 | 197 |
} |
191 | 198 |
} |
192 | 199 |
|
200 |
GraphLoader.rawInputSchema = JSON.parse(document.getElementById('imigerRawInputSchema').textContent); |
sources/src/main/webapp/js/showGraphApp.js | ||
---|---|---|
172 | 172 |
console.error(error); |
173 | 173 |
alert('Something went wrong. Check console for more details.'); |
174 | 174 |
} |
175 |
|
|
176 |
} else if (error instanceof AJVValidationError) { |
|
177 |
console.error(error); |
|
178 |
alert('Invalid input data: ' + error.message + '. Check console for more details.'); |
|
179 |
|
|
175 | 180 |
} else { |
176 | 181 |
console.error(error); |
177 | 182 |
alert('Something went wrong. Check console for more details.'); |
sources/src/main/webapp/package-lock.json | ||
---|---|---|
4 | 4 |
"lockfileVersion": 1, |
5 | 5 |
"requires": true, |
6 | 6 |
"dependencies": { |
7 |
"ajv": { |
|
8 |
"version": "6.5.4", |
|
9 |
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.5.4.tgz", |
|
10 |
"integrity": "sha512-4Wyjt8+t6YszqaXnLDfMmG/8AlO5Zbcsy3ATHncCzjW/NoPzAId8AK6749Ybjmdt+kUY1gP60fCu46oDxPv/mg==", |
|
11 |
"requires": { |
|
12 |
"fast-deep-equal": "^2.0.1", |
|
13 |
"fast-json-stable-stringify": "^2.0.0", |
|
14 |
"json-schema-traverse": "^0.4.1", |
|
15 |
"uri-js": "^4.2.2" |
|
16 |
} |
|
17 |
}, |
|
7 | 18 |
"babylon": { |
8 | 19 |
"version": "7.0.0-beta.19", |
9 | 20 |
"resolved": "https://registry.npmjs.org/babylon/-/babylon-7.0.0-beta.19.tgz", |
... | ... | |
31 | 42 |
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", |
32 | 43 |
"dev": true |
33 | 44 |
}, |
45 |
"fast-deep-equal": { |
|
46 |
"version": "2.0.1", |
|
47 |
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz", |
|
48 |
"integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=" |
|
49 |
}, |
|
50 |
"fast-json-stable-stringify": { |
|
51 |
"version": "2.0.0", |
|
52 |
"resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", |
|
53 |
"integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=" |
|
54 |
}, |
|
34 | 55 |
"graceful-fs": { |
35 | 56 |
"version": "4.1.11", |
36 | 57 |
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", |
... | ... | |
71 | 92 |
"underscore": "~1.8.3" |
72 | 93 |
} |
73 | 94 |
}, |
95 |
"json-schema-traverse": { |
|
96 |
"version": "0.4.1", |
|
97 |
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", |
|
98 |
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" |
|
99 |
}, |
|
74 | 100 |
"klaw": { |
75 | 101 |
"version": "2.0.0", |
76 | 102 |
"resolved": "https://registry.npmjs.org/klaw/-/klaw-2.0.0.tgz", |
... | ... | |
101 | 127 |
"minimist": "0.0.8" |
102 | 128 |
} |
103 | 129 |
}, |
130 |
"punycode": { |
|
131 |
"version": "2.1.1", |
|
132 |
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", |
|
133 |
"integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" |
|
134 |
}, |
|
104 | 135 |
"requizzle": { |
105 | 136 |
"version": "0.2.1", |
106 | 137 |
"resolved": "https://registry.npmjs.org/requizzle/-/requizzle-0.2.1.tgz", |
... | ... | |
168 | 199 |
} |
169 | 200 |
} |
170 | 201 |
}, |
202 |
"uri-js": { |
|
203 |
"version": "4.2.2", |
|
204 |
"resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", |
|
205 |
"integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==", |
|
206 |
"requires": { |
|
207 |
"punycode": "^2.1.0" |
|
208 |
} |
|
209 |
}, |
|
171 | 210 |
"xmlcreate": { |
172 | 211 |
"version": "1.0.2", |
173 | 212 |
"resolved": "https://registry.npmjs.org/xmlcreate/-/xmlcreate-1.0.2.tgz", |
sources/src/main/webapp/package.json | ||
---|---|---|
17 | 17 |
"jsdoc": "^3.5.5" |
18 | 18 |
}, |
19 | 19 |
"dependencies": { |
20 |
"ajv": "^6.5.4", |
|
20 | 21 |
"html-tags": "^2.0.0", |
21 | 22 |
"save-svg-as-png": "^1.4.6", |
22 | 23 |
"spin.js": "^4.0.0", |
sources/src/main/webapp/showGraph.jsp | ||
---|---|---|
31 | 31 |
|
32 | 32 |
<script id="htmlTags" type="application/json"><%@ include file="node_modules/html-tags/html-tags.json" %></script> |
33 | 33 |
<script id="svgTags" type="application/json"><%@ include file="node_modules/svg-tags/lib/svg-tags.json" %></script> |
34 |
<script id="imigerRawInputSchema" type="application/json"><%@ include file="imiger-raw-input-schema.json" %></script> |
|
34 | 35 |
|
36 |
<script src="node_modules/ajv/dist/ajv.min.js"></script> |
|
35 | 37 |
<script src="node_modules/save-svg-as-png/lib/saveSvgAsPng.js"></script> |
36 | 38 |
|
37 | 39 |
<script src="js/components/generic/modalWindow.js"></script> |
... | ... | |
61 | 63 |
<script src="js/components/vertexPopover.js"></script> |
62 | 64 |
<script src="js/components/viewport.js"></script> |
63 | 65 |
|
66 |
<script src="js/errors/ajvValidationError.js"></script> |
|
64 | 67 |
<script src="js/errors/httpError.js"></script> |
65 | 68 |
<script src="js/errors/invalidArgumentError.js"></script> |
66 | 69 |
|
Také k dispozici: Unified diff
input data are validated against JSON Schema with AJV