Skip to content

Commit 5fefc3a

Browse files
committed
fix failing errors for observations
1 parent 03b2297 commit 5fefc3a

File tree

4 files changed

+32
-48
lines changed

4 files changed

+32
-48
lines changed

plugins/arcgis/service/src/FeatureLayerProcessor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class FeatureLayerProcessor {
8585

8686
for (const arcObservation of observations.deletions) {
8787
if (this.layerInfo.geometryType == arcObservation.esriGeometryType) {
88-
this.sender.sendDelete(Number(arcObservation.id));
88+
this.sender.sendDelete(arcObservation.id);
8989
}
9090
}
9191
}

plugins/arcgis/service/src/FeatureQuerier.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ export class FeatureQuerier {
6262
queryUrl.searchParams.set('returnGeometry', geometry === false ? 'false' : 'true')
6363
this._console.info('ArcGIS query: ' + queryUrl)
6464

65-
const queryResponse = await request(queryUrl.toString(), {
65+
await request(queryUrl.toString(), {
6666
authentication: this._identityManager,
6767
params: { f: 'json' }
68-
});
69-
70-
response(queryResponse as QueryObjectResult);
68+
})
69+
.then((queryResponse) => response(queryResponse as QueryObjectResult))
70+
.catch((error) => this._console.error('Error in FeatureQuerier.queryObservation :: ' + error));
7171
}
7272

7373
/**
@@ -84,12 +84,12 @@ export class FeatureQuerier {
8484

8585
this._console.info('ArcGIS query: ' + queryUrl)
8686

87-
const queryResponse = await request(queryUrl.toString(), {
87+
await request(queryUrl.toString(), {
8888
authentication: this._identityManager,
8989
params: { f: 'json' }
90-
});
91-
92-
response(queryResponse as QueryObjectResult);
90+
})
91+
.then((queryResponse) => response(queryResponse as QueryObjectResult))
92+
.catch((error) => this._console.error('Error in FeatureQuerier.queryObservations :: ' + error));
9393
}
9494

9595
/**

plugins/arcgis/service/src/ObservationBinner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ export class ObservationBinner {
8989
const bins = new ObservationBins();
9090

9191
for (const arcObservation of observations.observations) {
92-
if (arcObservation.lastModified != arcObservation.createdAt) {
92+
// TODO: Would probably want a better way to determine which observations need to be updated in arcgis
93+
if (observations.firstRun || arcObservation.lastModified != arcObservation.createdAt) {
9394
bins.updates.add(arcObservation);
9495
} else if (!this._addedObs.has(arcObservation.id)) {
9596
bins.adds.add(arcObservation);

plugins/arcgis/service/src/ObservationsSender.ts

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,6 @@ export class ObservationsSender {
2121
*/
2222
private _url: string;
2323

24-
/**
25-
* The full url to the feature layer receiving observations.
26-
*/
27-
private _urlAdd: string;
28-
29-
/**
30-
* The full url to the feature layer receiving updates.
31-
*/
32-
private _urlUpdate: string;
33-
3424
/**
3525
* Used to log to the console.
3626
*/
@@ -56,8 +46,6 @@ export class ObservationsSender {
5646
*/
5747
constructor(layerInfo: LayerInfo, config: ArcGISPluginConfig, identityManager: ArcGISIdentityManager, console: Console) {
5848
this._url = layerInfo.url;
59-
this._urlAdd = this._url + '/addFeatures';
60-
this._urlUpdate = this._url + '/updateFeatures';
6149
this._console = console;
6250
this._attachmentDirectory = environment.attachmentBaseDirectory;
6351
this._config = config;
@@ -70,7 +58,7 @@ export class ObservationsSender {
7058
* @param observations The observations to convert.
7159
*/
7260
sendAdds(observations: ArcObjects) {
73-
this._console.info('ArcGIS addFeatures url ' + this._urlAdd);
61+
this._console.info('ArcGIS addFeatures');
7462

7563
let responseHandler = this.addResponseHandler(observations);
7664
addFeatures({
@@ -87,7 +75,7 @@ export class ObservationsSender {
8775
* @returns The json string of the observations.
8876
*/
8977
sendUpdates(observations: ArcObjects) {
90-
this._console.info('ArcGIS updateFeatures url ' + this._urlUpdate);
78+
this._console.info('ArcGIS updateFeatures');
9179

9280
let responseHandler = this.updateResponseHandler(observations);
9381
updateFeatures({
@@ -101,36 +89,34 @@ export class ObservationsSender {
10189
* Delete an observation.
10290
* @param id The observation id.
10391
*/
104-
sendDelete(id: number) {
105-
const url = this._url + '/deleteFeatures'
106-
this._console.info('ArcGIS deleteFeatures url ' + url + ', ' + this._config.observationIdField + ': ' + id)
92+
sendDelete(id: string) {
93+
this._console.info('ArcGIS deleteFeatures id: ' + id)
10794

108-
deleteFeatures({
109-
url,
95+
request(`${this._url}/deleteFeatures`, {
96+
httpMethod: 'POST',
11097
authentication: this._identityManager,
111-
objectIds: [id]
112-
}).catch((error) => this._console.error(error));
98+
params: {
99+
where: `${this._config.observationIdField} LIKE \'%${id}\'`
100+
}
101+
}).catch((error) => this._console.error('Error in ObservationSender.sendDelete :: ' + error));
113102
}
114103

115104
/**
116105
* Deletes all observations that are apart of a specified event.
117106
* @param id The event id.
118107
*/
119-
sendDeleteEvent(id: number) {
120-
121-
const url = this._url + '/deleteFeatures'
108+
sendDeleteEvent(id: string) {
109+
this._console.info('ArcGIS deleteFeatures by event ' + this._config.observationIdField + ': ' + id);
122110

123-
this._console.info('ArcGIS deleteFeatures by event url ' + url + ', ' + this._config.observationIdField + ': ' + id)
124-
125-
const form = new FormData()
126-
127-
if (this._config.eventIdField == null) {
128-
form.append('where', this._config.observationIdField + ' LIKE\'%' + this._config.idSeparator + id + '\'')
129-
} else {
130-
form.append('where', this._config.eventIdField + '=' + id)
131-
}
132-
133-
this.sendDelete(id);
111+
request(`${this._url}/deleteFeatures`, {
112+
httpMethod: 'POST',
113+
authentication: this._identityManager,
114+
params: {
115+
where: !!this._config.eventIdField
116+
? this._config.eventIdField + '=' + id
117+
: this._config.observationIdField + ' LIKE\'%' + this._config.idSeparator + id + '\''
118+
}
119+
}).catch((error) => this._console.error('Error in ObservationSender.sendDeleteEvent :: ' + error));
134120
}
135121

136122
/**
@@ -207,7 +193,6 @@ export class ObservationsSender {
207193
*/
208194
private queryAndUpdateAttachments(observation: ArcObservation, objectId: number) {
209195
// Query for existing attachments
210-
const queryUrl = this._url + '/' + objectId + '/attachments'
211196
getAttachments({
212197
url: this._url,
213198
authentication: this._identityManager,
@@ -225,7 +210,6 @@ export class ObservationsSender {
225210
* @param attachmentInfos The arc attachment infos.
226211
*/
227212
private updateAttachments(observation: ArcObservation, objectId: number, attachmentInfos: AttachmentInfo[]) {
228-
229213
// Build a mapping between existing arc attachment names and the attachment infos
230214
let nameAttachments = new Map<string, AttachmentInfo>()
231215
if (attachmentInfos != null) {
@@ -319,7 +303,6 @@ export class ObservationsSender {
319303
* @param attachmentInfos The arc attachment infos.
320304
*/
321305
private deleteAttachments(objectId: number, attachmentInfos: AttachmentInfo[]) {
322-
323306
const attachmentIds: number[] = []
324307

325308
for (const attachmentInfo of attachmentInfos) {

0 commit comments

Comments
 (0)