Repository: jhipster/jhipster-lite
Pull request #11342 (2024-11-11 10:37:37)

Refactoring LangChain4j
it should fix the current CI in main branch too


Patch:
diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/application/LangChain4JApplicationService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/application/LangChain4jApplicationService.java
similarity index 68%
rename from src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/application/LangChain4JApplicationService.java
rename to src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/application/LangChain4jApplicationService.java
index 2dfcfdf80..1576bb54e 100644
--- a/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/application/LangChain4JApplicationService.java
+++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/application/LangChain4jApplicationService.java
@@ -1,17 +1,17 @@
 package tech.jhipster.lite.generator.server.springboot.langchain4j.application;
 
 import org.springframework.stereotype.Service;
-import tech.jhipster.lite.generator.server.springboot.langchain4j.domain.LangChain4JModuleFactory;
+import tech.jhipster.lite.generator.server.springboot.langchain4j.domain.LangChain4jModuleFactory;
 import tech.jhipster.lite.module.domain.JHipsterModule;
 import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
 
 @Service
-public class LangChain4JApplicationService {
+public class LangChain4jApplicationService {
 
-  private final LangChain4JModuleFactory factory;
+  private final LangChain4jModuleFactory factory;
 
-  public LangChain4JApplicationService() {
-    factory = new LangChain4JModuleFactory();
+  public LangChain4jApplicationService() {
+    factory = new LangChain4jModuleFactory();
   }
 
   public JHipsterModule buildModule(JHipsterModuleProperties properties) {
diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4jModuleFactory.java
similarity index 91%
rename from src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactory.java
rename to src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4jModuleFactory.java
index 9465f0473..09dbe3d6e 100644
--- a/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactory.java
+++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4jModuleFactory.java
@@ -11,7 +11,7 @@ import tech.jhipster.lite.module.domain.javaproperties.PropertyKey;
 import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
 import tech.jhipster.lite.shared.error.domain.Assert;
 
-public class LangChain4JModuleFactory {
+public class LangChain4jModuleFactory {
 
   private static final String API_KEY_DEMO_COMMENT =
     "You can temporarily use 'demo' key, which is provided for free for demonstration purposes";
@@ -30,13 +30,13 @@ public class LangChain4JModuleFactory {
 
     //@formatter:off
     return moduleBuilder(properties)
-      .documentation(documentationTitle("Dev tools"), SOURCE.template("langchain4j.md"))
+      .documentation(documentationTitle("LangChain4j"), SOURCE.template("langchain4j.md"))
       .javaDependencies()
         .addDependency(GROUP_ID, ARTIFACT_ID, VERSION_SLUG)
         .addDependency(GROUP_ID, OPEN_AI_ARTIFACT_ID, VERSION_SLUG)
         .and()
       .springMainProperties()
-        .set(LANGCHAIN4J_PROPERTY_API_KEY, propertyValue("${OPENAI_API_KEY}"))
+        .set(LANGCHAIN4J_PROPERTY_API_KEY, propertyValue("demo"))
           .comment(LANGCHAIN4J_PROPERTY_API_KEY, comment(API_KEY_DEMO_COMMENT))
         .set(propertyKey("langchain4j.open-ai.chat-model.model-name"), propertyValue("gpt-4o-mini"))
         .set(propertyKey("langchain4j.open-ai.chat-model.log-requests"), propertyValue("true"))
diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/infrastructure/primary/LangChain4JModuleConfiguration.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/infrastructure/primary/LangChain4jModuleConfiguration.java
similarity index 79%
rename from src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/infrastructure/primary/LangChain4JModuleConfiguration.java
rename to src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/infrastructure/primary/LangChain4jModuleConfiguration.java
index b9a427a58..870e2f540 100644
--- a/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/infrastructure/primary/LangChain4JModuleConfiguration.java
+++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/infrastructure/primary/LangChain4jModuleConfiguration.java
@@ -5,22 +5,22 @@ import static tech.jhipster.lite.shared.slug.domain.JHLiteModuleSlug.SPRING_BOOT
 
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
-import tech.jhipster.lite.generator.server.springboot.langchain4j.application.LangChain4JApplicationService;
+import tech.jhipster.lite.generator.server.springboot.langchain4j.application.LangChain4jApplicationService;
 import tech.jhipster.lite.module.domain.resource.JHipsterModuleOrganization;
 import tech.jhipster.lite.module.domain.resource.JHipsterModulePropertiesDefinition;
 import tech.jhipster.lite.module.domain.resource.JHipsterModuleResource;
 
 @Configuration
-class LangChain4JModuleConfiguration {
+class LangChain4jModuleConfiguration {
 
   @Bean
-  JHipsterModuleResource langChain4JModule(LangChain4JApplicationService langChain4J) {
+  JHipsterModuleResource langChain4jModule(LangChain4jApplicationService langChain4j) {
     return JHipsterModuleResource.builder()
       .slug(LANGCHAIN4J)
       .propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addProjectBaseName().addIndentation().build())
-      .apiDoc("LangChain4J", "Add LangChain4j")
+      .apiDoc("LangChain4j", "Add LangChain4j")
       .organization(JHipsterModuleOrganization.builder().addDependency(SPRING_BOOT).build())
       .tags("server", "spring", "spring-boot", "langchain4j")
-      .factory(langChain4J::buildModule);
+      .factory(langChain4j::buildModule);
   }
 }


Test patch:
diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4jModuleFactoryTest.java
similarity index 93%
rename from src/test/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactoryTest.java
rename to src/test/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4jModuleFactoryTest.java
index 15e4afb3c..b4d83f5ce 100644
--- a/src/test/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactoryTest.java
+++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4jModuleFactoryTest.java
@@ -15,10 +15,10 @@ import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
 
 @UnitTest
 @ExtendWith(MockitoExtension.class)
-class LangChain4JModuleFactoryTest {
+class LangChain4jModuleFactoryTest {
 
   @InjectMocks
-  private LangChain4JModuleFactory factory;
+  private LangChain4jModuleFactory factory;
 
   @Test
   void shouldCreateModule() {
@@ -29,6 +29,7 @@ class LangChain4JModuleFactoryTest {
     JHipsterModule module = factory.buildModule(properties);
 
     assertThatModuleWithFiles(module, pomFile())
+      .hasFiles("documentation/langchain4j.md")
       .hasFile("pom.xml")
       .containing("<langchain4j.version>")
       .containing(
@@ -57,7 +58,7 @@ class LangChain4JModuleFactoryTest {
           open-ai:
             chat-model:
               # You can temporarily use 'demo' key, which is provided for free for demonstration purposes
-              api-key: ${OPENAI_API_KEY}
+              api-key: demo
               log-requests: 'true'
               log-responses: 'true'
               model-name: gpt-4o-mini