diff --git a/.gitea/workflows/test.yaml b/.gitea/workflows/test.yaml index cbd3290..d93aee3 100644 --- a/.gitea/workflows/test.yaml +++ b/.gitea/workflows/test.yaml @@ -1,5 +1,5 @@ name: CI fuzzy controller -on: [push] +on: [ push ] jobs: container-test-job: runs-on: ubuntu-latest @@ -8,8 +8,8 @@ jobs: - name: Set up JDK 21 for x64 uses: actions/setup-java@v4 with: - java-version: '21' - distribution: 'temurin' - architecture: x64 + java-version: '21' + distribution: 'temurin' + architecture: x64 - name: Test with Gradle run: bash ./gradlew test \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 9cad71a..9fa47b3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,12 +1,12 @@ { - "version": "0.2.0", - "configurations": [ - { - "type": "java", - "name": "FuzzyControllerApplication", - "request": "launch", - "mainClass": "ru.ulstu.fc.FuzzyControllerApplication", - "projectName": "fuzzy-controller" - } - ] + "version": "0.2.0", + "configurations": [ + { + "type": "java", + "name": "FuzzyControllerApplication", + "request": "launch", + "mainClass": "ru.ulstu.fc.FuzzyControllerApplication", + "projectName": "fuzzy-controller" + } + ] } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 0153b31..3ea84cf 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,4 @@ { - "java.configuration.updateBuildConfiguration": "interactive", - "java.compile.nullAnalysis.mode": "disabled" + "java.configuration.updateBuildConfiguration": "interactive", + "java.compile.nullAnalysis.mode": "disabled" } \ No newline at end of file diff --git a/src/main/java/ru/ulstu/fc/config/FuzzyEngine.java b/src/main/java/ru/ulstu/fc/config/FuzzyEngine.java new file mode 100644 index 0000000..15b1e76 --- /dev/null +++ b/src/main/java/ru/ulstu/fc/config/FuzzyEngine.java @@ -0,0 +1,16 @@ +package ru.ulstu.fc.config; + +import com.fuzzylite.Engine; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class FuzzyEngine { + @Bean + public Engine getFuzzyEngine() { + Engine engine = new Engine(); + engine.setName("Fuzzy rules"); + engine.setDescription(""); + return engine; + } +} diff --git a/src/main/java/ru/ulstu/fc/project/controller/ProjectController.java b/src/main/java/ru/ulstu/fc/project/controller/ProjectController.java index e248e4b..ca23828 100644 --- a/src/main/java/ru/ulstu/fc/project/controller/ProjectController.java +++ b/src/main/java/ru/ulstu/fc/project/controller/ProjectController.java @@ -18,15 +18,15 @@ import ru.ulstu.fc.user.model.UserRoleConstants; @Controller @Hidden @RequestMapping("project") -@Secured({ UserRoleConstants.ADMIN }) +@Secured({UserRoleConstants.ADMIN}) public class ProjectController { private final ProjectService projectService; private final ProjectRulesService projectRulesService; private final ProjectVariableService projectVariableService; public ProjectController(ProjectService projectService, - ProjectRulesService projectRulesService, - ProjectVariableService projectVariableService) { + ProjectRulesService projectRulesService, + ProjectVariableService projectVariableService) { this.projectService = projectService; this.projectRulesService = projectRulesService; this.projectVariableService = projectVariableService; diff --git a/src/main/java/ru/ulstu/fc/project/controller/ProjectRunController.java b/src/main/java/ru/ulstu/fc/project/controller/ProjectRunController.java new file mode 100644 index 0000000..c2ca79a --- /dev/null +++ b/src/main/java/ru/ulstu/fc/project/controller/ProjectRunController.java @@ -0,0 +1,37 @@ +package ru.ulstu.fc.project.controller; + +import io.swagger.v3.oas.annotations.Hidden; +import org.springframework.security.access.annotation.Secured; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import ru.ulstu.fc.project.service.ProjectRulesService; +import ru.ulstu.fc.project.service.ProjectService; +import ru.ulstu.fc.project.service.ProjectVariableService; +import ru.ulstu.fc.user.model.UserRoleConstants; + +@Controller +@Hidden +@RequestMapping("runProject") +@Secured({UserRoleConstants.ADMIN}) +public class ProjectRunController { + private final ProjectService projectService; + private final ProjectRulesService projectRulesService; + private final ProjectVariableService projectVariableService; + + public ProjectRunController(ProjectService projectService, + ProjectRulesService projectRulesService, + ProjectVariableService projectVariableService) { + this.projectService = projectService; + this.projectRulesService = projectRulesService; + this.projectVariableService = projectVariableService; + } + + @GetMapping("init/{projectId}") + public String getProjects(@PathVariable(value = "projectId") Integer projectId, Model model) { + model.addAttribute("project", projectService.getById(projectId)); + return "project/init"; + } +} diff --git a/src/main/java/ru/ulstu/fc/project/model/Project.java b/src/main/java/ru/ulstu/fc/project/model/Project.java index f071540..e5ff8c7 100644 --- a/src/main/java/ru/ulstu/fc/project/model/Project.java +++ b/src/main/java/ru/ulstu/fc/project/model/Project.java @@ -1,7 +1,5 @@ package ru.ulstu.fc.project.model; -import java.util.Date; - import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; import jakarta.persistence.ManyToOne; @@ -9,9 +7,11 @@ import jakarta.validation.constraints.NotEmpty; import ru.ulstu.fc.core.model.BaseEntity; import ru.ulstu.fc.user.model.User; +import java.util.Date; + @Entity public class Project extends BaseEntity { - @NotEmpty(message = "Текст новости не может быть пустым") + @NotEmpty(message = "Название проекта не может быть пустым") private String name; private Date createDate = new Date(); @ManyToOne(cascade = CascadeType.MERGE) diff --git a/src/main/java/ru/ulstu/fc/project/model/ProjectForm.java b/src/main/java/ru/ulstu/fc/project/model/ProjectForm.java index a03532b..b2a10c9 100644 --- a/src/main/java/ru/ulstu/fc/project/model/ProjectForm.java +++ b/src/main/java/ru/ulstu/fc/project/model/ProjectForm.java @@ -1,9 +1,12 @@ package ru.ulstu.fc.project.model; +import jakarta.validation.constraints.NotEmpty; + import java.util.Date; public class ProjectForm { private Integer id; + @NotEmpty(message = "Название проекта не может быть пустым") private String name; private Date createDate; diff --git a/src/main/java/ru/ulstu/fc/project/service/ProjectRulesService.java b/src/main/java/ru/ulstu/fc/project/service/ProjectRulesService.java index 88fe5d1..52f1d72 100644 --- a/src/main/java/ru/ulstu/fc/project/service/ProjectRulesService.java +++ b/src/main/java/ru/ulstu/fc/project/service/ProjectRulesService.java @@ -1,20 +1,19 @@ package ru.ulstu.fc.project.service; +import org.springframework.stereotype.Service; +import ru.ulstu.fc.rule.model.FuzzyRule; +import ru.ulstu.fc.rule.repository.FuzzyRuleRepository; + import java.util.Collections; import java.util.List; -import org.springframework.stereotype.Service; - -import ru.ulstu.fc.rule.repository.FuzzyRuleRepository; -import ru.ulstu.fc.rule.model.FuzzyRule; - @Service public class ProjectRulesService { private final FuzzyRuleRepository ruleRepository; private final ProjectService projectService; public ProjectRulesService(FuzzyRuleRepository ruleRepository, - ProjectService projectService) { + ProjectService projectService) { this.ruleRepository = ruleRepository; this.projectService = projectService; } diff --git a/src/main/java/ru/ulstu/fc/project/service/ProjectVariableService.java b/src/main/java/ru/ulstu/fc/project/service/ProjectVariableService.java index e05031a..5ec7194 100644 --- a/src/main/java/ru/ulstu/fc/project/service/ProjectVariableService.java +++ b/src/main/java/ru/ulstu/fc/project/service/ProjectVariableService.java @@ -1,20 +1,19 @@ package ru.ulstu.fc.project.service; +import org.springframework.stereotype.Service; +import ru.ulstu.fc.rule.model.Variable; +import ru.ulstu.fc.rule.repository.VariableRepository; + import java.util.Collections; import java.util.List; -import org.springframework.stereotype.Service; - -import ru.ulstu.fc.rule.repository.VariableRepository; -import ru.ulstu.fc.rule.model.Variable; - @Service public class ProjectVariableService { private final VariableRepository variableRepository; private final ProjectService projectService; public ProjectVariableService(VariableRepository variableRepository, - ProjectService projectService) { + ProjectService projectService) { this.variableRepository = variableRepository; this.projectService = projectService; } diff --git a/src/main/java/ru/ulstu/fc/rule/controller/RuleController.java b/src/main/java/ru/ulstu/fc/rule/controller/FuzzyRuleController.java similarity index 91% rename from src/main/java/ru/ulstu/fc/rule/controller/RuleController.java rename to src/main/java/ru/ulstu/fc/rule/controller/FuzzyRuleController.java index 284aa06..7febe09 100644 --- a/src/main/java/ru/ulstu/fc/rule/controller/RuleController.java +++ b/src/main/java/ru/ulstu/fc/rule/controller/FuzzyRuleController.java @@ -1,5 +1,6 @@ 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; @@ -7,23 +8,21 @@ 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 jakarta.validation.Valid; import ru.ulstu.fc.rule.model.FuzzyRuleForm; import ru.ulstu.fc.rule.service.FuzzyRuleService; @Controller @RequestMapping("rule") -public class RuleController { +public class FuzzyRuleController { private final FuzzyRuleService ruleService; - public RuleController(FuzzyRuleService ruleService) { + public FuzzyRuleController(FuzzyRuleService ruleService) { this.ruleService = ruleService; } @GetMapping("/edit/{projectId}/{ruleId}") public String edit(@PathVariable(value = "projectId") Integer projectId, - @PathVariable(value = "ruleId") Integer id, Model model) { + @PathVariable(value = "ruleId") Integer id, Model model) { model.addAttribute("projectId", projectId); model.addAttribute("fuzzyRuleForm", (id != null && id != 0) diff --git a/src/main/java/ru/ulstu/fc/rule/controller/FuzzyTermController.java b/src/main/java/ru/ulstu/fc/rule/controller/FuzzyTermController.java index 8a5eac0..895a412 100644 --- a/src/main/java/ru/ulstu/fc/rule/controller/FuzzyTermController.java +++ b/src/main/java/ru/ulstu/fc/rule/controller/FuzzyTermController.java @@ -1,5 +1,6 @@ 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; @@ -7,8 +8,6 @@ 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 jakarta.validation.Valid; import ru.ulstu.fc.rule.model.FuzzyTermForm; import ru.ulstu.fc.rule.service.FuzzyTermService; @@ -23,8 +22,8 @@ public class FuzzyTermController { @GetMapping("/edit/{projectId}/{variableId}/{fuzzyTermId}") public String edit(@PathVariable(value = "projectId") Integer projectId, - @PathVariable(value = "variableId") Integer variableId, - @PathVariable(value = "fuzzyTermId") Integer fuzzyTermId, Model model) { + @PathVariable(value = "variableId") Integer variableId, + @PathVariable(value = "fuzzyTermId") Integer fuzzyTermId, Model model) { model.addAttribute("projectId", projectId); model.addAttribute("variableId", variableId); model.addAttribute("fuzzyTermForm", diff --git a/src/main/java/ru/ulstu/fc/rule/controller/InferenceMvcController.java b/src/main/java/ru/ulstu/fc/rule/controller/InferenceMvcController.java index 07fe4dd..67bebab 100644 --- a/src/main/java/ru/ulstu/fc/rule/controller/InferenceMvcController.java +++ b/src/main/java/ru/ulstu/fc/rule/controller/InferenceMvcController.java @@ -7,8 +7,8 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import ru.ulstu.fc.rule.model.InferenceForm; import ru.ulstu.fc.rule.model.FuzzyTerm; +import ru.ulstu.fc.rule.model.InferenceForm; import ru.ulstu.fc.rule.model.Variable; import ru.ulstu.fc.rule.service.FuzzyInferenceService; diff --git a/src/main/java/ru/ulstu/fc/rule/controller/VariableController.java b/src/main/java/ru/ulstu/fc/rule/controller/VariableController.java index 9fba9b9..4b21a54 100644 --- a/src/main/java/ru/ulstu/fc/rule/controller/VariableController.java +++ b/src/main/java/ru/ulstu/fc/rule/controller/VariableController.java @@ -1,5 +1,6 @@ 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; @@ -7,8 +8,6 @@ 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 jakarta.validation.Valid; import ru.ulstu.fc.rule.model.VariableForm; import ru.ulstu.fc.rule.service.FuzzyTermService; import ru.ulstu.fc.rule.service.VariableService; @@ -20,14 +19,14 @@ public class VariableController { private final FuzzyTermService termService; public VariableController(VariableService variableService, - FuzzyTermService termService) { + FuzzyTermService termService) { this.variableService = variableService; this.termService = termService; } @GetMapping("/edit/{projectId}/{variableId}") public String edit(@PathVariable(value = "projectId") Integer projectId, - @PathVariable(value = "variableId") Integer variableId, Model model) { + @PathVariable(value = "variableId") Integer variableId, Model model) { model.addAttribute("projectId", projectId); model.addAttribute("variableForm", (variableId == null || variableId == 0) diff --git a/src/main/java/ru/ulstu/fc/rule/model/Variable.java b/src/main/java/ru/ulstu/fc/rule/model/Variable.java index fbb7ebc..9970fa7 100644 --- a/src/main/java/ru/ulstu/fc/rule/model/Variable.java +++ b/src/main/java/ru/ulstu/fc/rule/model/Variable.java @@ -1,8 +1,5 @@ package ru.ulstu.fc.rule.model; -import java.util.ArrayList; -import java.util.List; - import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; @@ -14,17 +11,20 @@ import jakarta.validation.constraints.Size; import ru.ulstu.fc.core.model.BaseEntity; import ru.ulstu.fc.project.model.Project; +import java.util.ArrayList; +import java.util.List; + @Entity public class Variable extends BaseEntity { @Size(min = 3, max = 250, message = "Длина должна быть от 3 до 250") private String name; - + @ManyToOne @NotNull private Project project; - + private boolean input = true; - + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinColumn(name = "variable_id") private List fuzzyTerms = new ArrayList<>(); @@ -72,4 +72,4 @@ public class Variable extends BaseEntity { public void setInput(boolean input) { this.input = input; } -} +} \ No newline at end of file diff --git a/src/main/java/ru/ulstu/fc/rule/repository/FuzzyRuleRepository.java b/src/main/java/ru/ulstu/fc/rule/repository/FuzzyRuleRepository.java index ed36909..deb0a71 100644 --- a/src/main/java/ru/ulstu/fc/rule/repository/FuzzyRuleRepository.java +++ b/src/main/java/ru/ulstu/fc/rule/repository/FuzzyRuleRepository.java @@ -1,12 +1,11 @@ package ru.ulstu.fc.rule.repository; -import java.util.List; - import org.springframework.data.jpa.repository.JpaRepository; - import ru.ulstu.fc.project.model.Project; import ru.ulstu.fc.rule.model.FuzzyRule; +import java.util.List; + public interface FuzzyRuleRepository extends JpaRepository { List findByProject(Project project); diff --git a/src/main/java/ru/ulstu/fc/rule/repository/FuzzyTermRepository.java b/src/main/java/ru/ulstu/fc/rule/repository/FuzzyTermRepository.java index 4aa4f2c..54ca372 100644 --- a/src/main/java/ru/ulstu/fc/rule/repository/FuzzyTermRepository.java +++ b/src/main/java/ru/ulstu/fc/rule/repository/FuzzyTermRepository.java @@ -1,7 +1,6 @@ package ru.ulstu.fc.rule.repository; import org.springframework.data.jpa.repository.JpaRepository; - import ru.ulstu.fc.rule.model.FuzzyTerm; public interface FuzzyTermRepository extends JpaRepository { diff --git a/src/main/java/ru/ulstu/fc/rule/repository/VariableRepository.java b/src/main/java/ru/ulstu/fc/rule/repository/VariableRepository.java index f0d4cdc..f228db7 100644 --- a/src/main/java/ru/ulstu/fc/rule/repository/VariableRepository.java +++ b/src/main/java/ru/ulstu/fc/rule/repository/VariableRepository.java @@ -1,12 +1,11 @@ package ru.ulstu.fc.rule.repository; -import java.util.List; - import org.springframework.data.jpa.repository.JpaRepository; - import ru.ulstu.fc.project.model.Project; import ru.ulstu.fc.rule.model.Variable; +import java.util.List; + public interface VariableRepository extends JpaRepository { List findByProject(Project project); diff --git a/src/main/java/ru/ulstu/fc/rule/service/FuzzyInferenceService.java b/src/main/java/ru/ulstu/fc/rule/service/FuzzyInferenceService.java index 7aded59..3812d83 100644 --- a/src/main/java/ru/ulstu/fc/rule/service/FuzzyInferenceService.java +++ b/src/main/java/ru/ulstu/fc/rule/service/FuzzyInferenceService.java @@ -14,8 +14,8 @@ import com.fuzzylite.variable.OutputVariable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; -import ru.ulstu.fc.rule.model.OutputValue; import ru.ulstu.fc.rule.model.FuzzyTerm; +import ru.ulstu.fc.rule.model.OutputValue; import ru.ulstu.fc.rule.model.Variable; import java.util.List; @@ -30,14 +30,17 @@ public class FuzzyInferenceService { + OUTPUT_VARIABLE_NAME + " is %s"; private final static String NO_RESULT = "Нет результата"; + private final Engine fuzzyEngine; + + public FuzzyInferenceService(Engine fuzzyEngine) { + this.fuzzyEngine = fuzzyEngine; + } private List getDemoRules() { return List.of( - String.format(RULE_TEMPLATE, "возраст", "молодой", "доход", "высокий", "большой"), - String.format(RULE_TEMPLATE, "возраст", "средний", "доход", "высокий", "средний"), - String.format(RULE_TEMPLATE, "возраст", "старый", "доход", "высокий", "средний"), - String.format(RULE_TEMPLATE, "возраст", "старый", "доход", "небольшой", "небольшой"), - String.format(RULE_TEMPLATE, "возраст", "молодой", "доход", "небольшой", "небольшой") + String.format(RULE_TEMPLATE, "возраст", "молодой", "доход", "высокий", "средний"), + String.format(RULE_TEMPLATE, "возраст", "средний", "доход", "высокий", "большой"), + String.format(RULE_TEMPLATE, "возраст", "старый", "доход", "средний", "средний") ); } @@ -102,13 +105,6 @@ public class FuzzyInferenceService { return mamdani; } - private Engine getFuzzyEngine() { - Engine engine = new Engine(); - engine.setName("Fuzzy rules"); - engine.setDescription(""); - return engine; - } - private List getConsequent(Engine engine, Map variableValues) { OutputVariable outputVariable = engine.getOutputVariable(OUTPUT_VARIABLE_NAME); for (Map.Entry variableValue : variableValues.entrySet()) { @@ -152,8 +148,8 @@ public class FuzzyInferenceService { Map values, List inputVariables, Variable outputVariable) { - Engine engine = getFuzzyEngine(); - engine.addRuleBlock(getRuleBlock(engine, rules, inputVariables, outputVariable)); - return getConsequent(engine, values); + fuzzyEngine.getRuleBlocks().clear(); + fuzzyEngine.addRuleBlock(getRuleBlock(fuzzyEngine, rules, inputVariables, outputVariable)); + return getConsequent(fuzzyEngine, values); } } diff --git a/src/main/java/ru/ulstu/fc/rule/service/FuzzyRuleParseService.java b/src/main/java/ru/ulstu/fc/rule/service/FuzzyRuleParseService.java new file mode 100644 index 0000000..5209a70 --- /dev/null +++ b/src/main/java/ru/ulstu/fc/rule/service/FuzzyRuleParseService.java @@ -0,0 +1,44 @@ +package ru.ulstu.fc.rule.service; + +import com.fuzzylite.Engine; +import com.fuzzylite.rule.Rule; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +public class FuzzyRuleParseService { + private final static String RU_IF_STATEMENT = "если"; + private final static String ENG_IF_STATEMENT = "if"; + private final static String RU_THEN_STATEMENT = "то"; + private final static String ENG_THEN_STATEMENT = "then"; + private final static String RU_AND_STATEMENT = "и"; + private final static String ENG_AND_STATEMENT = "and"; + private final static String RU_IS_STATEMENT = "является"; + private final static String RU_EQ_STATEMENT = "равно"; + private final static String ENG_IS_STATEMENT = "is"; + + private final Engine fuzzyEngine; + + public FuzzyRuleParseService(Engine fuzzyEngine) { + this.fuzzyEngine = fuzzyEngine; + } + + public List parseRules(List stringRules) { + return stringRules + .stream() + .map(s -> Rule.parse(replaceEnglishKeywords(s), fuzzyEngine)) + .collect(Collectors.toList()); + } + + private String replaceEnglishKeywords(String stringRule) { + stringRule = stringRule.toLowerCase(); + return stringRule + .replaceFirst(RU_IF_STATEMENT, ENG_IF_STATEMENT) + .replaceFirst(RU_AND_STATEMENT, ENG_AND_STATEMENT) + .replaceFirst(RU_IS_STATEMENT, ENG_IS_STATEMENT) + .replaceFirst(RU_EQ_STATEMENT, ENG_IS_STATEMENT) + .replaceAll(RU_THEN_STATEMENT, ENG_THEN_STATEMENT); + } +} diff --git a/src/main/java/ru/ulstu/fc/rule/service/FuzzyRuleService.java b/src/main/java/ru/ulstu/fc/rule/service/FuzzyRuleService.java index 6f2d1c6..e4df2b7 100644 --- a/src/main/java/ru/ulstu/fc/rule/service/FuzzyRuleService.java +++ b/src/main/java/ru/ulstu/fc/rule/service/FuzzyRuleService.java @@ -1,11 +1,10 @@ package ru.ulstu.fc.rule.service; import org.springframework.stereotype.Service; - -import ru.ulstu.fc.rule.repository.FuzzyRuleRepository; import ru.ulstu.fc.project.service.ProjectService; import ru.ulstu.fc.rule.model.FuzzyRule; import ru.ulstu.fc.rule.model.FuzzyRuleForm; +import ru.ulstu.fc.rule.repository.FuzzyRuleRepository; @Service public class FuzzyRuleService { diff --git a/src/main/java/ru/ulstu/fc/rule/service/FuzzyTermService.java b/src/main/java/ru/ulstu/fc/rule/service/FuzzyTermService.java index 339b906..a9f6d2c 100644 --- a/src/main/java/ru/ulstu/fc/rule/service/FuzzyTermService.java +++ b/src/main/java/ru/ulstu/fc/rule/service/FuzzyTermService.java @@ -1,21 +1,20 @@ package ru.ulstu.fc.rule.service; -import java.util.Collections; -import java.util.List; - import org.springframework.stereotype.Service; - import ru.ulstu.fc.rule.model.FuzzyTerm; import ru.ulstu.fc.rule.model.FuzzyTermForm; import ru.ulstu.fc.rule.repository.FuzzyTermRepository; +import java.util.Collections; +import java.util.List; + @Service public class FuzzyTermService { private final FuzzyTermRepository fuzzyTermRepository; private final VariableService variableService; public FuzzyTermService(FuzzyTermRepository fuzzyTermRepository, - VariableService variableService) { + VariableService variableService) { this.fuzzyTermRepository = fuzzyTermRepository; this.variableService = variableService; } diff --git a/src/main/java/ru/ulstu/fc/rule/service/VariableService.java b/src/main/java/ru/ulstu/fc/rule/service/VariableService.java index c07e397..5fca4eb 100644 --- a/src/main/java/ru/ulstu/fc/rule/service/VariableService.java +++ b/src/main/java/ru/ulstu/fc/rule/service/VariableService.java @@ -1,7 +1,6 @@ package ru.ulstu.fc.rule.service; import org.springframework.stereotype.Service; - import ru.ulstu.fc.project.service.ProjectService; import ru.ulstu.fc.rule.model.FuzzyTerm; import ru.ulstu.fc.rule.model.Variable; diff --git a/src/main/java/ru/ulstu/fc/user/controller/UserController.java b/src/main/java/ru/ulstu/fc/user/controller/UserController.java index c238db5..a1089eb 100644 --- a/src/main/java/ru/ulstu/fc/user/controller/UserController.java +++ b/src/main/java/ru/ulstu/fc/user/controller/UserController.java @@ -1,5 +1,7 @@ package ru.ulstu.fc.user.controller; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.validation.Valid; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.Errors; @@ -7,9 +9,6 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.context.request.WebRequest; - -import jakarta.servlet.http.HttpServletRequest; -import jakarta.validation.Valid; import ru.ulstu.fc.user.model.User; import ru.ulstu.fc.user.model.UserDto; import ru.ulstu.fc.user.service.UserService; diff --git a/src/main/java/ru/ulstu/fc/user/model/User.java b/src/main/java/ru/ulstu/fc/user/model/User.java index 352808e..9b1bc04 100644 --- a/src/main/java/ru/ulstu/fc/user/model/User.java +++ b/src/main/java/ru/ulstu/fc/user/model/User.java @@ -1,8 +1,5 @@ package ru.ulstu.fc.user.model; -import java.util.HashSet; -import java.util.Set; - import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.JoinColumn; @@ -15,6 +12,9 @@ import jakarta.validation.constraints.Size; import ru.ulstu.fc.config.Constants; import ru.ulstu.fc.core.model.BaseEntity; +import java.util.HashSet; +import java.util.Set; + @Entity @Table(name = "is_users") public class User extends BaseEntity { diff --git a/src/main/java/ru/ulstu/fc/user/service/UserSessionLoginHandler.java b/src/main/java/ru/ulstu/fc/user/service/UserSessionLoginHandler.java index 44d7904..971c37b 100644 --- a/src/main/java/ru/ulstu/fc/user/service/UserSessionLoginHandler.java +++ b/src/main/java/ru/ulstu/fc/user/service/UserSessionLoginHandler.java @@ -1,19 +1,18 @@ package ru.ulstu.fc.user.service; -import java.io.IOException; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.security.core.Authentication; -import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; -import org.springframework.stereotype.Component; - import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.security.core.Authentication; +import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; +import org.springframework.stereotype.Component; import ru.ulstu.fc.config.Constants; +import java.io.IOException; + @Component public class UserSessionLoginHandler extends SavedRequestAwareAuthenticationSuccessHandler { private final Logger log = LoggerFactory.getLogger(UserSessionLoginHandler.class); diff --git a/src/main/java/ru/ulstu/fc/user/service/UserSessionLogoutHandler.java b/src/main/java/ru/ulstu/fc/user/service/UserSessionLogoutHandler.java index 9703e9e..662c11e 100644 --- a/src/main/java/ru/ulstu/fc/user/service/UserSessionLogoutHandler.java +++ b/src/main/java/ru/ulstu/fc/user/service/UserSessionLogoutHandler.java @@ -1,19 +1,18 @@ package ru.ulstu.fc.user.service; -import java.io.IOException; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.security.core.Authentication; -import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler; -import org.springframework.stereotype.Component; - import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.security.core.Authentication; +import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler; +import org.springframework.stereotype.Component; import ru.ulstu.fc.config.Constants; +import java.io.IOException; + @Component public class UserSessionLogoutHandler extends SimpleUrlLogoutSuccessHandler { private final Logger log = LoggerFactory.getLogger(UserSessionLogoutHandler.class); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 4f4bd5b..05d3866 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -13,6 +13,7 @@ extractor.custom-projects-dir= server.error.include-stacktrace=always server.error.include-exception=true server.error.include-message=always +# go to http://localhost:8080/h2-console spring.datasource.url=jdbc:h2:file:./data/db spring.datasource.driverClassName=org.h2.Driver spring.datasource.username=sa diff --git a/src/main/resources/templates/addRule.html b/src/main/resources/templates/addRule.html deleted file mode 100644 index 0abb1e8..0000000 --- a/src/main/resources/templates/addRule.html +++ /dev/null @@ -1,83 +0,0 @@ - - - - Простая обработка формы на Spring MVC - - -
-
- -
-
- Если -
-
- -
-
- имеет тенденцию -
-
- -
-
- и -
-
- -
-
- имеет тенденцию -
-
- -
-
- то: -
-
- -
-
-
-
-
- - -
-
-
-
- diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index 783a0fc..d4459fb 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -1,71 +1,71 @@ + xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity6"> - + Нечеткий контроллер - + - - - + + + - +
+ + +
+ +
+
- -
- - -
- -
- -
-
-
+
+
\ No newline at end of file diff --git a/src/main/resources/templates/fuzzyTerm/edit.html b/src/main/resources/templates/fuzzyTerm/edit.html index 84837f9..1663feb 100644 --- a/src/main/resources/templates/fuzzyTerm/edit.html +++ b/src/main/resources/templates/fuzzyTerm/edit.html @@ -39,7 +39,7 @@ Не может быть пустым

- + Вернуться на страницу входа diff --git a/src/main/resources/templates/rule/edit.html b/src/main/resources/templates/rule/edit.html index 1b16584..bbe6824 100644 --- a/src/main/resources/templates/rule/edit.html +++ b/src/main/resources/templates/rule/edit.html @@ -12,9 +12,9 @@
- +
- +
+ + +
+
+ + +
+
+ + +
+
+ + +
+ Отмена -
+

Список термов

@@ -40,12 +40,13 @@
- Добавить терм + Добавить терм