feat(system): limit the label search to given codes
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
This commit is contained in:
1 parent
a24291edd2
commit
89662d0eb2
4 files changed
+28
-2
No files matched your search
+4
-1
@@ -4,13 +4,16 @@ import com.solvway.services.system.constant.SystemConstants.Area;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/** Translations search: searchKey over the code, English and Chinese text; missingLocale lists labels lacking that language. */
|
||||
import java.util.List;
|
||||
|
||||
/** Translations search: searchKey over the code, English and Chinese text; missingLocale lists labels lacking that language; codes, when set, limits to those codes ignoring case. */
|
||||
@Getter
|
||||
@Setter
|
||||
public class MessageSearchRequest {
|
||||
private String searchKey;
|
||||
private Area area;
|
||||
private String missingLocale;
|
||||
private List<String> codes;
|
||||
private int page;
|
||||
private int size;
|
||||
}
|
||||
+6
@@ -24,6 +24,8 @@ import java.util.Objects;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class MessageService {
|
||||
@@ -86,8 +88,12 @@ public class MessageService {
|
||||
List<Message> rows = req.getArea() == null ? messageRepository.findAll() : messageRepository.findAllByArea(req.getArea());
|
||||
String key = StringUtils.isEmpty(req.getSearchKey()) || req.getSearchKey().isBlank() ? null : lower(req.getSearchKey().trim());
|
||||
String missing = StringUtils.isEmpty(req.getMissingLocale()) ? null : req.getMissingLocale();
|
||||
Set<String> codes = req.getCodes() == null ? null : req.getCodes().stream().map(MessageService::lower).collect(Collectors.toSet());
|
||||
List<Message> hits = new ArrayList<>();
|
||||
for (Message m : rows) {
|
||||
if (codes != null && !codes.contains(lower(m.getCode()))) {
|
||||
continue;
|
||||
}
|
||||
Map<String, String> text = parseContent(m.getContent());
|
||||
if (key != null && !(lower(m.getCode()).contains(key) || lower(text.get("en_US")).contains(key) || lower(text.get("zh_CN")).contains(key))) {
|
||||
continue;
|
||||
|
||||
+17
@@ -85,6 +85,23 @@ class MessageServiceTranslationsTest {
|
||||
assertThat(codes(page)).containsExactly("A3");
|
||||
}
|
||||
|
||||
@Test
|
||||
void codesLimitTheListIgnoringCaseAndCombineWithTheOtherFilters() {
|
||||
when(repository.findAllByArea(Area.A)).thenReturn(List.of(
|
||||
msg(1, "Leads", "Leads", "线索"), msg(2, "OrderPayment", "Order payment", null), msg(3, "Users", "Users", null)));
|
||||
|
||||
MessageSearchRequest own = req(null, null, 0, 10);
|
||||
own.setCodes(List.of("leads", "USERS"));
|
||||
assertThat(codes(service.search(own))).containsExactly("Leads", "Users");
|
||||
|
||||
own.setMissingLocale("zh_CN");
|
||||
Page<Message> missing = service.search(own);
|
||||
assertThat(codes(missing)).containsExactly("Users");
|
||||
assertThat(missing.getTotalElements()).isEqualTo(1);
|
||||
|
||||
assertThat(codes(service.search(req(null, "zh_CN", 0, 10)))).containsExactly("OrderPayment", "Users");
|
||||
}
|
||||
|
||||
@Test
|
||||
void savingAnExistingLabelBumpsTheVersion() {
|
||||
Message stored = msg(7, "Leads", "Leads", "线索");
|
||||
|
||||
Reference in new issue
Block a user