All checks were successful
CI fuzzy controller / container-test-job (push) Successful in 1m32s
78 lines
3.1 KiB
Java
78 lines
3.1 KiB
Java
package ru.ulstu.fc.rule.controller;
|
|
|
|
import jakarta.validation.Valid;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.ui.Model;
|
|
import org.springframework.validation.BindingResult;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import ru.ulstu.fc.rule.model.FuzzyRuleForm;
|
|
import ru.ulstu.fc.rule.model.FuzzyTerm;
|
|
import ru.ulstu.fc.rule.model.Variable;
|
|
import ru.ulstu.fc.rule.service.FuzzyRuleService;
|
|
import ru.ulstu.fc.rule.service.FuzzyTermService;
|
|
import ru.ulstu.fc.rule.service.VariableService;
|
|
|
|
import java.util.List;
|
|
|
|
@Controller
|
|
@RequestMapping("rule")
|
|
public class FuzzyRuleController {
|
|
private final FuzzyRuleService fuzzyRuleService;
|
|
private final VariableService variableService;
|
|
private final FuzzyTermService fuzzyTermService;
|
|
|
|
public FuzzyRuleController(FuzzyRuleService fuzzyRuleService,
|
|
VariableService variableService,
|
|
FuzzyTermService fuzzyTermService) {
|
|
this.fuzzyRuleService = fuzzyRuleService;
|
|
this.variableService = variableService;
|
|
this.fuzzyTermService = fuzzyTermService;
|
|
}
|
|
|
|
@GetMapping("/edit/{projectId}/{ruleId}")
|
|
public String edit(@PathVariable(value = "projectId") Integer projectId,
|
|
@PathVariable(value = "ruleId") Integer id, Model model) {
|
|
model.addAttribute("projectId", projectId);
|
|
model.addAttribute("fuzzyRuleForm",
|
|
(id != null && id != 0)
|
|
? new FuzzyRuleForm(id, fuzzyRuleService.getById(id))
|
|
: new FuzzyRuleForm(id, projectId));
|
|
return "rule/edit";
|
|
}
|
|
|
|
@PostMapping(value = "save", params = "save")
|
|
public String save(@Valid FuzzyRuleForm fuzzyRuleForm, BindingResult bindingResult, Model model) {
|
|
if (bindingResult.hasErrors()) {
|
|
model.addAttribute("projectId", fuzzyRuleForm.getProjectId());
|
|
return "rule/edit";
|
|
}
|
|
fuzzyRuleService.save(fuzzyRuleForm);
|
|
return "redirect:/project/edit/" + fuzzyRuleForm.getProjectId();
|
|
}
|
|
|
|
@PostMapping(value = "save", params = "delete")
|
|
public String delete(FuzzyRuleForm fuzzyRuleForm) {
|
|
if (fuzzyRuleForm != null && fuzzyRuleForm.getId() != null) {
|
|
fuzzyRuleService.delete(fuzzyRuleForm);
|
|
}
|
|
return "redirect:/project/edit/" + fuzzyRuleForm.getProjectId();
|
|
}
|
|
|
|
@ResponseBody
|
|
@GetMapping("/getVariables/{projectId}")
|
|
public List<Variable> getVariables(@PathVariable("projectId") Integer projectId) {
|
|
//TODO: return DTO without terms
|
|
return variableService.getAllByProject(projectId);
|
|
}
|
|
|
|
@ResponseBody
|
|
@GetMapping("/getFuzzyTerms/{variableId}")
|
|
public List<FuzzyTerm> getTerms(@PathVariable("variableId") Integer variableId) {
|
|
return fuzzyTermService.getByVariableId(variableId);
|
|
}
|
|
}
|