Skip to content

Commit

Permalink
Merge branch 'switch-httpClient-to-esri-library' of https://github.co…
Browse files Browse the repository at this point in the history
…m/ngageoint/mage-server into switch-httpClient-to-esri-library
  • Loading branch information
ryanslatten committed Nov 7, 2024
2 parents 10b5444 + ed561a7 commit 86fb706
Show file tree
Hide file tree
Showing 10 changed files with 992 additions and 1,225 deletions.
107 changes: 5 additions & 102 deletions plugins/arcgis/service/src/ArcGISConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,11 @@ export interface FeatureServiceConfig {
*/
url: string

/**
* Username and password for ArcGIS authentication
*/
auth?: ArcGISAuthConfig

/**
* Create layers that don't exist
*/
createLayers?: boolean

/**
* The administration url to the arc feature service.
*/
adminUrl?: string

/**
* Administration access token
*/
adminToken?: string

/**
* Serialized ArcGISIdentityManager
*/
identityManager: string

/**
* The feature layers.
*/
Expand All @@ -49,10 +34,6 @@ export interface FeatureLayerConfig {
*/
geometryType?: string

/**
* Access token
*/
token?: string // TODO - can this be removed? Will Layers have a token too?
/**
* The event ids or names that sync to this arc feature layer.
*/
Expand All @@ -67,86 +48,8 @@ export interface FeatureLayerConfig {
* Delete editable layer fields missing from form fields
*/
deleteFields?: boolean

}

export enum AuthType {
Token = 'token',
UsernamePassword = 'usernamePassword',
OAuth = 'oauth'
}


/**
* Contains token-based authentication configuration.
*/
export interface TokenAuthConfig {
type: AuthType.Token
token: string
authTokenExpires?: string
}

/**
* Contains username and password for ArcGIS server authentication.
*/
export interface UsernamePasswordAuthConfig {
type: AuthType.UsernamePassword
/**
* The username for authentication.
*/
username: string

/**
* The password for authentication.
*/
password: string
}

/**
* Contains OAuth authentication configuration.
*/
export interface OAuthAuthConfig {

type: AuthType.OAuth

/**
* The Client Id for OAuth
*/
clientId: string

/**
* The redirectUri for OAuth
*/
redirectUri?: string

/**
* The temporary auth token for OAuth
*/
authToken?: string

/**
* The expiration date for the temporary token
*/
authTokenExpires?: number

/**
* The Refresh token for OAuth
*/
refreshToken?: string

/**
* The expiration date for the Refresh token
*/
refreshTokenExpires?: number
}

/**
* Union type for authentication configurations.
*/
export type ArcGISAuthConfig =
| TokenAuthConfig
| UsernamePasswordAuthConfig
| OAuthAuthConfig

/**
* Attribute configurations
Expand Down
119 changes: 0 additions & 119 deletions plugins/arcgis/service/src/ArcGISIdentityManagerFactory.ts

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/arcgis/service/src/ArcGISPluginConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export const defaultArcGISPluginConfig = Object.freeze<ArcGISPluginConfig>({
textAreaFieldLength: 256,
observationIdField: 'description',
idSeparator: '-',
// eventIdField: 'event_id',
eventIdField: 'event_id',
lastEditedDateField: 'last_edited_date',
eventNameField: 'event_name',
userIdField: 'user_id',
Expand Down
57 changes: 57 additions & 0 deletions plugins/arcgis/service/src/ArcGISService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { ArcGISIdentityManager } from '@esri/arcgis-rest-request'
import { FeatureServiceConfig } from './ArcGISConfig'
import { PluginStateRepository } from '@ngageoint/mage.service/lib/plugins.api'

export interface ArcGISIdentityService {
getIdentityManager(featureService: FeatureServiceConfig): Promise<ArcGISIdentityManager>
updateIndentityManagers(): Promise<void>
}

export function createArcGISIdentityService(
stateRepo: PluginStateRepository<any>
): ArcGISIdentityService {
const identityManagerCache: Map<string, Promise<ArcGISIdentityManager>> = new Map()

return {
async getIdentityManager(featureService: FeatureServiceConfig): Promise<ArcGISIdentityManager> {
let cached = await identityManagerCache.get(featureService.url)
if (!cached) {
const identityManager = ArcGISIdentityManager.deserialize(featureService.identityManager)
const promise = identityManager.getUser().then(() => identityManager)
identityManagerCache.set(featureService.url, promise)
return promise
} else {
return cached
}
},
async updateIndentityManagers() {
const config = await stateRepo.get()
for (let [url, persistedIdentityManagerPromise] of identityManagerCache) {
const persistedIdentityManager = await persistedIdentityManagerPromise
const featureService: FeatureServiceConfig | undefined = config.featureServices.find((service: FeatureServiceConfig) => service.url === url)
if (featureService) {
const identityManager = ArcGISIdentityManager.deserialize(featureService.identityManager)
if (identityManager.token !== persistedIdentityManager.token || identityManager.refreshToken !== persistedIdentityManager.refreshToken) {
featureService.identityManager = persistedIdentityManager.serialize()
await stateRepo.put(config)
}
}
}
}
}
}

export function getPortalUrl(featureService: FeatureServiceConfig | string): string {
const url = getFeatureServiceUrl(featureService)
return `https://${url.hostname}/arcgis/sharing/rest`
}

export function getServerUrl(featureService: FeatureServiceConfig | string): string {
const url = getFeatureServiceUrl(featureService)
return `https://${url.hostname}/arcgis`
}

export function getFeatureServiceUrl(featureService: FeatureServiceConfig | string): URL {
const url = typeof featureService === 'string' ? featureService : featureService.url
return new URL(url)
}
6 changes: 3 additions & 3 deletions plugins/arcgis/service/src/FeatureQuerier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export class FeatureQuerier {
this._console.info('ArcGIS query: ' + queryUrl)

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

this._console.info('ArcGIS response for ' + queryUrl + ' ' + queryResponse.toString)
Expand Down Expand Up @@ -107,10 +108,9 @@ export class FeatureQuerier {
queryUrl.searchParams.set('outFields', this.outFields([field]));
queryUrl.searchParams.set('returnGeometry', 'false');
this._console.info('ArcGIS query: ' + queryUrl)

const queryResponse = await request(queryUrl.toString(), {
authentication: this._identityManager

});
this._console.info('ArcGIS response for ' + queryUrl + ' ' + queryResponse)
const result = queryResponse as QueryObjectResult
Expand Down
29 changes: 5 additions & 24 deletions plugins/arcgis/service/src/FeatureService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import { LayerInfoResult } from "./LayerInfoResult";
import { FeatureServiceResult } from "./FeatureServiceResult";
import { HttpClient } from "./HttpClient";
import { getIdentityManager } from "./ArcGISIdentityManagerFactory"
import { ArcGISIdentityManager, request } from "@esri/arcgis-rest-request"
import { queryFeatures, applyEdits, IQueryFeaturesOptions } from "@esri/arcgis-rest-feature-service";
import { FeatureServiceConfig } from "./ArcGISConfig";
Expand All @@ -11,36 +7,21 @@ import { FeatureServiceConfig } from "./ArcGISConfig";
*/
export class FeatureService {

/**
* Used to make the get request about the feature layer.
*/
// private _httpClient: HttpClient;

/**
* Used to log messages.
*/
private _console: Console;
private _config: FeatureServiceConfig;
private _identityManager: ArcGISIdentityManager;

private _config: FeatureServiceConfig;
private _identityManager: ArcGISIdentityManager;

/**
* Constructor.
* @param console Used to log messages.
* @param token The access token.
*/
constructor(console: Console, config: FeatureServiceConfig, identityManager: ArcGISIdentityManager) {
this._config = config;
this._identityManager = identityManager;
// this._httpClient = new HttpClient(console, token);
this._config = config;
this._identityManager = identityManager;
this._console = console;
}

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


// Query features using arcgis-rest-js's queryFeatures
// Query features using arcgis-rest-js's queryFeatures
async queryFeatureService(whereClause: string): Promise<any> {
const queryParams = {
url: this._config.url,
Expand Down
Loading

0 comments on commit 86fb706

Please sign in to comment.