Skip to content

Commit

Permalink
Merge pull request #11814 from renanfranca/10934-implement-rank-mappe…
Browse files Browse the repository at this point in the history
…r-and-rest-dto

implement rank mapper and rest dto
  • Loading branch information
murdos authored Jan 27, 2025
2 parents bc49f98 + c955daf commit 17edf52
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ private JHipsterLandscapeModule moduleWithoutNestedDependencies(JHipsterLandscap
.module(module.slug())
.operation(module.operation())
.propertiesDefinition(module.propertiesDefinition())
.rank(module.rank())
.dependencies(dependenciesWithoutNested(module, knownDependencies));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -76,6 +71,7 @@ private static JHipsterLandscapeModule landscapeModule(JHipsterModuleResource re
.module(resource.slug())
.operation(resource.apiDoc().operation())
.propertiesDefinition(resource.propertiesDefinition())
.rank(resource.rank())
.dependencies(resource.organization().dependencies());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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;

Expand All @@ -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);
Expand All @@ -31,6 +33,7 @@ private JHipsterLandscapeModule(JHipsterLandscapeModuleBuilder builder) {
operation = builder.operation;
propertiesDefinition = builder.propertiesDefinition;
dependencies = JHipsterLandscapeDependencies.of(builder.dependencies);
rank = builder.rank;
}

public static JHipsterLandscapeModuleSlugBuilder builder() {
Expand All @@ -50,6 +53,10 @@ public JHipsterModulePropertiesDefinition propertiesDefinition() {
return propertiesDefinition;
}

public JHipsterModuleRank rank() {
return rank;
}

@Override
public Optional<JHipsterLandscapeDependencies> dependencies() {
return dependencies;
Expand Down Expand Up @@ -94,6 +101,7 @@ public String toString() {
.append("operation", operation)
.append("propertiesDefinition", propertiesDefinition)
.append("dependencies", dependencies)
.append("rank", rank)
.build();
}

Expand All @@ -108,6 +116,7 @@ private static final class JHipsterLandscapeModuleBuilder
private JHipsterModuleOperation operation;
private Collection<? extends JHipsterLandscapeDependency> dependencies;
private JHipsterModulePropertiesDefinition propertiesDefinition;
private JHipsterModuleRank rank;

@Override
public JHipsterLandscapeModuleOperationBuilder module(JHipsterModuleSlug module) {
Expand All @@ -130,6 +139,13 @@ public JHipsterLandscapeModuleDependenciesBuilder propertiesDefinition(JHipsterM
return this;
}

@Override
public JHipsterLandscapeModuleDependenciesBuilder rank(JHipsterModuleRank rank) {
this.rank = rank;

return this;
}

@Override
public JHipsterLandscapeModule dependencies(Collection<? extends JHipsterLandscapeDependency> dependencies) {
this.dependencies = dependencies;
Expand Down Expand Up @@ -159,6 +175,8 @@ public interface JHipsterLandscapeModulePropertiesDefinitionBuilder {
}

public interface JHipsterLandscapeModuleDependenciesBuilder {
JHipsterLandscapeModuleDependenciesBuilder rank(JHipsterModuleRank rank);

JHipsterLandscapeModule dependencies(Collection<? extends JHipsterLandscapeDependency> dependencies);

default JHipsterLandscapeModule withoutDependencies() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,32 @@
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 {

private final String slug;
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) {
return new RestJHipsterLandscapeModuleBuilder()
.slug(module.slug().get())
.operation(module.operation().get())
.properties(RestJHipsterModulePropertiesDefinition.from(module.propertiesDefinition()))
.rank(module.rank())
.dependencies(buildDependencies(module))
.build();
}
Expand Down Expand Up @@ -66,12 +70,18 @@ public Collection<RestJHipsterLandscapeDependency> getDependencies() {
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;
Expand All @@ -97,6 +107,12 @@ public RestJHipsterLandscapeModuleBuilder dependencies(List<RestJHipsterLandscap
return this;
}

public RestJHipsterLandscapeModuleBuilder rank(JHipsterModuleRank rank) {
this.rank = rank;

return this;
}

public RestJHipsterLandscapeModule build() {
return new RestJHipsterLandscapeModule(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -24,6 +25,7 @@ public static JHipsterLandscapeModule noDependencyLandscapeModule(String slug) {
.module(slug)
.operation("operation")
.propertiesDefinition(propertiesDefinition())
.rank(RANK_D)
.withoutDependencies();
}

Expand All @@ -32,6 +34,7 @@ public static JHipsterLandscapeModule oneModuleDependencyLandscapeModule(String
.module(slug)
.operation("operation")
.propertiesDefinition(propertiesDefinition())
.rank(RANK_D)
.dependencies(landscapeModuleDependencies(dependency));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand Down Expand Up @@ -147,6 +148,7 @@ void shouldBuildThreeLevelsLandscapeFromFourModules() {
.module("forth")
.operation("operation")
.propertiesDefinition(propertiesDefinition())
.rank(RANK_D)
.dependencies(List.of(new JHipsterFeatureDependency(new JHipsterFeatureSlug("my-feature"))))
)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,6 +21,7 @@ void shouldSerializeToJson() {
.slug("second")
.feature("my-feature")
.moduleDependency("first")
.rank(RANK_S)
.build();

assertThat(
Expand All @@ -33,9 +35,9 @@ private String json() {
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());
Expand Down

0 comments on commit 17edf52

Please sign in to comment.