-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the PDFv2 export type to new export types plugin (#158766)
## Summary This partially addresses #158092 This PR refactors the generic function getExportType(). This PR is concerned only with the PDF export type and refactors it into a class instance. This class is then used in the request handler and the execute report functionality in Reporting. The execute_report.test.ts is removed in this PR and will be part of the clean up needed in a subsequent PR once CSV and PNG are also refactored to class instances instead of the getExportType() function.
- Loading branch information
Showing
53 changed files
with
943 additions
and
3,009 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
x-pack/plugins/reporting/server/export_types/common/export_type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { | ||
IBasePath, | ||
Headers, | ||
Logger, | ||
CoreKibanaRequest, | ||
CoreSetup, | ||
FakeRawRequest, | ||
HttpServiceSetup, | ||
KibanaRequest, | ||
PluginInitializerContext, | ||
SavedObjectsClientContract, | ||
SavedObjectsServiceStart, | ||
UiSettingsServiceStart, | ||
} from '@kbn/core/server'; | ||
import { LicenseType } from '@kbn/licensing-plugin/common/types'; | ||
import { ScreenshottingStart } from '@kbn/screenshotting-plugin/server'; | ||
import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common'; | ||
import { SpacesPluginSetup } from '@kbn/spaces-plugin/server'; | ||
import { ReportingConfigType } from '../../config'; | ||
import { ReportingServerInfo } from '../../core'; | ||
import { CreateJobFn, ReportingStart, RunTaskFn } from '../../types'; | ||
|
||
/** | ||
* @TODO move to be within @kbn-reporting-export-types | ||
*/ | ||
export interface ExportTypeSetupDeps { | ||
basePath: Pick<IBasePath, 'set'>; | ||
spaces?: SpacesPluginSetup; | ||
} | ||
|
||
export interface ExportTypeStartDeps { | ||
savedObjects: SavedObjectsServiceStart; | ||
uiSettings: UiSettingsServiceStart; | ||
screenshotting: ScreenshottingStart; | ||
reporting: ReportingStart; | ||
} | ||
|
||
export abstract class ExportType< | ||
JobParamsType extends object = any, | ||
TaskPayloadType extends object = any | ||
> { | ||
abstract id: string; // ID for exportTypesRegistry.get() | ||
abstract name: string; // user-facing string | ||
abstract jobType: string; // for job params | ||
|
||
abstract jobContentEncoding?: 'base64' | 'csv'; | ||
abstract jobContentExtension: 'pdf' | 'png' | 'csv'; | ||
|
||
abstract createJob: CreateJobFn<JobParamsType>; | ||
abstract runTask: RunTaskFn<TaskPayloadType>; | ||
|
||
abstract validLicenses: LicenseType[]; | ||
|
||
public setupDeps!: ExportTypeSetupDeps; | ||
public startDeps!: ExportTypeStartDeps; | ||
public http!: HttpServiceSetup; | ||
|
||
constructor( | ||
core: CoreSetup, | ||
public config: ReportingConfigType, | ||
public logger: Logger, | ||
public context: PluginInitializerContext<ReportingConfigType> | ||
) { | ||
this.http = core.http; | ||
} | ||
|
||
setup(setupDeps: ExportTypeSetupDeps) { | ||
this.setupDeps = setupDeps; | ||
} | ||
start(startDeps: ExportTypeStartDeps) { | ||
this.startDeps = startDeps; | ||
} | ||
|
||
private async getSavedObjectsClient(request: KibanaRequest) { | ||
const { savedObjects } = this.startDeps; | ||
return savedObjects.getScopedClient(request) as SavedObjectsClientContract; | ||
} | ||
|
||
private getUiSettingsServiceFactory(savedObjectsClient: SavedObjectsClientContract) { | ||
const { uiSettings: uiSettingsService } = this.startDeps; | ||
const scopedUiSettingsService = uiSettingsService.asScopedToClient(savedObjectsClient); | ||
return scopedUiSettingsService; | ||
} | ||
|
||
protected async getUiSettingsClient(request: KibanaRequest, logger = this.logger) { | ||
const spacesService = this.setupDeps.spaces?.spacesService; | ||
const spaceId = this.startDeps.reporting.getSpaceId(request, logger); | ||
|
||
if (spacesService && spaceId) { | ||
logger.info(`Creating UI Settings Client for space: ${spaceId}`); | ||
} | ||
const savedObjectsClient = await this.getSavedObjectsClient(request); | ||
return this.getUiSettingsServiceFactory(savedObjectsClient); | ||
} | ||
|
||
protected getFakeRequest( | ||
headers: Headers, | ||
spaceId: string | undefined, | ||
logger = this.logger | ||
): KibanaRequest { | ||
const rawRequest: FakeRawRequest = { | ||
headers, | ||
path: '/', | ||
}; | ||
const fakeRequest = CoreKibanaRequest.from(rawRequest); | ||
|
||
const spacesService = this.setupDeps.spaces?.spacesService; | ||
if (spacesService) { | ||
if (spaceId && spaceId !== DEFAULT_SPACE_ID) { | ||
logger.info(`Generating request for space: ${spaceId}`); | ||
this.setupDeps.basePath.set(fakeRequest, `/s/${spaceId}`); | ||
} | ||
} | ||
return fakeRequest; | ||
} | ||
|
||
/* | ||
* Returns configurable server info | ||
*/ | ||
protected getServerInfo(): ReportingServerInfo { | ||
const serverInfo = this.http.getServerInfo(); | ||
return { | ||
basePath: this.http.basePath.serverBasePath, | ||
hostname: serverInfo.hostname, | ||
name: serverInfo.name, | ||
port: serverInfo.port, | ||
uuid: this.context.env.instanceUuid, | ||
protocol: serverInfo.protocol, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 0 additions & 19 deletions
19
x-pack/plugins/reporting/server/export_types/printable_pdf_v2/create_job.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.