2023-03-17 15:13:37 +00:00
|
|
|
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
|
|
|
|
// import User from 'App/Models/User';
|
|
|
|
// import Role from 'App/Models/Role';
|
|
|
|
// import Database from '@ioc:Adonis/Lucid/Database';
|
|
|
|
import License from 'App/Models/License';
|
2023-03-24 10:41:52 +00:00
|
|
|
import Project from 'App/Models/Project';
|
2023-03-17 15:13:37 +00:00
|
|
|
// import type { ModelQueryBuilderContract } from '@ioc:Adonis/Lucid/Orm';
|
|
|
|
// import CreateUserValidator from 'App/Validators/CreateUserValidator';
|
|
|
|
// import UpdateUserValidator from 'App/Validators/UpdateUserValidator';
|
|
|
|
// import { RenderResponse } from '@ioc:EidelLev/Inertia';
|
|
|
|
import { schema, CustomMessages, rules } from '@ioc:Adonis/Core/Validator';
|
2023-03-24 10:41:52 +00:00
|
|
|
import dayjs from 'dayjs';
|
2023-06-01 12:29:56 +00:00
|
|
|
// import Application from '@ioc:Adonis/Core/Application';
|
2023-03-17 15:13:37 +00:00
|
|
|
|
|
|
|
enum TitleTypes {
|
|
|
|
Main = 'Main',
|
|
|
|
Sub = 'Sub',
|
|
|
|
Alternative = 'Alternative',
|
|
|
|
Translated = 'Translated',
|
|
|
|
Other = 'Other',
|
|
|
|
}
|
|
|
|
|
|
|
|
enum DescriptionTypes {
|
|
|
|
Abstract = 'Abstract',
|
|
|
|
Methods = 'Methods',
|
|
|
|
Series_information = 'Series_information',
|
|
|
|
Technical_info = 'Technical_info',
|
|
|
|
Translated = 'Translated',
|
|
|
|
Other = 'Other',
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class DatasetController {
|
|
|
|
public async create({ inertia }: HttpContextContract) {
|
|
|
|
const licenses = await License.query().select('id', 'name_long').pluck('name_long', 'id');
|
|
|
|
|
2023-03-24 10:41:52 +00:00
|
|
|
const projects = await Project.query().pluck('label', 'id');
|
|
|
|
|
2023-03-17 15:13:37 +00:00
|
|
|
const doctypes = {
|
|
|
|
analysisdata: { label: 'Analysis', value: 'analysisdata' },
|
|
|
|
measurementdata: { label: 'Measurements', value: 'measurementdata' },
|
|
|
|
monitoring: 'Monitoring',
|
|
|
|
remotesensing: 'Remote Sensing',
|
|
|
|
gis: 'GIS',
|
|
|
|
models: 'Models',
|
|
|
|
mixedtype: 'Mixed Type',
|
|
|
|
};
|
|
|
|
|
|
|
|
// const titletypes = {
|
|
|
|
// Sub: 'Sub',
|
|
|
|
// Alternative: 'Alternative',
|
|
|
|
// Translated: 'Translated',
|
|
|
|
// Other: 'Other',
|
|
|
|
// };
|
|
|
|
|
2023-03-24 10:41:52 +00:00
|
|
|
// let test = Object.entries(TitleTypes).map(([key, value]) => ({id: key, value: value}))
|
|
|
|
|
2023-03-17 15:13:37 +00:00
|
|
|
// const languages = await Database.from('languages').select('*').where('active', true);
|
|
|
|
return inertia.render('Submitter/Dataset/Create', {
|
|
|
|
licenses: licenses,
|
|
|
|
doctypes: doctypes,
|
2023-03-24 10:41:52 +00:00
|
|
|
titletypes: Object.entries(TitleTypes)
|
|
|
|
.filter(([value]) => value !== 'Main')
|
|
|
|
.map(([key, value]) => ({ value: key, label: value })),
|
|
|
|
descriptiontypes: Object.entries(DescriptionTypes)
|
|
|
|
.filter(([value]) => value !== 'Abstract')
|
|
|
|
.map(([key, value]) => ({ value: key, label: value })),
|
2023-03-17 15:13:37 +00:00
|
|
|
// descriptiontypes: DescriptionTypes
|
2023-03-24 10:41:52 +00:00
|
|
|
projects: projects,
|
2023-03-17 15:13:37 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public async firstStep({ request, response }: HttpContextContract) {
|
|
|
|
const newDatasetSchema = schema.create({
|
|
|
|
language: schema.string({ trim: true }, [
|
|
|
|
rules.regex(/^[a-zA-Z0-9-_]+$/), //Must be alphanumeric with hyphens or underscores
|
|
|
|
]),
|
|
|
|
licenses: schema.array([rules.minLength(1)]).members(schema.number()), // define at least one license for the new dataset
|
|
|
|
rights: schema.string([rules.equalTo('true')]),
|
|
|
|
});
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Step 2 - Validate request body against the schema
|
2023-03-24 10:41:52 +00:00
|
|
|
|
2023-03-17 15:13:37 +00:00
|
|
|
await request.validate({ schema: newDatasetSchema, messages: this.messages });
|
|
|
|
// console.log({ payload });
|
|
|
|
} catch (error) {
|
|
|
|
// Step 3 - Handle errors
|
|
|
|
// return response.badRequest(error.messages);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
return response.redirect().back();
|
|
|
|
}
|
|
|
|
|
|
|
|
public async secondStep({ request, response }: HttpContextContract) {
|
|
|
|
const newDatasetSchema = schema.create({
|
2023-03-24 10:41:52 +00:00
|
|
|
// first step
|
|
|
|
language: schema.string({ trim: true }, [
|
|
|
|
rules.regex(/^[a-zA-Z0-9-_]+$/), //Must be alphanumeric with hyphens or underscores
|
|
|
|
]),
|
|
|
|
licenses: schema.array([rules.minLength(1)]).members(schema.number()), // define at least one license for the new dataset
|
|
|
|
rights: schema.string([rules.equalTo('true')]),
|
|
|
|
// second step
|
|
|
|
type: schema.string({ trim: true }, [rules.minLength(3), rules.maxLength(255)]),
|
|
|
|
creating_corporation: schema.string({ trim: true }, [rules.minLength(3), rules.maxLength(255)]),
|
|
|
|
titles: schema.array([rules.minLength(1)]).members(
|
|
|
|
schema.object().members({
|
|
|
|
value: schema.string({ trim: true }, [rules.minLength(3), rules.maxLength(255)]),
|
|
|
|
type: schema.enum(Object.values(TitleTypes)),
|
|
|
|
language: schema.string({ trim: true }, [
|
|
|
|
rules.minLength(2),
|
|
|
|
rules.maxLength(255),
|
2023-05-02 16:10:32 +00:00
|
|
|
rules.translatedLanguage('/language', 'type'),
|
2023-03-24 10:41:52 +00:00
|
|
|
]),
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
descriptions: schema.array([rules.minLength(1)]).members(
|
|
|
|
schema.object().members({
|
|
|
|
value: schema.string({ trim: true }, [rules.minLength(3), rules.maxLength(255)]),
|
|
|
|
type: schema.enum(Object.values(DescriptionTypes)),
|
|
|
|
language: schema.string({ trim: true }, [
|
|
|
|
rules.minLength(2),
|
|
|
|
rules.maxLength(255),
|
2023-05-02 16:10:32 +00:00
|
|
|
rules.translatedLanguage('/language', 'type'),
|
2023-03-24 10:41:52 +00:00
|
|
|
]),
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
authors: schema.array([rules.minLength(1)]).members(schema.object().members({ email: schema.string({ trim: true }) })),
|
|
|
|
|
|
|
|
// project_id: schema.number(),
|
|
|
|
});
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Step 2 - Validate request body against the schema
|
|
|
|
await request.validate({ schema: newDatasetSchema, messages: this.messages });
|
|
|
|
// console.log({ payload });
|
|
|
|
} catch (error) {
|
|
|
|
// Step 3 - Handle errors
|
|
|
|
// return response.badRequest(error.messages);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
return response.redirect().back();
|
|
|
|
}
|
|
|
|
|
|
|
|
public async thirdStep({ request, response }: HttpContextContract) {
|
|
|
|
const newDatasetSchema = schema.create({
|
|
|
|
// first step
|
2023-03-17 15:13:37 +00:00
|
|
|
language: schema.string({ trim: true }, [
|
|
|
|
rules.regex(/^[a-zA-Z0-9-_]+$/), //Must be alphanumeric with hyphens or underscores
|
|
|
|
]),
|
|
|
|
licenses: schema.array([rules.minLength(1)]).members(schema.number()), // define at least one license for the new dataset
|
2023-03-24 10:41:52 +00:00
|
|
|
rights: schema.string([rules.equalTo('true')]),
|
|
|
|
// second step
|
2023-03-17 15:13:37 +00:00
|
|
|
type: schema.string({ trim: true }, [rules.minLength(3), rules.maxLength(255)]),
|
|
|
|
creating_corporation: schema.string({ trim: true }, [rules.minLength(3), rules.maxLength(255)]),
|
|
|
|
titles: schema.array([rules.minLength(1)]).members(
|
|
|
|
schema.object().members({
|
|
|
|
value: schema.string({ trim: true }, [rules.minLength(3), rules.maxLength(255)]),
|
|
|
|
type: schema.enum(Object.values(TitleTypes)),
|
2023-03-31 12:54:15 +00:00
|
|
|
language: schema.string({ trim: true }, [
|
|
|
|
rules.minLength(2),
|
|
|
|
rules.maxLength(255),
|
2023-05-02 16:10:32 +00:00
|
|
|
rules.translatedLanguage('/language', 'type'),
|
2023-03-31 12:54:15 +00:00
|
|
|
]),
|
2023-03-17 15:13:37 +00:00
|
|
|
}),
|
|
|
|
),
|
|
|
|
descriptions: schema.array([rules.minLength(1)]).members(
|
|
|
|
schema.object().members({
|
|
|
|
value: schema.string({ trim: true }, [rules.minLength(3), rules.maxLength(255)]),
|
|
|
|
type: schema.enum(Object.values(DescriptionTypes)),
|
2023-03-31 12:54:15 +00:00
|
|
|
language: schema.string({ trim: true }, [
|
|
|
|
rules.minLength(2),
|
|
|
|
rules.maxLength(255),
|
2023-05-02 16:10:32 +00:00
|
|
|
rules.translatedLanguage('/language', 'type'),
|
2023-03-31 12:54:15 +00:00
|
|
|
]),
|
2023-03-17 15:13:37 +00:00
|
|
|
}),
|
|
|
|
),
|
2023-03-24 10:41:52 +00:00
|
|
|
authors: schema.array([rules.minLength(1)]).members(schema.object().members({ email: schema.string({ trim: true }) })),
|
|
|
|
// third step
|
|
|
|
project_id: schema.number.optional(),
|
|
|
|
embargo_date: schema.date.optional({ format: 'yyyy-MM-dd' }, [rules.after(10, 'days')]),
|
2023-05-02 16:10:32 +00:00
|
|
|
coverage: schema.object().members({
|
|
|
|
x_min: schema.number(),
|
|
|
|
x_max: schema.number(),
|
|
|
|
y_min: schema.number(),
|
|
|
|
y_max: schema.number(),
|
|
|
|
elevation_absolut: schema.number.optional(),
|
2023-06-01 12:29:56 +00:00
|
|
|
elevation_min: schema.number.optional([rules.requiredIfExists('elevation_max')]),
|
|
|
|
elevation_max: schema.number.optional([rules.requiredIfExists('elevation_min')]),
|
2023-05-02 16:10:32 +00:00
|
|
|
depth_absolut: schema.number.optional(),
|
2023-06-01 12:29:56 +00:00
|
|
|
depth_min: schema.number.optional([rules.requiredIfExists('depth_max')]),
|
|
|
|
depth_max: schema.number.optional([rules.requiredIfExists('depth_min')]),
|
2023-05-02 16:10:32 +00:00
|
|
|
}),
|
2023-05-19 09:30:49 +00:00
|
|
|
subjects: schema.array([rules.minLength(3)]).members(
|
|
|
|
schema.object().members({
|
2023-05-24 14:58:52 +00:00
|
|
|
value: schema.string({ trim: true }, [
|
2023-06-01 12:29:56 +00:00
|
|
|
rules.minLength(3),
|
2023-05-24 14:58:52 +00:00
|
|
|
rules.maxLength(255),
|
|
|
|
// rules.unique({ table: 'dataset_subjects', column: 'value' }),
|
|
|
|
]),
|
2023-05-19 09:30:49 +00:00
|
|
|
// type: schema.enum(Object.values(TitleTypes)),
|
2023-06-01 12:29:56 +00:00
|
|
|
language: schema.string({ trim: true }, [rules.minLength(2), rules.maxLength(255)]),
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
});
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Step 2 - Validate request body against the schema
|
|
|
|
await request.validate({ schema: newDatasetSchema, messages: this.messages });
|
|
|
|
// console.log({ payload });
|
|
|
|
} catch (error) {
|
|
|
|
// Step 3 - Handle errors
|
|
|
|
// return response.badRequest(error.messages);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
return response.redirect().back();
|
|
|
|
}
|
|
|
|
public async store({ request, response, session }: HttpContextContract) {
|
|
|
|
const newDatasetSchema = schema.create({
|
|
|
|
// first step
|
|
|
|
language: schema.string({ trim: true }, [
|
|
|
|
rules.regex(/^[a-zA-Z0-9-_]+$/), //Must be alphanumeric with hyphens or underscores
|
|
|
|
]),
|
|
|
|
licenses: schema.array([rules.minLength(1)]).members(schema.number()), // define at least one license for the new dataset
|
|
|
|
rights: schema.string([rules.equalTo('true')]),
|
|
|
|
// second step
|
|
|
|
type: schema.string({ trim: true }, [rules.minLength(3), rules.maxLength(255)]),
|
|
|
|
creating_corporation: schema.string({ trim: true }, [rules.minLength(3), rules.maxLength(255)]),
|
|
|
|
titles: schema.array([rules.minLength(1)]).members(
|
|
|
|
schema.object().members({
|
|
|
|
value: schema.string({ trim: true }, [rules.minLength(3), rules.maxLength(255)]),
|
|
|
|
type: schema.enum(Object.values(TitleTypes)),
|
2023-05-19 09:30:49 +00:00
|
|
|
language: schema.string({ trim: true }, [
|
|
|
|
rules.minLength(2),
|
|
|
|
rules.maxLength(255),
|
2023-06-01 12:29:56 +00:00
|
|
|
rules.translatedLanguage('/language', 'type'),
|
2023-05-19 09:30:49 +00:00
|
|
|
]),
|
|
|
|
}),
|
|
|
|
),
|
2023-06-01 12:29:56 +00:00
|
|
|
descriptions: schema.array([rules.minLength(1)]).members(
|
|
|
|
schema.object().members({
|
|
|
|
value: schema.string({ trim: true }, [rules.minLength(3), rules.maxLength(255)]),
|
|
|
|
type: schema.enum(Object.values(DescriptionTypes)),
|
|
|
|
language: schema.string({ trim: true }, [
|
|
|
|
rules.minLength(2),
|
|
|
|
rules.maxLength(255),
|
|
|
|
rules.translatedLanguage('/language', 'type'),
|
|
|
|
]),
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
authors: schema.array([rules.minLength(1)]).members(schema.object().members({ email: schema.string({ trim: true }) })),
|
|
|
|
// third step
|
|
|
|
project_id: schema.number.optional(),
|
|
|
|
embargo_date: schema.date.optional({ format: 'yyyy-MM-dd' }, [rules.after(10, 'days')]),
|
|
|
|
coverage: schema.object().members({
|
|
|
|
x_min: schema.number(),
|
|
|
|
x_max: schema.number(),
|
|
|
|
y_min: schema.number(),
|
|
|
|
y_max: schema.number(),
|
|
|
|
elevation_absolut: schema.number.optional(),
|
|
|
|
elevation_min: schema.number.optional([rules.requiredIfExists('elevation_max')]),
|
|
|
|
elevation_max: schema.number.optional([rules.requiredIfExists('elevation_min')]),
|
|
|
|
depth_absolut: schema.number.optional(),
|
|
|
|
depth_min: schema.number.optional([rules.requiredIfExists('depth_max')]),
|
|
|
|
depth_max: schema.number.optional([rules.requiredIfExists('depth_min')]),
|
|
|
|
}),
|
|
|
|
subjects: schema.array([rules.minLength(3)]).members(
|
|
|
|
schema.object().members({
|
|
|
|
value: schema.string({ trim: true }, [
|
|
|
|
rules.minLength(3),
|
|
|
|
rules.maxLength(255),
|
|
|
|
// rules.unique({ table: 'dataset_subjects', column: 'value' }),
|
|
|
|
]),
|
|
|
|
// type: schema.enum(Object.values(TitleTypes)),
|
|
|
|
language: schema.string({ trim: true }, [rules.minLength(2), rules.maxLength(255)]),
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
file: schema.file({
|
|
|
|
size: '100mb',
|
|
|
|
extnames: ['jpg', 'gif', 'png'],
|
|
|
|
}),
|
|
|
|
upload: schema.object().members({
|
|
|
|
label: schema.string({ trim: true }, [rules.maxLength(255)]),
|
2023-05-19 09:30:49 +00:00
|
|
|
|
2023-06-01 12:29:56 +00:00
|
|
|
// label: schema.string({ trim: true }, [
|
|
|
|
// // rules.minLength(3),
|
|
|
|
// // rules.maxLength(255),
|
|
|
|
// ]),
|
|
|
|
}),
|
2023-03-17 15:13:37 +00:00
|
|
|
});
|
2023-06-01 12:29:56 +00:00
|
|
|
// node ace make:validator CreateUser
|
2023-03-17 15:13:37 +00:00
|
|
|
try {
|
|
|
|
// Step 2 - Validate request body against the schema
|
2023-06-01 12:29:56 +00:00
|
|
|
// await request.validate(CreateUserValidator);
|
2023-03-17 15:13:37 +00:00
|
|
|
await request.validate({ schema: newDatasetSchema, messages: this.messages });
|
|
|
|
// console.log({ payload });
|
|
|
|
} catch (error) {
|
|
|
|
// Step 3 - Handle errors
|
|
|
|
// return response.badRequest(error.messages);
|
|
|
|
throw error;
|
|
|
|
}
|
2023-06-01 12:29:56 +00:00
|
|
|
const coverImage = request.file('file');
|
|
|
|
if (coverImage) {
|
|
|
|
|
|
|
|
// clientName: 'Gehaltsschema.png'
|
|
|
|
// extname: 'png'
|
|
|
|
// fieldName: 'file'
|
|
|
|
// size: 135624
|
|
|
|
|
|
|
|
coverImage.fileName = 'test'; //request.input('upload.label');
|
|
|
|
|
|
|
|
//const datasetFolder = 'files/' . dataset->id;
|
|
|
|
|
|
|
|
// await coverImage.moveToDisk('./')
|
|
|
|
await coverImage.moveToDisk('/test_dataset', {
|
|
|
|
name: 'renamed-file-name.jpg',
|
|
|
|
overwrite: true, // overwrite in case of conflict
|
|
|
|
},'local');
|
|
|
|
// let path = coverImage.filePath;
|
|
|
|
|
|
|
|
}
|
|
|
|
// const user = await User.create(input);
|
|
|
|
// if (request.input('roles')) {
|
|
|
|
// const roles: Array<number> = request.input('roles');
|
|
|
|
// await user.related('roles').attach(roles);
|
|
|
|
// }
|
|
|
|
|
|
|
|
session.flash('message', 'Dataset has been created successfully');
|
|
|
|
// return response.redirect().toRoute('user.index');
|
2023-03-17 15:13:37 +00:00
|
|
|
return response.redirect().back();
|
|
|
|
}
|
|
|
|
|
|
|
|
public messages: CustomMessages = {
|
2023-03-24 10:41:52 +00:00
|
|
|
'minLength': '{{ field }} must be at least {{ options.minLength }} characters long',
|
|
|
|
'maxLength': '{{ field }} must be less then {{ options.maxLength }} characters long',
|
|
|
|
'required': '{{ field }} is required',
|
|
|
|
'unique': '{{ field }} must be unique, and this value is already taken',
|
|
|
|
// 'confirmed': '{{ field }} is not correct',
|
|
|
|
'licences.minLength': 'at least {{ options.minLength }} permission must be defined',
|
|
|
|
'licences.*.number': 'Define roles as valid numbers',
|
2023-03-17 15:13:37 +00:00
|
|
|
'rights.equalTo': 'you must agree to continue',
|
2023-03-24 10:41:52 +00:00
|
|
|
|
2023-03-17 15:13:37 +00:00
|
|
|
'titles.0.value.minLength': 'Main Title must be at least {{ options.minLength }} characters long',
|
|
|
|
'titles.0.value.required': 'Main Title is required',
|
|
|
|
'titles.*.value.required': 'Additional title is required, if defined',
|
|
|
|
'titles.*.type.required': 'Additional title type is required',
|
|
|
|
'titles.*.language.required': 'Additional title language is required',
|
2023-03-24 10:41:52 +00:00
|
|
|
'titles.*.language.translatedLanguage': 'The language of the translated title must be different from the language of the dataset',
|
|
|
|
|
2023-03-17 15:13:37 +00:00
|
|
|
'descriptions.0.value.minLength': 'Main Abstract must be at least {{ options.minLength }} characters long',
|
|
|
|
'descriptions.0.value.required': 'Main Abstract is required',
|
|
|
|
'descriptions.*.value.required': 'Additional description is required, if defined',
|
|
|
|
'descriptions.*.type.required': 'Additional description type is required',
|
|
|
|
'descriptions.*.language.required': 'Additional description language is required',
|
2023-05-02 16:10:32 +00:00
|
|
|
'descriptions.*.language.translatedLanguage':
|
|
|
|
'The language of the translated description must be different from the language of the dataset',
|
2023-03-24 10:41:52 +00:00
|
|
|
|
|
|
|
'authors.minLength': 'at least {{ options.minLength }} author must be defined',
|
|
|
|
|
|
|
|
'after': `{{ field }} must be older than ${dayjs().add(10, 'day')}`,
|
2023-05-19 09:30:49 +00:00
|
|
|
|
|
|
|
'subjects.minLength': 'at least {{ options.minLength }} keywords must be defined',
|
|
|
|
'subjects.*.value.required': 'keyword value is required',
|
|
|
|
'subjects.*.value.minLength': 'keyword value must be at least {{ options.minLength }} characters long',
|
|
|
|
'subjects.*.type.required': 'keyword type is required',
|
|
|
|
'subjects.*.language.required': 'language of keyword is required',
|
2023-06-01 12:29:56 +00:00
|
|
|
|
|
|
|
'file.size': 'file size is to big',
|
|
|
|
'file.extnames': 'file extension is not supported',
|
2023-03-24 10:41:52 +00:00
|
|
|
};
|
2023-03-17 15:13:37 +00:00
|
|
|
}
|