Files
vpd-permission-poc/vpd-backoffice/src/main/java/com/cloudhandson/vpdbackoffice/web/SettingController.java

92 lines
3.7 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.cloudhandson.vpdbackoffice.web;
import com.cloudhandson.vpdbackoffice.service.BackofficeSchemaService;
import com.cloudhandson.vpdbackoffice.service.SettingService;
import com.cloudhandson.vpdbackoffice.config.McpProperties;
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 SettingController {
private final SettingService settingService;
private final BackofficeSchemaService backofficeSchemaService;
private final McpProperties mcpProperties;
public SettingController(
SettingService settingService,
BackofficeSchemaService backofficeSchemaService,
McpProperties mcpProperties
) {
this.settingService = settingService;
this.backofficeSchemaService = backofficeSchemaService;
this.mcpProperties = mcpProperties;
}
@GetMapping("/settings")
public String settings(Model model) {
model.addAttribute("hmmMcpPublicUrl", mcpProperties.resolvedPublicUrl());
try {
model.addAttribute("ordsBaseUrl", settingService.ordsBaseUrl());
} catch (DataAccessException exception) {
RuntimeErrorMessage error = RuntimeErrorMessages.dataAccess(exception);
model.addAttribute("ordsBaseUrl", "");
model.addAttribute("runtimeErrorTitle", error.title());
model.addAttribute("runtimeErrorMessage", error.message());
}
return "settings";
}
@GetMapping("/settings/database")
public String databaseSettings(Model model) {
try {
model.addAttribute("schemaPreflight", backofficeSchemaService.preflight());
} catch (DataAccessException exception) {
RuntimeErrorMessage error = RuntimeErrorMessages.dataAccess(exception);
model.addAttribute("schemaPreflightErrorTitle", error.title());
model.addAttribute("schemaPreflightErrorMessage", error.message());
}
return "settings-database";
}
@PostMapping("/settings/ords")
public String updateOrds(
@RequestParam String ordsBaseUrl,
RedirectAttributes redirectAttributes
) {
settingService.updateOrdsBaseUrl(ordsBaseUrl);
redirectAttributes.addFlashAttribute("message", ordsBaseUrl == null || ordsBaseUrl.isBlank()
? "레거시 ORDS 설정을 해제했습니다. HMM MCP 및 HR 질의에는 영향이 없습니다."
: "레거시 ORDS 설정을 저장했습니다.");
return "redirect:/settings";
}
@PostMapping("/settings/database/initialize")
public String initializeSchema(
@RequestParam String confirmation,
RedirectAttributes redirectAttributes
) {
if (!"DB 준비 실행".equals(confirmation)) {
redirectAttributes.addFlashAttribute(
"error", "DB 지원 DDL을 실행하려면 확인 문구 DB 준비 실행’을 정확히 입력하세요.");
return "redirect:/settings/database";
}
var results = backofficeSchemaService.initializeSchema();
long failures = results.stream()
.filter(result -> "FAILED".equalsIgnoreCase(result.status()))
.count();
redirectAttributes.addFlashAttribute("schemaResults", results);
if (failures > 0) {
redirectAttributes.addFlashAttribute("error", "백오피스 지원 DDL 실행 중 " + failures + "개 작업이 실패했습니다. 결과와 SQL을 확인하세요.");
} else {
redirectAttributes.addFlashAttribute("message", "백오피스 지원 테이블 DDL을 실행했습니다.");
}
return "redirect:/settings/database";
}
}