-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRegistryParser.js
108 lines (91 loc) · 3.32 KB
/
RegistryParser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* Copyright (c) 2021 Lenze SE
* SPDX-License-Identifier: Apache-2.0
*/
class RegistryParser extends ParserBase {
constructor(registryPrinter) {
super();
/* general */
this.run = this.run.bind(this);
this.trimSuffixSlash = this.trimSuffixSlash.bind(this);
/* AAS Registry */
this.parseRegistryRaw = this.parseRegistryRaw.bind(this);
this.addURLToList = this.addURLToList.bind(this);
this.registryPrinter = registryPrinter;
this.AjaxHelper = new AjaxHelper();
/* Variables */
this.registryURL = "";
this.RegistryRoot = this.newTreeObject("RegistryRoot", null,
"AssetAdministrationShellRegistryRoot");
this.treeRoot = this.RegistryRoot;
this.aasStorageHandler = new AASWebStorageHandler();
}
run() {
var regURL = this.getQueryVariable("endpoint");
if (regURL) {
regURL = decodeURIComponent(regURL);
regURL = this.trimSuffixSlash(regURL);
this.aasStorageHandler.setCurrentRegistry(regURL);
}
// Set extra base URL
if (regURL != null) {
var registryURL = new URL(regURL); /*new URL(this.aasStorageHandler.getCurrentRegistry());*/
this.setRootURLS(this.RegistryRoot, registryURL, 2);
this.RegistryRoot.tURL = registryURL.href;/*this.aasStorageHandler.getCurrentRegistry()*/;
}
else
this.RegistryRoot.tURL = "";
this.getByURL(this.RegistryRoot,
this.RegistryRoot.tURL,
this.parseRegistryRaw,
this.setErrorRegistry);
}
addURLToList(URL) {
this.aasStorageHandler.addAASURL(URL, true);
}
trimSuffixSlash(URL) {
if (!URL.endsWith("/"))
return URL;
return URL.slice(0, - 1);
}
/* unbound for compound -> this */
setErrorRegistry(status) {
var URL = this.URL;
var object = this.object;
var that = this.parentObj;
if (status.status == 401) {
var error = that.newTreeObject("RegistryError", object,
"tError");
that.parseString("Could not retrieve the Registry", "Description",
error);
that.parseString(URL, "URL", error);
that.parseValue(status.status, "ErrorCode", error);
that.registryPrinter.printError(error, "");
return;
}
if (this.retry < 2) {
this.retry++;
this.parentObj.AjaxHelper.getJSON(this.URL,
this.onSuccess,
this.onError,
this);
return;
}
var error = that.newTreeObject("RegistryError", object,
"tError");
that.parseString("Could not retrieve the Registry", "Description", error);
that.parseString(URL, "URL", error);
if (status.status != 0)
that.parseValue(status.status, "ErrorCode", error);
that.registryPrinter.printError(error, "");
}
parseRegistryRaw(JSON) {
var RegistryJSON = JSON;
if (JSON.hasOwnProperty("entity"))
RegistryJSON = RegistryJSON.entity;
var registry = this.parseRegistry(RegistryJSON, this.RegistryRoot);
this.aasStorageHandler.writeAASMap();
console.log(registry);
this.registryPrinter.printRegistry(this.registryPrinter.rootElement, registry);
}
}