diff --git a/codbex-methods/codbex-methods.gen b/codbex-methods/codbex-methods.gen index f7163d7..963eb9d 100644 --- a/codbex-methods/codbex-methods.gen +++ b/codbex-methods/codbex-methods.gen @@ -1,15 +1,17 @@ { "tablePrefix": "CODBEX_", "brand": "codbex", - "brandUrl": "https://www.codbex.com", - "title": "Methods Managing Application", - "description": "Managing methods data", + "brandUrl": "https://www.codbex.com/", + "title": "Methods Management Module", + "description": "Managing Methods Data", "projectName": "codbex-methods", "workspaceName": "workspace", "filePath": "codbex-methods.model", - "templateId": "template-application-angular-v2/template/template.js", + "templateId": "template-application-angular-java/template/template.js", "fileName": "codbex-methods", "genFolderName": "codbex-methods", + "javaRuntime": true, + "javaGenFolderName": "codbex_methods", "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": 20, "inputRule": "" @@ -125,6 +129,7 @@ "tooltip": "PaymentMethod", "type": "SETTING", "dataSource": "DefaultDB", + "javaPerspectiveName": "settings", "referencedProjections": [], "primaryKeys": [ "Id" @@ -157,6 +162,7 @@ "widgetDropdownControllerUrl": "", "dataTypeJava": "int", "dataTypeTypescript": "number", + "dataTypeJavaClass": "Integer", "inputRule": "" }, { @@ -184,6 +190,7 @@ "widgetDropdownControllerUrl": "", "dataTypeJava": "string", "dataTypeTypescript": "string", + "dataTypeJavaClass": "String", "minLength": 0, "maxLength": 20, "inputRule": "" @@ -216,6 +223,7 @@ "tooltip": "SentMethod", "type": "SETTING", "dataSource": "DefaultDB", + "javaPerspectiveName": "settings", "referencedProjections": [], "primaryKeys": [ "Id" diff --git a/codbex-methods/gen/codbex-methods/api/Settings/PaymentMethodController.ts b/codbex-methods/gen/codbex-methods/api/Settings/PaymentMethodController.ts deleted file mode 100644 index 5fb68ea..0000000 --- a/codbex-methods/gen/codbex-methods/api/Settings/PaymentMethodController.ts +++ /dev/null @@ -1,178 +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 { PaymentMethodRepository } from '../../data/Settings/PaymentMethodRepository' -import { PaymentMethodEntity } from '../../data/Settings/PaymentMethodEntity' - -const validationModules = await Extensions.loadExtensionModules('codbex-methods-Settings-PaymentMethod', ['validate']); - -@Controller -@Documentation('codbex-methods - PaymentMethod Controller') -@Injected() -class PaymentMethodController { - - @Inject('PaymentMethodRepository') - private readonly repository!: PaymentMethodRepository; - - @Get('/') - @Documentation('Get All PaymentMethod') - public getAll(_: any, ctx: any): PaymentMethodEntity[] { - 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 PaymentMethod') - public create(entity: PaymentMethodEntity): PaymentMethodEntity { - try { - this.checkPermissions('write'); - this.validateEntity(entity); - entity.Id = this.repository.create(entity) as any; - response.setHeader('Content-Location', '/services/ts/codbex-methods/gen/codbex-methods/api/Settings/PaymentMethodController.ts/' + entity.Id); - response.setStatus(response.CREATED); - return entity; - } catch (error: any) { - this.handleError(error); - } - return undefined as any; - } - - @Get('/count') - @Documentation('Count PaymentMethod') - 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 PaymentMethod 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 PaymentMethod') - public search(filter: any): PaymentMethodEntity[] { - try { - this.checkPermissions('read'); - return this.repository.findAll(filter); - } catch (error: any) { - this.handleError(error); - } - return undefined as any; - } - - @Get('/:id') - @Documentation('Get PaymentMethod by id') - public getById(_: any, ctx: any): PaymentMethodEntity { - 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('PaymentMethod not found'); - } - } catch (error: any) { - this.handleError(error); - } - return undefined as any; - } - - @Put('/:id') - @Documentation('Update PaymentMethod by id') - public update(entity: PaymentMethodEntity, ctx: any): PaymentMethodEntity { - 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 PaymentMethod 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('PaymentMethod 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-methods.PaymentMethod.PaymentMethodReadOnly') || user.isInRole('codbex-methods.PaymentMethod.PaymentMethodFullAccess'))) { - throw new ForbiddenError(); - } - if (operationType === 'write' && !user.isInRole('codbex-methods.PaymentMethod.PaymentMethodFullAccess')) { - throw new ForbiddenError(); - } - } - - private validateEntity(entity: any): void { - if (entity.Name === null || entity.Name === undefined) { - throw new ValidationError(`The 'Name' property is required, provide a valid value`); - } - if (entity.Name?.length > 20) { - throw new ValidationError(`The 'Name' exceeds the maximum length of [20] characters`); - } - for (const next of validationModules) { - next.validate(entity); - } - } - -} diff --git a/codbex-methods/gen/codbex-methods/api/Settings/SentMethodController.ts b/codbex-methods/gen/codbex-methods/api/Settings/SentMethodController.ts deleted file mode 100644 index 2f879d5..0000000 --- a/codbex-methods/gen/codbex-methods/api/Settings/SentMethodController.ts +++ /dev/null @@ -1,178 +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 { SentMethodRepository } from '../../data/Settings/SentMethodRepository' -import { SentMethodEntity } from '../../data/Settings/SentMethodEntity' - -const validationModules = await Extensions.loadExtensionModules('codbex-methods-Settings-SentMethod', ['validate']); - -@Controller -@Documentation('codbex-methods - SentMethod Controller') -@Injected() -class SentMethodController { - - @Inject('SentMethodRepository') - private readonly repository!: SentMethodRepository; - - @Get('/') - @Documentation('Get All SentMethod') - public getAll(_: any, ctx: any): SentMethodEntity[] { - 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 SentMethod') - public create(entity: SentMethodEntity): SentMethodEntity { - try { - this.checkPermissions('write'); - this.validateEntity(entity); - entity.Id = this.repository.create(entity) as any; - response.setHeader('Content-Location', '/services/ts/codbex-methods/gen/codbex-methods/api/Settings/SentMethodController.ts/' + entity.Id); - response.setStatus(response.CREATED); - return entity; - } catch (error: any) { - this.handleError(error); - } - return undefined as any; - } - - @Get('/count') - @Documentation('Count SentMethod') - 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 SentMethod 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 SentMethod') - public search(filter: any): SentMethodEntity[] { - try { - this.checkPermissions('read'); - return this.repository.findAll(filter); - } catch (error: any) { - this.handleError(error); - } - return undefined as any; - } - - @Get('/:id') - @Documentation('Get SentMethod by id') - public getById(_: any, ctx: any): SentMethodEntity { - 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('SentMethod not found'); - } - } catch (error: any) { - this.handleError(error); - } - return undefined as any; - } - - @Put('/:id') - @Documentation('Update SentMethod by id') - public update(entity: SentMethodEntity, ctx: any): SentMethodEntity { - 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 SentMethod 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('SentMethod 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-methods.SentMethod.SentMethodReadOnly') || user.isInRole('codbex-methods.SentMethod.SentMethodFullAccess'))) { - throw new ForbiddenError(); - } - if (operationType === 'write' && !user.isInRole('codbex-methods.SentMethod.SentMethodFullAccess')) { - throw new ForbiddenError(); - } - } - - private validateEntity(entity: any): void { - if (entity.Name === null || entity.Name === undefined) { - throw new ValidationError(`The 'Name' property is required, provide a valid value`); - } - if (entity.Name?.length > 20) { - throw new ValidationError(`The 'Name' exceeds the maximum length of [20] characters`); - } - for (const next of validationModules) { - next.validate(entity); - } - } - -} diff --git a/codbex-methods/gen/codbex-methods/data/Settings/PaymentMethodEntity.ts b/codbex-methods/gen/codbex-methods/data/Settings/PaymentMethodEntity.ts deleted file mode 100644 index 89ebe64..0000000 --- a/codbex-methods/gen/codbex-methods/data/Settings/PaymentMethodEntity.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { Entity, Table, Id, Generated, Column, Documentation, CreatedAt, CreatedBy, UpdatedAt, UpdatedBy} from '@aerokit/sdk/db' - -@Entity('PaymentMethodEntity') -@Table('CODBEX_PAYMENTMETHOD') -@Documentation('PaymentMethod entity mapping') -export class PaymentMethodEntity { - - @Id() - @Generated('sequence') - @Documentation('Id') - @Column({ - name: 'PAYMENTMETHOD_ID', - type: 'integer', - }) - public Id?: number; - - @Documentation('Name') - @Column({ - name: 'PAYMENTMETHOD_NAME', - type: 'string', - length: 20, - }) - public Name!: string; - -} - -(new PaymentMethodEntity()); diff --git a/codbex-methods/gen/codbex-methods/data/Settings/PaymentMethodRepository.ts b/codbex-methods/gen/codbex-methods/data/Settings/PaymentMethodRepository.ts deleted file mode 100644 index 8e0ca6a..0000000 --- a/codbex-methods/gen/codbex-methods/data/Settings/PaymentMethodRepository.ts +++ /dev/null @@ -1,25 +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 { PaymentMethodEntity } from './PaymentMethodEntity' - -@Component('PaymentMethodRepository') -export class PaymentMethodRepository extends Repository { - - constructor() { - super((PaymentMethodEntity as EntityConstructor)); - } - - protected override async triggerEvent(data: EntityEvent): Promise { - const triggerExtensions = await Extensions.loadExtensionModules('codbex-methods-Settings-PaymentMethod', ['trigger']); - triggerExtensions.forEach(triggerExtension => { - try { - triggerExtension.trigger(data); - } catch (error) { - console.error(error); - } - }); - Producer.topic('codbex-methods-Settings-PaymentMethod').send(JSON.stringify(data)); - } -} diff --git a/codbex-methods/gen/codbex-methods/data/Settings/SentMethodEntity.ts b/codbex-methods/gen/codbex-methods/data/Settings/SentMethodEntity.ts deleted file mode 100644 index 4b25f50..0000000 --- a/codbex-methods/gen/codbex-methods/data/Settings/SentMethodEntity.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { Entity, Table, Id, Generated, Column, Documentation, CreatedAt, CreatedBy, UpdatedAt, UpdatedBy} from '@aerokit/sdk/db' - -@Entity('SentMethodEntity') -@Table('CODBEX_SENTMETHOD') -@Documentation('SentMethod entity mapping') -export class SentMethodEntity { - - @Id() - @Generated('sequence') - @Documentation('Id') - @Column({ - name: 'SENTMETHOD_ID', - type: 'integer', - }) - public Id?: number; - - @Documentation('Name') - @Column({ - name: 'SENTMETHOD_NAME', - type: 'string', - length: 20, - }) - public Name!: string; - -} - -(new SentMethodEntity()); diff --git a/codbex-methods/gen/codbex-methods/data/Settings/SentMethodRepository.ts b/codbex-methods/gen/codbex-methods/data/Settings/SentMethodRepository.ts deleted file mode 100644 index 374f6c3..0000000 --- a/codbex-methods/gen/codbex-methods/data/Settings/SentMethodRepository.ts +++ /dev/null @@ -1,25 +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 { SentMethodEntity } from './SentMethodEntity' - -@Component('SentMethodRepository') -export class SentMethodRepository extends Repository { - - constructor() { - super((SentMethodEntity as EntityConstructor)); - } - - protected override async triggerEvent(data: EntityEvent): Promise { - const triggerExtensions = await Extensions.loadExtensionModules('codbex-methods-Settings-SentMethod', ['trigger']); - triggerExtensions.forEach(triggerExtension => { - try { - triggerExtension.trigger(data); - } catch (error) { - console.error(error); - } - }); - Producer.topic('codbex-methods-Settings-SentMethod').send(JSON.stringify(data)); - } -} diff --git a/codbex-methods/gen/codbex-methods/odata/codbex-methods.odata b/codbex-methods/gen/codbex-methods/odata/codbex-methods.odata deleted file mode 100644 index f149140..0000000 --- a/codbex-methods/gen/codbex-methods/odata/codbex-methods.odata +++ /dev/null @@ -1,4 +0,0 @@ -{ - "namespace": "", - "entities": [] -} diff --git a/codbex-methods/gen/codbex-methods/ui/Settings/PaymentMethod/controller.js b/codbex-methods/gen/codbex-methods/ui/Settings/PaymentMethod/controller.js index 50e4915..9e833b3 100644 --- a/codbex-methods/gen/codbex-methods/ui/Settings/PaymentMethod/controller.js +++ b/codbex-methods/gen/codbex-methods/ui/Settings/PaymentMethod/controller.js @@ -1,6 +1,6 @@ angular.module('page', ['blimpKit', 'platformView', 'platformLocale', 'EntityService']) .config(['EntityServiceProvider', (EntityServiceProvider) => { - EntityServiceProvider.baseUrl = '/services/ts/codbex-methods/gen/codbex-methods/api/Settings/PaymentMethodController.ts'; + EntityServiceProvider.baseUrl = '/services/java/codbex-methods/gen/codbex_methods/api/settings/PaymentMethodController'; }]) .controller('PageController', ($scope, EntityService, Extensions, LocaleService, ButtonStates) => { const Dialogs = new DialogHub(); diff --git a/codbex-methods/gen/codbex-methods/ui/Settings/PaymentMethod/dialog-window/controller.js b/codbex-methods/gen/codbex-methods/ui/Settings/PaymentMethod/dialog-window/controller.js index 89e1f64..9c20455 100644 --- a/codbex-methods/gen/codbex-methods/ui/Settings/PaymentMethod/dialog-window/controller.js +++ b/codbex-methods/gen/codbex-methods/ui/Settings/PaymentMethod/dialog-window/controller.js @@ -1,6 +1,6 @@ angular.module('page', ['blimpKit', 'platformView', 'platformLocale', 'EntityService']) .config(['EntityServiceProvider', (EntityServiceProvider) => { - EntityServiceProvider.baseUrl = '/services/ts/codbex-methods/gen/codbex-methods/api/Settings/PaymentMethodController.ts'; + EntityServiceProvider.baseUrl = '/services/java/codbex-methods/gen/codbex_methods/api/settings/PaymentMethodController'; }]) .controller('PageController', ($scope, $http, ViewParameters, LocaleService, EntityService) => { const Dialogs = new DialogHub(); diff --git a/codbex-methods/gen/codbex-methods/ui/Settings/SentMethod/controller.js b/codbex-methods/gen/codbex-methods/ui/Settings/SentMethod/controller.js index 3524409..69554d9 100644 --- a/codbex-methods/gen/codbex-methods/ui/Settings/SentMethod/controller.js +++ b/codbex-methods/gen/codbex-methods/ui/Settings/SentMethod/controller.js @@ -1,6 +1,6 @@ angular.module('page', ['blimpKit', 'platformView', 'platformLocale', 'EntityService']) .config(['EntityServiceProvider', (EntityServiceProvider) => { - EntityServiceProvider.baseUrl = '/services/ts/codbex-methods/gen/codbex-methods/api/Settings/SentMethodController.ts'; + EntityServiceProvider.baseUrl = '/services/java/codbex-methods/gen/codbex_methods/api/settings/SentMethodController'; }]) .controller('PageController', ($scope, EntityService, Extensions, LocaleService, ButtonStates) => { const Dialogs = new DialogHub(); diff --git a/codbex-methods/gen/codbex-methods/ui/Settings/SentMethod/dialog-window/controller.js b/codbex-methods/gen/codbex-methods/ui/Settings/SentMethod/dialog-window/controller.js index 1ec958b..5a952c7 100644 --- a/codbex-methods/gen/codbex-methods/ui/Settings/SentMethod/dialog-window/controller.js +++ b/codbex-methods/gen/codbex-methods/ui/Settings/SentMethod/dialog-window/controller.js @@ -1,6 +1,6 @@ angular.module('page', ['blimpKit', 'platformView', 'platformLocale', 'EntityService']) .config(['EntityServiceProvider', (EntityServiceProvider) => { - EntityServiceProvider.baseUrl = '/services/ts/codbex-methods/gen/codbex-methods/api/Settings/SentMethodController.ts'; + EntityServiceProvider.baseUrl = '/services/java/codbex-methods/gen/codbex_methods/api/settings/SentMethodController'; }]) .controller('PageController', ($scope, $http, ViewParameters, LocaleService, EntityService) => { const Dialogs = new DialogHub(); diff --git a/codbex-methods/gen/codbex_methods/api/settings/PaymentMethodController.java b/codbex-methods/gen/codbex_methods/api/settings/PaymentMethodController.java new file mode 100644 index 0000000..f7a4b89 --- /dev/null +++ b/codbex-methods/gen/codbex_methods/api/settings/PaymentMethodController.java @@ -0,0 +1,170 @@ +package gen.codbex_methods.api.settings; + +import gen.codbex_methods.data.settings.PaymentMethodEntity; +import gen.codbex_methods.data.settings.PaymentMethodRepository; + +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-methods - PaymentMethod Controller") +public class PaymentMethodController { + + private static final Set FILTER_FIELDS = Set.of("Id", "Name"); + + @Inject + private PaymentMethodRepository repository; + + @Get + @Documentation("List PaymentMethod") + 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 PaymentMethod") + public Map count() { + checkPermissions("read"); + return Map.of("count", repository.count()); + } + + @Post("/count") + @Documentation("Count PaymentMethod with filter") + public Map countWithFilter(@Body Map filter) { + checkPermissions("read"); + return Map.of("count", (long) runFilter(filter).size()); + } + + @Post("/search") + @Documentation("Search PaymentMethod") + public List search(@Body Map filter) { + checkPermissions("read"); + List result = runFilter(filter); + return result; + } + + @Get("/{id}") + @Documentation("Get PaymentMethod by id") + public PaymentMethodEntity getById(@PathParam("id") Integer id) { + checkPermissions("read"); + PaymentMethodEntity entity = repository.findOne(id) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "PaymentMethod not found")); + return entity; + } + + @Post + @Documentation("Create PaymentMethod") + public PaymentMethodEntity create(@Body PaymentMethodEntity entity) { + checkPermissions("write"); + validate(entity); + return repository.save(entity); + } + + @Put("/{id}") + @Documentation("Update PaymentMethod by id") + public PaymentMethodEntity update(@PathParam("id") Integer id, @Body PaymentMethodEntity entity) { + checkPermissions("write"); + entity.Id = id; + validate(entity); + return repository.update(entity); + } + + @Delete("/{id}") + @Documentation("Delete PaymentMethod by id") + public void deleteById(@PathParam("id") Integer id) { + checkPermissions("write"); + if (repository.findOne(id).isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "PaymentMethod not found"); + } + repository.deleteById(id); + } + + private List runFilter(Map filter) { + StringBuilder hql = new StringBuilder("from PaymentMethodEntity 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-methods.PaymentMethod.PaymentMethodReadOnly") || UserFacade.isInRole("codbex-methods.PaymentMethod.PaymentMethodFullAccess"))) { + throw new ResponseStatusException(HttpStatus.FORBIDDEN); + } + if ("write".equals(op) && !UserFacade.isInRole("codbex-methods.PaymentMethod.PaymentMethodFullAccess")) { + throw new ResponseStatusException(HttpStatus.FORBIDDEN); + } + } + + private static void validate(PaymentMethodEntity entity) { + if (entity.Name == null) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "The 'Name' property is required"); + } + if (entity.Name != null && entity.Name.length() > 20) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "The 'Name' exceeds the maximum length of 20"); + } + } +} diff --git a/codbex-methods/gen/codbex_methods/api/settings/SentMethodController.java b/codbex-methods/gen/codbex_methods/api/settings/SentMethodController.java new file mode 100644 index 0000000..5ceb57b --- /dev/null +++ b/codbex-methods/gen/codbex_methods/api/settings/SentMethodController.java @@ -0,0 +1,170 @@ +package gen.codbex_methods.api.settings; + +import gen.codbex_methods.data.settings.SentMethodEntity; +import gen.codbex_methods.data.settings.SentMethodRepository; + +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-methods - SentMethod Controller") +public class SentMethodController { + + private static final Set FILTER_FIELDS = Set.of("Id", "Name"); + + @Inject + private SentMethodRepository repository; + + @Get + @Documentation("List SentMethod") + 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 SentMethod") + public Map count() { + checkPermissions("read"); + return Map.of("count", repository.count()); + } + + @Post("/count") + @Documentation("Count SentMethod with filter") + public Map countWithFilter(@Body Map filter) { + checkPermissions("read"); + return Map.of("count", (long) runFilter(filter).size()); + } + + @Post("/search") + @Documentation("Search SentMethod") + public List search(@Body Map filter) { + checkPermissions("read"); + List result = runFilter(filter); + return result; + } + + @Get("/{id}") + @Documentation("Get SentMethod by id") + public SentMethodEntity getById(@PathParam("id") Integer id) { + checkPermissions("read"); + SentMethodEntity entity = repository.findOne(id) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "SentMethod not found")); + return entity; + } + + @Post + @Documentation("Create SentMethod") + public SentMethodEntity create(@Body SentMethodEntity entity) { + checkPermissions("write"); + validate(entity); + return repository.save(entity); + } + + @Put("/{id}") + @Documentation("Update SentMethod by id") + public SentMethodEntity update(@PathParam("id") Integer id, @Body SentMethodEntity entity) { + checkPermissions("write"); + entity.Id = id; + validate(entity); + return repository.update(entity); + } + + @Delete("/{id}") + @Documentation("Delete SentMethod by id") + public void deleteById(@PathParam("id") Integer id) { + checkPermissions("write"); + if (repository.findOne(id).isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "SentMethod not found"); + } + repository.deleteById(id); + } + + private List runFilter(Map filter) { + StringBuilder hql = new StringBuilder("from SentMethodEntity 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-methods.SentMethod.SentMethodReadOnly") || UserFacade.isInRole("codbex-methods.SentMethod.SentMethodFullAccess"))) { + throw new ResponseStatusException(HttpStatus.FORBIDDEN); + } + if ("write".equals(op) && !UserFacade.isInRole("codbex-methods.SentMethod.SentMethodFullAccess")) { + throw new ResponseStatusException(HttpStatus.FORBIDDEN); + } + } + + private static void validate(SentMethodEntity entity) { + if (entity.Name == null) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "The 'Name' property is required"); + } + if (entity.Name != null && entity.Name.length() > 20) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "The 'Name' exceeds the maximum length of 20"); + } + } +} diff --git a/codbex-methods/gen/codbex-methods/data/Settings/PaymentMethod.extensionpoint b/codbex-methods/gen/codbex_methods/data/settings/PaymentMethod.extensionpoint similarity index 98% rename from codbex-methods/gen/codbex-methods/data/Settings/PaymentMethod.extensionpoint rename to codbex-methods/gen/codbex_methods/data/settings/PaymentMethod.extensionpoint index f89539b..749af6f 100644 --- a/codbex-methods/gen/codbex-methods/data/Settings/PaymentMethod.extensionpoint +++ b/codbex-methods/gen/codbex_methods/data/settings/PaymentMethod.extensionpoint @@ -1,4 +1,4 @@ { "name": "codbex-methods-Settings-PaymentMethod", "description": "Extension Point for the codbex-methods-Settings-PaymentMethod entity" -} \ No newline at end of file +} diff --git a/codbex-methods/gen/codbex_methods/data/settings/PaymentMethodEntity.java b/codbex-methods/gen/codbex_methods/data/settings/PaymentMethodEntity.java new file mode 100644 index 0000000..b79abb8 --- /dev/null +++ b/codbex-methods/gen/codbex_methods/data/settings/PaymentMethodEntity.java @@ -0,0 +1,30 @@ +package gen.codbex_methods.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_PAYMENTMETHOD") +@Documentation("PaymentMethod entity mapping") +public class PaymentMethodEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "PAYMENTMETHOD_ID") + @Documentation("Id") + public Integer Id; + + @Column(name = "PAYMENTMETHOD_NAME", length = 20, nullable = false, unique = true) + @Documentation("Name") + public String Name; + +} diff --git a/codbex-methods/gen/codbex_methods/data/settings/PaymentMethodRepository.java b/codbex-methods/gen/codbex_methods/data/settings/PaymentMethodRepository.java new file mode 100644 index 0000000..3f50152 --- /dev/null +++ b/codbex-methods/gen/codbex_methods/data/settings/PaymentMethodRepository.java @@ -0,0 +1,12 @@ +package gen.codbex_methods.data.settings; + +import org.eclipse.dirigible.components.data.store.java.repository.JavaRepository; +import org.eclipse.dirigible.sdk.component.Repository; + +@Repository +public class PaymentMethodRepository extends JavaRepository { + + public PaymentMethodRepository() { + super(PaymentMethodEntity.class); + } +} diff --git a/codbex-methods/gen/codbex-methods/data/Settings/SentMethod.extensionpoint b/codbex-methods/gen/codbex_methods/data/settings/SentMethod.extensionpoint similarity index 98% rename from codbex-methods/gen/codbex-methods/data/Settings/SentMethod.extensionpoint rename to codbex-methods/gen/codbex_methods/data/settings/SentMethod.extensionpoint index 2fa0b47..e610bc3 100644 --- a/codbex-methods/gen/codbex-methods/data/Settings/SentMethod.extensionpoint +++ b/codbex-methods/gen/codbex_methods/data/settings/SentMethod.extensionpoint @@ -1,4 +1,4 @@ { "name": "codbex-methods-Settings-SentMethod", "description": "Extension Point for the codbex-methods-Settings-SentMethod entity" -} \ No newline at end of file +} diff --git a/codbex-methods/gen/codbex_methods/data/settings/SentMethodEntity.java b/codbex-methods/gen/codbex_methods/data/settings/SentMethodEntity.java new file mode 100644 index 0000000..5941d7e --- /dev/null +++ b/codbex-methods/gen/codbex_methods/data/settings/SentMethodEntity.java @@ -0,0 +1,30 @@ +package gen.codbex_methods.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_SENTMETHOD") +@Documentation("SentMethod entity mapping") +public class SentMethodEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "SENTMETHOD_ID") + @Documentation("Id") + public Integer Id; + + @Column(name = "SENTMETHOD_NAME", length = 20, nullable = false, unique = true) + @Documentation("Name") + public String Name; + +} diff --git a/codbex-methods/gen/codbex_methods/data/settings/SentMethodRepository.java b/codbex-methods/gen/codbex_methods/data/settings/SentMethodRepository.java new file mode 100644 index 0000000..b1e1b92 --- /dev/null +++ b/codbex-methods/gen/codbex_methods/data/settings/SentMethodRepository.java @@ -0,0 +1,12 @@ +package gen.codbex_methods.data.settings; + +import org.eclipse.dirigible.components.data.store.java.repository.JavaRepository; +import org.eclipse.dirigible.sdk.component.Repository; + +@Repository +public class SentMethodRepository extends JavaRepository { + + public SentMethodRepository() { + super(SentMethodEntity.class); + } +} diff --git a/codbex-methods/gen/codbex-methods/roles/default-roles.roles b/codbex-methods/gen/codbex_methods/roles/default-roles.roles similarity index 99% rename from codbex-methods/gen/codbex-methods/roles/default-roles.roles rename to codbex-methods/gen/codbex_methods/roles/default-roles.roles index 795598b..027aada 100644 --- a/codbex-methods/gen/codbex-methods/roles/default-roles.roles +++ b/codbex-methods/gen/codbex_methods/roles/default-roles.roles @@ -15,4 +15,4 @@ "name": "codbex-methods.SentMethod.SentMethodFullAccess", "description": "A role that grants full access for SentMethod." } -] \ No newline at end of file +]