Skip to content

Commit

Permalink
Fix addFields and deleteFields
Browse files Browse the repository at this point in the history
  • Loading branch information
Rick Saccoccia committed Oct 31, 2024
1 parent e2da608 commit e40718f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
9 changes: 5 additions & 4 deletions plugins/arcgis/service/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/arcgis/service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@esri/arcgis-rest-feature-service": "^4.0.6",
"@esri/arcgis-rest-request": "^4.2.3",
"@terraformer/arcgis": "2.1.2",
"form-data": "^4.0.0"
"form-data": "^4.0.1"
},
"peerDependencies": {
"@ngageoint/mage.service": "^6.2.9 || ^6.3.0-beta",
Expand Down
31 changes: 17 additions & 14 deletions plugins/arcgis/service/src/FeatureServiceAdmin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ 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()
Expand All @@ -110,6 +111,7 @@ export class FeatureServiceAdmin {
}
}

// TODO - where does New_field and New_field_2 come from with each startup?
if (addFields.length > 0) {
this.addFields(service, featureLayer, addFields)
}
Expand Down Expand Up @@ -462,24 +464,27 @@ export class FeatureServiceAdmin {
*/
private async addFields(service: FeatureServiceConfig, featureLayer: FeatureLayerConfig, fields: Field[]) {

const layer = {} as Layer
layer.fields = fields
const layer = { fields: fields} as Layer

const httpClient = this.httpClient(service)
const identityManager = await getIdentityManager(service, httpClient)
const url = this.adminUrl(service) + featureLayer.layer.toString() + '/addToDefinition'

this._console.info('ArcGIS feature layer addToDefinition (add fields) url ' + url)

const form = new FormData()
form.append('addToDefinition', JSON.stringify(layer))

const postResponse = request(url, {
await request(url, {
authentication: identityManager,
httpMethod: 'POST',
params: form
params: {
addToDefinition: JSON.stringify(layer),
f: "json"
}
}).then((postResponse) => {
console.log('Response: ' + postResponse)
}).catch((error) => {
console.log('Error: ' + error)
});
console.log('Response: ' + postResponse)

console.log('Remove me')

}

Expand Down Expand Up @@ -507,14 +512,12 @@ export class FeatureServiceAdmin {

this._console.info('ArcGIS feature layer deleteFromDefinition (delete fields) url ' + url)

const form = new FormData()
form.append('deleteFromDefinition', JSON.stringify(layer))

httpClient.sendPostForm(url, form)
const postResponse = request(url, {
authentication: identityManager,
httpMethod: 'POST',
params: form
params: {
deleteFromDefinition: JSON.stringify(layer)
}
});
console.log('Response: ' + postResponse)
}
Expand Down
6 changes: 4 additions & 2 deletions plugins/arcgis/service/src/ObservationProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ 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

if (featureLayer.token == null) {
featureLayer.token = featureServiceConfig.auth?.type == AuthType.Token ? featureServiceConfig.auth.token : ""
Expand Down Expand Up @@ -311,8 +313,8 @@ export class ObservationProcessor {
const identityManager = await getIdentityManager(featureServiceConfig, new HttpClient(console))
const layerProcessor = new FeatureLayerProcessor(info, config, identityManager,this._console);
this._layerProcessors.push(layerProcessor);
clearTimeout(this._nextTimeout);
this.scheduleNext(config);
clearTimeout(this._nextTimeout); // TODO why is this needed?
// this.scheduleNext(config); // TODO why is this needed when processAndScheduleNext is called upstream and ends with scheduleNext() This causes a query before updateLayer.
}
}

Expand Down

0 comments on commit e40718f

Please sign in to comment.