diff --git a/generators/kotlin/support/files.js b/generators/kotlin/support/files.js new file mode 100644 index 000000000..f907ba247 --- /dev/null +++ b/generators/kotlin/support/files.js @@ -0,0 +1,2 @@ +export const convertToKotlinFile = file => + file.replace('.java', '.kt').replace('src/main/java/', 'src/main/kotlin/').replace('src/test/java/', 'src/test/kotlin/'); diff --git a/generators/kotlin/support/index.js b/generators/kotlin/support/index.js index 4f07201dc..24c782206 100644 --- a/generators/kotlin/support/index.js +++ b/generators/kotlin/support/index.js @@ -1 +1,2 @@ export * from './constants.js'; +export * from './files.js'; diff --git a/generators/spring-boot/__snapshots__/matrix.spec.js.snap b/generators/spring-boot/__snapshots__/matrix.spec.js.snap index a231b070d..7ec5cb7a0 100644 --- a/generators/spring-boot/__snapshots__/matrix.spec.js.snap +++ b/generators/spring-boot/__snapshots__/matrix.spec.js.snap @@ -3150,9 +3150,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > gatew "src/main/resources/config/cql/drop-keyspace.cql": { "stateCleared": "modified", }, - "src/main/resources/config/liquibase/data/user.csv": { - "stateCleared": "modified", - }, "src/main/resources/config/tls/keystore.p12": { "stateCleared": "modified", }, @@ -3689,9 +3686,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > gatew "src/main/resources/config/couchmove/changelog/V20220129002000__entitywithcustomid.n1ql": { "stateCleared": "modified", }, - "src/main/resources/config/liquibase/data/user.csv": { - "stateCleared": "modified", - }, "src/main/resources/config/tls/keystore.p12": { "stateCleared": "modified", }, @@ -4270,9 +4264,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > gatew "src/main/resources/config/bootstrap.yml": { "stateCleared": "modified", }, - "src/main/resources/config/liquibase/data/user.csv": { - "stateCleared": "modified", - }, "src/main/resources/config/tls/keystore.p12": { "stateCleared": "modified", }, @@ -4812,9 +4803,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > gatew "src/main/resources/config/bootstrap.yml": { "stateCleared": "modified", }, - "src/main/resources/config/liquibase/data/user.csv": { - "stateCleared": "modified", - }, "src/main/resources/config/neo4j/migrations/user__admin.json": { "stateCleared": "modified", }, @@ -5363,12 +5351,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > gatew "src/main/resources/config/liquibase/data/authority.csv": { "stateCleared": "modified", }, - "src/main/resources/config/liquibase/data/user.csv": { - "stateCleared": "modified", - }, - "src/main/resources/config/liquibase/data/user_authority.csv": { - "stateCleared": "modified", - }, "src/main/resources/config/liquibase/fake-data/another_simple.csv": { "stateCleared": "modified", }, @@ -21580,9 +21562,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > monol "src/main/resources/config/cql/drop-keyspace.cql": { "stateCleared": "modified", }, - "src/main/resources/config/liquibase/data/user.csv": { - "stateCleared": "modified", - }, "src/main/resources/config/tls/keystore.p12": { "stateCleared": "modified", }, @@ -22140,9 +22119,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > monol "src/main/resources/config/cql/drop-keyspace.cql": { "stateCleared": "modified", }, - "src/main/resources/config/liquibase/data/user.csv": { - "stateCleared": "modified", - }, "src/main/resources/config/tls/keystore.p12": { "stateCleared": "modified", }, @@ -22712,9 +22688,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > monol "src/main/resources/config/couchmove/changelog/V20220129002000__entitywithcustomid.n1ql": { "stateCleared": "modified", }, - "src/main/resources/config/liquibase/data/user.csv": { - "stateCleared": "modified", - }, "src/main/resources/config/tls/keystore.p12": { "stateCleared": "modified", }, @@ -23272,9 +23245,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > monol "src/main/resources/config/couchmove/changelog/V20220129002000__entitywithcustomid.n1ql": { "stateCleared": "modified", }, - "src/main/resources/config/liquibase/data/user.csv": { - "stateCleared": "modified", - }, "src/main/resources/config/tls/keystore.p12": { "stateCleared": "modified", }, @@ -23841,9 +23811,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > monol "src/main/resources/config/bootstrap.yml": { "stateCleared": "modified", }, - "src/main/resources/config/liquibase/data/user.csv": { - "stateCleared": "modified", - }, "src/main/resources/config/tls/keystore.p12": { "stateCleared": "modified", }, @@ -24338,9 +24305,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > monol "src/main/resources/config/application.yml": { "stateCleared": "modified", }, - "src/main/resources/config/liquibase/data/user.csv": { - "stateCleared": "modified", - }, "src/main/resources/config/tls/keystore.p12": { "stateCleared": "modified", }, @@ -24886,9 +24850,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > monol "src/main/resources/config/bootstrap.yml": { "stateCleared": "modified", }, - "src/main/resources/config/liquibase/data/user.csv": { - "stateCleared": "modified", - }, "src/main/resources/config/neo4j/migrations/user__admin.json": { "stateCleared": "modified", }, @@ -25392,9 +25353,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > monol "src/main/resources/config/application.yml": { "stateCleared": "modified", }, - "src/main/resources/config/liquibase/data/user.csv": { - "stateCleared": "modified", - }, "src/main/resources/config/neo4j/migrations/user__admin.json": { "stateCleared": "modified", }, @@ -25940,12 +25898,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > monol "src/main/resources/config/liquibase/data/authority.csv": { "stateCleared": "modified", }, - "src/main/resources/config/liquibase/data/user.csv": { - "stateCleared": "modified", - }, - "src/main/resources/config/liquibase/data/user_authority.csv": { - "stateCleared": "modified", - }, "src/main/resources/config/liquibase/fake-data/another_simple.csv": { "stateCleared": "modified", }, @@ -26551,12 +26503,6 @@ exports[`Matrix test of SubGenerator kotlin of kotlin JHipster blueprint > monol "src/main/resources/config/liquibase/data/authority.csv": { "stateCleared": "modified", }, - "src/main/resources/config/liquibase/data/user.csv": { - "stateCleared": "modified", - }, - "src/main/resources/config/liquibase/data/user_authority.csv": { - "stateCleared": "modified", - }, "src/main/resources/config/liquibase/fake-data/another_simple.csv": { "stateCleared": "modified", }, diff --git a/generators/spring-boot/generator.js b/generators/spring-boot/generator.js index f87ed67f9..0a2bd6b1e 100644 --- a/generators/spring-boot/generator.js +++ b/generators/spring-boot/generator.js @@ -1,4 +1,4 @@ -import { dirname, join } from 'path'; +import { basename, dirname, join } from 'path'; import { fileURLToPath } from 'url'; import BaseApplicationGenerator from 'generator-jhipster/generators/spring-boot'; import { prepareSqlApplicationProperties } from 'generator-jhipster/generators/spring-data-relational/support'; @@ -6,6 +6,7 @@ import { files as entityServerFiles } from 'jhipster-7-templates/esm/generators/ import { getEnumInfo } from 'generator-jhipster/generators/base-application/support'; import { files as serverFiles } from 'jhipster-7-templates/esm/generators/server'; +import { convertToKotlinFile } from '../kotlin/support/files.js'; import migration from './migration.cjs'; import { serverFiles as sqlFiles } from './files-sql.js'; import { entityCouchbaseFiles } from './entity-files-couchbase.js'; @@ -25,8 +26,6 @@ const { DOCKER_ELASTICSEARCH_CONTAINER, ELASTICSEARCH_VERSION, MAIN_DIR, - SERVER_MAIN_SRC_DIR, - SERVER_TEST_SRC_DIR, TEST_DIR, } = jhipsterConstants; @@ -37,12 +36,6 @@ const jhipster7TemplatesPackage = dirname(fileURLToPath(import.meta.resolve('jhi const SERVER_MAIN_SRC_KOTLIN_DIR = `${MAIN_DIR}kotlin/`; const SERVER_TEST_SRC_KOTLIN_DIR = `${TEST_DIR}kotlin/`; -const convertToKotlinFile = file => - file - .replace('.java', '.kt') - .replace(SERVER_MAIN_SRC_DIR, SERVER_MAIN_SRC_KOTLIN_DIR) - .replace(SERVER_TEST_SRC_DIR, SERVER_TEST_SRC_KOTLIN_DIR); - const JAVA_VERSION = '11'; export default class extends BaseApplicationGenerator { @@ -104,10 +97,41 @@ export default class extends BaseApplicationGenerator { syncUserWithIdp: application.authenticationType === 'oauth2', }); - application.customizeTemplatePaths.push(file => { - const { resolvedSourceFile, sourceFile, destinationFile, namespace } = file; - if ( - sourceFile.includes('package-info.java') || + const isKotlinGeneratorFile = file => file.namespace === 'jhipster-kotlin:spring-boot'; + + application.customizeTemplatePaths.unshift( + // Remove package-info.java files + file => (file.sourceFile.includes('package-info.java') ? undefined : file), + file => { + // Don't use liquibase.gradle from liquibase generator + if (['gradle/liquibase.gradle'].includes(file.sourceFile)) return undefined; + // Passthrough non liquibase files + if (!file.sourceFile.includes('src/main/resources/config/liquibase')) return file; + // Use master.xml from jhipster 7 templates + if (file.sourceFile.includes('master.xml')) return file.namespace === 'jhipster:liquibase' ? undefined : file; + // Use liquibase templates from liquibase generator + return file.namespace === 'jhipster:liquibase' ? file : undefined; + }, + // Use docker-compose files from docker generator + file => + isKotlinGeneratorFile(file) && + file.sourceFile.includes('src/main/docker') && + !file.sourceFile.includes('src/main/docker/jhipster-control-center.yml') && + !file.sourceFile.includes('src/main/docker/jib') && + !file.sourceFile.includes('src/main/docker/grafana') && + !file.sourceFile.includes('src/main/docker/monitoring.yml') + ? undefined + : file, + // Use wrappers scripts from maven/gradle generators + file => + isKotlinGeneratorFile(file) && + ([('mvnw', 'mvnw.cmd', 'gradlew', 'gradlew.bat')].includes(file.sourceFile) || + file.sourceFile.includes('.mvnw') || + file.sourceFile.includes('gradle/wrapper/')) + ? undefined + : file, + // Ignore files from generators + file => [ 'jhipster:java:domain', 'jhipster:spring-cloud:gateway', @@ -116,69 +140,36 @@ export default class extends BaseApplicationGenerator { 'jhipster:spring-data-mongodb', 'jhipster:spring-data-neo4j', 'jhipster:spring-data-relational', - ].includes(namespace) - ) { - return undefined; - } - - // Use master.xml from jhipster 7 templates - if (sourceFile.includes('master.xml')) { - return namespace === 'jhipster:liquibase' ? undefined : file; - } - - if (namespace === 'jhipster-kotlin:spring-boot') { + ].includes(file.namespace) + ? undefined + : file, + // Kotling blueprint does not implements these files + file => { + const sourceBasename = basename(file.sourceFile); + return ['_persistClass_Asserts.java', '_persistClass_TestSamples.java'].includes(sourceBasename) ? undefined : file; + }, + file => { + let { resolvedSourceFile, sourceFile, destinationFile, namespace } = file; // Already resolved kotlin files if (resolvedSourceFile.endsWith('.kt') || resolvedSourceFile.includes('.kt.')) { return file; } - // Use docker-compose files from docker generator - if ( - sourceFile.includes('src/main/docker') && - !sourceFile.includes('src/main/docker/jhipster-control-center.yml') && - !sourceFile.includes('src/main/docker/jib') && - !sourceFile.includes('src/main/docker/grafana') && - !sourceFile.includes('src/main/docker/monitoring.yml') - ) { - return undefined; - } - - // Use wrappers scripts from maven/gradle generators - if ( - ['mvnw', 'mvnw.cmd', 'gradlew', 'gradlew.bat'].includes(sourceFile) || - sourceFile.includes('.mvnw') || - sourceFile.includes('gradle/wrapper/') - ) { - return undefined; - } - - // Use liquibase templates from liquibase generator - if (sourceFile.includes('src/main/resources/liquibase')) { - return undefined; + if (sourceFile.includes('.java')) { + sourceFile = isKotlinGeneratorFile(file) + ? convertToKotlinFile(sourceFile) + : join(namespace.split(':').pop(), convertToKotlinFile(sourceFile)); + return { + ...file, + sourceFile, + javaResolvedSourceFile: resolvedSourceFile, + resolvedSourceFile: this.templatePath(sourceFile), + destinationFile: convertToKotlinFile(destinationFile), + }; } - } - - // Don't use liquibase.gradle from liquibase generator - if (['gradle/liquibase.gradle'].includes(sourceFile)) { - return undefined; - } - - /* - // Ignore convention plugins - if (sourceFile.includes('buildSrc')) { - return undefined; - } - */ - - if (sourceFile.includes('.java')) { - return { - ...file, - resolvedSourceFile: this.templatePath(convertToKotlinFile(sourceFile)), - destinationFile: convertToKotlinFile(destinationFile), - }; - } - return file; - }); + return file; + }, + ); }, async migration({ application, applicationDefaults }) { // Downgrade elasticsearch to 7.17.4 @@ -284,6 +275,16 @@ export default class extends BaseApplicationGenerator { entity.jpaMetamodelFiltering = false; } }, + prepareEntityForKotlin({ entity }) { + const { primaryKey } = entity; + if (primaryKey && primaryKey.name === 'id') { + // Kotlin does not support string ids specifications. + primaryKey.javaBuildSpecification = 'buildRangeSpecification'; + for (const field of primaryKey.fields) { + field.fieldJavaBuildSpecification = 'buildRangeSpecification'; + } + } + }, }); } diff --git a/generators/spring-boot/templates/couchbase/src/main/kotlin/package/repository/PersistentTokenRepository_couchbase.kt.ejs b/generators/spring-boot/templates/couchbase/src/main/kotlin/package/repository/PersistentTokenRepository_couchbase.kt.ejs index 663b27d51..be5964e62 100644 --- a/generators/spring-boot/templates/couchbase/src/main/kotlin/package/repository/PersistentTokenRepository_couchbase.kt.ejs +++ b/generators/spring-boot/templates/couchbase/src/main/kotlin/package/repository/PersistentTokenRepository_couchbase.kt.ejs @@ -19,7 +19,7 @@ package <%= packageName %>.repository import <%= packageName %>.domain.PersistentToken -import <%= packageName %>.domain.<%= asEntity('User') %> +import <%= packageName %>.domain.<%= user.persistClass %> import org.springframework.data.couchbase.repository.CouchbaseRepository import java.util.List import java.util.Optional @@ -37,7 +37,7 @@ interface PersistentTokenRepository: CouchbaseRepository) = findByLogin(user.login) + fun findByUser(user: <%= user.persistClass %>) = findByLogin(user.login) fun findByLogin(login: String): List diff --git a/generators/spring-boot/templates/src/main/kotlin/_package_/config/LiquibaseConfiguration.kt.ejs b/generators/spring-boot/templates/liquibase/src/main/kotlin/_package_/config/LiquibaseConfiguration.kt.ejs similarity index 100% rename from generators/spring-boot/templates/src/main/kotlin/_package_/config/LiquibaseConfiguration.kt.ejs rename to generators/spring-boot/templates/liquibase/src/main/kotlin/_package_/config/LiquibaseConfiguration.kt.ejs diff --git a/generators/spring-boot/templates/partials/it_patch_update.partial.kt.ejs b/generators/spring-boot/templates/partials/it_patch_update.partial.kt.ejs index b76f6bc5d..94be30c58 100644 --- a/generators/spring-boot/templates/partials/it_patch_update.partial.kt.ejs +++ b/generators/spring-boot/templates/partials/it_patch_update.partial.kt.ejs @@ -50,7 +50,7 @@ webTestClient .expectStatus() .isOk <%_ } else { _%> -rest<%= entityClass %>MockMvc.perform(patch(ENTITY_API_URL_ID, partialUpdated<%= persistClass %>.<%= primaryKey.name %>)<% if (testsNeedCsrf) { %>.with(csrf())<% }%> +rest<%= entityClass %>MockMvc.perform(patch(ENTITY_API_URL_ID, partialUpdated<%= persistClass %>.<%= primaryKey.name %>)<% if (authenticationUsesCsrf) { %>.with(csrf())<% }%> .contentType("application/merge-patch+json") .content(convertObjectToJsonBytes(<%= 'partialUpdated' + persistClass %>))) .andExpect(status().isOk) diff --git a/generators/spring-boot/templates/sql/reactive/src/main/kotlin/package/repository/rowmapper/UserRowMapper.kt.ejs b/generators/spring-boot/templates/sql/reactive/src/main/kotlin/package/repository/rowmapper/UserRowMapper.kt.ejs index 42315fdb1..7c074ed3d 100644 --- a/generators/spring-boot/templates/sql/reactive/src/main/kotlin/package/repository/rowmapper/UserRowMapper.kt.ejs +++ b/generators/spring-boot/templates/sql/reactive/src/main/kotlin/package/repository/rowmapper/UserRowMapper.kt.ejs @@ -24,23 +24,23 @@ import java.util.function.BiFunction import org.springframework.stereotype.Service -import <%= packageName %>.domain.<%= asEntity('User') %> +import <%= packageName %>.domain.<%= user.persistClass %> import io.r2dbc.spi.Row /** - * Converter between [Row] to [<%= asEntity('User') %>], with proper type conversions. + * Converter between [Row] to [<%= user.persistClass %>], with proper type conversions. */ @Service class UserRowMapper( private val converter: ColumnConverter -): BiFunction> { +): BiFunction> { /** * Take a [Row] and a column prefix, and extract all the fields. - * @return the [<%= asEntity('User') %>] stored in the database. + * @return the [<%= user.persistClass %>] stored in the database. */ - override fun apply(row: Row, prefix: String): <%= asEntity('User') %> { - val entity = <%= asEntity('User') %>() + override fun apply(row: Row, prefix: String): <%= user.persistClass %> { + val entity = <%= user.persistClass %>() entity.id = converter.fromRow(row, "${prefix}_id", <%= user.primaryKey.type %>::class.java) entity.login = converter.fromRow(row, "${prefix}_login", String::class.java) <%_ if (!authenticationTypeOauth2) { _%> diff --git a/generators/spring-boot/templates/src/main/kotlin/package/config/CacheConfiguration.kt.ejs b/generators/spring-boot/templates/src/main/kotlin/package/config/CacheConfiguration.kt.ejs index 7aba87fcf..65d9c42b9 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/config/CacheConfiguration.kt.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/config/CacheConfiguration.kt.ejs @@ -18,7 +18,7 @@ -%> package <%= packageName %>.config -<%_ if (cacheProviderEhCache) { _%> +<%_ if (cacheProviderEhcache) { _%> import java.time.Duration import org.ehcache.config.builders.CacheConfigurationBuilder @@ -54,7 +54,7 @@ import com.hazelcast.core.HazelcastInstance import org.slf4j.LoggerFactory <%_ } _%> -<%_ if (cacheProviderEhCache || cacheProviderCaffeine) { _%> +<%_ if (cacheProviderEhcache || cacheProviderCaffeine) { _%> import org.springframework.boot.autoconfigure.cache.JCacheManagerCustomizer <%_ if (enableHibernateCache) { _%> import org.springframework.boot.autoconfigure.orm.jpa.HibernatePropertiesCustomizer @@ -168,7 +168,7 @@ import tech.jhipster.config.JHipsterProperties @EnableCaching class CacheConfiguration(<%_ if (!cacheProviderNo) { _%> @Autowired val gitProperties: GitProperties?, - @Autowired val buildProperties: BuildProperties?<% } %><% if (cacheProviderEhCache || cacheProviderCaffeine) { %>, + @Autowired val buildProperties: BuildProperties?<% } %><% if (cacheProviderEhcache || cacheProviderCaffeine) { %>, private val jHipsterProperties: JHipsterProperties<% } else if (cacheProviderHazelcast) { %>, private val env: Environment<% if (serviceDiscoveryAny) { %>, private val serverProperties: ServerProperties, @@ -177,12 +177,12 @@ class CacheConfiguration(<%_ if (!cacheProviderNo) { _%> @Autowired(required = false) val discoveryClient: DiscoveryClient?, @Autowired(required = false) val registration: Registration?<% } %><% } %> ) { - <%_ if (cacheProviderEhCache || cacheProviderCaffeine) { _%> + <%_ if (cacheProviderEhcache || cacheProviderCaffeine) { _%> private val jcacheConfiguration: javax.cache.configuration.Configuration init { - <%_ if (cacheProviderEhCache) { _%> + <%_ if (cacheProviderEhcache) { _%> val ehcache = jHipsterProperties.cache.ehcache jcacheConfiguration = Eh107Configuration.fromEhcacheCacheConfiguration( @@ -222,16 +222,16 @@ class CacheConfiguration(<%_ if (!cacheProviderNo) { _%> createCache(cm, <%= packageName %>.repository.UserRepository.USERS_BY_LOGIN_CACHE) createCache(cm, <%= packageName %>.repository.UserRepository.USERS_BY_EMAIL_CACHE) <%_ if (enableHibernateCache) { _%> - createCache(cm, <%= packageName %>.domain.<%= asEntity('User') %>::class.java.name) + createCache(cm, <%= packageName %>.domain.<%= user.persistClass %>::class.java.name) createCache(cm, <%= packageName %>.domain.Authority::class.java.name) - createCache(cm, <%= packageName %>.domain.<%= asEntity('User') %>::class.java.name + ".authorities") + createCache(cm, <%= packageName %>.domain.<%= user.persistClass %>::class.java.name + ".authorities") <%_ if (authenticationTypeSession) { _%> createCache(cm, <%= packageName %>.domain.PersistentToken::class.java.name) - createCache(cm, <%= packageName %>.domain.<%= asEntity('User') %>::class.java.name + ".persistentTokens") + createCache(cm, <%= packageName %>.domain.<%= user.persistClass %>::class.java.name + ".persistentTokens") <%_ } _%> <%_ } _%> <%_ } _%> - <%_ if (cacheProviderEhCache) { _%> + <%_ if (cacheProviderEhcache) { _%> // jhipster-needle-ehcache-add-entry <%_ } _%> <%_ if (cacheProviderCaffeine) { _%> @@ -731,12 +731,12 @@ class CacheConfiguration(<%_ if (!cacheProviderNo) { _%> createCache(it, <%= packageName %>.repository.UserRepository.USERS_BY_LOGIN_CACHE, jcacheConfiguration) createCache(it, <%= packageName %>.repository.UserRepository.USERS_BY_EMAIL_CACHE, jcacheConfiguration) <%_ if (enableHibernateCache) { _%> - createCache(it, <%= packageName %>.domain.<%= asEntity('User') %>::class.java.name, jcacheConfiguration) + createCache(it, <%= packageName %>.domain.<%= user.persistClass %>::class.java.name, jcacheConfiguration) createCache(it, <%= packageName %>.domain.Authority::class.java.name, jcacheConfiguration) - createCache(it, <%= packageName %>.domain.<%= asEntity('User') %>::class.java.name + ".authorities", jcacheConfiguration) + createCache(it, <%= packageName %>.domain.<%= user.persistClass %>::class.java.name + ".authorities", jcacheConfiguration) <%_ if (authenticationTypeSession) { _%> createCache(it, <%= packageName %>.domain.PersistentToken::class.java.name, jcacheConfiguration) - createCache(it, <%= packageName %>.domain.<%= asEntity('User') %>::class.java.name + ".persistentTokens", jcacheConfiguration) + createCache(it, <%= packageName %>.domain.<%= user.persistClass %>::class.java.name + ".persistentTokens", jcacheConfiguration) <%_ } _%> <%_ } _%> <%_ } _%> diff --git a/generators/spring-boot/templates/src/main/kotlin/package/config/WebConfigurer.kt.ejs b/generators/spring-boot/templates/src/main/kotlin/package/config/WebConfigurer.kt.ejs index 9ec988a34..9932ef170 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/config/WebConfigurer.kt.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/config/WebConfigurer.kt.ejs @@ -167,7 +167,7 @@ class WebConfigurer( private fun setLocationForStaticAssets(server: WebServerFactory) { if (server is ConfigurableServletWebServerFactory) { val prefixPath = resolvePathPrefix() - val root = File(prefixPath + "<%= CLIENT_DIST_DIR %>") + val root = File(prefixPath + "<%= clientDistDir %>") if (root.exists() && root.isDirectory) { server.setDocumentRoot(root) } @@ -181,7 +181,7 @@ class WebConfigurer( val fullExecutablePath = decode(this.javaClass.getResource("").path, StandardCharsets.UTF_8) val rootPath = Paths.get(".").toUri().normalize().path val extractedPath = fullExecutablePath.replace(rootPath, "") - val extractionEndIndex = extractedPath.indexOf("<%= BUILD_DIR %>") + val extractionEndIndex = extractedPath.indexOf("<%= temporaryDir %>") if (extractionEndIndex <= 0) { return "" } diff --git a/generators/spring-boot/templates/src/main/kotlin/package/config/dbmigrations/InitialSetupMigration.kt.ejs b/generators/spring-boot/templates/src/main/kotlin/package/config/dbmigrations/InitialSetupMigration.kt.ejs index a778cc7f3..8e83ceeb0 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/config/dbmigrations/InitialSetupMigration.kt.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/config/dbmigrations/InitialSetupMigration.kt.ejs @@ -19,7 +19,7 @@ package <%= packageName %>.config.dbmigrations import <%= packageName %>.domain.Authority -import <%= packageName %>.domain.<%= asEntity('User') %> +import <%= packageName %>.domain.<%= user.persistClass %> import <%= packageName %>.security.ADMIN import <%= packageName %>.security.USER import <%= packageName %>.config.SYSTEM_ACCOUNT @@ -70,8 +70,8 @@ class InitialSetupMigration(private val template: MongoTemplate) { template.save(admin) } - private fun createUser(userAuthority: Authority): <%= asEntity('User') %> { - val userUser = <%= asEntity('User') %>( + private fun createUser(userAuthority: Authority): <%= user.persistClass %> { + val userUser = <%= user.persistClass %>( id = "user-2", login = "user", password = "\$2a\$10\$VEjxo0jq2YG9Rbk2HmX9S.k1uZBGYUHdUcid3g/vfiEl7lwWgOH/K", @@ -87,8 +87,8 @@ class InitialSetupMigration(private val template: MongoTemplate) { return userUser; } - private fun createAdmin(adminAuthority: Authority, userAuthority: Authority): <%= asEntity('User') %> { - val adminUser = <%= asEntity('User') %>( + private fun createAdmin(adminAuthority: Authority, userAuthority: Authority): <%= user.persistClass %> { + val adminUser = <%= user.persistClass %>( id = "user-1", login = "admin", password = "\$2a\$10\$gSAhZrxMllrbgj/kkK9UceBPpChGWJA7SYIb1Mqo.n5aNLq1/oRrC", diff --git a/generators/spring-boot/templates/src/main/kotlin/package/domain/Entity.kt.jhi.ejs b/generators/spring-boot/templates/src/main/kotlin/package/domain/Entity.kt.jhi.ejs index dd403ff07..bfb1aa418 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/domain/Entity.kt.jhi.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/domain/Entity.kt.jhi.ejs @@ -59,18 +59,18 @@ import io.swagger.v3.oas.annotations.media.Schema <%_ } _%> import java.io.Serializable -<%_ if (fieldsContainBigDecimal) { _%> +<%_ if (anyFieldIsBigDecimal) { _%> import java.math.BigDecimal -<%_ } if (fieldsContainInstant) { _%> +<%_ } if (anyFieldIsInstant) { _%> import java.time.Instant -<%_ } if (fieldsContainLocalDate) { _%> +<%_ } if (anyFieldIsLocalDate) { _%> import java.time.LocalDate -<%_ } if (fieldsContainZonedDateTime) { _%> +<%_ } if (anyFieldIsZonedDateTime) { _%> import java.time.ZonedDateTime -<%_ } if (fieldsContainDuration) { _%> +<%_ } if (anyFieldIsDuration) { _%> import java.time.Duration <%_ } _%> -<%_ if (fieldsContainUUID || otherEntityPrimaryKeyTypesIncludesUUID) { _%> +<%_ if (anyFieldIsUUID || otherEntityPrimaryKeyTypesIncludesUUID) { _%> import java.util.UUID <%_ } Object.keys(uniqueEnums).forEach(function(element) { _%> diff --git a/generators/spring-boot/templates/src/main/kotlin/package/domain/Entity.kt.jhi.javax_persistence.ejs b/generators/spring-boot/templates/src/main/kotlin/package/domain/Entity.kt.jhi.javax_persistence.ejs index ac5ff21f1..70749bd6c 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/domain/Entity.kt.jhi.javax_persistence.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/domain/Entity.kt.jhi.javax_persistence.ejs @@ -22,7 +22,7 @@ -%> <&_ if (fragment.importSection) { -&> import javax.persistence.* -<%_ if ((databaseTypePostgres && fieldsContainTextBlob) || (fieldsContainUUID && (databaseTypeMysql || databaseTypeMariadb))) { _%> +<%_ if ((prodDatabaseTypePostgresql && anyFieldHasTextContentType) || (anyFieldIsUUID && (prodDatabaseTypeMysql || prodDatabaseTypeMariadb))) { _%> import org.hibernate.annotations.Type <%_ } _%> <&_ } -&> @@ -50,7 +50,7 @@ import org.hibernate.annotations.Type <%_ } _%> <%_ if (field.fieldTypeBytes) { _%> @Lob - <%_ if (databaseTypePostgres && field.blobContentTypeText) { _%> + <%_ if (prodDatabaseTypePostgresql && field.blobContentTypeText) { _%> @Type(type = "org.hibernate.type.TextType") <%_ } _%> <%_ } _%> @@ -58,7 +58,7 @@ import org.hibernate.annotations.Type @Column(name = "<%- field.fieldNameAsDatabaseColumn %>"<% if (field.fieldValidationRequired) { %>, nullable = false<% } %><% if (field.fieldValidationUnique) { %>, unique = true<% } %>) <%_ } else if (field.fieldTypeBigDecimal) { _%> @Column(name = "<%- field.fieldNameAsDatabaseColumn %>", precision = 21, scale = 2<% if (field.fieldValidationRequired) { %>, nullable = false<% } %><% if (field.fieldValidationUnique) { %>, unique = true<% } %>) - <%_ } else if (field.fieldTypeUUID && (databaseTypeMysql || databaseTypeMariadb)) { _%> + <%_ } else if (field.fieldTypeUUID && (prodDatabaseTypeMysql || prodDatabaseTypeMariadb)) { _%> @Type(type = "uuid-char") @Column(name = "<%- field.fieldNameAsDatabaseColumn %>", length = 36<% if (field.fieldValidationRequired) { %>, nullable = false<% } %><% if (field.fieldValidationUnique) { %>, unique = true<% } %>) <%_ } else { _%> diff --git a/generators/spring-boot/templates/src/main/kotlin/package/domain/Entity.kt.jhi.javax_validation.ejs b/generators/spring-boot/templates/src/main/kotlin/package/domain/Entity.kt.jhi.javax_validation.ejs index 35a8eb56c..cf7e17da9 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/domain/Entity.kt.jhi.javax_validation.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/domain/Entity.kt.jhi.javax_validation.ejs @@ -21,7 +21,7 @@ EJS fragments will process % delimiter tags in template and & delimiter tags in the merge process. -%> <&_ if (fragment.importSection) { -&> -<%_ if (validation) { _%> +<%_ if (anyPropertyHasValidation) { _%> import javax.validation.constraints.* <%_ } _%> <&_ } -&> diff --git a/generators/spring-boot/templates/src/main/kotlin/package/domain/Entity.kt.jhi.spring_data_cassandra.ejs b/generators/spring-boot/templates/src/main/kotlin/package/domain/Entity.kt.jhi.spring_data_cassandra.ejs index 9abf6e72b..d86981f5e 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/domain/Entity.kt.jhi.spring_data_cassandra.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/domain/Entity.kt.jhi.spring_data_cassandra.ejs @@ -22,7 +22,7 @@ -%> <&_ if (fragment.importSection) { -&> import org.springframework.data.annotation.Id - <%_ if (fieldsContainBlob) { _%> + <%_ if (anyFieldIsBlobDerived) { _%> import java.nio.ByteBuffer import org.springframework.data.cassandra.core.mapping.Column <%_ } _%> diff --git a/generators/spring-boot/templates/src/main/kotlin/package/domain/PersistentToken.kt.ejs b/generators/spring-boot/templates/src/main/kotlin/package/domain/PersistentToken.kt.ejs index d43f5708b..78db19b14 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/domain/PersistentToken.kt.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/domain/PersistentToken.kt.ejs @@ -178,7 +178,7 @@ class PersistentToken @JvmOverloads constructor( <%_ if (databaseTypeNeo4j) { _%> @Relationship(value = "HAS_PERSISTENT_TOKEN", direction = Relationship.Direction.INCOMING) <%_ } _%> - var user: <%= asEntity('User') %>? = null + var user: <%= user.persistClass %>? = null <%_ } _%> ) : Serializable { diff --git a/generators/spring-boot/templates/src/main/kotlin/package/domain/User.kt.ejs b/generators/spring-boot/templates/src/main/kotlin/package/domain/User.kt.ejs index 47748f09e..1dcfd7525 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/domain/User.kt.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/domain/User.kt.ejs @@ -140,7 +140,7 @@ import org.springframework.data.couchbase.core.mapping.id.GenerationStrategy.USE <%_ if (searchEngineElasticsearch) { _%> @org.springframework.data.elasticsearch.annotations.Document(indexName = "user") <%_ } _%> -class <%= asEntity('User') %> ( +class <%= user.persistClass %> ( <%_ if (databaseTypeSql) { _%> @Id @@ -465,7 +465,7 @@ class <%= asEntity('User') %> ( override fun equals(other: Any?): Boolean { if (this === other) return true - if (other !is <%= asEntity('User') %>) return false + if (other !is <%= user.persistClass %>) return false if (other.id == null || id == null) return false return id == other.id @@ -474,7 +474,7 @@ class <%= asEntity('User') %> ( override fun hashCode() = 31 override fun toString() = - "<%= asEntity('User') %>{" + + "<%= user.persistClass %>{" + "login='" + login + '\'' + ", firstName='" + firstName + '\'' + ", lastName='" + lastName + '\'' + diff --git a/generators/spring-boot/templates/src/main/kotlin/package/repository/EntityRepositoryInternalImpl_reactive.kt.ejs b/generators/spring-boot/templates/src/main/kotlin/package/repository/EntityRepositoryInternalImpl_reactive.kt.ejs index 2c7225972..802ea7ab0 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/repository/EntityRepositoryInternalImpl_reactive.kt.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/repository/EntityRepositoryInternalImpl_reactive.kt.ejs @@ -19,17 +19,17 @@ package <%= entityAbsolutePackage %>.repository import java.util.function.BiFunction -<%_ if (fieldsContainBigDecimal) { _%> +<%_ if (anyFieldIsBigDecimal) { _%> import java.math.BigDecimal -<%_} if (fieldsContainInstant) { _%> +<%_} if (anyFieldIsInstant) { _%> import java.time.Instant -<%_ } if (fieldsContainLocalDate) { _%> +<%_ } if (anyFieldIsLocalDate) { _%> import java.time.LocalDate -<%_ } if (fieldsContainZonedDateTime) { _%> +<%_ } if (anyFieldIsZonedDateTime) { _%> import java.time.ZonedDateTime -<%_ } if (fieldsContainDuration) { _%> +<%_ } if (anyFieldIsDuration) { _%> import java.time.Duration -<%_ } if (fieldsContainUUID) { _%> +<%_ } if (anyFieldIsUUID) { _%> import java.util.UUID <%_ } _%> import java.util.ArrayList @@ -116,7 +116,7 @@ class <%= entityClass %>RepositoryInternalImpl( companion object { private val entityTable = Table.aliased("<%= entityTableName %>", EntityManager.ENTITY_ALIAS) <%_ reactiveEagerRelations.forEach(function(rel) { _%> - private val <%= rel.relationshipName %>Table = Table.aliased("<%= rel.otherEntityTableName %>", "<%= _generateSqlSafeName(rel.relationshipName) %>") + private val <%= rel.relationshipName %>Table = Table.aliased("<%= rel.otherEntityTableName %>", "<%= rel.relationshipSqlSafeName %>") <%_ }); _%> <%_ relationships.forEach(function(rel) { if (rel.relationshipManyToMany && rel.ownerSide) { diff --git a/generators/spring-boot/templates/src/main/kotlin/package/repository/PersistentTokenRepository.kt.ejs b/generators/spring-boot/templates/src/main/kotlin/package/repository/PersistentTokenRepository.kt.ejs index ef5b6ab78..413cc72fd 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/repository/PersistentTokenRepository.kt.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/repository/PersistentTokenRepository.kt.ejs @@ -35,7 +35,7 @@ import com.datastax.oss.driver.api.mapper.annotations.Mapper import com.datastax.oss.driver.api.mapper.annotations.Select <%_ } _%> import <%= packageName %>.domain.PersistentToken -import <%= packageName %>.domain.<%= asEntity('User') %> +import <%= packageName %>.domain.<%= user.persistClass %> <%_ if (!databaseTypeCassandra) { _%> import java.time.LocalDate <%_ } _%> @@ -110,7 +110,7 @@ class PersistentTokenRepository( fun findById(presentedSeries: String): Optional = Optional.ofNullable(persistentTokenDao.get(presentedSeries)) - fun findByUser( user: <%= asEntity('User') %>): MutableList { + fun findByUser( user: <%= user.persistClass %>): MutableList { val statementBuilder = findPersistentTokenSeriesByUserIdStmt.boundStatementBuilder() statementBuilder.setString("user_id", user.id) val rs = session.execute(statementBuilder.build()) diff --git a/generators/spring-boot/templates/src/main/kotlin/package/repository/UserRepository.kt.ejs b/generators/spring-boot/templates/src/main/kotlin/package/repository/UserRepository.kt.ejs index ef69fe695..c5e8d0984 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/repository/UserRepository.kt.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/repository/UserRepository.kt.ejs @@ -21,7 +21,7 @@ package <%= packageName %>.repository <%_ if (databaseTypeSql && reactive) { _%> import <%= packageName %>.domain.Authority <%_ } _%> -import <%= packageName %>.domain.<%= asEntity('User') %> +import <%= packageName %>.domain.<%= user.persistClass %> <%_ if (databaseTypeCassandra) { _%> import com.datastax.oss.driver.api.core.CqlIdentifier @@ -58,7 +58,7 @@ import com.datastax.oss.driver.api.querybuilder.insert.RegularInsert <%_ if (databaseTypeSql && reactive) { _%> import org.apache.commons.beanutils.BeanComparator <%_ } _%> -<%_ if (cacheManagerIsAvailable) { _%> +<%_ if (cacheProviderAny) { _%> import org.springframework.cache.annotation.Cacheable <%_ } _%> <%_ if (databaseTypeSql || databaseTypeCouchbase || databaseTypeMongodb || databaseTypeNeo4j) { _%> @@ -139,7 +139,7 @@ import java.time.Instant <%_ } _%> /** - * Spring Data <% if (databaseTypeSql && !reactive) { %>JPA<% } else if (databaseTypeSql && reactive) { %>R2DBC<% } else if (databaseTypeMongodb) { %>MongoDB<% } else if (databaseTypeCouchbase) { %>Couchbase<% } else if (databaseTypeCassandra) { %>Cassandra<% } else if (databaseTypeNeo4j) { %>Neo4j<% } %> repository for the {@link <%= asEntity('User') %>} entity. + * Spring Data <% if (databaseTypeSql && !reactive) { %>JPA<% } else if (databaseTypeSql && reactive) { %>R2DBC<% } else if (databaseTypeMongodb) { %>MongoDB<% } else if (databaseTypeCouchbase) { %>Couchbase<% } else if (databaseTypeCassandra) { %>Cassandra<% } else if (databaseTypeNeo4j) { %>Neo4j<% } %> repository for the {@link <%= user.persistClass %>} entity. */ <%_ let optionalOrMono = reactive ? 'Mono' : 'Optional'; @@ -149,10 +149,10 @@ import java.time.Instant _%> <%_ if ((databaseTypeSql && !reactive) || databaseTypeMongodb || databaseTypeNeo4j || databaseTypeCouchbase) { _%> @Repository -interface UserRepository : <% if (databaseTypeSql) { %>JpaRepository<<%= asEntity('User') %>, <%= user.primaryKey.type %>><% } %><% if (reactive && !databaseTypeCouchbase) { %>Reactive<% } %><% if (databaseTypeMongodb) { %>MongoRepository<<%= asEntity('User') %>, String><% } %><% if (databaseTypeNeo4j) { %>Neo4jRepository<<%= asEntity('User') %>, String><% } %><% if (databaseTypeCouchbase) { %>JHipsterCouchbaseRepository<<%= asEntity('User') %>, String><%if (searchEngineCouchbase) { %>, CouchbaseSearchRepository<<%= asEntity('User') %>, String><% } } %> { +interface UserRepository : <% if (databaseTypeSql) { %>JpaRepository<<%= user.persistClass %>, <%= user.primaryKey.type %>><% } %><% if (reactive && !databaseTypeCouchbase) { %>Reactive<% } %><% if (databaseTypeMongodb) { %>MongoRepository<<%= user.persistClass %>, String><% } %><% if (databaseTypeNeo4j) { %>Neo4jRepository<<%= user.persistClass %>, String><% } %><% if (databaseTypeCouchbase) { %>JHipsterCouchbaseRepository<<%= user.persistClass %>, String><%if (searchEngineCouchbase) { %>, CouchbaseSearchRepository<<%= user.persistClass %>, String><% } } %> { <%_ if (!authenticationTypeOauth2) { _%> - fun findOneByActivationKey(activationKey: String): <%= optionalOrMono %><<%= asEntity('User') %>><% if (databaseTypeCouchbase) { %> { + fun findOneByActivationKey(activationKey: String): <%= optionalOrMono %><<%= user.persistClass %>><% if (databaseTypeCouchbase) { %> { return findIdByActivationKey(activationKey) .map(User::id) .flatMap(this::findById); @@ -163,7 +163,7 @@ interface UserRepository : <% if (databaseTypeSql) { %>JpaRepository<<%= asEntit <%_ } _%> <%_ if (!authenticationTypeOauth2) { _%> - fun findAllByActivatedIsFalseAndActivationKeyIsNotNullAndCreatedDateBefore(dateTime: Instant): <%= listOrFlux %><<%= asEntity('User') %>><% if (databaseTypeCouchbase) { %> { + fun findAllByActivatedIsFalseAndActivationKeyIsNotNullAndCreatedDateBefore(dateTime: Instant): <%= listOrFlux %><<%= user.persistClass %>><% if (databaseTypeCouchbase) { %> { return findAllById(toIds(findAllIdsByActivatedIsFalseAndActivationKeyIsNotNullAndCreatedDateBefore(dateTime)<%= toListSuffix %>)) } @@ -175,7 +175,7 @@ interface UserRepository : <% if (databaseTypeSql) { %>JpaRepository<<%= asEntit <%_ if (!authenticationTypeOauth2) { _%> <%_ if (databaseTypeCouchbase) { _%> <%_ } _%> - fun findOneByResetKey(resetKey: String): <%= optionalOrMono %><<%= asEntity('User') %>><% if (databaseTypeCouchbase) { %> { + fun findOneByResetKey(resetKey: String): <%= optionalOrMono %><<%= user.persistClass %>><% if (databaseTypeCouchbase) { %> { return findIdByResetKey(resetKey) .map(User::id) .flatMap(this::findById) @@ -188,11 +188,11 @@ interface UserRepository : <% if (databaseTypeSql) { %>JpaRepository<<%= asEntit <%_ if (!authenticationTypeOauth2) { _%> <%_ if (databaseTypeCouchbase || databaseTypeMongodb || databaseTypeNeo4j) { _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> @Cacheable(cacheNames = [USERS_BY_EMAIL_CACHE]) <%_ } _%> <%_ } _%> - fun findOneByEmailIgnoreCase(email: String?): <%= optionalOrMono %><<%= asEntity('User') %>><% if (databaseTypeCouchbase) { %> { + fun findOneByEmailIgnoreCase(email: String?): <%= optionalOrMono %><<%= user.persistClass %>><% if (databaseTypeCouchbase) { %> { return findIdByEmailIgnoreCase(email!!) .map(User::id) .flatMap(this::findById); @@ -204,45 +204,45 @@ interface UserRepository : <% if (databaseTypeSql) { %>JpaRepository<<%= asEntit <%_ } _%> <%_ if (databaseTypeCouchbase) { _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> @Cacheable(cacheNames = [USERS_BY_LOGIN_CACHE]) <%_ } _%> - fun findOneByLogin(login: String): <%= optionalOrMono %><<%= asEntity('User') %>> { + fun findOneByLogin(login: String): <%= optionalOrMono %><<%= user.persistClass %>> { return findById(login) } <%_ } else if (databaseTypeMongodb || databaseTypeNeo4j) { _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> @Cacheable(cacheNames = [USERS_BY_LOGIN_CACHE]) <%_ } _%> - fun findOneByLogin(login: String): <%= optionalOrMono %><<%= asEntity('User') %>> + fun findOneByLogin(login: String): <%= optionalOrMono %><<%= user.persistClass %>> <%_ } else { _%> - fun findOneByLogin(login: String): <%= optionalOrMono %><<%= asEntity('User') %>> + fun findOneByLogin(login: String): <%= optionalOrMono %><<%= user.persistClass %>> <%_ } _%> <%_ if (databaseTypeNeo4j) { _%> <% if (!reactive) { %>// See https://github.com/neo4j/sdn-rx/issues/51<% } %> - override fun findAll(): <%= listOrFlux %><<%= asEntity('User') %>> + override fun findAll(): <%= listOrFlux %><<%= user.persistClass %>> <%_ } _%> <%_ if (databaseTypeSql) { _%> @EntityGraph(attributePaths = ["authorities"]) - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> @Cacheable(cacheNames = [USERS_BY_LOGIN_CACHE]) <%_ } _%> - fun findOneWithAuthoritiesByLogin(login: String): Optional<<%= asEntity('User') %>> + fun findOneWithAuthoritiesByLogin(login: String): Optional<<%= user.persistClass %>> <%_ if (!authenticationTypeOauth2) { _%> @EntityGraph(attributePaths = ["authorities"]) - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> @Cacheable(cacheNames = [USERS_BY_EMAIL_CACHE]) <%_ } _%> - fun findOneWithAuthoritiesByEmailIgnoreCase(email: String): Optional<<%= asEntity('User') %>> + fun findOneWithAuthoritiesByEmailIgnoreCase(email: String): Optional<<%= user.persistClass %>> <%_ } _%> <%_ } _%> <% if (reactive) { %> <%_ if (!databaseTypeCouchbase) { _%> - fun findAllByIdNotNull(pageable: Pageable): Flux<<%= asEntity('User') %>> + fun findAllByIdNotNull(pageable: Pageable): Flux<<%= user.persistClass %>> <%_ } _%> <%_ if (databaseTypeCouchbase) { _%> @@ -253,26 +253,26 @@ interface UserRepository : <% if (databaseTypeSql) { %>JpaRepository<<%= asEntit @Query(FIND_IDS_QUERY + " AND activated = true") fun findAllIdsByActivatedIsTrue(pageable: Pageable): Flux <%_ } else { _%> - fun findAllByIdNotNullAndActivatedIsTrue(pageable: Pageable): Flux<<%= asEntity('User') %>> + fun findAllByIdNotNullAndActivatedIsTrue(pageable: Pageable): Flux<<%= user.persistClass %>> <%_ } _%> override fun count(): Mono <% } else { %> <%_ if (databaseTypeCouchbase) { _%> - fun findAllByActivatedIsTrue(pageable: Pageable): Page<<%= asEntity('User') %>> { + fun findAllByActivatedIsTrue(pageable: Pageable): Page<<%= user.persistClass %>> { val page = findAllIdsByActivatedIsTrue(pageable); - return PageImpl<<%= asEntity('User') %>>(findAllById(toIds(page.content)), pageable, page.totalElements) + return PageImpl<<%= user.persistClass %>>(findAllById(toIds(page.content)), pageable, page.totalElements) } @Query(FIND_IDS_QUERY + " AND activated = true") fun findAllIdsByActivatedIsTrue(pageable: Pageable): Page <%_ } else { _%> - fun findAllByIdNotNullAndActivatedIsTrue(pageable: Pageable): Page<<%= asEntity('User') %>> + fun findAllByIdNotNullAndActivatedIsTrue(pageable: Pageable): Page<<%= user.persistClass %>> <%_ } _%> <% } %> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> companion object { @@ -284,29 +284,29 @@ interface UserRepository : <% if (databaseTypeSql) { %>JpaRepository<<%= asEntit } <%_ } else if (databaseTypeSql && reactive) { _%> @Repository -interface UserRepository: R2dbcRepository<<%= asEntity('User') %>, <% if (authenticationTypeOauth2) { %>String<% } else { %>Long<% } %>>, UserRepositoryInternal { +interface UserRepository: R2dbcRepository<<%= user.persistClass %>, <% if (authenticationTypeOauth2) { %>String<% } else { %>Long<% } %>>, UserRepositoryInternal { <%_ if (!authenticationTypeOauth2) { _%> - fun findOneByActivationKey(activationKey: String): Mono<<%= asEntity('User') %>> + fun findOneByActivationKey(activationKey: String): Mono<<%= user.persistClass %>> - fun findAllByActivatedIsFalseAndActivationKeyIsNotNullAndCreatedDateBefore(dateTime: LocalDateTime): Flux<<%= asEntity('User') %>> + fun findAllByActivatedIsFalseAndActivationKeyIsNotNullAndCreatedDateBefore(dateTime: LocalDateTime): Flux<<%= user.persistClass %>> - fun findOneByResetKey(resetKey: String): Mono<<%= asEntity('User') %>> + fun findOneByResetKey(resetKey: String): Mono<<%= user.persistClass %>> - fun findOneByEmailIgnoreCase(email: String): Mono<<%= asEntity('User') %>> + fun findOneByEmailIgnoreCase(email: String): Mono<<%= user.persistClass %>> <%_ } _%> - fun findOneByLogin(login: String): Mono<<%= asEntity('User') %>> + fun findOneByLogin(login: String): Mono<<%= user.persistClass %>> <%_ if (databaseType === 'couchbase') { _%> @ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS) <%_ } _%> - fun findAllByIdNotNull(pageable: Pageable): Flux<<%= asEntity('User') %>> + fun findAllByIdNotNull(pageable: Pageable): Flux<<%= user.persistClass %>> <%_ if (databaseType === 'couchbase') { _%> @ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS) <%_ } _%> - fun findAllBy<% if (databaseType !== 'couchbase') { %>IdNotNullAnd<% } %>ActivatedIsTrue(pageable: Pageable): Flux<<%= asEntity('User') %>> + fun findAllBy<% if (databaseType !== 'couchbase') { %>IdNotNullAnd<% } %>ActivatedIsTrue(pageable: Pageable): Flux<<%= user.persistClass %>> <%_ if (databaseType === 'couchbase') { _%> @ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS) @@ -329,35 +329,35 @@ interface DeleteExtended { } <%_ } _%> -interface UserRepositoryInternal<% if (!authenticationTypeOauth2) { %> : DeleteExtended<<%= asEntity('User') %>><% } %> { +interface UserRepositoryInternal<% if (!authenticationTypeOauth2) { %> : DeleteExtended<<%= user.persistClass %>><% } %> { - fun findOneWithAuthoritiesByLogin(login: String): Mono<<%= asEntity('User') %>> + fun findOneWithAuthoritiesByLogin(login: String): Mono<<%= user.persistClass %>> <%_ if (!authenticationTypeOauth2) { _%> - fun findOneWithAuthoritiesByEmailIgnoreCase(email: String): Mono<<%= asEntity('User') %>> + fun findOneWithAuthoritiesByEmailIgnoreCase(email: String): Mono<<%= user.persistClass %>> <%_ } _%> <%_ if (authenticationTypeOauth2) { _%> - fun create(user: <%= asEntity('User') %>): Mono<<%= asEntity('User') %>> + fun create(user: <%= user.persistClass %>): Mono<<%= user.persistClass %>> <%_ } _%> - fun findAllWithAuthorities(pageable: Pageable): Flux<<%= asEntity('User') %>> + fun findAllWithAuthorities(pageable: Pageable): Flux<<%= user.persistClass %>> } class UserRepositoryInternalImpl(val db: DatabaseClient, val r2dbcEntityTemplate: R2dbcEntityTemplate, val r2dbcConverter: R2dbcConverter): UserRepositoryInternal { - override fun findOneWithAuthoritiesByLogin(login: String): Mono<<%= asEntity('User') %>> { + override fun findOneWithAuthoritiesByLogin(login: String): Mono<<%= user.persistClass %>> { return findOneWithAuthoritiesBy("login", login) } <%_ if (!authenticationTypeOauth2) { _%> - override fun findOneWithAuthoritiesByEmailIgnoreCase(email: String): Mono<<%= asEntity('User') %>> { + override fun findOneWithAuthoritiesByEmailIgnoreCase(email: String): Mono<<%= user.persistClass %>> { return findOneWithAuthoritiesBy("email", email.lowercase()) } <%_ } _%> - override fun findAllWithAuthorities(pageable: Pageable): Flux<<%= asEntity('User') %>> { + override fun findAllWithAuthorities(pageable: Pageable): Flux<<%= user.persistClass %>> { val property = pageable.sort.map(Sort.Order::getProperty).first() ?: "id" val direction = pageable.sort.map(Sort.Order::getDirection).first() ?: Sort.DEFAULT_DIRECTION val comparator = if (direction == Sort.DEFAULT_DIRECTION) { BeanComparator(property) } else { BeanComparator(property).reversed() } @@ -368,7 +368,7 @@ class UserRepositoryInternalImpl(val db: DatabaseClient, val r2dbcEntityTemplate .sql("SELECT * FROM <%= jhiTablePrefix %>_user u LEFT JOIN <%= jhiTablePrefix %>_user_authority ua ON u.id=ua.user_id") .map { row, metadata -> return@map Tuples.of( - r2dbcConverter.read(<%= asEntity('User') %>::class.java, row, metadata), + r2dbcConverter.read(<%= user.persistClass %>::class.java, row, metadata), Optional.ofNullable(row.get("authority_name", String::class.java)) ) }.all() @@ -380,30 +380,30 @@ class UserRepositoryInternalImpl(val db: DatabaseClient, val r2dbcEntityTemplate } <%_ if (!authenticationTypeOauth2) { _%> - override fun delete(user: <%= asEntity('User') %>): Mono { + override fun delete(user: <%= user.persistClass %>): Mono { return db.sql("DELETE FROM <%= jhiTablePrefix %>_user_authority WHERE user_id = :userId") .bind("userId", user.id) .then() - .then(r2dbcEntityTemplate.delete(<%= asEntity('User') %>::class.java) + .then(r2dbcEntityTemplate.delete(<%= user.persistClass %>::class.java) .matching(query(where("id").`is`(user.id))).all() .then() ) } <%_ } else { _%> - override fun create(user: <%= asEntity('User') %>): Mono<<%= asEntity('User') %>> { - return r2dbcEntityTemplate.insert(<%= asEntity('User') %>::class.java).using(user) + override fun create(user: <%= user.persistClass %>): Mono<<%= user.persistClass %>> { + return r2dbcEntityTemplate.insert(<%= user.persistClass %>::class.java).using(user) .defaultIfEmpty(user) } <%_ } _%> - private fun findOneWithAuthoritiesBy(fieldName: String, fieldValue: Any): Mono<<%= asEntity('User') %>> { + private fun findOneWithAuthoritiesBy(fieldName: String, fieldValue: Any): Mono<<%= user.persistClass %>> { return db.sql("SELECT * FROM <%= jhiTablePrefix %>_user u LEFT JOIN <%= jhiTablePrefix %>_user_authority ua ON u.id=ua.user_id WHERE u.$fieldName = :$fieldName") .bind(fieldName, fieldValue) .map { row, metadata -> return@map Tuples.of( - r2dbcConverter.read(<%= asEntity('User') %>::class.java, row, metadata), + r2dbcConverter.read(<%= user.persistClass %>::class.java, row, metadata), Optional.ofNullable(row.get("authority_name", String::class.java)) ) }.all() @@ -412,7 +412,7 @@ class UserRepositoryInternalImpl(val db: DatabaseClient, val r2dbcEntityTemplate .map { l -> updateUserWithAuthorities(l[0].t1, l) } } - private fun updateUserWithAuthorities(user: <%= asEntity('User') %>, tuples: List, Optional>>): <%= asEntity('User') %> { + private fun updateUserWithAuthorities(user: <%= user.persistClass %>, tuples: List, Optional>>): <%= user.persistClass %> { user.authorities = tuples.filter { it.t2.isPresent } .map { val authority = Authority() @@ -519,9 +519,9 @@ class UserRepository( private val truncateByEmailStmt = session.prepare("TRUNCATE user_by_email")<% if(reactive) { %>.block()<% } %> - fun findById(id: String): <%= optionalOrMono %><<%= asEntity('User') %>> { + fun findById(id: String): <%= optionalOrMono %><<%= user.persistClass %>> { <%_ if(reactive) { _%> - return cqlTemplate.selectOneById(id, <%= asEntity('User') %>::class.java) + return cqlTemplate.selectOneById(id, <%= user.persistClass %>::class.java) .map { user -> if(user.authorities == null) { user.authorities = mutableSetOf() @@ -533,35 +533,35 @@ class UserRepository( <%_ } _%> } - fun findOneByActivationKey(activationKey: String): <%= optionalOrMono %><<%= asEntity('User') %>> { + fun findOneByActivationKey(activationKey: String): <%= optionalOrMono %><<%= user.persistClass %>> { val stmt = findOneByActivationKeyStmt.bind().setString("activation_key", activationKey) return findOneFromIndex(stmt) } - fun findOneByResetKey(resetKey: String): <%= optionalOrMono %><<%= asEntity('User') %>> { + fun findOneByResetKey(resetKey: String): <%= optionalOrMono %><<%= user.persistClass %>> { val stmt = findOneByResetKeyStmt.bind().setString("reset_key", resetKey) return findOneFromIndex(stmt) } - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> @Cacheable(cacheNames = [USERS_BY_EMAIL_CACHE]) <%_ } _%> - fun findOneByEmailIgnoreCase(email: String?): <%= optionalOrMono %><<%= asEntity('User') %>> { + fun findOneByEmailIgnoreCase(email: String?): <%= optionalOrMono %><<%= user.persistClass %>> { val stmt = findOneByEmailStmt.bind().setString("email", email?.lowercase()) return findOneFromIndex(stmt) } - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> @Cacheable(cacheNames = [USERS_BY_LOGIN_CACHE]) <%_ } _%> - fun findOneByLogin(login: String): <%= optionalOrMono %><<%= asEntity('User') %>> { + fun findOneByLogin(login: String): <%= optionalOrMono %><<%= user.persistClass %>> { val stmt = findOneByLoginStmt.bind().setString("login", login) return findOneFromIndex(stmt) } - fun findAll(): <%= listOrFlux %><<%= asEntity('User') %>> { + fun findAll(): <%= listOrFlux %><<%= user.persistClass %>> { <%_ if(reactive) { _%> - return cqlTemplate.select(findAllStmt.bind(), <%= asEntity('User') %>::class.java) + return cqlTemplate.select(findAllStmt.bind(), <%= user.persistClass %>::class.java) .map { user -> if(user.authorities == null) { user.authorities = mutableSetOf() @@ -573,7 +573,7 @@ class UserRepository( <%_ } _%> } - fun save(user: <%= asEntity('User') %>): <% if(reactive) { %>Mono<<% } %><%= asEntity('User') %><% if(reactive) { %>><% } %> { + fun save(user: <%= user.persistClass %>): <% if(reactive) { %>Mono<<% } %><%= user.persistClass %><% if(reactive) { %>><% } %> { val violations = validator.validate(user) if (violations != null && violations.isNotEmpty()) { throw ConstraintViolationException(violations) @@ -620,7 +620,7 @@ class UserRepository( .thenReturn(user) } - private fun getInsertStatement(user: <%= asEntity('User') %>): SimpleStatement { + private fun getInsertStatement(user: <%= user.persistClass %>): SimpleStatement { val converter = cqlTemplate.getConverter() val persistentEntity = converter.getMappingContext().getRequiredPersistentEntity(user::class.java) val toInsert = mutableMapOf() @@ -672,7 +672,7 @@ class UserRepository( <%_ } _%> } - fun delete(user: <%= asEntity('User') %>)<% if(reactive) { %>: Mono<% } %> { + fun delete(user: <%= user.persistClass %>)<% if(reactive) { %>: Mono<% } %> { val batch = BatchStatement.builder(DefaultBatchType.LOGGED) batch.addStatement(<% if(reactive) { %>deleteByIdStmt.bind().setString("id", user.id)<% } else { %>userDao.deleteQuery(user)<% } %>) if (!StringUtils.isEmpty(user.activationKey)) { @@ -691,7 +691,7 @@ class UserRepository( } <%_ if(reactive) { _%> - private fun findOneFromIndex(stmt: BoundStatement): Mono<<%= asEntity('User') %>> { + private fun findOneFromIndex(stmt: BoundStatement): Mono<<%= user.persistClass %>> { return session.execute(stmt).flatMap { rs -> rs.rows().next() } .map { row -> row.getString("id") } .flatMap(this::findById) @@ -704,7 +704,7 @@ class UserRepository( .then() } <%_ } else { _%> - private fun findOneFromIndex(stmt: BoundStatement): Optional<<%= asEntity('User') %>> { + private fun findOneFromIndex(stmt: BoundStatement): Optional<<%= user.persistClass %>> { val rs = session.execute(stmt) return Optional.ofNullable(rs.one()) .map { it.getString("id") } @@ -726,7 +726,7 @@ class UserRepository( } <%_ } _%> -<%_ if (cacheManagerIsAvailable) { _%> +<%_ if (cacheProviderAny) { _%> companion object { const val USERS_BY_LOGIN_CACHE = "usersByLogin" diff --git a/generators/spring-boot/templates/src/main/kotlin/package/repository/rowmapper/EntityRowMapper.kt.ejs b/generators/spring-boot/templates/src/main/kotlin/package/repository/rowmapper/EntityRowMapper.kt.ejs index 6cc1aecbd..dec168920 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/repository/rowmapper/EntityRowMapper.kt.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/repository/rowmapper/EntityRowMapper.kt.ejs @@ -18,17 +18,17 @@ -%> package <%= entityAbsolutePackage %>.repository.rowmapper -<%_ if (fieldsContainBigDecimal) { _%> +<%_ if (anyFieldIsBigDecimal) { _%> import java.math.BigDecimal -<%_} if (fieldsContainInstant) { _%> +<%_} if (anyFieldIsInstant) { _%> import java.time.Instant -<%_ } if (fieldsContainLocalDate) { _%> +<%_ } if (anyFieldIsLocalDate) { _%> import java.time.LocalDate -<%_ } if (fieldsContainZonedDateTime) { _%> +<%_ } if (anyFieldIsZonedDateTime) { _%> import java.time.ZonedDateTime -<%_ } if (fieldsContainDuration) { _%> +<%_ } if (anyFieldIsDuration) { _%> import java.time.Duration -<%_ } if (fieldsContainUUID || otherEntityPrimaryKeyTypesIncludesUUID) { _%> +<%_ } if (anyFieldIsUUID || otherEntityPrimaryKeyTypesIncludesUUID) { _%> import java.util.UUID <%_ } _%> import java.util.function.BiFunction diff --git a/generators/spring-boot/templates/src/main/kotlin/package/repository/search/UserSearchRepository.kt.ejs b/generators/spring-boot/templates/src/main/kotlin/package/repository/search/UserSearchRepository.kt.ejs index 63930dd92..0d6e503ff 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/repository/search/UserSearchRepository.kt.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/repository/search/UserSearchRepository.kt.ejs @@ -18,7 +18,7 @@ -%> package <%= packageName %>.repository.search -import <%= packageName %>.domain.<%= asEntity('User') %> +import <%= packageName %>.domain.<%= user.persistClass %> <%_ if (reactive) { _%> import org.springframework.data.elasticsearch.core.ReactiveElasticsearchTemplate <%_ } else { _%> @@ -41,7 +41,7 @@ import org.elasticsearch.index.query.QueryBuilders.queryStringQuery /** * Spring Data Elasticsearch repository for the User entity. */ -interface UserSearchRepository : <% if (reactive) {%>Reactive<% } %>ElasticsearchRepository<<%= asEntity('User') %>, <% if (databaseTypeSql && !authenticationTypeOauth2) { %>Long<% } %><% if ((databaseTypeCassandra || databaseTypeMongodb || databaseTypeNeo4j) || authenticationTypeOauth2) { %>String<% } %>>, UserSearchRepositoryInternal +interface UserSearchRepository : <% if (reactive) {%>Reactive<% } %>ElasticsearchRepository<<%= user.persistClass %>, <% if (databaseTypeSql && !authenticationTypeOauth2) { %>Long<% } %><% if ((databaseTypeCassandra || databaseTypeMongodb || databaseTypeNeo4j) || authenticationTypeOauth2) { %>String<% } %>>, UserSearchRepositoryInternal <%_ if (reactive) { _%> interface UserSearchRepositoryInternal { diff --git a/generators/spring-boot/templates/src/main/kotlin/package/security/DomainUserDetailsService.kt.ejs b/generators/spring-boot/templates/src/main/kotlin/package/security/DomainUserDetailsService.kt.ejs index aa8318e0f..92cba2976 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/security/DomainUserDetailsService.kt.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/security/DomainUserDetailsService.kt.ejs @@ -18,7 +18,7 @@ -%> package <%= packageName %>.security -import <%= packageName %>.domain.<%= asEntity('User') %> +import <%= packageName %>.domain.<%= user.persistClass %> <%_ if (databaseTypeSql || databaseTypeMongodb || databaseTypeNeo4j) { _%> import <%= packageName %>.domain.Authority <%_ } _%> @@ -76,7 +76,7 @@ class DomainUserDetailsService(private val userRepository: UserRepository) : <% .orElseThrow { UsernameNotFoundException("User $lowercaseLogin was not found in the database") }<% } %> } - private fun createSpringSecurityUser(lowercaseLogin: String, user: <%= asEntity('User') %>) + private fun createSpringSecurityUser(lowercaseLogin: String, user: <%= user.persistClass %>) : org.springframework.security.core.userdetails.User { if (user.activated == null || user.activated == false) { throw UserNotActivatedException("User $lowercaseLogin was not activated") diff --git a/generators/spring-boot/templates/src/main/kotlin/package/service/EntityQueryService.kt.ejs b/generators/spring-boot/templates/src/main/kotlin/package/service/EntityQueryService.kt.ejs index 1eff77b80..e4e45ffda 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/service/EntityQueryService.kt.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/service/EntityQueryService.kt.ejs @@ -129,14 +129,14 @@ class <%= serviceClassName %>( specification = specification.and(distinct(distinctCriteria)); } if (criteria.<%= primaryKey.name %> != null) { - specification = specification.and(<%= getSpecificationBuilder(primaryKey.type) %>(criteria.<%= primaryKey.name %>, <%= persistClass %>_.<%= primaryKey.name %>)) + specification = specification.and(<%= primaryKey.javaBuildSpecification %>(criteria.<%= primaryKey.name %>, <%= persistClass %>_.<%= primaryKey.name %>)) } <%_ fields.forEach((field) => { if (field.id || field.transient) return; - if (isFilterableType(field.fieldType)) { _%> + if (field.filterableField) { _%> if (criteria.<%= field.fieldName %> != null) { - specification = specification.and(<%= getSpecificationBuilder(field.fieldType) %>(criteria.<%= field.fieldName %>, <%= persistClass %>_.<%= field.fieldName %>)) + specification = specification.and(<%= field.fieldJavaBuildSpecification %>(criteria.<%= field.fieldName %>, <%= persistClass %>_.<%= field.fieldName %>)) } <%_ } }); diff --git a/generators/spring-boot/templates/src/main/kotlin/package/service/MailService.kt.ejs b/generators/spring-boot/templates/src/main/kotlin/package/service/MailService.kt.ejs index 3d352cae9..392b515de 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/service/MailService.kt.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/service/MailService.kt.ejs @@ -18,7 +18,7 @@ -%> package <%= packageName %>.service -import <%= packageName %>.domain.<%= asEntity('User') %> +import <%= packageName %>.domain.<%= user.persistClass %> import tech.jhipster.config.JHipsterProperties @@ -79,7 +79,7 @@ class MailService( } @Async - fun sendEmailFromTemplate(user: <%= asEntity('User') %>, templateName: String, titleKey: String) { + fun sendEmailFromTemplate(user: <%= user.persistClass %>, templateName: String, titleKey: String) { if (user.email == null) { log.debug("Email doesn't exist for user '${user.login}'") return @@ -96,19 +96,19 @@ class MailService( <%_ if (!authenticationTypeOauth2) { _%> @Async - fun sendActivationEmail(user: <%= asEntity('User') %>) { + fun sendActivationEmail(user: <%= user.persistClass %>) { log.debug("Sending activation email to '${user.email}'") sendEmailFromTemplate(user, "mail/activationEmail", "email.activation.title") } @Async - fun sendCreationEmail(user: <%= asEntity('User') %>) { + fun sendCreationEmail(user: <%= user.persistClass %>) { log.debug("Sending creation email to '${user.email}'") sendEmailFromTemplate(user, "mail/creationEmail", "email.activation.title") } @Async - fun sendPasswordResetMail(user: <%= asEntity('User') %>) { + fun sendPasswordResetMail(user: <%= user.persistClass %>) { log.debug("Sending password reset email to '${user.email}'") sendEmailFromTemplate(user, "mail/passwordResetEmail", "email.reset.title") } diff --git a/generators/spring-boot/templates/src/main/kotlin/package/service/UserService.kt.ejs b/generators/spring-boot/templates/src/main/kotlin/package/service/UserService.kt.ejs index b86fbee2c..46d3ceff1 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/service/UserService.kt.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/service/UserService.kt.ejs @@ -24,8 +24,8 @@ import <%= packageName %>.config.SYSTEM_ACCOUNT import <%= packageName %>.domain.Authority <%_ } _%> <%_ if (!databaseTypeNo) { _%> -import <%= packageName %>.service.dto.<%= asDto('AdminUser') %> -import <%= packageName %>.domain.<%= asEntity('User') %> +import <%= packageName %>.service.dto.<%= user.adminUserDto %> +import <%= packageName %>.domain.<%= user.persistClass %> <%_ if (databaseTypeSql || databaseTypeMongodb || databaseTypeNeo4j || databaseTypeCouchbase) { _%> import <%= packageName %>.repository.AuthorityRepository <%_ if (authenticationTypeSession && !reactive) { _%> @@ -41,7 +41,7 @@ import <%= packageName %>.security.USER <%_ } _%> import <%= packageName %>.security.getCurrentUserLogin <%_ } _%> -import <%= packageName %>.service.dto.<%= asDto('User') %> +import <%= packageName %>.service.dto.<%= user.restClass %> <%_ if (!authenticationTypeOauth2) { _%> import tech.jhipster.security.RandomUtil <%_ } _%> @@ -49,7 +49,7 @@ import tech.jhipster.security.RandomUtil <%_ if (!databaseTypeNo) { _%> import org.slf4j.LoggerFactory <%_ } _%> -<%_ if (cacheManagerIsAvailable) { _%> +<%_ if (cacheProviderAny) { _%> import org.springframework.cache.CacheManager <%_ } _%> <%_ if (databaseTypeSql || databaseTypeMongodb || databaseTypeNeo4j || databaseTypeCouchbase) { _%> @@ -116,7 +116,7 @@ class UserService<% if (!databaseTypeNo) { %>( private val passwordEncoder: PasswordEncoder<%_ } if (searchEngineElasticsearch) { _%>, private val userSearchRepository: UserSearchRepository<%_ } if (databaseTypeSql || databaseTypeMongodb || databaseTypeNeo4j || databaseTypeCouchbase) { if (authenticationTypeSession && !reactive) { _%>, private val persistentTokenRepository: PersistentTokenRepository<%_ } _%>, - private val authorityRepository: AuthorityRepository<%_ } if (cacheManagerIsAvailable) { _%>, + private val authorityRepository: AuthorityRepository<%_ } if (cacheProviderAny) { _%>, private val cacheManager: CacheManager <%_ } _%> )<%_ } %> { @@ -128,7 +128,7 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (databaseTypeSql && reactive) { _%> @Transactional <%_ } _%> - fun activateRegistration(key: String): <% if (reactive) { %>Mono<% } else { %>Optional<% } %><<%= asEntity('User') %>> { + fun activateRegistration(key: String): <% if (reactive) { %>Mono<% } else { %>Optional<% } %><<%= user.persistClass %>> { log.debug("Activating user for activation key $key") return userRepository.findOneByActivationKey(key) .<% if (reactive) { %>flatMap<% } else { %>map<% } %> { user -> @@ -141,7 +141,7 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (searchEngineElasticsearch) { _%> .flatMap { userSearchRepository.save(it).thenReturn(it) } <%_ } _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> .doOnNext(this::clearUserCaches) <%_ } _%> .doOnNext { user -> log.debug("Activated user: $user") } @@ -152,7 +152,7 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (searchEngineElasticsearch) { _%> userSearchRepository.save(user) <%_ } _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> clearUserCaches(user) <%_ } _%> log.debug("Activated user: $user") @@ -164,7 +164,7 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (databaseTypeSql && reactive) { _%> @Transactional <%_ } _%> - fun completePasswordReset(newPassword: String, key: String): <% if (reactive) { %>Mono<% } else { %>Optional<% } %><<%= asEntity('User') %>> { + fun completePasswordReset(newPassword: String, key: String): <% if (reactive) { %>Mono<% } else { %>Optional<% } %><<%= user.persistClass %>> { log.debug("Reset user password for reset key $key") return userRepository.findOneByResetKey(key) .filter { user -> user.resetDate?.isAfter(Instant.now().minus(1, ChronoUnit.DAYS)) ?: false } @@ -176,7 +176,7 @@ class UserService<% if (!databaseTypeNo) { %>( it.resetDate = null it } - .flatMap(this::saveUser)<% if (cacheManagerIsAvailable) { %> + .flatMap(this::saveUser)<% if (cacheProviderAny) { %> .doOnNext(this::clearUserCaches)<% } %> <%_ } else { _%> .map { @@ -186,7 +186,7 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (databaseTypeMongodb || databaseTypeNeo4j || databaseTypeCouchbase || databaseTypeCassandra) { _%> userRepository.save(it) <%_ } _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> clearUserCaches(it) <%_ } _%> it @@ -197,7 +197,7 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (databaseTypeSql && reactive) { _%> @Transactional <%_ } _%> - fun requestPasswordReset(mail: String): <% if (reactive) { %>Mono<% } else { %>Optional<% } %><<%= asEntity('User') %>> { + fun requestPasswordReset(mail: String): <% if (reactive) { %>Mono<% } else { %>Optional<% } %><<%= user.persistClass %>> { return userRepository.findOneByEmailIgnoreCase(mail) <%_ if (reactive) { _%> .publishOn(Schedulers.boundedElastic()) @@ -206,7 +206,7 @@ class UserService<% if (!databaseTypeNo) { %>( it.resetDate = Instant.now() it } - .flatMap(this::saveUser)<% if (cacheManagerIsAvailable) { %> + .flatMap(this::saveUser)<% if (cacheProviderAny) { %> .doOnNext(this::clearUserCaches)<% } %> <%_ } else { _%> .filter { it.activated == true } @@ -216,7 +216,7 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (databaseTypeMongodb || databaseTypeNeo4j || databaseTypeCouchbase || databaseTypeCassandra) { _%> userRepository.save(it) <%_ } _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> clearUserCaches(it) <%_ } _%> it @@ -227,14 +227,14 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (databaseTypeSql && reactive) { _%> @Transactional <%_ } _%> - fun registerUser(userDTO: <%= asDto('AdminUser') %>, password: String): <% if (reactive) { %>Mono<<%= asEntity('User') %>><% } else { %><%= asEntity('User') %><% } %> { + fun registerUser(userDTO: <%= user.adminUserDto %>, password: String): <% if (reactive) { %>Mono<<%= user.persistClass %>><% } else { %><%= user.persistClass %><% } %> { val login = userDTO.login ?: throw IllegalArgumentException("Empty login not allowed") val email = userDTO.email <%_ if (reactive) { _%> return userRepository.findOneByLogin(login.lowercase()) .flatMap { existingUser -> if (existingUser.activated == false) { - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> clearUserCaches(existingUser) <%_ } _%> userRepository.delete(existingUser) @@ -245,7 +245,7 @@ class UserService<% if (!databaseTypeNo) { %>( .then(userRepository.findOneByEmailIgnoreCase(email!!)) .flatMap { existingUser -> if (existingUser.activated == false) { - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> clearUserCaches(existingUser) <%_ } _%> userRepository.delete(existingUser) @@ -255,7 +255,7 @@ class UserService<% if (!databaseTypeNo) { %>( } .publishOn(Schedulers.boundedElastic()) .then(Mono.fromCallable { - <%= asEntity('User') %>().apply { + <%= user.persistClass %>().apply { <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString() <%_ } _%> @@ -292,7 +292,7 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (searchEngineElasticsearch) { _%> .flatMap { user -> userSearchRepository.save(user).thenReturn(user) } <%_ } _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> .doOnNext(this::clearUserCaches) <%_ } _%> .doOnNext { user -> log.debug("Created Information for User: $user") } @@ -310,7 +310,7 @@ class UserService<% if (!databaseTypeNo) { %>( throw EmailAlreadyUsedException() } } - val newUser = <%= asEntity('User') %>() + val newUser = <%= user.persistClass %>() <%_ if (databaseTypeCassandra) { _%> newUser.id = UUID.randomUUID().toString() <%_ } _%> @@ -341,7 +341,7 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (searchEngineElasticsearch) { _%> userSearchRepository.save(newUser) <%_ } _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> clearUserCaches(newUser) <%_ } _%> log.debug("Created Information for User: $newUser") @@ -350,7 +350,7 @@ class UserService<% if (!databaseTypeNo) { %>( } <%_ if (!reactive) { _%> - private fun removeNonActivatedUser(existingUser: <%= asEntity('User') %>): Boolean { + private fun removeNonActivatedUser(existingUser: <%= user.persistClass %>): Boolean { if (existingUser.activated == true) { return false } @@ -358,7 +358,7 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (databaseTypeSql) { _%> userRepository.flush() <%_ } _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> clearUserCaches(existingUser) <%_ } _%> return true @@ -368,8 +368,8 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (databaseTypeSql && reactive) { _%> @Transactional <%_ } _%> - fun createUser(userDTO: <%= asDto('AdminUser') %>): <% if (reactive) { %>Mono<<%= asEntity('User') %>><% } else { %><%= asEntity('User') %><% } %> { - val user = <%= asEntity('User') %>( + fun createUser(userDTO: <%= user.adminUserDto %>): <% if (reactive) { %>Mono<<%= user.persistClass %>><% } else { %><%= user.persistClass %><% } %> { + val user = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> @@ -404,7 +404,7 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (searchEngineElasticsearch) { _%> .flatMap { userSearchRepository.save(it).thenReturn(it) } <%_ } _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> .doOnNext(this::clearUserCaches) <%_ } _%> .doOnNext { user -> log.debug("Changed Information for User: $user") } @@ -427,7 +427,7 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (searchEngineElasticsearch) { _%> userSearchRepository.save(user) <%_ } _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> clearUserCaches(user) <%_ } _%> log.debug("Created Information for User: $user") @@ -444,13 +444,13 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (databaseTypeSql && reactive) { _%> @Transactional <%_ } _%> - fun updateUser(userDTO: <%= asDto('AdminUser') %>): <% if (reactive) { %>Mono<% } else { %>Optional<% } %><<%= asDto('AdminUser') %>> { + fun updateUser(userDTO: <%= user.adminUserDto %>): <% if (reactive) { %>Mono<% } else { %>Optional<% } %><<%= user.adminUserDto %>> { <%_ if (reactive) { _%> return userRepository.findById(userDTO.id!!) .<%_ if (databaseTypeSql || databaseTypeMongodb || databaseTypeNeo4j) { _%>flatMap<% } else { %>map<% } %> { user -> <%_ } else { _%> return Optional.of(userRepository.findById(userDTO.id!!)) - .filter(Optional<<%= asEntity('User') %>>::isPresent) + .filter(Optional<<%= user.persistClass %>>::isPresent) .map { it.get() } .map { user -> <%_ } _%> @@ -459,7 +459,7 @@ class UserService<% if (!databaseTypeNo) { %>( userRepository.deleteById(userDTO.id!!) } <%_ } _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> clearUserCaches(user) <%_ } _%> user.apply { @@ -500,7 +500,7 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (searchEngineElasticsearch) { _%> .flatMap { userSearchRepository.save(it).thenReturn(it) } <%_ } _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> .doOnNext(this::clearUserCaches) <%_ } _%> .doOnNext { log.debug("Changed Information for User: $it") } @@ -520,14 +520,14 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (searchEngineElasticsearch) { _%> userSearchRepository.save(user) <%_ } _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> clearUserCaches(user) <%_ } _%> log.debug("Changed Information for User: $user") user } <%_ } _%> - .map { <%= asDto('AdminUser') %>(it) } + .map { <%= user.adminUserDto %>(it) } } <%_ if (reactive) { _%> @@ -540,7 +540,7 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (searchEngineElasticsearch) { _%> .flatMap { userSearchRepository.delete(it).thenReturn(it) } <%_ } _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> .doOnNext(this::clearUserCaches) <%_ } _%> .doOnNext { log.debug("Changed Information for User: $it") } @@ -553,7 +553,7 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (searchEngineElasticsearch) { _%> userSearchRepository.delete(user) <%_ } _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> clearUserCaches(user) <%_ } _%> log.debug("Deleted User: $user") @@ -597,7 +597,7 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (searchEngineElasticsearch) { _%> .flatMap { userSearchRepository.save(it).thenReturn(it) } <%_ } _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> .doOnNext(this::clearUserCaches) <%_ } _%> .doOnNext { log.debug("Changed Information for User: $it") } @@ -609,7 +609,7 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (searchEngineElasticsearch) { _%> userSearchRepository.save(it) <%_ } _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> clearUserCaches(it) <%_ } _%> log.debug("Changed Information for User: $it") @@ -620,13 +620,13 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (reactive) { _%> <%_ if (databaseTypeSql && authenticationTypeOauth2) { _%> @Transactional - fun saveUser(user: <%= asEntity('User') %>) = saveUser(user, false) + fun saveUser(user: <%= user.persistClass %>) = saveUser(user, false) <%_ } _%> <%_ if (databaseTypeSql) { _%> @Transactional <%_ } _%> - <% if (!databaseTypeSql) { %>private <% } %> fun saveUser(user: <%= asEntity('User') %><% if (databaseTypeSql && authenticationTypeOauth2) { %>, forceCreate: Boolean<% } %>): Mono<<%= asEntity('User') %>> { + <% if (!databaseTypeSql) { %>private <% } %> fun saveUser(user: <%= user.persistClass %><% if (databaseTypeSql && authenticationTypeOauth2) { %>, forceCreate: Boolean<% } %>): Mono<<%= user.persistClass %>> { <%_ if (databaseTypeCassandra) { _%> return userRepository.save(user) <%_ } else { _%> @@ -681,7 +681,7 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (reactive) { _%> user }.flatMap { saveUser(it) } - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> .doOnNext(this::clearUserCaches) <%_ } _%> .doOnNext { user -> log.debug("Changed password for User: $user") } @@ -690,7 +690,7 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (databaseTypeMongodb || databaseTypeNeo4j || databaseTypeCouchbase || databaseTypeCassandra) { _%> userRepository.save(user) <%_ } _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> clearUserCaches(user) <%_ } _%> log.debug("Changed password for User: $user") @@ -704,15 +704,15 @@ class UserService<% if (!databaseTypeNo) { %>( @Transactional(readOnly = true) <%_ } _%> <%_ if (databaseTypeSql || databaseTypeMongodb || databaseTypeNeo4j || databaseTypeCouchbase) { _%> - fun getAllManagedUsers(pageable: Pageable): <% if (reactive) { %>Flux<% } else { %>Page<% } %><<%= asDto('AdminUser') %>> { - return userRepository.findAll<% if (reactive) { %><% if (databaseTypeSql) { %>WithAuthorities<% } else { %>By<% if (!databaseTypeCouchbase) { %>IdNotNull<% }}} %>(pageable).map { <%= asDto('AdminUser') %>(it) } + fun getAllManagedUsers(pageable: Pageable): <% if (reactive) { %>Flux<% } else { %>Page<% } %><<%= user.adminUserDto %>> { + return userRepository.findAll<% if (reactive) { %><% if (databaseTypeSql) { %>WithAuthorities<% } else { %>By<% if (!databaseTypeCouchbase) { %>IdNotNull<% }}} %>(pageable).map { <%= user.adminUserDto %>(it) } } <%_ if (databaseTypeSql) { _%> @Transactional(readOnly = true) <%_ } _%> - fun getAllPublicUsers(pageable: Pageable): <% if (reactive) { %>Flux<% } else { %>Page<% } %><<%= asDto('User') %>> { - return userRepository.findAllBy<% if (!databaseTypeCouchbase) { %>IdNotNullAnd<% } %>ActivatedIsTrue(pageable).map { <%= asDto('User') %>(it) } + fun getAllPublicUsers(pageable: Pageable): <% if (reactive) { %>Flux<% } else { %>Page<% } %><<%= user.restClass %>> { + return userRepository.findAllBy<% if (!databaseTypeCouchbase) { %>IdNotNullAnd<% } %>ActivatedIsTrue(pageable).map { <%= user.restClass %>(it) } } <%_ if (reactive) { _%> @@ -723,24 +723,24 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ } _%> <%_ } else { /* Cassandra */ _%> - fun getAllManagedUsers() = userRepository.findAll().map { <%= asDto('AdminUser') %>(it) } + fun getAllManagedUsers() = userRepository.findAll().map { <%= user.adminUserDto %>(it) } fun getAllPublicUsers() = userRepository.findAll() .filter { it.activated == true } - .map { <%= asDto('User') %>(it) } + .map { <%= user.restClass %>(it) } <%_ } _%> <%_ if (databaseTypeSql) { _%> @Transactional(readOnly = true) <%_ } _%> - fun getUserWithAuthoritiesByLogin(login: String): <% if (reactive) { %>Mono<% } else { %>Optional<% } %><<%= asEntity('User') %>> = + fun getUserWithAuthoritiesByLogin(login: String): <% if (reactive) { %>Mono<% } else { %>Optional<% } %><<%= user.persistClass %>> = userRepository.<% if (databaseTypeSql) { %>findOneWithAuthoritiesByLogin(login)<% } else { %>findOneByLogin(login)<% } %> <%_ if (!authenticationTypeOauth2) { _%> <%_ if (databaseTypeSql) { _%> @Transactional(readOnly = true) <%_ } _%> - fun getUserWithAuthorities(): <% if (reactive) { %>Mono<% } else { %>Optional<% } %><<%= asEntity('User') %>> = + fun getUserWithAuthorities(): <% if (reactive) { %>Mono<% } else { %>Optional<% } %><<%= user.persistClass %>> = getCurrentUserLogin().flatMap(userRepository::findOne<% if (databaseTypeSql) { %>WithAuthorities<% } %>ByLogin) <%_ } _%> <%_ if ((databaseTypeSql || databaseTypeMongodb || databaseTypeNeo4j || databaseTypeCouchbase) && authenticationTypeSession && !reactive) { _%> @@ -784,7 +784,7 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (searchEngineElasticsearch) { _%> userSearchRepository.delete(user) <%_ } _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> clearUserCaches(user) <%_ } _%> } @@ -795,14 +795,14 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (databaseTypeSql) { _%> @Transactional <%_ } _%> - fun removeNotActivatedUsersReactively(): Flux<<%= asEntity('User') %>> { + fun removeNotActivatedUsersReactively(): Flux<<%= user.persistClass %>> { return userRepository .findAllByActivatedIsFalseAndActivationKeyIsNotNullAndCreatedDateBefore(<%_ if (databaseTypeSql) { _%>LocalDateTime.ofInstant(Instant.now().minus(3, ChronoUnit.DAYS), ZoneOffset.UTC)<%_ } else { _%>Instant.now().minus(3, ChronoUnit.DAYS)<%_ } _%>) .flatMap { user -> userRepository.delete(user).thenReturn(user) } <%_ if (searchEngineElasticsearch) { _%> .flatMap { user -> userSearchRepository.delete(user).thenReturn(user) } <%_ } _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> .doOnNext(this::clearUserCaches) <%_ } _%> .doOnNext { user -> log.debug("Deleted User: $user") } @@ -822,7 +822,7 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ } _%> <%_ if (authenticationTypeOauth2) { _%> - private fun syncUserWithIdP(details: Map, user: <%= asEntity('User') %>): <% if (reactive) { %>Mono<<%= asEntity('User') %>><% } else { %><%= asEntity('User') %><% } %> { + private fun syncUserWithIdP(details: Map, user: <%= user.persistClass %>): <% if (reactive) { %>Mono<<%= user.persistClass %>><% } else { %><%= user.persistClass %><% } %> { // save authorities in to sync user roles/groups between IdP and JHipster's local database <%_ if (reactive) { _%> val userAuthorities = user.authorities<% if (!databaseTypeCouchbase) { %>.map { it.name }<% } %>.toList() @@ -855,7 +855,7 @@ class UserService<% if (!databaseTypeNo) { %>( log.debug("Updating user '${user.login}' in local database") return@flatMap updateUser(user.firstName, user.lastName, user.email, user.langKey, user.imageUrl) } - return@flatMap Mono.empty<<%= asEntity('User') %>>() + return@flatMap Mono.empty<<%= user.persistClass %>>() } .thenReturn(user) <%_ } else { _%> @@ -891,7 +891,7 @@ class UserService<% if (!databaseTypeNo) { %>( } else { log.debug("Saving user '${user.login}' in local database") userRepository.save(user) - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> clearUserCaches(user) <%_ } _%> } @@ -914,7 +914,7 @@ class UserService<% if (!databaseTypeNo) { %>( <%_ if (databaseTypeSql) { _%> @Transactional <%_ } _%> - fun getUserFromAuthentication(authToken: AbstractAuthenticationToken): <% if (reactive) { %>Mono<<%= asDto('AdminUser') %>><% } else { %><%= asDto('AdminUser') %><% } %> { + fun getUserFromAuthentication(authToken: AbstractAuthenticationToken): <% if (reactive) { %>Mono<<%= user.adminUserDto %>><% } else { %><%= user.adminUserDto %><% } %> { val attributes: Map = when (authToken) { is OAuth2AuthenticationToken -> authToken.principal.attributes @@ -933,16 +933,16 @@ class UserService<% if (!databaseTypeNo) { %>( return <% if (reactive) { %>Mono.just(user)<% } else { %>user<% } %> <%_ } else { _%> <%_ if (reactive) { _%> - return syncUserWithIdP(attributes, user).flatMap{Mono.just(<%= asDto('AdminUser') %>(it))} + return syncUserWithIdP(attributes, user).flatMap{Mono.just(<%= user.adminUserDto %>(it))} <%_ } else { _%> - return <%= asDto('AdminUser') %>(syncUserWithIdP(attributes, user)) + return <%= user.adminUserDto %>(syncUserWithIdP(attributes, user)) <%_ } _%> <%_ } _%> } <%_ } _%> - <%_ if (cacheManagerIsAvailable && !databaseTypeNo) { _%> + <%_ if (cacheProviderAny && !databaseTypeNo) { _%> - private fun clearUserCaches(user: <%= asEntity('User') %>) { + private fun clearUserCaches(user: <%= user.persistClass %>) { user.login?.let{ cacheManager.getCache(UserRepository.USERS_BY_LOGIN_CACHE)?.evict(it) } @@ -956,11 +956,11 @@ class UserService<% if (!databaseTypeNo) { %>( companion object { @JvmStatic - private fun getUser(details: Map): <%= databaseTypeNo ? asDto('AdminUser') : asEntity('User') %> { + private fun getUser(details: Map): <%= databaseTypeNo ? user.adminUserDto : user.persistClass %> { var activated = true val sub = details["sub"] as String; val username = details["preferred_username"]?.let { it as String } ?: null - val user = <%= databaseTypeNo ? asDto('AdminUser') : asEntity('User') %>() + val user = <%= databaseTypeNo ? user.adminUserDto : user.persistClass %>() // handle resource server JWT, where sub claim is email and uid is ID if (details["uid"] != null) { user.id = details["uid"] as String diff --git a/generators/spring-boot/templates/src/main/kotlin/package/service/dto/AdminUserDTO.kt.ejs b/generators/spring-boot/templates/src/main/kotlin/package/service/dto/AdminUserDTO.kt.ejs index 351562880..d2ffb8e6b 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/service/dto/AdminUserDTO.kt.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/service/dto/AdminUserDTO.kt.ejs @@ -23,7 +23,7 @@ import <%= packageName %>.config.LOGIN_REGEX import <%= packageName %>.domain.Authority <%_ } _%> <%_ if (!databaseTypeNo) { _%> -import <%= packageName %>.domain.<%= asEntity('User') %> +import <%= packageName %>.domain.<%= user.persistClass %> <%_ } _%> import java.io.Serializable @@ -38,7 +38,7 @@ import java.util.UUID /** * A DTO representing a user, with his authorities. */ -open class <%= asDto('AdminUser') %>( +open class <%= user.adminUserDto %>( var id: <%= user.primaryKey.type %>? = null, @field:NotBlank @@ -80,7 +80,7 @@ open class <%= asDto('AdminUser') %>( ): Serializable { <%_ if (!databaseTypeNo) { _%> - constructor(user: <%= asEntity('User') %>?) : this( + constructor(user: <%= user.persistClass %>?) : this( user?.id, user?.login, user?.firstName, @@ -103,7 +103,7 @@ open class <%= asDto('AdminUser') %>( <%_ } _%> override fun toString(): String { - return "<%= asDto('AdminUser') %>{" + + return "<%= user.adminUserDto %>{" + "login='" + login + '\'' + ", firstName='" + firstName + '\'' + ", lastName='" + lastName + '\'' + diff --git a/generators/spring-boot/templates/src/main/kotlin/package/service/dto/EntityDTO.kt.ejs b/generators/spring-boot/templates/src/main/kotlin/package/service/dto/EntityDTO.kt.ejs index 5c12af049..d1f663606 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/service/dto/EntityDTO.kt.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/service/dto/EntityDTO.kt.ejs @@ -22,32 +22,32 @@ import java.util.Objects <%_ if (typeof javadoc !== 'undefined' || importApiModelProperty) { _%> import io.swagger.v3.oas.annotations.media.Schema <%_ } _%> -<%_ if (fieldsContainInstant) { _%> +<%_ if (anyFieldIsInstant) { _%> import java.time.Instant <%_ } _%> -<%_ if (fieldsContainLocalDate) { _%> +<%_ if (anyFieldIsLocalDate) { _%> import java.time.LocalDate <%_ } _%> -<%_ if (fieldsContainZonedDateTime) { _%> +<%_ if (anyFieldIsZonedDateTime) { _%> import java.time.ZonedDateTime <%_ } _%> -<%_ if (fieldsContainDuration) { _%> +<%_ if (anyFieldIsDuration) { _%> import java.time.Duration <%_ } _%> -<%_ if (validation) { _%> +<%_ if (anyPropertyHasValidation) { _%> import javax.validation.constraints.* <%_ } _%> import java.io.Serializable -<%_ if (fieldsContainBigDecimal) { _%> +<%_ if (anyFieldIsBigDecimal) { _%> import java.math.BigDecimal <%_ } _%> -<%_ if (fieldsContainBlob && databaseTypeCassandra) { _%> +<%_ if (anyFieldIsBlobDerived && databaseTypeCassandra) { _%> import java.nio.ByteBuffer <%_ } _%> -<%_ if (fieldsContainUUID) { _%> +<%_ if (anyFieldIsUUID) { _%> import java.util.UUID <%_ } _%> -<%_ if (fieldsContainBlob && databaseTypeSql) { _%> +<%_ if (anyFieldIsBlobDerived && databaseTypeSql) { _%> import javax.persistence.Lob <%_ } _%> <%_ Object.keys(uniqueEnums).forEach(function(element) { _%> diff --git a/generators/spring-boot/templates/src/main/kotlin/package/service/dto/UserDTO.kt.ejs b/generators/spring-boot/templates/src/main/kotlin/package/service/dto/UserDTO.kt.ejs index d68dd6d1e..117c29a4a 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/service/dto/UserDTO.kt.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/service/dto/UserDTO.kt.ejs @@ -19,7 +19,7 @@ package <%= packageName %>.service.dto <%_ if (!databaseTypeNo) { _%> -import <%= packageName %>.domain.<%= asEntity('User') %> +import <%= packageName %>.domain.<%= user.persistClass %> <%_ } _%> import java.io.Serializable @@ -29,7 +29,7 @@ import java.util.UUID /** * A DTO representing a user, with only the public attributes. */ -open class <%= asDto('User') %>( +open class <%= user.restClass %>( var id: <%= user.primaryKey.type %>? = null, var login: String? = null, <%_ for (field of user.fields.filter(field => !field.builtIn && field.relatedByOtherEntity)) { _%> @@ -38,10 +38,10 @@ open class <%= asDto('User') %>( ): Serializable{ <%_ if (!databaseTypeNo) { _%> - constructor(user: <%= asEntity('User') %>): this(user.id, user.login) + constructor(user: <%= user.persistClass %>): this(user.id, user.login) <%_ } _%> - override fun toString() = "<%= asDto('User') %>{" + + override fun toString() = "<%= user.restClass %>{" + "login='" + login + '\'' + <%_ for (field of user.fields.filter(field => !field.builtIn && field.relatedByOtherEntity)) { _%> ", <%= field.fieldName %>='" + <%= field.fieldName %> + '\'' + diff --git a/generators/spring-boot/templates/src/main/kotlin/package/service/mapper/UserMapper.kt.ejs b/generators/spring-boot/templates/src/main/kotlin/package/service/mapper/UserMapper.kt.ejs index 090ddefd3..a2e64bdd2 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/service/mapper/UserMapper.kt.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/service/mapper/UserMapper.kt.ejs @@ -21,9 +21,9 @@ package <%= packageName %>.service.mapper <%_ if (databaseTypeSql || databaseTypeMongodb || databaseTypeNeo4j) { _%> import <%= packageName %>.domain.Authority <%_ } _%> -import <%= packageName %>.domain.<%= asEntity('User') %> -import <%= packageName %>.service.dto.<%= asDto('AdminUser') %> -import <%= packageName %>.service.dto.<%= asDto('User') %> +import <%= packageName %>.domain.<%= user.persistClass %> +import <%= packageName %>.service.dto.<%= user.adminUserDto %> +import <%= packageName %>.service.dto.<%= user.restClass %> import org.springframework.stereotype.Service @@ -33,7 +33,7 @@ import org.mapstruct.Mapping import org.mapstruct.Named /** - * Mapper for the entity [<%= asEntity('User') %>] and its DTO called [<%= asDto('User') %>]. + * Mapper for the entity [<%= user.persistClass %>] and its DTO called [<%= user.restClass %>]. * * Normal mappers are generated using MapStruct, this one is hand-coded as MapStruct * support is still in beta, and requires a manual step with an IDE. @@ -41,29 +41,29 @@ import org.mapstruct.Named @Service class UserMapper { - fun usersToUserDTOs(users: List<<%= asEntity('User') %>?>): MutableList<<%= asDto('User') %>> = + fun usersToUserDTOs(users: List<<%= user.persistClass %>?>): MutableList<<%= user.restClass %>> = users.asSequence() .filterNotNull() .mapTo(mutableListOf()) { userToUserDTO(it) } - fun userToUserDTO(user: <%= asEntity('User') %>): <%= asDto('User') %> = <%= asDto('User') %>(user) + fun userToUserDTO(user: <%= user.persistClass %>): <%= user.restClass %> = <%= user.restClass %>(user) - fun usersToAdminUserDTOs(users: List<<%= asEntity('User') %>>): MutableList<<%= asDto('AdminUser') %>> = + fun usersToAdminUserDTOs(users: List<<%= user.persistClass %>>): MutableList<<%= user.adminUserDto %>> = users.asSequence() .filterNotNull() .mapTo(mutableListOf()) { userToAdminUserDTO(it) } - fun userToAdminUserDTO(user: <%= asEntity('User') %>) = <%= asDto('AdminUser') %>(user) + fun userToAdminUserDTO(user: <%= user.persistClass %>) = <%= user.adminUserDto %>(user) - fun userDTOsToUsers(userDTOs: List<<%= asDto('AdminUser') %>?>) = + fun userDTOsToUsers(userDTOs: List<<%= user.adminUserDto %>?>) = userDTOs.asSequence() .mapNotNullTo(mutableListOf()) { userDTOToUser(it) } - fun userDTOToUser(userDTO: <%= asDto('AdminUser') %>?) = + fun userDTOToUser(userDTO: <%= user.adminUserDto %>?) = when (userDTO) { null -> null else -> { - <%= asEntity('User') %>( + <%= user.persistClass %>( id = userDTO.id, login = userDTO.login, firstName = userDTO.firstName, @@ -94,16 +94,16 @@ class UserMapper { authoritiesAsString?.filterNotNullTo(mutableSetOf()) ?: mutableSetOf() <%_ } _%> - fun userFromId(id: <%= user.primaryKey.type %>?) = id?.let { <%= asEntity('User') %>(id = it) } + fun userFromId(id: <%= user.primaryKey.type %>?) = id?.let { <%= user.persistClass %>(id = it) } @Named("id") @BeanMapping(ignoreByDefault = true) @Mapping(target = "id", source = "id") - fun toDtoId(user: <%= asEntity('User') %>?): <%= asDto('User') %>? { + fun toDtoId(user: <%= user.persistClass %>?): <%= user.restClass %>? { if (user == null) { return null } - val userDto = <%= asDto('User') %>() + val userDto = <%= user.restClass %>() userDto.id = user.id return userDto } @@ -111,12 +111,12 @@ class UserMapper { @Named("idSet") @BeanMapping(ignoreByDefault = true) @Mapping(target = "id", source = "id") - fun toDtoIdSet(users: Set<<%= asEntity('User') %>>?): Set<<%= asDto('User') %>>? { + fun toDtoIdSet(users: Set<<%= user.persistClass %>>?): Set<<%= user.restClass %>>? { if ( users == null ) { - return emptySet<<%= asDto('User') %>>() + return emptySet<<%= user.restClass %>>() } - val userSet = hashSetOf<<%= asDto('User') %>>() + val userSet = hashSetOf<<%= user.restClass %>>() users.forEach { this.toDtoId(it)?.let { userSet.add(it) @@ -131,11 +131,11 @@ class UserMapper { Mapping(target = "id", source = "id"), Mapping(target = "login", source = "login") ) - fun toDtoLogin(user: <%= asEntity('User') %>?): <%= asDto('User') %>? { + fun toDtoLogin(user: <%= user.persistClass %>?): <%= user.restClass %>? { if (user == null) { return null } - val userDto = <%= asDto('User') %>() + val userDto = <%= user.restClass %>() userDto.id = user.id userDto.login = user.login return userDto @@ -147,12 +147,12 @@ class UserMapper { Mapping(target = "id", source = "id"), Mapping(target = "login", source = "login") ) - fun toDtoLoginSet(users: Set<<%= asEntity('User') %>>?): Set<<%= asDto('User') %>>? { + fun toDtoLoginSet(users: Set<<%= user.persistClass %>>?): Set<<%= user.restClass %>>? { if ( users == null ) { - return emptySet<<%= asDto('User') %>>() + return emptySet<<%= user.restClass %>>() } - val userSet = hashSetOf<<%= asDto('User') %>>() + val userSet = hashSetOf<<%= user.restClass %>>() users.forEach { this.toDtoLogin(it)?.let { userSet.add(it) diff --git a/generators/spring-boot/templates/src/main/kotlin/package/web/rest/AccountResource.kt.ejs b/generators/spring-boot/templates/src/main/kotlin/package/web/rest/AccountResource.kt.ejs index 355585ca3..793cadd2a 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/web/rest/AccountResource.kt.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/web/rest/AccountResource.kt.ejs @@ -23,7 +23,7 @@ package <%= packageName %>.web.rest import <%= packageName %>.security.getCurrentUserLogin <%_ } _%> import <%= packageName %>.service.UserService -import <%= packageName %>.service.dto.<%= asDto('AdminUser') %> +import <%= packageName %>.service.dto.<%= user.adminUserDto %> import org.slf4j.LoggerFactory import org.springframework.security.authentication.AbstractAuthenticationToken @@ -58,7 +58,7 @@ class AccountResource(private val userService: UserService) { * @throws AccountResourceException `500 (Internal Server Error)` if the user couldn't be returned. */ @GetMapping("/account") - fun getAccount(principal: Principal?): <% if (reactive) { %>Mono<<%= asDto('AdminUser') %>><% } else { %><%= asDto('AdminUser') %><% } %> = + fun getAccount(principal: Principal?): <% if (reactive) { %>Mono<<%= user.adminUserDto %>><% } else { %><%= user.adminUserDto %><% } %> = if (principal is AbstractAuthenticationToken) { userService.getUserFromAuthentication(principal) } else { @@ -189,7 +189,7 @@ import <%= packageName %>.security.getCurrentUserLogin import <%= packageName %>.service.MailService import <%= packageName %>.service.UserService import <%= packageName %>.service.dto.PasswordChangeDTO -import <%= packageName %>.service.dto.<%= asDto('AdminUser') %> +import <%= packageName %>.service.dto.<%= user.adminUserDto %> import <%= packageName %>.web.rest.errors.EmailAlreadyUsedException import <%= packageName %>.web.rest.errors.InvalidPasswordException import <%= packageName %>.web.rest.errors.LoginAlreadyUsedException @@ -314,9 +314,9 @@ class AccountResource( * @throws RuntimeException `500 (Internal Server Error)` if the user couldn't be returned. */ @GetMapping("/account") - fun getAccount(): <% if (reactive) { %>Mono<<%= asDto('AdminUser') %>><% } else { %><%= asDto('AdminUser') %><% } %> = + fun getAccount(): <% if (reactive) { %>Mono<<%= user.adminUserDto %>><% } else { %><%= user.adminUserDto %><% } %> = userService.getUserWithAuthorities() - .map { <%= asDto('AdminUser') %>(it) } + .map { <%= user.adminUserDto %>(it) } <%_ if (reactive) { _%> .switchIfEmpty(Mono.error(AccountResourceException("User could not be found"))) <%_ } else { _%> @@ -332,7 +332,7 @@ class AccountResource( */ @PostMapping("/account") <%_ if (reactive) { _%> - fun saveAccount(@Valid @RequestBody userDTO: <%= asDto('AdminUser') %>): Mono = + fun saveAccount(@Valid @RequestBody userDTO: <%= user.adminUserDto %>): Mono = getCurrentUserLogin() .switchIfEmpty(Mono.error(AccountResourceException("Current user login not found"))) .flatMap { userLogin -> @@ -353,7 +353,7 @@ class AccountResource( ) } <%_ } else { _%> - fun saveAccount(@Valid @RequestBody userDTO: <%= asDto('AdminUser') %>) { + fun saveAccount(@Valid @RequestBody userDTO: <%= user.adminUserDto %>) { val userLogin = getCurrentUserLogin() .orElseThrow { AccountResourceException("") } val existingUser = userRepository.findOneByEmailIgnoreCase(userDTO.email) diff --git a/generators/spring-boot/templates/src/main/kotlin/package/web/rest/EntityResource.kt.ejs b/generators/spring-boot/templates/src/main/kotlin/package/web/rest/EntityResource.kt.ejs index 36ae494fb..fbeab38eb 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/web/rest/EntityResource.kt.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/web/rest/EntityResource.kt.ejs @@ -88,7 +88,7 @@ import reactor.core.publisher.Flux import reactor.core.publisher.Mono <%_ } _%> -<%_ if (validation) { _%> +<%_ if (anyPropertyHasValidation) { _%> import javax.validation.Valid import javax.validation.constraints.NotNull <%_ } _%> @@ -157,7 +157,7 @@ _%><%- include('../../common/inject_template', {viaService: viaService, construc * @throws URISyntaxException if the Location URI syntax is incorrect. */ @PostMapping("/<%= entityApiUrl %>") - fun create<%= entityClass %>(<% if (validation) { %>@Valid <% } %>@RequestBody <%= instanceName %>: <%= instanceType %>): <% if (reactive) { %>Mono<<% } %>ResponseEntity<<%= instanceType %>><% if (reactive) { %>><% } %> { + fun create<%= entityClass %>(<% if (anyPropertyHasValidation) { %>@Valid <% } %>@RequestBody <%= instanceName %>: <%= instanceType %>): <% if (reactive) { %>Mono<<% } %>ResponseEntity<<%= instanceType %>><% if (reactive) { %>><% } %> { log.debug("REST request to save <%= entityClass %> : $<%= instanceName %>") if (<%= instanceName %>.<%= primaryKey.name %> != null) { throw BadRequestAlertException( @@ -216,7 +216,7 @@ _%><%- include('../../common/inject_template', {viaService: viaService, construc @PutMapping("/<%= entityApiUrl %>/{<%= primaryKey.name %>}") fun update<%= entityClass %>( @PathVariable(value = "<%= primaryKey.name %>", required = false) <%= primaryKey.name %>: <%= primaryKey.type %>, - <% if (validation) { %>@Valid <% } %>@RequestBody <%= instanceName %>: <%= instanceType %> + <% if (anyPropertyHasValidation) { %>@Valid <% } %>@RequestBody <%= instanceName %>: <%= instanceType %> ): <% if (reactive) { %>Mono<<% } %>ResponseEntity<<%= instanceType %>><% if (reactive) { %>><% } %> { log.debug("REST request to update <%= entityClass %> : {}, {}", <%= primaryKey.name %>, <%= instanceName %>) if (<%= instanceName %>.<%= primaryKey.name %> == null) { @@ -289,7 +289,7 @@ _%><%- include('../../common/inject_template', {viaService: viaService, construc @Throws(URISyntaxException::class) fun partialUpdate<%= entityClass %>( @PathVariable(value = "<%= primaryKey.name %>", required = false) <%= primaryKey.name %>: <%= primaryKey.type %>, - <% if (validation) { %>@NotNull <% } %>@RequestBody <%= instanceName %>:<%= instanceType %> + <% if (anyPropertyHasValidation) { %>@NotNull <% } %>@RequestBody <%= instanceName %>:<%= instanceType %> ): <% if (reactive) { %>Mono<<% } %>ResponseEntity<<%= instanceType %>><% if (reactive) { %>><% } %> { log.debug("REST request to partial update <%= entityClass %> partially : {}, {}", <%= primaryKey.name %>, <%= instanceName %>) if (<%= instanceName %>.<%= primaryKey.name %> == null) { diff --git a/generators/spring-boot/templates/src/main/kotlin/package/web/rest/PublicUserResource.kt.ejs b/generators/spring-boot/templates/src/main/kotlin/package/web/rest/PublicUserResource.kt.ejs index 24c5c3930..0f331791b 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/web/rest/PublicUserResource.kt.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/web/rest/PublicUserResource.kt.ejs @@ -33,7 +33,7 @@ import org.springframework.data.domain.Sort import java.util.Collections <%_ } _%> import <%= packageName %>.service.UserService -import <%= packageName %>.service.dto.<%= asDto('User') %> +import <%= packageName %>.service.dto.<%= user.restClass %> <%_ if (databaseTypeSql || databaseTypeMongodb || databaseTypeNeo4j || databaseTypeCouchbase) { _%> import tech.jhipster.web.util.PaginationUtil @@ -112,7 +112,7 @@ class PublicUserResource( @GetMapping("/users") <%_ if (databaseTypeSql || databaseTypeMongodb || databaseTypeNeo4j || databaseTypeCouchbase) { _%> <%_ if (reactive) { _%> - fun getAllPublicUsers(request: ServerHttpRequest, @org.springdoc.api.annotations.ParameterObject pageable: Pageable): Mono>>> { + fun getAllPublicUsers(request: ServerHttpRequest, @org.springdoc.api.annotations.ParameterObject pageable: Pageable): Mono>>> { log.debug("REST request to get all public User names") <%_ if (!authenticationTypeOauth2) { _%> if (!onlyContainsAllowedProperties(pageable)) { @@ -121,12 +121,12 @@ class PublicUserResource( <%_ } _%> return userService.countManagedUsers() - .map { PageImpl<<%= asDto('User') %>>(listOf(), pageable, it) } + .map { PageImpl<<%= user.restClass %>>(listOf(), pageable, it) } .map { PaginationUtil.generatePaginationHttpHeaders(UriComponentsBuilder.fromHttpRequest(request), it) } .map { ResponseEntity.ok().headers(it).body(userService.getAllPublicUsers(pageable)) } } <%_ } else { _%> - fun getAllPublicUsers(@org.springdoc.api.annotations.ParameterObject pageable: Pageable): ResponseEntity>> { + fun getAllPublicUsers(@org.springdoc.api.annotations.ParameterObject pageable: Pageable): ResponseEntity>> { log.debug("REST request to get all public User names") <%_ if (!authenticationTypeOauth2) { _%> if (!onlyContainsAllowedProperties(pageable)) { @@ -152,7 +152,7 @@ class PublicUserResource( fun getAuthorities() = userService.getAuthorities()<% if (reactive) { %>.collectList()<% } %> <%_ } else { /* Cassandra */ _%> - fun getAllPublicUsers(): <% if (reactive) { %>Flux<% } else { %>List<% } %><<%= asDto('User') %>> = userService.getAllPublicUsers() + fun getAllPublicUsers(): <% if (reactive) { %>Flux<% } else { %>List<% } %><<%= user.restClass %>> = userService.getAllPublicUsers() <%_ } _%> @@ -165,20 +165,20 @@ class PublicUserResource( * @return the result of the search. */ @GetMapping("/_search/users/{query}") - fun search(@PathVariable query: String): <% if(reactive) { %>MonoList<<%= asDto('User') %>><% if(reactive) { %>><% } %> { + fun search(@PathVariable query: String): <% if(reactive) { %>MonoList<<%= user.restClass %>><% if(reactive) { %>><% } %> { <%/* TODO fix this */%> <%_ if (searchEngineElasticsearch) { _%> <%_ if (reactive) { _%> - return userSearchRepository.search(query).map { <%= asDto('User') %>(it) }.collectList() + return userSearchRepository.search(query).map { <%= user.restClass %>(it) }.collectList() <%_ } else { _%> - return userSearchRepository.search(query).map { <%= asDto('User') %>(it) } + return userSearchRepository.search(query).map { <%= user.restClass %>(it) } <%_ } _%> <%_ } else { _%> <%_ if (reactive) { _%> - return userRepository.search(query).map { <%= asDto('User') %>(it) }.collectList() + return userRepository.search(query).map { <%= user.restClass %>(it) }.collectList() <%_ } else { _%> return userRepository.search(query) - .map { <%= asDto('User') %>(it) } + .map { <%= user.restClass %>(it) } <%_ } _%> <%_ } _%> } diff --git a/generators/spring-boot/templates/src/main/kotlin/package/web/rest/UserResource.kt.ejs b/generators/spring-boot/templates/src/main/kotlin/package/web/rest/UserResource.kt.ejs index 3d56fce6a..480574911 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/web/rest/UserResource.kt.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/web/rest/UserResource.kt.ejs @@ -19,13 +19,13 @@ package <%= packageName %>.web.rest import <%= packageName %>.config.LOGIN_REGEX -import <%= packageName %>.domain.<%= asEntity('User') %> +import <%= packageName %>.domain.<%= user.persistClass %> import <%= packageName %>.repository.UserRepository import <%= packageName %>.security.ADMIN import <%= packageName %>.service.MailService import org.springframework.data.domain.Sort import <%= packageName %>.service.UserService -import <%= packageName %>.service.dto.<%= asDto('AdminUser') %> +import <%= packageName %>.service.dto.<%= user.adminUserDto %> import <%= packageName %>.web.rest.errors.BadRequestAlertException import <%= packageName %>.web.rest.errors.EmailAlreadyUsedException import <%= packageName %>.web.rest.errors.LoginAlreadyUsedException @@ -142,7 +142,7 @@ class UserResource( <%_ if (!reactive) { _%> @Throws(URISyntaxException::class) <%_ } _%> - fun createUser(@Valid @RequestBody userDTO: <%= asDto('AdminUser') %>): <% if (reactive) { %>Mono>><% } else { %>ResponseEntity<<%= asEntity('User') %>><% } %> { + fun createUser(@Valid @RequestBody userDTO: <%= user.adminUserDto %>): <% if (reactive) { %>Mono>><% } else { %>ResponseEntity<<%= user.persistClass %>><% } %> { log.debug("REST request to save User : $userDTO") if (userDTO.id != null) { @@ -201,7 +201,7 @@ class UserResource( @PutMapping("/users") @PreAuthorize("hasAuthority(\"$ADMIN\")") <%_ if (reactive) { _%> - fun updateUser(@Valid @RequestBody userDTO: <%= asDto('AdminUser') %>) : Mono>> { + fun updateUser(@Valid @RequestBody userDTO: <%= user.adminUserDto %>) : Mono>> { log.debug("REST request to update User : $userDTO") return userRepository.findOneByEmailIgnoreCase(userDTO.email!!) .filter { user -> user.id != userDTO.id } @@ -227,7 +227,7 @@ class UserResource( .body(user) } <%_ } else { _%> - fun updateUser(@Valid @RequestBody userDTO: <%= asDto('AdminUser') %>): ResponseEntity<<%= asDto('AdminUser') %>> { + fun updateUser(@Valid @RequestBody userDTO: <%= user.adminUserDto %>): ResponseEntity<<%= user.adminUserDto %>> { log.debug("REST request to update User : $userDTO") var existingUser = userRepository.findOneByEmailIgnoreCase(userDTO.email) if (existingUser.isPresent && existingUser.get().id != userDTO.id) { @@ -262,19 +262,19 @@ class UserResource( fun getAllUsers( request: ServerHttpRequest, @org.springdoc.api.annotations.ParameterObject pageable: Pageable - ): Mono>>> { + ): Mono>>> { log.debug("REST request to get all User for an admin") if (!onlyContainsAllowedProperties(pageable)) { return Mono.just(ResponseEntity.badRequest().build()) } return userService.countManagedUsers() - .map { total -> PageImpl(mutableListOf<<%= asDto('AdminUser') %>>(), pageable, total!!) } + .map { total -> PageImpl(mutableListOf<<%= user.adminUserDto %>>(), pageable, total!!) } .map { page -> PaginationUtil.generatePaginationHttpHeaders(UriComponentsBuilder.fromHttpRequest(request), page) } .map { headers -> ResponseEntity.ok().headers(headers).body(userService.getAllManagedUsers(pageable)) } } <%_ } else { _%> - fun getAllUsers(@org.springdoc.api.annotations.ParameterObject pageable: Pageable): ResponseEntity>> { + fun getAllUsers(@org.springdoc.api.annotations.ParameterObject pageable: Pageable): ResponseEntity>> { log.debug("REST request to get all User for an admin") if (!onlyContainsAllowedProperties(pageable)) { return ResponseEntity.badRequest().build() @@ -300,17 +300,17 @@ class UserResource( @GetMapping("/users/{login}") @PreAuthorize("hasAuthority(\"$ADMIN\")") <%_ if (reactive) { _%> - fun getUser(@PathVariable login: String): Mono<<%= asDto('AdminUser') %>> { + fun getUser(@PathVariable login: String): Mono<<%= user.adminUserDto %>> { log.debug("REST request to get User : $login") return userService.getUserWithAuthoritiesByLogin(login) - .map { <%= asDto('AdminUser') %>(it) } + .map { <%= user.adminUserDto %>(it) } .switchIfEmpty(Mono.error(ResponseStatusException(HttpStatus.NOT_FOUND))) <%_ } else { _%> - fun getUser(@PathVariable @Pattern(regexp = LOGIN_REGEX) login: String): ResponseEntity<<%= asDto('AdminUser') %>> { + fun getUser(@PathVariable @Pattern(regexp = LOGIN_REGEX) login: String): ResponseEntity<<%= user.adminUserDto %>> { log.debug("REST request to get User : $login") return ResponseUtil.wrapOrNotFound( userService.getUserWithAuthoritiesByLogin(login) - .map { <%= asDto('AdminUser') %>(it) }) + .map { <%= user.adminUserDto %>(it) }) <%_ } _%> } diff --git a/generators/spring-boot/templates/src/main/kotlin/package/web/rest/vm/ManagedUserVM.kt.ejs b/generators/spring-boot/templates/src/main/kotlin/package/web/rest/vm/ManagedUserVM.kt.ejs index 272a7abc0..c638823e5 100644 --- a/generators/spring-boot/templates/src/main/kotlin/package/web/rest/vm/ManagedUserVM.kt.ejs +++ b/generators/spring-boot/templates/src/main/kotlin/package/web/rest/vm/ManagedUserVM.kt.ejs @@ -18,15 +18,15 @@ -%> package <%= packageName %>.web.rest.vm -import <%= packageName %>.service.dto.<%= asDto('AdminUser') %> +import <%= packageName %>.service.dto.<%= user.adminUserDto %> <%_ if (!authenticationTypeOauth2) { _%> import javax.validation.constraints.Size <%_ } _%> /** - * View Model extending the [<%= asDto('AdminUser') %>], which is meant to be used in the user management UI. + * View Model extending the [<%= user.adminUserDto %>], which is meant to be used in the user management UI. */ -class ManagedUserVM : <%= asDto('AdminUser') %>() { +class ManagedUserVM : <%= user.adminUserDto %>() { <%_ if (!authenticationTypeOauth2) { _%> @field:Size(min = PASSWORD_MIN_LENGTH, max = PASSWORD_MAX_LENGTH) diff --git a/generators/spring-boot/templates/src/test/kotlin/package/config/WebConfigurerTest.kt.ejs b/generators/spring-boot/templates/src/test/kotlin/package/config/WebConfigurerTest.kt.ejs index a708272fe..b99c5df4a 100644 --- a/generators/spring-boot/templates/src/test/kotlin/package/config/WebConfigurerTest.kt.ejs +++ b/generators/spring-boot/templates/src/test/kotlin/package/config/WebConfigurerTest.kt.ejs @@ -92,7 +92,7 @@ class WebConfigurerTest { assertThat(container.mimeMappings.get("html")).isEqualTo("text/html") assertThat(container.mimeMappings.get("json")).isEqualTo("application/json") if (container.documentRoot != null) { - assertThat(container.documentRoot).isEqualTo(File("<%= CLIENT_DIST_DIR %>")) + assertThat(container.documentRoot).isEqualTo(File("<%= clientDistDir %>")) } } <%_ } _%> diff --git a/generators/spring-boot/templates/src/test/kotlin/package/domain/EntityTest.kt.ejs b/generators/spring-boot/templates/src/test/kotlin/package/domain/EntityTest.kt.ejs index f33fdee82..4365837d5 100644 --- a/generators/spring-boot/templates/src/test/kotlin/package/domain/EntityTest.kt.ejs +++ b/generators/spring-boot/templates/src/test/kotlin/package/domain/EntityTest.kt.ejs @@ -31,11 +31,11 @@ class <%= persistClass %>Test { equalsVerifier(<%= persistClass %>::class) <%_if (!embedded) { _%> val <%= persistInstance %>1 = <%= persistClass %>() - <%= persistInstance %>1.<%= primaryKey.name %> = <% if (databaseTypeSql && hasOauthUser) { %>UUID.randomUUID().toString()<% } else if (primaryKey.typeLong) { %>1L<% } else if (primaryKey.typeString) { %>"id1"<% } else if (primaryKey.typeUUID) { %>UUID.randomUUID()<% } %> + <%= persistInstance %>1.<%= primaryKey.name %> = <% if (databaseTypeSql && authenticationTypeOauth2 && generateBuiltInUserEntity) { %>UUID.randomUUID().toString()<% } else if (primaryKey.typeLong) { %>1L<% } else if (primaryKey.typeString) { %>"id1"<% } else if (primaryKey.typeUUID) { %>UUID.randomUUID()<% } %> val <%= persistInstance %>2 = <%= persistClass %>() <%= persistInstance %>2.<%= primaryKey.name %> = <%= persistInstance %>1.<%= primaryKey.name %> assertThat(<%= persistInstance %>1).isEqualTo(<%= persistInstance %>2) - <%= persistInstance %>2.<%= primaryKey.name %> = <% if (databaseTypeSql && hasOauthUser) { %>UUID.randomUUID().toString()<% } else if (primaryKey.typeLong) { %>2L<% } else if (primaryKey.typeString) { %>"id2"<% } else if (primaryKey.typeUUID) { %>UUID.randomUUID()<% } %> + <%= persistInstance %>2.<%= primaryKey.name %> = <% if (databaseTypeSql && authenticationTypeOauth2 && generateBuiltInUserEntity) { %>UUID.randomUUID().toString()<% } else if (primaryKey.typeLong) { %>2L<% } else if (primaryKey.typeString) { %>"id2"<% } else if (primaryKey.typeUUID) { %>UUID.randomUUID()<% } %> assertThat(<%= persistInstance %>1).isNotEqualTo(<%= persistInstance %>2) <%= persistInstance %>1.<%= primaryKey.name %> = null assertThat(<%= persistInstance %>1).isNotEqualTo(<%= persistInstance %>2) diff --git a/generators/spring-boot/templates/src/test/kotlin/package/security/DomainUserDetailsServiceIT.kt.ejs b/generators/spring-boot/templates/src/test/kotlin/package/security/DomainUserDetailsServiceIT.kt.ejs index dbf9f9263..8b76b4c66 100644 --- a/generators/spring-boot/templates/src/test/kotlin/package/security/DomainUserDetailsServiceIT.kt.ejs +++ b/generators/spring-boot/templates/src/test/kotlin/package/security/DomainUserDetailsServiceIT.kt.ejs @@ -22,7 +22,7 @@ import <%= packageName %>.IntegrationTest <%_ if (databaseTypeSql && reactive) { _%> import <%= packageName %>.config.SYSTEM_ACCOUNT <%_ } _%> -import <%= packageName %>.domain.<%= asEntity('User') %> +import <%= packageName %>.domain.<%= user.persistClass %> import <%= packageName %>.repository.UserRepository import org.apache.commons.lang3.RandomStringUtils @@ -86,7 +86,7 @@ class DomainUserDetailsServiceIT { userRepository.deleteAll()<% if (reactive) { %>.block()<% } %> <%_ } _%> - val userOne = <%= asEntity('User') %>( + val userOne = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> @@ -103,7 +103,7 @@ class DomainUserDetailsServiceIT { ) userRepository.save(userOne)<% if (reactive) { %>.block()<% } %> - val userTwo = <%= asEntity('User') %>( + val userTwo = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> @@ -120,7 +120,7 @@ class DomainUserDetailsServiceIT { ) userRepository.save(userTwo)<% if (reactive) { %>.block()<% } %> - val userThree = <%= asEntity('User') %>( + val userThree = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> diff --git a/generators/spring-boot/templates/src/test/kotlin/package/service/MailServiceIT.kt.ejs b/generators/spring-boot/templates/src/test/kotlin/package/service/MailServiceIT.kt.ejs index f39b1a51e..fd57dc376 100644 --- a/generators/spring-boot/templates/src/test/kotlin/package/service/MailServiceIT.kt.ejs +++ b/generators/spring-boot/templates/src/test/kotlin/package/service/MailServiceIT.kt.ejs @@ -20,7 +20,7 @@ package <%= packageName %>.service import <%= packageName %>.config.DEFAULT_LANGUAGE import <%= packageName %>.IntegrationTest -import <%= packageName %>.domain.<%= asEntity('User') %> +import <%= packageName %>.domain.<%= user.persistClass %> import tech.jhipster.config.JHipsterProperties import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -144,7 +144,7 @@ class MailServiceIT { @Test fun testSendEmailFromTemplate() { - val user = <%= asEntity('User') %>( + val user = <%= user.persistClass %>( login = "john", email = "john.doe@example.com", langKey = DEFAULT_LANGUAGE @@ -162,7 +162,7 @@ class MailServiceIT { @Test fun testSendActivationEmail() { - val user = <%= asEntity('User') %>( + val user = <%= user.persistClass %>( langKey = DEFAULT_LANGUAGE, login = "john", email = "john.doe@example.com" @@ -178,7 +178,7 @@ class MailServiceIT { @Test fun testCreationEmail() { - val user = <%= asEntity('User') %>( + val user = <%= user.persistClass %>( langKey = DEFAULT_LANGUAGE, login = "john", email = "john.doe@example.com" @@ -194,7 +194,7 @@ class MailServiceIT { @Test fun testSendPasswordResetMail() { - val user = <%= asEntity('User') %>( + val user = <%= user.persistClass %>( langKey = DEFAULT_LANGUAGE, login = "john", email = "john.doe@example.com" @@ -223,7 +223,7 @@ class MailServiceIT { @Test fun testSendLocalizedEmailForAllSupportedLanguages() { - val user = <%= asEntity('User') %>( + val user = <%= user.persistClass %>( login = "john", email = "john.doe@example.com" ) diff --git a/generators/spring-boot/templates/src/test/kotlin/package/service/UserServiceIT.kt.ejs b/generators/spring-boot/templates/src/test/kotlin/package/service/UserServiceIT.kt.ejs index 553db8a60..36383c529 100644 --- a/generators/spring-boot/templates/src/test/kotlin/package/service/UserServiceIT.kt.ejs +++ b/generators/spring-boot/templates/src/test/kotlin/package/service/UserServiceIT.kt.ejs @@ -27,7 +27,7 @@ import <%= packageName %>.config.DEFAULT_LANGUAGE import <%= packageName %>.domain.PersistentToken <%_ } _%> <%_ if (!databaseTypeNo) { _%> -import <%= packageName %>.domain.<%= asEntity('User') %> +import <%= packageName %>.domain.<%= user.persistClass %> <%_ } _%> <%_ if ((databaseTypeSql || databaseTypeMongodb || databaseTypeNeo4j || databaseTypeCouchbase) && authenticationTypeSession && !reactive) { _%> import <%= packageName %>.repository.PersistentTokenRepository @@ -170,7 +170,7 @@ class UserServiceIT { <%_ } _%> <%_ if (!databaseTypeNo) { _%> - private lateinit var user: <%= asEntity('User') %> + private lateinit var user: <%= user.persistClass %> <%_ } _%> <%_ if (authenticationTypeOauth2 ) { _%> @@ -192,7 +192,7 @@ class UserServiceIT { userRepository.deleteAll()<% if (reactive) { %>.block()<% } %> <%_ } _%> <%_ if (!databaseTypeNo) { _%> - user = <%= asEntity('User') %>( + user = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> @@ -404,7 +404,7 @@ class UserServiceIT { <%_ } _%> <%_ if ((databaseTypeSql || databaseTypeNeo4j || databaseTypeMongodb || databaseTypeCouchbase) && authenticationTypeSession && !reactive) { _%> - private fun generateUserToken(user: <%= asEntity('User') %>, tokenSeries: String, localDate: LocalDate) { + private fun generateUserToken(user: <%= user.persistClass %>, tokenSeries: String, localDate: LocalDate) { val token = PersistentToken( series = tokenSeries, <%_ if (databaseTypeCouchbase) { _%> diff --git a/generators/spring-boot/templates/src/test/kotlin/package/service/dto/EntityDTOTest.kt.ejs b/generators/spring-boot/templates/src/test/kotlin/package/service/dto/EntityDTOTest.kt.ejs index 9196a43b2..7f5e115fa 100644 --- a/generators/spring-boot/templates/src/test/kotlin/package/service/dto/EntityDTOTest.kt.ejs +++ b/generators/spring-boot/templates/src/test/kotlin/package/service/dto/EntityDTOTest.kt.ejs @@ -25,8 +25,8 @@ import <%= packageName %>.web.rest.equalsVerifier let id1; let id2; if (!embedded) { - id1 = getPrimaryKeyValue(primaryKey.type, databaseType, '1'); - id2 = getPrimaryKeyValue(primaryKey.type, databaseType, '2'); + id1 = this.getPrimaryKeyValue(primaryKey.type, databaseType, '1'); + id2 = this.getPrimaryKeyValue(primaryKey.type, databaseType, '2'); } %> import java.util.UUID diff --git a/generators/spring-boot/templates/src/test/kotlin/package/service/mapper/UserMapperTest.kt.ejs b/generators/spring-boot/templates/src/test/kotlin/package/service/mapper/UserMapperTest.kt.ejs index 221b67f3d..32e8f0211 100644 --- a/generators/spring-boot/templates/src/test/kotlin/package/service/mapper/UserMapperTest.kt.ejs +++ b/generators/spring-boot/templates/src/test/kotlin/package/service/mapper/UserMapperTest.kt.ejs @@ -18,9 +18,9 @@ -%> package <%= packageName %>.service.mapper -import <%= packageName %>.domain.<%= asEntity('User') %> -import <%= packageName %>.service.dto.<%= asDto('AdminUser') %> -import <%= packageName %>.service.dto.<%= asDto('User') %> +import <%= packageName %>.domain.<%= user.persistClass %> +import <%= packageName %>.service.dto.<%= user.adminUserDto %> +import <%= packageName %>.service.dto.<%= user.restClass %> <%_ if (!authenticationTypeOauth2) { _%> import org.apache.commons.lang3.RandomStringUtils <%_ } _%> @@ -39,7 +39,7 @@ private const val DEFAULT_LOGIN = "johndoe" <%_ if (databaseTypeCouchbase){ _%> private const val DEFAULT_ID = DEFAULT_LOGIN <%_ } else { _%> -private const val DEFAULT_ID = <%- getPrimaryKeyValue(user.primaryKey.type) %> +private const val DEFAULT_ID = <%- this.getPrimaryKeyValue(user.primaryKey.type) %> <%_ } _%> /** @@ -49,13 +49,13 @@ class UserMapperTest { private lateinit var userMapper: UserMapper - private lateinit var user: <%= asEntity('User') %> - private lateinit var userDto: <%= asDto('AdminUser') %> + private lateinit var user: <%= user.persistClass %> + private lateinit var userDto: <%= user.adminUserDto %> @BeforeEach fun init() { userMapper = UserMapper() - user = <%= asEntity('User') %>( + user = <%= user.persistClass %>( login = DEFAULT_LOGIN, <%_ if (!authenticationTypeOauth2) { _%> password = RandomStringUtils.randomAlphanumeric(60), @@ -70,7 +70,7 @@ class UserMapperTest { langKey = "en" ) - userDto = <%= asDto('AdminUser') %>(user) + userDto = <%= user.adminUserDto %>(user) } @Test diff --git a/generators/spring-boot/templates/src/test/kotlin/package/web/rest/AccountResourceIT.kt.ejs b/generators/spring-boot/templates/src/test/kotlin/package/web/rest/AccountResourceIT.kt.ejs index 74280c2dd..2786acd5d 100644 --- a/generators/spring-boot/templates/src/test/kotlin/package/web/rest/AccountResourceIT.kt.ejs +++ b/generators/spring-boot/templates/src/test/kotlin/package/web/rest/AccountResourceIT.kt.ejs @@ -26,7 +26,7 @@ import <%= packageName %>.config.DEFAULT_LANGUAGE <%_ if (authenticationTypeSession && !reactive) { _%> import <%= packageName %>.domain.PersistentToken <%_ } _%> -import <%= packageName %>.domain.<%= asEntity('User') %> +import <%= packageName %>.domain.<%= user.persistClass %> <%_ if (databaseTypeSql || databaseTypeMongodb || databaseTypeNeo4j) { _%> import <%= packageName %>.repository.AuthorityRepository @@ -42,12 +42,12 @@ import <%= packageName %>.security.ADMIN import <%= packageName %>.security.USER import <%= packageName %>.service.UserService import <%= packageName %>.service.dto.PasswordChangeDTO -import <%= packageName %>.service.dto.<%= asDto('User') %> -import <%= packageName %>.service.dto.<%= asDto('AdminUser') %> +import <%= packageName %>.service.dto.<%= user.restClass %> +import <%= packageName %>.service.dto.<%= user.adminUserDto %> import <%= packageName %>.web.rest.vm.KeyAndPasswordVM import <%= packageName %>.web.rest.vm.ManagedUserVM import org.apache.commons.lang3.RandomStringUtils -<%_ if (reactive && testsNeedCsrf || databaseTypeMongodb || databaseTypeNeo4j) { _%> +<%_ if (reactive && authenticationUsesCsrf || databaseTypeMongodb || databaseTypeNeo4j) { _%> import org.junit.jupiter.api.BeforeEach <%_ } _%> import org.junit.jupiter.api.Test @@ -98,11 +98,11 @@ import org.hamcrest.Matchers.hasItem <%_ } _%> import <%= packageName %>.web.rest.TEST_USER_LOGIN <%_ if (reactive) { _%> - <%_ if (testsNeedCsrf) { _%> + <%_ if (authenticationUsesCsrf) { _%> import org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.csrf <%_ } _%> <%_ } else { _%> - <%_ if (testsNeedCsrf) { _%> + <%_ if (authenticationUsesCsrf) { _%> import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf <%_ } _%> import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.* @@ -165,7 +165,7 @@ class AccountResourceIT { userRepository.deleteAll()<% if (reactive) { %>.block()<% } %> } <%_ } _%> - <%_ if (reactive && testsNeedCsrf) { _%> + <%_ if (reactive && authenticationUsesCsrf) { _%> @BeforeEach fun setupCsrf() { @@ -224,7 +224,7 @@ class AccountResourceIT { <%_ } _%> fun testGetExistingAccount() { val authorities = mutableSetOf(ADMIN) - val user = <%= asDto('AdminUser') %>( + val user = <%= user.adminUserDto %>( login = TEST_USER_LOGIN, firstName = "john", lastName = "doe", @@ -316,7 +316,7 @@ class AccountResourceIT { restAccountMockMvc.perform( post("/api/register") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(validUser))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(validUser))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().isCreated) @@ -354,7 +354,7 @@ class AccountResourceIT { restAccountMockMvc.perform( post("/api/register") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(invalidUser))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(invalidUser))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) <%_ if (databaseTypeCouchbase) { _%> @@ -396,7 +396,7 @@ class AccountResourceIT { restAccountMockMvc.perform( post("/api/register") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(invalidUser))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(invalidUser))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().isBadRequest) @@ -435,7 +435,7 @@ class AccountResourceIT { restAccountMockMvc.perform( post("/api/register") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(invalidUser))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(invalidUser))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().isBadRequest) @@ -474,7 +474,7 @@ class AccountResourceIT { restAccountMockMvc.perform( post("/api/register") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(invalidUser))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(invalidUser))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().isBadRequest) @@ -534,7 +534,7 @@ class AccountResourceIT { restAccountMockMvc.perform( post("/api/register") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(firstUser))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(firstUser))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().isCreated) @@ -552,7 +552,7 @@ class AccountResourceIT { restAccountMockMvc.perform( post("/api/register") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(secondUser))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(secondUser))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) <%_ if (databaseTypeCouchbase) { _%> @@ -578,7 +578,7 @@ class AccountResourceIT { restAccountMockMvc.perform( post("/api/register") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(secondUser))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(secondUser))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().is4xxClientError) @@ -615,7 +615,7 @@ class AccountResourceIT { restAccountMockMvc.perform( post("/api/register") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(firstUser))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(firstUser))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().isCreated) @@ -650,7 +650,7 @@ class AccountResourceIT { restAccountMockMvc.perform( post("/api/register") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(secondUser))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(secondUser))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().isCreated) @@ -689,7 +689,7 @@ class AccountResourceIT { restAccountMockMvc.perform( post("/api/register") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(userWithUpperCaseEmail))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(userWithUpperCaseEmail))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().isCreated) @@ -701,7 +701,7 @@ class AccountResourceIT { assertThat(testUser4.get().email).isEqualTo("test-register-duplicate-email@example.com") testUser4.get().activated = true - userService.updateUser((<%= asDto('AdminUser') %>(testUser4.get())))<% if (reactive) { %>.block()<% } %> + userService.updateUser((<%= user.adminUserDto %>(testUser4.get())))<% if (reactive) { %>.block()<% } %> // Register 4th (already activated) user <%_ if (reactive) { _%> @@ -714,7 +714,7 @@ class AccountResourceIT { restAccountMockMvc.perform( post("/api/register") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(secondUser))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(secondUser))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().is4xxClientError) @@ -750,7 +750,7 @@ class AccountResourceIT { restAccountMockMvc.perform( post("/api/register") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(validUser))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(validUser))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().isCreated) @@ -770,7 +770,7 @@ class AccountResourceIT { <%_ } _%> fun testActivateAccount() { val activationKey = "some activation key" - var user = <%= asEntity('User') %>( + var user = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> @@ -819,7 +819,7 @@ class AccountResourceIT { @WithMockUser("save-account") @Throws(Exception::class) fun testSaveAccount() { - val user = <%= asEntity('User') %>( + val user = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> @@ -833,7 +833,7 @@ class AccountResourceIT { ) userRepository.save<% if (databaseTypeSql && !reactive) { %>AndFlush<% } %>(user)<% if (reactive) { %>.block()<% } %> - val userDTO = <%= asDto('AdminUser') %>( + val userDTO = <%= user.adminUserDto %>( login = "not-used", firstName = "firstname", lastName = "lastname", @@ -856,7 +856,7 @@ class AccountResourceIT { restAccountMockMvc.perform( post("/api/account") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(userDTO))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(userDTO))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().isOk) @@ -883,7 +883,7 @@ class AccountResourceIT { @Throws(Exception::class) <%_ } _%> fun testSaveInvalidEmail() { - val user = <%= asEntity('User') %>( + val user = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> @@ -898,7 +898,7 @@ class AccountResourceIT { userRepository.save<% if (databaseTypeSql && !reactive) { %>AndFlush<% } %>(user)<% if (reactive) { %>.block()<% } %> - val userDTO = <%= asDto('AdminUser') %>( + val userDTO = <%= user.adminUserDto %>( login = "not-used", firstName = "firstname", lastName = "lastname", @@ -921,7 +921,7 @@ class AccountResourceIT { restAccountMockMvc.perform( post("/api/account") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(userDTO))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(userDTO))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) <%_ if (databaseTypeCouchbase) { _%> @@ -941,7 +941,7 @@ class AccountResourceIT { @Throws(Exception::class) <%_ } _%> fun testSaveExistingEmail() { - val user = <%= asEntity('User') %>( + val user = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> @@ -956,7 +956,7 @@ class AccountResourceIT { userRepository.save<% if (databaseTypeSql && !reactive) { %>AndFlush<% } %>(user)<% if (reactive) { %>.block()<% } %> - val anotherUser = <%= asEntity('User') %>( + val anotherUser = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> @@ -971,7 +971,7 @@ class AccountResourceIT { userRepository.save<% if (databaseTypeSql && !reactive) { %>AndFlush<% } %>(anotherUser)<% if (reactive) { %>.block()<% } %> - val userDTO = <%= asDto('AdminUser') %>( + val userDTO = <%= user.adminUserDto %>( login = "not-used", firstName = "firstname", lastName = "lastname", @@ -994,7 +994,7 @@ class AccountResourceIT { restAccountMockMvc.perform( post("/api/account") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(userDTO))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(userDTO))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().isBadRequest) @@ -1010,7 +1010,7 @@ class AccountResourceIT { @WithMockUser("save-existing-email-and-login") <%_ if (!reactive) { _%>@Throws(Exception::class)<%_ } _%> fun testSaveExistingEmailAndLogin() { - val user = <%= asEntity('User') %>( + val user = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> @@ -1024,7 +1024,7 @@ class AccountResourceIT { ) userRepository.save<% if (databaseTypeSql && !reactive) { %>AndFlush<% } %>(user)<% if (reactive) { %>.block()<% } %> - val userDTO = <%= asDto('AdminUser') %>( + val userDTO = <%= user.adminUserDto %>( login = "not-used", firstName = "firstname", lastName = "lastname", @@ -1047,7 +1047,7 @@ class AccountResourceIT { restAccountMockMvc.perform( post("/api/account") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(userDTO))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(userDTO))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().isOk) @@ -1064,7 +1064,7 @@ class AccountResourceIT { <%_ if (!reactive) { _%>@Throws(Exception::class)<%_ } _%> fun testChangePasswordWrongExistingPassword() { val currentPassword = RandomStringUtils.randomAlphanumeric(60) - val user = <%= asEntity('User') %>( + val user = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> @@ -1089,7 +1089,7 @@ class AccountResourceIT { post("/api/account/change-password") .contentType(MediaType.APPLICATION_JSON) .content(convertObjectToJsonBytes(PasswordChangeDTO("1$currentPassword", "new password"))) - <%_ if (testsNeedCsrf) { _%> + <%_ if (authenticationUsesCsrf) { _%> .with(csrf())<%_ } _%> ) .andExpect(status().isBadRequest) @@ -1106,7 +1106,7 @@ class AccountResourceIT { <%_ if (!reactive) { _%>@Throws(Exception::class)<%_ } _%> fun testChangePassword() { val currentPassword = RandomStringUtils.randomAlphanumeric(60) - val user = <%= asEntity('User') %>( + val user = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> @@ -1131,7 +1131,7 @@ class AccountResourceIT { post("/api/account/change-password") .contentType(MediaType.APPLICATION_JSON) .content(convertObjectToJsonBytes(PasswordChangeDTO(currentPassword, "new password"))) - <%_ if (testsNeedCsrf) { _%> + <%_ if (authenticationUsesCsrf) { _%> .with(csrf())<%_ } _%> ) .andExpect(status().isOk) @@ -1147,7 +1147,7 @@ class AccountResourceIT { <%_ if (!reactive) { _%>@Throws(Exception::class)<%_ } _%> fun testChangePasswordTooSmall() { val currentPassword = RandomStringUtils.randomAlphanumeric(60) - val user = <%= asEntity('User') %>( + val user = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> @@ -1174,7 +1174,7 @@ class AccountResourceIT { post("/api/account/change-password") .contentType(MediaType.APPLICATION_JSON) .content(convertObjectToJsonBytes(PasswordChangeDTO(currentPassword, newPassword))) - <%_ if (testsNeedCsrf) { _%> + <%_ if (authenticationUsesCsrf) { _%> .with(csrf())<%_ } _%> ) .andExpect(status().isBadRequest) @@ -1190,7 +1190,7 @@ class AccountResourceIT { <%_ if (!reactive) { _%>@Throws(Exception::class)<%_ } _%> fun testChangePasswordTooLong() { val currentPassword = RandomStringUtils.randomAlphanumeric(60) - val user = <%= asEntity('User') %>( + val user = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> @@ -1217,7 +1217,7 @@ class AccountResourceIT { post("/api/account/change-password") .contentType(MediaType.APPLICATION_JSON) .content(convertObjectToJsonBytes(PasswordChangeDTO(currentPassword, newPassword))) - <%_ if (testsNeedCsrf) { _%> + <%_ if (authenticationUsesCsrf) { _%> .with(csrf())<%_ } _%> ) .andExpect(status().isBadRequest) @@ -1233,7 +1233,7 @@ class AccountResourceIT { <%_ if (!reactive) { _%>@Throws(Exception::class)<%_ } _%> fun testChangePasswordEmpty() { val currentPassword = RandomStringUtils.randomAlphanumeric(60) - val user = <%= asEntity('User') %>( + val user = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> @@ -1258,7 +1258,7 @@ class AccountResourceIT { post("/api/account/change-password") .contentType(MediaType.APPLICATION_JSON) .content(convertObjectToJsonBytes(PasswordChangeDTO(currentPassword, ""))) - <%_ if (testsNeedCsrf) { _%> + <%_ if (authenticationUsesCsrf) { _%> .with(csrf())<%_ } _%> ) .andExpect(status().isBadRequest) @@ -1274,7 +1274,7 @@ class AccountResourceIT { @WithMockUser("current-sessions") <%_ if (!reactive) { _%>@Throws(Exception::class)<%_ } _%> fun testGetCurrentSessions() { - val user = <%= asEntity('User') %>( + val user = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> @@ -1322,7 +1322,7 @@ class AccountResourceIT { @WithMockUser("invalidate-session") <%_ if (!reactive) { _%>@Throws(Exception::class)<%_ } _%> fun testInvalidateSession() { - val user = <%= asEntity('User') %>( + val user = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> @@ -1359,7 +1359,7 @@ class AccountResourceIT { assertThat(persistentTokenRepository.findByUser(user)).hasSize(1) - restAccountMockMvc.perform(delete("/api/account/sessions/invalidate-session")<%_ if (testsNeedCsrf) { _%>.with(csrf())<%_ } _%>) + restAccountMockMvc.perform(delete("/api/account/sessions/invalidate-session")<%_ if (authenticationUsesCsrf) { _%>.with(csrf())<%_ } _%>) .andExpect(status().isOk) assertThat(persistentTokenRepository.findByUser(user)).isEmpty() @@ -1372,7 +1372,7 @@ class AccountResourceIT { @Throws(Exception::class) <%_ } _%> fun testRequestPasswordReset() { - val user = <%= asEntity('User') %>( + val user = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> @@ -1397,7 +1397,7 @@ class AccountResourceIT { restAccountMockMvc.perform( post("/api/account/reset-password/init") .content("password-reset@example.com") - <%_ if (testsNeedCsrf) { _%> + <%_ if (authenticationUsesCsrf) { _%> .with(csrf())<%_ } _%> ) .andExpect(status().isOk) @@ -1410,7 +1410,7 @@ class AccountResourceIT { @Throws(Exception::class) <%_ } _%> fun testRequestPasswordResetUpperCaseEmail() { - val user = <%= asEntity('User') %>( + val user = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> @@ -1435,7 +1435,7 @@ class AccountResourceIT { restAccountMockMvc.perform( post("/api/account/reset-password/init") .content("password-reset@EXAMPLE.COM") - <%_ if (testsNeedCsrf) { _%> + <%_ if (authenticationUsesCsrf) { _%> .with(csrf())<%_ } _%> ) .andExpect(status().isOk) @@ -1454,7 +1454,7 @@ class AccountResourceIT { fun testRequestPasswordResetWrongEmail() { restAccountMockMvc.perform( post("/api/account/reset-password/init") - .content("password-reset-wrong-email@example.com")<% if (testsNeedCsrf) { %> + .content("password-reset-wrong-email@example.com")<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().isOk) @@ -1465,7 +1465,7 @@ class AccountResourceIT { @Transactional<% } %> @Throws(Exception::class) fun testFinishPasswordReset() { - val user = <%= asEntity('User') %>( + val user = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> @@ -1493,7 +1493,7 @@ class AccountResourceIT { restAccountMockMvc.perform( post("/api/account/reset-password/finish") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(keyAndPassword))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(keyAndPassword))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().isOk) @@ -1508,7 +1508,7 @@ class AccountResourceIT { @Transactional<% } %> @Throws(Exception::class) fun testFinishPasswordResetTooSmall() { - val user = <%= asEntity('User') %>( + val user = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> @@ -1536,7 +1536,7 @@ class AccountResourceIT { restAccountMockMvc.perform( post("/api/account/reset-password/finish") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(keyAndPassword))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(keyAndPassword))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().isBadRequest) @@ -1563,7 +1563,7 @@ class AccountResourceIT { restAccountMockMvc.perform( post("/api/account/reset-password/finish") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(keyAndPassword))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(keyAndPassword))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().isInternalServerError) diff --git a/generators/spring-boot/templates/src/test/kotlin/package/web/rest/EntityResourceIT.kt.ejs b/generators/spring-boot/templates/src/test/kotlin/package/web/rest/EntityResourceIT.kt.ejs index f652c66be..68c6a242a 100644 --- a/generators/spring-boot/templates/src/test/kotlin/package/web/rest/EntityResourceIT.kt.ejs +++ b/generators/spring-boot/templates/src/test/kotlin/package/web/rest/EntityResourceIT.kt.ejs @@ -152,7 +152,7 @@ import org.springframework.security.test.context.support.WithMockUser <%_ if (databaseTypeSql && !reactive) { _%> import org.springframework.transaction.annotation.Transactional <%_ } _%> -<%_ if (fieldsContainBlob) { _%> +<%_ if (anyFieldIsBlobDerived) { _%> import org.springframework.util.Base64Utils <%_ } _%> <%_ if (reactive && (implementsEagerLoadApis || searchEngineElasticsearch)) { _%> @@ -163,32 +163,32 @@ import org.springframework.validation.Validator <%_ if (databaseTypeSql && !reactive) { _%> import javax.persistence.EntityManager <%_ } _%> -<%_ if (fieldsContainBigDecimal) { _%> +<%_ if (anyFieldIsBigDecimal) { _%> import java.math.BigDecimal <%_ } _%> -<%_ if (fieldsContainBlob&& databaseTypeCassandra) { _%> +<%_ if (anyFieldIsBlobDerived&& databaseTypeCassandra) { _%> import java.nio.ByteBuffer <%_ } _%> -<%_ if (reactive || fieldsContainDuration) { _%> +<%_ if (reactive || anyFieldIsDuration) { _%> import java.time.Duration <%_ } _%> -<%_ if (fieldsContainLocalDate) { _%> +<%_ if (anyFieldIsLocalDate) { _%> import java.time.LocalDate <%_ } _%> -<%_ if (fieldsContainInstant|| fieldsContainZonedDateTime) { _%> +<%_ if (anyFieldIsInstant|| anyFieldIsZonedDateTime) { _%> import java.time.Instant <%_ } _%> -<%_ if (fieldsContainZonedDateTime) { _%> +<%_ if (anyFieldIsZonedDateTime) { _%> import java.time.ZonedDateTime import java.time.ZoneOffset <%_ } _%> -<%_ if (fieldsContainLocalDate|| fieldsContainZonedDateTime) { _%> +<%_ if (anyFieldIsLocalDate|| anyFieldIsZonedDateTime) { _%> import java.time.ZoneId <%_ } _%> -<%_ if (fieldsContainInstant) { _%> +<%_ if (anyFieldIsInstant) { _%> import java.time.temporal.ChronoUnit <%_ } _%> -<%_ if (fieldsContainUUID || primaryKey.typeString || otherEntityPrimaryKeyTypesIncludesUUID) { _%> +<%_ if (anyFieldIsUUID || primaryKey.typeString || otherEntityPrimaryKeyTypesIncludesUUID) { _%> import java.util.UUID <%_ } _%> <%_ if (!embedded && primaryKey.hasLong) { _%> @@ -202,7 +202,7 @@ import org.hamcrest.Matchers.hasItem <%_ if (reactive) { _%> import org.hamcrest.Matchers.`is` <%_ } _%> -<%_ if (testsNeedCsrf) { _%> +<%_ if (authenticationUsesCsrf) { _%> <%_ if (reactive) { _%> import org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.csrf <%_ } else { _%> @@ -318,7 +318,7 @@ class <%= entityClass %>ResourceIT { } <%_ } _%> - <%_ if (reactive && testsNeedCsrf) { _%> + <%_ if (reactive && authenticationUsesCsrf) { _%> @BeforeEach fun setupCsrf() { webTestClient = webTestClient.mutateWith(csrf()) @@ -364,7 +364,7 @@ class <%= entityClass %>ResourceIT { .expectStatus().isCreated <%_ } else { _%> rest<%= entityClass %>MockMvc.perform( - post(ENTITY_API_URL)<% if (testsNeedCsrf) { %>.with(csrf())<% }%> + post(ENTITY_API_URL)<% if (authenticationUsesCsrf) { %>.with(csrf())<% }%> .contentType(MediaType.APPLICATION_JSON) .content(convertObjectToJsonBytes(<%= restInstance %>)) ).andExpect(status().isCreated) @@ -428,7 +428,7 @@ class <%= entityClass %>ResourceIT { .expectStatus().isBadRequest <%_ } else { _%> rest<%= entityClass %>MockMvc.perform( - post(ENTITY_API_URL)<% if (testsNeedCsrf) { %>.with(csrf())<% }%> + post(ENTITY_API_URL)<% if (authenticationUsesCsrf) { %>.with(csrf())<% }%> .contentType(MediaType.APPLICATION_JSON) .content(convertObjectToJsonBytes(<%= restInstance %>)) ).andExpect(status().isBadRequest) @@ -495,7 +495,7 @@ class <%= entityClass %>ResourceIT { .exchange() .expectStatus().isOk <%_ } else { _%> - rest<%= entityClass %>MockMvc.perform(put(ENTITY_API_URL_ID, <%_ if (dtoMapstruct) { _%>updated<%= dtoClass %> <%_ } else { _%> updated<%= persistClass %> <%_ } _%>.<%= primaryKey.name %>)<% if (testsNeedCsrf) { %>.with(csrf())<% }%> + rest<%= entityClass %>MockMvc.perform(put(ENTITY_API_URL_ID, <%_ if (dtoMapstruct) { _%>updated<%= dtoClass %> <%_ } else { _%> updated<%= persistClass %> <%_ } _%>.<%= primaryKey.name %>)<% if (authenticationUsesCsrf) { %>.with(csrf())<% }%> .contentType(MediaType.APPLICATION_JSON) .content(convertObjectToJsonBytes(<%_ if (dtoMapstruct) { _%>updated<%= dtoClass %> <%_ } else { _%> updated<%= persistClass %> <%_ } _%>))) .andExpect(status().isOk) @@ -547,7 +547,7 @@ class <%= entityClass %>ResourceIT { .expectStatus().isBadRequest <%_ } else { _%> rest<%= entityClass %>MockMvc.perform( - post(ENTITY_API_URL)<% if (testsNeedCsrf) { %>.with(csrf())<% }%> + post(ENTITY_API_URL)<% if (authenticationUsesCsrf) { %>.with(csrf())<% }%> .contentType(MediaType.APPLICATION_JSON) .content(convertObjectToJsonBytes(<%= restInstance %>)) ).andExpect(status().isBadRequest) @@ -574,7 +574,7 @@ class <%= entityClass %>ResourceIT { // Initialize the database <%_ if (!primaryKey.derived) { _%> <%_ for (field of primaryKey.fields.filter(f => !f.autoGenerateByRepository)) { _%> - <%= persistInstance %>.<%= field.fieldName %> = <%- getJavaValueGeneratorForType(field.fieldType) %> + <%= persistInstance %>.<%= field.fieldName %> = <%- field.javaValueGenerator %> <%_ } _%> <%_ } _%> <%= entityInstance %>Repository.save(<%= persistInstance %>)<%= callBlock %> @@ -617,7 +617,7 @@ class <%= entityClass %>ResourceIT { // Initialize the database <%_ if (!primaryKey.derived) { _%> <%_ for (field of primaryKey.fields.filter(f => !f.autoGenerateByRepository)) { _%> - <%= persistInstance %>.<%= field.fieldName %> = <%- getJavaValueGeneratorForType(field.fieldType) %> + <%= persistInstance %>.<%= field.fieldName %> = <%- field.javaValueGenerator %> <%_ } _%> <%_ } _%> <%= entityInstance %>Repository.<%= saveMethod %>(<%= persistInstance %>)<%= callBlock %> @@ -709,7 +709,7 @@ class <%= entityClass %>ResourceIT { // Initialize the database <%_ if (!primaryKey.derived) { _%> <%_ for (field of primaryKey.fields.filter(f => !f.autoGenerateByRepository)) { _%> - <%= persistInstance %>.<%= field.fieldName %> = <%- getJavaValueGeneratorForType(field.fieldType) %> + <%= persistInstance %>.<%= field.fieldName %> = <%- field.javaValueGenerator %> <%_ } _%> <%_ } _%> <%= entityInstance %>Repository.<%= saveMethod %>(<%= persistInstance %>)<%= callBlock %> @@ -768,7 +768,7 @@ class <%= entityClass %>ResourceIT { <%_ } _%> } <%_ fieldsToTest.forEach((searchBy) => { /* we can't filter by all the fields. */ _%> - <%_ if (isFilterableType(searchBy.fieldType)) { _%> + <%_ if (searchBy.filterableField) { _%> @Test<%= transactionalAnnotation %> <% if (!reactive) { %>@Throws(Exception::class)<% } %> fun getAll<%= entityClassPlural %>By<%= searchBy.fieldInJavaBeanMethod %>IsEqualToSomething() { @@ -1097,7 +1097,7 @@ class <%= entityClass %>ResourceIT { // Initialize the database <%_ if (!primaryKey.derived) { _%> <%_ for (field of primaryKey.fields.filter(f => !f.autoGenerateByRepository)) { _%> - <%= persistInstance %>.<%= field.fieldName %> = <%- getJavaValueGeneratorForType(field.fieldType) %> + <%= persistInstance %>.<%= field.fieldName %> = <%- field.javaValueGenerator %> <%_ } _%> <%_ } _%> <%= entityInstance %>Repository.<%= saveMethod %>(<%= persistInstance %>)<%= callBlock %> @@ -1132,7 +1132,7 @@ class <%= entityClass %>ResourceIT { .expectStatus().isOk <%_ } else { _%> rest<%= entityClass %>MockMvc.perform( - put(ENTITY_API_URL_ID, <%= (dtoMapstruct ? asDto(entityInstance) : 'updated' + persistClass) %>.<%= primaryKey.name %>)<% if (testsNeedCsrf) { %>.with(csrf())<% }%> + put(ENTITY_API_URL_ID, <%= (dtoMapstruct ? asDto(entityInstance) : 'updated' + persistClass) %>.<%= primaryKey.name %>)<% if (authenticationUsesCsrf) { %>.with(csrf())<% }%> .contentType(MediaType.APPLICATION_JSON) .content(convertObjectToJsonBytes(<% if (dtoMapstruct) { %><%= dtoInstance %><% } else { %>updated<%= persistClass %><% } %>)) ).andExpect(status().isOk) @@ -1200,7 +1200,7 @@ class <%= entityClass %>ResourceIT { .exchange() .expectStatus().isBadRequest <%_ } else { _%> - rest<%= entityClass %>MockMvc.perform(put(ENTITY_API_URL_ID, <%= restInstance %>.<%= primaryKey.name %>)<% if (testsNeedCsrf) { %>.with(csrf())<% }%> + rest<%= entityClass %>MockMvc.perform(put(ENTITY_API_URL_ID, <%= restInstance %>.<%= primaryKey.name %>)<% if (authenticationUsesCsrf) { %>.with(csrf())<% }%> .contentType(MediaType.APPLICATION_JSON) .content(convertObjectToJsonBytes(<%= restInstance %>))) .andExpect(status().isBadRequest) @@ -1235,7 +1235,7 @@ 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 (testsNeedCsrf) { %>.with(csrf())<% }%> + put(ENTITY_API_URL_ID, <%= getJavaValueGeneratorForType(primaryKey.type) %>)<% if (authenticationUsesCsrf) { %>.with(csrf())<% }%> .contentType(MediaType.APPLICATION_JSON) .content(convertObjectToJsonBytes(<%= restInstance %>)) ).andExpect(status().isBadRequest) @@ -1281,7 +1281,7 @@ class <%= entityClass %>ResourceIT { .exchange() .expectStatus().isEqualTo(405) <%_ } else { _%> - rest<%= entityClass %>MockMvc.perform(put(ENTITY_API_URL)<% if (testsNeedCsrf) { %>.with(csrf())<% } %> + rest<%= entityClass %>MockMvc.perform(put(ENTITY_API_URL)<% if (authenticationUsesCsrf) { %>.with(csrf())<% } %> .contentType(MediaType.APPLICATION_JSON) .content(convertObjectToJsonBytes(<%= restInstance %>))) .andExpect(status().isMethodNotAllowed) @@ -1313,12 +1313,12 @@ class <%= entityClass %>ResourceIT { fun partialUpdate<%= entityClass %>WithPatch() { <%_ if (!primaryKey.derived) { _%> <%_ for (field of primaryKey.fields.filter(f => !f.autoGenerateByRepository)) { _%> - <%= persistInstance %>.<%= field.fieldName %> = <%- getJavaValueGeneratorForType(field.fieldType) %> + <%= persistInstance %>.<%= field.fieldName %> = <%- field.javaValueGenerator %> <%_ } _%> <%_ } _%> <%= entityInstance %>Repository.<%= saveMethod %>(<%= persistInstance %>)<%= callBlock %> <% const fieldsToIncludeInPartialPatchTest = fieldsToTest.map(field => prepareFieldForPatchTest(field, () => faker.datatype.boolean())); %> - <%- include('/partials/it_patch_update.partial.kt.ejs', {fields: fieldsToIncludeInPartialPatchTest, saveMethod, asEntity, callBlock, callListBlock, getPrimaryKeyValue, testsNeedCsrf}); -%> + <%- include('/partials/it_patch_update.partial.kt.ejs', {fields: fieldsToIncludeInPartialPatchTest, saveMethod, asEntity, callBlock, callListBlock, getPrimaryKeyValue, authenticationUsesCsrf}); -%> } @Test<%= transactionalAnnotation %> @@ -1326,12 +1326,12 @@ class <%= entityClass %>ResourceIT { fun fullUpdate<%= entityClass %>WithPatch() { <%_ if (!primaryKey.derived) { _%> <%_ for (field of primaryKey.fields.filter(f => !f.autoGenerateByRepository)) { _%> - <%= persistInstance %>.<%= field.fieldName %> = <%- getJavaValueGeneratorForType(field.fieldType) %> + <%= persistInstance %>.<%= field.fieldName %> = <%- field.javaValueGenerator %> <%_ } _%> <%_ } _%> <%= entityInstance %>Repository.<%= saveMethod %>(<%= persistInstance %>)<%= callBlock %> <% const fieldsToIncludeInFullPatchTest = fieldsToTest.map(field => prepareFieldForPatchTest(field, () => true)); %> - <%- include('/partials/it_patch_update.partial.kt.ejs', {fields: fieldsToIncludeInFullPatchTest, saveMethod, asEntity, callBlock, callListBlock, getPrimaryKeyValue, testsNeedCsrf}); -%> + <%- include('/partials/it_patch_update.partial.kt.ejs', {fields: fieldsToIncludeInFullPatchTest, saveMethod, asEntity, callBlock, callListBlock, getPrimaryKeyValue, authenticationUsesCsrf}); -%> } @Test<%= transactionalAnnotation %> @@ -1356,7 +1356,7 @@ class <%= entityClass %>ResourceIT { .exchange() .expectStatus().isBadRequest <%_ } else { _%> - rest<%= entityClass %>MockMvc.perform(patch(ENTITY_API_URL_ID, <%= (dtoMapstruct ? asDto(entityInstance) : asEntity(entityInstance)) %>.<%= primaryKey.name %>)<% if (testsNeedCsrf) { %>.with(csrf())<% }%> + rest<%= entityClass %>MockMvc.perform(patch(ENTITY_API_URL_ID, <%= (dtoMapstruct ? asDto(entityInstance) : asEntity(entityInstance)) %>.<%= primaryKey.name %>)<% if (authenticationUsesCsrf) { %>.with(csrf())<% }%> .contentType("application/merge-patch+json") .content(convertObjectToJsonBytes(<%= (dtoMapstruct ? asDto(entityInstance) : asEntity(entityInstance)) %>))) .andExpect(status().isBadRequest) @@ -1396,7 +1396,7 @@ class <%= entityClass %>ResourceIT { .exchange() .expectStatus().isBadRequest <%_ } else { _%> - rest<%= entityClass %>MockMvc.perform(patch(ENTITY_API_URL_ID, <%= getJavaValueGeneratorForType(primaryKey.type) %>)<% if (testsNeedCsrf) { %>.with(csrf())<% } %> + rest<%= entityClass %>MockMvc.perform(patch(ENTITY_API_URL_ID, <%= getJavaValueGeneratorForType(primaryKey.type) %>)<% if (authenticationUsesCsrf) { %>.with(csrf())<% } %> .contentType("application/merge-patch+json") .content(convertObjectToJsonBytes(<%= (dtoMapstruct ? asDto(entityInstance) : asEntity(entityInstance)) %>))) .andExpect(status().isBadRequest) @@ -1436,7 +1436,7 @@ class <%= entityClass %>ResourceIT { .exchange() .expectStatus().isEqualTo(405) <%_ } else { _%> - rest<%= entityClass %>MockMvc.perform(patch(ENTITY_API_URL)<% if (testsNeedCsrf) { %>.with(csrf())<% } %> + rest<%= entityClass %>MockMvc.perform(patch(ENTITY_API_URL)<% if (authenticationUsesCsrf) { %>.with(csrf())<% } %> .contentType("application/merge-patch+json") .content(convertObjectToJsonBytes(<%= (dtoMapstruct ? asDto(entityInstance) : asEntity(entityInstance)) %>))) .andExpect(status().isMethodNotAllowed) @@ -1460,7 +1460,7 @@ class <%= entityClass %>ResourceIT { // Initialize the database <%_ if (!primaryKey.derived) { _%> <%_ for (field of primaryKey.fields.filter(f => !f.autoGenerateByRepository)) { _%> - <%= persistInstance %>.<%= field.fieldName %> = <%- getJavaValueGeneratorForType(field.fieldType) %> + <%= persistInstance %>.<%= field.fieldName %> = <%- field.javaValueGenerator %> <%_ } _%> <%_ } _%> <%= entityInstance %>Repository.<%= saveMethod %>(<%= persistInstance %>)<%= callBlock %> @@ -1481,7 +1481,7 @@ class <%= entityClass %>ResourceIT { .expectStatus().isNoContent <%_ } else { _%> rest<%= entityClass %>MockMvc.perform( - delete(ENTITY_API_URL_ID, <%= persistInstance %>.<%= primaryKey.name %><% if (primaryKey.typeUUID && databaseTypeSql) { %>.toString()<% } %>)<% if (testsNeedCsrf) { %>.with(csrf())<% }%> + delete(ENTITY_API_URL_ID, <%= persistInstance %>.<%= primaryKey.name %><% if (primaryKey.typeUUID && databaseTypeSql) { %>.toString()<% } %>)<% if (authenticationUsesCsrf) { %>.with(csrf())<% }%> .accept(MediaType.APPLICATION_JSON) ).andExpect(status().isNoContent) <%_ } _%> @@ -1510,7 +1510,7 @@ class <%= entityClass %>ResourceIT { // Initialize the database <%_ if (!primaryKey.derived) { _%> <%_ for (field of primaryKey.fields.filter(f => !f.autoGenerateByRepository)) { _%> - <%= persistInstance %>.<%= field.fieldName %> = <%- getJavaValueGeneratorForType(field.fieldType) %> + <%= persistInstance %>.<%= field.fieldName %> = <%- field.javaValueGenerator %> <%_ } _%> <%_ } _%> <%= persistInstance %> = <%= entityInstance %>Repository.<%= saveMethod %>(<%= persistInstance %>)<%= callBlock %> @@ -1557,7 +1557,7 @@ class <%= entityClass %>ResourceIT { const defaultValueName = 'DEFAULT_' + field.fieldNameUnderscored.toUpperCase(); const updatedValueName = 'UPDATED_' + field.fieldNameUnderscored.toUpperCase(); const smallerValueName = 'SMALLER_' + field.fieldNameUnderscored.toUpperCase(); - const needsSmallerValueName = jpaMetamodelFiltering && isFilterableType(field.fieldType) + const needsSmallerValueName = jpaMetamodelFiltering && field.filterableField && (field.fieldTypeNumeric || field.fieldTypeDuration || field.fieldTypeLocalDate || field.fieldTypeZonedDateTime); let defaultValue = 1; diff --git a/generators/spring-boot/templates/src/test/kotlin/package/web/rest/PublicUserResourceIT.kt.ejs b/generators/spring-boot/templates/src/test/kotlin/package/web/rest/PublicUserResourceIT.kt.ejs index d36ec16e8..0fe222931 100644 --- a/generators/spring-boot/templates/src/test/kotlin/package/web/rest/PublicUserResourceIT.kt.ejs +++ b/generators/spring-boot/templates/src/test/kotlin/package/web/rest/PublicUserResourceIT.kt.ejs @@ -24,7 +24,7 @@ import <%= packageName %>.security.USER <%_ if (authenticationTypeOauth2) { _%> import <%= packageName %>.config.TestSecurityConfiguration <%_ } _%> -import <%= packageName %>.domain.<%= asEntity('User') %> +import <%= packageName %>.domain.<%= user.persistClass %> import <%= packageName %>.repository.UserRepository <%_ if (searchEngineElasticsearch) { _%> import <%= packageName %>.repository.search.UserSearchRepository @@ -40,7 +40,7 @@ import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWeb <%_ } else { _%> import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc <%_ } _%> -<%_ if (cacheManagerIsAvailable) { _%> +<%_ if (cacheProviderAny) { _%> import org.springframework.cache.CacheManager <%_ } _%> <%_ if (cacheProviderMemcached ) { _%> @@ -53,7 +53,7 @@ import org.springframework.security.test.context.TestSecurityContextHolder <%_ } _%> import org.springframework.security.test.context.support.WithMockUser <%_ if (reactive) { _%> -import <%= packageName %>.service.dto.<%= asDto('User') %> +import <%= packageName %>.service.dto.<%= user.restClass %> import org.springframework.test.web.reactive.server.WebTestClient <%_ } else { _%> import org.springframework.test.web.servlet.MockMvc @@ -82,7 +82,7 @@ import org.assertj.core.api.Assertions.assertThat <%_ if (reactive && searchEngineElasticsearch) { _%> import org.mockito.Mockito.* <%_ } _%> -<%_ if (reactive && testsNeedCsrf) { _%> +<%_ if (reactive && authenticationUsesCsrf) { _%> import org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.csrf <%_ } else if (!reactive) { _%> <%_ if (databaseTypeSql || databaseTypeMongodb || databaseTypeNeo4j || databaseTypeCouchbase) { _%> @@ -129,7 +129,7 @@ class PublicUserResourceIT { @Autowired private lateinit var em: EntityManager <%_ } _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> @Autowired private lateinit var cacheManager: CacheManager @@ -142,9 +142,9 @@ class PublicUserResourceIT { private lateinit var restUserMockMvc: MockMvc <%_ } _%> - private lateinit var user: <%= asEntity('User') %> + private lateinit var user: <%= user.persistClass %> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> @BeforeEach fun setup() { cacheManager.getCache(UserRepository.USERS_BY_LOGIN_CACHE).clear() @@ -152,7 +152,7 @@ class PublicUserResourceIT { } <%_ } _%> - <%_ if (reactive && testsNeedCsrf) { _%> + <%_ if (reactive && authenticationUsesCsrf) { _%> @BeforeEach fun setupCsrf() { webTestClient = webTestClient.mutateWith(csrf()) @@ -182,7 +182,7 @@ class PublicUserResourceIT { .exchange() .expectStatus().isOk .expectHeader().contentType(MediaType.APPLICATION_JSON) - .returnResult(<%= asDto('User') %>::class.java).responseBody.blockFirst() + .returnResult(<%= user.restClass %>::class.java).responseBody.blockFirst() assertThat(foundUser.login).isEqualTo(DEFAULT_LOGIN) <%_ for (field of user.fields.filter(field => !field.builtIn && field.relatedByOtherEntity)) { _%> diff --git a/generators/spring-boot/templates/src/test/kotlin/package/web/rest/UserJWTControllerIT.kt.ejs b/generators/spring-boot/templates/src/test/kotlin/package/web/rest/UserJWTControllerIT.kt.ejs index 80a36c64c..31ee78526 100644 --- a/generators/spring-boot/templates/src/test/kotlin/package/web/rest/UserJWTControllerIT.kt.ejs +++ b/generators/spring-boot/templates/src/test/kotlin/package/web/rest/UserJWTControllerIT.kt.ejs @@ -23,7 +23,7 @@ import <%= packageName %>.IntegrationTest import <%= packageName %>.config.SYSTEM_ACCOUNT <%_ } _%> <%_ if (!skipUserManagement) { _%> -import <%= packageName %>.domain.<%= asEntity('User') %> +import <%= packageName %>.domain.<%= user.persistClass %> import <%= packageName %>.repository.UserRepository <%_ } _%> import <%= packageName %>.web.rest.vm.LoginVM @@ -92,7 +92,7 @@ class UserJWTControllerIT { <%_ } _%> @Throws(Exception::class) fun testAuthorize() { - val user = <%= asEntity('User') %>( + val user = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> @@ -143,7 +143,7 @@ class UserJWTControllerIT { <%_ } _%> @Throws(Exception::class) fun testAuthorizeWithRememberMe() { - val user = <%= asEntity('User') %>( + val user = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> diff --git a/generators/spring-boot/templates/src/test/kotlin/package/web/rest/UserResourceIT.kt.ejs b/generators/spring-boot/templates/src/test/kotlin/package/web/rest/UserResourceIT.kt.ejs index 17e24a0c7..1f5293088 100644 --- a/generators/spring-boot/templates/src/test/kotlin/package/web/rest/UserResourceIT.kt.ejs +++ b/generators/spring-boot/templates/src/test/kotlin/package/web/rest/UserResourceIT.kt.ejs @@ -34,7 +34,7 @@ import <%= packageName %>.config.SYSTEM_ACCOUNT <%_ if (!databaseTypeCassandra && !databaseTypeCouchbase) { _%> import <%= packageName %>.domain.Authority <%_ } _%> -import <%= packageName %>.domain.<%= asEntity('User') %> +import <%= packageName %>.domain.<%= user.persistClass %> <%_ if (databaseTypeSql && reactive) { _%> import <%= packageName %>.repository.AuthorityRepository <%_ } _%> @@ -44,7 +44,7 @@ import <%= packageName %>.repository.search.UserSearchRepository <%_ } _%> import <%= packageName %>.security.ADMIN import <%= packageName %>.security.USER -import <%= packageName %>.service.dto.<%= asDto('AdminUser') %> +import <%= packageName %>.service.dto.<%= user.adminUserDto %> <%_ if (databaseTypeSql && reactive) { _%> import <%= packageName %>.repository.EntityManager <%_ } _%> @@ -61,7 +61,7 @@ import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWeb <%_ } else { _%> import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc <%_ } _%> -<%_ if (cacheManagerIsAvailable) { _%> +<%_ if (cacheProviderAny) { _%> import org.springframework.cache.CacheManager <%_ } _%> <%_ if (cacheProviderMemcached ) { _%> @@ -98,11 +98,11 @@ import org.assertj.core.api.Assertions.assertThat <%_ if (reactive && searchEngineElasticsearch) { _%> import org.mockito.Mockito.* <%_ } _%> -<%_ if (reactive && testsNeedCsrf) { _%> +<%_ if (reactive && authenticationUsesCsrf) { _%> import org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.csrf <%_ } else if (!reactive) { _%> import org.hamcrest.Matchers.hasItem -<%_ if (testsNeedCsrf) { _%> +<%_ if (authenticationUsesCsrf) { _%> import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf <%_ } _%> import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete @@ -112,12 +112,12 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status -<%_ } else if (testsNeedCsrf) { _%> +<%_ } else if (authenticationUsesCsrf) { _%> import org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.csrf <%_ } _%> import kotlin.test.assertNotNull -<%_ if (cacheManagerIsAvailable) { _%> +<%_ if (cacheProviderAny) { _%> import kotlin.test.assertNull <%_ } _%> @@ -155,7 +155,7 @@ class UserResourceIT { @Autowired private lateinit var em: EntityManager <%_ } _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> @Autowired private lateinit var cacheManager: CacheManager @@ -168,9 +168,9 @@ class UserResourceIT { private lateinit var restUserMockMvc: MockMvc <%_ } _%> - private lateinit var user: <%= asEntity('User') %> + private lateinit var user: <%= user.persistClass %> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> @BeforeEach fun setup() { cacheManager.getCache(UserRepository.USERS_BY_LOGIN_CACHE)!!.clear() @@ -178,7 +178,7 @@ class UserResourceIT { } <%_ } _%> - <%_ if (reactive && testsNeedCsrf) { _%> + <%_ if (reactive && authenticationUsesCsrf) { _%> @BeforeEach fun setupCsrf() { webTestClient = webTestClient.mutateWith(csrf()) @@ -224,7 +224,7 @@ class UserResourceIT { restUserMockMvc.perform( post("/api/admin/users") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(managedUserVM))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(managedUserVM))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().isCreated) @@ -292,7 +292,7 @@ class UserResourceIT { restUserMockMvc.perform( post("/api/admin/users") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(managedUserVM))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(managedUserVM))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().isBadRequest) @@ -349,7 +349,7 @@ class UserResourceIT { restUserMockMvc.perform( post("/api/admin/users") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(managedUserVM))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(managedUserVM))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().isBadRequest) @@ -403,7 +403,7 @@ class UserResourceIT { restUserMockMvc.perform( post("/api/admin/users") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(managedUserVM))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(managedUserVM))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().isBadRequest) @@ -440,7 +440,7 @@ class UserResourceIT { .exchange() .expectStatus().isOk .expectHeader().contentType(MediaType.APPLICATION_JSON) - .returnResult(<%= asDto('AdminUser') %>::class.java).responseBody.blockFirst() + .returnResult(<%= user.adminUserDto %>::class.java).responseBody.blockFirst() assertNotNull(foundUser) assertThat(foundUser.login).isEqualTo(DEFAULT_LOGIN) @@ -498,7 +498,7 @@ class UserResourceIT { <%_ if (searchEngineElasticsearch) { _%> userSearchRepository.save(user) <%_ } _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> assertNull(cacheManager.getCache(UserRepository.USERS_BY_LOGIN_CACHE)!!.get(user.login!!)) <%_ } _%> @@ -537,7 +537,7 @@ class UserResourceIT { if (cacheManager !is NoOpCacheManager) { assertThat(cacheManager.getCache(UserRepository.USERS_BY_LOGIN_CACHE)!!.get(user.login!!)).isNotNull } - <%_ } else if (cacheManagerIsAvailable) { _%> + <%_ } else if (cacheProviderAny) { _%> assertNotNull(cacheManager.getCache(UserRepository.USERS_BY_LOGIN_CACHE)!!.get(user.login!!)) <%_ } _%> @@ -613,7 +613,7 @@ class UserResourceIT { restUserMockMvc.perform( put("/api/admin/users") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(managedUserVM))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(managedUserVM))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().isOk) @@ -683,7 +683,7 @@ class UserResourceIT { restUserMockMvc.perform( put("/api/admin/users") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(managedUserVM))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(managedUserVM))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().isOk) @@ -720,7 +720,7 @@ class UserResourceIT { userSearchRepository.save(user) <%_ } _%> - val anotherUser = <%= asEntity('User') %>( + val anotherUser = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> @@ -778,7 +778,7 @@ class UserResourceIT { restUserMockMvc.perform( put("/api/admin/users") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(managedUserVM))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(managedUserVM))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().isBadRequest) @@ -802,7 +802,7 @@ class UserResourceIT { userSearchRepository.save(user) <%_ } _%> - val anotherUser = <%= asEntity('User') %>( + val anotherUser = <%= user.persistClass %>( <%_ if (databaseTypeCassandra) { _%> id = UUID.randomUUID().toString(), <%_ } _%> @@ -860,7 +860,7 @@ class UserResourceIT { restUserMockMvc.perform( put("/api/admin/users") .contentType(MediaType.APPLICATION_JSON) - .content(convertObjectToJsonBytes(managedUserVM))<% if (testsNeedCsrf) { %> + .content(convertObjectToJsonBytes(managedUserVM))<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().isBadRequest) @@ -894,12 +894,12 @@ class UserResourceIT { <%_ } else { _%> restUserMockMvc.perform( delete("/api/admin/users/{login}", user.login) - .accept(MediaType.APPLICATION_JSON)<% if (testsNeedCsrf) { %> + .accept(MediaType.APPLICATION_JSON)<% if (authenticationUsesCsrf) { %> .with(csrf())<% } %> ) .andExpect(status().isNoContent) <%_ } _%> - <%_ if (cacheManagerIsAvailable) { _%> + <%_ if (cacheProviderAny) { _%> assertNull(cacheManager.getCache(UserRepository.USERS_BY_LOGIN_CACHE)!!.get(user.login!!)) <%_ } _%> @@ -912,11 +912,11 @@ class UserResourceIT { @Test @Throws(Exception::class) fun testUserEquals() { - equalsVerifier(<%= asEntity('User') %>::class) - val user1 = <%= asEntity('User') %>(id = DEFAULT_ID) - val user2 = <%= asEntity('User') %>(id = user1.id) + equalsVerifier(<%= user.persistClass %>::class) + val user1 = <%= user.persistClass %>(id = DEFAULT_ID) + val user2 = <%= user.persistClass %>(id = user1.id) assertThat(user1).isEqualTo(user2) - user2.id = <%- getPrimaryKeyValue(user.primaryKey.type, databaseType, 2) %> + user2.id = <%- this.getPrimaryKeyValue(user.primaryKey.type, databaseType, 2) %> assertThat(user1).isNotEqualTo(user2) user1.id = null assertThat(user1).isNotEqualTo(user2) @@ -924,7 +924,7 @@ class UserResourceIT { @Test fun testUserDTOtoUser() { - val userDTO = <%= asDto('AdminUser') %>( + val userDTO = <%= user.adminUserDto %>( id = DEFAULT_ID, login = DEFAULT_LOGIN, firstName = DEFAULT_FIRSTNAME, @@ -1036,7 +1036,7 @@ class UserResourceIT { <%_ if (databaseTypeCouchbase){ _%> private const val DEFAULT_ID = DEFAULT_LOGIN <%_ } else { _%> - private const val DEFAULT_ID = <%- getPrimaryKeyValue(user.primaryKey.type) %> + private const val DEFAULT_ID = <%- this.getPrimaryKeyValue(user.primaryKey.type) %> <%_ } _%> <%_ if (!authenticationTypeOauth2) { _%> @@ -1078,8 +1078,8 @@ class UserResourceIT { * if they test an entity which has a required relationship to the User entity. */ @JvmStatic - fun createEntity(<% if (databaseTypeSql) { %>em: EntityManager?<% } %>): <%= asEntity('User') %> { - return <%= asEntity('User') %>( + fun createEntity(<% if (databaseTypeSql) { %>em: EntityManager?<% } %>): <%= user.persistClass %> { + return <%= user.persistClass %>( <%_ if (databaseTypeCassandra || (authenticationTypeOauth2 && !databaseTypeCouchbase)) { _%> id = UUID.randomUUID().toString(), <%_ } _%> @@ -1110,7 +1110,7 @@ class UserResourceIT { fun deleteEntities(em: EntityManager) { try { em.deleteAll("<%= jhiTablePrefix %>_user_authority").block() - em.deleteAll(<%= asEntity('User') %>::class.java).block() + em.deleteAll(<%= user.persistClass %>::class.java).block() } catch (e: Exception) { // It can fail, if other entities are still referring this - it will be removed later. } @@ -1121,7 +1121,7 @@ class UserResourceIT { * Setups the database with one user. */ @JvmStatic - fun initTestUser(userRepository: UserRepository<% if (databaseTypeSql ) { %>, em: EntityManager<% } _%>): <%= asEntity('User') %> { + fun initTestUser(userRepository: UserRepository<% if (databaseTypeSql ) { %>, em: EntityManager<% } _%>): <%= user.persistClass %> { <%_ if (databaseTypeSql && reactive) { _%> userRepository.deleteAllUserAuthorities().block() <%_ } _%> @@ -1135,7 +1135,7 @@ class UserResourceIT { } } - fun assertPersistedUsers(userAssertion: (List<<%= asEntity('User') %>>) -> Unit) { + fun assertPersistedUsers(userAssertion: (List<<%= user.persistClass %>>) -> Unit) { <%_ if (databaseTypeCouchbase) { _%> // The security filter chain clears the security context after remote calls SecurityContextHolder.setContext(TestSecurityContextHolder.getContext()) diff --git a/generators/spring-boot/templates/src/test/kotlin/package/web/rest/errors/ExceptionTranslatorIT.kt.ejs b/generators/spring-boot/templates/src/test/kotlin/package/web/rest/errors/ExceptionTranslatorIT.kt.ejs index 7d3d3a7ec..007511be2 100644 --- a/generators/spring-boot/templates/src/test/kotlin/package/web/rest/errors/ExceptionTranslatorIT.kt.ejs +++ b/generators/spring-boot/templates/src/test/kotlin/package/web/rest/errors/ExceptionTranslatorIT.kt.ejs @@ -28,7 +28,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock import org.springframework.http.MediaType import org.springframework.test.web.servlet.MockMvc -<%_ if (testsNeedCsrf) { _%> +<%_ if (authenticationUsesCsrf) { _%> import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf <%_ } _%> import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get @@ -53,7 +53,7 @@ class ExceptionTranslatorIT { @Test @Throws(Exception::class) fun testConcurrencyFailure() { - mockMvc.perform(get("/api/exception-translator-test/concurrency-failure")<% if (testsNeedCsrf) { %>.with(csrf())<% } %>) + mockMvc.perform(get("/api/exception-translator-test/concurrency-failure")<% if (authenticationUsesCsrf) { %>.with(csrf())<% } %>) .andExpect(status().isConflict) .andExpect(content().contentType(MediaType.APPLICATION_PROBLEM_JSON)) .andExpect(jsonPath("\$.message").value(ERR_CONCURRENCY_FAILURE)) @@ -63,7 +63,7 @@ class ExceptionTranslatorIT { @Test @Throws(Exception::class) fun testMethodArgumentNotValid() { - mockMvc.perform(post("/api/exception-translator-test/method-argument").content("{}").contentType(MediaType.APPLICATION_JSON)<% if (testsNeedCsrf) { %>.with(csrf())<% } %>) + mockMvc.perform(post("/api/exception-translator-test/method-argument").content("{}").contentType(MediaType.APPLICATION_JSON)<% if (authenticationUsesCsrf) { %>.with(csrf())<% } %>) .andExpect(status().isBadRequest) .andExpect(content().contentType(MediaType.APPLICATION_PROBLEM_JSON)) .andExpect(jsonPath("\$.message").value(ERR_VALIDATION)) @@ -75,7 +75,7 @@ class ExceptionTranslatorIT { @Test @Throws(Exception::class) fun testMissingServletRequestPartException() { - mockMvc.perform(get("/api/exception-translator-test/missing-servlet-request-part")<% if (testsNeedCsrf) { %>.with(csrf())<% } %>) + mockMvc.perform(get("/api/exception-translator-test/missing-servlet-request-part")<% if (authenticationUsesCsrf) { %>.with(csrf())<% } %>) .andExpect(status().isBadRequest) .andExpect(content().contentType(MediaType.APPLICATION_PROBLEM_JSON)) .andExpect(jsonPath("\$.message").value("error.http.400")) @@ -84,7 +84,7 @@ class ExceptionTranslatorIT { @Test @Throws(Exception::class) fun testMissingServletRequestParameterException() { - mockMvc.perform(get("/api/exception-translator-test/missing-servlet-request-parameter")<% if (testsNeedCsrf) { %>.with(csrf())<% } %>) + mockMvc.perform(get("/api/exception-translator-test/missing-servlet-request-parameter")<% if (authenticationUsesCsrf) { %>.with(csrf())<% } %>) .andExpect(status().isBadRequest) .andExpect(content().contentType(MediaType.APPLICATION_PROBLEM_JSON)) .andExpect(jsonPath("\$.message").value("error.http.400")) @@ -93,7 +93,7 @@ class ExceptionTranslatorIT { @Test @Throws(Exception::class) fun testAccessDenied() { - mockMvc.perform(get("/api/exception-translator-test/access-denied")<% if (testsNeedCsrf) { %>.with(csrf())<% } %>) + mockMvc.perform(get("/api/exception-translator-test/access-denied")<% if (authenticationUsesCsrf) { %>.with(csrf())<% } %>) .andExpect(status().isForbidden) .andExpect(content().contentType(MediaType.APPLICATION_PROBLEM_JSON)) .andExpect(jsonPath("\$.message").value("error.http.403")) @@ -103,7 +103,7 @@ class ExceptionTranslatorIT { @Test @Throws(Exception::class) fun testUnauthorized() { - mockMvc.perform(get("/api/exception-translator-test/unauthorized")<% if (testsNeedCsrf) { %>.with(csrf())<% } %>) + mockMvc.perform(get("/api/exception-translator-test/unauthorized")<% if (authenticationUsesCsrf) { %>.with(csrf())<% } %>) .andExpect(status().isUnauthorized) .andExpect(content().contentType(MediaType.APPLICATION_PROBLEM_JSON)) .andExpect(jsonPath("\$.message").value("error.http.401")) @@ -114,7 +114,7 @@ class ExceptionTranslatorIT { @Test @Throws(Exception::class) fun testMethodNotSupported() { - mockMvc.perform(post("/api/exception-translator-test/access-denied")<% if (testsNeedCsrf) { %>.with(csrf())<% } %>) + mockMvc.perform(post("/api/exception-translator-test/access-denied")<% if (authenticationUsesCsrf) { %>.with(csrf())<% } %>) .andExpect(status().isMethodNotAllowed) .andExpect(content().contentType(MediaType.APPLICATION_PROBLEM_JSON)) .andExpect(jsonPath("\$.message").value("error.http.405")) @@ -124,7 +124,7 @@ class ExceptionTranslatorIT { @Test @Throws(Exception::class) fun testExceptionWithResponseStatus() { - mockMvc.perform(get("/api/exception-translator-test/response-status")<% if (testsNeedCsrf) { %>.with(csrf())<% } %>) + mockMvc.perform(get("/api/exception-translator-test/response-status")<% if (authenticationUsesCsrf) { %>.with(csrf())<% } %>) .andExpect(status().isBadRequest) .andExpect(content().contentType(MediaType.APPLICATION_PROBLEM_JSON)) .andExpect(jsonPath("\$.message").value("error.http.400")) @@ -134,7 +134,7 @@ class ExceptionTranslatorIT { @Test @Throws(Exception::class) fun testInternalServerError() { - mockMvc.perform(get("/api/exception-translator-test/internal-server-error")<% if (testsNeedCsrf) { %>.with(csrf())<% } %>) + mockMvc.perform(get("/api/exception-translator-test/internal-server-error")<% if (authenticationUsesCsrf) { %>.with(csrf())<% } %>) .andExpect(status().isInternalServerError) .andExpect(content().contentType(MediaType.APPLICATION_PROBLEM_JSON)) .andExpect(jsonPath("\$.message").value("error.http.500")) diff --git a/generators/spring-boot/templates/src/test/kotlin/package/web/rest/errors/ExceptionTranslatorIT_reactive.kt.ejs b/generators/spring-boot/templates/src/test/kotlin/package/web/rest/errors/ExceptionTranslatorIT_reactive.kt.ejs index ae1d760f8..2dd5eb1ca 100644 --- a/generators/spring-boot/templates/src/test/kotlin/package/web/rest/errors/ExceptionTranslatorIT_reactive.kt.ejs +++ b/generators/spring-boot/templates/src/test/kotlin/package/web/rest/errors/ExceptionTranslatorIT_reactive.kt.ejs @@ -24,14 +24,14 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest import org.springframework.security.test.context.support.WithMockUser - <%_ if (testsNeedCsrf) { _%> + <%_ if (authenticationUsesCsrf) { _%> import org.junit.jupiter.api.BeforeEach <%_ } _%> import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient import org.springframework.http.HttpStatus import org.springframework.http.MediaType import org.springframework.test.web.reactive.server.WebTestClient -<%_ if (testsNeedCsrf) { _%> +<%_ if (authenticationUsesCsrf) { _%> import org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.csrf <%_ } _%> @@ -45,7 +45,7 @@ class ExceptionTranslatorIT { @Autowired private lateinit var webTestClient: WebTestClient - <%_ if (testsNeedCsrf) { _%> + <%_ if (authenticationUsesCsrf) { _%> @BeforeEach fun setupCsrf() { diff --git a/test/__snapshots__/app.spec.js.snap b/test/__snapshots__/app.spec.js.snap index 89cc7413c..bb2b95ae9 100644 --- a/test/__snapshots__/app.spec.js.snap +++ b/test/__snapshots__/app.spec.js.snap @@ -2520,9 +2520,6 @@ exports[`JHipster generator for App generator > Application with other options > "src/main/resources/config/application.yml": { "stateCleared": "modified", }, - "src/main/resources/config/liquibase/data/user.csv": { - "stateCleared": "modified", - }, "src/main/resources/config/tls/keystore.p12": { "stateCleared": "modified", },