fix #477: filter vpd targets by schema

This commit is contained in:
devmrko
2026-06-26 06:07:27 +09:00
parent cf46b4ddd1
commit 0b81d5b1a1
6 changed files with 84 additions and 14 deletions

View File

@@ -13,7 +13,7 @@ public interface VpdPolicyMapper {
List<VpdPolicyView> findPolicies();
List<VpdTargetView> findVpdTargets();
List<VpdTargetView> findVpdTargets(@Param("owner") String owner);
List<String> findPolicyNameOptions();

View File

@@ -12,7 +12,9 @@ import com.cloudhandson.vpdbackoffice.domain.vpd.VpdTargetView;
import com.cloudhandson.vpdbackoffice.mapper.VpdPolicyMapper;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
@@ -27,7 +29,7 @@ public class VpdPolicyService {
private final VpdPolicyMapper mapper;
private final JdbcTemplate jdbcTemplate;
private final OpenAiCompatibleClient aiClient;
private volatile CacheEntry<List<VpdTargetView>> vpdTargetsCache;
private final Map<String, CacheEntry<List<VpdTargetView>>> vpdTargetsCache = new ConcurrentHashMap<>();
private volatile CacheEntry<VpdPolicyFormOptions> formOptionsCache;
public VpdPolicyService(VpdPolicyMapper mapper, JdbcTemplate jdbcTemplate, OpenAiCompatibleClient aiClient) {
@@ -41,12 +43,18 @@ public class VpdPolicyService {
}
public List<VpdTargetView> findVpdTargets() {
CacheEntry<List<VpdTargetView>> cached = vpdTargetsCache;
return findVpdTargets(null);
}
public List<VpdTargetView> findVpdTargets(String owner) {
String normalizedOwner = normalizeOptionalIdentifier(owner);
String cacheKey = normalizedOwner == null ? "__MANAGED__" : normalizedOwner;
CacheEntry<List<VpdTargetView>> cached = vpdTargetsCache.get(cacheKey);
if (cached != null && !cached.expired()) {
return cached.value();
}
List<VpdTargetView> targets = List.copyOf(mapper.findVpdTargets());
vpdTargetsCache = new CacheEntry<>(targets, System.currentTimeMillis() + CATALOG_CACHE_MILLIS);
List<VpdTargetView> targets = List.copyOf(mapper.findVpdTargets(normalizedOwner));
vpdTargetsCache.put(cacheKey, new CacheEntry<>(targets, System.currentTimeMillis() + CATALOG_CACHE_MILLIS));
return targets;
}
@@ -273,7 +281,7 @@ public class VpdPolicyService {
}
public void clearCatalogCache() {
vpdTargetsCache = null;
vpdTargetsCache.clear();
formOptionsCache = null;
}

View File

@@ -22,27 +22,42 @@ public class VpdPolicyController {
}
@GetMapping("/vpd-policies")
public String policies(Model model) {
populatePolicyModel(model);
public String policies(
@RequestParam(required = false) String schemaOwner,
Model model
) {
populatePolicyModel(schemaOwner, model);
return "vpd-policies";
}
@GetMapping("/vpd-filter-policies")
public String filterPolicies(Model model) {
populatePolicyModel(model);
public String filterPolicies(
@RequestParam(required = false) String schemaOwner,
Model model
) {
populatePolicyModel(schemaOwner, model);
return "vpd-filter-policies";
}
private void populatePolicyModel(Model model) {
private void populatePolicyModel(String schemaOwner, Model model) {
try {
String selectedSchemaOwner = schemaOwner == null ? "" : schemaOwner.trim().toUpperCase();
model.addAttribute("policies", vpdPolicyService.findPolicies());
model.addAttribute("vpdTargets", vpdPolicyService.findVpdTargets());
model.addAttribute("vpdTargets", vpdPolicyService.findVpdTargets(selectedSchemaOwner));
model.addAttribute("selectedSchemaOwner", selectedSchemaOwner);
model.addAttribute("formOptions", vpdPolicyService.formOptions());
} catch (DataAccessException exception) {
RuntimeErrorMessage message = RuntimeErrorMessages.dataAccess(exception);
model.addAttribute("runtimeError", message);
model.addAttribute("policies", List.of());
model.addAttribute("vpdTargets", List.of());
model.addAttribute("selectedSchemaOwner", "");
model.addAttribute("formOptions", vpdPolicyService.emptyFormOptions());
} catch (AppException exception) {
model.addAttribute("errorMessage", exception.getMessage());
model.addAttribute("policies", List.of());
model.addAttribute("vpdTargets", List.of());
model.addAttribute("selectedSchemaOwner", "");
model.addAttribute("formOptions", vpdPolicyService.emptyFormOptions());
}
}