UNPKG

@ngageoint/mage.arcgis.service

Version:

A mage service plugin that synchronizes mage observations to a configured ArcGIS feature layer.

102 lines 4.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EventDeletionHandler = void 0; /** * Class that handles deleting observations from an arc server for any deleted events. */ class EventDeletionHandler { /** * Constructor. * @param {Console} console Used to log messages. * @param {ArcGISPluginConfig} config The plugin configuration. */ constructor(console, config) { this._currentEventIds = new Map(); this._console = console; this._config = config; } updateConfig(newConfig) { this._config = newConfig; } /** * * @param {MageEventAttrs[]} activeEvents The current set of active events. * @param {FeatureLayerProcessor[]} layerProcessors The different layer processors currently syncing arc layers with mage data. * @param {boolean} firstRun True if this is the first run at startup. */ checkForEventDeletion(activeEvents, layerProcessors, firstRun) { if (firstRun) { for (const activeEvent of activeEvents) { this._currentEventIds.set(activeEvent.id, activeEvent.name); } for (const layerProcessor of layerProcessors) { const response = (result) => { this.figureOutAllEventsOnArc(layerProcessor, result); }; if (this._config.eventIdField == null) { layerProcessor.featureQuerier.queryObservations(response, [this._config.observationIdField], false); } else { layerProcessor.featureQuerier.queryDistinct(response, this._config.eventIdField); } } } else { this._console.log('Checking for event deletions the previous known events are:'); const deletedEvents = new Map(); this._currentEventIds.forEach((eventName, eventId) => { this._console.log(eventName + ' with id ' + eventId); deletedEvents.set(eventId, eventName); }); this._console.log('Active events are:'); for (const activeEvent of activeEvents) { this._console.log(activeEvent.name + ' with id ' + activeEvent.id); deletedEvents.delete(activeEvent.id); } deletedEvents.forEach((eventName, eventId) => { this._console.log('Event named ' + eventName + ' was deleted removing observations from arc layers'); for (const layerProcessor of layerProcessors) { layerProcessor.sender.sendDeleteEvent(eventId); } this._currentEventIds.delete(eventId); }); for (const activeEvent of activeEvents) { this._currentEventIds.set(activeEvent.id, activeEvent.name); } } } /** * Called when the query is finished. It goes through the results and gathers all event Ids currently stored * in the arc layer. It then will remove any events from the arc layer that do not exist. * @param {FeatureLayerProcessor} layerProcessor The feature layer processor. * @param {QueryObjectResult} result The returned results. */ figureOutAllEventsOnArc(layerProcessor, result) { this._console.log('ArcGIS investigating all events for feature layer ' + layerProcessor.layerInfo.url); if (result.features != null) { const arcEventIds = new Set(); for (const feature of result.features) { if (this._config.eventIdField == null) { const value = feature.attributes[this._config.observationIdField]; const splitIds = value.split(this._config.idSeparator); if (splitIds.length === 2) { const eventId = parseInt(splitIds[1]); if (!isNaN(eventId)) { arcEventIds.add(eventId); } } } else { const value = feature.attributes[this._config.eventIdField]; arcEventIds.add(value); } } this._currentEventIds.forEach((eventName, eventId) => { arcEventIds.delete(eventId); }); for (const arcEventId of arcEventIds) { layerProcessor.sender.sendDeleteEvent(arcEventId); } } } } exports.EventDeletionHandler = EventDeletionHandler; //# sourceMappingURL=EventDeletionHandler.js.map