Skip to content

Commit cf2556e

Browse files
authored
Merge pull request #121 from dfpc-coe/contentResource
Mission Change - Content Resource
2 parents 9cb1110 + 2d4d965 commit cf2556e

7 files changed

Lines changed: 663 additions & 460 deletions

File tree

lib/parser.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ export class CoTParser {
5555
if (opts.flow === undefined) opts.flow = true;
5656

5757
checkXML(cot.raw);
58-
if (checkXML.errors) throw new Err(400, null, `${checkXML.errors[0].message} (${checkXML.errors[0].instancePath})`);
58+
if (checkXML.errors) {
59+
throw new Err(400, null, `${checkXML.errors[0].message} (${checkXML.errors[0].instancePath})`);
60+
}
5961

6062
if (opts.flow) {
6163
if (!cot.raw.event.detail) cot.raw.event.detail = {};

lib/parser/to_geojson.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
Feature,
55
Polygon,
66
FeaturePropertyMission,
7+
FeaturePropertyMissionChange,
78
FeaturePropertyMissionLayer,
89
} from '../types/feature.js';
910
import type {
@@ -219,20 +220,40 @@ export async function to_geojson(cot: CoT): Promise<Static<typeof Feature>> {
219220

220221
mission.missionChanges = []
221222
for (const change of changes) {
222-
mission.missionChanges.push({
223-
contentUid: change.MissionChange.contentUid._text,
223+
const mc: Static<typeof FeaturePropertyMissionChange> = {
224+
contentUid: change.MissionChange.contentUid ? change.MissionChange.contentUid._text : undefined,
224225
creatorUid: change.MissionChange.creatorUid._text,
225226
isFederatedChange: change.MissionChange.isFederatedChange._text,
226227
missionName: change.MissionChange.missionName._text,
227228
timestamp: change.MissionChange.timestamp._text,
228229
type: change.MissionChange.type._text,
229-
details: {
230+
};
231+
232+
if (change.MissionChange.contentResource) {
233+
const cr = change.MissionChange.contentResource;
234+
mc.contentResource = {
235+
expiration: cr.expiration._text,
236+
filename: cr.filename._text,
237+
hash: cr.hash._text,
238+
name: cr.name._text,
239+
size: parseInt(cr.size._text),
240+
submissionTime: cr.submissionTime._text,
241+
submitter: cr.submitter._text,
242+
tool: cr.tool._text,
243+
uid: cr.uid._text,
244+
};
245+
}
246+
247+
if (change.MissionChange.details) {
248+
mc.details = {
230249
...change.MissionChange.details._attributes,
231250
...change.MissionChange.details.location
232251
? change.MissionChange.details.location._attributes
233252
: {}
234-
}
235-
})
253+
};
254+
}
255+
256+
mission.missionChanges.push(mc)
236257
}
237258
}
238259

lib/types/feature.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,30 @@ export const FeaturePropertyMissionLayer = Type.Object({
3939
})
4040

4141
export const FeaturePropertyMissionChange = Type.Object({
42-
contentUid: Type.String(),
42+
contentUid: Type.Optional(Type.String()),
4343
creatorUid: Type.String(),
4444
isFederatedChange: Type.Boolean(),
4545
missionName: Type.String(),
4646
timestamp: Type.String(),
4747
type: Type.String(),
48-
details: Type.Object({
48+
contentResource: Type.Optional(Type.Object({
49+
expiration: Type.String(),
50+
filename: Type.String(),
51+
hash: Type.String(),
52+
name: Type.String(),
53+
size: Type.Integer(),
54+
submissionTime: Type.String(),
55+
submitter: Type.String(),
56+
tool: Type.String(),
57+
uid: Type.String(),
58+
})),
59+
details: Type.Optional(Type.Object({
4960
type: Type.String(),
5061
callsign: Type.String(),
5162
color: Type.String(),
5263
lat: Type.String(),
5364
lon: Type.String()
54-
})
65+
}))
5566
})
5667

5768
export const FeaturePropertyMission = Type.Object({

lib/types/types.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ export const GenericTextBoolean = Type.Object({
208208
_text: Type.Boolean()
209209
})
210210

211+
export const GenericTextInteger = Type.Object({
212+
_text: Type.Integer()
213+
})
214+
215+
211216
export const TrackAttributes = Type.Object({
212217
speed: Type.Optional(Type.String()),
213218
course: Type.Optional(Type.String()),
@@ -322,13 +327,27 @@ export const MissionChangeDetails = Type.Object({
322327
}))
323328
})
324329

330+
export const MissionChangeContentResource = Type.Object({
331+
expiration: GenericText,
332+
filename: GenericText,
333+
hash: GenericText,
334+
name: GenericText,
335+
size: GenericTextInteger,
336+
submissionTime: GenericText,
337+
submitter: GenericText,
338+
tool: GenericText,
339+
uid: GenericText
340+
});
341+
325342
export const MissionChange = Type.Object({
326343
contentUid: Type.Optional(GenericText),
327344
creatorUid: GenericOptionalText,
328345
isFederatedChange: GenericTextBoolean,
329346
missionName: GenericText,
347+
missionGuid: Type.Optional(GenericText),
330348
timestamp: GenericText,
331349
type: GenericText,
350+
contentResource: Type.Optional(MissionChangeContentResource),
332351
details: Type.Optional(MissionChangeDetails)
333352
})
334353

0 commit comments

Comments
 (0)