diff --git a/codbex-currencies/codbex-currencies.edm b/codbex-currencies/codbex-currencies.edm index dd56de9..70fa9af 100644 --- a/codbex-currencies/codbex-currencies.edm +++ b/codbex-currencies/codbex-currencies.edm @@ -31,5 +31,5 @@ - + \ No newline at end of file diff --git a/codbex-currencies/codbex-currencies.gen b/codbex-currencies/codbex-currencies.gen index ec0adbd..0a60202 100644 --- a/codbex-currencies/codbex-currencies.gen +++ b/codbex-currencies/codbex-currencies.gen @@ -1,15 +1,17 @@ { "tablePrefix": "CODBEX_", "brand": "codbex", - "brandUrl": "https://www.codbex.com", - "title": "Currency Management Application", - "description": "Managing currencies data", + "brandUrl": "https://www.codbex.com/", + "title": "Currencies Management Module", + "description": "Managing Currencies Data", "projectName": "codbex-currencies", "workspaceName": "workspace", "filePath": "codbex-currencies.model", - "templateId": "template-application-angular-v2/template/template.js", + "templateId": "template-application-angular-java/template/template.js", "fileName": "codbex-currencies", "genFolderName": "codbex-currencies", + "javaRuntime": true, + "javaGenFolderName": "codbex_currencies", "dataSource": "DefaultDB", "perspectives": { "Settings": { @@ -66,6 +68,7 @@ "widgetDropdownControllerUrl": "", "dataTypeJava": "int", "dataTypeTypescript": "number", + "dataTypeJavaClass": "Integer", "inputRule": "" }, { @@ -93,6 +96,7 @@ "widgetDropdownControllerUrl": "", "dataTypeJava": "string", "dataTypeTypescript": "string", + "dataTypeJavaClass": "String", "minLength": 0, "maxLength": 3, "inputRule": "" @@ -122,6 +126,7 @@ "widgetDropdownControllerUrl": "", "dataTypeJava": "string", "dataTypeTypescript": "string", + "dataTypeJavaClass": "String", "minLength": 0, "maxLength": 127, "inputRule": "" @@ -151,6 +156,7 @@ "widgetDropdownControllerUrl": "", "dataTypeJava": "string", "dataTypeTypescript": "string", + "dataTypeJavaClass": "String", "minLength": 0, "maxLength": 3, "inputRule": "" @@ -179,6 +185,7 @@ "widgetDropdownControllerUrl": "", "dataTypeJava": "int", "dataTypeTypescript": "number", + "dataTypeJavaClass": "Integer", "inputRule": "" }, { @@ -205,6 +212,7 @@ "widgetDropdownControllerUrl": "", "dataTypeJava": "boolean", "dataTypeTypescript": "boolean", + "dataTypeJavaClass": "Boolean", "inputRule": "" }, { @@ -231,6 +239,7 @@ "widgetDropdownControllerUrl": "", "dataTypeJava": "double", "dataTypeTypescript": "number", + "dataTypeJavaClass": "Double", "inputRule": "" }, { @@ -257,6 +266,7 @@ "widgetDropdownControllerUrl": "", "dataTypeJava": "timestamp", "dataTypeTypescript": "Date", + "dataTypeJavaClass": "java.time.Instant", "isDateType": true, "inputRule": "" }, @@ -285,6 +295,7 @@ "widgetDropdownControllerUrl": "", "dataTypeJava": "string", "dataTypeTypescript": "string", + "dataTypeJavaClass": "String", "minLength": 0, "maxLength": 20, "inputRule": "" @@ -313,6 +324,7 @@ "widgetDropdownControllerUrl": "", "dataTypeJava": "timestamp", "dataTypeTypescript": "Date", + "dataTypeJavaClass": "java.time.Instant", "isDateType": true, "inputRule": "" }, @@ -341,6 +353,7 @@ "widgetDropdownControllerUrl": "", "dataTypeJava": "string", "dataTypeTypescript": "string", + "dataTypeJavaClass": "String", "minLength": 0, "maxLength": 20, "inputRule": "" @@ -373,6 +386,7 @@ "tooltip": "Currency", "type": "SETTING", "dataSource": "DefaultDB", + "javaPerspectiveName": "settings", "referencedProjections": [], "primaryKeys": [ "Id" @@ -406,6 +420,7 @@ "widgetDropdownControllerUrl": "", "dataTypeJava": "int", "dataTypeTypescript": "number", + "dataTypeJavaClass": "Integer", "inputRule": "" }, { @@ -434,10 +449,11 @@ "isCalculatedProperty": false, "isReadOnlyProperty": false, "widgetLabel": "Currency", - "widgetDropdownUrl": "/services/ts/codbex-currencies/gen/codbex-currencies/api/Settings/CurrencyService.ts", - "widgetDropdownControllerUrl": "/services/ts/codbex-currencies/gen/codbex-currencies/api/Settings/CurrencyController.ts", + "widgetDropdownUrl": "/services/java/codbex-currencies/gen/codbex_currencies/api/settings/CurrencyController", + "widgetDropdownControllerUrl": "/services/java/codbex-currencies/gen/codbex_currencies/api/settings/CurrencyController", "dataTypeJava": "int", "dataTypeTypescript": "number", + "dataTypeJavaClass": "Integer", "inputRule": "" }, { @@ -464,6 +480,7 @@ "widgetDropdownControllerUrl": "", "dataTypeJava": "date", "dataTypeTypescript": "Date", + "dataTypeJavaClass": "java.time.LocalDate", "isDateType": true, "inputRule": "" }, @@ -491,6 +508,7 @@ "widgetDropdownControllerUrl": "", "dataTypeJava": "double", "dataTypeTypescript": "number", + "dataTypeJavaClass": "Double", "inputRule": "" }, { @@ -517,6 +535,7 @@ "widgetDropdownControllerUrl": "", "dataTypeJava": "timestamp", "dataTypeTypescript": "Date", + "dataTypeJavaClass": "java.time.Instant", "isDateType": true, "inputRule": "" }, @@ -545,6 +564,7 @@ "widgetDropdownControllerUrl": "", "dataTypeJava": "string", "dataTypeTypescript": "string", + "dataTypeJavaClass": "String", "minLength": 0, "maxLength": 20, "inputRule": "" @@ -573,6 +593,7 @@ "widgetDropdownControllerUrl": "", "dataTypeJava": "timestamp", "dataTypeTypescript": "Date", + "dataTypeJavaClass": "java.time.Instant", "isDateType": true, "inputRule": "" }, @@ -601,6 +622,7 @@ "widgetDropdownControllerUrl": "", "dataTypeJava": "string", "dataTypeTypescript": "string", + "dataTypeJavaClass": "String", "minLength": 0, "maxLength": 20, "inputRule": "" @@ -631,6 +653,7 @@ "tooltip": "CurrencyRate", "type": "SETTING", "dataSource": "DefaultDB", + "javaPerspectiveName": "settings", "referencedProjections": [], "primaryKeys": [ "Id" diff --git a/codbex-currencies/gen/codbex-currencies/api/Settings/CurrencyController.ts b/codbex-currencies/gen/codbex-currencies/api/Settings/CurrencyController.ts deleted file mode 100644 index f7b0075..0000000 --- a/codbex-currencies/gen/codbex-currencies/api/Settings/CurrencyController.ts +++ /dev/null @@ -1,202 +0,0 @@ -import { Controller, Get, Post, Put, Delete, Documentation, request, response } from '@aerokit/sdk/http' -import { HttpUtils } from "@aerokit/sdk/http/utils"; -import { ValidationError } from '@aerokit/sdk/http/errors' -import { ForbiddenError } from '@aerokit/sdk/http/errors' -import { user } from '@aerokit/sdk/security' -import { Options } from '@aerokit/sdk/db' -import { Extensions } from "@aerokit/sdk/extensions" -import { Injected, Inject } from '@aerokit/sdk/component' -import { CurrencyRepository } from '../../data/Settings/CurrencyRepository' -import { CurrencyEntity } from '../../data/Settings/CurrencyEntity' - -const validationModules = await Extensions.loadExtensionModules('codbex-currencies-Settings-Currency', ['validate']); - -@Controller -@Documentation('codbex-currencies - Currency Controller') -@Injected() -class CurrencyController { - - @Inject('CurrencyRepository') - private readonly repository!: CurrencyRepository; - - @Get('/') - @Documentation('Get All Currency') - public getAll(_: any, ctx: any): CurrencyEntity[] { - try { - this.checkPermissions('read'); - const options: Options = { - limit: ctx.queryParameters["$limit"] ? parseInt(ctx.queryParameters["$limit"]) : 20, - offset: ctx.queryParameters["$offset"] ? parseInt(ctx.queryParameters["$offset"]) : 0, - language: request.getLocale()?.split("_")[0] - }; - - return this.repository.findAll(options); - } catch (error: any) { - this.handleError(error); - } - return undefined as any; - } - - @Post('/') - @Documentation('Create Currency') - public create(entity: CurrencyEntity): CurrencyEntity { - try { - this.checkPermissions('write'); - this.validateEntity(entity); - entity.Id = this.repository.create(entity) as any; - response.setHeader('Content-Location', '/services/ts/codbex-currencies/gen/codbex-currencies/api/Settings/CurrencyController.ts/' + entity.Id); - response.setStatus(response.CREATED); - return entity; - } catch (error: any) { - this.handleError(error); - } - return undefined as any; - } - - @Get('/count') - @Documentation('Count Currency') - public count(): { count: number } { - try { - this.checkPermissions('read'); - return { count: this.repository.count() }; - } catch (error: any) { - this.handleError(error); - } - return undefined as any; - } - - @Post('/count') - @Documentation('Count Currency with filter') - public countWithFilter(filter: any): { count: number } { - try { - this.checkPermissions('read'); - return { count: this.repository.count(filter) }; - } catch (error: any) { - this.handleError(error); - } - return undefined as any; - } - - @Post('/search') - @Documentation('Search Currency') - public search(filter: any): CurrencyEntity[] { - try { - this.checkPermissions('read'); - return this.repository.findAll(filter); - } catch (error: any) { - this.handleError(error); - } - return undefined as any; - } - - @Get('/:id') - @Documentation('Get Currency by id') - public getById(_: any, ctx: any): CurrencyEntity { - try { - this.checkPermissions('read'); - const id = parseInt(ctx.pathParameters.id); - const options: Options = { - language: request.getLocale()?.split("_")[0] - }; - const entity = this.repository.findById(id, options); - if (entity) { - return entity; - } else { - HttpUtils.sendResponseNotFound('Currency not found'); - } - } catch (error: any) { - this.handleError(error); - } - return undefined as any; - } - - @Put('/:id') - @Documentation('Update Currency by id') - public update(entity: CurrencyEntity, ctx: any): CurrencyEntity { - try { - this.checkPermissions('write'); - const id = parseInt(ctx.pathParameters.id); - entity.Id = id; - this.validateEntity(entity); - this.repository.update(entity); - return entity; - } catch (error: any) { - this.handleError(error); - } - return undefined as any; - } - - @Delete('/:id') - @Documentation('Delete Currency by id') - public deleteById(_: any, ctx: any): void { - try { - this.checkPermissions('write'); - const id = parseInt(ctx.pathParameters.id); - const entity = this.repository.findById(id); - if (entity) { - this.repository.deleteById(id); - HttpUtils.sendResponseNoContent(); - } else { - HttpUtils.sendResponseNotFound('Currency not found'); - } - } catch (error: any) { - this.handleError(error); - } - } - - private handleError(error: any) { - if (error.name === 'ForbiddenError') { - HttpUtils.sendForbiddenRequest(error.message); - } else if (error.name === 'ValidationError') { - HttpUtils.sendResponseBadRequest(error.message); - } else { - HttpUtils.sendInternalServerError(error.message); - } - } - - private checkPermissions(operationType: string) { - if (operationType === 'read' && !(user.isInRole('codbex-currencies.Currencies.CurrencyReadOnly') || user.isInRole('codbex-currencies.Currencies.CurrencyFullAccess'))) { - throw new ForbiddenError(); - } - if (operationType === 'write' && !user.isInRole('codbex-currencies.Currencies.CurrencyFullAccess')) { - throw new ForbiddenError(); - } - } - - private validateEntity(entity: any): void { - if (entity.Code === null || entity.Code === undefined) { - throw new ValidationError(`The 'Code' property is required, provide a valid value`); - } - if (entity.Code?.length > 3) { - throw new ValidationError(`The 'Code' exceeds the maximum length of [3] characters`); - } - if (entity.Name === null || entity.Name === undefined) { - throw new ValidationError(`The 'Name' property is required, provide a valid value`); - } - if (entity.Name?.length > 127) { - throw new ValidationError(`The 'Name' exceeds the maximum length of [127] characters`); - } - if (entity.Numeric === null || entity.Numeric === undefined) { - throw new ValidationError(`The 'Numeric' property is required, provide a valid value`); - } - if (entity.Numeric?.length > 3) { - throw new ValidationError(`The 'Numeric' exceeds the maximum length of [3] characters`); - } - if (entity.Rounding === null || entity.Rounding === undefined) { - throw new ValidationError(`The 'Rounding' property is required, provide a valid value`); - } - if (entity.Rate === null || entity.Rate === undefined) { - throw new ValidationError(`The 'Rate' property is required, provide a valid value`); - } - if (entity.CreatedBy?.length > 20) { - throw new ValidationError(`The 'CreatedBy' exceeds the maximum length of [20] characters`); - } - if (entity.UpdatedBy?.length > 20) { - throw new ValidationError(`The 'UpdatedBy' exceeds the maximum length of [20] characters`); - } - for (const next of validationModules) { - next.validate(entity); - } - } - -} diff --git a/codbex-currencies/gen/codbex-currencies/api/Settings/CurrencyRateController.ts b/codbex-currencies/gen/codbex-currencies/api/Settings/CurrencyRateController.ts deleted file mode 100644 index 6b8e4c9..0000000 --- a/codbex-currencies/gen/codbex-currencies/api/Settings/CurrencyRateController.ts +++ /dev/null @@ -1,187 +0,0 @@ -import { Controller, Get, Post, Put, Delete, Documentation, request, response } from '@aerokit/sdk/http' -import { HttpUtils } from "@aerokit/sdk/http/utils"; -import { ValidationError } from '@aerokit/sdk/http/errors' -import { ForbiddenError } from '@aerokit/sdk/http/errors' -import { user } from '@aerokit/sdk/security' -import { Options } from '@aerokit/sdk/db' -import { Extensions } from "@aerokit/sdk/extensions" -import { Injected, Inject } from '@aerokit/sdk/component' -import { CurrencyRateRepository } from '../../data/Settings/CurrencyRateRepository' -import { CurrencyRateEntity } from '../../data/Settings/CurrencyRateEntity' - -const validationModules = await Extensions.loadExtensionModules('codbex-currencies-Settings-CurrencyRate', ['validate']); - -@Controller -@Documentation('codbex-currencies - CurrencyRate Controller') -@Injected() -class CurrencyRateController { - - @Inject('CurrencyRateRepository') - private readonly repository!: CurrencyRateRepository; - - @Get('/') - @Documentation('Get All CurrencyRate') - public getAll(_: any, ctx: any): CurrencyRateEntity[] { - try { - this.checkPermissions('read'); - const options: Options = { - limit: ctx.queryParameters["$limit"] ? parseInt(ctx.queryParameters["$limit"]) : 20, - offset: ctx.queryParameters["$offset"] ? parseInt(ctx.queryParameters["$offset"]) : 0, - language: request.getLocale()?.split("_")[0] - }; - - return this.repository.findAll(options); - } catch (error: any) { - this.handleError(error); - } - return undefined as any; - } - - @Post('/') - @Documentation('Create CurrencyRate') - public create(entity: CurrencyRateEntity): CurrencyRateEntity { - try { - this.checkPermissions('write'); - this.validateEntity(entity); - entity.Id = this.repository.create(entity) as any; - response.setHeader('Content-Location', '/services/ts/codbex-currencies/gen/codbex-currencies/api/Settings/CurrencyRateController.ts/' + entity.Id); - response.setStatus(response.CREATED); - return entity; - } catch (error: any) { - this.handleError(error); - } - return undefined as any; - } - - @Get('/count') - @Documentation('Count CurrencyRate') - public count(): { count: number } { - try { - this.checkPermissions('read'); - return { count: this.repository.count() }; - } catch (error: any) { - this.handleError(error); - } - return undefined as any; - } - - @Post('/count') - @Documentation('Count CurrencyRate with filter') - public countWithFilter(filter: any): { count: number } { - try { - this.checkPermissions('read'); - return { count: this.repository.count(filter) }; - } catch (error: any) { - this.handleError(error); - } - return undefined as any; - } - - @Post('/search') - @Documentation('Search CurrencyRate') - public search(filter: any): CurrencyRateEntity[] { - try { - this.checkPermissions('read'); - return this.repository.findAll(filter); - } catch (error: any) { - this.handleError(error); - } - return undefined as any; - } - - @Get('/:id') - @Documentation('Get CurrencyRate by id') - public getById(_: any, ctx: any): CurrencyRateEntity { - try { - this.checkPermissions('read'); - const id = parseInt(ctx.pathParameters.id); - const options: Options = { - language: request.getLocale()?.split("_")[0] - }; - const entity = this.repository.findById(id, options); - if (entity) { - return entity; - } else { - HttpUtils.sendResponseNotFound('CurrencyRate not found'); - } - } catch (error: any) { - this.handleError(error); - } - return undefined as any; - } - - @Put('/:id') - @Documentation('Update CurrencyRate by id') - public update(entity: CurrencyRateEntity, ctx: any): CurrencyRateEntity { - try { - this.checkPermissions('write'); - const id = parseInt(ctx.pathParameters.id); - entity.Id = id; - this.validateEntity(entity); - this.repository.update(entity); - return entity; - } catch (error: any) { - this.handleError(error); - } - return undefined as any; - } - - @Delete('/:id') - @Documentation('Delete CurrencyRate by id') - public deleteById(_: any, ctx: any): void { - try { - this.checkPermissions('write'); - const id = parseInt(ctx.pathParameters.id); - const entity = this.repository.findById(id); - if (entity) { - this.repository.deleteById(id); - HttpUtils.sendResponseNoContent(); - } else { - HttpUtils.sendResponseNotFound('CurrencyRate not found'); - } - } catch (error: any) { - this.handleError(error); - } - } - - private handleError(error: any) { - if (error.name === 'ForbiddenError') { - HttpUtils.sendForbiddenRequest(error.message); - } else if (error.name === 'ValidationError') { - HttpUtils.sendResponseBadRequest(error.message); - } else { - HttpUtils.sendInternalServerError(error.message); - } - } - - private checkPermissions(operationType: string) { - if (operationType === 'read' && !(user.isInRole('codbex-currencies.Currencies.CurrencyRateReadOnly') || user.isInRole('codbex-currencies.Currencies.CurrencyRateFullAccess'))) { - throw new ForbiddenError(); - } - if (operationType === 'write' && !user.isInRole('codbex-currencies.Currencies.CurrencyRateFullAccess')) { - throw new ForbiddenError(); - } - } - - private validateEntity(entity: any): void { - if (entity.Currency === null || entity.Currency === undefined) { - throw new ValidationError(`The 'Currency' property is required, provide a valid value`); - } - if (entity.Date === null || entity.Date === undefined) { - throw new ValidationError(`The 'Date' property is required, provide a valid value`); - } - if (entity.Rate === null || entity.Rate === undefined) { - throw new ValidationError(`The 'Rate' property is required, provide a valid value`); - } - if (entity.CreatedBy?.length > 20) { - throw new ValidationError(`The 'CreatedBy' exceeds the maximum length of [20] characters`); - } - if (entity.UpdatedBy?.length > 20) { - throw new ValidationError(`The 'UpdatedBy' exceeds the maximum length of [20] characters`); - } - for (const next of validationModules) { - next.validate(entity); - } - } - -} diff --git a/codbex-currencies/gen/codbex-currencies/data/Settings/CurrencyEntity.ts b/codbex-currencies/gen/codbex-currencies/data/Settings/CurrencyEntity.ts deleted file mode 100644 index 122c4d8..0000000 --- a/codbex-currencies/gen/codbex-currencies/data/Settings/CurrencyEntity.ts +++ /dev/null @@ -1,103 +0,0 @@ -import { Entity, Table, Id, Generated, Column, Documentation, CreatedAt, CreatedBy, UpdatedAt, UpdatedBy} from '@aerokit/sdk/db' - -@Entity('CurrencyEntity') -@Table('CODBEX_CURRENCY') -@Documentation('Currency entity mapping') -export class CurrencyEntity { - - @Id() - @Generated('sequence') - @Documentation('Id') - @Column({ - name: 'CURRENCY_ID', - type: 'integer', - }) - public Id?: number; - - @Documentation('Code') - @Column({ - name: 'CURRENCY_CODE', - type: 'string', - length: 3, - }) - public Code!: string; - - @Documentation('Name') - @Column({ - name: 'CURRENCY_NAME', - type: 'string', - length: 127, - }) - public Name!: string; - - @Documentation('Numeric') - @Column({ - name: 'CURRENCY_NUMERIC', - type: 'string', - length: 3, - }) - public Numeric!: string; - - @Documentation('Rounding') - @Column({ - name: 'CURRENCY_ROUNDING', - type: 'integer', - }) - public Rounding!: number; - - @Documentation('Base') - @Column({ - name: 'CURRENCY_BASE', - type: 'boolean', - nullable: true, - }) - public Base?: boolean; - - @Documentation('Rate') - @Column({ - name: 'CURRENCY_RATE', - type: 'double', - }) - public Rate!: number; - - @Documentation('CreatedAt') - @Column({ - name: 'CURRENCY_CREATEDAT', - type: 'timestamp', - nullable: true, - }) - @CreatedAt() - public CreatedAt?: Date; - - @Documentation('CreatedBy') - @Column({ - name: 'CURRENCY_CREATEDBY', - type: 'string', - length: 20, - nullable: true, - }) - @CreatedBy() - public CreatedBy?: string; - - @Documentation('UpdatedAt') - @Column({ - name: 'CURRENCY_UPDATEDAT', - type: 'timestamp', - nullable: true, - }) - @UpdatedAt() - public UpdatedAt?: Date; - - @Documentation('UpdatedBy') - @Column({ - name: 'CURRENCY_UPDATEDBY', - type: 'string', - length: 20, - nullable: true, - }) - @UpdatedBy() - public UpdatedBy?: string; - -} - -(new CurrencyEntity()); diff --git a/codbex-currencies/gen/codbex-currencies/data/Settings/CurrencyRateEntity.ts b/codbex-currencies/gen/codbex-currencies/data/Settings/CurrencyRateEntity.ts deleted file mode 100644 index b0ee743..0000000 --- a/codbex-currencies/gen/codbex-currencies/data/Settings/CurrencyRateEntity.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { Entity, Table, Id, Generated, Column, Documentation, CreatedAt, CreatedBy, UpdatedAt, UpdatedBy} from '@aerokit/sdk/db' - -@Entity('CurrencyRateEntity') -@Table('CODBEX_CURRENCYRATE') -@Documentation('CurrencyRate entity mapping') -export class CurrencyRateEntity { - - @Id() - @Generated('sequence') - @Documentation('Id') - @Column({ - name: 'CURRENCYRATE_ID', - type: 'integer', - }) - public Id?: number; - - @Documentation('Currency') - @Column({ - name: 'CURRENCYRATE_CURRENCY', - type: 'integer', - }) - public Currency!: number; - - @Documentation('Date') - @Column({ - name: 'CURRENCYRATE_DATE', - type: 'date', - }) - public Date!: Date; - - @Documentation('Rate') - @Column({ - name: 'CURRENCYRATE_RATE', - type: 'double', - }) - public Rate!: number; - - @Documentation('CreatedAt') - @Column({ - name: 'CURRENCYRATE_CREATEDAT', - type: 'timestamp', - nullable: true, - }) - @CreatedAt() - public CreatedAt?: Date; - - @Documentation('CreatedBy') - @Column({ - name: 'CURRENCYRATE_CREATEDBY', - type: 'string', - length: 20, - nullable: true, - }) - @CreatedBy() - public CreatedBy?: string; - - @Documentation('UpdatedAt') - @Column({ - name: 'CURRENCYRATE_UPDATEDAT', - type: 'timestamp', - nullable: true, - }) - @UpdatedAt() - public UpdatedAt?: Date; - - @Documentation('UpdatedBy') - @Column({ - name: 'CURRENCYRATE_UPDATEDBY', - type: 'string', - length: 20, - nullable: true, - }) - @UpdatedBy() - public UpdatedBy?: string; - -} - -(new CurrencyRateEntity()); diff --git a/codbex-currencies/gen/codbex-currencies/data/Settings/CurrencyRateRepository.ts b/codbex-currencies/gen/codbex-currencies/data/Settings/CurrencyRateRepository.ts deleted file mode 100644 index e60d6fc..0000000 --- a/codbex-currencies/gen/codbex-currencies/data/Settings/CurrencyRateRepository.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { Repository, EntityEvent, EntityConstructor, Options } from '@aerokit/sdk/db' -import { Component } from '@aerokit/sdk/component' -import { Producer } from '@aerokit/sdk/messaging' -import { Extensions } from '@aerokit/sdk/extensions' -import { CurrencyRateEntity } from './CurrencyRateEntity' - -@Component('CurrencyRateRepository') -export class CurrencyRateRepository extends Repository { - - constructor() { - super((CurrencyRateEntity as EntityConstructor)); - } - - public override findById(id: string | number, options?: Options): CurrencyRateEntity | undefined { - const entity = super.findById(id, options); - if (entity) { - entity.Date = entity.Date ? new Date(entity.Date) : undefined; - entity.CreatedAt = entity.CreatedAt ? new Date(entity.CreatedAt) : undefined; - entity.UpdatedAt = entity.UpdatedAt ? new Date(entity.UpdatedAt) : undefined; - } - return entity; - } - - public override findAll(options?: Options): CurrencyRateEntity[] { - const entities = super.findAll(options); - entities.forEach(entity => { - entity.Date = entity.Date ? new Date(entity.Date) : undefined; - entity.CreatedAt = entity.CreatedAt ? new Date(entity.CreatedAt) : undefined; - entity.UpdatedAt = entity.UpdatedAt ? new Date(entity.UpdatedAt) : undefined; - }); - return entities; - } - - protected override async triggerEvent(data: EntityEvent): Promise { - const triggerExtensions = await Extensions.loadExtensionModules('codbex-currencies-Settings-CurrencyRate', ['trigger']); - triggerExtensions.forEach(triggerExtension => { - try { - triggerExtension.trigger(data); - } catch (error) { - console.error(error); - } - }); - Producer.topic('codbex-currencies-Settings-CurrencyRate').send(JSON.stringify(data)); - } -} diff --git a/codbex-currencies/gen/codbex-currencies/data/Settings/CurrencyRepository.ts b/codbex-currencies/gen/codbex-currencies/data/Settings/CurrencyRepository.ts deleted file mode 100644 index b6d37b8..0000000 --- a/codbex-currencies/gen/codbex-currencies/data/Settings/CurrencyRepository.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { Repository, EntityEvent, EntityConstructor, Options } from '@aerokit/sdk/db' -import { Component } from '@aerokit/sdk/component' -import { Producer } from '@aerokit/sdk/messaging' -import { Extensions } from '@aerokit/sdk/extensions' -import { CurrencyEntity } from './CurrencyEntity' - -@Component('CurrencyRepository') -export class CurrencyRepository extends Repository { - - constructor() { - super((CurrencyEntity as EntityConstructor)); - } - - public override findById(id: string | number, options?: Options): CurrencyEntity | undefined { - const entity = super.findById(id, options); - if (entity) { - entity.CreatedAt = entity.CreatedAt ? new Date(entity.CreatedAt) : undefined; - entity.UpdatedAt = entity.UpdatedAt ? new Date(entity.UpdatedAt) : undefined; - } - return entity; - } - - public override findAll(options?: Options): CurrencyEntity[] { - const entities = super.findAll(options); - entities.forEach(entity => { - entity.CreatedAt = entity.CreatedAt ? new Date(entity.CreatedAt) : undefined; - entity.UpdatedAt = entity.UpdatedAt ? new Date(entity.UpdatedAt) : undefined; - }); - return entities; - } - - protected override async triggerEvent(data: EntityEvent): Promise { - const triggerExtensions = await Extensions.loadExtensionModules('codbex-currencies-Settings-Currency', ['trigger']); - triggerExtensions.forEach(triggerExtension => { - try { - triggerExtension.trigger(data); - } catch (error) { - console.error(error); - } - }); - Producer.topic('codbex-currencies-Settings-Currency').send(JSON.stringify(data)); - } -} diff --git a/codbex-currencies/gen/codbex-currencies/odata/codbex-currencies.odata b/codbex-currencies/gen/codbex-currencies/odata/codbex-currencies.odata deleted file mode 100644 index f149140..0000000 --- a/codbex-currencies/gen/codbex-currencies/odata/codbex-currencies.odata +++ /dev/null @@ -1,4 +0,0 @@ -{ - "namespace": "", - "entities": [] -} diff --git a/codbex-currencies/gen/codbex-currencies/ui/Settings/Currency/controller.js b/codbex-currencies/gen/codbex-currencies/ui/Settings/Currency/controller.js index df589cb..07bff03 100644 --- a/codbex-currencies/gen/codbex-currencies/ui/Settings/Currency/controller.js +++ b/codbex-currencies/gen/codbex-currencies/ui/Settings/Currency/controller.js @@ -1,6 +1,6 @@ angular.module('page', ['blimpKit', 'platformView', 'platformLocale', 'EntityService']) .config(['EntityServiceProvider', (EntityServiceProvider) => { - EntityServiceProvider.baseUrl = '/services/ts/codbex-currencies/gen/codbex-currencies/api/Settings/CurrencyController.ts'; + EntityServiceProvider.baseUrl = '/services/java/codbex-currencies/gen/codbex_currencies/api/settings/CurrencyController'; }]) .controller('PageController', ($scope, EntityService, Extensions, LocaleService, ButtonStates) => { const Dialogs = new DialogHub(); diff --git a/codbex-currencies/gen/codbex-currencies/ui/Settings/Currency/dialog-window/controller.js b/codbex-currencies/gen/codbex-currencies/ui/Settings/Currency/dialog-window/controller.js index 56fe139..f5e6af5 100644 --- a/codbex-currencies/gen/codbex-currencies/ui/Settings/Currency/dialog-window/controller.js +++ b/codbex-currencies/gen/codbex-currencies/ui/Settings/Currency/dialog-window/controller.js @@ -1,6 +1,6 @@ angular.module('page', ['blimpKit', 'platformView', 'platformLocale', 'EntityService']) .config(['EntityServiceProvider', (EntityServiceProvider) => { - EntityServiceProvider.baseUrl = '/services/ts/codbex-currencies/gen/codbex-currencies/api/Settings/CurrencyController.ts'; + EntityServiceProvider.baseUrl = '/services/java/codbex-currencies/gen/codbex_currencies/api/settings/CurrencyController'; }]) .controller('PageController', ($scope, $http, ViewParameters, LocaleService, EntityService) => { const Dialogs = new DialogHub(); diff --git a/codbex-currencies/gen/codbex-currencies/ui/Settings/CurrencyRate/controller.js b/codbex-currencies/gen/codbex-currencies/ui/Settings/CurrencyRate/controller.js index 4e8f4f0..c4aefe2 100644 --- a/codbex-currencies/gen/codbex-currencies/ui/Settings/CurrencyRate/controller.js +++ b/codbex-currencies/gen/codbex-currencies/ui/Settings/CurrencyRate/controller.js @@ -1,6 +1,6 @@ angular.module('page', ['blimpKit', 'platformView', 'platformLocale', 'EntityService']) .config(['EntityServiceProvider', (EntityServiceProvider) => { - EntityServiceProvider.baseUrl = '/services/ts/codbex-currencies/gen/codbex-currencies/api/Settings/CurrencyRateController.ts'; + EntityServiceProvider.baseUrl = '/services/java/codbex-currencies/gen/codbex_currencies/api/settings/CurrencyRateController'; }]) .controller('PageController', ($scope, $http, EntityService, Extensions, LocaleService, ButtonStates) => { const Dialogs = new DialogHub(); @@ -100,7 +100,7 @@ angular.module('page', ['blimpKit', 'platformView', 'platformLocale', 'EntitySer if (optionsCurrencyHasMore) { const optionsCurrencySearchValues = Array.from(new Set(response.data.map(e => e.Currency))); if (optionsCurrencySearchValues.length > 0) { - $http.post('/services/ts/codbex-currencies/gen/codbex-currencies/api/Settings/CurrencyController.ts/search', { + $http.post('/services/java/codbex-currencies/gen/codbex_currencies/api/settings/CurrencyController/search', { conditions: [ { propertyName: 'Id', operator: 'IN', value: optionsCurrencySearchValues } ] @@ -243,9 +243,9 @@ angular.module('page', ['blimpKit', 'platformView', 'platformLocale', 'EntitySer let optionsCurrencyHasMore = true; - $http.get('/services/ts/codbex-currencies/gen/codbex-currencies/api/Settings/CurrencyController.ts/count').then((response) => { + $http.get('/services/java/codbex-currencies/gen/codbex_currencies/api/settings/CurrencyController/count').then((response) => { const optionsCurrencyCount = response.data.count; - $http.get('/services/ts/codbex-currencies/gen/codbex-currencies/api/Settings/CurrencyController.ts').then((response) => { + $http.get('/services/java/codbex-currencies/gen/codbex_currencies/api/settings/CurrencyController').then((response) => { $scope.optionsCurrency = response.data.map(e => ({ value: e.Id, text: e.Code diff --git a/codbex-currencies/gen/codbex-currencies/ui/Settings/CurrencyRate/dialog-filter/controller.js b/codbex-currencies/gen/codbex-currencies/ui/Settings/CurrencyRate/dialog-filter/controller.js index 7a73ec1..31da1db 100644 --- a/codbex-currencies/gen/codbex-currencies/ui/Settings/CurrencyRate/dialog-filter/controller.js +++ b/codbex-currencies/gen/codbex-currencies/ui/Settings/CurrencyRate/dialog-filter/controller.js @@ -132,7 +132,7 @@ angular.module('page', ['blimpKit', 'platformView', 'platformLocale']).controlle $scope.loadMoreOptionsCurrency = () => { const limit = 20; $scope.optionsCurrencyLoading = true; - $http.get(`/services/ts/codbex-currencies/gen/codbex-currencies/api/Settings/CurrencyController.ts?$limit=${limit}&$offset=${++loadMoreOptionsCurrencyCounter * limit}`) + $http.get(`/services/java/codbex-currencies/gen/codbex_currencies/api/settings/CurrencyController?$limit=${limit}&$offset=${++loadMoreOptionsCurrencyCounter * limit}`) .then((response) => { const optionValues = allValuesCurrency.map(e => e.value); const resultValues = response.data.map(e => ({ @@ -182,7 +182,7 @@ angular.module('page', ['blimpKit', 'platformView', 'platformLocale']).controlle } }) if (!cacheHit) { - $http.post('/services/ts/codbex-currencies/gen/codbex-currencies/api/Settings/CurrencyController.ts/search', { + $http.post('/services/java/codbex-currencies/gen/codbex_currencies/api/settings/CurrencyController/search', { conditions: [ { propertyName: 'Code', operator: 'LIKE', value: `${event.originalEvent.target.value}%` } ] diff --git a/codbex-currencies/gen/codbex-currencies/ui/Settings/CurrencyRate/dialog-window/controller.js b/codbex-currencies/gen/codbex-currencies/ui/Settings/CurrencyRate/dialog-window/controller.js index f8c9e22..a7d9b56 100644 --- a/codbex-currencies/gen/codbex-currencies/ui/Settings/CurrencyRate/dialog-window/controller.js +++ b/codbex-currencies/gen/codbex-currencies/ui/Settings/CurrencyRate/dialog-window/controller.js @@ -1,6 +1,6 @@ angular.module('page', ['blimpKit', 'platformView', 'platformLocale', 'EntityService']) .config(['EntityServiceProvider', (EntityServiceProvider) => { - EntityServiceProvider.baseUrl = '/services/ts/codbex-currencies/gen/codbex-currencies/api/Settings/CurrencyRateController.ts'; + EntityServiceProvider.baseUrl = '/services/java/codbex-currencies/gen/codbex_currencies/api/settings/CurrencyRateController'; }]) .controller('PageController', ($scope, $http, ViewParameters, LocaleService, EntityService) => { const Dialogs = new DialogHub(); @@ -90,11 +90,11 @@ angular.module('page', ['blimpKit', 'platformView', 'platformLocale', 'EntitySer }); }; - $scope.serviceCurrency = '/services/ts/codbex-currencies/gen/codbex-currencies/api/Settings/CurrencyController.ts'; + $scope.serviceCurrency = '/services/java/codbex-currencies/gen/codbex_currencies/api/settings/CurrencyController'; $scope.optionsCurrency = []; - $http.get('/services/ts/codbex-currencies/gen/codbex-currencies/api/Settings/CurrencyController.ts').then((response) => { + $http.get('/services/java/codbex-currencies/gen/codbex_currencies/api/settings/CurrencyController').then((response) => { $scope.optionsCurrency = response.data.map(e => ({ value: e.Id, text: e.Code @@ -118,7 +118,7 @@ angular.module('page', ['blimpKit', 'platformView', 'platformLocale', 'EntitySer $scope.loadMoreOptionsCurrency = () => { const limit = 20; $scope.optionsCurrencyLoading = true; - $http.get(`/services/ts/codbex-currencies/gen/codbex-currencies/api/Settings/CurrencyController.ts?$limit=${limit}&$offset=${++loadMoreOptionsCurrencyCounter * limit}`) + $http.get(`/services/java/codbex-currencies/gen/codbex_currencies/api/settings/CurrencyController?$limit=${limit}&$offset=${++loadMoreOptionsCurrencyCounter * limit}`) .then((response) => { const optionValues = allValuesCurrency.map(e => e.value); const resultValues = response.data.map(e => ({ @@ -168,7 +168,7 @@ angular.module('page', ['blimpKit', 'platformView', 'platformLocale', 'EntitySer } }) if (!cacheHit) { - $http.post('/services/ts/codbex-currencies/gen/codbex-currencies/api/Settings/CurrencyController.ts/search', { + $http.post('/services/java/codbex-currencies/gen/codbex_currencies/api/settings/CurrencyController/search', { conditions: [ { propertyName: 'Code', operator: 'LIKE', value: `${event.originalEvent.target.value}%` } ] diff --git a/codbex-currencies/gen/codbex_currencies/api/settings/CurrencyController.java b/codbex-currencies/gen/codbex_currencies/api/settings/CurrencyController.java new file mode 100644 index 0000000..3260fc1 --- /dev/null +++ b/codbex-currencies/gen/codbex_currencies/api/settings/CurrencyController.java @@ -0,0 +1,194 @@ +package gen.codbex_currencies.api.settings; + +import gen.codbex_currencies.data.settings.CurrencyEntity; +import gen.codbex_currencies.data.settings.CurrencyRepository; + +import org.eclipse.dirigible.components.api.security.UserFacade; +import org.eclipse.dirigible.sdk.platform.Documentation; +import org.eclipse.dirigible.sdk.component.Inject; +import org.eclipse.dirigible.sdk.http.Body; +import org.eclipse.dirigible.sdk.http.Controller; +import org.eclipse.dirigible.sdk.http.Delete; +import org.eclipse.dirigible.sdk.http.Get; +import org.eclipse.dirigible.sdk.http.PathParam; +import org.eclipse.dirigible.sdk.http.Post; +import org.eclipse.dirigible.sdk.http.Put; +import org.eclipse.dirigible.sdk.http.QueryParam; +import org.springframework.http.HttpStatus; +import org.springframework.web.server.ResponseStatusException; + +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +@Controller +@Documentation("codbex-currencies - Currency Controller") +public class CurrencyController { + + private static final Set FILTER_FIELDS = Set.of("Id", "Code", "Name", "Numeric", "Rounding", "Base", "Rate", "CreatedAt", "CreatedBy", "UpdatedAt", "UpdatedBy"); + + @Inject + private CurrencyRepository repository; + + @Get + @Documentation("List Currency") + public List getAll(@QueryParam("$limit") Integer limit, + @QueryParam("$offset") Integer offset) { + checkPermissions("read"); + int actualLimit = limit != null ? limit.intValue() : 20; + int actualOffset = offset != null ? offset.intValue() : 0; + List result = repository.findAll(actualLimit, actualOffset); + return result; + } + + @Get("/count") + @Documentation("Count Currency") + public Map count() { + checkPermissions("read"); + return Map.of("count", repository.count()); + } + + @Post("/count") + @Documentation("Count Currency with filter") + public Map countWithFilter(@Body Map filter) { + checkPermissions("read"); + return Map.of("count", (long) runFilter(filter).size()); + } + + @Post("/search") + @Documentation("Search Currency") + public List search(@Body Map filter) { + checkPermissions("read"); + List result = runFilter(filter); + return result; + } + + @Get("/{id}") + @Documentation("Get Currency by id") + public CurrencyEntity getById(@PathParam("id") Integer id) { + checkPermissions("read"); + CurrencyEntity entity = repository.findOne(id) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Currency not found")); + return entity; + } + + @Post + @Documentation("Create Currency") + public CurrencyEntity create(@Body CurrencyEntity entity) { + checkPermissions("write"); + validate(entity); + return repository.save(entity); + } + + @Put("/{id}") + @Documentation("Update Currency by id") + public CurrencyEntity update(@PathParam("id") Integer id, @Body CurrencyEntity entity) { + checkPermissions("write"); + entity.Id = id; + validate(entity); + return repository.update(entity); + } + + @Delete("/{id}") + @Documentation("Delete Currency by id") + public void deleteById(@PathParam("id") Integer id) { + checkPermissions("write"); + if (repository.findOne(id).isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Currency not found"); + } + repository.deleteById(id); + } + + private List runFilter(Map filter) { + StringBuilder hql = new StringBuilder("from CurrencyEntity e"); + Map params = new LinkedHashMap<>(); + boolean first = true; + if (filter != null && filter.get("equals") instanceof Map equals) { + for (Map.Entry entry : equals.entrySet()) { + String field = requireKnownField(String.valueOf(entry.getKey())); + String paramName = "p" + params.size(); + hql.append(first ? " where e." : " and e.").append(field).append(" = :").append(paramName); + params.put(paramName, entry.getValue()); + first = false; + } + } + if (filter != null && filter.get("conditions") instanceof List conditions) { + for (Object raw : conditions) { + if (!(raw instanceof Map condition)) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid filter condition"); + } + String field = requireKnownField(String.valueOf(condition.get("propertyName"))); + String operator = String.valueOf(condition.get("operator")).toUpperCase(Locale.ROOT); + Object value = condition.get("value"); + String paramName = "p" + params.size(); + String clause = switch (operator) { + case "EQ" -> "e." + field + " = :" + paramName; + case "IN" -> { + if (!(value instanceof Collection)) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "IN value must be a list for field: " + field); + } + yield "e." + field + " in (:" + paramName + ")"; + } + case "LIKE" -> "e." + field + " like :" + paramName; + default -> throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Unsupported operator: " + operator); + }; + hql.append(first ? " where " : " and ").append(clause); + params.put(paramName, value); + first = false; + } + } + return repository.query(hql.toString(), params); + } + + private static String requireKnownField(String field) { + if (!FILTER_FIELDS.contains(field)) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Unknown filter field: " + field); + } + return field; + } + + private void checkPermissions(String op) { + if ("read".equals(op) && !(UserFacade.isInRole("codbex-currencies.Currencies.CurrencyReadOnly") || UserFacade.isInRole("codbex-currencies.Currencies.CurrencyFullAccess"))) { + throw new ResponseStatusException(HttpStatus.FORBIDDEN); + } + if ("write".equals(op) && !UserFacade.isInRole("codbex-currencies.Currencies.CurrencyFullAccess")) { + throw new ResponseStatusException(HttpStatus.FORBIDDEN); + } + } + + private static void validate(CurrencyEntity entity) { + if (entity.Code == null) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "The 'Code' property is required"); + } + if (entity.Code != null && entity.Code.length() > 3) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "The 'Code' exceeds the maximum length of 3"); + } + if (entity.Name == null) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "The 'Name' property is required"); + } + if (entity.Name != null && entity.Name.length() > 127) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "The 'Name' exceeds the maximum length of 127"); + } + if (entity.Numeric == null) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "The 'Numeric' property is required"); + } + if (entity.Numeric != null && entity.Numeric.length() > 3) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "The 'Numeric' exceeds the maximum length of 3"); + } + if (entity.Rounding == null) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "The 'Rounding' property is required"); + } + if (entity.Rate == null) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "The 'Rate' property is required"); + } + if (entity.CreatedBy != null && entity.CreatedBy.length() > 20) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "The 'CreatedBy' exceeds the maximum length of 20"); + } + if (entity.UpdatedBy != null && entity.UpdatedBy.length() > 20) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "The 'UpdatedBy' exceeds the maximum length of 20"); + } + } +} diff --git a/codbex-currencies/gen/codbex_currencies/api/settings/CurrencyRateController.java b/codbex-currencies/gen/codbex_currencies/api/settings/CurrencyRateController.java new file mode 100644 index 0000000..bc6c0a5 --- /dev/null +++ b/codbex-currencies/gen/codbex_currencies/api/settings/CurrencyRateController.java @@ -0,0 +1,179 @@ +package gen.codbex_currencies.api.settings; + +import gen.codbex_currencies.data.settings.CurrencyRateEntity; +import gen.codbex_currencies.data.settings.CurrencyRateRepository; + +import org.eclipse.dirigible.components.api.security.UserFacade; +import org.eclipse.dirigible.sdk.platform.Documentation; +import org.eclipse.dirigible.sdk.component.Inject; +import org.eclipse.dirigible.sdk.http.Body; +import org.eclipse.dirigible.sdk.http.Controller; +import org.eclipse.dirigible.sdk.http.Delete; +import org.eclipse.dirigible.sdk.http.Get; +import org.eclipse.dirigible.sdk.http.PathParam; +import org.eclipse.dirigible.sdk.http.Post; +import org.eclipse.dirigible.sdk.http.Put; +import org.eclipse.dirigible.sdk.http.QueryParam; +import org.springframework.http.HttpStatus; +import org.springframework.web.server.ResponseStatusException; + +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +@Controller +@Documentation("codbex-currencies - CurrencyRate Controller") +public class CurrencyRateController { + + private static final Set FILTER_FIELDS = Set.of("Id", "Currency", "Date", "Rate", "CreatedAt", "CreatedBy", "UpdatedAt", "UpdatedBy"); + + @Inject + private CurrencyRateRepository repository; + + @Get + @Documentation("List CurrencyRate") + public List getAll(@QueryParam("$limit") Integer limit, + @QueryParam("$offset") Integer offset) { + checkPermissions("read"); + int actualLimit = limit != null ? limit.intValue() : 20; + int actualOffset = offset != null ? offset.intValue() : 0; + List result = repository.findAll(actualLimit, actualOffset); + return result; + } + + @Get("/count") + @Documentation("Count CurrencyRate") + public Map count() { + checkPermissions("read"); + return Map.of("count", repository.count()); + } + + @Post("/count") + @Documentation("Count CurrencyRate with filter") + public Map countWithFilter(@Body Map filter) { + checkPermissions("read"); + return Map.of("count", (long) runFilter(filter).size()); + } + + @Post("/search") + @Documentation("Search CurrencyRate") + public List search(@Body Map filter) { + checkPermissions("read"); + List result = runFilter(filter); + return result; + } + + @Get("/{id}") + @Documentation("Get CurrencyRate by id") + public CurrencyRateEntity getById(@PathParam("id") Integer id) { + checkPermissions("read"); + CurrencyRateEntity entity = repository.findOne(id) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "CurrencyRate not found")); + return entity; + } + + @Post + @Documentation("Create CurrencyRate") + public CurrencyRateEntity create(@Body CurrencyRateEntity entity) { + checkPermissions("write"); + validate(entity); + return repository.save(entity); + } + + @Put("/{id}") + @Documentation("Update CurrencyRate by id") + public CurrencyRateEntity update(@PathParam("id") Integer id, @Body CurrencyRateEntity entity) { + checkPermissions("write"); + entity.Id = id; + validate(entity); + return repository.update(entity); + } + + @Delete("/{id}") + @Documentation("Delete CurrencyRate by id") + public void deleteById(@PathParam("id") Integer id) { + checkPermissions("write"); + if (repository.findOne(id).isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "CurrencyRate not found"); + } + repository.deleteById(id); + } + + private List runFilter(Map filter) { + StringBuilder hql = new StringBuilder("from CurrencyRateEntity e"); + Map params = new LinkedHashMap<>(); + boolean first = true; + if (filter != null && filter.get("equals") instanceof Map equals) { + for (Map.Entry entry : equals.entrySet()) { + String field = requireKnownField(String.valueOf(entry.getKey())); + String paramName = "p" + params.size(); + hql.append(first ? " where e." : " and e.").append(field).append(" = :").append(paramName); + params.put(paramName, entry.getValue()); + first = false; + } + } + if (filter != null && filter.get("conditions") instanceof List conditions) { + for (Object raw : conditions) { + if (!(raw instanceof Map condition)) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid filter condition"); + } + String field = requireKnownField(String.valueOf(condition.get("propertyName"))); + String operator = String.valueOf(condition.get("operator")).toUpperCase(Locale.ROOT); + Object value = condition.get("value"); + String paramName = "p" + params.size(); + String clause = switch (operator) { + case "EQ" -> "e." + field + " = :" + paramName; + case "IN" -> { + if (!(value instanceof Collection)) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "IN value must be a list for field: " + field); + } + yield "e." + field + " in (:" + paramName + ")"; + } + case "LIKE" -> "e." + field + " like :" + paramName; + default -> throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Unsupported operator: " + operator); + }; + hql.append(first ? " where " : " and ").append(clause); + params.put(paramName, value); + first = false; + } + } + return repository.query(hql.toString(), params); + } + + private static String requireKnownField(String field) { + if (!FILTER_FIELDS.contains(field)) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Unknown filter field: " + field); + } + return field; + } + + private void checkPermissions(String op) { + if ("read".equals(op) && !(UserFacade.isInRole("codbex-currencies.Currencies.CurrencyRateReadOnly") || UserFacade.isInRole("codbex-currencies.Currencies.CurrencyRateFullAccess"))) { + throw new ResponseStatusException(HttpStatus.FORBIDDEN); + } + if ("write".equals(op) && !UserFacade.isInRole("codbex-currencies.Currencies.CurrencyRateFullAccess")) { + throw new ResponseStatusException(HttpStatus.FORBIDDEN); + } + } + + private static void validate(CurrencyRateEntity entity) { + if (entity.Currency == null) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "The 'Currency' property is required"); + } + if (entity.Date == null) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "The 'Date' property is required"); + } + if (entity.Rate == null) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "The 'Rate' property is required"); + } + if (entity.CreatedBy != null && entity.CreatedBy.length() > 20) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "The 'CreatedBy' exceeds the maximum length of 20"); + } + if (entity.UpdatedBy != null && entity.UpdatedBy.length() > 20) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "The 'UpdatedBy' exceeds the maximum length of 20"); + } + } +} diff --git a/codbex-currencies/gen/codbex-currencies/data/Settings/Currency.extensionpoint b/codbex-currencies/gen/codbex_currencies/data/settings/Currency.extensionpoint similarity index 98% rename from codbex-currencies/gen/codbex-currencies/data/Settings/Currency.extensionpoint rename to codbex-currencies/gen/codbex_currencies/data/settings/Currency.extensionpoint index e0693fc..14232c0 100644 --- a/codbex-currencies/gen/codbex-currencies/data/Settings/Currency.extensionpoint +++ b/codbex-currencies/gen/codbex_currencies/data/settings/Currency.extensionpoint @@ -1,4 +1,4 @@ { "name": "codbex-currencies-Settings-Currency", "description": "Extension Point for the codbex-currencies-Settings-Currency entity" -} \ No newline at end of file +} diff --git a/codbex-currencies/gen/codbex_currencies/data/settings/CurrencyEntity.java b/codbex-currencies/gen/codbex_currencies/data/settings/CurrencyEntity.java new file mode 100644 index 0000000..e38fb20 --- /dev/null +++ b/codbex-currencies/gen/codbex_currencies/data/settings/CurrencyEntity.java @@ -0,0 +1,70 @@ +package gen.codbex_currencies.data.settings; + +import org.eclipse.dirigible.sdk.db.Column; +import org.eclipse.dirigible.sdk.db.CreatedAt; +import org.eclipse.dirigible.sdk.db.CreatedBy; +import org.eclipse.dirigible.sdk.platform.Documentation; +import org.eclipse.dirigible.sdk.db.Entity; +import org.eclipse.dirigible.sdk.db.GeneratedValue; +import org.eclipse.dirigible.sdk.db.GenerationType; +import org.eclipse.dirigible.sdk.db.Id; +import org.eclipse.dirigible.sdk.db.Table; +import org.eclipse.dirigible.sdk.db.UpdatedAt; +import org.eclipse.dirigible.sdk.db.UpdatedBy; + +@Entity +@Table(name = "CODBEX_CURRENCY") +@Documentation("Currency entity mapping") +public class CurrencyEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "CURRENCY_ID") + @Documentation("Id") + public Integer Id; + + @Column(name = "CURRENCY_CODE", length = 3, nullable = false, unique = true) + @Documentation("Code") + public String Code; + + @Column(name = "CURRENCY_NAME", length = 127, nullable = false) + @Documentation("Name") + public String Name; + + @Column(name = "CURRENCY_NUMERIC", length = 3, nullable = false, unique = true) + @Documentation("Numeric") + public String Numeric; + + @Column(name = "CURRENCY_ROUNDING", nullable = false) + @Documentation("Rounding") + public Integer Rounding; + + @Column(name = "CURRENCY_BASE", nullable = true) + @Documentation("Base") + public Boolean Base; + + @Column(name = "CURRENCY_RATE", nullable = false) + @Documentation("Rate") + public Double Rate; + + @CreatedAt + @Column(name = "CURRENCY_CREATEDAT", nullable = true) + @Documentation("CreatedAt") + public java.time.Instant CreatedAt; + + @CreatedBy + @Column(name = "CURRENCY_CREATEDBY", length = 20, nullable = true) + @Documentation("CreatedBy") + public String CreatedBy; + + @UpdatedAt + @Column(name = "CURRENCY_UPDATEDAT", nullable = true) + @Documentation("UpdatedAt") + public java.time.Instant UpdatedAt; + + @UpdatedBy + @Column(name = "CURRENCY_UPDATEDBY", length = 20, nullable = true) + @Documentation("UpdatedBy") + public String UpdatedBy; + +} diff --git a/codbex-currencies/gen/codbex-currencies/data/Settings/CurrencyRate.extensionpoint b/codbex-currencies/gen/codbex_currencies/data/settings/CurrencyRate.extensionpoint similarity index 98% rename from codbex-currencies/gen/codbex-currencies/data/Settings/CurrencyRate.extensionpoint rename to codbex-currencies/gen/codbex_currencies/data/settings/CurrencyRate.extensionpoint index 44244c9..6f6e786 100644 --- a/codbex-currencies/gen/codbex-currencies/data/Settings/CurrencyRate.extensionpoint +++ b/codbex-currencies/gen/codbex_currencies/data/settings/CurrencyRate.extensionpoint @@ -1,4 +1,4 @@ { "name": "codbex-currencies-Settings-CurrencyRate", "description": "Extension Point for the codbex-currencies-Settings-CurrencyRate entity" -} \ No newline at end of file +} diff --git a/codbex-currencies/gen/codbex_currencies/data/settings/CurrencyRateEntity.java b/codbex-currencies/gen/codbex_currencies/data/settings/CurrencyRateEntity.java new file mode 100644 index 0000000..a19e551 --- /dev/null +++ b/codbex-currencies/gen/codbex_currencies/data/settings/CurrencyRateEntity.java @@ -0,0 +1,58 @@ +package gen.codbex_currencies.data.settings; + +import org.eclipse.dirigible.sdk.db.Column; +import org.eclipse.dirigible.sdk.db.CreatedAt; +import org.eclipse.dirigible.sdk.db.CreatedBy; +import org.eclipse.dirigible.sdk.platform.Documentation; +import org.eclipse.dirigible.sdk.db.Entity; +import org.eclipse.dirigible.sdk.db.GeneratedValue; +import org.eclipse.dirigible.sdk.db.GenerationType; +import org.eclipse.dirigible.sdk.db.Id; +import org.eclipse.dirigible.sdk.db.Table; +import org.eclipse.dirigible.sdk.db.UpdatedAt; +import org.eclipse.dirigible.sdk.db.UpdatedBy; + +@Entity +@Table(name = "CODBEX_CURRENCYRATE") +@Documentation("CurrencyRate entity mapping") +public class CurrencyRateEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "CURRENCYRATE_ID") + @Documentation("Id") + public Integer Id; + + @Column(name = "CURRENCYRATE_CURRENCY", nullable = false) + @Documentation("Currency") + public Integer Currency; + + @Column(name = "CURRENCYRATE_DATE", nullable = false) + @Documentation("Date") + public java.time.LocalDate Date; + + @Column(name = "CURRENCYRATE_RATE", nullable = false) + @Documentation("Rate") + public Double Rate; + + @CreatedAt + @Column(name = "CURRENCYRATE_CREATEDAT", nullable = true) + @Documentation("CreatedAt") + public java.time.Instant CreatedAt; + + @CreatedBy + @Column(name = "CURRENCYRATE_CREATEDBY", length = 20, nullable = true) + @Documentation("CreatedBy") + public String CreatedBy; + + @UpdatedAt + @Column(name = "CURRENCYRATE_UPDATEDAT", nullable = true) + @Documentation("UpdatedAt") + public java.time.Instant UpdatedAt; + + @UpdatedBy + @Column(name = "CURRENCYRATE_UPDATEDBY", length = 20, nullable = true) + @Documentation("UpdatedBy") + public String UpdatedBy; + +} diff --git a/codbex-currencies/gen/codbex_currencies/data/settings/CurrencyRateRepository.java b/codbex-currencies/gen/codbex_currencies/data/settings/CurrencyRateRepository.java new file mode 100644 index 0000000..12eba4f --- /dev/null +++ b/codbex-currencies/gen/codbex_currencies/data/settings/CurrencyRateRepository.java @@ -0,0 +1,12 @@ +package gen.codbex_currencies.data.settings; + +import org.eclipse.dirigible.components.data.store.java.repository.JavaRepository; +import org.eclipse.dirigible.sdk.component.Repository; + +@Repository +public class CurrencyRateRepository extends JavaRepository { + + public CurrencyRateRepository() { + super(CurrencyRateEntity.class); + } +} diff --git a/codbex-currencies/gen/codbex_currencies/data/settings/CurrencyRepository.java b/codbex-currencies/gen/codbex_currencies/data/settings/CurrencyRepository.java new file mode 100644 index 0000000..f766364 --- /dev/null +++ b/codbex-currencies/gen/codbex_currencies/data/settings/CurrencyRepository.java @@ -0,0 +1,12 @@ +package gen.codbex_currencies.data.settings; + +import org.eclipse.dirigible.components.data.store.java.repository.JavaRepository; +import org.eclipse.dirigible.sdk.component.Repository; + +@Repository +public class CurrencyRepository extends JavaRepository { + + public CurrencyRepository() { + super(CurrencyEntity.class); + } +} diff --git a/codbex-currencies/gen/codbex-currencies/roles/default-roles.roles b/codbex-currencies/gen/codbex_currencies/roles/default-roles.roles similarity index 99% rename from codbex-currencies/gen/codbex-currencies/roles/default-roles.roles rename to codbex-currencies/gen/codbex_currencies/roles/default-roles.roles index 0b432b1..63596a6 100644 --- a/codbex-currencies/gen/codbex-currencies/roles/default-roles.roles +++ b/codbex-currencies/gen/codbex_currencies/roles/default-roles.roles @@ -15,4 +15,4 @@ "name": "codbex-currencies.Currencies.CurrencyRateFullAccess", "description": "A role that grants full access for CurrencyRate." } -] \ No newline at end of file +]