-
Notifications
You must be signed in to change notification settings - Fork 14
[OGUI-1783] Backend download post request #3139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 4 commits
95a5088
146af18
2a0ea62
74b0853
4731299
f2a4272
afcdf76
eb37754
d472cc2
489dc00
4d3aa4a
dd99118
2cf0c0c
cca21e8
a840d30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,12 +25,16 @@ | |
| updateAndSendExpressResponseFromNativeError, | ||
| } | ||
| from '@aliceo2/web-ui'; | ||
| import { parseRequestToLayout } from '../utils/download/configurator.js'; | ||
| import { MapStorage } from '../utils/download/classes/domain/MapStorage.js'; | ||
| import { saveDownloadData } from '../utils/download/DownloadEngine.js'; | ||
|
|
||
| /** | ||
| * @typedef {import('../repositories/LayoutRepository.js').LayoutRepository} LayoutRepository | ||
| */ | ||
|
|
||
| const logger = LogManager.getLogger(`${process.env.npm_config_log_label ?? 'qcg'}/layout-ctrl`); | ||
| const mapStorage = new MapStorage(); | ||
|
|
||
| /** | ||
| * Gateway for all HTTP requests with regards to QCG Layouts | ||
|
|
@@ -219,6 +223,22 @@ | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Store layout data for later download request. | ||
| * @param {Request<import('../utils/download/configurator.js').Query>}req | ||
|
Check warning on line 228 in QualityControl/lib/controllers/LayoutController.js
|
||
| * @param {Response} res | ||
|
Check warning on line 229 in QualityControl/lib/controllers/LayoutController.js
|
||
| */ | ||
| async postDownloadHandler(req, res) { | ||
| try { | ||
| const downloadLayoutDomain = parseRequestToLayout(req); | ||
| const userId = Number(req.query.user_id ?? 0); | ||
| const key = saveDownloadData(mapStorage, downloadLayoutDomain, userId); | ||
| res.status(201).send(key); | ||
| } catch { | ||
| res.status(400).send('Could not save download data'); | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Patch a layout entity with information as per LayoutPatchDto.js | ||
| * @param {Request} req - HTTP request object with "params" and "body" information on layout | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { DownloadMode } from '../../enum/DownloadMode.js'; | ||
|
|
||
| export class DownloadConfigData { | ||
| /** | ||
| * constructor | ||
| * @param {string[]} tabIds | ||
| * @param {string[]} objectIds | ||
| * @param {string[]} archiveNameTemplateOptions | ||
| * @param {string[]} objectNameTemplateOptions | ||
| * @param {string} downloadMode | ||
| * @param {boolean} pathNameStructure | ||
| */ | ||
| // eslint-disable-next-line @stylistic/js/max-len | ||
| constructor(tabIds, objectIds, archiveNameTemplateOptions, objectNameTemplateOptions, downloadMode, pathNameStructure) { | ||
| this.tabIds = tabIds, | ||
| this.objectIds = objectIds, | ||
| this.archiveNameTemplateOptions = archiveNameTemplateOptions, | ||
| this.objectNameTemplateOptions = objectNameTemplateOptions, | ||
| this.downloadMode = downloadMode, | ||
| this.pathNameStructure = pathNameStructure; | ||
| } | ||
|
|
||
| tabIds; | ||
|
|
||
| objectIds; | ||
|
|
||
| archiveNameTemplateOptions; | ||
|
|
||
| objectNameTemplateOptions; | ||
|
|
||
| downloadMode; | ||
|
|
||
| pathNameStructure; | ||
|
|
||
| /** | ||
| * mapper from plain object to instance of DownloadConfigData. | ||
| * @static | ||
| * @param {any} downloadConfigPlain | ||
| * @returns {DownloadConfigData} | ||
| */ | ||
| static mapFromPlain(downloadConfigPlain) { | ||
| if (!downloadConfigPlain || typeof downloadConfigPlain !== 'object') { | ||
| throw new Error('invalid DownloadConfig'); | ||
| } | ||
| // eslint-disable-next-line @stylistic/js/max-len | ||
| return new DownloadConfigData(Array.isArray(downloadConfigPlain.tabIds) ? downloadConfigPlain.tabIds : downloadConfigPlain.tabIds?.split(',') ?? [], Array.isArray(downloadConfigPlain.objectIds) ? downloadConfigPlain.objectIds : downloadConfigPlain.objectIds?.split(',') ?? [], Array.isArray(downloadConfigPlain.archiveNameTemplateOptions) ? downloadConfigPlain.archiveNameTemplateOptions : downloadConfigPlain.archiveNameTemplateOptions?.split(',') ?? [], Array.isArray(downloadConfigPlain.objectNameTemplateOptions) ? downloadConfigPlain.objectNameTemplateOptions : downloadConfigPlain.objectNameTemplateOptions?.split(',') ?? [], downloadConfigPlain?.downloadMode ?? DownloadMode.object, downloadConfigPlain?.pathNameStructure == 'true' ? true : false); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { LayoutDomain } from '../../classes/domain/LayoutDomain.js'; | ||
| import { TabData } from './TabData.js'; | ||
| export class LayoutData { | ||
| /** | ||
| * constructor | ||
| * @param {string} id | ||
| * @param {string} name | ||
| * @param {number} owner_id | ||
| * @param {string} owner_name | ||
| * @param {TabData[]} tabs | ||
| * @param {any[]} collaborators | ||
| * @param {boolean} displayTimestamp | ||
| * @param {number} autoTabChange | ||
| * @param {boolean} isOfficial | ||
| */ | ||
| constructor(id, name, owner_id, owner_name, tabs, collaborators, displayTimestamp, autoTabChange, isOfficial) { | ||
| this.id = id; | ||
| this.name = name, | ||
| this.owner_id = owner_id, | ||
| this.owner_name = owner_name, | ||
| this.tabs = tabs, | ||
| this.collaborators = collaborators, | ||
| this.displayTimestamp = displayTimestamp, | ||
| this.autoTabChange = autoTabChange, | ||
| this.isOfficial = isOfficial; | ||
| } | ||
|
|
||
| id; | ||
|
|
||
| name; | ||
|
|
||
| owner_id; | ||
|
|
||
| owner_name; | ||
|
|
||
| tabs; | ||
|
|
||
| collaborators; | ||
|
|
||
| displayTimestamp; | ||
|
|
||
| autoTabChange; | ||
|
|
||
| isOfficial; | ||
|
|
||
| /** | ||
| * map to an instance of LayoutData from a plain object. | ||
| * @static | ||
| * @param {any} layoutPlain | ||
| * @returns {LayoutData} | ||
| */ | ||
| static mapFromPlain(layoutPlain) { | ||
| if (!layoutPlain || typeof layoutPlain !== 'object' || layoutPlain.id == undefined) { | ||
| throw new Error('invalid layout'); | ||
| } | ||
| // eslint-disable-next-line @stylistic/js/max-len | ||
| return new LayoutData(layoutPlain.id, layoutPlain.name, Number(layoutPlain.owner_id), layoutPlain.owner_name, Array.isArray(layoutPlain.tabs) ? layoutPlain.tabs.map(TabData.mapFromPlain) : [], Array.isArray(layoutPlain.collaborators) ? layoutPlain.collaborators : [], Boolean(layoutPlain.displayTimestamp), Number(layoutPlain.autoTabChange), Boolean(layoutPlain.isOfficial)); | ||
| } | ||
|
|
||
| /** | ||
| * mapper to Domain model | ||
| * @returns {LayoutDomain} Resulting LayoutDomain. | ||
| */ | ||
| mapToDomain() { | ||
| return new LayoutDomain(this.id, this.name, this.tabs.map((tab) => tab.mapToDomain())); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { ObjectDomain } from '../../classes/domain/ObjectDomain.js'; | ||
| export class ObjectData { | ||
| /** | ||
| * constructor | ||
| * @param {string} id | ||
| * @param {number} x | ||
| * @param {number} y | ||
| * @param {number} h | ||
| * @param {number} w | ||
| * @param {string} name | ||
| * @param {string[]} options | ||
| * @param {boolean} autoSize | ||
| * @param {boolean} ignoreDefaults | ||
| */ | ||
| constructor(id, x, y, h, w, name, options, autoSize, ignoreDefaults) { | ||
| this.id = id, | ||
| this.x = x, | ||
| this.y = y, | ||
| this.h = h, | ||
| this.w = w, | ||
| this.name = name; | ||
| this.options = options, | ||
| this.autoSize = autoSize, | ||
| this.ignoreDefaults = ignoreDefaults; | ||
| } | ||
|
|
||
| id; | ||
|
|
||
| x; | ||
|
|
||
| y; | ||
|
|
||
| h; | ||
|
|
||
| w; | ||
|
|
||
| name; | ||
|
|
||
| options; | ||
|
|
||
| autoSize; | ||
|
|
||
| ignoreDefaults; | ||
|
|
||
| /** | ||
| * mapper to map from plain object to instance of ObjectData. | ||
| * @static | ||
| * @param {any} objectPlain | ||
| * @returns {ObjectData} | ||
| */ | ||
| static mapFromPlain(objectPlain) { | ||
| if (!objectPlain || typeof objectPlain !== 'object') { | ||
| throw new Error('invalid object'); | ||
| } | ||
| // eslint-disable-next-line @stylistic/js/max-len | ||
| return new ObjectData(objectPlain.id, Number(objectPlain.x ?? 0), Number(objectPlain.y ?? 0), Number(objectPlain.h ?? 0), Number(objectPlain.w ?? 0), objectPlain.name, Array.isArray(objectPlain.options) ? objectPlain.options : [], Boolean(objectPlain.autoSize), Boolean(objectPlain.ignoreDefaults)); | ||
| } | ||
|
|
||
| /** | ||
| * mapper to domain model. | ||
| * @returns {ObjectDomain} | ||
| */ | ||
| mapToDomain() { | ||
| return new ObjectDomain(this.id, this.name); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { TabDomain } from '../domain/TabDomain.js'; | ||
| import { ObjectData } from './ObjectData.js'; | ||
|
|
||
| export class TabData { | ||
| /** | ||
| * constructor | ||
| * @param {string} id | ||
| * @param {string} name | ||
| * @param {ObjectData[]} objects | ||
| * @param {number} columns | ||
| */ | ||
| constructor(id, name, objects, columns) { | ||
| this.id = id, | ||
| this.name = name, | ||
| this.objects = objects, | ||
| this.columns = columns; | ||
| } | ||
|
|
||
| id; | ||
|
|
||
| name; | ||
|
|
||
| objects; | ||
|
|
||
| columns; | ||
|
|
||
| /** | ||
| * mapFromPlain, map to an instance of TabData from a plain object. | ||
| * @static | ||
| * @param {any} tabPlain | ||
| * @returns {TabData} | ||
| */ | ||
| static mapFromPlain(tabPlain) { | ||
| if (!tabPlain || typeof tabPlain !== 'object') { | ||
| throw new Error('invalid tab'); | ||
| } | ||
| // eslint-disable-next-line @stylistic/js/max-len | ||
| return new TabData(tabPlain.id, tabPlain.name, Array.isArray(tabPlain.objects) ? tabPlain.objects.map(ObjectData.mapFromPlain) : [], Number(tabPlain.columns)); | ||
| } | ||
|
|
||
| /** | ||
| * mapper to Domain model. | ||
| * @returns {TabDomain} | ||
| */ | ||
| mapToDomain() { | ||
| return new TabDomain(this.id, this.name, this.objects.map((object) => object.mapToDomain())); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| export class DownloadConfigDomain { | ||
| /** | ||
| * constructor | ||
| * @param {string[]} tabIds | ||
| * @param {string[]} objectIds | ||
| * @param {NameTemplateOption[]} archiveNameTemplateOptions | ||
| * @param {NameTemplateOption[]} objectNameTemplateOptions | ||
| * @param {DownloadMode} downloadMode | ||
| * @param {boolean} pathNameStructure | ||
| */ | ||
| constructor( | ||
| tabIds, objectIds, archiveNameTemplateOptions, | ||
| objectNameTemplateOptions, downloadMode, pathNameStructure, | ||
| ) { | ||
| this.tabIds = tabIds, | ||
| this.objectIds = objectIds, | ||
| this.archiveNameTemplateOptions = archiveNameTemplateOptions, | ||
| this.objectNameTemplateOptions = objectNameTemplateOptions, | ||
| this.downloadMode = downloadMode, | ||
| this.pathNameStructure = pathNameStructure; | ||
| } | ||
|
|
||
| tabIds; | ||
|
|
||
| objectIds; | ||
|
|
||
| archiveNameTemplateOptions; | ||
|
|
||
| objectNameTemplateOptions; | ||
|
|
||
| downloadMode; | ||
|
|
||
| pathNameStructure; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // eslint-disable-next-line no-unused-vars | ||
| import { TabDomain } from './TabDomain.js'; | ||
|
|
||
| export class LayoutDomain { | ||
| /** | ||
| * constructor | ||
| * @param {string} id - id | ||
| * @param {string} name - name | ||
| * @param {TabDomain[]} tabs - tabs | ||
| */ | ||
| constructor(id, name, tabs) { | ||
| this.id = id, | ||
| this.name = name, | ||
| this.tabs = tabs; | ||
| } | ||
|
|
||
| id; | ||
|
|
||
| name; | ||
|
|
||
| tabs; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.