diff --git a/.blueprint/generate-sample/command.mjs b/.blueprint/generate-sample/command.mjs index c5e9b9e58..e6416f999 100644 --- a/.blueprint/generate-sample/command.mjs +++ b/.blueprint/generate-sample/command.mjs @@ -16,27 +16,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { existsSync, readdirSync } from 'node:fs'; +import { readdirSync } from 'node:fs'; import { entitiesByType, workflowSamples } from '../generate-sample/support/index.mjs'; -import { getSamples } from './get-samples.mjs'; /** * @type {import('generator-jhipster').JHipsterCommandDefinition} */ const command = { - arguments: { - sampleName: { - type: String, - }, - }, configs: { sampleName: { + argument: { + type: String, + }, prompt: gen => ({ - when: !gen.jdlSamples && !gen.appSample && !gen.all && existsSync(gen.templatePath(gen.samplesFolder)), + when: !gen.jdlSamples && !gen.appSample && !gen.all, type: 'list', message: 'which sample do you want to generate?', - choices: async () => getSamples(gen.templatePath(gen.samplesFolder)), }), + choices: Object.keys(workflowSamples), configure: gen => { const sample = workflowSamples[gen.sampleName]; if (!sample) { diff --git a/.blueprint/generate-sample/get-samples.mjs b/.blueprint/generate-sample/get-samples.mjs deleted file mode 100644 index 3dd6aae9b..000000000 --- a/.blueprint/generate-sample/get-samples.mjs +++ /dev/null @@ -1,11 +0,0 @@ -import { readdir, stat } from 'node:fs/promises'; -import { extname } from 'path'; - -export const getSamples = async samplesFolder => { - const filenames = await readdir(samplesFolder); - const entries = await Promise.all(filenames.map(async filename => [filename, await stat(`${samplesFolder}/${filename}`)])); - return entries - .filter(([filename, statResult]) => extname(filename) === '.jdl' || statResult.isDirectory()) - .map(([filename]) => filename) - .filter(filename => !filename.includes('disabled')); -}; diff --git a/.github/workflows/angular.yml b/.github/workflows/angular.yml index 60ff51a7c..f535b7d8a 100644 --- a/.github/workflows/angular.yml +++ b/.github/workflows/angular.yml @@ -91,12 +91,7 @@ jobs: !contains(github.event.pull_request.labels.*.name, 'pr: disable-compare') with: generator-path: jhipster-kotlin - cmd: cli.cjs generate-sample --skip-jhipster-dependencies --skip-install --skip-ktlint-format ${{ matrix.extra-args }} - env: - JHI_APP: ${{ matrix.app-sample || 'jdl' }} - JHI_ENTITY: ${{ matrix.entity || 'none' }} - JHI_JDL_ENTITY: ${{ matrix.jdl-entity || '' }} - JHI_JDL_APP: ${{ matrix.jdl-samples || '' }} + cmd: cli.cjs generate-sample ${{ matrix.sample }} --skip-jhipster-dependencies --skip-install --skip-ktlint-format ${{ matrix.extra-args }} #---------------------------------------------------------------------- # Launch tests #---------------------------------------------------------------------- diff --git a/.github/workflows/react.yml b/.github/workflows/react.yml index 3276df403..92a707df5 100644 --- a/.github/workflows/react.yml +++ b/.github/workflows/react.yml @@ -91,12 +91,7 @@ jobs: !contains(github.event.pull_request.labels.*.name, 'pr: disable-compare') with: generator-path: jhipster-kotlin - cmd: cli.cjs generate-sample --skip-jhipster-dependencies --skip-install --skip-ktlint-format ${{ matrix.extra-args }} - env: - JHI_APP: ${{ matrix.app-sample || 'jdl' }} - JHI_ENTITY: ${{ matrix.entity || 'none' }} - JHI_JDL_ENTITY: ${{ matrix.jdl-entity || '' }} - JHI_JDL_APP: ${{ matrix.jdl-samples || '' }} + cmd: cli.cjs generate-sample ${{ matrix.sample }} --skip-jhipster-dependencies --skip-install --skip-ktlint-format ${{ matrix.extra-args }} #---------------------------------------------------------------------- # Launch tests #---------------------------------------------------------------------- diff --git a/generators/kotlin/generator.js b/generators/kotlin/generator.js index b3e748fdc..5c351108e 100644 --- a/generators/kotlin/generator.js +++ b/generators/kotlin/generator.js @@ -1,5 +1,5 @@ import BaseApplicationGenerator from 'generator-jhipster/generators/base-application'; -import { passthrough, transform } from '@yeoman/transform'; +import { passthrough } from '@yeoman/transform'; import { getPrimaryKeyValue } from 'generator-jhipster/generators/server/support'; import { SERVER_MAIN_SRC_KOTLIN_DIR, SERVER_TEST_SRC_KOTLIN_DIR } from './support/index.js'; @@ -28,18 +28,6 @@ export default class extends BaseApplicationGenerator { get [BaseApplicationGenerator.DEFAULT]() { return this.asDefaultTaskGroup({ - async checkForJavaFiles() { - this.queueTransformStream( - { - name: 'removing remaining java files', - filter: file => file.path.endsWith('.java'), - refresh: true, - }, - transform(file => { - this.log.warn(`Remaining java file ${file.path} removed`); - }), - ); - }, async convertGradleScripts({ application }) { if (application.buildToolGradle) { this.queueTransformStream( diff --git a/generators/kotlin/support/files.js b/generators/kotlin/support/files.js index f907ba247..555110f18 100644 --- a/generators/kotlin/support/files.js +++ b/generators/kotlin/support/files.js @@ -1,2 +1,6 @@ -export const convertToKotlinFile = file => - file.replace('.java', '.kt').replace('src/main/java/', 'src/main/kotlin/').replace('src/test/java/', 'src/test/kotlin/'); +export const convertToKotlinFile = (file, replaceExtension = true) => { + if (replaceExtension) { + file = file.replace('.java', '.kt'); + } + return file.replace('src/main/java/', 'src/main/kotlin/').replace('src/test/java/', 'src/test/kotlin/'); +}; diff --git a/generators/spring-boot-v2/generator.js b/generators/spring-boot-v2/generator.js index ab12a72e1..194fb09c4 100644 --- a/generators/spring-boot-v2/generator.js +++ b/generators/spring-boot-v2/generator.js @@ -110,6 +110,9 @@ export default class extends BaseApplicationGenerator { if (application.user && destinationFile.endsWith('UserCallback.java')) { return undefined; } + if (application.generateBuiltInAuthorityEntity && destinationFile.endsWith('AuthorityRepository.java')) { + return undefined; + } if ( sourceFile.endsWith('/TestContainersSpringContextCustomizerFactory.java') && diff --git a/generators/spring-boot-v2/templates/src/main/kotlin/_package_/repository/AuthorityRepository.kt.ejs b/generators/spring-boot-v2/templates/src/main/kotlin/_package_/repository/AuthorityRepository.kt.ejs deleted file mode 100644 index 78bcf8732..000000000 --- a/generators/spring-boot-v2/templates/src/main/kotlin/_package_/repository/AuthorityRepository.kt.ejs +++ /dev/null @@ -1,71 +0,0 @@ -<%# - Copyright 2013-2025 the original author or authors from the JHipster project. - - This file is part of the JHipster project, see https://www.jhipster.tech/ - for more information. - - Licensed under the Apache License, Version 2.0 (the "License") - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --%> -package <%= packageName %>.repository - -import <%= packageName %>.domain.Authority -<%_ if (databaseTypeCouchbase) { _%> -import org.springframework.stereotype.Repository -<%_ } _%> -<%_ if (databaseTypeSql) { _%> - <%_ if (reactive) { _%> -import org.springframework.data.r2dbc.repository.R2dbcRepository - <%_ } else { _%> -import org.springframework.data.jpa.repository.JpaRepository - <%_ } _%> -<%_ } _%> -<%_ if (databaseTypeMongodb) { _%> -import org.springframework.data.mongodb.repository.<% if (reactive) { %>Reactive<% } %>MongoRepository -<%_ } _%> -<%_ if (databaseTypeNeo4j) { _%> -import org.springframework.data.neo4j.repository.<% if (reactive) { %>Reactive<% } %>Neo4jRepository -<%_ } _%> -<%_ if (databaseTypeNeo4j) { _%> -<%_ if (reactive) { _%> -import reactor.core.publisher.Flux -<%_ } _%> -<%_ } _%> -<% if (databaseTypeSql) { %> -/** - * Spring Data <% if (reactive) { %>R2DBC<% } else { %>JPA<% } %> repository for the [Authority] entity. - */ -<% } %><% if (databaseTypeMongodb) { %> -/** - * Spring Data MongoDB repository for the [Authority] entity. - */ -<% } %><%_ if (databaseTypeNeo4j) { _%> -/** -* Spring Data Neo4j repository for the {@link Authority} entity. -*/ -<%_ } _%><% if (databaseTypeCouchbase) { %> -/** - * Spring Data Couchbase repository for the [Authority] entity. - */ -<% } %> -<% if (databaseTypeCouchbase) { %> -@Repository -<%_ } _%> -<%_ - let listOrFlux = reactive ? 'Flux' : 'List'; -_%> -interface AuthorityRepository : <% if (databaseTypeSql) { %><% if (reactive) { %>R2dbc<% } else { %>Jpa<% } %>Repository<% } else { %><% if (reactive && !databaseTypeCouchbase) { %>Reactive<% } %><% if (databaseTypeMongodb) { %>MongoRepository<% } %><% if (databaseTypeNeo4j) { %>Neo4jRepository<% } %><% if (databaseTypeCouchbase) { %>JHipsterCouchbaseRepository<% } %><% } %> { - <%_ if (databaseTypeNeo4j) { _%> - <% if (!reactive) { %>// See https://github.com/neo4j/sdn-rx/issues/51<%_ } _%> - override fun findAll(): <% if (reactive) { %>Flux<% } else { %>List<% } %> - <%_ } _%> -} diff --git a/generators/spring-boot/generator.js b/generators/spring-boot/generator.js index b29f84823..d63587bad 100644 --- a/generators/spring-boot/generator.js +++ b/generators/spring-boot/generator.js @@ -57,34 +57,48 @@ export default class extends BaseApplicationGenerator { // We don't want to handle spring-boot-v2 templates here if (file.namespace === 'jhipster-kotlin:spring-boot-v2') return file; const { resolvedSourceFile: javaResolvedSourceFile, namespace: ns } = file; - let { sourceFile, destinationFile } = file; + const { sourceFile, destinationFile } = file; // Already resolved kotlin files if (javaResolvedSourceFile && (javaResolvedSourceFile.endsWith('.kt') || javaResolvedSourceFile.includes('.kt.'))) { return file; } - if (sourceFile.includes('.java')) { - // Kotlint User template does not implements Persistable api. Ignore for now. - if (application.user && destinationFile.endsWith('UserCallback.java')) { - return undefined; - } - - sourceFile = convertToKotlinFile(sourceFile); - destinationFile = convertToKotlinFile(destinationFile); + // Kotlint User template does not implements Persistable api. Ignore for now. + if (application.user && destinationFile.endsWith('UserCallback.java')) { + return undefined; } const prefix = ns === 'jhipster:spring-boot' ? '' : ns.split(':').pop(); - sourceFile = join(prefix, sourceFile); - let resolvedSourceFile = this.templatePath(sourceFile); - if (!existsSync(`${resolvedSourceFile}.ejs`)) { - if (resolvedSourceFile.includes('.kt')) { - // Ignore v8 file if it does not exist + const kotlinSourceFile = join(prefix, convertToKotlinFile(sourceFile)); + const resolvedSourceFile = this.templatePath(kotlinSourceFile); + + if (!sourceFile.includes('.java')) { + return existsSync(`${resolvedSourceFile}.ejs`) ? { ...file, resolvedSourceFile } : file; + } + + if (existsSync(`${resolvedSourceFile}.ejs`)) { + return { + ...file, + sourceFile: kotlinSourceFile, + resolvedSourceFile, + javaResolvedSourceFile, + destinationFile: convertToKotlinFile(destinationFile), + }; + } + + if (resolvedSourceFile.includes('.kt')) { + if (resolvedSourceFile.includes('src/test/')) { + // Ignore test files that are not converted to kotlin return undefined; } - resolvedSourceFile = javaResolvedSourceFile; } - return { ...file, sourceFile, javaResolvedSourceFile, resolvedSourceFile, destinationFile }; + return { + ...file, + javaResolvedSourceFile, + resolvedSourceFile: javaResolvedSourceFile, + destinationFile: convertToKotlinFile(destinationFile, false), + }; }, ); }, diff --git a/generators/spring-boot/templates/spring-data-relational/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository_r2dbc.kt.ejs b/generators/spring-boot/templates/spring-data-relational/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository_r2dbc.kt.ejs new file mode 100644 index 000000000..a5d3c5e15 --- /dev/null +++ b/generators/spring-boot/templates/spring-data-relational/src/main/kotlin/_package_/_entityPackage_/repository/_entityClass_Repository_r2dbc.kt.ejs @@ -0,0 +1,34 @@ +<%# + Copyright 2013-2024 the original author or authors from the JHipster project. + + This file is part of the JHipster project, see https://www.jhipster.tech/ + for more information. + + Licensed under the Apache License, Version 2.0 (the "License") + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +-%> +package <%= entityAbsolutePackage %>.repository + +import <%= entityAbsolutePackage %>.domain.<%= persistClass %> + +import org.springframework.data.r2dbc.repository.R2dbcRepository +import org.springframework.stereotype.Repository +<%_ if (primaryKey.typeUUID) { _%> + +import java.util.UUID +<%_ } _%> + +/** + * <%= springDataDescription %> repository for the [<%= persistClass %>] entity. + */ +@Repository +interface <%= entityClass %>Repository : R2dbcRepository<<%= persistClass %>, <%= primaryKey.type %>> diff --git a/generators/spring-boot/templates/src/main/kotlin/_package_/_entityPackage_/service/impl/_entityClass_ServiceImpl.kt.ejs b/generators/spring-boot/templates/src/main/kotlin/_package_/_entityPackage_/service/impl/_entityClass_ServiceImpl.kt.ejs index aa1178617..00d3cbc26 100644 --- a/generators/spring-boot/templates/src/main/kotlin/_package_/_entityPackage_/service/impl/_entityClass_ServiceImpl.kt.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/_package_/_entityPackage_/service/impl/_entityClass_ServiceImpl.kt.ejs @@ -86,7 +86,7 @@ import org.elasticsearch.index.query.QueryBuilders.queryStringQuery @Service<% if (databaseTypeSql) { %> @Transactional<% } %> class <%= serviceClassName %>( - <%- include('../../_partials_entity_/inject_template', {asEntity, asDto, viaService: false, constructorName: serviceClassName, queryService: false, isUsingMapsId: isUsingMapsId, mapsIdAssoc: mapsIdAssoc, isController: false, noReturn: false}); -%> + <%- include('../../_partials_entity_/inject_template', {viaService: false, constructorName: serviceClassName, queryService: false, isUsingMapsId: isUsingMapsId, mapsIdAssoc: mapsIdAssoc, isController: false, noReturn: false}); -%> )<% if (serviceImpl) { %> : <%= entityClass %>Service<% } %> { private val log = LoggerFactory.getLogger(javaClass) @@ -101,7 +101,7 @@ class <%= serviceClassName %>( <%_ } _%> <% if (serviceImpl) { _%>override <% } %>fun save(<%= instanceName %>: <%= instanceType %>): <% if (reactive) { %>Mono<<% } %><%= instanceType %><% if (reactive) { %>><% } %> { log.debug("Request to save <%= entityClass %> : $<%= instanceName %>") -<%- include('/_global_partials_entity_/save_template', {asEntity, asDto, viaService: false, returnDirectly: true, isUsingMapsId: isUsingMapsId, mapsIdAssoc: mapsIdAssoc, isController: false, isPersisted: false, noReturn: false}); -%> +<%- include('/_global_partials_entity_/save_template', {viaService: false, returnDirectly: true, isUsingMapsId: isUsingMapsId, mapsIdAssoc: mapsIdAssoc, isController: false, isPersisted: false, noReturn: false}); -%> } <%_ if (!serviceImpl) { _%> @@ -127,7 +127,7 @@ class <%= serviceClassName %>( <%_ } _%> <% if (serviceImpl) { %>override <% } %>fun partialUpdate(<%= instanceName %>: <%= instanceType %>): <% if (reactive) { %>Mono<<% } else { %>Optional<<% } %><%= instanceType %>> { log.debug("Request to partially update <%= entityClass %> : {}", <%= instanceName %>) -<%- include('../../_partials_entity_/patch_template', {asEntity, asDto, isService: true, viaService: false}); -%> +<%- include('../../_partials_entity_/patch_template', {isService: true, viaService: false}); -%> } <%_ if (!serviceImpl) { _%> @@ -165,7 +165,7 @@ class <%= serviceClassName %>( <%= entityInstance %>Repository.findAllWithEagerRelationships(pageable)<% if (!dtoMapstruct) { %><% } else { %>.map(<%= entityToDtoReference %>)<% } %> <%_ } _%> -<%- include('../../_partials_entity_/get_filtered_template', {asEntity, asDto}); -%> +<%- include('../../_partials_entity_/get_filtered_template'); -%> <%_ if (reactive) { _%> <%_ if (!serviceImpl) { _%> /** @@ -198,7 +198,7 @@ class <%= serviceClassName %>( @Transactional(readOnly = true) <%_ } _%> <% if (serviceImpl) { %>override <% } %>fun findOne(id: <%= primaryKey.type %>): <%= optionalOrMono %><<%= instanceType %>> { - log.debug("Request to get <%= entityClass %> : $id")<%- include('../../_partials_entity_/get_template', {asEntity, asDto, viaService: false, returnDirectly:true, implementsEagerLoadApis}); -%> + log.debug("Request to get <%= entityClass %> : $id")<%- include('../../_partials_entity_/get_template', {viaService: false, returnDirectly:true, implementsEagerLoadApis}); -%> } <%_ if (!serviceImpl) { _%> diff --git a/generators/spring-boot/templates/src/main/kotlin/_package_/_entityPackage_/web/rest/_entityClass_Resource.kt.ejs b/generators/spring-boot/templates/src/main/kotlin/_package_/_entityPackage_/web/rest/_entityClass_Resource.kt.ejs index 0bc6e2a10..3d3ad8a12 100644 --- a/generators/spring-boot/templates/src/main/kotlin/_package_/_entityPackage_/web/rest/_entityClass_Resource.kt.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/_package_/_entityPackage_/web/rest/_entityClass_Resource.kt.ejs @@ -185,7 +185,7 @@ _%><%- include('../../_partials_entity_/inject_template', {viaService: viaServic <%= instanceName %>.<%= field.fieldName %> = UUID.randomUUID() <%_ } _%> <%_ } _%> -<%- include('/_global_partials_entity_/save_template', {asEntity, asDto, viaService: viaService, returnDirectly: false, isUsingMapsId: isUsingMapsId, mapsIdAssoc: mapsIdAssoc, isController: true, noReturn: false}); -%> +<%- include('/_global_partials_entity_/save_template', {viaService: viaService, returnDirectly: false, isUsingMapsId: isUsingMapsId, mapsIdAssoc: mapsIdAssoc, isController: true, noReturn: false}); -%> <%_ if (reactive) { _%> .map { result -> try { @@ -325,7 +325,7 @@ _%><%- include('../../_partials_entity_/inject_template', {viaService: viaServic <%_ } _%> <% } %> <%_ } _%> -<%- include('../../_partials_entity_/patch_template', {asEntity, asDto, isService: false, viaService: viaService}); -%> +<%- include('../../_partials_entity_/patch_template', {isService: false, viaService: viaService}); -%> <%_ if (reactive) { _%> result .switchIfEmpty(Mono.error(ResponseStatusException(HttpStatus.NOT_FOUND))) @@ -360,7 +360,7 @@ _%><%- include('../../_partials_entity_/inject_template', {viaService: viaServic */ @GetMapping("/<%= entityApiUrl %>")<%_ if (databaseTypeSql && isUsingMapsId&& !viaService) { %> @Transactional(readOnly = true)<%_ } _%> - <%- include('../../_partials_entity_/get_all_template', {asEntity, asDto, viaService}); -%> + <%- include('../../_partials_entity_/get_all_template', {viaService}); -%> <%_ if (reactive && paginationNo) { _%> /** @@ -392,7 +392,7 @@ _%><%- include('../../_partials_entity_/inject_template', {viaService: viaServic @Transactional(readOnly = true) <%_ } _%> fun get<%= entityClass %>(@PathVariable id: <%= primaryKey.type %>): <% if (reactive) { %>Mono<<% } %>ResponseEntity<<%= instanceType %>><% if (reactive) { %>><% } %> { - log.debug("REST request to get <%= entityClass %> : $id")<%- include('../../_partials_entity_/get_template', {asEntity, asDto, viaService, returnDirectly:false, implementsEagerLoadApis}); -%> + log.debug("REST request to get <%= entityClass %> : $id")<%- include('../../_partials_entity_/get_template', {viaService, returnDirectly:false, implementsEagerLoadApis}); -%> return ResponseUtil.wrapOrNotFound(<%= instanceName %>) } <%_ if (!readOnly) { _%> @@ -437,6 +437,6 @@ _%><%- include('../../_partials_entity_/inject_template', {viaService: viaServic <%_ } _%> * @return the result of the search. */ - @GetMapping("/_search/<%= entityApiUrl %>")<%- include('../../_partials_entity_/search_template', {asEntity, asDto, viaService}); -%> + @GetMapping("/_search/<%= entityApiUrl %>")<%- include('../../_partials_entity_/search_template', {viaService}); -%> <%_ } _%> } diff --git a/generators/spring-boot/templates/src/test/kotlin/_package_/_entityPackage_/web/rest/_entityClass_ResourceIT.kt.ejs b/generators/spring-boot/templates/src/test/kotlin/_package_/_entityPackage_/web/rest/_entityClass_ResourceIT.kt.ejs index a7b8c891c..337e81c44 100644 --- a/generators/spring-boot/templates/src/test/kotlin/_package_/_entityPackage_/web/rest/_entityClass_ResourceIT.kt.ejs +++ b/generators/spring-boot/templates/src/test/kotlin/_package_/_entityPackage_/web/rest/_entityClass_ResourceIT.kt.ejs @@ -69,13 +69,14 @@ import <%= entityAbsolutePackage %>.domain.<%= persistClass %> <%_ var imported = []; for (relationship of relationships) { // import entities in required relationships + const { otherEntity } = relationship; const relationshipValidate = relationship.relationshipValidate; const otherEntityNameCapitalized = relationship.otherEntityNameCapitalized; const isUsingMapsIdL1 = relationship.id; - if(imported.indexOf(otherEntityNameCapitalized) === -1 && persistClass !== asEntity(otherEntityNameCapitalized)) { + if(imported.indexOf(otherEntityNameCapitalized) === -1 && persistClass !== otherEntity.persistClass) { if ((relationshipValidate !== null && relationshipValidate) || jpaMetamodelFiltering || (isUsingMapsIdL1)) { _%> -import <%= entityAbsolutePackage %>.domain.<%= asEntity(otherEntityNameCapitalized) %> +import <%= entityAbsolutePackage %>.domain.<%= otherEntity.persistClass %> <%_ imported.push(otherEntityNameCapitalized); } } } _%> <%_ if (saveUserSnapshot) { _%> @@ -194,10 +195,17 @@ import java.time.temporal.ChronoUnit <%_ if (anyFieldIsUUID || primaryKey.typeString || otherEntityPrimaryKeyTypesIncludesUUID) { _%> import java.util.UUID <%_ } _%> -<%_ if (!embedded && primaryKey.hasLong) { _%> +<%_ if (!embedded) { _%> + <%_ if (primaryKey.hasLong && !readOnly && updatableEntity || primaryKey.hasInteger) { _%> import java.util.Random + <%_ } _%> + <%_ if (primaryKey.hasLong && !readOnly && updatableEntity) { _%> import java.util.concurrent.atomic.AtomicLong + <%_ } else if (primaryKey.hasInteger) { _%> +import java.util.concurrent.atomic.AtomicInteger + <%_ } _%> <%_ } _%> + import java.util.stream.Stream import org.assertj.core.api.Assertions.assertThat @@ -924,12 +932,12 @@ class <%= entityClass %>ResourceIT { val <%= relationship.relationshipFieldName %> = <%= persistInstance %>.<%= relationship.relationshipName %> <%_ } else { _%> <%_ if (databaseTypeSql && !reactive) { _%> - var <%= relationship.relationshipFieldName %>: <%= asEntity(relationship.otherEntityNameCapitalized) %> - if (findAll(em, <%= asEntity(relationship.otherEntityNameCapitalized) %>::class).isEmpty()) { + var <%= relationship.relationshipFieldName %>: <%= relationship.otherEntity.persistClass %> + if (findAll(em, <%= relationship.otherEntity.persistClass %>::class).isEmpty()) { <%= entityInstance %>Repository.saveAndFlush(<%= persistInstance %>) <%= relationship.relationshipFieldName %> = <%= createEntityPrefix %><%= relationship.otherEntityNameCapitalized %>ResourceIT.createEntity(em) } else { - <%= relationship.relationshipFieldName %> = findAll(em, <%= asEntity(relationship.otherEntityNameCapitalized) %>::class)[0] + <%= relationship.relationshipFieldName %> = findAll(em, <%= relationship.otherEntity.persistClass %>::class)[0] } <%_ } else { _%> var <%= relationship.relationshipFieldName %> = <%= relationship.otherEntityNameCapitalized %>ResourceIT.createEntity(em) @@ -1128,14 +1136,14 @@ class <%= entityClass %>ResourceIT { <%_ } _%> <%_ if (reactive) { _%> - webTestClient.put().uri(ENTITY_API_URL_ID, <%= (dtoMapstruct ? asDto(entityInstance) : 'updated' + persistClass) %>.<%= primaryKey.name %>) + webTestClient.put().uri(ENTITY_API_URL_ID, <%= (dtoMapstruct ? dtoInstance : 'updated' + persistClass) %>.<%= primaryKey.name %>) .contentType(MediaType.APPLICATION_JSON) .bodyValue(convertObjectToJsonBytes(<%= (dtoMapstruct ? dtoInstance : 'updated' + persistClass) %>)) .exchange() .expectStatus().isOk <%_ } else { _%> rest<%= entityClass %>MockMvc.perform( - put(ENTITY_API_URL_ID, <%= (dtoMapstruct ? asDto(entityInstance) : 'updated' + persistClass) %>.<%= primaryKey.name %>)<% if (authenticationUsesCsrf) { %>.with(csrf())<% }%> + put(ENTITY_API_URL_ID, <%= (dtoMapstruct ? dtoInstance : 'updated' + persistClass) %>.<%= primaryKey.name %>)<% if (authenticationUsesCsrf) { %>.with(csrf())<% }%> .contentType(MediaType.APPLICATION_JSON) .content(convertObjectToJsonBytes(<% if (dtoMapstruct) { %><%= dtoInstance %><% } else { %>updated<%= persistClass %><% } %>)) ).andExpect(status().isOk) @@ -1188,7 +1196,7 @@ class <%= entityClass %>ResourceIT { <%_ if (searchEngineElasticsearch) { _%> val searchDatabaseSizeBefore = IterableUtil.sizeOf(<%= entityInstance %>SearchRepository.findAll()<%= callListBlock %>) <%_ } _%> - <%= persistInstance %>.<%= primaryKey.name %> = <%= getJavaValueGeneratorForType(primaryKey.type) %> + <%= persistInstance %>.<%= primaryKey.name %> = <%= primaryKey.javaValueGenerator %> <%_ if (dtoMapstruct) { _%> // Create the <%= entityClass %> @@ -1228,7 +1236,7 @@ class <%= entityClass %>ResourceIT { <%_ if (searchEngineElasticsearch) { _%> val searchDatabaseSizeBefore = IterableUtil.sizeOf(<%= entityInstance %>SearchRepository.findAll()<%= callListBlock %>) <%_ } _%> - <%= persistInstance %>.<%= primaryKey.name %> = <%= getJavaValueGeneratorForType(primaryKey.type) %> + <%= persistInstance %>.<%= primaryKey.name %> = <%= primaryKey.javaValueGenerator %> <%_ if (dtoMapstruct) { _%> // Create the <%= entityClass %> @@ -1238,12 +1246,12 @@ class <%= entityClass %>ResourceIT { // If url ID doesn't match entity ID, it will throw BadRequestAlertException <%_ if (!reactive) { _%> rest<%= entityClass %>MockMvc.perform( - put(ENTITY_API_URL_ID, <%= getJavaValueGeneratorForType(primaryKey.type) %>)<% if (authenticationUsesCsrf) { %>.with(csrf())<% }%> + put(ENTITY_API_URL_ID, <%= primaryKey.javaValueGenerator %>)<% if (authenticationUsesCsrf) { %>.with(csrf())<% }%> .contentType(MediaType.APPLICATION_JSON) .content(convertObjectToJsonBytes(<%= restInstance %>)) ).andExpect(status().isBadRequest) <%_ } else { _%> - webTestClient.put().uri(ENTITY_API_URL_ID, <%= getJavaValueGeneratorForType(primaryKey.type) %>) + webTestClient.put().uri(ENTITY_API_URL_ID, <%= primaryKey.javaValueGenerator %>) .contentType(MediaType.APPLICATION_JSON) .bodyValue(convertObjectToJsonBytes(<%= restInstance %>)) .exchange() @@ -1269,7 +1277,7 @@ class <%= entityClass %>ResourceIT { <%_ if (searchEngineElasticsearch) { _%> val searchDatabaseSizeBefore = IterableUtil.sizeOf(<%= entityInstance %>SearchRepository.findAll()<%= callListBlock %>); <%_ } _%> - <%= persistInstance %>.<%= primaryKey.name %> = <%= getJavaValueGeneratorForType(primaryKey.type) %> + <%= persistInstance %>.<%= primaryKey.name %> = <%= primaryKey.javaValueGenerator %> <%_ if (dtoMapstruct) { _%> // Create the <%= entityClass %> @@ -1321,7 +1329,7 @@ class <%= entityClass %>ResourceIT { <%_ } _%> <%= entityInstance %>Repository.<%= saveMethod %>(<%= persistInstance %>)<%= callBlock %> <% const fieldsToIncludeInPartialPatchTest = fieldsToTest.map(field => prepareFieldForPatchTest(field, () => faker.datatype.boolean())); %> - <%- include('/_global_partials_entity_/it_patch_update.partial.kt.ejs', {fields: fieldsToIncludeInPartialPatchTest, saveMethod, asEntity, callBlock, callListBlock, authenticationUsesCsrf}); -%> + <%- include('/_global_partials_entity_/it_patch_update.partial.kt.ejs', {fields: fieldsToIncludeInPartialPatchTest, saveMethod, callBlock, callListBlock, authenticationUsesCsrf}); -%> } @Test<%= transactionalAnnotation %> @@ -1334,7 +1342,7 @@ class <%= entityClass %>ResourceIT { <%_ } _%> <%= entityInstance %>Repository.<%= saveMethod %>(<%= persistInstance %>)<%= callBlock %> <% const fieldsToIncludeInFullPatchTest = fieldsToTest.map(field => prepareFieldForPatchTest(field, () => true)); %> - <%- include('/_global_partials_entity_/it_patch_update.partial.kt.ejs', {fields: fieldsToIncludeInFullPatchTest, saveMethod, asEntity, callBlock, callListBlock, authenticationUsesCsrf}); -%> + <%- include('/_global_partials_entity_/it_patch_update.partial.kt.ejs', {fields: fieldsToIncludeInFullPatchTest, saveMethod, callBlock, callListBlock, authenticationUsesCsrf}); -%> } @Test<%= transactionalAnnotation %> @@ -1344,24 +1352,24 @@ class <%= entityClass %>ResourceIT { <%_ if (searchEngineElasticsearch) { _%> val searchDatabaseSizeBefore = IterableUtil.sizeOf(<%= entityInstance %>SearchRepository.findAll()<%= callListBlock %>) <%_ } _%> - <%= asEntity(entityInstance) %>.<%= primaryKey.name %> = <%= getJavaValueGeneratorForType(primaryKey.type) %> + <%= persistInstance %>.<%= primaryKey.name %> = <%= primaryKey.javaValueGenerator %> <%_ if (dtoMapstruct) { _%> // Create the <%= entityClass %> - val <%= asDto(entityInstance) %> = <%= entityInstance %>Mapper.toDto(<%= asEntity(entityInstance) %>) + val <%= restInstance %> = <%= entityInstance %>Mapper.toDto(<%= persistInstance %>) <%_ } _%> // If the entity doesn't have an ID, it will throw BadRequestAlertException <%_ if (reactive) { _%> - webTestClient.patch().uri(ENTITY_API_URL_ID, <%= (dtoMapstruct ? asDto(entityInstance) : asEntity(entityInstance)) %>.<%= primaryKey.name %>) + webTestClient.patch().uri(ENTITY_API_URL_ID, <%= restInstance %>.<%= primaryKey.name %>) .contentType(MediaType.valueOf("application/merge-patch+json")) - .bodyValue(convertObjectToJsonBytes(<%= (dtoMapstruct ? asDto(entityInstance) : asEntity(entityInstance)) %>)) + .bodyValue(convertObjectToJsonBytes(<%= restInstance %>)) .exchange() .expectStatus().isBadRequest <%_ } else { _%> - rest<%= entityClass %>MockMvc.perform(patch(ENTITY_API_URL_ID, <%= (dtoMapstruct ? asDto(entityInstance) : asEntity(entityInstance)) %>.<%= primaryKey.name %>)<% if (authenticationUsesCsrf) { %>.with(csrf())<% }%> + rest<%= entityClass %>MockMvc.perform(patch(ENTITY_API_URL_ID, <%= restInstance %>.<%= primaryKey.name %>)<% if (authenticationUsesCsrf) { %>.with(csrf())<% }%> .contentType("application/merge-patch+json") - .content(convertObjectToJsonBytes(<%= (dtoMapstruct ? asDto(entityInstance) : asEntity(entityInstance)) %>))) + .content(convertObjectToJsonBytes(<%= restInstance %>))) .andExpect(status().isBadRequest) <%_ } _%> @@ -1384,24 +1392,24 @@ class <%= entityClass %>ResourceIT { <%_ if (searchEngineElasticsearch) { _%> val searchDatabaseSizeBefore = IterableUtil.sizeOf(<%= entityInstance %>SearchRepository.findAll()<%= callListBlock %>) <%_ } _%> - <%= asEntity(entityInstance) %>.<%= primaryKey.name %> = <%= getJavaValueGeneratorForType(primaryKey.type) %> + <%= persistInstance %>.<%= primaryKey.name %> = <%= primaryKey.javaValueGenerator %> <%_ if (dtoMapstruct) { _%> // Create the <%= entityClass %> - val <%= asDto(entityInstance) %> = <%= entityInstance %>Mapper.toDto(<%= asEntity(entityInstance) %>) + val <%= restInstance %> = <%= entityInstance %>Mapper.toDto(<%= persistInstance %>) <%_ } _%> // If url ID doesn't match entity ID, it will throw BadRequestAlertException <%_ if (reactive) { _%> - webTestClient.patch().uri(ENTITY_API_URL_ID, <%= getJavaValueGeneratorForType(primaryKey.type) %>) + webTestClient.patch().uri(ENTITY_API_URL_ID, <%= primaryKey.javaValueGenerator %>) .contentType(MediaType.valueOf("application/merge-patch+json")) - .bodyValue(convertObjectToJsonBytes(<%= (dtoMapstruct ? asDto(entityInstance) : asEntity(entityInstance)) %>)) + .bodyValue(convertObjectToJsonBytes(<%= restInstance %>)) .exchange() .expectStatus().isBadRequest <%_ } else { _%> - rest<%= entityClass %>MockMvc.perform(patch(ENTITY_API_URL_ID, <%= getJavaValueGeneratorForType(primaryKey.type) %>)<% if (authenticationUsesCsrf) { %>.with(csrf())<% } %> + rest<%= entityClass %>MockMvc.perform(patch(ENTITY_API_URL_ID, <%= primaryKey.javaValueGenerator %>)<% if (authenticationUsesCsrf) { %>.with(csrf())<% } %> .contentType("application/merge-patch+json") - .content(convertObjectToJsonBytes(<%= (dtoMapstruct ? asDto(entityInstance) : asEntity(entityInstance)) %>))) + .content(convertObjectToJsonBytes(<%= restInstance %>))) .andExpect(status().isBadRequest) <%_ } _%> @@ -1424,24 +1432,24 @@ class <%= entityClass %>ResourceIT { <%_ if (searchEngineElasticsearch) { _%> val searchDatabaseSizeBefore = IterableUtil.sizeOf(<%= entityInstance %>SearchRepository.findAll()<%= callListBlock %>); <%_ } _%> - <%= asEntity(entityInstance) %>.<%= primaryKey.name %> = <%= getJavaValueGeneratorForType(primaryKey.type) %> + <%= persistInstance %>.<%= primaryKey.name %> = <%= primaryKey.javaValueGenerator %> <%_ if (dtoMapstruct) { _%> // Create the <%= entityClass %> - val <%= asDto(entityInstance) %> = <%= entityInstance %>Mapper.toDto(<%= asEntity(entityInstance) %>) + val <%= restInstance %> = <%= entityInstance %>Mapper.toDto(<%= persistInstance %>) <%_ } _%> // If url ID doesn't match entity ID, it will throw BadRequestAlertException <%_ if (reactive) { _%> webTestClient.patch().uri(ENTITY_API_URL) .contentType(MediaType.valueOf("application/merge-patch+json")) - .bodyValue(convertObjectToJsonBytes(<%= (dtoMapstruct ? asDto(entityInstance) : asEntity(entityInstance)) %>)) + .bodyValue(convertObjectToJsonBytes(<%= restInstance %>)) .exchange() .expectStatus().isEqualTo(405) <%_ } else { _%> rest<%= entityClass %>MockMvc.perform(patch(ENTITY_API_URL)<% if (authenticationUsesCsrf) { %>.with(csrf())<% } %> .contentType("application/merge-patch+json") - .content(convertObjectToJsonBytes(<%= (dtoMapstruct ? asDto(entityInstance) : asEntity(entityInstance)) %>))) + .content(convertObjectToJsonBytes(<%= restInstance %>))) .andExpect(status().isMethodNotAllowed) <%_ } _%> @@ -1735,14 +1743,18 @@ class <%= entityClass %>ResourceIT { <%_ if (searchEngine !== false) { _%> private val ENTITY_SEARCH_API_URL: String = "/api/_search/<%= entityApiUrl %>" <%_ } _%> - <%_ if (!embedded && primaryKey.hasLong) { _%> + <%_ if (!embedded) { _%> + <%_ if (primaryKey.hasLong && !readOnly && updatableEntity || primaryKey.hasInteger) { _%> private val random: Random = Random() - private val count: AtomicLong = AtomicLong(random.nextInt().toLong() + ( 2 * Integer.MAX_VALUE )) + <%_ } _%> + <%_ if (primaryKey.hasLong && !readOnly && updatableEntity) { _%> + private val longCount: AtomicLong = AtomicLong(random.nextInt().toLong() + ( 2 * Integer.MAX_VALUE )) + <%_ } else if (primaryKey.hasInteger) { _%> + private val intCount: AtomicInteger = AtomicInteger(random.nextInt() + ( 2 * Integer.MAX_VALUE )) + <%_ } _%> <%_ } _%> - - <%_ ['DEFAULT_', 'UPDATED_'].forEach((fieldStatus) => { _%> /** @@ -1780,6 +1792,7 @@ class <%= entityClass %>ResourceIT { <%_ const alreadyGeneratedEntities = [] for (relationship of relationships) { + const { otherEntity } = relationship; const relationshipValidate = relationship.relationshipValidate; const otherEntityName = relationship.otherEntityName; const otherEntityNameCapitalized = relationship.otherEntityNameCapitalized; @@ -1800,17 +1813,17 @@ class <%= entityClass %>ResourceIT { <%= otherEntityName %>.<%= primaryKey.name %> = "fixed-id-for-tests" <%_ } _%> <%_ } else { _%> - val <%= otherEntityName %>: <%= asEntity(otherEntityNameCapitalized) %> + val <%= otherEntityName %>: <%= otherEntity.persistClass %> <%_ if (databaseTypeSql && !reactive) { _%> <%_ if (!isUsingMapsId || fieldStatus !== "UPDATED_") { _%> - if (findAll(em, <%= asEntity(otherEntityNameCapitalized) %>::class).isEmpty()) { + if (findAll(em, <%= otherEntity.persistClass %>::class).isEmpty()) { <%_ } _%> <%= otherEntityName %> = <%= createEntityPrefix %><%= otherEntityNameCapitalized %>ResourceIT.create<% if (fieldStatus === 'UPDATED_') { %>Updated<% } %>Entity(<% if (databaseTypeSql) { %>em<% } %>)<%= createEntityPostfix %> em.persist(<%= otherEntityName %>) em.flush() <%_ if (!isUsingMapsId || fieldStatus !== "UPDATED_") { _%> } else { - <%= otherEntityName %> = findAll(em, <%= asEntity(otherEntityNameCapitalized) %>::class)[0] + <%= otherEntityName %> = findAll(em, <%= otherEntity.persistClass %>::class)[0] } <%_ } _%> <%_ } else { _%> diff --git a/test/__snapshots__/app.spec.js.snap b/test/__snapshots__/app.spec.js.snap index 66a5c03ab..ac50765f1 100644 --- a/test/__snapshots__/app.spec.js.snap +++ b/test/__snapshots__/app.spec.js.snap @@ -2469,9 +2469,6 @@ exports[`JHipster generator for App generator > Application with other options > "src/main/kotlin/com/test/reactui/domain/User.kt": { "stateCleared": "modified", }, - "src/main/kotlin/com/test/reactui/repository/AuthorityRepository.kt": { - "stateCleared": "modified", - }, "src/main/kotlin/com/test/reactui/security/AuthoritiesConstants.kt": { "stateCleared": "modified", },