Skip to content

Commit dfc7b23

Browse files
committed
GroupByParent.transformCategories(): replace FirstLevelCategoryDto by SelectItem.
Fix #743 No functional changes.
1 parent d28545b commit dfc7b23

File tree

5 files changed

+17
-69
lines changed

5 files changed

+17
-69
lines changed

src/main/java/ru/mystamps/web/controller/SeriesController.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
import ru.mystamps.web.controller.dto.AddImageForm;
6262
import ru.mystamps.web.controller.dto.AddSeriesForm;
6363
import ru.mystamps.web.controller.dto.AddSeriesSalesForm;
64-
import ru.mystamps.web.controller.dto.FirstLevelCategoryDto;
6564
import ru.mystamps.web.controller.dto.NullableImageUrl;
6665
import ru.mystamps.web.controller.dto.SelectItem;
6766
import ru.mystamps.web.controller.interceptor.DownloadImageInterceptor;
@@ -481,8 +480,7 @@ public String searchSeriesByCatalog(
481480
protected void addCategoriesToModel(Model model, String lang) {
482481
List<CategoryDto> categories = categoryService.findCategoriesWithParents(lang);
483482

484-
List<FirstLevelCategoryDto> groupedCategories =
485-
GroupByParent.transformCategories(categories);
483+
List<SelectItem> groupedCategories = GroupByParent.transformCategories(categories);
486484

487485
model.addAttribute("categories", groupedCategories);
488486
}

src/main/java/ru/mystamps/web/controller/dto/FirstLevelCategoryDto.java

-48
This file was deleted.

src/main/java/ru/mystamps/web/support/thymeleaf/GroupByParent.java

+8-10
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.Collections;
2222
import java.util.List;
2323

24-
import ru.mystamps.web.controller.dto.FirstLevelCategoryDto;
2524
import ru.mystamps.web.controller.dto.SelectItem;
2625
import ru.mystamps.web.dao.dto.CategoryDto;
2726
import ru.mystamps.web.dao.dto.TransactionParticipantDto;
@@ -77,21 +76,20 @@ public static List<SelectItem> transformParticipants(
7776
return items;
7877
}
7978

80-
// @todo #592 GroupByParent.transformCategories(): replace FirstLevelCategoryDto by SelectItem
8179
// @todo #592 GroupByParent.transformCategories(): use unified class that represents entity with parent
8280
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
83-
public static List<FirstLevelCategoryDto> transformCategories(List<CategoryDto> categories) {
81+
public static List<SelectItem> transformCategories(List<CategoryDto> categories) {
8482
if (categories.isEmpty()) {
8583
return Collections.emptyList();
8684
}
8785

88-
List<FirstLevelCategoryDto> items = new ArrayList<>();
86+
List<SelectItem> items = new ArrayList<>();
8987
String lastParent = null;
90-
FirstLevelCategoryDto lastItem = null;
88+
SelectItem lastItem = null;
9189

9290
for (CategoryDto category : categories) {
9391
String name = category.getName();
94-
String slug = category.getSlug();
92+
String value = category.getSlug();
9593
String parent = category.getParentName();
9694

9795
boolean categoryWithoutParent = parent == null;
@@ -100,14 +98,14 @@ public static List<FirstLevelCategoryDto> transformCategories(List<CategoryDto>
10098
if (createNewItem) {
10199
lastParent = parent;
102100
if (categoryWithoutParent) {
103-
lastItem = new FirstLevelCategoryDto(slug, name);
101+
lastItem = new SelectItem(name, value);
104102
} else {
105-
lastItem = new FirstLevelCategoryDto(parent);
106-
lastItem.addChild(slug, name);
103+
lastItem = new SelectItem(parent);
104+
lastItem.addChild(name, value);
107105
}
108106
items.add(lastItem);
109107
} else {
110-
lastItem.addChild(slug, name);
108+
lastItem.addChild(name, value);
111109
}
112110
}
113111

src/main/webapp/WEB-INF/views/series/add.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ <h3 th:text="${#strings.capitalize(add_series)}">
106106
<th:block th:each="category : ${categories}">
107107
<optgroup th:if="${not #lists.isEmpty(category.children)}" th:label="${category.name}">
108108
<option th:each="subcategory : ${category.children}"
109-
th:value="${subcategory.slug}"
109+
th:value="${subcategory.value}"
110110
th:text="${subcategory.name}"
111-
th:selected="${addSeriesForm.category != null and addSeriesForm.category.slug == subcategory.slug}">
111+
th:selected="${addSeriesForm.category != null and addSeriesForm.category.slug == subcategory.value}">
112112
</option>
113113
</optgroup>
114114
<option th:if="${#lists.isEmpty(category.children)}"
115-
th:value="${category.slug}"
115+
th:value="${category.value}"
116116
th:text="${category.name}"
117-
th:selected="${addSeriesForm.category != null and addSeriesForm.category.slug == category.slug}">
117+
th:selected="${addSeriesForm.category != null and addSeriesForm.category.slug == category.value}">
118118
</option>
119119
</th:block>
120120
/*/-->

src/main/webapp/WEB-INF/views/series/import/info.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,15 @@ <h3 th:text="#{t_gathered_data}">
128128
<th:block th:each="category : ${categories}">
129129
<optgroup th:if="${not #lists.isEmpty(category.children)}" th:label="${category.name}">
130130
<option th:each="subcategory : ${category.children}"
131-
th:value="${subcategory.slug}"
131+
th:value="${subcategory.value}"
132132
th:text="${subcategory.name}"
133-
th:selected="${importSeriesForm.category != null and importSeriesForm.category.slug == subcategory.slug}">
133+
th:selected="${importSeriesForm.category != null and importSeriesForm.category.slug == subcategory.value}">
134134
</option>
135135
</optgroup>
136136
<option th:if="${#lists.isEmpty(category.children)}"
137-
th:value="${category.slug}"
137+
th:value="${category.value}"
138138
th:text="${category.name}"
139-
th:selected="${importSeriesForm.category != null and importSeriesForm.category.slug == category.slug}">
139+
th:selected="${importSeriesForm.category != null and importSeriesForm.category.slug == category.value}">
140140
</option>
141141
</th:block>
142142
/*/-->

0 commit comments

Comments
 (0)