Skip to content

Commit

Permalink
fix failing errors for observations
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanslatten committed Nov 27, 2024
1 parent 03b2297 commit 5fefc3a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 48 deletions.
2 changes: 1 addition & 1 deletion plugins/arcgis/service/src/FeatureLayerProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class FeatureLayerProcessor {

for (const arcObservation of observations.deletions) {
if (this.layerInfo.geometryType == arcObservation.esriGeometryType) {
this.sender.sendDelete(Number(arcObservation.id));
this.sender.sendDelete(arcObservation.id);
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions plugins/arcgis/service/src/FeatureQuerier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ export class FeatureQuerier {
queryUrl.searchParams.set('returnGeometry', geometry === false ? 'false' : 'true')
this._console.info('ArcGIS query: ' + queryUrl)

const queryResponse = await request(queryUrl.toString(), {
await request(queryUrl.toString(), {
authentication: this._identityManager,
params: { f: 'json' }
});

response(queryResponse as QueryObjectResult);
})
.then((queryResponse) => response(queryResponse as QueryObjectResult))
.catch((error) => this._console.error('Error in FeatureQuerier.queryObservation :: ' + error));
}

/**
Expand All @@ -84,12 +84,12 @@ export class FeatureQuerier {

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

const queryResponse = await request(queryUrl.toString(), {
await request(queryUrl.toString(), {
authentication: this._identityManager,
params: { f: 'json' }
});

response(queryResponse as QueryObjectResult);
})
.then((queryResponse) => response(queryResponse as QueryObjectResult))
.catch((error) => this._console.error('Error in FeatureQuerier.queryObservations :: ' + error));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion plugins/arcgis/service/src/ObservationBinner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ export class ObservationBinner {
const bins = new ObservationBins();

for (const arcObservation of observations.observations) {
if (arcObservation.lastModified != arcObservation.createdAt) {
// TODO: Would probably want a better way to determine which observations need to be updated in arcgis
if (observations.firstRun || arcObservation.lastModified != arcObservation.createdAt) {
bins.updates.add(arcObservation);
} else if (!this._addedObs.has(arcObservation.id)) {
bins.adds.add(arcObservation);
Expand Down
59 changes: 21 additions & 38 deletions plugins/arcgis/service/src/ObservationsSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ export class ObservationsSender {
*/
private _url: string;

/**
* The full url to the feature layer receiving observations.
*/
private _urlAdd: string;

/**
* The full url to the feature layer receiving updates.
*/
private _urlUpdate: string;

/**
* Used to log to the console.
*/
Expand All @@ -56,8 +46,6 @@ export class ObservationsSender {
*/
constructor(layerInfo: LayerInfo, config: ArcGISPluginConfig, identityManager: ArcGISIdentityManager, console: Console) {
this._url = layerInfo.url;
this._urlAdd = this._url + '/addFeatures';
this._urlUpdate = this._url + '/updateFeatures';
this._console = console;
this._attachmentDirectory = environment.attachmentBaseDirectory;
this._config = config;
Expand All @@ -70,7 +58,7 @@ export class ObservationsSender {
* @param observations The observations to convert.
*/
sendAdds(observations: ArcObjects) {
this._console.info('ArcGIS addFeatures url ' + this._urlAdd);
this._console.info('ArcGIS addFeatures');

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

let responseHandler = this.updateResponseHandler(observations);
updateFeatures({
Expand All @@ -101,36 +89,34 @@ export class ObservationsSender {
* Delete an observation.
* @param id The observation id.
*/
sendDelete(id: number) {
const url = this._url + '/deleteFeatures'
this._console.info('ArcGIS deleteFeatures url ' + url + ', ' + this._config.observationIdField + ': ' + id)
sendDelete(id: string) {
this._console.info('ArcGIS deleteFeatures id: ' + id)

deleteFeatures({
url,
request(`${this._url}/deleteFeatures`, {
httpMethod: 'POST',
authentication: this._identityManager,
objectIds: [id]
}).catch((error) => this._console.error(error));
params: {
where: `${this._config.observationIdField} LIKE \'%${id}\'`
}
}).catch((error) => this._console.error('Error in ObservationSender.sendDelete :: ' + error));
}

/**
* Deletes all observations that are apart of a specified event.
* @param id The event id.
*/
sendDeleteEvent(id: number) {

const url = this._url + '/deleteFeatures'
sendDeleteEvent(id: string) {
this._console.info('ArcGIS deleteFeatures by event ' + this._config.observationIdField + ': ' + id);

this._console.info('ArcGIS deleteFeatures by event url ' + url + ', ' + this._config.observationIdField + ': ' + id)

const form = new FormData()

if (this._config.eventIdField == null) {
form.append('where', this._config.observationIdField + ' LIKE\'%' + this._config.idSeparator + id + '\'')
} else {
form.append('where', this._config.eventIdField + '=' + id)
}

this.sendDelete(id);
request(`${this._url}/deleteFeatures`, {
httpMethod: 'POST',
authentication: this._identityManager,
params: {
where: !!this._config.eventIdField
? this._config.eventIdField + '=' + id
: this._config.observationIdField + ' LIKE\'%' + this._config.idSeparator + id + '\''
}
}).catch((error) => this._console.error('Error in ObservationSender.sendDeleteEvent :: ' + error));
}

/**
Expand Down Expand Up @@ -207,7 +193,6 @@ export class ObservationsSender {
*/
private queryAndUpdateAttachments(observation: ArcObservation, objectId: number) {
// Query for existing attachments
const queryUrl = this._url + '/' + objectId + '/attachments'
getAttachments({
url: this._url,
authentication: this._identityManager,
Expand All @@ -225,7 +210,6 @@ export class ObservationsSender {
* @param attachmentInfos The arc attachment infos.
*/
private updateAttachments(observation: ArcObservation, objectId: number, attachmentInfos: AttachmentInfo[]) {

// Build a mapping between existing arc attachment names and the attachment infos
let nameAttachments = new Map<string, AttachmentInfo>()
if (attachmentInfos != null) {
Expand Down Expand Up @@ -319,7 +303,6 @@ export class ObservationsSender {
* @param attachmentInfos The arc attachment infos.
*/
private deleteAttachments(objectId: number, attachmentInfos: AttachmentInfo[]) {

const attachmentIds: number[] = []

for (const attachmentInfo of attachmentInfos) {
Expand Down

0 comments on commit 5fefc3a

Please sign in to comment.