From 157d209e56b0e4041cd69c11311efd803c07eb9f Mon Sep 17 00:00:00 2001 From: William Newman <3382274+newmanw@users.noreply.github.com> Date: Thu, 7 Nov 2024 15:45:32 -0700 Subject: [PATCH] [service] ArcGIS field names are lowercase, account for this when adding/removing fields --- plugins/arcgis/service/src/ArcGISConfig.ts | 10 --- .../arcgis/service/src/FeatureServiceAdmin.ts | 75 +++++++++---------- .../service/src/ObservationProcessor.ts | 9 +-- 3 files changed, 36 insertions(+), 58 deletions(-) diff --git a/plugins/arcgis/service/src/ArcGISConfig.ts b/plugins/arcgis/service/src/ArcGISConfig.ts index ceded02c6..28311a53e 100644 --- a/plugins/arcgis/service/src/ArcGISConfig.ts +++ b/plugins/arcgis/service/src/ArcGISConfig.ts @@ -38,16 +38,6 @@ export interface FeatureLayerConfig { * The event ids or names that sync to this arc feature layer. */ events?: (number|string)[] - - /** - * Add layer fields from form fields - */ - addFields?: boolean - - /** - * Delete editable layer fields missing from form fields - */ - deleteFields?: boolean } diff --git a/plugins/arcgis/service/src/FeatureServiceAdmin.ts b/plugins/arcgis/service/src/FeatureServiceAdmin.ts index bdf0c6a94..2f3f08ded 100644 --- a/plugins/arcgis/service/src/FeatureServiceAdmin.ts +++ b/plugins/arcgis/service/src/FeatureServiceAdmin.ts @@ -78,51 +78,44 @@ export class FeatureServiceAdmin { const eventFields = this.fields(events) const layerFields = layerInfo.fields - // TODO - better naming: addFields is a boolean, array of fields, and a method. Ditto for deleteFields - if (featureLayer.addFields) { - - const layerFieldSet = new Set() - for (const field of layerFields) { - layerFieldSet.add(field.name) - } - - const addFields = [] - for (const field of eventFields) { - if (!layerFieldSet.has(field.name)) { - addFields.push(field) - const layerField = {} as LayerField - layerField.name = field.name - layerField.editable = true - layerFields.push(layerField) - } - } + const layerFieldSet = new Set() + for (const field of layerFields) { + layerFieldSet.add(field.name) + } - if (addFields.length > 0) { - this.addFields(service, featureLayer, addFields) - } + const addFields = [] + for (const field of eventFields) { + if (!layerFieldSet.has(field.name)) { + addFields.push(field) + const layerField = {} as LayerField + layerField.name = field.name + layerField.editable = true + layerFields.push(layerField) + } + } + if (addFields.length > 0) { + this.addFields(service, featureLayer, addFields) } - if (featureLayer.deleteFields) { - const eventFieldSet = new Set() - for (const field of eventFields) { - eventFieldSet.add(field.name) - } + const eventFieldSet = new Set() + for (const field of eventFields) { + eventFieldSet.add(field.name) + } - const deleteFields = [] - const remainingFields = [] - for (const field of layerFields) { - if (field.editable && !eventFieldSet.has(field.name)) { - deleteFields.push(field) - } else { - remainingFields.push(field) - } + const deleteFields = [] + const remainingFields = [] + for (const field of layerFields) { + if (field.editable && !eventFieldSet.has(field.name)) { + deleteFields.push(field) + } else { + remainingFields.push(field) } + } - if (deleteFields.length > 0) { - layerInfo.fields = remainingFields - this.deleteFields(service, featureLayer, deleteFields) - } + if (deleteFields.length > 0) { + layerInfo.fields = remainingFields + this.deleteFields(service, featureLayer, deleteFields) } } @@ -331,7 +324,7 @@ export class FeatureServiceAdmin { if (field != null) { const sanitizedName = ObservationsTransformer.replaceSpaces(formField.title) const sanitizedFormName = ObservationsTransformer.replaceSpaces(form.name) - const name = `${sanitizedFormName}_${sanitizedName}` + const name = `${sanitizedFormName}_${sanitizedName}`.toLowerCase() fieldNames.add(name) @@ -438,7 +431,7 @@ export class FeatureServiceAdmin { await request(url, { authentication: identityManager, params: { - addToDefinition: JSON.stringify(layer), + addToDefinition: layer, f: "json" } }).then((postResponse) => { @@ -474,7 +467,7 @@ export class FeatureServiceAdmin { authentication: identityManager, httpMethod: 'POST', params: { - deleteFromDefinition: JSON.stringify(layer) + deleteFromDefinition: layer } }); console.log('Response: ' + postResponse) diff --git a/plugins/arcgis/service/src/ObservationProcessor.ts b/plugins/arcgis/service/src/ObservationProcessor.ts index 23379aff5..ccaa54886 100644 --- a/plugins/arcgis/service/src/ObservationProcessor.ts +++ b/plugins/arcgis/service/src/ObservationProcessor.ts @@ -230,9 +230,6 @@ export class ObservationProcessor { } for (const featureLayer of featureServiceConfig.layers) { - // Initiate the feature layer and event fields to sync with the feature service - featureLayer.addFields = true - const eventNames: string[] = [] const events = featureLayer.events if (events != null) { @@ -285,10 +282,8 @@ export class ObservationProcessor { private async handleLayerInfo(url: string, featureServiceConfig: FeatureServiceConfig, featureLayer: FeatureLayerConfig, layerInfo: LayerInfoResult, config: ArcGISPluginConfig) { if (layerInfo.geometryType != null) { const events = featureLayer.events as string[] - if (featureLayer.addFields || featureLayer.deleteFields) { - const admin = new FeatureServiceAdmin(config, this._identityService, this._console) - await admin.updateLayer(featureServiceConfig, featureLayer, layerInfo, this._eventRepo) - } + const admin = new FeatureServiceAdmin(config, this._identityService, this._console) + await admin.updateLayer(featureServiceConfig, featureLayer, layerInfo, this._eventRepo) const info = new LayerInfo(url, events, layerInfo) const identityManager = await this._identityService.getIdentityManager(featureServiceConfig) const layerProcessor = new FeatureLayerProcessor(info, config, identityManager, this._console);