Skip to content

Commit

Permalink
fix issues with updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanslatten committed Dec 5, 2024
1 parent 8db0006 commit 4625296
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 87 deletions.
88 changes: 28 additions & 60 deletions plugins/arcgis/service/src/FeatureQuerier.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand All @@ -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));
}

}
2 changes: 1 addition & 1 deletion plugins/arcgis/service/src/ObservationProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
31 changes: 5 additions & 26 deletions plugins/arcgis/service/src/ObservationsSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand All @@ -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`, {
Expand All @@ -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))
Expand Down

0 comments on commit 4625296

Please sign in to comment.