- added the possibility to delete 'inprogress' dataset again for the submitter - concat run commands insider Dockerfile for better docker image - npm updates - add own Exception classes HttpException.ts and InternalServerException.ts
This commit is contained in:
parent
b6b1c90ff8
commit
6fa22aad9b
18 changed files with 473 additions and 251 deletions
|
@ -14,7 +14,7 @@ export default class DatasetController {
|
|||
return datasets;
|
||||
}
|
||||
|
||||
public async findAll({ response }: HttpContextContract) {
|
||||
public async findAll({ response }: HttpContextContract) {
|
||||
try {
|
||||
const datasets = await Dataset.query()
|
||||
.where('server_state', 'published')
|
||||
|
|
|
@ -18,15 +18,7 @@ export default class HomeController {
|
|||
// .orderBy('server_date_published');
|
||||
|
||||
const datasets = await Database.from('documents as doc')
|
||||
.select([
|
||||
'publish_id',
|
||||
'server_date_published',
|
||||
Database.raw(`date_part('year', server_date_published) as pub_year`)
|
||||
],
|
||||
// Database
|
||||
// .raw('select "ip_address" from "user_logins" where "users.id" = "user_logins.user_id" limit 1')
|
||||
// .wrap('(', ')')
|
||||
)
|
||||
.select(['publish_id', 'server_date_published', Database.raw(`date_part('year', server_date_published) as pub_year`)])
|
||||
.where('server_state', serverState)
|
||||
.innerJoin('link_documents_persons as ba', 'doc.id', 'ba.document_id')
|
||||
.andWhereRaw(`date_part('year', server_date_published) = ?`, [from])
|
||||
|
|
|
@ -8,8 +8,6 @@ import Description from 'App/Models/Description';
|
|||
import Language from 'App/Models/Language';
|
||||
import Coverage from 'App/Models/Coverage';
|
||||
import Collection from 'App/Models/Collection';
|
||||
// import CreateUserValidator from 'App/Validators/CreateUserValidator';
|
||||
// import UpdateUserValidator from 'App/Validators/UpdateUserValidator';
|
||||
import { schema, CustomMessages, rules } from '@ioc:Adonis/Core/Validator';
|
||||
import dayjs from 'dayjs';
|
||||
import Person from 'App/Models/Person';
|
||||
|
@ -17,13 +15,23 @@ import Database from '@ioc:Adonis/Lucid/Database';
|
|||
import { TransactionClientContract } from '@ioc:Adonis/Lucid/Database';
|
||||
import Subject from 'App/Models/Subject';
|
||||
import CreateDatasetValidator from 'App/Validators/CreateDatasetValidator';
|
||||
import { TitleTypes, DescriptionTypes, ContributorTypes, PersonNameTypes, ReferenceIdentifierTypes, RelationTypes } from 'Contracts/enums';
|
||||
import {
|
||||
TitleTypes,
|
||||
DescriptionTypes,
|
||||
ContributorTypes,
|
||||
PersonNameTypes,
|
||||
ReferenceIdentifierTypes,
|
||||
RelationTypes,
|
||||
DatasetTypes,
|
||||
} from 'Contracts/enums';
|
||||
import type { ModelQueryBuilderContract } from '@ioc:Adonis/Lucid/Orm';
|
||||
import DatasetReference from 'App/Models/DatasetReference';
|
||||
import { cuid } from '@ioc:Adonis/Core/Helpers';
|
||||
import File from 'App/Models/File';
|
||||
import ClamScan from 'clamscan';
|
||||
import { ValidationException } from '@ioc:Adonis/Core/Validator';
|
||||
import Drive from '@ioc:Adonis/Core/Drive';
|
||||
import { Exception } from '@adonisjs/core/build/standalone';
|
||||
|
||||
export default class DatasetController {
|
||||
public async index({ auth, request, inertia }: HttpContextContract) {
|
||||
|
@ -98,30 +106,21 @@ export default class DatasetController {
|
|||
|
||||
const projects = await Project.query().pluck('label', 'id');
|
||||
|
||||
const doctypes = {
|
||||
analysisdata: { label: 'Analysis', value: 'analysisdata' },
|
||||
measurementdata: { label: 'Measurements', value: 'measurementdata' },
|
||||
monitoring: 'Monitoring',
|
||||
remotesensing: 'Remote Sensing',
|
||||
gis: 'GIS',
|
||||
models: 'Models',
|
||||
mixedtype: 'Mixed Type',
|
||||
vocabulary: 'Vocabulary'
|
||||
};
|
||||
|
||||
// const titletypes = {
|
||||
// Sub: 'Sub',
|
||||
// Alternative: 'Alternative',
|
||||
// Translated: 'Translated',
|
||||
// Other: 'Other',
|
||||
// const doctypes = {
|
||||
// analysisdata: { label: 'Analysis', value: 'analysisdata' },
|
||||
// measurementdata: { label: 'Measurements', value: 'measurementdata' },
|
||||
// monitoring: 'Monitoring',
|
||||
// remotesensing: 'Remote Sensing',
|
||||
// gis: 'GIS',
|
||||
// models: 'Models',
|
||||
// mixedtype: 'Mixed Type',
|
||||
// vocabulary: 'Vocabulary',
|
||||
// };
|
||||
|
||||
// let test = Object.entries(TitleTypes).map(([key, value]) => ({id: key, value: value}))
|
||||
|
||||
// const languages = await Database.from('languages').select('*').where('active', true);
|
||||
return inertia.render('Submitter/Dataset/Create', {
|
||||
licenses: licenses,
|
||||
doctypes: doctypes,
|
||||
doctypes: DatasetTypes,
|
||||
titletypes: Object.entries(TitleTypes)
|
||||
.filter(([value]) => value !== 'Main')
|
||||
.map(([key, value]) => ({ value: key, label: value })),
|
||||
|
@ -293,7 +292,6 @@ export default class DatasetController {
|
|||
// node ace make:validator CreateDataset
|
||||
try {
|
||||
// Step 2 - Validate request body against the schema
|
||||
// await request.validate(CreateUserValidator);
|
||||
// await request.validate({ schema: newDatasetSchema, messages: this.messages });
|
||||
await request.validate(CreateDatasetValidator);
|
||||
// console.log({ payload });
|
||||
|
@ -755,4 +753,79 @@ export default class DatasetController {
|
|||
doctypes,
|
||||
});
|
||||
}
|
||||
|
||||
public async delete({ request, inertia, response, session }) {
|
||||
const id = request.param('id');
|
||||
try {
|
||||
const dataset = await Dataset.query()
|
||||
.preload('user', (builder) => {
|
||||
builder.select('id', 'login');
|
||||
})
|
||||
.preload('files')
|
||||
.where('id', id)
|
||||
.firstOrFail();
|
||||
const validStates = ['inprogress', 'rejected_editor'];
|
||||
if (!validStates.includes(dataset.server_state)) {
|
||||
// session.flash('errors', 'Invalid server state!');
|
||||
return response
|
||||
.flash(
|
||||
'warning',
|
||||
`Invalid server state. Dataset with id ${id} cannot be deleted. Datset has server state ${dataset.server_state}.`,
|
||||
)
|
||||
.redirect()
|
||||
.toRoute('dataset.list');
|
||||
}
|
||||
return inertia.render('Submitter/Dataset/Delete', {
|
||||
dataset,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.code == 'E_ROW_NOT_FOUND') {
|
||||
session.flash({ warning: 'Dataset is not found in database' });
|
||||
} else {
|
||||
session.flash({ warning: 'general error occured, you cannot delete the dataset' });
|
||||
}
|
||||
return response.redirect().toRoute('dataset.list');
|
||||
}
|
||||
}
|
||||
|
||||
public async deleteUpdate({ params, session, response }) {
|
||||
try {
|
||||
const dataset = await Dataset.query().where('id', params.id).preload('files').firstOrFail();
|
||||
|
||||
const validStates = ['inprogress', 'rejected_editor'];
|
||||
if (validStates.includes(dataset.server_state)) {
|
||||
if (dataset.files && dataset.files.length > 0) {
|
||||
for (const file of dataset.files) {
|
||||
if (file.pathName) {
|
||||
// delete file from filesystem
|
||||
await Drive.delete(file.pathName);
|
||||
}
|
||||
}
|
||||
}
|
||||
// delete dataset wirh relation from db
|
||||
await dataset.delete();
|
||||
session.flash({ message: 'You have deleted 1 dataset!' });
|
||||
return response.redirect().toRoute('dataset.list');
|
||||
} else {
|
||||
session.flash({
|
||||
warning: `You cannot delete this dataset! The status of this dataset is "${dataset.server_state}"!`,
|
||||
});
|
||||
return response.redirect().back();
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof ValidationException) {
|
||||
// Validation exception handling
|
||||
throw error;
|
||||
} else if (error instanceof Exception) {
|
||||
// General exception handling
|
||||
return response
|
||||
.flash({ errors: { error: error.message } })
|
||||
.redirect()
|
||||
.back();
|
||||
} else {
|
||||
session.flash({ error: 'An error occurred while deleting the dataset.' });
|
||||
return response.redirect().back();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
12
app/Exceptions/HttpException.ts
Normal file
12
app/Exceptions/HttpException.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
class HTTPException extends Error {
|
||||
public status: number;
|
||||
public message: string;
|
||||
|
||||
constructor(status: number, message: string) {
|
||||
super(message);
|
||||
this.status = status;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
export default HTTPException;
|
10
app/Exceptions/InternalServerException.ts
Normal file
10
app/Exceptions/InternalServerException.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { StatusCodes } from 'http-status-codes';
|
||||
import HTTPException from './HttpException';
|
||||
|
||||
class InternalServerErrorException extends HTTPException {
|
||||
constructor(message?: string) {
|
||||
super(StatusCodes.INTERNAL_SERVER_ERROR, message || 'Server Error');
|
||||
this.stack = '';
|
||||
}
|
||||
}
|
||||
export default InternalServerErrorException;
|
|
@ -197,7 +197,7 @@ export default class Dataset extends BaseModel {
|
|||
},
|
||||
})
|
||||
public authors: ManyToMany<typeof Person>;
|
||||
|
||||
|
||||
@manyToMany(() => Person, {
|
||||
pivotForeignKey: 'document_id',
|
||||
pivotRelatedForeignKey: 'person_id',
|
||||
|
|
|
@ -14,7 +14,7 @@ export default class DatasetIdentifier extends BaseModel {
|
|||
public id: number;
|
||||
|
||||
@column({})
|
||||
public dataset_id: number;
|
||||
public dataset_id: number;
|
||||
|
||||
@column({})
|
||||
public type: string;
|
||||
|
|
|
@ -56,6 +56,4 @@ export default class DatasetReference extends BaseModel {
|
|||
foreignKey: 'related_document_id',
|
||||
})
|
||||
public new_dataset: BelongsTo<typeof Dataset>;
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue