feat: align DDS with common permission and vector flow
This commit is contained in:
@@ -2,6 +2,9 @@ package com.cloudhandson.ddsbackoffice.web;
|
||||
|
||||
import com.cloudhandson.ddsbackoffice.domain.DdsQueryResult;
|
||||
import com.cloudhandson.ddsbackoffice.service.DdsQueryService;
|
||||
import com.cloudhandson.vpdbackoffice.service.PermissionService;
|
||||
import java.util.List;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -12,12 +15,29 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
public class DdsController {
|
||||
|
||||
private final DdsQueryService service;
|
||||
private final PermissionService permissionService;
|
||||
|
||||
public DdsController(DdsQueryService service) {
|
||||
public DdsController(DdsQueryService service, PermissionService permissionService) {
|
||||
this.service = service;
|
||||
this.permissionService = permissionService;
|
||||
}
|
||||
|
||||
@GetMapping({"/", "/dds"})
|
||||
@GetMapping("/")
|
||||
public String home(Model model) {
|
||||
try {
|
||||
model.addAttribute("roles", permissionService.findRoles());
|
||||
model.addAttribute("permissions", permissionService.findPermissionViews());
|
||||
} catch (DataAccessException exception) {
|
||||
model.addAttribute("roles", List.of());
|
||||
model.addAttribute("permissions", List.of());
|
||||
model.addAttribute("runtimeError", exception.getMessage());
|
||||
}
|
||||
model.addAttribute("vectorObject", service.vectorObject());
|
||||
model.addAttribute("configuredUserCount", service.users().stream().filter(user -> user.configured()).count());
|
||||
return "dds-home";
|
||||
}
|
||||
|
||||
@GetMapping("/dds")
|
||||
public String page(Model model) {
|
||||
addOptions(model, "both", "PG", null);
|
||||
return "dds";
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.cloudhandson.ddsbackoffice.web;
|
||||
|
||||
import com.cloudhandson.ddsbackoffice.config.DdsProperties;
|
||||
import com.cloudhandson.ddsbackoffice.service.DdsQueryService;
|
||||
import com.cloudhandson.vpdbackoffice.domain.permission.PermissionView;
|
||||
import com.cloudhandson.vpdbackoffice.service.PermissionService;
|
||||
import java.util.List;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.servlet.view.RedirectView;
|
||||
|
||||
/** DDS equivalent of the VPD protection-connection step. */
|
||||
@Controller
|
||||
public class DdsProtectionController {
|
||||
|
||||
private static final String MANAGEMENT_OBJECT = "CB_VECTOR_SEARCH_DOCUMENTS";
|
||||
|
||||
private final PermissionService permissionService;
|
||||
private final DdsProperties properties;
|
||||
private final DdsQueryService queryService;
|
||||
|
||||
public DdsProtectionController(
|
||||
PermissionService permissionService,
|
||||
DdsProperties properties,
|
||||
DdsQueryService queryService
|
||||
) {
|
||||
this.permissionService = permissionService;
|
||||
this.properties = properties;
|
||||
this.queryService = queryService;
|
||||
}
|
||||
|
||||
@GetMapping("/vpd-policies")
|
||||
public String page(Model model) {
|
||||
model.addAttribute("ddsVectorObject", properties.vectorObject());
|
||||
model.addAttribute("managementObject", MANAGEMENT_OBJECT);
|
||||
model.addAttribute("ddsUsers", queryService.users());
|
||||
try {
|
||||
List<PermissionView> permissions = permissionService.findPermissionViews().stream()
|
||||
.filter(permission -> MANAGEMENT_OBJECT.equalsIgnoreCase(permission.objectName()))
|
||||
.toList();
|
||||
model.addAttribute("permissions", permissions);
|
||||
} catch (DataAccessException exception) {
|
||||
model.addAttribute("permissions", List.of());
|
||||
model.addAttribute("runtimeError", exception.getMessage());
|
||||
}
|
||||
return "vpd-policies";
|
||||
}
|
||||
|
||||
@GetMapping("/vpd-filter-policies")
|
||||
public RedirectView filterPolicies() {
|
||||
return new RedirectView("/vpd-policies");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.cloudhandson.ddsbackoffice.web;
|
||||
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
|
||||
@ControllerAdvice
|
||||
public class DdsTrackModelAdvice {
|
||||
|
||||
@ModelAttribute("backofficeTrack")
|
||||
public String backofficeTrack() {
|
||||
return "DDS";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.cloudhandson.ddsbackoffice.web;
|
||||
|
||||
import com.cloudhandson.ddsbackoffice.service.DdsQueryService;
|
||||
import com.cloudhandson.ddsbackoffice.service.DdsVectorKnowledgeService;
|
||||
import com.cloudhandson.vpdbackoffice.domain.vector.VectorIngestCommand;
|
||||
import com.cloudhandson.vpdbackoffice.service.AppException;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
@Controller
|
||||
public class DdsVectorKnowledgeController {
|
||||
|
||||
private final DdsVectorKnowledgeService service;
|
||||
private final DdsQueryService ddsQueryService;
|
||||
|
||||
public DdsVectorKnowledgeController(
|
||||
DdsVectorKnowledgeService service,
|
||||
DdsQueryService ddsQueryService
|
||||
) {
|
||||
this.service = service;
|
||||
this.ddsQueryService = ddsQueryService;
|
||||
}
|
||||
|
||||
@GetMapping("/vector-knowledge")
|
||||
public String page(Model model) {
|
||||
populatePage(model);
|
||||
return "vector-knowledge";
|
||||
}
|
||||
|
||||
@PostMapping("/vector-knowledge/ingest")
|
||||
public String ingest(
|
||||
@RequestParam String documentId,
|
||||
@RequestParam String title,
|
||||
@RequestParam(required = false, defaultValue = "") String sourceUri,
|
||||
@RequestParam String content,
|
||||
@RequestParam String techTags,
|
||||
@RequestParam(defaultValue = "600") int chunkSize,
|
||||
@RequestParam(defaultValue = "DEMO") String embeddingMode,
|
||||
RedirectAttributes redirectAttributes
|
||||
) {
|
||||
try {
|
||||
var result = service.ingest(new VectorIngestCommand(
|
||||
documentId, title, sourceUri, content, techTags, chunkSize, embeddingMode));
|
||||
redirectAttributes.addFlashAttribute("ingestResult", result);
|
||||
redirectAttributes.addFlashAttribute("message",
|
||||
result.chunkCount() + "개 청크를 저장했습니다. DDS 권한 평가용 태그 "
|
||||
+ result.tagCount() + "개가 연결되었습니다.");
|
||||
} catch (Exception exception) {
|
||||
redirectAttributes.addFlashAttribute("errorMessage", exception.getMessage());
|
||||
}
|
||||
return "redirect:/vector-knowledge";
|
||||
}
|
||||
|
||||
@PostMapping("/vector-knowledge/search")
|
||||
public String search(
|
||||
@RequestParam String userKey,
|
||||
@RequestParam String query,
|
||||
@RequestParam(defaultValue = "10") int limit,
|
||||
@RequestParam(defaultValue = "DEMO") String embeddingMode,
|
||||
Model model
|
||||
) {
|
||||
try {
|
||||
model.addAttribute("searchResult", service.search(userKey, query, limit, embeddingMode));
|
||||
} catch (AppException | IllegalArgumentException exception) {
|
||||
model.addAttribute("errorMessage", exception.getMessage());
|
||||
}
|
||||
return "fragments/dds-vector-search-result :: result";
|
||||
}
|
||||
|
||||
private void populatePage(Model model) {
|
||||
try {
|
||||
model.addAttribute("summary", service.summary());
|
||||
model.addAttribute("aiEmbeddingConfigured", service.aiEmbeddingConfigured());
|
||||
} catch (DataAccessException exception) {
|
||||
model.addAttribute("summary", null);
|
||||
model.addAttribute("runtimeError", exception.getMessage());
|
||||
model.addAttribute("aiEmbeddingConfigured", false);
|
||||
}
|
||||
model.addAttribute("ddsUsers", ddsQueryService.users());
|
||||
model.addAttribute("ddsVectorObject", ddsQueryService.vectorObject());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user