diff --git a/plugins/arcgis/service/src/FeatureQuerier.ts b/plugins/arcgis/service/src/FeatureQuerier.ts index 3a4da4a4c..f75b442eb 100644 --- a/plugins/arcgis/service/src/FeatureQuerier.ts +++ b/plugins/arcgis/service/src/FeatureQuerier.ts @@ -1,7 +1,8 @@ import { ArcGISPluginConfig } from "./ArcGISPluginConfig"; import { LayerInfo } from "./LayerInfo"; import { QueryObjectResult } from "./QueryObjectResult"; -import { ArcGISIdentityManager, request } from "@esri/arcgis-rest-request"; +import { ArcGISIdentityManager } from "@esri/arcgis-rest-request"; +import { queryFeatures } from '@esri/arcgis-rest-feature-service'; /** * Performs various queries on observations for a specific arc feature layer. @@ -52,22 +53,17 @@ export class FeatureQuerier { * @param geometry query the geometry, default is true */ async queryObservation(observationId: string, response: (result: QueryObjectResult) => void, fields?: string[], geometry?: boolean) { - const queryUrl = new URL(this._url) - if (this._config.eventIdField == null) { - queryUrl.searchParams.set('where', `${this._config.observationIdField} LIKE '${observationId}${this._config.idSeparator}%'`); - } else { - queryUrl.searchParams.set('where', `${this._config.observationIdField} = ${observationId}`); - } - queryUrl.searchParams.set('outFields', this.outFields(fields)) - queryUrl.searchParams.set('returnGeometry', geometry === false ? 'false' : 'true') - this._console.info('ArcGIS query: ' + queryUrl) - - await request(queryUrl.toString(), { + const where = !this._config.eventIdField + ? `${this._config.observationIdField} LIKE '${observationId}${this._config.idSeparator}%'` + : `${this._config.observationIdField} = '${observationId}'`; + this._console.info('ArcGIS query observation: ' + this._url.toString() + where); + await queryFeatures({ + url: this._url.toString(), authentication: this._identityManager, - params: { f: 'json' } - }) - .then((queryResponse) => response(queryResponse as QueryObjectResult)) - .catch((error) => this._console.error('Error in FeatureQuerier.queryObservation :: ' + error)); + where, + returnGeometry: geometry, + outFields: fields?.length ? fields : '*' + }).then((queryResponse) => response(queryResponse as QueryObjectResult)).catch((error) => this._console.error('Error in FeatureQuerier.queryObservation :: ' + error)); } /** @@ -77,19 +73,14 @@ export class FeatureQuerier { * @param geometry query the geometry, default is true */ async queryObservations(response: (result: QueryObjectResult) => void, fields?: string[], geometry?: boolean) { - const queryUrl = new URL(this._url) - queryUrl.searchParams.set('where', `${this._config.observationIdField} IS NOT NULL`); - queryUrl.searchParams.set('outFields', this.outFields(fields)); - queryUrl.searchParams.set('returnGeometry', geometry === false ? 'false' : 'true'); - - this._console.info('ArcGIS query: ' + queryUrl) - - await request(queryUrl.toString(), { + this._console.info('ArcGIS query observation: ' + this._url.toString()); + await queryFeatures({ + url: this._url.toString(), authentication: this._identityManager, - params: { f: 'json' } - }) - .then((queryResponse) => response(queryResponse as QueryObjectResult)) - .catch((error) => this._console.error('Error in FeatureQuerier.queryObservations :: ' + error)); + where: `${this._config.observationIdField} IS NOT NULL`, + returnGeometry: geometry, + outFields: fields?.length ? fields : '*' + }).then((queryResponse) => response(queryResponse as QueryObjectResult)).catch((error) => this._console.error('Error in FeatureQuerier.queryObservations :: ' + error)); } /** @@ -98,37 +89,14 @@ export class FeatureQuerier { * @param field field to query */ async queryDistinct(response: (result: QueryObjectResult) => void, field: string) { - const queryUrl = new URL(this._url); - queryUrl.searchParams.set('where', `${field} IS NOT NULL`); - queryUrl.searchParams.set('returnDistinctValues', 'true'); - queryUrl.searchParams.set('outFields', this.outFields([field])); - queryUrl.searchParams.set('returnGeometry', 'false'); - this._console.info('ArcGIS query: ' + queryUrl) - - try { - const queryResponse = await request(queryUrl.toString(), { - authentication: this._identityManager, - params: { f: 'json' } - - }); - - response(queryResponse as QueryObjectResult); - } catch (err) { - console.error("could not query", err) - } - } - - /** - * Build the out fields query parameter - * @param fields query fields - * @returns out fields - */ - private outFields(fields?: string[]): string { - if (fields != null && fields.length > 0) { - return fields.join(','); - } else { - return '*'; - } + this._console.info('ArcGIS query observation: ' + this._url.toString()); + await queryFeatures({ + url: this._url.toString(), + authentication: this._identityManager, + where: `${field} IS NOT NULL`, + returnGeometry: false, + outFields: field ? [field] : '*', + returnDistinctValues: true + }).then((queryResponse) => response(queryResponse as QueryObjectResult)).catch((error) => this._console.error('Error in FeatureQuerier.queryDistinct :: ' + error)); } - } \ No newline at end of file diff --git a/plugins/arcgis/service/src/ObservationProcessor.ts b/plugins/arcgis/service/src/ObservationProcessor.ts index c4ffed54a..59c67c342 100644 --- a/plugins/arcgis/service/src/ObservationProcessor.ts +++ b/plugins/arcgis/service/src/ObservationProcessor.ts @@ -410,7 +410,7 @@ export class ObservationProcessor { } arcObjects.firstRun = this._firstRun; for (const layerProcessor of layerProcessors) { - layerProcessor.processArcObjects(JSON.parse(JSON.stringify(arcObjects))); + layerProcessor.processArcObjects(arcObjects); } newNumberLeft -= latestObs.items.length; pagingSettings.pageIndex++; diff --git a/plugins/arcgis/service/src/ObservationsSender.ts b/plugins/arcgis/service/src/ObservationsSender.ts index edc38952a..e8b6f593b 100644 --- a/plugins/arcgis/service/src/ObservationsSender.ts +++ b/plugins/arcgis/service/src/ObservationsSender.ts @@ -7,9 +7,8 @@ import { AttachmentInfosResult, AttachmentInfo } from './AttachmentInfosResult'; import environment from '@ngageoint/mage.service/lib/environment/env' import fs from 'fs' import path from 'path' -import FormData from 'form-data'; import { ArcGISIdentityManager, IFeature, request } from "@esri/arcgis-rest-request" -import { addFeatures, updateFeatures, deleteFeatures, getAttachments, updateAttachment, addAttachment, deleteAttachments } from "@esri/arcgis-rest-feature-service"; +import { addFeatures, updateFeatures, getAttachments, updateAttachment, addAttachment, deleteAttachments } from "@esri/arcgis-rest-feature-service"; /** * Class that transforms observations into a json string that can then be sent to an arcgis server. @@ -60,12 +59,11 @@ export class ObservationsSender { sendAdds(observations: ArcObjects) { this._console.info('ArcGIS addFeatures'); - let responseHandler = this.addResponseHandler(observations); addFeatures({ url: this._url, authentication: this._identityManager, features: observations.objects as IFeature[] - }).then(responseHandler).catch((error) => this._console.error(error)); + }).then(this.responseHandler(observations)).catch((error) => this._console.error(error)); } /** @@ -77,12 +75,11 @@ export class ObservationsSender { sendUpdates(observations: ArcObjects) { this._console.info('ArcGIS updateFeatures'); - let responseHandler = this.updateResponseHandler(observations); updateFeatures({ url: this._url, authentication: this._identityManager, features: observations.objects as IFeature[] - }).then(responseHandler).catch((error) => this._console.error(error)); + }).then(this.responseHandler(observations, true)).catch((error) => this._console.error(error)); } /** @@ -105,7 +102,7 @@ export class ObservationsSender { * Deletes all observations that are apart of a specified event. * @param id The event id. */ - sendDeleteEvent(id: string) { + sendDeleteEvent(id: number) { this._console.info('ArcGIS deleteFeatures by event ' + this._config.observationIdField + ': ' + id); request(`${this._url}/deleteFeatures`, { @@ -119,31 +116,13 @@ export class ObservationsSender { }).catch((error) => this._console.error('Error in ObservationSender.sendDeleteEvent :: ' + error)); } - /** - * Creates an add observation response handler. - * @param observations The observations sent. - * @returns The response handler. - */ - private addResponseHandler(observations: ArcObjects): (chunk: any) => void { - return this.responseHandler(observations, false) - } - - /** - * Creates an update observation response handler. - * @param observations The observations sent. - * @returns The response handler. - */ - private updateResponseHandler(observations: ArcObjects): (chunk: any) => void { - return this.responseHandler(observations, true) - } - /** * Creates an observation response handler. * @param observations The observations sent. * @param update The update or add flag value. * @returns The response handler. */ - private responseHandler(observations: ArcObjects, update: boolean): (chunk: any) => void { + private responseHandler(observations: ArcObjects, update?: boolean): (chunk: any) => void { const console = this._console return (chunk: any) => { console.log('ArcGIS ' + (update ? 'Update' : 'Add') + ' Response: ' + JSON.stringify(chunk))