Skip to content

Commit

Permalink
migrate kafka templates
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Aug 5, 2024
1 parent 37c7e1c commit 74f0ede
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 14 deletions.
11 changes: 11 additions & 0 deletions generators/spring-boot-v2/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,17 @@ export default class extends BaseApplicationGenerator {
'AuthorizationHeaderUtilTest.java',
'AuthorizationHeaderUtil.java',
'OAuthIdpTokenResponseDTO.java',
// jhipster:spring-cloud-stream:kafka
'KafkaTestContainer.java',
'EmbeddedKafka.java',
'EmbeddedKafka.java',
'EmbeddedKafka.java',
'KafkaResource.java',
'KafkaResourceIT.java',
'KafkaResource_reactive.java',
'KafkaResourceIT_reactive.java',
'KafkaSseConsumer.java',
'KafkaSseProducer.java',
// jhipster:java:openapi-generator v7.6.1
// 'swagger.gradle',
].includes(sourceBasename)
Expand Down
13 changes: 5 additions & 8 deletions generators/spring-boot/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ export default class extends BaseApplicationGenerator {
application.customizeTemplatePaths.unshift(
// Remove package-info.java files
file => (file.sourceFile.includes('package-info.java') ? undefined : file),
// Ignore files from generators
file =>
['jhipster:spring-cloud-stream:kafka', 'jhipster:spring-cloud-stream:pulsar'].includes(file.namespace) &&
!file.sourceFile.includes('buildSrc')
? undefined
: file,
// Kotling blueprint does not implements these files
file => {
const sourceBasename = basename(file.sourceFile);
Expand Down Expand Up @@ -122,6 +116,7 @@ export default class extends BaseApplicationGenerator {
destinationFile = adjustTestContainersSpringContextCustomizerFactoryFile(destinationFile);
}

sourceFile = sourceFile.replace('KafkaConsumer_reactive', 'KafkaConsumer_imperative');
sourceFile = convertToKotlinFile(sourceFile);
destinationFile = convertToKotlinFile(destinationFile);
}
Expand All @@ -143,14 +138,16 @@ export default class extends BaseApplicationGenerator {

return { ...file, sourceFile, javaResolvedSourceFile, resolvedSourceFile, destinationFile };
},
// Adjust feign-client for jhipster 7 paths
// Adjust feign-client and kafka destinationFile for jhipster 7 paths
file => {
if (file.namespace !== 'jhipster:feign-client') return file;
if (!['jhipster:feign-client', 'jhipster:spring-cloud-stream:kafka'].includes(file.namespace)) return file;
const renamedFiles = file => {
for (const fileMap of [
['security/oauth2/AuthorizationHeaderUtilTest.', 'client/AuthorizationHeaderUtilTest.'],
['security/oauth2/AuthorizationHeaderUtil.', 'client/AuthorizationHeaderUtil.'],
['security/oauth2/OAuthIdpTokenResponseDTO.', 'client/OAuthIdpTokenResponseDTO.'],
['config/KafkaSseConsumer.', 'broker/KafkaConsumer.'],
['config/KafkaSseProducer.', 'broker/KafkaProducer.'],
]) {
// Files renamed in v8
file = file.replace(...fileMap.reverse());
Expand Down
12 changes: 10 additions & 2 deletions generators/spring-boot/templates.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ describe('test if kotlin templates has a matching java template', async () => {
// Partials reworked
!file.includes('relationship_validators.ejs') &&
// Modularized file in JHipster 8
!file.includes('_entityClass_Repository'),
!file.includes('_entityClass_Repository') &&
// Mapped to KafkaResourceIT_imperative
!file.includes('KafkaResourceIT_reactive'),
)) {
const javaTemplate = file.replace('.kt', '.java').replace('kotlin/_package_', 'java/_package_');
const possibleTemplates = [];
Expand All @@ -39,7 +41,13 @@ describe('test if kotlin templates has a matching java template', async () => {
if (['domain'].includes(folder)) {
possibleTemplates.push(join(jhipster8Generators, 'java/generators', folder, 'templates', javaTemplateRelativePath));
} else if (['gateway'].includes(folder)) {
possibleTemplates.push(join(jhipster8Generators, 'spring-cloud/generators', folder, 'templates', javaTemplateRelativePath));
possibleTemplates.push(
join(jhipster8Generators, 'spring-cloud/generators', folder, 'templates', javaTemplateRelativePath),
);
} else if (['kafka'].includes(folder)) {
possibleTemplates.push(
join(jhipster8Generators, 'spring-cloud-stream/generators', folder, 'templates', javaTemplateRelativePath),
);
} else {
possibleTemplates.push(join(jhipster8Generators, folder, 'templates', javaTemplateRelativePath));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import <%= packageName %>.config.KafkaSseProducer
@RestController
@RequestMapping("/api/<%= dasherizedBaseName %>-kafka")
class <%= upperFirstCamelCase(baseName) %>KafkaResource(
class <%= upperFirstCamelCaseBaseName %>KafkaResource(
@Qualifier(KafkaSseProducer.CHANNELNAME) val output: MessageChannel
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import <%= packageName %>.config.KafkaSseProducer

@RestController
@RequestMapping("/api/<%= dasherizedBaseName %>-kafka")
class <%= upperFirstCamelCase(baseName) %>KafkaResource(@Qualifier(KafkaSseProducer.CHANNELNAME) val output: MessageChannel) {
class <%= upperFirstCamelCaseBaseName %>KafkaResource(@Qualifier(KafkaSseProducer.CHANNELNAME) val output: MessageChannel) {

private val log = LoggerFactory.getLogger(javaClass)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import <%= packageName %>.config.KafkaSseProducer;
@AutoConfigureMockMvc
@WithMockUser
@EmbeddedKafka
class <%= upperFirstCamelCase(baseName) %>KafkaResourceIT {
class <%= upperFirstCamelCaseBaseName %>KafkaResourceIT {
@Autowired
private lateinit var collector: MessageCollector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import <%= packageName %>.config.KafkaSseProducer
@AutoConfigureMockMvc
@WithMockUser
@EmbeddedKafka
class <%= upperFirstCamelCase(baseName) %>KafkaResourceIT {
class <%= upperFirstCamelCaseBaseName %>KafkaResourceIT {

@Autowired
private lateinit var client: WebTestClient
Expand Down

0 comments on commit 74f0ede

Please sign in to comment.