Skip to content

Commit

Permalink
[service] ArcGIS field names are lowercase, account for this when add…
Browse files Browse the repository at this point in the history
…ing/removing fields
  • Loading branch information
newmanw committed Nov 7, 2024
1 parent 86fb706 commit 157d209
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 58 deletions.
10 changes: 0 additions & 10 deletions plugins/arcgis/service/src/ArcGISConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}


Expand Down
75 changes: 34 additions & 41 deletions plugins/arcgis/service/src/FeatureServiceAdmin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -438,7 +431,7 @@ export class FeatureServiceAdmin {
await request(url, {
authentication: identityManager,
params: {
addToDefinition: JSON.stringify(layer),
addToDefinition: layer,
f: "json"
}
}).then((postResponse) => {
Expand Down Expand Up @@ -474,7 +467,7 @@ export class FeatureServiceAdmin {
authentication: identityManager,
httpMethod: 'POST',
params: {
deleteFromDefinition: JSON.stringify(layer)
deleteFromDefinition: layer
}
});
console.log('Response: ' + postResponse)
Expand Down
9 changes: 2 additions & 7 deletions plugins/arcgis/service/src/ObservationProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 157d209

Please sign in to comment.