Skip to content

Commit 86fb706

Browse files
committed
Merge branch 'switch-httpClient-to-esri-library' of https://github.com/ngageoint/mage-server into switch-httpClient-to-esri-library
2 parents 10b5444 + ed561a7 commit 86fb706

File tree

10 files changed

+992
-1225
lines changed

10 files changed

+992
-1225
lines changed

plugins/arcgis/service/src/ArcGISConfig.ts

Lines changed: 5 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,11 @@ export interface FeatureServiceConfig {
88
*/
99
url: string
1010

11-
/**
12-
* Username and password for ArcGIS authentication
13-
*/
14-
auth?: ArcGISAuthConfig
15-
16-
/**
17-
* Create layers that don't exist
18-
*/
19-
createLayers?: boolean
20-
21-
/**
22-
* The administration url to the arc feature service.
23-
*/
24-
adminUrl?: string
25-
26-
/**
27-
* Administration access token
28-
*/
29-
adminToken?: string
30-
11+
/**
12+
* Serialized ArcGISIdentityManager
13+
*/
14+
identityManager: string
15+
3116
/**
3217
* The feature layers.
3318
*/
@@ -49,10 +34,6 @@ export interface FeatureLayerConfig {
4934
*/
5035
geometryType?: string
5136

52-
/**
53-
* Access token
54-
*/
55-
token?: string // TODO - can this be removed? Will Layers have a token too?
5637
/**
5738
* The event ids or names that sync to this arc feature layer.
5839
*/
@@ -67,86 +48,8 @@ export interface FeatureLayerConfig {
6748
* Delete editable layer fields missing from form fields
6849
*/
6950
deleteFields?: boolean
70-
71-
}
72-
73-
export enum AuthType {
74-
Token = 'token',
75-
UsernamePassword = 'usernamePassword',
76-
OAuth = 'oauth'
77-
}
78-
79-
80-
/**
81-
* Contains token-based authentication configuration.
82-
*/
83-
export interface TokenAuthConfig {
84-
type: AuthType.Token
85-
token: string
86-
authTokenExpires?: string
87-
}
88-
89-
/**
90-
* Contains username and password for ArcGIS server authentication.
91-
*/
92-
export interface UsernamePasswordAuthConfig {
93-
type: AuthType.UsernamePassword
94-
/**
95-
* The username for authentication.
96-
*/
97-
username: string
98-
99-
/**
100-
* The password for authentication.
101-
*/
102-
password: string
10351
}
10452

105-
/**
106-
* Contains OAuth authentication configuration.
107-
*/
108-
export interface OAuthAuthConfig {
109-
110-
type: AuthType.OAuth
111-
112-
/**
113-
* The Client Id for OAuth
114-
*/
115-
clientId: string
116-
117-
/**
118-
* The redirectUri for OAuth
119-
*/
120-
redirectUri?: string
121-
122-
/**
123-
* The temporary auth token for OAuth
124-
*/
125-
authToken?: string
126-
127-
/**
128-
* The expiration date for the temporary token
129-
*/
130-
authTokenExpires?: number
131-
132-
/**
133-
* The Refresh token for OAuth
134-
*/
135-
refreshToken?: string
136-
137-
/**
138-
* The expiration date for the Refresh token
139-
*/
140-
refreshTokenExpires?: number
141-
}
142-
143-
/**
144-
* Union type for authentication configurations.
145-
*/
146-
export type ArcGISAuthConfig =
147-
| TokenAuthConfig
148-
| UsernamePasswordAuthConfig
149-
| OAuthAuthConfig
15053

15154
/**
15255
* Attribute configurations

plugins/arcgis/service/src/ArcGISIdentityManagerFactory.ts

Lines changed: 0 additions & 119 deletions
This file was deleted.

plugins/arcgis/service/src/ArcGISPluginConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export const defaultArcGISPluginConfig = Object.freeze<ArcGISPluginConfig>({
145145
textAreaFieldLength: 256,
146146
observationIdField: 'description',
147147
idSeparator: '-',
148-
// eventIdField: 'event_id',
148+
eventIdField: 'event_id',
149149
lastEditedDateField: 'last_edited_date',
150150
eventNameField: 'event_name',
151151
userIdField: 'user_id',
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { ArcGISIdentityManager } from '@esri/arcgis-rest-request'
2+
import { FeatureServiceConfig } from './ArcGISConfig'
3+
import { PluginStateRepository } from '@ngageoint/mage.service/lib/plugins.api'
4+
5+
export interface ArcGISIdentityService {
6+
getIdentityManager(featureService: FeatureServiceConfig): Promise<ArcGISIdentityManager>
7+
updateIndentityManagers(): Promise<void>
8+
}
9+
10+
export function createArcGISIdentityService(
11+
stateRepo: PluginStateRepository<any>
12+
): ArcGISIdentityService {
13+
const identityManagerCache: Map<string, Promise<ArcGISIdentityManager>> = new Map()
14+
15+
return {
16+
async getIdentityManager(featureService: FeatureServiceConfig): Promise<ArcGISIdentityManager> {
17+
let cached = await identityManagerCache.get(featureService.url)
18+
if (!cached) {
19+
const identityManager = ArcGISIdentityManager.deserialize(featureService.identityManager)
20+
const promise = identityManager.getUser().then(() => identityManager)
21+
identityManagerCache.set(featureService.url, promise)
22+
return promise
23+
} else {
24+
return cached
25+
}
26+
},
27+
async updateIndentityManagers() {
28+
const config = await stateRepo.get()
29+
for (let [url, persistedIdentityManagerPromise] of identityManagerCache) {
30+
const persistedIdentityManager = await persistedIdentityManagerPromise
31+
const featureService: FeatureServiceConfig | undefined = config.featureServices.find((service: FeatureServiceConfig) => service.url === url)
32+
if (featureService) {
33+
const identityManager = ArcGISIdentityManager.deserialize(featureService.identityManager)
34+
if (identityManager.token !== persistedIdentityManager.token || identityManager.refreshToken !== persistedIdentityManager.refreshToken) {
35+
featureService.identityManager = persistedIdentityManager.serialize()
36+
await stateRepo.put(config)
37+
}
38+
}
39+
}
40+
}
41+
}
42+
}
43+
44+
export function getPortalUrl(featureService: FeatureServiceConfig | string): string {
45+
const url = getFeatureServiceUrl(featureService)
46+
return `https://${url.hostname}/arcgis/sharing/rest`
47+
}
48+
49+
export function getServerUrl(featureService: FeatureServiceConfig | string): string {
50+
const url = getFeatureServiceUrl(featureService)
51+
return `https://${url.hostname}/arcgis`
52+
}
53+
54+
export function getFeatureServiceUrl(featureService: FeatureServiceConfig | string): URL {
55+
const url = typeof featureService === 'string' ? featureService : featureService.url
56+
return new URL(url)
57+
}

plugins/arcgis/service/src/FeatureQuerier.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ export class FeatureQuerier {
6363
this._console.info('ArcGIS query: ' + queryUrl)
6464

6565
const queryResponse = await request(queryUrl.toString(), {
66-
authentication: this._identityManager
66+
authentication: this._identityManager,
67+
params: { f: 'json' }
6768
});
6869

6970
this._console.info('ArcGIS response for ' + queryUrl + ' ' + queryResponse.toString)
@@ -107,10 +108,9 @@ export class FeatureQuerier {
107108
queryUrl.searchParams.set('outFields', this.outFields([field]));
108109
queryUrl.searchParams.set('returnGeometry', 'false');
109110
this._console.info('ArcGIS query: ' + queryUrl)
110-
111+
111112
const queryResponse = await request(queryUrl.toString(), {
112113
authentication: this._identityManager
113-
114114
});
115115
this._console.info('ArcGIS response for ' + queryUrl + ' ' + queryResponse)
116116
const result = queryResponse as QueryObjectResult

plugins/arcgis/service/src/FeatureService.ts

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import { LayerInfoResult } from "./LayerInfoResult";
2-
import { FeatureServiceResult } from "./FeatureServiceResult";
3-
import { HttpClient } from "./HttpClient";
4-
import { getIdentityManager } from "./ArcGISIdentityManagerFactory"
51
import { ArcGISIdentityManager, request } from "@esri/arcgis-rest-request"
62
import { queryFeatures, applyEdits, IQueryFeaturesOptions } from "@esri/arcgis-rest-feature-service";
73
import { FeatureServiceConfig } from "./ArcGISConfig";
@@ -11,36 +7,21 @@ import { FeatureServiceConfig } from "./ArcGISConfig";
117
*/
128
export class FeatureService {
139

14-
/**
15-
* Used to make the get request about the feature layer.
16-
*/
17-
// private _httpClient: HttpClient;
18-
19-
/**
20-
* Used to log messages.
21-
*/
2210
private _console: Console;
11+
private _config: FeatureServiceConfig;
12+
private _identityManager: ArcGISIdentityManager;
2313

24-
private _config: FeatureServiceConfig;
25-
private _identityManager: ArcGISIdentityManager;
26-
27-
/**
28-
* Constructor.
29-
* @param console Used to log messages.
30-
* @param token The access token.
31-
*/
3214
constructor(console: Console, config: FeatureServiceConfig, identityManager: ArcGISIdentityManager) {
33-
this._config = config;
34-
this._identityManager = identityManager;
35-
// this._httpClient = new HttpClient(console, token);
15+
this._config = config;
16+
this._identityManager = identityManager;
3617
this._console = console;
3718
}
3819

3920
// TODO this entire class is a Work in Progress and not used. Currently using @esri/arcgis-rest-request and not arcgis-rest-js.
4021
// By finishing this class, we can transition from low-level generic requests that leverage ArcGISIdentityManager for auth to higher-level strongly typed requests.
4122

4223

43-
// Query features using arcgis-rest-js's queryFeatures
24+
// Query features using arcgis-rest-js's queryFeatures
4425
async queryFeatureService(whereClause: string): Promise<any> {
4526
const queryParams = {
4627
url: this._config.url,

0 commit comments

Comments
 (0)