diff --git a/src/parser/ShogunApplicationUtil.ts b/src/parser/ShogunApplicationUtil.ts index 673932e5e..d16773777 100644 --- a/src/parser/ShogunApplicationUtil.ts +++ b/src/parser/ShogunApplicationUtil.ts @@ -32,17 +32,17 @@ import { MapUtil } from '@terrestris/ol-util/dist/MapUtil/MapUtil'; import Application, { DefaultLayerTree } from '../model/Application'; import Layer from '../model/Layer'; -import SHOGunClient from '../service/SHOGunClient'; +import SHOGunAPIClient from '../service/SHOGunAPIClient'; import { getBearerTokenHeader } from '../security/getBearerTokenHeader'; export interface ShogunApplicationUtilOpts { - client?: SHOGunClient; + client?: SHOGunAPIClient; } class ShogunApplicationUtil { - private client: SHOGunClient | undefined; + private client: SHOGunAPIClient | undefined; constructor(opts?: ShogunApplicationUtilOpts) { // TODO Default client? diff --git a/src/service/SHOGunClient.spec.ts b/src/service/SHOGunAPIClient.spec.ts similarity index 93% rename from src/service/SHOGunClient.spec.ts rename to src/service/SHOGunAPIClient.spec.ts index 06622658b..f399fcb99 100644 --- a/src/service/SHOGunClient.spec.ts +++ b/src/service/SHOGunAPIClient.spec.ts @@ -13,7 +13,7 @@ import GroupService from './GroupService'; import fetchSpy, { successResponse } from '../spec/fetchSpy'; -import SHOGunClient from './SHOGunClient'; +import SHOGunAPIClient from './SHOGunAPIClient'; import CacheService from './CacheService'; import FileService from './FileService'; import ImageFileService from './ImageFileService'; @@ -37,12 +37,12 @@ export default class MyApplication extends Application { } } -describe('SHOGunClient', () => { +describe('SHOGunAPIClient', () => { let fetchMock: jest.SpyInstance; - let client: SHOGunClient; + let client: SHOGunAPIClient; beforeEach(() => { - client = new SHOGunClient(); + client = new SHOGunAPIClient(); }); afterEach(() => { @@ -53,7 +53,7 @@ describe('SHOGunClient', () => { }); it('is defined', () => { - expect(SHOGunClient).toBeDefined(); + expect(SHOGunAPIClient).toBeDefined(); }); it('can be instantiated', async () => { diff --git a/src/service/SHOGunAPIClient.ts b/src/service/SHOGunAPIClient.ts new file mode 100644 index 000000000..ee736e074 --- /dev/null +++ b/src/service/SHOGunAPIClient.ts @@ -0,0 +1,197 @@ +import Keycloak from 'keycloak-js'; + +import Application from '../model/Application'; +import File from '../model/File'; +import Group, { ProviderGroupDetails } from '../model/Group'; +import ImageFile from '../model/ImageFile'; +import Layer from '../model/Layer'; +import User, { ProviderUserDetails } from '../model/User'; + +import AppInfoService from './AppInfoService'; +import ApplicationService from './ApplicationService'; +import AuthService from './AuthService'; +import CacheService from './CacheService'; +import FileService from './FileService'; +import GraphQLService from './GraphQLService'; +import GroupService from './GroupService'; +import ImageFileService from './ImageFileService'; +import LayerService from './LayerService'; +import OpenAPIService from './OpenAPIService'; +import UserService from './UserService'; + +export interface SHOGunAPIClientOpts { + /** + * The URL to the SHOGun instance, e.g. '/api'. The default is to '/'. + */ + url: string; + + /** + * The keycloak instance. + */ + keycloak?: Keycloak; +} + +export class SHOGunAPIClient { + + private basePath: string; + + private keycloak?: Keycloak; + + private cacheService?: CacheService; + private appInfoService?: AppInfoService; + private applicationService?: ApplicationService; + private layerService?: LayerService; + private groupService?: GroupService; + private userService?: UserService; + private fileService?: FileService; + private imageFileService?: ImageFileService; + private authService?: AuthService; + private graphqlService?: GraphQLService; + private openapiService?: OpenAPIService; + + constructor(opts: SHOGunAPIClientOpts = { + url: '/' + }) { + this.basePath = opts.url; + this.keycloak = opts.keycloak; + } + + cache(): CacheService { + if (!this.cacheService) { + this.cacheService = new CacheService({ + basePath: `${this.basePath}cache`, + keycloak: this.keycloak + }); + } + + return this.cacheService; + } + + info(): AppInfoService { + if (!this.appInfoService) { + this.appInfoService = new AppInfoService({ + basePath: `${this.basePath}info`, + keycloak: this.keycloak + }); + } + + return this.appInfoService; + } + + application(): ApplicationService { + if (!this.applicationService) { + this.applicationService = new ApplicationService({ + basePath: `${this.basePath}applications`, + keycloak: this.keycloak + }); + } + + return this.applicationService; + } + + layer(): LayerService { + if (!this.layerService) { + this.layerService = new LayerService({ + basePath: `${this.basePath}layers`, + keycloak: this.keycloak + }); + } + + return this.layerService; + } + + group, S extends ProviderGroupDetails>(): GroupService { + if (!this.groupService) { + this.groupService = new GroupService({ + basePath: `${this.basePath}groups`, + keycloak: this.keycloak + }); + } + + return this.groupService; + } + + user, S extends ProviderUserDetails>(): UserService { + if (!this.userService) { + this.userService = new UserService({ + basePath: `${this.basePath}users`, + keycloak: this.keycloak + }); + } + + return this.userService; + } + + file(): FileService { + if (!this.fileService) { + this.fileService = new FileService({ + basePath: `${this.basePath}files`, + keycloak: this.keycloak + }); + } + + return this.fileService; + } + + imagefile(): ImageFileService { + if (!this.imageFileService) { + this.imageFileService = new ImageFileService({ + basePath: `${this.basePath}imagefiles`, + keycloak: this.keycloak + }); + } + + return this.imageFileService; + } + + auth(): AuthService { + if (!this.authService) { + this.authService = new AuthService({ + basePath: `${this.basePath}sso`, + keycloak: this.keycloak + }); + } + + return this.authService; + } + + graphql(): GraphQLService { + if (!this.graphqlService) { + this.graphqlService = new GraphQLService({ + basePath: `${this.basePath}graphql`, + keycloak: this.keycloak + }); + } + + return this.graphqlService; + } + + openapi(): OpenAPIService { + if (!this.openapiService) { + this.openapiService = new OpenAPIService({ + basePath: `${this.basePath}v2`, + keycloak: this.keycloak + }); + } + + return this.openapiService; + } + + getBasePath() { + return this.basePath; + } + + setBasePath(basePath: string) { + this.basePath = basePath; + } + + getKeycloak() { + return this.keycloak; + } + + setKeycloak(keycloak: Keycloak) { + this.keycloak = keycloak; + } +} + +export default SHOGunAPIClient; diff --git a/src/service/SHOGunClient.ts b/src/service/SHOGunClient.ts deleted file mode 100644 index 44ab55aa9..000000000 --- a/src/service/SHOGunClient.ts +++ /dev/null @@ -1,141 +0,0 @@ -import Keycloak from 'keycloak-js'; - -import Application from '../model/Application'; -import File from '../model/File'; -import Group, { ProviderGroupDetails } from '../model/Group'; -import ImageFile from '../model/ImageFile'; -import Layer from '../model/Layer'; -import User, { ProviderUserDetails } from '../model/User'; - -import AppInfoService from './AppInfoService'; -import ApplicationService from './ApplicationService'; -import AuthService from './AuthService'; -import CacheService from './CacheService'; -import FileService from './FileService'; -import GraphQLService from './GraphQLService'; -import GroupService from './GroupService'; -import ImageFileService from './ImageFileService'; -import LayerService from './LayerService'; -import OpenAPIService from './OpenAPIService'; -import UserService from './UserService'; - -export interface SHOGunClientOpts { - /** - * The URL to the SHOGun instance, e.g. '/api'. The default is to '/'. - */ - url: string; - - /** - * The keycloak instance. - */ - keycloak?: Keycloak; -} - -export class SHOGunClient { - - private basePath: string; - - private keycloak?: Keycloak; - - constructor(opts: SHOGunClientOpts = { - url: '/' - }) { - this.basePath = opts.url; - this.keycloak = opts.keycloak; - } - - cache() { - return new CacheService({ - basePath: `${this.basePath}cache`, - keycloak: this.keycloak - }); - } - - info() { - return new AppInfoService({ - basePath: `${this.basePath}info`, - keycloak: this.keycloak - }); - } - - application() { - return new ApplicationService({ - basePath: `${this.basePath}applications`, - keycloak: this.keycloak - }); - } - - layer() { - return new LayerService({ - basePath: `${this.basePath}layers`, - keycloak: this.keycloak - }); - } - - group, S extends ProviderGroupDetails>() { - return new GroupService({ - basePath: `${this.basePath}groups`, - keycloak: this.keycloak - }); - } - - user, S extends ProviderUserDetails>() { - return new UserService({ - basePath: `${this.basePath}users`, - keycloak: this.keycloak - }); - } - - file() { - return new FileService({ - basePath: `${this.basePath}files`, - keycloak: this.keycloak - }); - } - - imagefile() { - return new ImageFileService({ - basePath: `${this.basePath}imagefiles`, - keycloak: this.keycloak - }); - } - - auth() { - return new AuthService({ - basePath: `${this.basePath}sso`, - keycloak: this.keycloak - }); - } - - graphql() { - return new GraphQLService({ - basePath: `${this.basePath}graphql`, - keycloak: this.keycloak - }); - } - - openapi() { - return new OpenAPIService({ - basePath: `${this.basePath}v2`, - keycloak: this.keycloak - }); - } - - getBasePath() { - return this.basePath; - } - - setBasePath(basePath: string) { - this.basePath = basePath; - } - - getKeycloak() { - return this.keycloak; - } - - setKeycloak(keycloak: Keycloak) { - this.keycloak = keycloak; - } -} - -export default SHOGunClient;