-
Notifications
You must be signed in to change notification settings - Fork 353
/
WebProcessingServiceCapabilities.ts
194 lines (168 loc) · 5.44 KB
/
WebProcessingServiceCapabilities.ts
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import i18next from "i18next";
import filterOutUndefined from "../../../Core/filterOutUndefined";
import { isJsonObject, isJsonString } from "../../../Core/Json";
import loadXML from "../../../Core/loadXML";
import TerriaError, { networkRequestError } from "../../../Core/TerriaError";
import xml2json from "../../../ThirdParty/xml2json";
import {
OnlineResource,
OwsKeywordList,
parseOnlineResource,
parseOwsKeywordList
} from "./OwsInterfaces";
type Capabilities = {
ServiceIdentification: ServiceIdentification;
ServiceProvider?: ServiceProvider;
ProcessOfferings: ProcessOfferings;
};
export type ProcessOfferings = Process[];
export type Process = {
/** Process identifier */
Identifier: string;
/** Title of the process. */
Title?: string;
/** Longer narative description of the process. */
Abstract?: string;
};
export interface ServiceIdentification {
/** Title of the service. */
readonly Title?: string;
/** Longer narative description of the service. */
readonly Abstract?: string /** Fees for this service */;
/** Fees for this service */
readonly Fees?: string;
/** Access contraints for this service. */
readonly AccessConstraints?: string;
/** List of keywords or keyword phrases to help catalog searching. */
readonly Keywords?: OwsKeywordList;
readonly ServiceType: string;
readonly ServiceTypeVersion: string[];
}
export interface ServiceProvider {
/** A unique identifier for service provider organization. */
readonly ProviderName?: string;
/** Reference to the most relevant web site of the service provider. */
readonly ProviderSite?: OnlineResource;
}
export default class WebProcessingServiceCapabilities {
constructor(
readonly capabilitiesXml: XMLDocument,
readonly capabilities: Capabilities
) {}
static fromUrl(url: string): Promise<WebProcessingServiceCapabilities> {
return Promise.resolve(loadXML(url)).then(function (capabilitiesXml) {
const capabilities = parseCapabilities(xml2json(capabilitiesXml));
if (capabilitiesXml === undefined || capabilities === undefined) {
throw networkRequestError({
title: i18next.t(
"models.webProcessingServiceCatalogGroup.invalidCapabilitiesTitle"
),
message: i18next.t(
"models.webProcessingServiceCatalogGroup.invalidCapabilitiesMessage",
{
url: url
}
)
});
}
return new WebProcessingServiceCapabilities(
capabilitiesXml,
capabilities
);
});
}
get ServiceIdentification(): ServiceIdentification {
return this.capabilities.ServiceIdentification;
}
get ServiceProvider(): ServiceProvider | undefined {
return this.capabilities.ServiceProvider;
}
get ProcessOfferings(): ProcessOfferings | undefined {
return this.capabilities.ProcessOfferings;
}
}
function parseCapabilities(json: any): Capabilities | undefined {
if (!isJsonObject(json)) return;
const ServiceIdentification = parseServiceIdentification(
json.ServiceIdentification
);
if (ServiceIdentification === undefined) return;
const ServiceProvider = parseServiceProvider(json.ServiceProvider);
const ProcessOfferings = parseProcessOfferings(json.ProcessOfferings) ?? [];
return {
ServiceIdentification,
ServiceProvider,
ProcessOfferings
};
}
function parseServiceIdentification(
json: any
): ServiceIdentification | undefined {
if (!isJsonObject(json)) return;
const ServiceType = isJsonString(json.ServiceType)
? json.ServiceType
: undefined;
const ServiceTypeVersion = isJsonString(json.ServiceTypeVersion)
? [json.ServiceTypeVersion]
: Array.isArray(json.ServiceTypeVersion)
? filterOutUndefined(
json.ServiceTypeVersion.map((s) => (isJsonString(s) ? s : undefined))
)
: undefined;
if (
ServiceType === undefined ||
ServiceTypeVersion === undefined ||
ServiceTypeVersion.length === 0
) {
return;
}
const Title = isJsonString(json.Title) ? json.Title : undefined;
const Abstract = isJsonString(json.Abstract) ? json.Abstract : undefined;
const Fees = isJsonString(json.Fees) ? json.Fees : undefined;
const AccessConstraints = isJsonString(json.AccessConstraints)
? json.AccessConstraints
: undefined;
const Keywords = parseOwsKeywordList(json);
return {
ServiceType,
ServiceTypeVersion,
Title,
Abstract,
Fees,
AccessConstraints,
Keywords
};
}
function parseServiceProvider(json: any): ServiceProvider | undefined {
if (!isJsonObject(json)) return;
const ProviderName = isJsonString(json.ProviderName)
? json.ProviderName
: undefined;
const ProviderSite = parseOnlineResource(json.OnlineResource);
return {
ProviderName,
ProviderSite
};
}
function parseProcessOfferings(json: any): Process[] | undefined {
if (!isJsonObject(json)) return undefined;
const processes: any[] = Array.isArray(json.Process)
? json.Process
: isJsonObject(json.Process)
? [json.Process]
: [];
const ProcessOfferings = filterOutUndefined(processes.map(parseProcess));
return ProcessOfferings;
}
function parseProcess(json: any): Process | undefined {
if (!isJsonObject(json)) return;
if (!isJsonString(json.Identifier)) return;
const Identifier = json.Identifier;
const Title = isJsonString(json.Title) ? json.Title : undefined;
const Abstract = isJsonString(json.Abstract) ? json.Abstract : undefined;
return {
Identifier,
Title,
Abstract
};
}