From c74d5df2f84aaaa3012c64a1db4ae6cfb826dfdd Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 18 Sep 2024 12:42:24 -0300 Subject: [PATCH] adjusts --- generators/bootstrap-application-base/generator.ts | 11 +++++++++++ lib/application/field-types.ts | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/generators/bootstrap-application-base/generator.ts b/generators/bootstrap-application-base/generator.ts index 376490ce2608..79c6325c0353 100644 --- a/generators/bootstrap-application-base/generator.ts +++ b/generators/bootstrap-application-base/generator.ts @@ -43,6 +43,7 @@ import { lookupCommandsConfigs } from '../../lib/command/lookup-commands-configs import { loadCommandConfigsIntoApplication, loadCommandConfigsKeysIntoTemplatesContext } from '../../lib/command/load.js'; import { getConfigWithDefaults } from '../../lib/jhipster/default-application-options.js'; import { removeFieldsWithNullishValues } from '../base/support/index.js'; +import { getBlobContentType, isFieldBinaryType, isFieldBlobType } from '../../lib/application/field-types.js'; import { createAuthorityEntity, createUserEntity, createUserManagementEntity } from './utils.js'; import { exportJDLTransform, importJDLTransform } from './support/index.js'; @@ -360,6 +361,16 @@ export default class BootstrapApplicationBase extends BaseApplicationGenerator { this.validateResult(loadEntitiesOtherSide(entities, { application })); for (const entity of entities) { + for (const field of entity.fields) { + if (isFieldBinaryType(field)) { + field.fieldTypeBlobContent |= getBlobContentType(field.fieldType); + if (application.databaseTypeCassandra) { + field.fieldType = 'ByteBuffer'; + } else if (isFieldBlobType(field)) { + field.fieldType = 'byte[]' as any; + } + } + } for (const relationship of entity.relationships) { if (relationship.ownerSide === undefined) { // ownerSide backward compatibility diff --git a/lib/application/field-types.ts b/lib/application/field-types.ts index 920b44d88a57..519f120d26ba 100644 --- a/lib/application/field-types.ts +++ b/lib/application/field-types.ts @@ -37,6 +37,8 @@ export type FieldType = (typeof fieldTypes)[keyof typeof fieldTypes]; type FieldBlobType = (typeof blobFieldTypes)[keyof typeof blobFieldTypes]; +type FieldBinaryType = (typeof blobFieldTypes)[keyof typeof blobFieldTypes] | 'byte[]'; + export const isBlobType = (fieldType: string): fieldType is FieldBlobType => blobFieldTypesValues.includes(fieldType); export const getBlobContentType = (fieldType: FieldBlobType) => { @@ -52,6 +54,9 @@ export const getBlobContentType = (fieldType: FieldBlobType) => { export const isFieldBlobType = (field: Field): field is SetFieldType => isBlobType(field.fieldType); +export const isFieldBinaryType = (field: Field): field is SetFieldType => + isBlobType(field.fieldType) || field.fieldType === 'byte[]'; + export const isFieldEnumType = (field: Field): field is SetRequired => Boolean(field.fieldValues); -export const isFieldNotEnumType = (field: Field): field is SetFieldType => Boolean(field.fieldValues); +export const isFieldNotEnumType = (field: Field): field is SetFieldType => !field.fieldValues;