Skip to content

Commit 4625296

Browse files
committed
fix issues with updates
1 parent 8db0006 commit 4625296

File tree

3 files changed

+34
-87
lines changed

3 files changed

+34
-87
lines changed
Lines changed: 28 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { ArcGISPluginConfig } from "./ArcGISPluginConfig";
22
import { LayerInfo } from "./LayerInfo";
33
import { QueryObjectResult } from "./QueryObjectResult";
4-
import { ArcGISIdentityManager, request } from "@esri/arcgis-rest-request";
4+
import { ArcGISIdentityManager } from "@esri/arcgis-rest-request";
5+
import { queryFeatures } from '@esri/arcgis-rest-feature-service';
56

67
/**
78
* Performs various queries on observations for a specific arc feature layer.
@@ -52,22 +53,17 @@ export class FeatureQuerier {
5253
* @param geometry query the geometry, default is true
5354
*/
5455
async queryObservation(observationId: string, response: (result: QueryObjectResult) => void, fields?: string[], geometry?: boolean) {
55-
const queryUrl = new URL(this._url)
56-
if (this._config.eventIdField == null) {
57-
queryUrl.searchParams.set('where', `${this._config.observationIdField} LIKE '${observationId}${this._config.idSeparator}%'`);
58-
} else {
59-
queryUrl.searchParams.set('where', `${this._config.observationIdField} = ${observationId}`);
60-
}
61-
queryUrl.searchParams.set('outFields', this.outFields(fields))
62-
queryUrl.searchParams.set('returnGeometry', geometry === false ? 'false' : 'true')
63-
this._console.info('ArcGIS query: ' + queryUrl)
64-
65-
await request(queryUrl.toString(), {
56+
const where = !this._config.eventIdField
57+
? `${this._config.observationIdField} LIKE '${observationId}${this._config.idSeparator}%'`
58+
: `${this._config.observationIdField} = '${observationId}'`;
59+
this._console.info('ArcGIS query observation: ' + this._url.toString() + where);
60+
await queryFeatures({
61+
url: this._url.toString(),
6662
authentication: this._identityManager,
67-
params: { f: 'json' }
68-
})
69-
.then((queryResponse) => response(queryResponse as QueryObjectResult))
70-
.catch((error) => this._console.error('Error in FeatureQuerier.queryObservation :: ' + error));
63+
where,
64+
returnGeometry: geometry,
65+
outFields: fields?.length ? fields : '*'
66+
}).then((queryResponse) => response(queryResponse as QueryObjectResult)).catch((error) => this._console.error('Error in FeatureQuerier.queryObservation :: ' + error));
7167
}
7268

7369
/**
@@ -77,19 +73,14 @@ export class FeatureQuerier {
7773
* @param geometry query the geometry, default is true
7874
*/
7975
async queryObservations(response: (result: QueryObjectResult) => void, fields?: string[], geometry?: boolean) {
80-
const queryUrl = new URL(this._url)
81-
queryUrl.searchParams.set('where', `${this._config.observationIdField} IS NOT NULL`);
82-
queryUrl.searchParams.set('outFields', this.outFields(fields));
83-
queryUrl.searchParams.set('returnGeometry', geometry === false ? 'false' : 'true');
84-
85-
this._console.info('ArcGIS query: ' + queryUrl)
86-
87-
await request(queryUrl.toString(), {
76+
this._console.info('ArcGIS query observation: ' + this._url.toString());
77+
await queryFeatures({
78+
url: this._url.toString(),
8879
authentication: this._identityManager,
89-
params: { f: 'json' }
90-
})
91-
.then((queryResponse) => response(queryResponse as QueryObjectResult))
92-
.catch((error) => this._console.error('Error in FeatureQuerier.queryObservations :: ' + error));
80+
where: `${this._config.observationIdField} IS NOT NULL`,
81+
returnGeometry: geometry,
82+
outFields: fields?.length ? fields : '*'
83+
}).then((queryResponse) => response(queryResponse as QueryObjectResult)).catch((error) => this._console.error('Error in FeatureQuerier.queryObservations :: ' + error));
9384
}
9485

9586
/**
@@ -98,37 +89,14 @@ export class FeatureQuerier {
9889
* @param field field to query
9990
*/
10091
async queryDistinct(response: (result: QueryObjectResult) => void, field: string) {
101-
const queryUrl = new URL(this._url);
102-
queryUrl.searchParams.set('where', `${field} IS NOT NULL`);
103-
queryUrl.searchParams.set('returnDistinctValues', 'true');
104-
queryUrl.searchParams.set('outFields', this.outFields([field]));
105-
queryUrl.searchParams.set('returnGeometry', 'false');
106-
this._console.info('ArcGIS query: ' + queryUrl)
107-
108-
try {
109-
const queryResponse = await request(queryUrl.toString(), {
110-
authentication: this._identityManager,
111-
params: { f: 'json' }
112-
113-
});
114-
115-
response(queryResponse as QueryObjectResult);
116-
} catch (err) {
117-
console.error("could not query", err)
118-
}
119-
}
120-
121-
/**
122-
* Build the out fields query parameter
123-
* @param fields query fields
124-
* @returns out fields
125-
*/
126-
private outFields(fields?: string[]): string {
127-
if (fields != null && fields.length > 0) {
128-
return fields.join(',');
129-
} else {
130-
return '*';
131-
}
92+
this._console.info('ArcGIS query observation: ' + this._url.toString());
93+
await queryFeatures({
94+
url: this._url.toString(),
95+
authentication: this._identityManager,
96+
where: `${field} IS NOT NULL`,
97+
returnGeometry: false,
98+
outFields: field ? [field] : '*',
99+
returnDistinctValues: true
100+
}).then((queryResponse) => response(queryResponse as QueryObjectResult)).catch((error) => this._console.error('Error in FeatureQuerier.queryDistinct :: ' + error));
132101
}
133-
134102
}

plugins/arcgis/service/src/ObservationProcessor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ export class ObservationProcessor {
410410
}
411411
arcObjects.firstRun = this._firstRun;
412412
for (const layerProcessor of layerProcessors) {
413-
layerProcessor.processArcObjects(JSON.parse(JSON.stringify(arcObjects)));
413+
layerProcessor.processArcObjects(arcObjects);
414414
}
415415
newNumberLeft -= latestObs.items.length;
416416
pagingSettings.pageIndex++;

plugins/arcgis/service/src/ObservationsSender.ts

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import { AttachmentInfosResult, AttachmentInfo } from './AttachmentInfosResult';
77
import environment from '@ngageoint/mage.service/lib/environment/env'
88
import fs from 'fs'
99
import path from 'path'
10-
import FormData from 'form-data';
1110
import { ArcGISIdentityManager, IFeature, request } from "@esri/arcgis-rest-request"
12-
import { addFeatures, updateFeatures, deleteFeatures, getAttachments, updateAttachment, addAttachment, deleteAttachments } from "@esri/arcgis-rest-feature-service";
11+
import { addFeatures, updateFeatures, getAttachments, updateAttachment, addAttachment, deleteAttachments } from "@esri/arcgis-rest-feature-service";
1312

1413
/**
1514
* Class that transforms observations into a json string that can then be sent to an arcgis server.
@@ -60,12 +59,11 @@ export class ObservationsSender {
6059
sendAdds(observations: ArcObjects) {
6160
this._console.info('ArcGIS addFeatures');
6261

63-
let responseHandler = this.addResponseHandler(observations);
6462
addFeatures({
6563
url: this._url,
6664
authentication: this._identityManager,
6765
features: observations.objects as IFeature[]
68-
}).then(responseHandler).catch((error) => this._console.error(error));
66+
}).then(this.responseHandler(observations)).catch((error) => this._console.error(error));
6967
}
7068

7169
/**
@@ -77,12 +75,11 @@ export class ObservationsSender {
7775
sendUpdates(observations: ArcObjects) {
7876
this._console.info('ArcGIS updateFeatures');
7977

80-
let responseHandler = this.updateResponseHandler(observations);
8178
updateFeatures({
8279
url: this._url,
8380
authentication: this._identityManager,
8481
features: observations.objects as IFeature[]
85-
}).then(responseHandler).catch((error) => this._console.error(error));
82+
}).then(this.responseHandler(observations, true)).catch((error) => this._console.error(error));
8683
}
8784

8885
/**
@@ -105,7 +102,7 @@ export class ObservationsSender {
105102
* Deletes all observations that are apart of a specified event.
106103
* @param id The event id.
107104
*/
108-
sendDeleteEvent(id: string) {
105+
sendDeleteEvent(id: number) {
109106
this._console.info('ArcGIS deleteFeatures by event ' + this._config.observationIdField + ': ' + id);
110107

111108
request(`${this._url}/deleteFeatures`, {
@@ -119,31 +116,13 @@ export class ObservationsSender {
119116
}).catch((error) => this._console.error('Error in ObservationSender.sendDeleteEvent :: ' + error));
120117
}
121118

122-
/**
123-
* Creates an add observation response handler.
124-
* @param observations The observations sent.
125-
* @returns The response handler.
126-
*/
127-
private addResponseHandler(observations: ArcObjects): (chunk: any) => void {
128-
return this.responseHandler(observations, false)
129-
}
130-
131-
/**
132-
* Creates an update observation response handler.
133-
* @param observations The observations sent.
134-
* @returns The response handler.
135-
*/
136-
private updateResponseHandler(observations: ArcObjects): (chunk: any) => void {
137-
return this.responseHandler(observations, true)
138-
}
139-
140119
/**
141120
* Creates an observation response handler.
142121
* @param observations The observations sent.
143122
* @param update The update or add flag value.
144123
* @returns The response handler.
145124
*/
146-
private responseHandler(observations: ArcObjects, update: boolean): (chunk: any) => void {
125+
private responseHandler(observations: ArcObjects, update?: boolean): (chunk: any) => void {
147126
const console = this._console
148127
return (chunk: any) => {
149128
console.log('ArcGIS ' + (update ? 'Update' : 'Add') + ' Response: ' + JSON.stringify(chunk))

0 commit comments

Comments
 (0)