Repository: jhipster/jhipster-lite
Pull request #11814 (2025-01-27 13:13:10)

implement rank mapper and rest dto
- related to https://github.com/jhipster/jhipster-lite/issues/10934


Patch:
diff --git a/src/main/java/tech/jhipster/lite/module/domain/landscape/JHipsterLandscape.java b/src/main/java/tech/jhipster/lite/module/domain/landscape/JHipsterLandscape.java
index 6672ad553..41708ca2b 100644
--- a/src/main/java/tech/jhipster/lite/module/domain/landscape/JHipsterLandscape.java
+++ b/src/main/java/tech/jhipster/lite/module/domain/landscape/JHipsterLandscape.java
@@ -73,6 +73,7 @@ public final class JHipsterLandscape {
       .module(module.slug())
       .operation(module.operation())
       .propertiesDefinition(module.propertiesDefinition())
+      .rank(module.rank())
       .dependencies(dependenciesWithoutNested(module, knownDependencies));
   }
 
diff --git a/src/main/java/tech/jhipster/lite/module/domain/landscape/JHipsterLandscapeLevels.java b/src/main/java/tech/jhipster/lite/module/domain/landscape/JHipsterLandscapeLevels.java
index 8dffcda4a..52223d30e 100644
--- a/src/main/java/tech/jhipster/lite/module/domain/landscape/JHipsterLandscapeLevels.java
+++ b/src/main/java/tech/jhipster/lite/module/domain/landscape/JHipsterLandscapeLevels.java
@@ -1,12 +1,7 @@
 package tech.jhipster.lite.module.domain.landscape;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.Map.Entry;
-import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.function.Consumer;
 import java.util.function.Function;
@@ -76,6 +71,7 @@ public record JHipsterLandscapeLevels(Collection<JHipsterLandscapeLevel> levels)
         .module(resource.slug())
         .operation(resource.apiDoc().operation())
         .propertiesDefinition(resource.propertiesDefinition())
+        .rank(resource.rank())
         .dependencies(resource.organization().dependencies());
     }
 
diff --git a/src/main/java/tech/jhipster/lite/module/domain/landscape/JHipsterLandscapeModule.java b/src/main/java/tech/jhipster/lite/module/domain/landscape/JHipsterLandscapeModule.java
index ff89124ce..fc8530c85 100644
--- a/src/main/java/tech/jhipster/lite/module/domain/landscape/JHipsterLandscapeModule.java
+++ b/src/main/java/tech/jhipster/lite/module/domain/landscape/JHipsterLandscapeModule.java
@@ -12,6 +12,7 @@ import tech.jhipster.lite.module.domain.JHipsterModuleSlug;
 import tech.jhipster.lite.module.domain.JHipsterSlug;
 import tech.jhipster.lite.module.domain.resource.JHipsterModuleOperation;
 import tech.jhipster.lite.module.domain.resource.JHipsterModulePropertiesDefinition;
+import tech.jhipster.lite.module.domain.resource.JHipsterModuleRank;
 import tech.jhipster.lite.shared.error.domain.Assert;
 import tech.jhipster.lite.shared.generation.domain.ExcludeFromGeneratedCodeCoverage;
 
@@ -21,6 +22,7 @@ public final class JHipsterLandscapeModule implements JHipsterLandscapeElement {
   private final JHipsterModuleOperation operation;
   private final JHipsterModulePropertiesDefinition propertiesDefinition;
   private final Optional<JHipsterLandscapeDependencies> dependencies;
+  private final JHipsterModuleRank rank;
 
   private JHipsterLandscapeModule(JHipsterLandscapeModuleBuilder builder) {
     Assert.notNull("module", builder.module);
@@ -31,6 +33,7 @@ public final class JHipsterLandscapeModule implements JHipsterLandscapeElement {
     operation = builder.operation;
     propertiesDefinition = builder.propertiesDefinition;
     dependencies = JHipsterLandscapeDependencies.of(builder.dependencies);
+    rank = builder.rank;
   }
 
   public static JHipsterLandscapeModuleSlugBuilder builder() {
@@ -50,6 +53,10 @@ public final class JHipsterLandscapeModule implements JHipsterLandscapeElement {
     return propertiesDefinition;
   }
 
+  public JHipsterModuleRank rank() {
+    return rank;
+  }
+
   @Override
   public Optional<JHipsterLandscapeDependencies> dependencies() {
     return dependencies;
@@ -94,6 +101,7 @@ public final class JHipsterLandscapeModule implements JHipsterLandscapeElement {
       .append("operation", operation)
       .append("propertiesDefinition", propertiesDefinition)
       .append("dependencies", dependencies)
+      .append("rank", rank)
       .build();
   }
 
@@ -108,6 +116,7 @@ public final class JHipsterLandscapeModule implements JHipsterLandscapeElement {
     private JHipsterModuleOperation operation;
     private Collection<? extends JHipsterLandscapeDependency> dependencies;
     private JHipsterModulePropertiesDefinition propertiesDefinition;
+    private JHipsterModuleRank rank;
 
     @Override
     public JHipsterLandscapeModuleOperationBuilder module(JHipsterModuleSlug module) {
@@ -130,6 +139,13 @@ public final class JHipsterLandscapeModule implements JHipsterLandscapeElement {
       return this;
     }
 
+    @Override
+    public JHipsterLandscapeModuleDependenciesBuilder rank(JHipsterModuleRank rank) {
+      this.rank = rank;
+
+      return this;
+    }
+
     @Override
     public JHipsterLandscapeModule dependencies(Collection<? extends JHipsterLandscapeDependency> dependencies) {
       this.dependencies = dependencies;
@@ -159,6 +175,8 @@ public final class JHipsterLandscapeModule implements JHipsterLandscapeElement {
   }
 
   public interface JHipsterLandscapeModuleDependenciesBuilder {
+    JHipsterLandscapeModuleDependenciesBuilder rank(JHipsterModuleRank rank);
+
     JHipsterLandscapeModule dependencies(Collection<? extends JHipsterLandscapeDependency> dependencies);
 
     default JHipsterLandscapeModule withoutDependencies() {
diff --git a/src/main/java/tech/jhipster/lite/module/infrastructure/primary/RestJHipsterLandscapeModule.java b/src/main/java/tech/jhipster/lite/module/infrastructure/primary/RestJHipsterLandscapeModule.java
index 4b3d9d4cb..4027f2a85 100644
--- a/src/main/java/tech/jhipster/lite/module/infrastructure/primary/RestJHipsterLandscapeModule.java
+++ b/src/main/java/tech/jhipster/lite/module/infrastructure/primary/RestJHipsterLandscapeModule.java
@@ -7,8 +7,9 @@ import java.util.Collection;
 import java.util.List;
 import tech.jhipster.lite.module.domain.landscape.JHipsterLandscapeElementType;
 import tech.jhipster.lite.module.domain.landscape.JHipsterLandscapeModule;
+import tech.jhipster.lite.module.domain.resource.JHipsterModuleRank;
 
-@JsonPropertyOrder({ "type", "slug", "operation", "properties", "dependencies" })
+@JsonPropertyOrder({ "type", "slug", "operation", "properties", "dependencies", "rank" })
 @Schema(name = "JHipsterLandscapeModule", description = "Module in a landscape")
 final class RestJHipsterLandscapeModule implements RestJHipsterLandscapeElement {
 
@@ -16,12 +17,14 @@ final class RestJHipsterLandscapeModule implements RestJHipsterLandscapeElement
   private final String operation;
   private final RestJHipsterModulePropertiesDefinition properties;
   private final Collection<RestJHipsterLandscapeDependency> dependencies;
+  private final JHipsterModuleRank rank;
 
   private RestJHipsterLandscapeModule(RestJHipsterLandscapeModuleBuilder builder) {
     slug = builder.slug;
     operation = builder.operation;
     properties = builder.properties;
     dependencies = builder.dependencies;
+    rank = builder.rank;
   }
 
   static RestJHipsterLandscapeModule fromModule(JHipsterLandscapeModule module) {
@@ -29,6 +32,7 @@ final class RestJHipsterLandscapeModule implements RestJHipsterLandscapeElement
       .slug(module.slug().get())
       .operation(module.operation().get())
       .properties(RestJHipsterModulePropertiesDefinition.from(module.propertiesDefinition()))
+      .rank(module.rank())
       .dependencies(buildDependencies(module))
       .build();
   }
@@ -66,12 +70,18 @@ final class RestJHipsterLandscapeModule implements RestJHipsterLandscapeElement
     return dependencies;
   }
 
+  @Schema(description = "Rank of this module", requiredMode = RequiredMode.REQUIRED)
+  public JHipsterModuleRank getRank() {
+    return rank;
+  }
+
   private static final class RestJHipsterLandscapeModuleBuilder {
 
     private String slug;
     private String operation;
     private RestJHipsterModulePropertiesDefinition properties;
     private List<RestJHipsterLandscapeDependency> dependencies;
+    private JHipsterModuleRank rank;
 
     public RestJHipsterLandscapeModuleBuilder slug(String slug) {
       this.slug = slug;
@@ -97,6 +107,12 @@ final class RestJHipsterLandscapeModule implements RestJHipsterLandscapeElement
       return this;
     }
 
+    public RestJHipsterLandscapeModuleBuilder rank(JHipsterModuleRank rank) {
+      this.rank = rank;
+
+      return this;
+    }
+
     public RestJHipsterLandscapeModule build() {
       return new RestJHipsterLandscapeModule(this);
     }


Test patch:
diff --git a/src/test/java/tech/jhipster/lite/module/domain/landscape/JHipsterLandscapeFixture.java b/src/test/java/tech/jhipster/lite/module/domain/landscape/JHipsterLandscapeFixture.java
index bfbda4fca..bf3cf2193 100644
--- a/src/test/java/tech/jhipster/lite/module/domain/landscape/JHipsterLandscapeFixture.java
+++ b/src/test/java/tech/jhipster/lite/module/domain/landscape/JHipsterLandscapeFixture.java
@@ -1,5 +1,6 @@
 package tech.jhipster.lite.module.domain.landscape;
 
+import static tech.jhipster.lite.module.domain.resource.JHipsterModuleRank.*;
 import static tech.jhipster.lite.module.domain.resource.JHipsterModulesResourceFixture.*;
 
 import java.util.Collection;
@@ -24,6 +25,7 @@ public final class JHipsterLandscapeFixture {
       .module(slug)
       .operation("operation")
       .propertiesDefinition(propertiesDefinition())
+      .rank(RANK_D)
       .withoutDependencies();
   }
 
@@ -32,6 +34,7 @@ public final class JHipsterLandscapeFixture {
       .module(slug)
       .operation("operation")
       .propertiesDefinition(propertiesDefinition())
+      .rank(RANK_D)
       .dependencies(landscapeModuleDependencies(dependency));
   }
 
diff --git a/src/test/java/tech/jhipster/lite/module/domain/landscape/JHipsterLandscapeTest.java b/src/test/java/tech/jhipster/lite/module/domain/landscape/JHipsterLandscapeTest.java
index f92a7856e..ff4a9f603 100644
--- a/src/test/java/tech/jhipster/lite/module/domain/landscape/JHipsterLandscapeTest.java
+++ b/src/test/java/tech/jhipster/lite/module/domain/landscape/JHipsterLandscapeTest.java
@@ -4,6 +4,7 @@ import static org.assertj.core.api.Assertions.*;
 import static tech.jhipster.lite.module.domain.JHipsterModulesFixture.*;
 import static tech.jhipster.lite.module.domain.landscape.JHipsterLandscapeFixture.*;
 import static tech.jhipster.lite.module.domain.landscape.JHipsterLandscapeFixture.moduleResources;
+import static tech.jhipster.lite.module.domain.resource.JHipsterModuleRank.*;
 import static tech.jhipster.lite.module.domain.resource.JHipsterModulesResourceFixture.*;
 
 import java.util.Iterator;
@@ -147,6 +148,7 @@ class JHipsterLandscapeTest {
             .module("forth")
             .operation("operation")
             .propertiesDefinition(propertiesDefinition())
+            .rank(RANK_D)
             .dependencies(List.of(new JHipsterFeatureDependency(new JHipsterFeatureSlug("my-feature"))))
         )
       );
diff --git a/src/test/java/tech/jhipster/lite/module/infrastructure/primary/RestJHipsterLandscapeTest.java b/src/test/java/tech/jhipster/lite/module/infrastructure/primary/RestJHipsterLandscapeTest.java
index fc2a225e7..ffc599366 100644
--- a/src/test/java/tech/jhipster/lite/module/infrastructure/primary/RestJHipsterLandscapeTest.java
+++ b/src/test/java/tech/jhipster/lite/module/infrastructure/primary/RestJHipsterLandscapeTest.java
@@ -1,6 +1,7 @@
 package tech.jhipster.lite.module.infrastructure.primary;
 
 import static org.assertj.core.api.Assertions.*;
+import static tech.jhipster.lite.module.domain.resource.JHipsterModuleRank.*;
 import static tech.jhipster.lite.module.domain.resource.JHipsterModulesResourceFixture.*;
 
 import org.junit.jupiter.api.Test;
@@ -20,6 +21,7 @@ class RestJHipsterLandscapeTest {
       .slug("second")
       .feature("my-feature")
       .moduleDependency("first")
+      .rank(RANK_S)
       .build();
 
     assertThat(
@@ -33,9 +35,9 @@ class RestJHipsterLandscapeTest {
     return """
     {\
     "levels":[\
-    {"elements":[{"type":"MODULE","slug":"first","operation":"operation","properties":{PROPERTIES_DEFINITION}}]},\
+    {"elements":[{"type":"MODULE","slug":"first","operation":"operation","properties":{PROPERTIES_DEFINITION},"rank":"RANK_D"}]},\
     {"elements":[{"type":"FEATURE","slug":"my-feature","modules":\
-    [{"type":"MODULE","slug":"second","operation":"operation","properties":{PROPERTIES_DEFINITION},"dependencies":[{"type":"MODULE","slug":"first"}]}]}]}\
+    [{"type":"MODULE","slug":"second","operation":"operation","properties":{PROPERTIES_DEFINITION},"dependencies":[{"type":"MODULE","slug":"first"}],"rank":"RANK_S"}]}]}\
     ]\
     }\
     """.replace("{PROPERTIES_DEFINITION}", RestJHipsterModulePropertiesDefinitionTest.json());